fix(install): nvm fallback when node/npm missing

Fresh machine had no npm → install.sh err-exited before the Claude Code
CLI install could run. Instead of aborting, bootstrap the current LTS via
nvm (v0.39.7) → `nvm install --lts` when node or npm is absent. Keeps the
>=18 floor + friendly messages on hard failure.

Replaces the reverted lib/install-prereqs.sh centralization with the
minimal targeted fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UyNYwD4UccVw9ZCFZyJX55
This commit is contained in:
Bastien Chanot 2026-06-23 14:09:12 +02:00
parent 937dd1d366
commit b6cc8b1a86

View File

@ -22,8 +22,23 @@ echo ""
# ── 1. Check prerequisites ── # ── 1. Check prerequisites ──
echo "── Checking prerequisites..." echo "── Checking prerequisites..."
# node + npm drive the Claude Code CLI install below. On a fresh machine
# they may be absent — install the current LTS via nvm instead of aborting.
install_node_via_nvm() {
info "Node.js/npm missing — installing LTS via nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install --lts
}
if ! command -v node &>/dev/null || ! command -v npm &>/dev/null; then
install_node_via_nvm
fi
if ! command -v node &>/dev/null; then if ! command -v node &>/dev/null; then
err "Node.js not found. Install it first: https://nodejs.org" err "Node.js install failed — install it manually: https://nodejs.org"
fi fi
NODE_MAJOR=$(node -v | sed 's/v//' | cut -d. -f1) NODE_MAJOR=$(node -v | sed 's/v//' | cut -d. -f1)
@ -33,7 +48,7 @@ fi
ok "Node.js $(node -v)" ok "Node.js $(node -v)"
if ! command -v npm &>/dev/null; then if ! command -v npm &>/dev/null; then
err "npm not found" err "npm not found (expected alongside Node.js)"
fi fi
ok "npm $(npm -v)" ok "npm $(npm -v)"