Skip to content

Replace Chalk by Picocolors #1333

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

Merged
merged 1 commit into from
Sep 7, 2024
Merged
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
26 changes: 13 additions & 13 deletions bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const parseRuntime = require('../lib/config/parse-runtime');
const context = require('../lib/context');
const chalk = require('chalk');
const pc = require('picocolors');
const logger = require('../lib/logger');

const runtimeConfig = parseRuntime(
Expand Down Expand Up @@ -41,7 +41,7 @@ if (indexPublicArgument !== -1) {

if (!runtimeConfig.isValidCommand) {
if (runtimeConfig.command) {
console.log(chalk.bgRed.white(`Invalid command "${runtimeConfig.command}"`));
console.log(pc.bgRed(pc.white(`Invalid command "${runtimeConfig.command}"`)));
console.log();
}
showUsageInstructions();
Expand Down Expand Up @@ -72,26 +72,26 @@ if (runtimeConfig.useDevServer) {
function showUsageInstructions() {
const validCommands = ['dev', 'prod', 'production', 'dev-server'];

console.log(`usage ${chalk.green('encore')} [${ validCommands.map(command => chalk.green(command)).join('|') }]`);
console.log(`usage ${pc.green('encore')} [${ validCommands.map(command => pc.green(command)).join('|') }]`);
console.log();
console.log('encore is a thin executable around the webpack or webpack-dev-server executables');
console.log();
console.log('Commands:');
console.log(` ${chalk.green('dev')} : runs webpack for development`);
console.log(` ${pc.green('dev')} : runs webpack for development`);
console.log(' - Supports any webpack options (e.g. --watch)');
console.log();
console.log(` ${chalk.green('dev-server')} : runs webpack-dev-server`);
console.log(` - ${chalk.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
console.log(` - ${chalk.yellow('--port')} The port the webpack-dev-server will bind to`);
console.log(` - ${chalk.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
console.log(` - ${chalk.yellow('--public')} The public url for entry asset in entrypoints.json`);
console.log(` ${pc.green('dev-server')} : runs webpack-dev-server`);
console.log(` - ${pc.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
console.log(` - ${pc.yellow('--port')} The port the webpack-dev-server will bind to`);
console.log(` - ${pc.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
console.log(` - ${pc.yellow('--public')} The public url for entry asset in entrypoints.json`);
console.log(' - Supports any webpack-dev-server options');
console.log();
console.log(` ${chalk.green('production')} : runs webpack for production`);
console.log(` ${pc.green('production')} : runs webpack for production`);
console.log(' - Supports any webpack options (e.g. --watch)');
console.log();
console.log(chalk.yellow(' encore dev --watch'));
console.log(chalk.yellow(' encore dev-server'));
console.log(chalk.yellow(' encore production'));
console.log(pc.yellow(' encore dev --watch'));
console.log(pc.yellow(' encore dev-server'));
console.log(pc.yellow(' encore production'));
console.log();
}
6 changes: 3 additions & 3 deletions lib/EncoreProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');
const levenshtein = require('fastest-levenshtein');
const prettyError = require('./utils/pretty-error');

Expand Down Expand Up @@ -76,9 +76,9 @@ module.exports = {
}
}

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

// Prettify the error message.
Expand Down
4 changes: 2 additions & 2 deletions lib/friendly-errors/asset-output-display-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');

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

callback();
Expand Down
4 changes: 2 additions & 2 deletions lib/friendly-errors/formatters/missing-css-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');

function formatErrors(errors) {
if (errors.length === 0) {
Expand All @@ -19,7 +19,7 @@ function formatErrors(errors) {
let messages = [];

messages.push(
chalk.red('Module build failed: Module not found:')
pc.red('Module build failed: Module not found:')
);
for (let error of errors) {
messages.push(`"${error.file}" contains a reference to the file "${error.ref}".`);
Expand Down
10 changes: 5 additions & 5 deletions lib/friendly-errors/formatters/missing-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');
const loaderFeatures = require('../../features');

function formatErrors(errors) {
Expand All @@ -24,7 +24,7 @@ function formatErrors(errors) {

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

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

Expand All @@ -42,15 +42,15 @@ function formatErrors(errors) {
messages.push('');
} else {
messages = messages.concat([
chalk.red(`Error loading ${chalk.yellow(error.file)}`),
pc.red(`Error loading ${pc.yellow(error.file)}`),
''
]);
}

if (error.loaderName) {
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} To ${loaderFeatures.getFeatureDescription(error.loaderName)}:`);
messages.push(`${pc.bgGreen(pc.black('FIX'))} To ${loaderFeatures.getFeatureDescription(error.loaderName)}:`);
} else {
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} To load "${error.file}":`);
messages.push(`${pc.bgGreen(pc.black('FIX'))} To load "${error.file}":`);
}

let index = 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/friendly-errors/formatters/missing-postcss-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');

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

messages.push(
chalk.red('Module build failed: Error: No PostCSS Config found')
pc.red('Module build failed: Error: No PostCSS Config found')
);
messages.push('');
messages.push(`${chalk.bgGreen.black('', 'FIX', '')} Create a ${chalk.yellow('postcss.config.js')} file at the root of your project.`);
messages.push(`${pc.bgGreen(pc.black('FIX'))} Create a ${pc.yellow('postcss.config.js')} file at the root of your project.`);
messages.push('');
messages.push('Here is an example to get you started!');
messages.push(chalk.yellow(`
messages.push(pc.yellow(`
// postcss.config.js
module.exports = {
plugins: {
Expand Down
10 changes: 5 additions & 5 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');

const messagesKeys = [
'debug',
Expand Down Expand Up @@ -47,26 +47,26 @@ module.exports = {
messages.debug.push(message);

if (config.isVerbose) {
log(`${chalk.bgBlack.white(' DEBUG ')} ${message}`);
log(`${pc.bgBlack(pc.white(' DEBUG '))} ${message}`);
}
},

recommendation(message) {
messages.recommendation.push(message);

log(`${chalk.bgBlue.white(' RECOMMEND ')} ${message}`);
log(`${pc.bgBlue(pc.white(' RECOMMEND '))} ${message}`);
},

warning(message) {
messages.warning.push(message);

log(`${chalk.bgYellow.black(' WARNING ')} ${chalk.yellow(message)}`);
log(`${pc.bgYellow(pc.black(' WARNING '))} ${pc.yellow(message)}`);
},

deprecation(message) {
messages.deprecation.push(message);

log(`${chalk.bgYellow.black(' DEPRECATION ')} ${chalk.yellow(message)}`);
log(`${pc.bgYellow(pc.black(' DEPRECATION '))} ${pc.yellow(message)}`);
},

getMessages() {
Expand Down
20 changes: 10 additions & 10 deletions lib/package-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const chalk = require('chalk');
const pc = require('picocolors');
const fs = require('fs');
const logger = require('./logger');
const semver = require('semver');
Expand Down Expand Up @@ -52,14 +52,14 @@ function getInstallCommand(packageConfigs) {
});

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

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

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

function isPackageInstalled(packageConfig) {
Expand Down Expand Up @@ -101,9 +101,9 @@ function getMissingPackageRecommendations(packagesConfig, requestedFeature = nul
return;
}

const missingPackageNamesChalked = missingPackageConfigs.map(function(packageConfigs) {
const missingPackageNamesPicocolorsed = missingPackageConfigs.map(function(packageConfigs) {
const packageNames = packageConfigs.map(packageConfig => {
return chalk.green(packageConfig.name);
return pc.green(packageConfig.name);
});

let missingPackages = packageNames[0];
Expand All @@ -115,9 +115,9 @@ function getMissingPackageRecommendations(packagesConfig, requestedFeature = nul
return missingPackages;
});

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

const installCommand = getInstallCommand(missingPackageConfigs);
Expand Down Expand Up @@ -159,11 +159,11 @@ function getInvalidPackageVersionRecommendations(packagesConfig) {

if (semver.gtr(version, packageConfig.version)) {
return [
`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.`
`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.`
];
} else {
return [
`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.`
`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.`
];
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
"assets-webpack-plugin": "7.0.*",
"babel-loader": "^9.1.3",
"chalk": "^4.0.0",
"css-loader": "^6.7.0",
"css-minimizer-webpack-plugin": "^7.0.0",
"fastest-levenshtein": "^1.0.16",
"mini-css-extract-plugin": "^2.6.0",
"picocolors": "^1.1.0",
"pretty-error": "^4.0.0",
"resolve-url-loader": "^5.0.0",
"semver": "^7.3.2",
Expand Down
3 changes: 2 additions & 1 deletion test/bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ module.exports = Encore.getWebpackConfig();
const binPath = path.resolve(__dirname, '../', '../', 'bin', 'encore.js');
exec(`node ${binPath} dev --context=${testDir}`, { cwd: testDir }, (err, stdout, stderr) => {
expect(err).not.to.be.null;
expect(stdout).to.contain('is not a recognized property or method');
expect(stdout).to.contain('is not a recognized property');
expect(stdout).to.contain('or method');
expect(stdout).to.contain('Did you mean');
done();
});
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5435,7 +5435,7 @@ periscopic@^3.1.0:
estree-walker "^3.0.0"
is-reference "^3.0.0"

picocolors@^1.0.0, picocolors@^1.0.1:
picocolors@^1.0.0, picocolors@^1.0.1, picocolors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==
Expand Down
Loading