Repository navigation
refactor: use webpack's webpack-sources for source maps instead of @jridgewell/trace-mapping - #767
Conversation
🦋 Changeset detectedLatest commit: 860db71 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #767 +/- ##
==========================================
+ Coverage 97.67% 98.32% +0.64%
==========================================
Files 5 6 +1
Lines 1718 1667 -51
Branches 664 659 -5
==========================================
- Hits 1678 1639 -39
+ Misses 39 27 -12
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Findings
|
…k to webpack-sources
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
645f9a6e-51f8-4754-88e7-fb4bf3369176
Files selected for processing: 6-
src/index.jssrc/minify.jssrc/sources.jstest/sources.test.jstypes/index.d.tstypes/sources.d.ts
Files skipped from review as they are similar to previous changes: 1-
- types/index.d.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
-
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FhutT9pGF4tTqxRZdbiB8
One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via: Supported
Alternatively, if the co-author should not be included, remove the Please update your commit message(s) by doing |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Preserve decoded custom maps in composeSourceMaps. · minify.js:27-44
src/minify.js:27-44
Major · Data Integrity & Integration · Heavy lift Preserve decoded custom maps in
composeSourceMaps.When webpack provides an input source map, the first custom minimizer returns its decoded
mappingsarray andcomposeSourceMapspasses it directly toSourceMapSource.webpack-sources@3.7.0callsmappings.charCodeAt(i), so the first composition throws before the built-in Terser minimizer runs. The asset handler records a compilation error and does not update the asset.Restore the previous
TraceMap-based composition incomposeSourceMaps, or encode decoded mappings before callingSourceMapSource. The correction belongs at this composition boundary, not in the asset error handler.

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8bed4155-d3d9-4a22-92b4-9310a570cccd
Files ignored due to path filters: 1-
package-lock.jsonis excluded by!**/package-lock.json
Files selected for processing: 9-
.changeset/webpack-sources-source-maps.mdREADME.mdpackage.jsonsrc/index.jssrc/sources.jstest/MinimizerPlugin.test.jstest/sources.test.jstypes/index.d.tstypes/sources.d.ts
Files skipped from review as they are similar to previous changes: 1-
- .changeset/webpack-sources-source-maps.md
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.
-
|
Re CodeRabbit's outside-diff finding on Generated by Claude Code |
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5f2a1e00-258a-45ba-b419-9b4660dfd6f2
Files selected for processing: 2-
src/minify.jstest/source-map-chain.test.js
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
-
Summary
Drops
@jridgewell/trace-mappingfromdependencies(it stays a devDependency, so tests still check maps with an independent decoder) and uses webpack's ownwebpack-sourcesinstead, adding no dependency:SourceMapSourcewith an inner source map, which resolves theTODOinsrc/minify.jsand replaces a 290-line hand-written composer and VLQ encoder.buildErroruseutil.sourceMap.originalPositionFor, added in webpack-sources 3.7.0 (feat: add util.sourceMap.originalPositionFor webpack-sources#313, with fix: keep an empty string in sourcesContent webpack-sources#314 keeping""insourcesContent).Which
webpack-sourcesis used. Only webpack's:compiler.webpack.sourcesin the plugin, andrequire("webpack").sourcesin workers, where there is no compiler (src/sources.js).SourceMapSourcewith an inner map exists in everywebpack-sourceswebpack 5 ships.util.sourceMapis new in 3.7.0, so with an older copybuildErrorreports minifier errors at their minified position, as it does without a source map. ATODOmarks dropping that check in the next major release.Composed maps now point each token at its exact original column. On a real build (three entries,
devtool: "source-map"), I checked for every named mapping whether the name sits at the mapped original position:trace-mappingis still installed for users throughterser→@jridgewell/source-map, so the install shrinks only onceterseris no longer a dependency.What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
Yes.
test/source-map-chain.test.jschecks every named mapping against the original source, through 1, 2 and 3 terser steps, terser then uglify-js, and in workers. The existing chain tests only snapshot the map and are skipped on Node < 18 and Windows; this file runs everywhere and fails on the old composer (all 5 cases).test/sources.test.jscoversgetSources(the defaultrequire("webpack")) andgetSourceMapUtilwith 3.7.0 and with older copies (with or withoututil).test/minify-option.test.jscovers a map without mappings passed to the next minimizer.test/MinimizerPlugin.test.js(buildError method) covers an error mapped back to its original file, and one kept at its minified position when webpack'swebpack-sourceshas noutil.sourceMap.28 source-map snapshots changed, and I decoded each one: only
mappingsdiffers. All 791 tests pass against the published webpack-sources 3.7.0.I also built the packed plugin with two chained
terserMinifysteps anddevtool: "source-map", both serially and withparallel: true. Each build had 0 errors, and every named mapping fromsrc/index.js(14) sits at its original position:webpack-sourcesusedpnpMode: strictpnpMode: strictUnder PnP,
require("webpack")resolves in workers becausewebpackis a peer dependency, and the plugin never requireswebpack-sourcesitself.Does this PR introduce a breaking change?
No. The supported range stays
webpack@^5.1.0(verified on 5.1.0 above). With a webpack whosewebpack-sourcespredates 3.7.0, minifier errors show their minified position instead of the original one; source maps themselves are composed either way. Onmain,trace-mappingmapped errors back on any webpack. Current webpack depends onwebpack-sources@^3.5.1, which a fresh install resolves to 3.7.0, so this affects only older webpack releases (5.1.0 depends on^2.0.1) and lockfiles pinned to an older copy. In the types,RawSourceMapis now the map type webpack'sSource#map()returns, so the types need nothing beyondwebpack, and the privatebuildErrortakes a raw map instead of aTraceMap.If relevant, what needs to be documented once your changes are merged or what have you already documented?
The
minifysignature inREADME.mdnow uses thatRawSourceMaptype.Use of AI
Written with Claude Code from my requirements; I reviewed the change, the map-accuracy check and the snapshot diffs.
🤖 Generated with Claude Code
https://claude.ai/code/session_013FhutT9pGF4tTqxRZdbiB8
Summary by CodeRabbit
Bug Fixes
Documentation
minifyFnsource-map type documentation to align with webpack’s types.