Skip to content

Commit d29cec4

Browse files
authored
Migrate to picocolors (#1606)
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.
1 parent 4166c32 commit d29cec4

File tree

4 files changed

+446
-469
lines changed

4 files changed

+446
-469
lines changed

bin/svgo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
const { red } = require('nanocolors');
3+
const colors = require('picocolors');
44
const { program } = require('commander');
55
const makeProgram = require('../lib/svgo/coa');
66
makeProgram(program);
77
program.parseAsync(process.argv).catch(error => {
8-
console.error(red(error.stack));
8+
console.error(colors.red(error.stack));
99
process.exit(1);
1010
});

lib/svgo/coa.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

388388
const result = optimize(data, { ...config, ...info });
389389
if (result.modernError) {
390-
console.error(red(result.modernError.toString()));
390+
console.error(colors.red(result.modernError.toString()));
391391
process.exit(1);
392392
}
393393
if (config.datauri) {
@@ -457,7 +457,7 @@ function printProfitInfo(inBytes, outBytes) {
457457
Math.round((inBytes / 1024) * 1000) / 1000 +
458458
' KiB' +
459459
(profitPercents < 0 ? ' + ' : ' - ') +
460-
green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
460+
colors.green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
461461
' = ' +
462462
Math.round((outBytes / 1024) * 1000) / 1000 +
463463
' KiB'
@@ -509,7 +509,7 @@ function checkWriteFileError(input, output, data, error) {
509509
function showAvailablePlugins() {
510510
const list = Object.entries(pluginsMap)
511511
.sort(([a], [b]) => a.localeCompare(b))
512-
.map(([name, plugin]) => ` [ ${green(name)} ] ${plugin.description}`)
512+
.map(([name, plugin]) => ` [ ${colors.green(name)} ] ${plugin.description}`)
513513
.join('\n');
514514
console.log('Currently available plugins:\n' + list);
515515
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"css-select": "^4.1.3",
106106
"css-tree": "^1.1.3",
107107
"csso": "^4.2.0",
108-
"nanocolors": "^0.2.1",
108+
"picocolors": "^1.0.0",
109109
"stable": "^0.1.8"
110110
},
111111
"devDependencies": {
@@ -117,7 +117,7 @@
117117
"@types/jest": "^27.0.1",
118118
"del": "^6.0.0",
119119
"eslint": "^7.32.0",
120-
"jest": "^27.2.1",
120+
"jest": "^27.2.5",
121121
"mock-stdin": "^1.0.0",
122122
"node-fetch": "^2.6.2",
123123
"pixelmatch": "^5.2.1",

0 commit comments

Comments
 (0)