mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-09 13:21:42 +00:00
fix(installer): put node.exe on PATH for Windows npm lifecycle scripts
npm postinstall hooks spawn cmd.exe child processes that could not resolve `node` even when the installer found npm — causing desktop workspace npm install to fail with exit 1 (#48130).
This commit is contained in:
parent
009b42d008
commit
2bc6e1a74b
1 changed files with 26 additions and 0 deletions
|
|
@ -502,6 +502,26 @@ function Sync-EnvPath {
|
|||
$env:Path = [Environment]::GetEnvironmentVariable("Path", "User") + ";" + [Environment]::GetEnvironmentVariable("Path", "Machine")
|
||||
}
|
||||
|
||||
# npm lifecycle scripts on Windows spawn ``cmd.exe /d /s /c node <script>``.
|
||||
# PowerShell can resolve ``node`` via Get-Command while the child cmd process
|
||||
# still sees a PATH without node.exe's directory (nvm4w shims, App Paths
|
||||
# aliases, stale cross-process PATH). Prepend the resolved node.exe parent
|
||||
# directory so postinstall hooks (electron-winstaller, native modules, etc.)
|
||||
# can find ``node``. Regression for #48130.
|
||||
function Ensure-NodeExeOnPath {
|
||||
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
|
||||
if (-not $nodeCmd) { return $false }
|
||||
|
||||
$nodeExeDir = Split-Path $nodeCmd.Source -Parent
|
||||
if (-not $nodeExeDir) { return $false }
|
||||
|
||||
$pathParts = $env:Path -split ";"
|
||||
if ($pathParts -notcontains $nodeExeDir) {
|
||||
$env:Path = "$nodeExeDir;$env:Path"
|
||||
}
|
||||
return $true
|
||||
}
|
||||
|
||||
# Re-discover uv without re-installing it. Cross-process stage drivers
|
||||
# (the desktop GUI's onboarding wizard, CI step-runners) invoke each stage
|
||||
# in a fresh powershell process, so $script:UvCmd set by Install-Uv in a
|
||||
|
|
@ -920,6 +940,7 @@ function Test-Node {
|
|||
if (Get-Command node -ErrorAction SilentlyContinue) {
|
||||
$version = node --version
|
||||
if (Test-NodeVersionOk $version) {
|
||||
Ensure-NodeExeOnPath | Out-Null
|
||||
Write-Success "Node.js $version found"
|
||||
$script:HasNode = $true
|
||||
return $true
|
||||
|
|
@ -2247,6 +2268,11 @@ function Install-NodeDeps {
|
|||
}
|
||||
}
|
||||
|
||||
# npm lifecycle scripts need node.exe on the PATH visible to child
|
||||
# cmd.exe processes. Stage-Node may have run in a prior process, so
|
||||
# re-apply here before any npm install (regression #48130).
|
||||
Ensure-NodeExeOnPath | Out-Null
|
||||
|
||||
# Resolve npm explicitly to npm.cmd, NOT npm.ps1. Node.js on Windows
|
||||
# ships BOTH npm.cmd (a batch shim) and npm.ps1 (a PowerShell shim).
|
||||
# Get-Command's default ordering picks whichever comes first in PATHEXT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue