Repository navigation
fix(build): shift index.js's source map past the bootstrap banner - #27336
outof-place wants to merge 1 commit into
Conversation
createMainBootstrapPlugin prepends the fatal-exit guard and startup diagnostics banner (205 lines) to index.js in generateBundle, after Rolldown has already emitted index.js.map. The map kept describing the code without the banner, so every position in index.js decoded 205 lines too early, and the last 205 lines decoded to nothing. Crash traces symbolicated through the uploaded map named the wrong source. prependChunkBanner() now prepends the banner and adds one empty line per banner line to the start of the .map asset's mappings. A banner that ends mid-line throws, since it would shift columns too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The reviewed change is mergeable after normal checks. Source-map shifting for byte-backed assets remains unverified, but no failure in the supported build was established. Pre-merge checks |
|
|
Thanks so much @outof-place for tracking down the misaligned index.js source map! We couldn't push to your branch, so we've continued this in #33899, which keeps your diagnosis and switches the fix to Rolldown's native |
ELI5
A source map tells a debugger which line of our TypeScript each line of the built
index.jscame from. After the build writesindex.jsand its map, one build step adds 205 lines of start-up guard code to the top ofindex.js. The map was never told. So every line it describes is 205 lines off, and a crash in main gets traced back to the wrong source line, or to nothing. This PR moves the map down by the same 205 lines when the banner goes in.What Changed
Before:
createMainBootstrapPlugindidmainChunk.code = banner + mainChunk.codeingenerateBundle. By then Rolldown has already emittedindex.js.mapas its own asset, so the map still describedindex.jswithout the banner:After: the plugin calls
prependChunkBanner(bundle, chunk, banner)(config/build-plugins/prepend-chunk-banner.ts). It prepends the banner and puts one empty line (;) per banner line at the start of the.mapasset'smappings. Every segment moves down to the line its code now sits on. Nothing changes at runtime: index.js is byte-identical.Why
generateBundle. Moving it torenderChunkoroutput.bannerwould change where it lands relative to that prelude. Fixing the map leaves that ordering exactly as it is.Linked Issue
None. Found while decoding main-process profiles.
Visual Proof
N/A: build output only.
Testing
config/scripts/prepend-chunk-banner.test.ts:Built
pnpm run build:electron-vitebefore and after this change, and decoded two string literals' positions inout/main/index.jsthroughindex.js.map:'journal_item_resolved_to_nothing'decodes tojournal-item-appender.ts:11, and'Refusing to start E2E outside its disposable home boundary'toconfigure-process.ts:204. Both are the lines that hold them.oxlinton the changed files,tsc -p config/tsconfig.node.jsonandpnpm run check:code-quality:changedpass. Fullpnpm test,pnpm lintandpnpm buildwere left to CI.I manually tested these changes locally (not done: only the builds, the map decode and the checks above ran)
Automated tests added/updated, or explained why not below
AI Disclosure
Implemented with Claude Opus 5.5 via Claude Code: investigation, code, tests and the map check. A human (outof-place) directed the work.
Review
prependChunkBannerinconfig/build-plugins/prepend-chunk-banner.ts.electron.vite.config.ts.Agent skill upstream boundary
Trade-offs
generateBundlebanner can use the same helper.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code