Chain the input source map in the RUM privacy plugin on rspack and webpack #251
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.
What and why?
When multiple loaders transform a file, it's necessary to combine (or "chain") the source maps produced by each loader to produce an end-to-end source map that connects the bundled code to the original source. Failing to chain the source maps produced by intermediate loaders can produce source maps which are either broken, or which simply map to partially-transformed code. Either outcome can make debugging difficult.
Unfortunately, source map chaining behavior is inconsistent between the various bundlers that Unplugin supports, and Unplugin does not paper over those differences. For example:
As a result of these differences, source map chaining is currently not working for Rspack and Webpack. As a result, early adopters of the RUM Privacy plugin are reporting incorrect source maps. This PR adds code to handle source map chaining within the RUM Privacy plugin for these bundlers, resolving the issue.
Ideally, Unplugin would provide consistent source map chaining behavior across all bundlers, and I expect we'll eventually see that happen. However, because that would be a backwards-incompatible change for some bundlers if implemented in the obvious way, it will probably take some time to get there.
How?
inputSourceMapon Unplugin'sNativeBuildContexttype. On Rspack and Webpack, this property is populated with the input source map, if there is one.instrument()function exposes byjs-instrumentation-wasm.instrument()already supports source map chaining, so that's enough to fix the issue.