Skip to content

fix: Windows build + partial-overlap export dedup#510

Open
BenIsLegit wants to merge 3 commits into
rynfar:mainfrom
BenIsLegit:fix/windows-build-and-export-dedup
Open

fix: Windows build + partial-overlap export dedup#510
BenIsLegit wants to merge 3 commits into
rynfar:mainfrom
BenIsLegit:fix/windows-build-and-export-dedup

Conversation

@BenIsLegit
Copy link
Copy Markdown

What broke

npm run build fails on Windows. Three separate issues, all in the same pipeline:

  1. Unix-only shell commands in package.json. rm -rf dist, test -f, and the single-quoted '[name].js' all work fine on Linux/macOS but blow up on cmd.exe. The single-quote issue is subtle — Windows doesn't strip them, so bun creates files literally named 'cli.js' and 'server.js'.

  2. fix-bun-exports.mjs silently doesn't run on Windows. The CLI entry guard compared import.meta.url against `file://${process.argv[1]}`, which fails on Windows because import.meta.url uses file:/// with forward slashes and process.argv[1] uses backslashes. The script loads, does nothing, exits. No error. Meanwhile the duplicate-export bugs it's supposed to fix stay in the built output.

  3. Partial-overlap export blocks survive the dedup. Even once the script actually runs, it only removes subsequent export blocks where every symbol is already in the canonical block. The tokenRefresh chunk has a block mixing 5 duplicates with 2 novel symbols (withClaudeLogContext, claudeLog) — the script sees the novel symbols, decides the block isn't a pure subset, and skips it. Runtime: SyntaxError: Duplicate export of 'stopBackgroundRefresh'.

Fix

package.json scripts — replaced the three Unix commands with cross-platform node -e one-liners. Re-quoted [name].js with escaped double quotes (\"[name].js\") so the shell doesn't glob-expand [name] on Linux (it's a character class matching one of n/a/m/e).

fix-bun-exports.mjs path handling — switched from the import.meta.url string comparison to fileURLToPath + path.resolve, and from new URL().pathname + string concat to path.resolve + path.join. Added an argv[1] truthiness guard so the module doesn't throw TypeError if imported from a context without argv[1].

Partial-overlap dedup — the loop now has three branches:

Subsequent block Action
All symbols already in canonical Remove the block
Mix of novel + duplicate symbols Rewrite to keep only the novel ones
All symbols are novel Leave it alone, add symbols to the canonical set

Before, only the first case was handled. The second case (the tokenRefresh pattern) was silently skipped.

Tests

All 16 fix-bun-exports tests pass, including 2 new ones:

  • Partial overlap: canonical {a, b, c}, subsequent {a, d} → verify output is export { d };
  • TokenRefresh pattern: large canonical block, subsequent block with novel + duplicate symbols → verify duplicates are stripped

Updated the existing "keeps a subsequent block" test — the old assertion and comment described pre-change behavior (leave both blocks intact). Now asserts the second block is rewritten to only contain novel symbols.

Full suite: bun test clean. Build clean. node --check passes on all dist entry points.

Ben added 3 commits May 12, 2026 16:04
Three issues prevented `npm run build` on Windows:

1. `rm -rf dist` - not available on Windows cmd.exe. Replaced with Node.js fs.rmSync.

2. `--entry-naming '[name].js'` - single quotes aren't stripped by cmd.exe, causing bun to create files with literal quotes in filenames. Removed the quotes.

3. `test -f` in postbuild - Unix-only. Replaced with Node.js fs.existsSync.

4. fix-bun-exports.mjs used `import.meta.url === file://` comparison that fails on Windows (different path separators and file:/// scheme). Switched to fileURLToPath + resolve for robust path comparison and construction.
The fix-bun-exports script only removed subsequent export blocks where ALL symbols were already in the canonical block. When a block had a mix of novel and duplicate symbols (e.g. tokenRefresh chunk), it was left untouched, causing a SyntaxError: Duplicate export at runtime.

Now rewrites partial-overlap blocks to keep only the novel symbols.
- Re-quote [name].js with double quotes to prevent shell glob expansion on Linux (the unquoted form is a character class matching n/a/m/e)

- Guard resolve(process.argv[1]) against undefined to avoid TypeError when the module is imported from unusual contexts

- Update stale test name/assertions and add dedicated test for partial-overlap dedup (the tokenRefresh pattern that motivated the prior commit)
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