Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️ Fix a bug with remapping when dist is run a second time #37653

Merged
merged 1 commit into from Feb 11, 2022

Conversation

jridgewell
Copy link
Contributor

This is fun. When babel performs internal remapping (when there is an input sourcemap), it just fails to output a valid sourcemap if the output has multiple source files (I actually recently fixed this...). When esbuild generates a sourcemap, it'll link to the map file with a sourceMappingUrl comment. Babel will try see that comment, and interpret the sourcemap as an input. And we hit the bug if the output has multiple sources.

This works fine on the initial build, because the map file hasn't been written to disk yet. But on a re-dist, the map file will exist, and babel will read it. This will cause a bug in our @ampproject/remapping, because we see a transformation that outputs an invalid map (and we throw an error).

This is fun. When babel performs internal remapping (when there is an input sourcemap), it just fails to output a valid sourcemap if the output has multiple source files (I actually recently fixed this...). When esbuild generates a sourcemap, it'll link to the map file with a `sourceMappingUrl` comment. Babel will try see that comment, and interpret the sourcemap as an input. And we hit the bug if the output has multiple sources.

This works fine on the initial build, because the map file hasn't been written to disk yet. But on a re-dist, the map file will exist, and babel will read it. This will cause a bug in our `@ampproject/remapping`, because we see a transformation that outputs an invalid map (and we throw an error).
Copy link
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing sleuthing!

@jridgewell jridgewell enabled auto-merge (squash) February 11, 2022 21:57
@samouri
Copy link
Member

samouri commented Feb 11, 2022

FYI @dethstrobe: this looks like it solves the problem you were running into

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants