Repository navigation
Conversation
WalkthroughThis PR fixes Bun issue ChangesShebang
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
|
Updated 2:05 AM PT - Jun 28th, 2026
❌ @robobun, your commit 348b216 has 2 failures in
🧪 To try this PR locally: bunx bun-pr 31391That installs a local version of the PR into your bun-31391 --bun |
|
Found 2 issues this PR may fix:
🤖 Generated with Claude Code |
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
LGTM — thanks for moving the tests into test/cli/install/shebang-normalize.test.ts.
Extended reasoning...
Overview
This PR teaches the Windows .bunx shim's shebang parser to recognize #!/usr/bin/env -S <prog> <args>. The functional change is a single if block (~14 lines) in Shebang::parse in src/install/windows-shim/BinLinkingShim.rs: when the token after /usr/bin/env is exactly -S, skip it, re-capture rest, and re-read the program token. The same logic is mirrored in BinLinkingShim.zig (kept as a porting reference, not compiled). The remainder is tests: 9 Rust unit tests covering the parse surface and 2 integration tests folded into the existing test/cli/install/shebang-normalize.test.ts.
Security risks
None identified. The input is a shebang line read from an installed package's bin file — content that bun install already trusts enough to execute. The change only narrows which token is treated as the interpreter; it does not introduce new spawn paths, shell evaluation, or untrusted-input handling. The -S match is exact (no greedy -* loop), so there's no ambiguity with other env flags.
Level of scrutiny
Moderate-to-low. While this lives in the install path (production-critical), the change is strictly additive: it only fires when the program token is literally -S, a case that was previously 100% broken (the shim tried to spawn -S and failed with "interpreter executable "-S" not found"). All existing working shebangs (env bun, env node, direct paths) take an unchanged code path. The empty-program fallback after -S reuses the existing program.is_empty() → parse_from_bin_path branch, so degenerate inputs are handled.
Other factors
- My earlier nit about test placement (
test/regression/issue/vs.test/cli/install/) was addressed in commit491a74b0. - No CODEOWNERS coverage for the touched files.
- Test coverage is thorough: Rust unit tests exercise
env bun/nodebaselines,-Swith bun/node/python3,-Salone (fallback), multi-space, CRLF, and the/bin/envalias; the JS integration test runs install→execute end-to-end on POSIX and decodes the generated.bunxon Windows to assert the launcher no longer starts with-S. - The harness import was reshaped (
bunEnv as env→bunEnv+const env = bunEnv) to addisPosix/tempDirWithFileswithout breaking the pre-existing CRLF test in the same file. - Three prior community PRs (#27925, #28206, #28595) attempted the same fix against the now-unused
.zigfile, so the approach itself is well-vetted.
|
CI red lanes are the known pre-existing Windows flake tracked by #31382: |
491a74b to
50cfc06
Compare
There was a problem hiding this comment.
LGTM — tight, well-tested fix; the inline note is a test-hygiene nit and not blocking.
Extended reasoning...
Overview
Adds a single conditional to Shebang::parse in src/install/windows-shim/BinLinkingShim.rs (mirrored in the non-shipping BinLinkingShim.zig reference): when the token following /usr/bin/env (or /bin/env) is exactly -S, skip it and re-read the real interpreter token, then proceed unchanged. The empty-program fallback still fires for env -S with nothing after it. The PR also adds 8 Rust unit tests covering bun/node/other interpreters, multi-space, CRLF, /bin/env, and the empty fallback, plus two integration tests in test/cli/install/shebang-normalize.test.ts (cross-platform install+run, and a Windows-only .bunx decoder assertion). My earlier feedback about test placement was addressed — the test was moved out of test/regression/issue/ into the install suite.
Security risks
None. The parser only reshapes a shebang line the package author already wrote into the launcher string of a local .bunx shim; running that bin already implies executing the package's code. No new external input, no auth/crypto/permissions surface.
Level of scrutiny
Low–medium. The runtime change is ~14 lines of straightforward tokenizer logic confined to the /usr/bin/env branch and gated on an exact -S match — pre-existing shebangs without -S are byte-for-byte unaffected. The Zig change is reference-only (not compiled). Unit tests directly assert the parsed launcher and is_node_or_bun for every relevant shape, and the integration test exercises the real install→shim→spawn path.
Other factors
No CODEOWNERS cover these paths. CI is green aside from a known unrelated Windows transpiler flake (#31382). The one outstanding inline finding is a repo-convention nit about draining piped stdout in the new tests — output here is a few hundred bytes vs a ~64KB pipe buffer, so there's no practical deadlock risk; worth tidying but not a merge blocker.
There was a problem hiding this comment.
LGTM — both prior nits addressed; the runtime change is a narrow ~14-line tokenizer skip with thorough unit + integration coverage.
Extended reasoning...
Overview
The PR fixes a Windows-only bun install bug where bin scripts using #!/usr/bin/env -S <prog> <args> produced broken .bunx shims (the shim tried to spawn -S as the interpreter). The runtime change is ~14 lines in Shebang::parse (src/install/windows-shim/BinLinkingShim.rs): if the token after /usr/bin/env is exactly -S, skip it and re-read the real program token. The non-compiled BinLinkingShim.zig reference is updated in lockstep, and the rest of the diff is tests — 8 Rust unit tests on the parser plus 2 integration tests in test/cli/install/shebang-normalize.test.ts (cross-platform install+run, and a Windows-only .bunx decoder check).
Security risks
None identified. The parser already takes arbitrary shebang content from package bin files and encodes it as the shim launcher; this change only re-tokenizes when the first arg is the literal -S. The failure mode of any parse mistake here is a non-functional shim, not elevated execution — the launcher string was already attacker-controlled (via the package's own bin file) before this change.
Level of scrutiny
Low-to-moderate. The logic change is mechanical and mirrors the existing tokenizer pattern (skip spaces → read token) exactly, using the same eql_comptime helper as the surrounding code. The -S handling is deliberately narrow (no greedy -* loop) to avoid the -u VAR / -C DIR arg-ambiguity the PR description calls out. Edge cases (empty after -S, multi-space, CRLF, /bin/env alias) are each pinned by a unit test.
Other factors
I left two organizational nits on earlier revisions (test-placement convention, undrained piped stdout/stderr) — both were addressed in 491a74b and 4186568 respectively, and the current diff reflects those fixes. No CODEOWNERS cover these paths. The only red CI lane noted in the thread is the pre-existing Windows transpiler flake tracked separately. Three prior community PRs targeted the same bug but only edited the now-uncompiled .zig file; this PR correctly patches the live .rs implementation and supersedes them.
|
CI note: build 61245's only test failure was |
There was a problem hiding this comment.
LGTM — narrow, well-tested parser fix; both prior nits addressed, and the remaining -S<prog> joined-form note is a non-blocking follow-up.
Extended reasoning...
Overview
This PR teaches the Windows .bunx shim's shebang parser to recognize #!/usr/bin/env -S <prog> <args> so the encoded launcher is <prog> <args> instead of the literal -S ... (which fails at spawn time). The actual logic change is ~14 lines in src/install/windows-shim/BinLinkingShim.rs (plus a mirrored ~6 lines in the reference-only BinLinkingShim.zig), gated entirely on program == b"-S" inside the existing /usr/bin/env branch — every other input path is byte-for-byte unchanged. Nine new Rust unit tests pin the parse surface (bun/node/other interpreters, multi-space, CRLF, /bin/env, -S alone → bin-path fallback), and two integration tests in test/cli/install/shebang-normalize.test.ts exercise install+run end-to-end and decode the generated .bunx on Windows.
Security risks
None identified. The parser reads a package bin's first line to decide which launcher string to embed in a local shim file; it does not execute the shebang content, expand variables, or touch network/auth/permissions. The change only narrows what was previously a guaranteed failure ("interpreter executable -S not found") into the correct launcher; it cannot cause a previously-working shebang to resolve to a different program.
Level of scrutiny
Low-to-moderate. The diff is small, mechanical, and additive within an existing well-understood tokenizer. The fallback when -S is the last token reuses the pre-existing program.is_empty() → parse_from_bin_path path, so no new edge-case handling was invented. The Zig file is documented as a non-shipping porting reference, so divergence risk is nil. Test coverage is unusually thorough for a change this size.
Other factors
Both of my earlier inline nits (test-file placement, undrained piped stdout/stderr) were addressed in 491a74b and 4186568 respectively and are now resolved. The one new inline comment from this run — the joined short-option form -Sbun — is explicitly a nit: it's valid env syntax but not used by any of the three linked issues or named packages, was never supported, and the PR is a strict improvement without it. CI red lanes are documented pre-existing flakes (#31382 transpiler stack overflow; bunx.test.ts Angular engines bump) unrelated to the env -S branch. No CODEOWNERS cover these paths.
There was a problem hiding this comment.
LGTM — narrow, additive parser fix with thorough unit + integration coverage; all prior review feedback addressed.
Extended reasoning...
Overview
This PR fixes Windows .bunx shim generation for package bins that use #!/usr/bin/env -S <prog> <args> shebangs. The change touches three files: src/install/windows-shim/BinLinkingShim.rs (~15 lines of parser logic + ~115 lines of unit tests), src/install/windows-shim/BinLinkingShim.zig (mirror change in the non-compiled porting reference), and test/cli/install/shebang-normalize.test.ts (~130 lines of integration tests including a .bunx binary decoder). The core change is a single if/else if block inside the existing /usr/bin/env branch of Shebang::parse that skips a -S token (or strips a joined -Sxxx prefix) before reading the interpreter name.
Security risks
None identified. The parser reads shebang lines from installed package bin files — the same trust boundary as executing the package's code itself. The change does not introduce new process-spawning surface; it only changes which token is treated as the interpreter name in a case that previously failed outright. No injection, auth, or data-exposure surface.
Level of scrutiny
Moderate-to-low. While bun install bin-linking is a production-critical path on Windows, this change is strictly additive: the new branch only fires when the post-env token is exactly -S or starts with -S — inputs that previously produced broken shims (interpreter executable "-S" not found). All other shebang shapes flow through unchanged code. There is no realistic regression vector for currently-working installs. The logic is a straightforward re-application of the same tokenizer pattern already used three lines above.
Other factors
- Test coverage is strong: 11 Rust unit tests covering plain
env,-Swith bun/node/python3,-Salone (fallback), multi-space, CRLF,/bin/env, and both joined-form variants; plus a cross-platform end-to-end install+run test and a Windows-only test that decodes the generated.bunxand asserts the launcher field. - All prior review feedback addressed across three rounds: test moved out of
test/regression/issue/per repo convention, subprocess pipes properly drained per CLAUDE.md, and the joined-Sbunform added with tests. - No CODEOWNERS for the touched paths.
- CI green per the author's notes; the two red lanes are documented pre-existing flakes (#31382 transpiler stack overflow, and an unrelated
bunx.test.tsengines-version failure against the live npm registry). - Three prior community PRs (#27925, #28206, #28595) attempted this same fix but edited only the no-longer-compiled
.zigfile; this PR correctly targets the.rsimplementation and supersedes them.
|
Build 61252: same unrelated failure, different lane. |
…ang parser Fixes #31387. `Shebang::parse` in src/install/windows-shim/BinLinkingShim.rs drives the Windows `.bunx` shim generator. For a bin whose shebang is `#!/usr/bin/env -S <prog> <args>` (as in `ocx@2.0.11`: `#!/usr/bin/env -S bun --no-env-file`) the parser consumed `/usr/bin/env` and then treated `-S` as the interpreter program, so the encoded launcher became `-S bun --no-env-file` and `bun_shim_impl.exe` greeted users with: error: interpreter executable "-S" not found in %PATH% `-S` / `--split-string` is a documented `env(1)` flag: it forwards everything after it as separate args to the real interpreter, which is the standard way to pass flags through a shebang on Linux/BSD. Recognize and skip it so the real interpreter token (`bun`, `node`, ...) becomes the program and the rest stays as the launcher args. BinLinkingShim.zig is kept in sync as a porting reference.
…st.ts `test/regression/issue/` is reserved for true regressions (worked in a previous release, then broke). `env -S` handling never worked in any prior release — the Zig spec was already wrong — so this is a never-worked bug, not a regression. Fold the tests into the existing file that already covers bin-linking shebang behavior.
…arser GNU/BSD env accept the joined short-option spelling -SSTRING, so prefix from the same token; the optarg is unambiguous, no lookahead.
9d990c0 to
221eea7
Compare
|
Rebased onto main (221eea7). Conflict resolution: main removed the |
There was a problem hiding this comment.
All my earlier nits are addressed and I have nothing further — the parser change is small and well-tested, but since it sits in the Windows bun install shim encoder it's worth a quick maintainer glance before merge.
Extended reasoning...
Overview
Two files: a ~19-line additive branch in Shebang::parse (src/install/windows-shim/BinLinkingShim.rs) that skips the env -S / -Sbun token so the real interpreter becomes the launcher, plus 11 Rust unit tests and ~126 lines of integration test in test/cli/install/shebang-normalize.test.ts. Fixes three open issues (#31387, #22422, #27924). The .zig mirror was dropped during rebase since main removed it.
Security risks
None identified. Input is the first line of a package bin file; the change only skips a token inside an existing branch and reuses the same tokenizer loops verbatim. No new execution surface, no auth/crypto/permissions, and the program.is_empty() fallback to parse_from_bin_path is preserved. Shebangs without -S after env are byte-for-byte unaffected.
Level of scrutiny
Moderate. The logic is small, additive, and pattern-matches the surrounding code, but it lives in the Windows .bunx shim encoder — every bun install on Windows that links a bin runs through here, so a regression would be wide-blast-radius. The integration test also hand-decodes the .bunx binary format, which a maintainer familiar with the encoder layout should sanity-check.
Other factors
I've reviewed this PR across four rounds; every nit (test placement, pipe draining, joined -S form, env alias, comment length) was addressed and all inline threads are resolved. The bug-hunting pass found nothing this run. No CODEOWNERS match. CI red is documented by the author as pre-existing unrelated flakes (#31382 transpiler stack overflow; bunx.test.ts Angular engines floor) — a human should confirm that before merge, which is the main reason I'm deferring rather than approving.
The env -S fix lives in Windows-only shim code that never runs on POSIX, so the Linux test lane couldn't exercise it. Expose Shebang::parse through bun:internal-for-testing and drive it directly, covering both the spaced and joined -S forms across all platforms.
The end-to-end `bun run` case relied on the host /usr/bin/env supporting -S, which alpine's BusyBox env does not, so the bin never ran and the test failed on musl lanes. It also only exercised the OS's env on POSIX, not the shim parser the fix touches. The parseBinShebang cases (portable) and the Windows .bunx decode test already cover the fix.
|
CI status (build 66065): both red lanes are unrelated flakes, not this diff.
This diff only changes the Windows install-shim shebang parser ( |
|
Stale PR review: keep open, rework. The fix is still needed. On main, The current diff is not the shape to merge:
The wanted shape is two files, like #28206 (c75e86f). That PR was closed only because it edited Zig files that the Rust rewrite removed.
|
|
This is Claude (an AI assistant) writing on Jarred's behalf. Included in #44968: Windows only. |
Fixes #31387
Fixes #22422
Fixes #27924
Problem
Installing a package whose bin uses
#!/usr/bin/env -S <prog> <args>on Windows produces a broken.bunxshim. Forocx@2.0.11(#!/usr/bin/env -S bun --no-env-file) the shim launches with:Root cause
Shebang::parseinsrc/install/windows-shim/BinLinkingShim.rstokenizes the shebang. After consuming/usr/bin/envit reads the next token as the interpreter program — but for-Sshebangs that token is literally-S, so the encoded launcher becomes-S bun --no-env-fileand the shim tries to spawn-Sat runtime.env -S/--split-stringis the documented way to forward flags to the real interpreter from a shebang on Linux/BSD (because the kernel collapses everything after the first space into a single arg). Node uses it, Bun-built CLIs likeocxuse it, many tools use it.Fix
In the
/usr/bin/env//bin/envbranch ofShebang::parse, if the next token is-S, skip it and re-read the real program token. The remainder of the line stays as the launcher args, so flags like--no-env-filestill reach Bun.It also handles the joined short-option form
-Sbun(envaccepts-SSTRINGas-S STRING). The-u VAR/-C DIRambiguity where subsequent tokens are flag arguments is deliberately out of scope.Verification
cargo check --workspace --target x86_64-pc-windows-msvccompiles cleanly (viabun run rust:check-all).BinLinkingShim.rscover the parse surface:env bun,env node,env -S bun --no-env-file,env -S node --experimental-vm-modules,env -S python3 -u,env -Salone, joined-Sbun/-Snode, multi-space variants, CRLF,/bin/envalias.test/cli/install/shebang-normalize.test.tsdrivesShebang::parsedirectly on all platforms via abun:internal-for-testingbinding (parseBinShebang) for the spaced and joined-Sforms, and on Windows installs a package and decodes the generated.bunxto verify the encoded launcher isbun --no-env-file, not-S bun .... The shim parser only runs on Windows at install time, so the binding is how the Linux lanes exercise it.Prior PRs
#27925 and #28595 target this same bug but only edit
BinLinkingShim.zig— which is no longer compiled (the runtime isBinLinkingShim.rsnow). Both are effectively no-ops against currentmain. This PR supersedes them.