Skip to content

install(windows-shim): handle env -S in bin shebang parser - #31391

Closed
robobun wants to merge 15 commits into
mainfrom
farm/91f51e30/windows-shim-env-dash-s
Closed

robobun wants to merge 15 commits into
mainfrom
farm/91f51e30/windows-shim-env-dash-s

Conversation

@robobun

@robobun robobun commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #31387
Fixes #22422
Fixes #27924

Problem

Installing a package whose bin uses #!/usr/bin/env -S <prog> <args> on Windows produces a broken .bunx shim. For ocx@2.0.11 (#!/usr/bin/env -S bun --no-env-file) the shim launches with:

error: interpreter executable "-S" not found in %PATH%

Bun failed to remap this bin to its proper location within node_modules.

Root cause

Shebang::parse in src/install/windows-shim/BinLinkingShim.rs tokenizes the shebang. After consuming /usr/bin/env it reads the next token as the interpreter program — but for -S shebangs that token is literally -S, so the encoded launcher becomes -S bun --no-env-file and the shim tries to spawn -S at runtime.

env -S / --split-string is 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 like ocx use it, many tools use it.

Fix

In the /usr/bin/env / /bin/env branch of Shebang::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-file still reach Bun.

It also handles the joined short-option form -Sbun (env accepts -SSTRING as -S STRING). The -u VAR / -C DIR ambiguity where subsequent tokens are flag arguments is deliberately out of scope.

Verification

  • cargo check --workspace --target x86_64-pc-windows-msvc compiles cleanly (via bun run rust:check-all).
  • Rust unit tests in BinLinkingShim.rs cover the parse surface: env bun, env node, env -S bun --no-env-file, env -S node --experimental-vm-modules, env -S python3 -u, env -S alone, joined -Sbun/-Snode, multi-space variants, CRLF, /bin/env alias.
  • test/cli/install/shebang-normalize.test.ts drives Shebang::parse directly on all platforms via a bun:internal-for-testing binding (parseBinShebang) for the spaced and joined -S forms, and on Windows installs a package and decodes the generated .bunx to verify the encoded launcher is bun --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 is BinLinkingShim.rs now). Both are effectively no-ops against current main. This PR supersedes them.

@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR fixes Bun issue #31387 by updating Windows shim shebang parsers to recognize the env -S flag. When a package bin uses #!/usr/bin/env -S <prog> <args>, the parser now skips -S and treats the following token as the actual launcher instead of failing with "interpreter executable -S not found" errors. Changes span Rust and Zig implementations with unit and regression tests.

Changes

Shebang -S flag recognition across platforms

Layer / File(s) Summary
Rust shebang parser -S flag handling
src/install/windows-shim/BinLinkingShim.rs
Updated Shebang::parse to detect -S as the first token after env, skip it and whitespace, and use the subsequent token as the launcher. Added unit tests covering basic env detection, -S stripping for multiple interpreters, fallback when no program follows -S, and edge cases with multiple spaces, CRLF, and /bin/env variants.
Zig shebang parser -S flag handling
src/install/windows-shim/BinLinkingShim.zig
Implemented equivalent logic in Zig's Shebang.parse to recognize and skip the -S flag in env-style shebangs, advancing the tokenizer so the subsequent token becomes the launcher/program.
Regression test suite for issue #31387
test/regression/issue/31387.test.ts
Comprehensive test coverage including fixture setup with a package bin using #!/usr/bin/env -S bun --no-env-file, cross-platform integration test running bun install and validating bin execution, binary .bunx shim decoder, and Windows-only verification that the extracted launcher does not start with -S and matches the expected program and arguments.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: handling the env -S flag in the Windows shim bin shebang parser.
Linked Issues check ✅ Passed The PR directly fixes all objectives from #31387: handles env -S shebangs, enables proper bin installation on Windows, and restores correct interpreter invocation with preserved flags.
Out of Scope Changes check ✅ Passed All changes (Rust parser update, Zig reference update, unit tests, and regression test) are scoped to fixing the env -S shebang parsing issue per #31387.
Description check ✅ Passed The PR description includes the purpose and verification details, even though it uses custom headings instead of the template.

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 2:05 AM PT - Jun 28th, 2026

❌ @robobun, your commit 348b216 has 2 failures in Build #66065 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31391

That installs a local version of the PR into your bun-31391 executable, so you can run:

bun-31391 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 2 issues this PR may fix:

  1. Failed to remap bin to proper location for github dependency #22422 - Reports error: interpreter executable "-S" not found in %PATH% when installing a GitHub dependency (quartz) whose bin script uses #!/usr/bin/env -S
  2. Globally installed CLIs are not working on my system #27924 - Same -S interpreter error when running globally installed CLIs (e.g. @google/gemini-cli) that use #!/usr/bin/env -S node

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #22422
Fixes #27924

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. fix(install): skip env flags like -S when parsing shebangs on Windows #27925 - Also fixes env -S shebang parsing in Windows shims (edits only the .zig file, which is no longer compiled)
  2. fix(install): skip env flags in Windows shebang parser #28206 - Also skips env flags in Windows shebang parser (edits only the .zig file, which is no longer compiled)
  3. Skip env flags (-S, --split-string) in Windows shebang parser #28595 - Also handles -S/--split-string in shebang parsing (edits only the .zig file, which is no longer compiled)

🤖 Generated with Claude Code

Comment thread test/regression/issue/31387.test.ts Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 commit 491a74b0.
  • No CODEOWNERS coverage for the touched files.
  • Test coverage is thorough: Rust unit tests exercise env bun/node baselines, -S with bun/node/python3, -S alone (fallback), multi-space, CRLF, and the /bin/env alias; the JS integration test runs install→execute end-to-end on POSIX and decodes the generated .bunx on Windows to assert the launcher no longer starts with -S.
  • The harness import was reshaped (bunEnv as env → bunEnv + const env = bunEnv) to add isPosix/tempDirWithFiles without 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 .zig file, so the approach itself is well-vetted.

@robobun

robobun commented May 25, 2026

Copy link
Copy Markdown
Collaborator Author

CI red lanes are the known pre-existing Windows flake tracked by #31382: Bun.Transpiler.transform{,Sync} stack overflows in test/bundler/transpiler/transpiler.test.js, same two tests that have been failing on every Windows 2019 build since #31333 merged — unrelated to the shim shebang parser this PR touches. Every other lane is green. Skipping the ci: retrigger since the flake is deterministic. Needs a maintainer to merge.

@robobun
robobun force-pushed the farm/91f51e30/windows-shim-env-dash-s branch from 491a74b to 50cfc06 Compare June 7, 2026 05:42

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@robobun

robobun commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI note: build 61245's only test failure was bunx.test.ts "should handle package that requires node 24" (exit 3, 4/4 retries on one Windows runner). That test runs bun x --bun @angular/cli@latest --help against the live registry; @angular/cli@22.0.0 (published 2026-06-03) raised engines to ^22.22.3 || ^24.15.0 || >=26.0.0 and Bun reports process.version v24.3.0, which fails ^24.15.0. Unrelated to this PR (the ng bin is a plain env node shebang, and this diff only changes the env -S branch). Affects any runner with a cold bunx cache; fixing it means bumping REPORTED_NODEJS_VERSION or pinning the test's package version. Used the one retrigger.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, -S with bun/node/python3, -S alone (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 .bunx and 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 -Sbun form 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.ts engines-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 .zig file; this PR correctly targets the .rs implementation and supersedes them.

@robobun

robobun commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator Author

Build 61252: same unrelated failure, different lane. bunx.test.ts "should handle package that requires node 24" failed on debian-13-x64-asan (exit 3, 4 retries) — the @angular/cli@latest engines floor again (^24.15.0 vs Bun's reported v24.3.0), hits any lane with a cold bunx cache. Every test touched by this PR passes on all lanes. Retrigger already used; this needs either a maintainer merge or a separate fix to bump REPORTED_NODEJS_VERSION / pin that test's package version.

robobun and others added 6 commits June 27, 2026 23:35
…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.
@robobun
robobun force-pushed the farm/91f51e30/windows-shim-env-dash-s branch from 9d990c0 to 221eea7 Compare June 27, 2026 23:47
@robobun

robobun commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (221eea7). Conflict resolution: main removed the .zig porting-reference files (including src/install/windows-shim/BinLinkingShim.zig), which my commits had edited in lockstep. Dropped those .zig edits and kept the live .rs implementation — both the spaced (-S bun) and joined (-Sbun) forms are intact in BinLinkingShim.rs, and the unit + integration tests are unchanged. cargo check and bun bd test test/cli/install/shebang-normalize.test.ts pass locally.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

robobun and others added 3 commits June 28, 2026 00:43
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.
robobun added 2 commits June 28, 2026 01:41
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.
@robobun

robobun commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

CI status (build 66065): both red lanes are unrelated flakes, not this diff.

This diff only changes the Windows install-shim shebang parser (BinLinkingShim.rs) plus its bun:internal-for-testing binding and tests; every test it touches passes on all lanes. The one ci: retrigger allowance was already used earlier (738cc31), so I'm not pushing another. Ready for a maintainer to merge once the unrelated flakes clear.

@robobun

robobun commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Stale PR review: keep open, rework.

The fix is still needed. On main, Shebang::parse (src/install/windows-shim/BinLinkingShim.rs:315-333) takes the token after /usr/bin/env as the interpreter. A bin with a #!/usr/bin/env -S node ... shebang then fails on Windows with interpreter executable "-S" not found in %PATH%. #22422 is open, and #27924 and #31387 are closed as duplicates of it. I found no other open PR for this bug.

The current diff is not the shape to merge:

  • It conflicts with main. Only the Shebang::parse hunk (22 added lines) is the fix. The other added lines are test plumbing.
  • The parseBinShebang testing binding calls the shim encoder on every platform. Since Narrow crate-internal Rust visibility across all targets and delete the code it proves dead #36184 (77ab49c), the module is #[cfg(windows)] (src/install/lib.rs:235) and Shebang::parse is pub(crate) (BinLinkingShim.rs:272). The binding needs both reverted, only for a test.
  • No CI job runs the 11 Rust #[cfg(test)] unit tests. The only cargo test job on main is for lol-html (.github/workflows/rust-lints.yml:93-113).
  • The Windows test uses tempDirWithFiles and expect(installStderr).not.toContain("error"). CLAUDE.md asks for tempDir and does not allow that kind of assertion.

The wanted shape is two files, like #28206 (c75e86f). That PR was closed only because it edited Zig files that the Rust rewrite removed.

  1. The Shebang::parse change in BinLinkingShim.rs: skip a standalone -S, strip a joined -S<prog> prefix, and also skip NAME=VALUE tokens. npm's cmd-shim handles -S and NAME=VALUE (lib/index.js:24, fix: drop the -S flag from env npm/cmd-shim#96). This PR does not handle NAME=VALUE.
  2. One Windows-only test in test/cli/install/shebang-normalize.test.ts that installs a file: package and decodes the .bunx shim. The existing test at lines 71-103 of that file on main shows the pattern.

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

This is Claude (an AI assistant) writing on Jarred's behalf.

Included in #44968: Windows only.

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

Labels

Projects

None yet

2 participants