From eb52bbd9d3c096e0f5c54a10fd1c4d729ad48961 Mon Sep 17 00:00:00 2001 From: Jerry Chae Date: Wed, 13 May 2026 20:03:18 +0900 Subject: [PATCH] =?UTF-8?q?npm=20=EC=97=86=EC=9C=BC=EB=A9=B4=20=EC=84=A4?= =?UTF-8?q?=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install-pi.ps1 | 32 +++++++++++++++++++++++++++++++- install-pi.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/install-pi.ps1 b/install-pi.ps1 index ae34750..24501b2 100644 --- a/install-pi.ps1 +++ b/install-pi.ps1 @@ -79,7 +79,37 @@ function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 } Info "Platform: $([System.Environment]::OSVersion.Platform) ($([System.Environment]::GetEnvironmentVariable('PROCESSOR_ARCHITECTURE')))" if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { - ErrExit "npm is required. Install Node.js 18+: https://nodejs.org/" + Info "npm is not installed. Installing Node.js (includes npm) via winget..." + + if (-not (Get-Command winget -ErrorAction SilentlyContinue)) { + ErrExit "Neither npm nor winget is available. Install Node.js 18+ manually: https://nodejs.org/" + } + + winget install --id OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>&1 | Out-Null + + # Refresh PATH and verify npm is now available + $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + + if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { + # Search common Node.js install paths + $nodePaths = @( + (Join-Path $env:ProgramFiles 'nodejs'), + (Join-Path $env:ProgramFiles(x86) 'nodejs'), + (Join-Path $env:LOCALAPPDATA 'Programs\nodejs') + ) + foreach ($np in $nodePaths) { + if ((Test-Path $np) -and ($env:Path -notlike "*$np*")) { + $env:Path = "$np;$env:Path" + break + } + } + } + + if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { + ErrExit "Node.js installation completed but npm not found. Please restart your terminal and run this script again." + } + + Success "Node.js installed via winget" } # ──────────────────────────────────────────── diff --git a/install-pi.sh b/install-pi.sh index 4af7374..928f6c8 100755 --- a/install-pi.sh +++ b/install-pi.sh @@ -58,6 +58,51 @@ for cmd in curl; do command -v "$cmd" &>/dev/null || error "'$cmd' is required." done +# Check for Node.js (npm) — install if missing +if ! command -v npm &>/dev/null; then + info "npm is not installed. Installing Node.js..." + case "$OS" in + Darwin) + if command -v brew &>/dev/null; then + brew install node + success "Node.js installed via Homebrew" + else + error "Homebrew (brew) is required to install Node.js on macOS. Install it from https://brew.sh/" + fi + ;; + Linux) + if command -v apt-get &>/dev/null; then + sudo apt-get update -y && sudo apt-get install -y nodejs npm + success "Node.js installed via apt-get" + elif command -v dnf &>/dev/null; then + sudo dnf install -y nodejs + success "Node.js installed via dnf" + elif command -v yum &>/dev/null; then + sudo yum install -y nodejs + success "Node.js installed via yum" + elif command -v zypper &>/dev/null; then + sudo zypper -n install nodejs npm + success "Node.js installed via zypper" + elif command -v pacman &>/dev/null; then + sudo pacman -S --noconfirm nodejs npm + success "Node.js installed via pacman" + else + error "No supported package manager found. Install Node.js 18+ manually: https://nodejs.org/" + fi + ;; + *) + error "Cannot auto-install Node.js on this OS. Install Node.js 18+ manually: https://nodejs.org/" + ;; + esac + + # Verify npm is now available + if ! command -v npm &>/dev/null; then + error "Node.js installation completed but npm not found. Install Node.js 18+ manually: https://nodejs.org/" + fi +fi + +info "npm is available: $(command -v npm)" + # ──────────────────────────────────────────── # Detect OS / Architecture # ────────────────────────────────────────────