Skip to content

Commit

Permalink
Migrate to picocolors (#1606)
Browse files Browse the repository at this point in the history
Ref https://github.com/ai/nanocolors#nano-colors

Nanocolors is deprecated in favour of picocolors to avoid drama.
All dependencies already migrated. Also fixed one vulnerability.

The main change is step away from named exports and dual modules
support in favour of smaller package.
  • Loading branch information
TrySound authored Oct 15, 2021
1 parent 4166c32 commit d29cec4
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 469 deletions.
4 changes: 2 additions & 2 deletions bin/svgo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

const { red } = require('nanocolors');
const colors = require('picocolors');
const { program } = require('commander');
const makeProgram = require('../lib/svgo/coa');
makeProgram(program);
program.parseAsync(process.argv).catch(error => {
console.error(red(error.stack));
console.error(colors.red(error.stack));
process.exit(1);
});
10 changes: 5 additions & 5 deletions lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs');
const path = require('path');
const { green, red } = require('nanocolors');
const colors = require('picocolors');
const { loadConfig, optimize } = require('../svgo-node.js');
const pluginsMap = require('../../plugins/plugins.js');
const PKG = require('../../package.json');
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = function makeProgram(program) {
'Only output error messages, not regular status messages'
)
.option('--show-plugins', 'Show available plugins and exit')
// used by nanocolors internally
// used by picocolors internally
.option('--no-color', 'Output plain text without color')
.action(action);
};
Expand Down Expand Up @@ -387,7 +387,7 @@ function processSVGData(config, info, data, output, input) {

const result = optimize(data, { ...config, ...info });
if (result.modernError) {
console.error(red(result.modernError.toString()));
console.error(colors.red(result.modernError.toString()));
process.exit(1);
}
if (config.datauri) {
Expand Down Expand Up @@ -457,7 +457,7 @@ function printProfitInfo(inBytes, outBytes) {
Math.round((inBytes / 1024) * 1000) / 1000 +
' KiB' +
(profitPercents < 0 ? ' + ' : ' - ') +
green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
colors.green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
' = ' +
Math.round((outBytes / 1024) * 1000) / 1000 +
' KiB'
Expand Down Expand Up @@ -509,7 +509,7 @@ function checkWriteFileError(input, output, data, error) {
function showAvailablePlugins() {
const list = Object.entries(pluginsMap)
.sort(([a], [b]) => a.localeCompare(b))
.map(([name, plugin]) => ` [ ${green(name)} ] ${plugin.description}`)
.map(([name, plugin]) => ` [ ${colors.green(name)} ] ${plugin.description}`)
.join('\n');
console.log('Currently available plugins:\n' + list);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"css-select": "^4.1.3",
"css-tree": "^1.1.3",
"csso": "^4.2.0",
"nanocolors": "^0.2.1",
"picocolors": "^1.0.0",
"stable": "^0.1.8"
},
"devDependencies": {
Expand All @@ -117,7 +117,7 @@
"@types/jest": "^27.0.1",
"del": "^6.0.0",
"eslint": "^7.32.0",
"jest": "^27.2.1",
"jest": "^27.2.5",
"mock-stdin": "^1.0.0",
"node-fetch": "^2.6.2",
"pixelmatch": "^5.2.1",
Expand Down
Loading

0 comments on commit d29cec4

Please sign in to comment.