Skip to content

Commit fd5cdd4

Browse files
committed
Replace Chalk by Picocolors
1 parent 90d4b21 commit fd5cdd4

10 files changed

+46
-46
lines changed

bin/encore.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const parseRuntime = require('../lib/config/parse-runtime');
1414
const context = require('../lib/context');
15-
const chalk = require('chalk');
15+
const pc = require('picocolors');
1616
const logger = require('../lib/logger');
1717

1818
const runtimeConfig = parseRuntime(
@@ -41,7 +41,7 @@ if (indexPublicArgument !== -1) {
4141

4242
if (!runtimeConfig.isValidCommand) {
4343
if (runtimeConfig.command) {
44-
console.log(chalk.bgRed.white(`Invalid command "${runtimeConfig.command}"`));
44+
console.log(pc.bgRed(pc.white(`Invalid command "${runtimeConfig.command}"`)));
4545
console.log();
4646
}
4747
showUsageInstructions();
@@ -72,26 +72,26 @@ if (runtimeConfig.useDevServer) {
7272
function showUsageInstructions() {
7373
const validCommands = ['dev', 'prod', 'production', 'dev-server'];
7474

75-
console.log(`usage ${chalk.green('encore')} [${ validCommands.map(command => chalk.green(command)).join('|') }]`);
75+
console.log(`usage ${pc.green('encore')} [${ validCommands.map(command => pc.green(command)).join('|') }]`);
7676
console.log();
7777
console.log('encore is a thin executable around the webpack or webpack-dev-server executables');
7878
console.log();
7979
console.log('Commands:');
80-
console.log(` ${chalk.green('dev')} : runs webpack for development`);
80+
console.log(` ${pc.green('dev')} : runs webpack for development`);
8181
console.log(' - Supports any webpack options (e.g. --watch)');
8282
console.log();
83-
console.log(` ${chalk.green('dev-server')} : runs webpack-dev-server`);
84-
console.log(` - ${chalk.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
85-
console.log(` - ${chalk.yellow('--port')} The port the webpack-dev-server will bind to`);
86-
console.log(` - ${chalk.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
87-
console.log(` - ${chalk.yellow('--public')} The public url for entry asset in entrypoints.json`);
83+
console.log(` ${pc.green('dev-server')} : runs webpack-dev-server`);
84+
console.log(` - ${pc.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
85+
console.log(` - ${pc.yellow('--port')} The port the webpack-dev-server will bind to`);
86+
console.log(` - ${pc.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
87+
console.log(` - ${pc.yellow('--public')} The public url for entry asset in entrypoints.json`);
8888
console.log(' - Supports any webpack-dev-server options');
8989
console.log();
90-
console.log(` ${chalk.green('production')} : runs webpack for production`);
90+
console.log(` ${pc.green('production')} : runs webpack for production`);
9191
console.log(' - Supports any webpack options (e.g. --watch)');
9292
console.log();
93-
console.log(chalk.yellow(' encore dev --watch'));
94-
console.log(chalk.yellow(' encore dev-server'));
95-
console.log(chalk.yellow(' encore production'));
93+
console.log(pc.yellow(' encore dev --watch'));
94+
console.log(pc.yellow(' encore dev-server'));
95+
console.log(pc.yellow(' encore production'));
9696
console.log();
9797
}

lib/EncoreProxy.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313
const levenshtein = require('fastest-levenshtein');
1414
const prettyError = require('./utils/pretty-error');
1515

@@ -76,9 +76,9 @@ module.exports = {
7676
}
7777
}
7878

79-
let errorMessage = `${chalk.red(`Encore.${prop}`)} is not a recognized property or method.`;
79+
let errorMessage = `${pc.red(`Encore.${prop}`)} is not a recognized property or method.`;
8080
if (minDistance < (prop.length / 3)) {
81-
errorMessage += ` Did you mean ${chalk.green(`Encore.${similarProperty}`)}?`;
81+
errorMessage += ` Did you mean ${pc.green(`Encore.${similarProperty}`)}?`;
8282
}
8383

8484
// Prettify the error message.

lib/friendly-errors/asset-output-display-plugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313

1414
function AssetOutputDisplayPlugin(outputPath, friendlyErrorsPlugin) {
1515
this.outputPath = outputPath;
@@ -21,7 +21,7 @@ AssetOutputDisplayPlugin.prototype.apply = function(compiler) {
2121
// completely reset messages key to avoid adding more and more messages
2222
// when using watch
2323
this.friendlyErrorsPlugin.compilationSuccessInfo.messages = [
24-
`${chalk.yellow(Object.keys(compilation.assets).length)} files written to ${chalk.yellow(this.outputPath)}`
24+
`${pc.yellow(Object.keys(compilation.assets).length)} files written to ${pc.yellow(this.outputPath)}`
2525
];
2626

2727
callback();

lib/friendly-errors/formatters/missing-css-file.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313

1414
function formatErrors(errors) {
1515
if (errors.length === 0) {
@@ -19,7 +19,7 @@ function formatErrors(errors) {
1919
let messages = [];
2020

2121
messages.push(
22-
chalk.red('Module build failed: Module not found:')
22+
pc.red('Module build failed: Module not found:')
2323
);
2424
for (let error of errors) {
2525
messages.push(`"${error.file}" contains a reference to the file "${error.ref}".`);

lib/friendly-errors/formatters/missing-loader.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313
const loaderFeatures = require('../../features');
1414

1515
function formatErrors(errors) {
@@ -24,7 +24,7 @@ function formatErrors(errors) {
2424

2525
if (error.loaderName) {
2626
let neededCode = `Encore.${loaderFeatures.getFeatureMethod(error.loaderName)}`;
27-
fixes.push(`Add ${chalk.green(neededCode)} to your webpack.config.js file.`);
27+
fixes.push(`Add ${pc.green(neededCode)} to your webpack.config.js file.`);
2828

2929
const packageRecommendations = loaderFeatures.getMissingPackageRecommendations(error.loaderName);
3030

@@ -42,15 +42,15 @@ function formatErrors(errors) {
4242
messages.push('');
4343
} else {
4444
messages = messages.concat([
45-
chalk.red(`Error loading ${chalk.yellow(error.file)}`),
45+
pc.red(`Error loading ${pc.yellow(error.file)}`),
4646
''
4747
]);
4848
}
4949

5050
if (error.loaderName) {
51-
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} To ${loaderFeatures.getFeatureDescription(error.loaderName)}:`);
51+
messages.push(`${pc.bgGreen(pc.black('FIX'))} To ${loaderFeatures.getFeatureDescription(error.loaderName)}:`);
5252
} else {
53-
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} To load "${error.file}":`);
53+
messages.push(`${pc.bgGreen(pc.black('FIX'))} To load "${error.file}":`);
5454
}
5555

5656
let index = 0;

lib/friendly-errors/formatters/missing-postcss-config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313

1414
function formatErrors(errors) {
1515
if (errors.length === 0) {
@@ -21,13 +21,13 @@ function formatErrors(errors) {
2121
// the error over and over again is not helpful
2222

2323
messages.push(
24-
chalk.red('Module build failed: Error: No PostCSS Config found')
24+
pc.red('Module build failed: Error: No PostCSS Config found')
2525
);
2626
messages.push('');
27-
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} Create a ${chalk.yellow('postcss.config.js')} file at the root of your project.`);
27+
messages.push(`${pc.bgGreen(pc.black('FIX'))} Create a ${pc.yellow('postcss.config.js')} file at the root of your project.`);
2828
messages.push('');
2929
messages.push('Here is an example to get you started!');
30-
messages.push(chalk.yellow(`
30+
messages.push(pc.yellow(`
3131
// postcss.config.js
3232
module.exports = {
3333
plugins: {

lib/logger.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313

1414
const messagesKeys = [
1515
'debug',
@@ -47,26 +47,26 @@ module.exports = {
4747
messages.debug.push(message);
4848

4949
if (config.isVerbose) {
50-
log(`${chalk.bgBlack.white(' DEBUG ')} ${message}`);
50+
log(`${pc.bgBlack(pc.white(' DEBUG '))} ${message}`);
5151
}
5252
},
5353

5454
recommendation(message) {
5555
messages.recommendation.push(message);
5656

57-
log(`${chalk.bgBlue.white(' RECOMMEND ')} ${message}`);
57+
log(`${pc.bgBlue(pc.white(' RECOMMEND '))} ${message}`);
5858
},
5959

6060
warning(message) {
6161
messages.warning.push(message);
6262

63-
log(`${chalk.bgYellow.black(' WARNING ')} ${chalk.yellow(message)}`);
63+
log(`${pc.bgYellow(pc.black(' WARNING '))} ${pc.yellow(message)}`);
6464
},
6565

6666
deprecation(message) {
6767
messages.deprecation.push(message);
6868

69-
log(`${chalk.bgYellow.black(' DEPRECATION ')} ${chalk.yellow(message)}`);
69+
log(`${pc.bgYellow(pc.black(' DEPRECATION '))} ${pc.yellow(message)}`);
7070
},
7171

7272
getMessages() {

lib/package-helper.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const chalk = require('chalk');
12+
const pc = require('picocolors');
1313
const fs = require('fs');
1414
const logger = require('./logger');
1515
const semver = require('semver');
@@ -52,14 +52,14 @@ function getInstallCommand(packageConfigs) {
5252
});
5353

5454
if (hasPnpmLockfile) {
55-
return chalk.yellow(`pnpm add ${packageInstallStrings.join(' ')} --save-dev`);
55+
return pc.yellow(`pnpm add ${packageInstallStrings.join(' ')} --save-dev`);
5656
}
5757

5858
if (hasYarnLockfile) {
59-
return chalk.yellow(`yarn add ${packageInstallStrings.join(' ')} --dev`);
59+
return pc.yellow(`yarn add ${packageInstallStrings.join(' ')} --dev`);
6060
}
6161

62-
return chalk.yellow(`npm install ${packageInstallStrings.join(' ')} --save-dev`);
62+
return pc.yellow(`npm install ${packageInstallStrings.join(' ')} --save-dev`);
6363
}
6464

6565
function isPackageInstalled(packageConfig) {
@@ -101,9 +101,9 @@ function getMissingPackageRecommendations(packagesConfig, requestedFeature = nul
101101
return;
102102
}
103103

104-
const missingPackageNamesChalked = missingPackageConfigs.map(function(packageConfigs) {
104+
const missingPackageNamesPicocolorsed = missingPackageConfigs.map(function(packageConfigs) {
105105
const packageNames = packageConfigs.map(packageConfig => {
106-
return chalk.green(packageConfig.name);
106+
return pc.green(packageConfig.name);
107107
});
108108

109109
let missingPackages = packageNames[0];
@@ -115,9 +115,9 @@ function getMissingPackageRecommendations(packagesConfig, requestedFeature = nul
115115
return missingPackages;
116116
});
117117

118-
let message = `Install ${missingPackageNamesChalked.join(' & ')}`;
118+
let message = `Install ${missingPackageNamesPicocolorsed.join(' & ')}`;
119119
if (requestedFeature) {
120-
message += ` to use ${chalk.green(requestedFeature)}`;
120+
message += ` to use ${pc.green(requestedFeature)}`;
121121
}
122122

123123
const installCommand = getInstallCommand(missingPackageConfigs);
@@ -159,11 +159,11 @@ function getInvalidPackageVersionRecommendations(packagesConfig) {
159159

160160
if (semver.gtr(version, packageConfig.version)) {
161161
return [
162-
`Webpack Encore requires version ${chalk.green(packageConfig.version)} of ${chalk.green(packageConfig.name)}. Your version ${chalk.green(version)} is too new. The related feature *may* still work properly. If you have issues, try downgrading the library, or upgrading Encore.`
162+
`Webpack Encore requires version ${pc.green(packageConfig.version)} of ${pc.green(packageConfig.name)}. Your version ${pc.green(version)} is too new. The related feature *may* still work properly. If you have issues, try downgrading the library, or upgrading Encore.`
163163
];
164164
} else {
165165
return [
166-
`Webpack Encore requires version ${chalk.green(packageConfig.version)} of ${chalk.green(packageConfig.name)}, but your version (${chalk.green(version)}) is too old. The related feature will probably *not* work correctly.`
166+
`Webpack Encore requires version ${pc.green(packageConfig.version)} of ${pc.green(packageConfig.name)}, but your version (${pc.green(version)}) is too old. The related feature will probably *not* work correctly.`
167167
];
168168
}
169169
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
3131
"assets-webpack-plugin": "7.0.*",
3232
"babel-loader": "^9.1.3",
33-
"chalk": "^4.0.0",
3433
"css-loader": "^6.7.0",
3534
"css-minimizer-webpack-plugin": "^7.0.0",
3635
"fastest-levenshtein": "^1.0.16",
3736
"mini-css-extract-plugin": "^2.6.0",
37+
"picocolors": "^1.1.0",
3838
"pretty-error": "^4.0.0",
3939
"resolve-url-loader": "^5.0.0",
4040
"semver": "^7.3.2",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -5435,7 +5435,7 @@ periscopic@^3.1.0:
54355435
estree-walker "^3.0.0"
54365436
is-reference "^3.0.0"
54375437

5438-
picocolors@^1.0.0, picocolors@^1.0.1:
5438+
picocolors@^1.0.0, picocolors@^1.0.1, picocolors@^1.1.0:
54395439
version "1.1.0"
54405440
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
54415441
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==

0 commit comments

Comments
 (0)