Skip to content

fix(cli): ship runtime binary launcher to support npm v12 and disabled install scripts - #48885

Open
marwanvx wants to merge 1 commit into
anomalyco:v2from
marwanvx:npm-binary-launcher
Open

marwanvx wants to merge 1 commit into
anomalyco:v2from
marwanvx:npm-binary-launcher

Conversation

@marwanvx

Copy link
Copy Markdown

Issue for this PR

Closes #48884

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When @opencode/cli is installed in environments where package lifecycle scripts are disabled (such as Node 26 / npm 12 where allowScripts is false by default, or with --ignore-scripts), postinstall.mjs is never invoked. The published package previously shipped an unlinked binary stub in bin/ that failed with an error asking the user to manually run postinstall.

This change:

  1. Ships bin/opencode.cjs (and legacy alias opencode2.cjs) as the npm package bin entry point instead of an unlinked stub.
  2. Resolves and launches the platform native binary at runtime via require.resolve() and directory traversal from optionalDependencies.
  3. Treats postinstall.mjs pre-linking into bin/.${sourceCommand} as an optional performance optimization: it caches the binary if run, but exits 0 cleanly if scripts are blocked, avoiding failed package installations.
  4. Adds launcher unit tests in packages/cli/test/launcher.test.ts.

How did you verify your code works?

  • cd packages/cli && bun test test/launcher.test.ts (4 passed, 0 failed)
  • cd packages/cli && bun run typecheck (0 errors)
  • Verified simulated global install with blocked scripts executes the native binary cleanly.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Ship bin/opencode.cjs as the npm distribution entry point instead of a dummy stub. Modern package managers (Node 26 / npm 12+ default allowScripts: false, pnpm, bun) block lifecycle install scripts by default, leaving the stub in place.

Use require.resolve and directory traversal to locate the native binary from optionalDependencies at runtime, and treat postinstall pre-caching as an optional optimization that exits cleanly if blocked.

Fixes anomalyco#48884
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@marwanvx

Copy link
Copy Markdown
Author

Linked issue: #48884 (Closes #48884 is in the PR description).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant