Skip to content

Commit 7c08d09

Browse files
fix: switch from ansi-colors to picocolors (#5323)
1 parent 1a0caf6 commit 7c08d09

File tree

7 files changed

+28
-57
lines changed

7 files changed

+28
-57
lines changed

lib/cli/cli.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const {
2020
} = require('./options');
2121
const lookupFiles = require('./lookup-files');
2222
const commands = require('./commands');
23-
const ansi = require('ansi-colors');
23+
const pc = require('picocolors');
2424
const {repository, homepage, version, discord} = require('../../package.json');
2525
const {cwd} = require('../utils');
2626

@@ -60,7 +60,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
6060
.fail((msg, err, yargs) => {
6161
debug('caught error sometime before command handler: %O', err);
6262
yargs.showHelp();
63-
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
63+
console.error(`\n${symbols.error} ${pc.red('ERROR:')} ${msg}`);
6464
process.exit(1);
6565
})
6666
.help('help', 'Show usage information & exit')
@@ -69,10 +69,10 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
6969
.alias('version', 'V')
7070
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
7171
.epilog(
72-
`${ansi.reset("Mocha Resources")}
73-
Chat: ${ansi.magenta(discord)}
74-
GitHub: ${ansi.blue(repository.url)}
75-
Docs: ${ansi.yellow(homepage)}
72+
`${pc.reset("Mocha Resources")}
73+
Chat: ${pc.magenta(discord)}
74+
GitHub: ${pc.blue(repository.url)}
75+
Docs: ${pc.yellow(homepage)}
7676
`
7777
)
7878
.parserConfiguration(YARGS_PARSER_CONFIG)

lib/cli/collect-files.js

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

33
const fs = require('node:fs');
44
const path = require('node:path');
5-
const ansi = require('ansi-colors');
5+
const pc = require('picocolors');
66
const debug = require('debug')('mocha:cli:run:helpers');
77
const minimatch = require('minimatch');
88
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
@@ -94,12 +94,12 @@ module.exports = ({
9494
unmatchedSpecFiles[0].pattern
9595
)}` // stringify to print escaped characters raw
9696
: 'Error: No test files found';
97-
console.error(ansi.red(noneFoundMsg));
97+
console.error(pc.red(noneFoundMsg));
9898
process.exit(1);
9999
} else {
100100
// print messages as a warning
101101
unmatchedSpecFiles.forEach(warning => {
102-
console.warn(ansi.yellow(`Warning: ${warning.message}`));
102+
console.warn(pc.yellow(`Warning: ${warning.message}`));
103103
});
104104
}
105105

lib/cli/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
const fs = require('node:fs');
11-
const ansi = require('ansi-colors');
11+
const pc = require('picocolors');
1212
const yargsParser = require('yargs-parser');
1313
const {
1414
types,
@@ -180,7 +180,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
180180
boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
181181
});
182182
if (result.error) {
183-
console.error(ansi.red(`Error: ${result.error.message}`));
183+
console.error(pc.red(`Error: ${result.error.message}`));
184184
process.exit(1);
185185
}
186186

lib/cli/run-helpers.js

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

1010
const fs = require('node:fs');
1111
const path = require('node:path');
12-
const ansi = require('ansi-colors');
12+
const pc = require('picocolors');
1313
const debug = require('debug')('mocha:cli:run:helpers');
1414
const {watchRun, watchParallelRun} = require('./watch-run');
1515
const collectFiles = require('./collect-files');
@@ -121,7 +121,7 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
121121

122122
unmatchedFiles.forEach(({pattern, absolutePath}) => {
123123
console.error(
124-
ansi.yellow(
124+
pc.yellow(
125125
`Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`
126126
)
127127
);

lib/cli/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
const symbols = require('log-symbols');
11-
const ansi = require('ansi-colors');
11+
const pc = require('picocolors');
1212
const Mocha = require('../mocha');
1313
const {
1414
createUnsupportedError,
@@ -357,7 +357,7 @@ exports.builder = yargs =>
357357
Object.assign(argv, plugins);
358358
} catch (err) {
359359
// this could be a bad --require, bad reporter, ui, etc.
360-
console.error(`\n${symbols.error} ${ansi.red('ERROR:')}`, err);
360+
console.error(`\n${symbols.error} ${pc.red('ERROR:')}`, err);
361361
yargs.exit(1);
362362
}
363363
})

package-lock.json

Lines changed: 12 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
"version": "run-p version:* && git add -A ./AUTHORS ./CHANGELOG.md"
9595
},
9696
"dependencies": {
97-
"ansi-colors": "^4.1.3",
9897
"browser-stdout": "^1.3.1",
9998
"chokidar": "^3.5.3",
10099
"debug": "^4.3.5",
@@ -107,6 +106,7 @@
107106
"log-symbols": "^4.1.0",
108107
"minimatch": "^5.1.6",
109108
"ms": "^2.1.3",
109+
"picocolors": "^1.1.1",
110110
"serialize-javascript": "^6.0.2",
111111
"strip-json-comments": "^3.1.1",
112112
"supports-color": "^8.1.1",

0 commit comments

Comments
 (0)