Skip to content

Fix Bun Windows build script compatibility#1544

Open
Charlie-El wants to merge 1 commit into
garrytan:mainfrom
Charlie-El:fix/windows-bun-build-shell-compat
Open

Fix Bun Windows build script compatibility#1544
Charlie-El wants to merge 1 commit into
garrytan:mainfrom
Charlie-El:fix/windows-bun-build-shell-compat

Conversation

@Charlie-El
Copy link
Copy Markdown

@Charlie-El Charlie-El commented May 16, 2026

Summary

Fixes Windows setup/build failures with Bun 1.3.x where package scripts containing subshell redirections fail with:

Subshells with redirections are currently not supported

This PR moves the long build pipeline out of package.json and into a Bash script, so Bun no longer has to parse complex shell syntax. It also handles a related Windows issue where bun build --compile can fail when bun.exe is installed under a non-ASCII user path, such as a Windows username containing Chinese characters.

What changed

  • Replaced the long inline package.json build command with bash scripts/build.sh.
  • Added scripts/build.sh to run the full build pipeline under Bash instead of Bun's package-script shell parser.
  • Added scripts/write-version-files.sh to write .version files without ( git ... ) > file.
  • Updated setup so Windows installs can temporarily copy bun.exe to an ASCII-only path for bun build --compile, then clean it up afterward.
  • Updated test/build-script-shell-compat.test.ts to guard against reintroducing subshell redirections in the build script.

Why

On Windows Git Bash with Bun 1.3.x, bun run build failed before compilation with:

error: Failed to run script build due to error Subshells with redirections are currently not supported.

The failing pattern was:

( git rev-parse HEAD 2>/dev/null || true ) > browse/dist/.version

After removing that pattern, I also reproduced a second Windows-specific issue where bun build --compile failed when Bun was installed under a non-ASCII user path:

error: failed to copy bun executable into temporary file: ENOENT
Failed to get temp file path: FileNotFound

Using an ASCII-path temporary Bun copy allowed bun build --compile to complete.

Relationship to related PRs

This overlaps with #1531 on the .version redirection failure, but takes a broader approach:

  1. Moves the full build pipeline into scripts/build.sh, so Bun does not parse the long shell command at all.
  2. Keeps .version writes in a helper script.
  3. Adds a Windows setup workaround for non-ASCII bun.exe paths, which reproduced locally with a Chinese Windows username and bun build --compile.

It is also related to #1480, #1540, and #1460. The main additional coverage here is the non-ASCII Windows user path case plus verified end-to-end setup --host codex behavior.

Test Plan

  • bash -n scripts/build.sh scripts/write-version-files.sh setup
  • bun test test/build-script-shell-compat.test.ts
  • bun run build
  • Manually verified bash ./setup --host codex completes on Windows Git Bash.

Move the long package build pipeline into a bash script so Bun's Windows script parser no longer sees subshell redirections like '( git ... ) > dist/.version'.

Write version files via a dedicated helper and add regression coverage for the shell pattern.

When setup runs on Windows from a non-ASCII bun.exe path, use a temporary ASCII-path bun copy for --compile and clean it up afterward.
@Charlie-El
Copy link
Copy Markdown
Author

This overlaps with #1531 on the .version redirection failure, but it takes a broader approach:

  1. Moves the full build pipeline into scripts/build.sh, so Bun does not parse the long shell command at all.
  2. Keeps .version writes in a helper script.
  3. Adds a Windows setup workaround for non-ASCII bun.exe paths, which reproduced locally with a Chinese Windows username and bun build --compile.

Manual verification on Windows Git Bash:

  • bun run build
  • bash ./setup --host codex

Both completed successfully.

shelman09 pushed a commit to Namleh-Studios/gstack that referenced this pull request May 19, 2026
…s Bun compat (garrytan#1538, garrytan#1537, garrytan#1530, garrytan#1457, garrytan#1561)

Bun's Windows shell parser rejects multiple constructs the inline
package.json build chain used: brace groups `{ cmd; }`, subshells with
redirection `( git ... ) > path/.version`, and (in Bun 1.3.x) subshells
near redirections in general. Every Windows install + every
auto-upgrade since v1.34.2.0 has failed on `bun run build`.

Extracts the build chain to scripts/build.sh and the .version writes to
scripts/write-version-files.sh. POSIX-portable, no Bun shell parsing
involved. Also adds Windows-specific bun.exe handling for non-ASCII
PATHs (a separate Windows footgun where Bun's --compile fails when the
binary lives under a path with non-ASCII chars).

Updates test/build-script-shell-compat.test.ts to assert the new shape:
no subshells with redirections anywhere in the build chain, and build
delegates to scripts/build.sh which delegates .version writes.

Contributed by @Charlie-El via garrytan#1544. Supersedes garrytan#1531 (@scarson, fixed
in build helper), garrytan#1480 (@mikepsinn, partial overlap), garrytan#1460
(@realcarsonterry, brace-group fix subsumed) — credit retained.
Closes garrytan#1538, garrytan#1537, garrytan#1530, garrytan#1457, garrytan#1561.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant