Skip to content

Commit 3551e98

Browse files
committed
fix(installer): bootstrap portable Windows Node
1 parent 1fdc73a commit 3551e98

4 files changed

Lines changed: 199 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Docs: https://docs.openclaw.ai
4242
- OpenAI Codex: preserve image input support for sparse `openai-codex/gpt-5.5` catalog rows. (#85095) Thanks @sercada.
4343
- Plugins/discovery: strip `-plugin` package suffixes when deriving plugin id hints so package names line up with manifest ids. (#85170) Thanks @JulyanXu.
4444
- Telegram: preserve fenced code block languages through Markdown rendering so Telegram receives `language-*` code classes. (#85209) Thanks @leno23.
45+
- Windows installer: bootstrap a user-local portable Node.js when native Windows has no Node and no winget, Chocolatey, or Scoop, so first-run installs can continue on raw hosts.
4546
- fix(integrations): enforce channel read target allowlists [AI]. (#84982) Thanks @pgondhi987.
4647
- Agents/heartbeat: route single-owner `session.dmScope=main` direct-message exec and cron event wakes back to the agent main session so async completions no longer strand context in orphan direct-DM queues. Fixes #71581. (#83743) Thanks @Kaspre.
4748
- Agents/code-mode: expose outer code-mode `exec` source through the `command` hook alias with `toolKind`/`toolInputKind` discriminators so exec-shaped policies can distinguish code-mode cells. (#83483) Thanks @Kaspre.

‎docs/install/installer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ by default, plus git-checkout installs under the same prefix flow.
284284
Requires PowerShell 5+.
285285
</Step>
286286
<Step title="Ensure Node.js 24 by default">
287-
If missing, attempts install via winget, then Chocolatey, then Scoop. Node 22 LTS, currently `22.19+`, remains supported for compatibility.
287+
If missing, attempts install via winget, then Chocolatey, then Scoop. If no package manager is available, the script downloads the official Node.js Windows zip into `%LOCALAPPDATA%\OpenClaw\deps\portable-node` and adds it to the current process and user PATH. Node 22 LTS, currently `22.19+`, remains supported for compatibility.
288288
</Step>
289289
<Step title="Install OpenClaw">
290290
- `npm` method (default): global npm install using selected `-Tag`, launched from a writable installer temp directory so shells opened in protected folders such as `C:\` still work

‎scripts/install.ps1‎

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,144 @@ function Check-Node {
104104
return $false
105105
}
106106

107+
function Get-WindowsNodeArchitecture {
108+
foreach ($architecture in @($env:PROCESSOR_ARCHITEW6432, $env:PROCESSOR_ARCHITECTURE)) {
109+
if ($architecture -match "ARM64") {
110+
return "arm64"
111+
}
112+
}
113+
return "x64"
114+
}
115+
116+
function Get-OpenClawDepsRoot {
117+
$localAppData = $env:LOCALAPPDATA
118+
if ([string]::IsNullOrWhiteSpace($localAppData)) {
119+
$localAppData = [Environment]::GetFolderPath("LocalApplicationData")
120+
}
121+
if ([string]::IsNullOrWhiteSpace($localAppData)) {
122+
$localAppData = Join-Path ([Environment]::GetFolderPath("UserProfile")) "AppData\Local"
123+
}
124+
return (Join-Path $localAppData "OpenClaw\deps")
125+
}
126+
127+
function Get-PortableNodeRoot {
128+
return (Join-Path (Get-OpenClawDepsRoot) "portable-node")
129+
}
130+
131+
function Get-PortableNodeCommandPath {
132+
$root = Get-PortableNodeRoot
133+
$candidate = Join-Path $root "node.exe"
134+
if (Test-Path $candidate) {
135+
return $candidate
136+
}
137+
return $null
138+
}
139+
140+
function Use-PortableNodeIfPresent {
141+
$nodeExe = Get-PortableNodeCommandPath
142+
if (-not $nodeExe) {
143+
return $false
144+
}
145+
146+
Add-ToProcessPath (Split-Path -Parent $nodeExe)
147+
return (Check-Node)
148+
}
149+
150+
function Ensure-PortableNodeOnUserPath {
151+
$nodeExe = Get-PortableNodeCommandPath
152+
if (-not $nodeExe) {
153+
return
154+
}
155+
156+
$nodeDir = Split-Path -Parent $nodeExe
157+
if (Add-ToUserPath $nodeDir) {
158+
Write-Host "[!] Added $nodeDir to user PATH (restart terminal if node or openclaw is not found)" -ForegroundColor Yellow
159+
}
160+
}
161+
162+
function Resolve-PortableNodeDownload {
163+
$architecture = Get-WindowsNodeArchitecture
164+
$index = Invoke-RestMethod -Uri "https://nodejs.org/dist/index.json"
165+
$release = $index |
166+
Where-Object { $_.version -match '^v24\.' } |
167+
Select-Object -First 1
168+
169+
if (-not $release -or -not $release.version) {
170+
throw "Could not resolve latest Node.js 24 release metadata."
171+
}
172+
173+
$fileKey = "win-$architecture-zip"
174+
if ($release.files -and -not ($release.files -contains $fileKey)) {
175+
throw "Node.js $($release.version) does not publish $fileKey."
176+
}
177+
178+
$name = "node-$($release.version)-win-$architecture.zip"
179+
return @{
180+
Version = $release.version
181+
Name = $name
182+
Url = "https://nodejs.org/dist/$($release.version)/$name"
183+
}
184+
}
185+
186+
function Install-PortableNode {
187+
if (Use-PortableNodeIfPresent) {
188+
Ensure-PortableNodeOnUserPath
189+
$nodeVersion = (& node -v 2>$null)
190+
if ($nodeVersion) {
191+
Write-Host "[OK] User-local Node.js already available: $nodeVersion" -ForegroundColor Green
192+
}
193+
return
194+
}
195+
196+
Write-Host " No package manager found; bootstrapping user-local portable Node.js..." -ForegroundColor Gray
197+
198+
$download = Resolve-PortableNodeDownload
199+
$portableRoot = Get-PortableNodeRoot
200+
$portableParent = Split-Path -Parent $portableRoot
201+
$tmpZip = Join-Path $env:TEMP $download.Name
202+
$tmpExtract = Join-Path $env:TEMP ("openclaw-portable-node-" + [guid]::NewGuid().ToString("N"))
203+
204+
New-Item -ItemType Directory -Force -Path $portableParent | Out-Null
205+
if (Test-Path $portableRoot) {
206+
Remove-Item -Recurse -Force $portableRoot
207+
}
208+
if (Test-Path $tmpExtract) {
209+
Remove-Item -Recurse -Force $tmpExtract
210+
}
211+
New-Item -ItemType Directory -Force -Path $tmpExtract | Out-Null
212+
213+
try {
214+
Write-Host " Downloading Node.js $($download.Version)..." -ForegroundColor Gray
215+
Invoke-WebRequest -UseBasicParsing -Uri $download.Url -OutFile $tmpZip
216+
Expand-Archive -Path $tmpZip -DestinationPath $tmpExtract -Force
217+
218+
$nodeDir = Get-ChildItem -Path $tmpExtract -Directory |
219+
Where-Object { Test-Path (Join-Path $_.FullName "node.exe") } |
220+
Select-Object -First 1
221+
if (-not $nodeDir) {
222+
throw "Node.js archive did not contain node.exe."
223+
}
224+
225+
New-Item -ItemType Directory -Force -Path $portableRoot | Out-Null
226+
Move-Item -Path (Join-Path $nodeDir.FullName "*") -Destination $portableRoot -Force
227+
} finally {
228+
if (Test-Path $tmpZip) {
229+
Remove-Item -Force $tmpZip
230+
}
231+
if (Test-Path $tmpExtract) {
232+
Remove-Item -Recurse -Force $tmpExtract
233+
}
234+
}
235+
236+
if (-not (Use-PortableNodeIfPresent)) {
237+
throw "Portable Node.js bootstrap completed, but node is still unavailable."
238+
}
239+
Ensure-PortableNodeOnUserPath
240+
241+
$nodeVersion = (& node -v 2>$null)
242+
Write-Host "[OK] User-local Node.js ready: $nodeVersion" -ForegroundColor Green
243+
}
244+
107245
# Install Node.js
108246
function Install-Node {
109247
Write-Host "[*] Installing Node.js..." -ForegroundColor Yellow
@@ -143,9 +281,18 @@ function Install-Node {
143281
return $true
144282
}
145283

284+
try {
285+
Install-PortableNode
286+
if (Check-Node) {
287+
return $true
288+
}
289+
} catch {
290+
Write-Host "[!] Portable Node.js bootstrap failed: $($_.Exception.Message)" -ForegroundColor Yellow
291+
}
292+
146293
# Manual download fallback
147294
Write-Host ""
148-
Write-Host "Error: Could not find a package manager (winget, choco, or scoop)" -ForegroundColor Red
295+
Write-Host "Error: Could not install Node.js automatically." -ForegroundColor Red
149296
Write-Host ""
150297
Write-Host "Please install Node.js 22+ manually:" -ForegroundColor Yellow
151298
Write-Host " https://nodejs.org/en/download/" -ForegroundColor Cyan
@@ -190,6 +337,33 @@ function Add-ToProcessPath {
190337
$env:Path = "$PathEntry;$env:Path"
191338
}
192339

340+
function Add-ToUserPath {
341+
param(
342+
[Parameter(Mandatory = $true)]
343+
[string]$PathEntry
344+
)
345+
346+
if ([string]::IsNullOrWhiteSpace($PathEntry)) {
347+
return $false
348+
}
349+
350+
Add-ToProcessPath $PathEntry
351+
352+
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
353+
$userEntries = @($userPath -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
354+
if ($userEntries | Where-Object { $_ -ieq $PathEntry }) {
355+
return $false
356+
}
357+
358+
$newUserPath = if ([string]::IsNullOrWhiteSpace($userPath)) {
359+
$PathEntry
360+
} else {
361+
"$userPath;$PathEntry"
362+
}
363+
[Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
364+
return $true
365+
}
366+
193367
function Get-PortableGitRoot {
194368
$base = Join-Path $env:LOCALAPPDATA "OpenClaw\deps"
195369
return (Join-Path $base "portable-git")

‎test/scripts/install-ps1.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ describe("install.ps1 failure handling", () => {
114114
expect(npmInstallBody).toContain("-InstallMethod git -Tag main");
115115
});
116116

117+
it("falls back to a user-local portable Node.js bootstrap when package managers are absent", () => {
118+
const installNodeBody = extractFunctionBody(source, "Install-Node");
119+
const portableNodeBody = extractFunctionBody(source, "Install-PortableNode");
120+
const portableNodePathBody = extractFunctionBody(source, "Ensure-PortableNodeOnUserPath");
121+
const userPathBody = extractFunctionBody(source, "Add-ToUserPath");
122+
const depsRootBody = extractFunctionBody(source, "Get-OpenClawDepsRoot");
123+
const resolveNodeBody = extractFunctionBody(source, "Resolve-PortableNodeDownload");
124+
125+
expect(installNodeBody).toContain("Install-PortableNode");
126+
expect(installNodeBody).toContain("Portable Node.js bootstrap failed");
127+
expect(installNodeBody).toContain("Error: Could not install Node.js automatically.");
128+
expect(depsRootBody).toContain("OpenClaw\\deps");
129+
expect(portableNodeBody).toContain("portable-node");
130+
expect(portableNodeBody).toContain("Ensure-PortableNodeOnUserPath");
131+
expect(portableNodePathBody).toContain("Add-ToUserPath $nodeDir");
132+
expect(userPathBody).toContain('[Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")');
133+
expect(portableNodeBody).toContain("Invoke-WebRequest -UseBasicParsing");
134+
expect(resolveNodeBody).toContain("https://nodejs.org/dist/index.json");
135+
expect(resolveNodeBody).toContain("win-$architecture-zip");
136+
expect(resolveNodeBody).toContain("node-$($release.version)-win-$architecture.zip");
137+
});
138+
117139
it("cleans legacy git submodules only from the selected git checkout", () => {
118140
const gitInstallBody = extractFunctionBody(source, "Install-OpenClawFromGit");
119141
const mainBody = extractFunctionBody(source, "Main");

0 commit comments

Comments
 (0)