-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(tools): replace @colors/colors with smaller and faster ansis #4195
base: main
Are you sure you want to change the base?
Conversation
- replace @colors/colors with ansis - add color preview for selectors used in CSS - fix ESLint errors in tools code
@@ -5,7 +5,7 @@ const css = require("css"); | |||
const wcagContrast = require("wcag-contrast"); | |||
const Table = require('cli-table'); | |||
const csscolors = require('css-color-names'); | |||
require("@colors/colors"); |
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.
require("@colors/colors")
<= extends the String.prototype
, that is the bad practice.
@@ -5,7 +5,7 @@ const css = require("css"); | |||
const wcagContrast = require("wcag-contrast"); | |||
const Table = require('cli-table'); | |||
const csscolors = require('css-color-names'); | |||
require("@colors/colors"); | |||
const { cyan, green, yellow, magentaBright, hex } = require('ansis'); |
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.
ansis supports the named import that allow to write shorter and cleaner code
const doesNotSupport = has_rules.map(x => x[1]).includes(false); | ||
const skipped = has_rules.find(x => x[2]); | ||
if (doesNotSupport || skipped) { | ||
console.log(group.name.yellow); |
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.
group.name
is the string that prototype was extended with the yellow
function.
This is unreadable and is very bad practice.
if (doesNotSupport) { | ||
console.log(`- Theme does not fully support.`.brightMagenta); | ||
console.log(magentaBright`- Theme does not fully support.`); |
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.
with ansis
you can use the template string syntax very well,
this is clear and readable code unlike using extended String.prototype
by @colors/colors
}); | ||
console.log(); | ||
} | ||
} | ||
|
||
const round2 = (x) => Math.round(x*100)/100; | ||
const round2 = (x) => Math.round(x * 100) / 100; |
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.
fix ESLint error
|
||
class CSSRule { | ||
constructor(rule, body) { | ||
this.rule = rule; | ||
if (rule.declarations) { | ||
this.bg = rule.declarations.find(x => x.property == "background-color")?.value; | ||
this.bg = rule.declarations.find(x => x.property === "background-color")?.value; |
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.
fix ESLint error
get background() { | ||
return this.bg | ||
return this.bg; |
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.
fix ESLint error
This PR replaces @colors/colors used in CLI tools with smaller and faster ansis.
Benefits of
ansis
@colors/colors
- 41.5 kB,ansis
- 7 kB, see Compare the size of packages@colors/colors
, see BenchmarksString.prototype
Packages that already use
ansis
facebook/stylex, nestjs/nest, sequelize/core, oclif/core, salesforcecli/cli and thousands others
Changes
The changes in CLI tools:
@colors/colors
withansis
Checklist
CHANGES.md
Test
This PR does not require unit/integration tests, but you can do the
manual test
.Clone and install the forked repository:
1) Run CheckTheme tools in CLI
For example, we want to check the
vs2015
style:In console output will be displayed color text and NEW added preview of colors used in CSS selectors:
2) Run CheckAutoDetect tools in CLI
In console output will be displayed color text: