Skip to content

fix(build): bun-on-Windows compatibility for the package.json build script#1480

Open
mikepsinn wants to merge 1 commit into
garrytan:mainfrom
mikepsinn:fix/windows-bun-build-script
Open

fix(build): bun-on-Windows compatibility for the package.json build script#1480
mikepsinn wants to merge 1 commit into
garrytan:mainfrom
mikepsinn:fix/windows-bun-build-script

Conversation

@mikepsinn
Copy link
Copy Markdown

@mikepsinn mikepsinn commented May 13, 2026

Problem

bun run build fails on Windows + Bun 1.3 because three things in the current build script don't parse in bun's POSIX shell on Windows:

  1. Brace-grouped redirect: { git rev-parse HEAD 2>/dev/null || true; } > browse/dist/.version (and two more for design/dist, make-pdf/dist). Bun on Windows treats { as a literal command and errors with bun: command not found: {.
  2. Subshell-grouped redirect: I tried ( ... ) > FILE as a fix — bun errors with Subshells with redirections are currently not supported.
  3. Glob-no-match cleanup: (rm -f .*.bun-build || true) fails BEFORE the || true has a chance to catch the no-match, because bun's glob rejection happens at parse time.

Net effect: ./setup on Windows logs a real-looking build then dies with error: script "build" exited with code 1, leaving .version files unwritten.

Fix

  1. Replace the three brace-grouped git rev-parse HEAD ... > .version constructs with a single node scripts/write-versions.mjs invocation. Same semantics — write the current HEAD SHA into browse/dist/.version, design/dist/.version, make-pdf/dist/.version, with a try/catch fallback when not in a git repo. Cross-platform.
  2. Remove the final (rm -f .*.bun-build || true) cleanup; bun on Windows can't parse it and the build tool already cleans its temp files on success.

scripts/write-versions.mjs uses fileURLToPath(new URL('..', import.meta.url)) (portable to older Node) rather than import.meta.dirname (newer-Node-only).

Verified

  • Windows 11 + Bun 1.3.6 + Node 22: bun run build now completes and produces browse.exe, find-browse.exe, design.exe, pdf.exe, gstack-global-discover.exe, server-node.mjs, and the three .version files (containing the current HEAD SHA).
  • macOS/Linux behavior unchanged — the brace-grouped redirects were just version-stamp writes, which the node helper now does cross-platform.

Notes

  • I'm a new gstack user (installed yesterday on Windows). Hitting this build failure was my first 30 seconds with gstack — figured upstreaming was less hassle for everyone than carrying a local fork.
  • Happy to adjust the patch shape if you'd rather solve this differently (e.g. a scripts/build.sh that runs the brace-grouped writes via bash instead of bun's shell). Tell me what you'd prefer and I'll re-shape.

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Three changes to package.json 'build' script so bun run build completes on
Windows + Bun 1.3 (where bun's shell parser does not accept the POSIX
brace-group + redirect form, the (subshell) + redirect form, or a glob
that matches nothing even with || true):

1. Replace three '{ git rev-parse HEAD 2>/dev/null || true; } > FILE'
   constructs with one 'node scripts/write-versions.mjs' invocation that
   writes browse/dist/.version, design/dist/.version, and
   make-pdf/dist/.version from a single try/catch around 'git rev-parse
   HEAD'. Same semantics, parses on bun-on-Windows.

2. Remove the final '(rm -f .*.bun-build || true)' cleanup. Bun's shell
   errors on the glob no-match BEFORE the '|| true' has a chance to
   catch it, so the cleanup itself blocks the entire build. The build
   tool already cleans temp files on success.

scripts/write-versions.mjs is intentionally Node-version-portable:
uses fileURLToPath(new URL('..', import.meta.url)) rather than
import.meta.dirname, so it works on Node versions before the dirname
property landed.

Verified: 'bun run build' now completes cleanly on Windows 11 + Bun
1.3.6 + Node 22, producing browse/dist/browse.exe, browse/dist/find-
browse.exe, design/dist/design.exe, make-pdf/dist/pdf.exe,
bin/gstack-global-discover.exe, browse/dist/server-node.mjs, and the
three .version files (all containing the current HEAD SHA).

No behavior change on macOS/Linux — the brace-grouped redirects were
just version-stamp writes, which the node helper now does
cross-platform.

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