Describe the bug
The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly:
- When the loader has no input source map, the adapter discards
res.map.
- When both an input map and
res.map exist, the adapter forwards only res.map instead of composing both mapping layers, so mappings from earlier loaders are lost.
As a result, the generated bundle reports incorrect original source locations even though the transform hook returns a valid source map.
Reproduction
https://github.com/SyMind/unplugin-rspack-sourcemap-repro
The reproduction uses unplugin@3.3.0 and @rspack/core@2.2.1. Both cases run an unplugin transform that prepends one generated line and returns the corresponding high-resolution source map. The second case also runs a preceding loader that prepends a line and returns its own source map.
Actual result:
without-input-map: expected source line 1, received line 2
with-input-map: expected source line 1, received line 2
Expected behavior
The map returned by the transform hook should be preserved. The generated statement should trace back to line 1 of src/index.js in both cases, so pnpm repro should succeed.
When an input map is also present, the adapter should compose the transform map with the input map so the complete loader chain is retained.
Root cause
Both webpack-like transform loaders currently use this callback logic:
callback(null, res.code, map == null ? map : (res.map || map))
This explicitly passes a nullish input map when no input map exists, dropping res.map. When both maps exist, it selects one map without composing them.
This is related to #154 and follows up on #561 / #562: exposing inputSourceMap makes manual composition possible, but the adapter output still does not preserve the complete transform chain by default.
A fix with regression tests is available in #615.
Describe the bug
The webpack and Rspack adapters do not preserve source maps returned by a
transformhook correctly:res.map.res.mapexist, the adapter forwards onlyres.mapinstead of composing both mapping layers, so mappings from earlier loaders are lost.As a result, the generated bundle reports incorrect original source locations even though the transform hook returns a valid source map.
Reproduction
https://github.com/SyMind/unplugin-rspack-sourcemap-repro
The reproduction uses
unplugin@3.3.0and@rspack/core@2.2.1. Both cases run an unplugin transform that prepends one generated line and returns the corresponding high-resolution source map. The second case also runs a preceding loader that prepends a line and returns its own source map.Actual result:
Expected behavior
The map returned by the transform hook should be preserved. The generated statement should trace back to line 1 of
src/index.jsin both cases, sopnpm reproshould succeed.When an input map is also present, the adapter should compose the transform map with the input map so the complete loader chain is retained.
Root cause
Both webpack-like transform loaders currently use this callback logic:
This explicitly passes a nullish input map when no input map exists, dropping
res.map. When both maps exist, it selects one map without composing them.This is related to #154 and follows up on #561 / #562: exposing
inputSourceMapmakes manual composition possible, but the adapter output still does not preserve the complete transform chain by default.A fix with regression tests is available in #615.