cli: handle -v/--version in the node argv0 shim - #36128
Conversation
When bun is invoked as 'node' (via the /tmp/bun-node-<rev>/node symlink that 'bun run' puts on PATH), 'node -v' and 'node --version' now print 'v<process.version>' and exit 0, matching Node.js. Previously RunAsNodeCommand used RUN_TABLE, which has no -v/--version entry: '--version' was silently dropped (empty positionals -> 'Missing script to execute'), and '-v' hit clap's short-flag chainer which hard-errors on unknown shorts. This broke engine-version preflights (node-gyp, prepare/postinstall scripts) on machines without a real node installed. The flag is only honoured before the first positional or '--', so 'node app.js --version' still passes '--version' through to the script.
|
Updated 12:04 PM PT - Jul 27th, 2026
❌ @robobun, your commit fea90e2 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 36128That installs a local version of the PR into your bun-36128 --bun |
WalkthroughChangesThe node-mode CLI handles leading Node version flag handling
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/cli/mod.rs`:
- Around line 1532-1537: Update the argument scan around bun::argv() so
value-taking Node options, including --require, consume their following token
before classifying positional arguments. Preserve handling of --version and --,
continue scanning to process later flags such as --version, and add a regression
test for --require preload.js --version.
In `@test/cli/run/as-node.test.ts`:
- Around line 90-121: Extend the “node script.js --version passes the flag
through to the script” test around fakeNodeRun to cover the explicit -- option
terminator: invoke node with --, index.js, and each of --version and -v, and
assert the script receives the corresponding flag in process.argv.slice(2).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3ce58083-0249-4a58-9a32-c410a21ef572
📒 Files selected for processing (2)
src/runtime/cli/mod.rstest/cli/run/as-node.test.ts
|
CI status for fea90e2: The failures in build 83498 are all darwin-only and unrelated to this CLI argv change:
This diff only touches |
What
node -vandnode --versionnow printv<process.version>and exit 0 when bun is invoked through itsnodeargv0 shim (the/tmp/bun-node-<rev>/nodesymlink thatbun run/--bunput onPATH).Repro
With no real
nodeonPATH:Before:
After:
Cause
RunAsNodeCommandparses argv withRUN_TABLE, which has no-v/--versionentry (those live inAUTO_ONLY_PARAMS). So:--versionwas an unknown long flag, silently dropped (node-mode clearsWARN_ON_UNRECOGNIZED_FLAG), leavingctx.positionalsempty and hittingexec_as_if_node_missing_script()→error: Missing script to execute(rc 1).-vwas an unknown short flag, which clap's short-flag chainer hard-rejects (streaming.rs::chainging) →error: Invalid Argument '-v'plus the fullbun runusage screen (rc 1).This broke engine-version preflights (
node --versionin prepare/postinstall/CI scripts, node-gyp's version probe) on machines without a realnodeinstalled, whilenode -e/-p/file.jsthrough the same shim worked fine.Fix
Scan argv in
exec_run_as_nodebeforeinit()runs clap: if-v/--versionappears before the first positional (or--), printv<REPORTED_NODEJS_VERSION>\nand exit 0.node app.js --versionis unaffected; the flag still reaches the script.Tests
Added to
test/cli/run/as-node.test.ts:node -v/node --versionprintprocess.versionwith exit 0node -e 'console.log(process.version)'node script.js --versionstill passes--versionthrough to the script[review] gate passed · iteration 0 · 2 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 0
evidence per changed file