Skip to content

v1.39.2.0 fix: bun run build crashes on Windows from subshell-with-redirection#1531

Open
scarson wants to merge 2 commits into
garrytan:mainfrom
scarson:fix/bun-windows-build-subshell
Open

v1.39.2.0 fix: bun run build crashes on Windows from subshell-with-redirection#1531
scarson wants to merge 2 commits into
garrytan:mainfrom
scarson:fix/bun-windows-build-subshell

Conversation

@scarson
Copy link
Copy Markdown
Contributor

@scarson scarson commented May 15, 2026

Summary

Fixes #1530.

bun run build crashes on Windows + Git Bash + bun 1.3.13 with:

error: Subshells with redirections are currently not supported.

The current package.json scripts.build contains three ( git rev-parse HEAD 2>/dev/null || true ) > path/.version patterns. Bun's bundled shell on Windows rejects all single-line forms of "swallow stderr, swallow exit code, write stdout to a file" — brace groups, subshells-with-redirect, and dual-redirect commands all fail. The only safe option is to delegate to bash.

The same root cause produced the v1.38.0.0 → v1.39.1.0 ping-pong between brace groups and subshells (CHANGELOG v1.39.1.0 notes the brace-group regression; this PR notes that the v1.39.1.0 fix swapped to a different Bun-shell-hostile pattern). See #1530 for the full RCA and the matrix of Bun shell limitations observed.

Changes

  • scripts/write-versions.sh (new) — bash script that writes git rev-parse HEAD to all three .version files. Mirrors the precedent of browse/scripts/build-node-server.sh. Handles git-missing case cleanly; setup's existing safety net backfills missing .version files at install time, so an empty file is acceptable.
  • package.json scripts.build — replace the three subshell-with-redirect patterns with bash scripts/write-versions.sh. Net result: one shorter command instead of three POSIX-spelled-but-Bun-shell-rejected ones.
  • test/build-script-shell-compat.test.ts — strengthen coverage:
    • Existing no bash brace groups test kept.
    • New no subshell-with-redirection patterns test — catches the v1.39.1.0 regression that this PR fixes.
    • New no command with both stderr-suppress and stdout-redirect test — catches the third Bun-shell-hostile form so future inline rewrites can't sneak it in.
    • Existing must be a subshell test replaced with .version writes are delegated to a bash script — gates on the right property (delegation), not the previously-incorrect property (subshell prefix).

Why a regex test is still useful

The strengthened regex test catches all three currently-observed Bun-shell-hostile patterns and prevents reintroduction. It does not predict future Bun shell limitations. A complementary follow-up would be to execute bun run build (or a parse-only probe) under windows-free-tests.yml — flagged in #1530 as a recommendation but out of scope for this PR.

Test plan

  • bun test test/build-script-shell-compat.test.ts → 4 pass, 0 fail (Windows 11 + bun 1.3.13)
  • bun run build end-to-end on Windows → exit 0; all three .version files contain the correct HEAD SHA
  • ./setup end-to-end on Windows → "gstack ready (claude)."
  • CI: standard Linux pipeline runs against the new test
  • CI: windows-free-tests.yml runs the new test (currently includes test/build-script-shell-compat.test.ts per its existing test-list)

Out of scope

🤖 Generated with Claude Code

Samuel Carson added 2 commits May 15, 2026 15:34
`( git rev-parse HEAD 2>/dev/null || true ) > path/.version` is POSIX-valid
but rejected by Bun's bundled shell on Windows with:

    error: Subshells with redirections are currently not supported.

The same pattern caused the v1.38.0.0 → v1.39.1.0 ping-pong between brace
groups and subshells. Both forms are Bun-Windows-hostile; the third option
(`cmd 2>/dev/null > file` with multiple redirections) is also rejected. The
underlying constraint is that no single-line inline form of "swallow stderr,
swallow exit code, and write stdout to a file" parses under Bun shell on
Windows.

Move the .version writes into `scripts/write-versions.sh`, matching the
existing precedent of `browse/scripts/build-node-server.sh`. The build
script now calls `bash scripts/write-versions.sh` for all three files, and
the bash script handles both git-available and git-missing cases (the setup
script's safety net still backfills missing .version files at install time).

Tests:
- `no bash brace groups` — kept from prior version.
- `no subshell-with-redirection patterns` — new; catches the v1.39.1.0
  regression.
- `no command with both stderr-suppress and stdout-redirect on one line` —
  new; catches the third Bun-shell-hostile form.
- `.version writes are delegated to a bash script (not inline)` — new;
  replaces the prior `must be a subshell` assertion, which gated on the
  wrong property.

Verified end-to-end on Windows 11 + Git Bash + bun 1.3.13: `bun run build`
completes, all three `.version` files contain the correct HEAD SHA.

Reported during gstack global install upgrade from v1.32.0.0 → v1.39.1.0.
…ted by Bun shell)

VERSION bump + CHANGELOG entry for the build-script fix in the previous
commit. Required by the upstream version-gate workflow.
@scarson scarson changed the title fix: bun run build crashes on Windows from subshell-with-redirection v1.39.2.0 fix: bun run build crashes on Windows from subshell-with-redirection May 15, 2026
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.

bun run build crashes on Windows: "Subshells with redirections are currently not supported"

1 participant