fix: Windows build + partial-overlap export dedup#510
Open
BenIsLegit wants to merge 3 commits into
Open
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What broke
npm run buildfails on Windows. Three separate issues, all in the same pipeline: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 oncmd.exe. The single-quote issue is subtle — Windows doesn't strip them, so bun creates files literally named'cli.js'and'server.js'.fix-bun-exports.mjssilently doesn't run on Windows. The CLI entry guard comparedimport.meta.urlagainst`file://${process.argv[1]}`, which fails on Windows becauseimport.meta.urlusesfile:///with forward slashes andprocess.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.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
tokenRefreshchunk 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.jsonscripts — replaced the three Unix commands with cross-platformnode -eone-liners. Re-quoted[name].jswith 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.mjspath handling — switched from theimport.meta.urlstring comparison tofileURLToPath+path.resolve, and fromnew URL().pathname+ string concat topath.resolve+path.join. Added anargv[1]truthiness guard so the module doesn't throwTypeErrorif imported from a context withoutargv[1].Partial-overlap dedup — the loop now has three branches:
Before, only the first case was handled. The second case (the tokenRefresh pattern) was silently skipped.
Tests
All 16
fix-bun-exportstests pass, including 2 new ones:{a, b, c}, subsequent{a, d}→ verify output isexport { d };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 testclean. Build clean.node --checkpasses on all dist entry points.