Skip to content

fix(windows): write node script to temp file instead of node -e#250

Open
scottconverse wants to merge 1 commit intoJuliusBrussee:mainfrom
scottconverse:fix/windows-node-e-truncation
Open

fix(windows): write node script to temp file instead of node -e#250
scottconverse wants to merge 1 commit intoJuliusBrussee:mainfrom
scottconverse:fix/windows-node-e-truncation

Conversation

@scottconverse
Copy link
Copy Markdown
Contributor

Fixes #249

What broke

install.ps1 failed on Windows PowerShell 5.1 with a SyntaxError mid-script:

[eval]:17
      command: 'node '
SyntaxError: Unexpected end of input

Hook files were copied but settings.json was never updated, leaving caveman non-functional.

Root cause

node -e $nodeScript on Windows passes the multiline string through the Windows command processor, which terminates the argument at the first " character. The JS string contains 'node "' + hooksDir + ... — the " after node ends the argument early.

Fix

Write the script to a temp .js file and run node tempfile.js. Temp file is cleaned up in a finally block regardless of success or failure.

$tmpScript = Join-Path $env:TEMP "caveman-install-$([System.Diagnostics.Process]::GetCurrentProcess().Id).js"
try {
    [System.IO.File]::WriteAllText($tmpScript, $nodeScript, [System.Text.Encoding]::UTF8)
    node $tmpScript
} finally {
    if (Test-Path $tmpScript) { Remove-Item $tmpScript -Force }
}

Verified clean install output on Windows 11 / PowerShell 5.1 / Node v24.14.0.

On Windows PowerShell 5.1, passing a multiline JS string via `node -e`
truncates the argument at the first double-quote character, causing a
SyntaxError mid-script. Fix: write the script to a temp file and run
`node tempfile.js`, cleaning up in a finally block.

Fixes install failing with:
  [eval]:17
    command: 'node '
  SyntaxError: Unexpected end of input
JuliusBrussee added a commit that referenced this pull request Apr 30, 2026
PowerShell 5.1 mangles the multiline $nodeScript when passed to
node -e — the embedded `"` after `node ` terminates the argument
early, causing SyntaxError mid-install. Hook files copy but
settings.json never updates, leaving caveman non-functional.

Write the script to %TEMP%\caveman-install-<pid>.js, run it, clean
up in a finally block. Verified clean install on Windows 11 /
PowerShell 5.1 / Node 24.

Closes #249.

Co-Authored-By: Scott Converse <scottconverse@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: install.ps1 fails with SyntaxError due to node -e truncating at double-quotes

1 participant