fix(optimizer): preserve sourcemaps for transformed optimized deps with follow-up transforms#22428
fix(optimizer): preserve sourcemaps for transformed optimized deps with follow-up transforms#22428Andarist wants to merge 6 commits into
Conversation
| fsp | ||
| .readFile(`${file}.map`, 'utf-8') | ||
| .then((map) => JSON.parse(map)) | ||
| .catch(() => null), |
There was a problem hiding this comment.
this is somewhat defensive... but I wasn't sure if you'd prefer a hard crash on invalid data here or how this should otherwise behave
| ]) | ||
| if (map) { | ||
| return { | ||
| code: code.replace(/^\/\/# sourceMappingURL=.*$/m, ''), |
There was a problem hiding this comment.
This is required for the added Babel-based test. When it sees the sourceMappingURL comment it actually grabs that map and does something with the information contained in it. That then somehow conflicts with the Rolldown's sourcemap chaining. I think that mechanism is preferred (transform hook itself doesn't give users access to the sourcemap and the user is not requested to pass the input source map to the performed transform and handle that on their own) - so I think it makes sense to just strip it here to avoid issues with doubly-processed source maps.
There was a problem hiding this comment.
I guess we can set sourcemap: 'hidden' here.
That should remove the comment.
There was a problem hiding this comment.
Nice! I pushed out this change.
1a1da2b to
cd9e7e8
Compare
…th follow-up transforms
cd9e7e8 to
5b3a987
Compare
| ]) | ||
| if (map) { | ||
| return { | ||
| code: code.replace(/^\/\/# sourceMappingURL=.*$/m, ''), |
There was a problem hiding this comment.
I guess we can set sourcemap: 'hidden' here.
That should remove the comment.
There was a problem hiding this comment.
Can we merge this to playground/js-sourcemap/vite.config.js?
There was a problem hiding this comment.
I specifically wanted to isolate it because it relies on specific rolldownOptions. I can merge it back into that config but I felt it's kinda harder to grasp what is actually needed for which test there, as a bunch of different tests were running against that "catch-all" config that had to handle all of them at once.
There was a problem hiding this comment.
But ofc if you want to keep them together - I can move this into that existing config
There was a problem hiding this comment.
I prefer to be merged for now. The relationship between the tests and the option is not complex. I think we should have a comment on rolldownOptions.transform.target anyways because it's unclear why that is needed.
There was a problem hiding this comment.
Ok, I got them merged.
|
@sapphi-red I'm confused as to why zizmor would fail here. I'm not even touching any workflow files and I synced this with the |
|
You can ignore the zizmor failure. It is failing because the action we are using was taken down temporary due to a recent incident (just to clarify we were / are not affected). |
fixes #13560
On the screenshot above, we can see that
rootfails to be evaluated to the correct identifier (because it can't be properly mapped). I stumbled upon this in a previous version of Vite that was usingesbuildand that was always renaming original identifiers that were shadowing some outer bindings (esbuild playground):In this PR, I had to figure out some oxc-based builtin transform that would be used by the optimizer that would actually rename some original binding (that's why the tests in this PR don't rely on the above example).