-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
feat!(postcss-normalize-url): inline third-party dep and remove options #1480
Conversation
Support the normalize-url code.
d72fad0
to
5b9a9a9
Compare
5b9a9a9
to
7367ab9
Compare
Inline a simplified version of normalize-url. Reasons: - the two most recent major releases of normalize-url use ES modules, so cssnano cannot use them - most options change the meaning of the URLs, so it is unlikely that turning them on during minification makes sense THe remaining code removes redundant slashes and default ports, so performs the same as the previous default configuration. It does not sort parameters any more because we haven't yet found a method that preserves the correct encoding in all cases. If the user does not like these transforms they can turn the plugin off completely.
7367ab9
to
6dd9d95
Compare
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #1480 +/- ##
==========================================
- Coverage 97.62% 96.97% -0.65%
==========================================
Files 122 123 +1
Lines 10000 10136 +136
==========================================
+ Hits 9762 9829 +67
- Misses 238 307 +69
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
This is based on version 8.0 of normalize-url, with the default cssnano options hardcoded.
// Remove duplicate slashes if not preceded by a protocol | ||
if (urlObject.pathname) { | ||
urlObject.pathname = urlObject.pathname.replace( | ||
/(?<!\b[a-z][a-z\d+\-.]{1,50}:)\/{2,}/g, |
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.
This regex was commented out in normalize-url 7.0.1 to support Safari, and replaced with much longer code. I've restored the regex since I don't think we care about running on Safari. Safari 16.4 is going to support lookbehind so this is soon going to work on Safari anyway.
Inline a simplified version of normalize-url. Reasons:
so cssnano cannot use them
that turning them on during minification makes sense
The remaining code removes redundant slashes and default ports,
so performs the same as the previous default configuration. It does not
sort parameters any more because we haven't yet found a method that preserves
the correct encoding in all cases.
If the user does not like these transforms they can turn the plugin
off completely.
See this issue sindresorhus/normalize-url#180 to see why sorting the parameters cannot be guaranteed to work.