Skip to content

fix(opencode): make the npm postinstall failure diagnosable and its Windows fallback work - #355

Merged
quickbeard merged 2 commits into
mainfrom
fix/postinstall-diagnostics
Sep 10, 2026
Merged

quickbeard merged 2 commits into
mainfrom
fix/postinstall-diagnostics

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

A user on Windows (npm 12.0.2) hit npm i -g codev-code ending with "It seems your package manager failed to install the right codev CLI package. Try manually installing …". Investigating that showed the message is reachable from three unrelated failures and the script gives no way to tell them apart, plus one path that cannot work on Windows at all.

  • Diagnostics. installPackage and verifyBinary now report why they failed instead of returning false: the platform package was not installed by the package manager (with the resolve error), the fallback npm install could not start or exited non-zero, or the copied binary's --version failed (spawn error, exit code or signal, and the first stderr line — stderr is piped rather than ignored, because an antivirus or application-control block says so there). main collects one line per package and step and appends a What was tried list to the final error.
  • Windows fallback actually runs. The fallback that fetches the platform package into a temp prefix spawned npm with no shell. On Windows that is npm.cmd, which Node has refused to spawn without a shell since 18.20.2 / 20.12.2 (CVE-2024-27980), so it failed instantly and silently on every supported Node. It now spawns cmd.exe /d /s /c npm … as the Node docs recommend; Node still quotes each argument, so a temp path with spaces is fine. Upstream opencode's script has the same bug.
  • npm 12 hint. npm 12 blocks install scripts on global installs by default (verified: npx npm@12.0.2 install -g codev-code leaves the placeholder in place and warns). The placeholder stub's message now shows npm install -g codev-code --allow-scripts=codev-code.

Both scripts are upstream files; their DIVERGENCES.md rows are extended. CHANGELOG has an Install entry.

Test plan

  • node --check and prettier on the script
  • Scratch layout, package manager skipped the optional dep → fallback fetch of codev-code-darwin-arm64@1.18.23-2 succeeds, bin/codev.exe --version prints 1.18.23-2
  • Scratch layout, unpublished version → error ends with What was tried: listing the resolve failure and npm install … exited with 1
  • Scratch layout, installed binary that exits 3 with a stderr line → error reports installed, but … exited with code 3: <stderr line>
  • bun typecheck in packages/opencode
  • Windows: confirm the cmd.exe fallback path fetches the package when the optional dep is missing (npm i -g codev-code --omit=optional --allow-scripts=codev-code)

🤖 Generated with Claude Code

https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y

quickbeard and others added 2 commits September 10, 2026 15:49
…indows fallback work

The postinstall swallowed every error and ended with a message that only
named packages to retry, so an install that failed because the platform
package never arrived, because the fallback npm fetch failed, or because
the installed binary refused to run all looked identical. Each step now
records a one-line reason (spawn error, exit code or signal, first stderr
line of `--version`) and the final error lists them under "What was tried".

The fallback fetch spawned `npm` without a shell; on Windows that is
npm.cmd, which Node has refused to spawn without a shell since 18.20.2 /
20.12.2 (CVE-2024-27980), so the fallback silently never ran there. It now
goes through cmd.exe as the Node docs recommend.

The placeholder stub that runs when the postinstall did not points npm 12
users at --allow-scripts, since npm 12 blocks install scripts on global
installs by default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y
@quickbeard
quickbeard merged commit 13b634f into main Sep 10, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the fix/postinstall-diagnostics branch September 10, 2026 08:50
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.

1 participant