Skip to content

Commit e4e2e21

Browse files
Skip plain-forge install when Node.js is unavailable
The npx presence check passes when a version-manager shim (nvm, volta, asdf) is on PATH without a working Node.js behind it. The npx call then fails and aborts the whole installer: set -euo pipefail in bash, ErrorActionPreference=Stop in PowerShell. The PowerShell installer also marked plain-forge as installed even when the npx command failed. Verify node actually runs before invoking npx, skip the step with a clear message when it doesn't, and let a failed plain-forge install print a retry hint instead of aborting the remaining setup steps. The final next-steps screen already reminds the user to install plain-forge manually whenever the step was skipped or failed.
1 parent 9c2c659 commit e4e2e21

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎install/bash/install.sh‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,20 @@ fi
312312

313313
PLAIN_FORGE_INSTALLED=false
314314
if [[ ! "${INSTALL_PLAIN_FORGE:-}" =~ ^[Nn]$ ]]; then
315-
if command -v npx &> /dev/null; then
316-
npx plain-forge install < /dev/tty
317-
PLAIN_FORGE_INSTALLED=true
315+
# A stale nvm/volta/asdf shim can make npx resolvable without a working
316+
# Node.js behind it, so verify node actually runs before invoking npx.
317+
if command -v npx &> /dev/null && node --version &> /dev/null; then
318+
# The install must not abort the rest of the setup if plain-forge
319+
# fails (set -e is active), so run it inside the condition.
320+
if npx plain-forge install < /dev/tty; then
321+
PLAIN_FORGE_INSTALLED=true
322+
else
323+
echo -e "${GRAY}plain-forge installation failed. You can retry later with:${NC}"
324+
echo -e " npx plain-forge install"
325+
fi
318326
echo ""
319327
else
320-
echo -e "${GRAY}npx not found. Install Node.js, then run:${NC}"
328+
echo -e "${GRAY}Node.js not found. Skipping plain-forge. Install Node.js, then run:${NC}"
321329
echo -e " npx plain-forge install"
322330
echo ""
323331
fi

‎install/powershell/install.ps1‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,35 @@ if ($nonInteractive) {
347347

348348
$plainForgeInstalled = $false
349349
if ($installPlainForge -notmatch '^[Nn]$') {
350-
if (Get-Command npx -ErrorAction SilentlyContinue) {
351-
npx plain-forge install
352-
$plainForgeInstalled = $true
350+
# A stale version-manager shim can make npx resolvable without a working
351+
# Node.js behind it, so verify node actually runs before invoking npx.
352+
$nodeWorks = $false
353+
if ((Get-Command node -ErrorAction SilentlyContinue) -and (Get-Command npx -ErrorAction SilentlyContinue)) {
354+
try {
355+
& node --version *> $null
356+
$nodeWorks = ($LASTEXITCODE -eq 0)
357+
} catch {
358+
$nodeWorks = $false
359+
}
360+
}
361+
if ($nodeWorks) {
362+
# A plain-forge failure must not abort the rest of the setup
363+
# ($ErrorActionPreference is 'Stop').
364+
try {
365+
npx plain-forge install
366+
if ($LASTEXITCODE -eq 0) {
367+
$plainForgeInstalled = $true
368+
}
369+
} catch {
370+
# fall through to the retry hint below
371+
}
372+
if (-not $plainForgeInstalled) {
373+
Write-Host "${GRAY}plain-forge installation failed. You can retry later with:${NC}"
374+
Write-Host " npx plain-forge install"
375+
}
353376
Write-Host ""
354377
} else {
355-
Write-Host "${GRAY}npx not found. Install Node.js, then run:${NC}"
378+
Write-Host "${GRAY}Node.js not found. Skipping plain-forge. Install Node.js, then run:${NC}"
356379
Write-Host " npx plain-forge install"
357380
Write-Host ""
358381
}

0 commit comments

Comments
 (0)