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

feat: use picocolors instead of chalk #2377

Open
wants to merge 2 commits 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
18 changes: 9 additions & 9 deletions cli/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const colors = require('picocolors')
const confirm = require('@inquirer/confirm').default
const invariant = require('./invariant')
const { SERVICE_WORKER_BUILD_PATH } = require('../config/constants')
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = async function init(args) {
// will equal to false.
else if (args.save == null) {
console.log(`\
${chalk.cyan(
${colors.cyan(
'INFO',
)} In order to ease the future updates to the worker script,
we recommend saving the path to the worker directory in your package.json.`)
Expand Down Expand Up @@ -141,20 +141,20 @@ async function copyWorkerScript(destination, cwd) {
*/
function printSuccessMessage(paths) {
console.log(`
${chalk.green('Worker script successfully copied!')}
${paths.map((path) => chalk.gray(` - ${path}\n`))}
${colors.green('Worker script successfully copied!')}
${paths.map((path) => colors.gray(` - ${path}\n`))}
Continue by describing the network in your application:


${chalk.cyan.bold('https://mswjs.io/docs/getting-started')}
${colors.red(colors.bold('https://mswjs.io/docs/getting-started'))}
`)
}

function printFailureMessage(pathsWithErrors) {
console.error(`\
${chalk.red('Copying the worker script failed at following paths:')}
${colors.red('Copying the worker script failed at following paths:')}
${pathsWithErrors
.map(([path, error]) => chalk.gray(` - ${path}`) + '\n' + ` ${error}`)
.map(([path, error]) => colors.gray(` - ${path}`) + '\n' + ` ${error}`)
.join('\n\n')}
`)
}
Expand All @@ -167,7 +167,7 @@ function saveWorkerDirectory(packageJsonPath, publicDir) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))

console.log(
chalk.gray('Updating "msw.workerDirectory" at "%s"...'),
colors.gray('Updating "msw.workerDirectory" at "%s"...'),
packageJsonPath,
)

Expand Down Expand Up @@ -200,7 +200,7 @@ function saveWorkerDirectory(packageJsonPath, publicDir) {
function promptWorkerDirectoryUpdate(message, packageJsonPath, publicDir) {
return confirm({
theme: {
prefix: chalk.yellowBright('?'),
prefix: colors.yellowBright('?'),
},
message,
}).then((answer) => {
Expand Down
4 changes: 2 additions & 2 deletions cli/invariant.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chalk = require('chalk')
const colors = require('picocolors')

module.exports = function invariant(predicate, message, ...args) {
if (!predicate) {
console.error(chalk.red(message), ...args)
console.error(colors.red(message), ...args)
process.exit(1)
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
"chalk": "^4.1.2",
"graphql": "^16.8.1",
"headers-polyfill": "^4.0.2",
"is-node-process": "^1.2.0",
"outvariant": "^1.4.3",
"path-to-regexp": "^6.3.0",
"picocolors": "^1.1.1",
"strict-event-emitter": "^0.5.1",
"type-fest": "^4.26.1",
"yargs": "^17.7.2"
Expand Down
Loading
Loading