Skip to content
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!: replace ansi-colors with smaller and faster ansis #5274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
} = require('./options');
const lookupFiles = require('./lookup-files');
const commands = require('./commands');
const ansi = require('ansi-colors');
const {blue, magenta, red, yellow} = require('ansis');
const {repository, homepage, version, discord} = require('../../package.json');
const {cwd} = require('../utils');

Expand Down Expand Up @@ -62,7 +62,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
.fail((msg, err, yargs) => {
debug('caught error sometime before command handler: %O', err);
yargs.showHelp();
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
console.error(`\n${symbols.error} ${red`ERROR:`} ${msg}`);
process.exitCode = 1;
})
.help('help', 'Show usage information & exit')
Expand All @@ -72,9 +72,9 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
.epilog(
`Mocha Resources
Chat: ${ansi.magenta(discord)}
GitHub: ${ansi.blue(repository.url)}
Docs: ${ansi.yellow(homepage)}
Chat: ${magenta(discord)}
GitHub: ${blue(repository.url)}
Docs: ${yellow(homepage)}
`
)
.parserConfiguration(YARGS_PARSER_CONFIG)
Expand Down
6 changes: 3 additions & 3 deletions lib/cli/collect-files.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 ansi = require('ansi-colors');
const {red, yellow} = require('ansis');
const debug = require('debug')('mocha:cli:run:helpers');
const minimatch = require('minimatch');
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
Expand Down Expand Up @@ -94,12 +94,12 @@ module.exports = ({
unmatchedSpecFiles[0].pattern
)}` // stringify to print escaped characters raw
: 'Error: No test files found';
console.error(ansi.red(noneFoundMsg));
console.error(red(noneFoundMsg));
process.exit(1);
} else {
// print messages as a warning
unmatchedSpecFiles.forEach(warning => {
console.warn(ansi.yellow(`Warning: ${warning.message}`));
console.warn(yellow`Warning: ${warning.message}`);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

const fs = require('fs');
const ansi = require('ansi-colors');
const {red} = require('ansis');
const yargsParser = require('yargs-parser');
const {
types,
Expand Down Expand Up @@ -180,7 +180,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
});
if (result.error) {
console.error(ansi.red(`Error: ${result.error.message}`));
console.error(red`Error: ${result.error.message}`);
process.exit(1);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const fs = require('fs');
const path = require('path');
const ansi = require('ansi-colors');
const {yellow} = require('ansis');
const debug = require('debug')('mocha:cli:run:helpers');
const {watchRun, watchParallelRun} = require('./watch-run');
const collectFiles = require('./collect-files');
Expand Down Expand Up @@ -121,9 +121,7 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {

unmatchedFiles.forEach(({pattern, absolutePath}) => {
console.error(
ansi.yellow(
`Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`
)
yellow`Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`
);
});
console.log(
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

const symbols = require('log-symbols');
const ansi = require('ansi-colors');
const {red} = require('ansis');
const Mocha = require('../mocha');
const {
createUnsupportedError,
Expand Down Expand Up @@ -357,7 +357,7 @@ exports.builder = yargs =>
Object.assign(argv, plugins);
} catch (err) {
// this could be a bad --require, bad reporter, ui, etc.
console.error(`\n${symbols.error} ${ansi.red('ERROR:')}`, err);
console.error(`\n${symbols.error} ${red`ERROR:`}`, err);
yargs.exit(1);
}
})
Expand Down
29 changes: 15 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"version": "run-p version:* && git add -A ./AUTHORS ./CHANGELOG.md"
},
"dependencies": {
"ansi-colors": "^4.1.3",
"ansis": "3.4.0",
"browser-stdout": "^1.3.1",
"chokidar": "^3.5.3",
"debug": "^4.3.5",
Expand Down