fix(bundle): rename sourcemap for HTML entrypoints#34901
Merged
Conversation
When bundling an HTML entrypoint with `--sourcemap=external` (or `linked`), the emitted `.js.map` kept the internal virtual-entry name (`<entry>.deno-bundle-html.entry-HASH.js.map`) instead of being renamed to match the JS bundle (`<entry>-HASH.js.map`). In linked mode the JS `//# sourceMappingURL=` comment also pointed at the leaked name. Rename the sourcemap alongside its JS bundle in `patch_html_with_response` and rewrite the `sourceMappingURL` reference so the output no longer leaks the `deno-bundle-html.entry` implementation detail. This is the broken-output case behind the reporter's `sourcemap: 'external'` + HTML config. Refs #30750 Co-Authored-By: Divy Srivastava <[email protected]>
littledivy
approved these changes
Jun 5, 2026
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.
Problem
denoland/deno#30750 reports a
Deno.bundlefailure when bundling an HTML entrypoint whose<script>references a TS module, usingsourcemap: 'external'+platform: 'browser'.While investigating I found a concrete, reproducible defect in exactly that configuration: when bundling an HTML entrypoint with
--sourcemap=external(orlinked), the emitted sourcemap file leaks the internal virtual-entry name instead of matching the JS bundle.Repro (no remote modules needed):
where
index.htmlhas<script src="./index.ts" type="module">.Before:
In
linkedmode the JS//# sourceMappingURL=comment also pointed at the leakedindex.deno-bundle-html.entry-…js.mapname.After:
and the
sourceMappingURLcomment is rewritten toindex-NWUVJ7TJ.js.map.Change
HTML entrypoints are bundled via a virtual module named
<entry>.deno-bundle-html.entry.js; esbuild emits the bundle as<entry>.deno-bundle-html.entry-HASH.jsandpatch_html_with_responserenames it back to the original<entry>-HASH.js. The sibling.js.mapwas never renamed.This patch renames the
.js.mapalongside its JS bundle and, forlinkedsourcemaps, rewrites the JSsourceMappingURLreference to the new name.inlinesourcemaps (embedded data URL) and the no-sourcemap case are unaffected.Tests
Added a
sourcemapcase totests/specs/bundle/html/that bundles with--sourcemap=externaland asserts:deno-bundle-html.entryname,.js.mapis named to match the JS bundle,All existing
bundle::htmlspec tests and thetools::bundle::htmlunit tests pass;cargo clippy -p denois clean.Note on the "channel closed" panic
The literal
channel closedpanic in the issue title surfaces when the bundling worker thread panics (the provider's oneshot is dropped, soop_bundlerejects with theRecvErrormessage). I could not reproduce that panic on currentmain(macOS) — HTML bundling with the reporter's config now completes successfully; the reporter is on Windows. The panic appears to have already been addressed (likely the bundle HTML rewriter refactor in #34408), leaving the sourcemap mis-naming as the remaining reproducible defect in the reporter's exactsourcemap: 'external'+ HTML scenario, which this PR fixes.Closes #30750
Closes denoland/divybot#492