Resolve relative `sources` against source map URL in webpack plugin
`EvalSourceMapDevToolPlugin` is a fork of webpack's plugin that adds `ignoreList` support. When it processes a module whose source map carries relative `sources` entries (e.g. `../../../../src/server/web/adapter.ts` emitted by our SWC compile step), the plugin was absolutizing them via `makePathsAbsolute(compiler.options.context, sourceMapSource.slice(10), compiler.root)`. Per the source-map spec, relative source entries must resolve against the source map's own URL, not the compilation root. As a result, a relative entry pointing four levels up from `.../next/dist/esm/server/web/adapter.js.map` would resolve to something like `/private/var/folders/src/server/web/adapter.ts` instead of `.../next/src/server/web/adapter.ts`. The resulting path contains neither `node_modules` nor `next/dist`, so `shouldIgnorePath` no longer flags the source as ignored, and framework-internal frames leak into user-facing error output. The `adapter.ts` edits in #93070 happened to shift source-map emission enough that webpack started prefixing the module's entry with `webpack://` and thus hitting this branch, which made the existing bug newly visible in `test/development/middleware-errors/index.test.ts`. Framework-frame leakage from the same cause has been observed in other dev-mode stack assertions. CI will indicate whether any test snapshots need follow-up cleanup now that the frames are correctly ignored. The fix recovers the map's location from the module's `//# sourceMappingURL=` trailer (available on the module content passed into the plugin hook) and uses `path.dirname` of that as the base for `makePathsAbsolute`. Inline `data:` maps fall back to `path.dirname(moduleResource)` since the map is embedded in the module source. When the trailer is absent or the module is neither a `NormalModule` nor a `ConcatenatedModule` whose `rootModule` is one, the plugin still uses `compiler.options.context` so the pre-existing behavior for those cases is unchanged. `ConcatenatedModule` is handled heuristically: all constituent sources are resolved against `rootModule.resource`, which can be wrong for a non-root constituent that had its own relative source-map entries. Failed lookups still fall through to `compilation.findModule`, so the worst case matches prior behavior. Preserving the input map's `ignoreList` directly was not viable because `webpack-sources` strips it before the map reaches this plugin (verified empirically: `sourceMap.ignoreList` is `undefined` at the hook's entry). Correct source-path resolution is therefore the only place the ignore-list decision can be restored.
Showing
Please
register
or
sign in
to comment