Skip to content

Commit 85bdd82

Browse files
Namcheekettanaito
andauthored
feat: use picocolors instead of chalk (#2377)
Co-authored-by: Artem Zakharchenko <[email protected]>
1 parent 58f2d2c commit 85bdd82

File tree

7 files changed

+29
-33
lines changed

7 files changed

+29
-33
lines changed

.github/workflows/ci.yml

-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ jobs:
198198
node-version: 18
199199
cache: 'pnpm'
200200

201-
- name: Restore build cache
202-
uses: actions/cache@v4
203-
with:
204-
path: ./lib
205-
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
206-
restore-keys: |
207-
${{ runner.os }}-node-20-build-
208-
209201
- name: Install dependencies
210202
run: pnpm install
211203

cli/init.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const chalk = require('chalk')
3+
const colors = require('picocolors')
44
const confirm = require('@inquirer/confirm').default
55
const invariant = require('./invariant')
66
const { SERVICE_WORKER_BUILD_PATH } = require('../config/constants')
@@ -34,7 +34,7 @@ module.exports = async function init(args) {
3434
// will equal to false.
3535
else if (args.save == null) {
3636
console.log(`\
37-
${chalk.cyan(
37+
${colors.cyan(
3838
'INFO',
3939
)} In order to ease the future updates to the worker script,
4040
we recommend saving the path to the worker directory in your package.json.`)
@@ -141,20 +141,20 @@ async function copyWorkerScript(destination, cwd) {
141141
*/
142142
function printSuccessMessage(paths) {
143143
console.log(`
144-
${chalk.green('Worker script successfully copied!')}
145-
${paths.map((path) => chalk.gray(` - ${path}\n`))}
144+
${colors.green('Worker script successfully copied!')}
145+
${paths.map((path) => colors.gray(` - ${path}\n`))}
146146
Continue by describing the network in your application:
147147
148148
149-
${chalk.cyan.bold('https://mswjs.io/docs/getting-started')}
149+
${colors.red(colors.bold('https://mswjs.io/docs/getting-started'))}
150150
`)
151151
}
152152

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

169169
console.log(
170-
chalk.gray('Updating "msw.workerDirectory" at "%s"...'),
170+
colors.gray('Updating "msw.workerDirectory" at "%s"...'),
171171
packageJsonPath,
172172
)
173173

@@ -200,7 +200,7 @@ function saveWorkerDirectory(packageJsonPath, publicDir) {
200200
function promptWorkerDirectoryUpdate(message, packageJsonPath, publicDir) {
201201
return confirm({
202202
theme: {
203-
prefix: chalk.yellowBright('?'),
203+
prefix: colors.yellowBright('?'),
204204
},
205205
message,
206206
}).then((answer) => {

cli/invariant.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const chalk = require('chalk')
1+
const colors = require('picocolors')
22

33
module.exports = function invariant(predicate, message, ...args) {
44
if (!predicate) {
5-
console.error(chalk.red(message), ...args)
5+
console.error(colors.red(message), ...args)
66
process.exit(1)
77
}
88
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@
149149
"@open-draft/until": "^2.1.0",
150150
"@types/cookie": "^0.6.0",
151151
"@types/statuses": "^2.0.4",
152-
"chalk": "^4.1.2",
153152
"graphql": "^16.8.1",
154153
"headers-polyfill": "^4.0.2",
155154
"is-node-process": "^1.2.0",
156155
"outvariant": "^1.4.3",
157156
"path-to-regexp": "^6.3.0",
157+
"picocolors": "^1.1.1",
158158
"strict-event-emitter": "^0.5.1",
159159
"type-fest": "^4.26.1",
160160
"yargs": "^17.7.2"

pnpm-lock.yaml

+5-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/cli-init.node.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ afterAll(async () => {
3737
await fsMock.cleanup()
3838
})
3939

40-
async function init(inlineArgs: Array<string>) {
41-
return fsMock.exec(`node ${cliPath} init ${inlineArgs.join(' ')}`)
40+
async function init(inlineArgs: Array<string>): ReturnType<typeof fsMock.exec> {
41+
const result = await fsMock.exec(
42+
`node ${cliPath} init ${inlineArgs.join(' ')}`,
43+
)
44+
45+
return {
46+
...result,
47+
// Strip stdout from color unicode characters:
48+
stdout: result.stdout.replace(/\x1b\[\d+m/gi, ''),
49+
stderr: result.stderr.replace(/\x1b\[\d+m/gi, ''),
50+
}
4251
}
4352

4453
test('copies the script to a given path without saving', async () => {

tsup.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const reactNativeConfig: Options = {
9595
name: 'react-native',
9696
platform: 'node',
9797
entry: ['./src/native/index.ts'],
98-
external: ['chalk', 'util', 'events', mswCore, ecosystemDependencies],
98+
external: ['picocolors', 'util', 'events', mswCore, ecosystemDependencies],
9999
format: ['esm', 'cjs'],
100100
outDir: './lib/native',
101101
bundle: true,

0 commit comments

Comments
 (0)