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
chore(postcss-minify-gradients): replace is-color-stop with own code #1181
Conversation
91f4daa
to
52d865c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1181 +/- ##
==========================================
+ Coverage 96.55% 96.56% +0.01%
==========================================
Files 116 117 +1
Lines 3627 3644 +17
Branches 1065 1071 +6
==========================================
+ Hits 3502 3519 +17
Misses 117 117
Partials 8 8
Continue to review full report at Codecov.
|
Yes indeed! I made good progress on building up a thorough and up to date suite of functional tests to support all the gradient types (repeating and non-repeating) with both one and two position syntax... and how they can be shortened according to the various 'fixup' rules etc. Which is quite a lot of work - but allowing me to build a good understanding of the relatively large and complex specs around this. In preparation for diving in with some heavy handed refactoring coupled with unit tests! I stalled a bit due to what I'll summarise as #life (😅 )... and also in between things trying to give a hand with triage and such in the Jest issue tracker while the maintainer was on vacation. But I aim to shift more focus back towards cssnano this coming week, and in addition to continuing the gradient-work also follow up with a PR on this. =) Nuking I'm guessing these are not the only places in the codebase where there are these kind of redundancies... for example duplicating the functionality of |
Yes, it does not even detect a color stop according to the current spec, since it expects only two values.
Can these tests be added to the repository? Working on these optimizations is indeed a lot of work, I think you have to undertake it more for fun than for anything else. From the various tests I've found on the web, switching to brotli compression from gzip gives a size decrease that's much bigger than the difference between the output of any two css minifiers. So a generic text compression algorithm beats techniques that use CSS domain knowledge. |
css-color-names only exports a list of all color names with matching hex value, so that's already included in colord. The issue is more with special names like |
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 suggested a couple of small tweaks just to bring the code style more in line with our code base. I'll leave the rest be, since the main benefit here is to get rid of the dependency - and spending time on it beyond that adds little value at this point, considering (as you pointed out) the limited impact. :)
Since the code is pretty much copied straight out of is-color-stop
should that be mentioned somewhere to satisfy licensing/copyright? I'm not entirely sure what applies here, so just asking to be on the safe side
]; | ||
|
||
function isCSSLengthUnit(input) { | ||
return lengthArray.indexOf(input.toUpperCase()) >= 0; |
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.
return lengthArray.indexOf(input.toUpperCase()) >= 0; | |
return lengthArray.includes(input.toLowerCase()); |
const lengthArray = [ | ||
'PX', | ||
'IN', | ||
'CM', | ||
'MM', | ||
'EM', | ||
'REM', | ||
'POINTS', | ||
'PC', | ||
'EX', | ||
'CH', | ||
'VW', | ||
'VH', | ||
'VMIN', | ||
'VMAX', | ||
'%', | ||
]; |
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.
const lengthArray = [ | |
'PX', | |
'IN', | |
'CM', | |
'MM', | |
'EM', | |
'REM', | |
'POINTS', | |
'PC', | |
'EX', | |
'CH', | |
'VW', | |
'VH', | |
'VMIN', | |
'VMAX', | |
'%', | |
]; | |
const lengthArray = [ | |
'px', | |
'in', | |
'cm', | |
'mm', | |
'em', | |
'rem', | |
'points', | |
'pc', | |
'ex', | |
'ch', | |
'vw', | |
'vh', | |
'vmin', | |
'vmax', | |
'%', | |
]; |
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've left it uppercase because it looks like an unintuitive choice so I thought there might be a reason behind it?
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.
looks like an unintuitive choice
Indeed
might be a reason behind it?
Hmm.. well... we are not expecting any exotic characters - and even if we were... then forcing case in either direction wouldn't be a good way of doing case insensitive comparison anyway. So it strikes me as merely being down to personal preference / coding style... as in... the author thought it looked prettier? I at least can't think of anything else that should differ between them in the context of comparison; can you?
We use lower case comparison everywhere else, as far as I know successfully, that's why I suggested the change. I'm okay with leaving it as-is if you feel that is safer though
Yep; my plan is to add the tests as the basis for a draft PR. Then we can use that for tracking further progress. 👍 The rest I followed up in #1173 |
Get rid of 7 dependencies in a cssnano install. is-color-stop duplicates functionality available from other dependencies. It copies unit parsing code directly from postcss-value-parser. cssnano has color detection logic is already available in colord.
52d865c
to
2f82285
Compare
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 have applied some of the suggestions and added a link to the original code.
const lengthArray = [ | ||
'PX', | ||
'IN', | ||
'CM', | ||
'MM', | ||
'EM', | ||
'REM', | ||
'POINTS', | ||
'PC', | ||
'EX', | ||
'CH', | ||
'VW', | ||
'VH', | ||
'VMIN', | ||
'VMAX', | ||
'%', | ||
]; |
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've left it uppercase because it looks like an unintuitive choice so I thought there might be a reason behind it?
|
||
extend([namesPlugin]); | ||
|
||
/* Code derived from https://github.com/pigcan/is-color-stop */ |
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.
Added a link to the orignal code, I don't think the MIT license requires it but I agree it is nicer to have proper attribution
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.
👍
const lengthArray = [ | ||
'PX', | ||
'IN', | ||
'CM', | ||
'MM', | ||
'EM', | ||
'REM', | ||
'POINTS', | ||
'PC', | ||
'EX', | ||
'CH', | ||
'VW', | ||
'VH', | ||
'VMIN', | ||
'VMAX', | ||
'%', | ||
]; |
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.
looks like an unintuitive choice
Indeed
might be a reason behind it?
Hmm.. well... we are not expecting any exotic characters - and even if we were... then forcing case in either direction wouldn't be a good way of doing case insensitive comparison anyway. So it strikes me as merely being down to personal preference / coding style... as in... the author thought it looked prettier? I at least can't think of anything else that should differ between them in the context of comparison; can you?
We use lower case comparison everywhere else, as far as I know successfully, that's why I suggested the change. I'm okay with leaving it as-is if you feel that is safer though
|
||
extend([namesPlugin]); | ||
|
||
/* Code derived from https://github.com/pigcan/is-color-stop */ |
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.
👍
Get rid of 7 dependencies in a cssnano install.
is-color-stop duplicates functionality available from other dependencies. It copies
unit parsing code directly from postcss-value-parser.
cssnano has color detection logic is already available in colord.
Bringing the code inside might also help #650