-
Notifications
You must be signed in to change notification settings - Fork 922
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 sourcemap plugin #1505
Fix sourcemap plugin #1505
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/8yaaahtjl |
73b446a
to
cbca203
Compare
@@ -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=.+$/, ''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FredKSchott this now breaks the “mid-file“ rule; maybe we should limit to newline-only instead? I think that’d be muuuch safer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, unfortunately we see this mid-file after bundling multiple files together. That would be a regression (I think lit-html or lit-element was the most popular known example of this).
I know you hate this, but these are such one-off weird cases I'd rather handle this as a one-off solution. How about:
- code.replace(/[^'"`]\/\/+#\s*sourceMappingURL=.+$/gm, '')
+ code.replace(/[^'"`]\/\/+#\s*sourceMappingURL=[^'"`].+$/gm, '')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What breaks it is the \n
too so it‘d have to be:
/[^'"`](\\n)?\/\/+#\s*sourceMappingURL=[^'"`]+$/gm
If it works it works, but I‘m gonna add some tests for this plugin specifically to make sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to strip any character that comes before it. Gonna try and get these tests passing, then you can tell me how you feel about the result
cbca203
to
c969d86
Compare
c969d86
to
80edfe2
Compare
Ah yea, in that case you'll need to do: .replace(/[^'"`]((\\n)?\/\/+#\s*sourceMappingURL=[^'"`]+$)/gm, '$1')
// I think $1 would be correct, but may be $2 due to nested `(\n)`.
// you could turn that nested capture group into a non-capturing group as well |
80edfe2
to
f0d7ff6
Compare
f0d7ff6
to
4fd5c5e
Compare
Updated the RegEx. LMK what you think! And if you have any other cases we need to preserve, happy to add it to the test cases. |
4fd5c5e
to
faa47c7
Compare
faa47c7
to
a2739d5
Compare
a2739d5
to
fcda48a
Compare
code: code.replace(/[^'"`]\/\/+#\s*sourceMappingURL=.+$/gm, ''), | ||
code: code | ||
// [a-zA-Z0-9-_\*?\.\/\&=+%]: valid URL characters (for sourcemaps) | ||
.replace(/\/\/#\s*sourceMappingURL=[a-zA-Z0-9-_\*\?\.\/\&=+%\s]+$/gm, ''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah gotcha, so now youre testing that nothing non-URL comes afterwards in the line? Smart!
only random thing that I can think of: can this line end with a semicolon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don‘t think so? Because it‘s a line comment. And a sourcemap URL probably won‘t have a semicolon in it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I don't think so either
FTR if we need to rewrite this RegEx I really don‘t care about the final structure now that we have tests. Please modify this as-needed (and add tests) if you come across any other cases we need to handle. |
Changes
Was investigating CDN issues and came across skypackjs/skypack-cdn#22. Guy Bedford’s
es-module-shims
package won’t load because our builtin Rollup plugin catches the following line:As a result this package couldn’t be installed.
This changes the RegEx to handle end-of-file (single line) differently than middle-of-file
Testing
New snapshot was added for this
Docs