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 source map stripping issue #1146

Merged
merged 1 commit into from
Oct 1, 2020
Merged

Conversation

FredKSchott
Copy link
Owner

Changes

  • Makes our "outdated source map" replacer more strict, can no longer be found inside/next to a string
  • This is a small incremental improvement over what we have to fix Installing dependency fails with 'Unterminated string constant' error #1115 (and others like it)
  • If we still run into issues in the future, we can go more strict and say "we only strip this type of comment if it starts on a new line".

Testing

  • Added a test

@FredKSchott FredKSchott requested a review from a team as a code owner September 28, 2020 23:38
@vercel
Copy link

vercel bot commented Sep 28, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/nfajjmwt2
✅ Preview: https://snowpack-git-strip-sourcemapping-url-fix.pikapkg.vercel.app

@@ -9,7 +9,7 @@ export function rollupPluginStripSourceMapping(): Plugin {
return {
name: 'snowpack:rollup-plugin-strip-source-mapping',
transform: (code) => ({
code: code.replace(/\/\/+#\s*sourceMappingURL=.+$/gm, ''),
code: code.replace(/[^'"`]\/\/+#\s*sourceMappingURL=.+$/gm, ''),
Copy link
Collaborator

@drwpow drwpow Sep 30, 2020

Choose a reason for hiding this comment

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

Ok so this doesn’t strip the source map if a string character is right before it?

This works for me. But I wonder if there’s a way to also change this so that it only strips it if it’s literally the last thing in the file (which may or may not end on a newline). This doesn’t have to be on its own line, but I’ve never seen it mid-file before; only at the end.

Something like (pseudocode)

/\/\/#s\*sourceMappingURL=[A-Za-z0-9-/:.]+\n?$/

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah, unfortunately, I've seen a few mid-file, usually when the package has been pre-bundled in some way. But, there's a chance that esinstall actually caused that, and each individual transform had only one sourceMappingURL comment.

This is enough for now and I don't want a regression unnecessarily, but if there are still bugs after this then let's revisit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I thought there was a reason for scanning mid-file. Bug found 🙃 : #1505

.markdown-body, .grid-body-header, .toc {
padding: 0 1em;
}

.grid-nav-container {
width: 100vw;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

100% never does what you think it will, does it? 😄

Copy link
Owner Author

Choose a reason for hiding this comment

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

haha sadly, no

@FredKSchott FredKSchott force-pushed the strip-sourcemapping-url-fix branch from 38a9646 to 37b1ba5 Compare October 1, 2020 00:00
@FredKSchott FredKSchott merged commit 5aef32a into master Oct 1, 2020
@FredKSchott FredKSchott deleted the strip-sourcemapping-url-fix branch October 1, 2020 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants