Skip to content

Commit f598725

Browse files
committed
fix(dependencies): replace colorette with chalk for better color support detection
1 parent 1bbe37a commit f598725

7 files changed

+66
-53
lines changed

bin/lint-staged.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import fs from 'node:fs'
44
import path from 'node:path'
55
import { fileURLToPath } from 'node:url'
66

7-
import { isColorSupported } from 'colorette'
7+
import { supportsColor } from 'chalk'
88
import { Option, program } from 'commander'
99
import debug from 'debug'
1010

1111
import lintStaged from '../lib/index.js'
1212
import { CONFIG_STDIN_ERROR } from '../lib/messages.js'
1313

1414
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
15-
if (isColorSupported) {
16-
process.env.FORCE_COLOR = '1'
15+
if (supportsColor) {
16+
process.env.FORCE_COLOR = supportsColor.level.toString()
1717
}
1818

1919
// Do not terminate main Listr process on SIGINT

lib/figures.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { blue, redBright, yellow } from 'colorette'
1+
import chalk from 'chalk'
22
import { figures } from 'listr2'
33

4-
export const info = blue(figures.arrowRight)
4+
export const info = chalk.blue(figures.arrowRight)
55

6-
export const error = redBright(figures.cross)
6+
export const error = chalk.redBright(figures.cross)
77

8-
export const warning = yellow(figures.warning)
8+
export const warning = chalk.yellow(figures.warning)

lib/messages.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { redBright, bold, yellow } from 'colorette'
1+
import chalk from 'chalk'
22
import inspect from 'object-inspect'
33

44
import { error, info, warning } from './figures.js'
55

66
export const configurationError = (opt, helpMsg, value) =>
7-
`${redBright(`${error} Validation Error:`)}
7+
`${chalk.redBright(`${error} Validation Error:`)}
88
9-
Invalid value for '${bold(opt)}': ${bold(
9+
Invalid value for '${chalk.bold(opt)}': ${chalk.bold(
1010
inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY })
1111
)}
1212
1313
${helpMsg}`
1414

15-
export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`)
15+
export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`)
1616

17-
export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`)
17+
export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`)
1818

1919
export const incorrectBraces = (before, after) =>
20-
yellow(
20+
chalk.yellow(
2121
`${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\`
2222
`
2323
)
@@ -36,10 +36,10 @@ export const skippingBackup = (hasInitialCommit, diff) => {
3636
? '`--no-stash` was used'
3737
: 'there’s no initial commit yet'
3838

39-
return yellow(`${warning} Skipping backup because ${reason}.\n`)
39+
return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`)
4040
}
4141

42-
export const DEPRECATED_GIT_ADD = yellow(
42+
export const DEPRECATED_GIT_ADD = chalk.yellow(
4343
`${warning} Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
4444
`
4545
)
@@ -48,18 +48,20 @@ export const TASK_ERROR = 'Skipped because of errors from tasks.'
4848

4949
export const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'
5050

51-
export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}`
51+
export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}`
5252

53-
export const invalidOption = (name, value, message) => `${redBright(`${error} Validation Error:`)}
53+
export const invalidOption = (name, value, message) => `${chalk.redBright(
54+
`${error} Validation Error:`
55+
)}
5456
55-
Invalid value for option '${bold(name)}': ${bold(value)}
57+
Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)}
5658
5759
${message}
5860
5961
See https://github.com/okonet/lint-staged#command-line-flags`
6062

6163
export const PREVENTED_EMPTY_COMMIT = `
62-
${yellow(`${warning} lint-staged prevented an empty git commit.
64+
${chalk.yellow(`${warning} lint-staged prevented an empty git commit.
6365
Use the --allow-empty option to continue, or check your task configuration`)}
6466
`
6567

lib/resolveTaskFn.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { redBright, dim } from 'colorette'
1+
import chalk from 'chalk'
22
import { execa, execaCommand } from 'execa'
33
import debug from 'debug'
44
import { parseArgsStringToArgv } from 'string-argv'
@@ -32,7 +32,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
3232
const hasOutput = !!stderr || !!stdout
3333

3434
if (hasOutput) {
35-
const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:`
35+
const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:`
3636
const output = []
3737
.concat(ctx.quiet ? [] : ['', outputTitle])
3838
.concat(stderr ? stderr : [])
@@ -41,7 +41,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
4141
} else if (isError) {
4242
// Show generic error when task had no output
4343
const tag = getTag(result)
44-
const message = redBright(`\n${error} ${command} failed without output (${tag}).`)
44+
const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`)
4545
if (!ctx.quiet) ctx.output.push(message)
4646
}
4747
}
@@ -116,7 +116,7 @@ const makeErr = (command, result, ctx) => {
116116

117117
handleOutput(command, result, ctx, true)
118118
const tag = getTag(result)
119-
return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`)
119+
return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`)
120120
}
121121

122122
/**

lib/runAll.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import path from 'node:path'
44

5-
import { dim } from 'colorette'
5+
import chalk from 'chalk'
66
import debug from 'debug'
77
import { Listr } from 'listr2'
88
import normalize from 'normalize-path'
@@ -204,7 +204,7 @@ export const runAll = async (
204204
const fileCount = task.fileList.length
205205

206206
return {
207-
title: `${task.pattern}${dim(
207+
title: `${task.pattern}${chalk.dim(
208208
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
209209
)}`,
210210
task: async (ctx, task) =>
@@ -216,7 +216,7 @@ export const runAll = async (
216216
skip: () => {
217217
// Skip task when no files matched
218218
if (fileCount === 0) {
219-
return `${task.pattern}${dim(' — no files')}`
219+
return `${task.pattern}${chalk.dim(' — no files')}`
220220
}
221221
return false
222222
},
@@ -227,15 +227,15 @@ export const runAll = async (
227227

228228
listrTasks.push({
229229
title:
230-
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
231-
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
230+
`${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
231+
(chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
232232
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
233233
skip: () => {
234234
// Skip if the first step (backup) failed
235235
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
236236
// Skip chunk when no every task is skipped (due to no matches)
237237
if (chunkListrTasks.every((task) => task.skip())) {
238-
return `${configName}${dim(' — no tasks to run')}`
238+
return `${configName}${chalk.dim(' — no tasks to run')}`
239239
}
240240
return false
241241
},

package-lock.json

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"test:watch": "jest --watch"
3434
},
3535
"dependencies": {
36+
"chalk": "5.2.0",
3637
"cli-truncate": "^3.1.0",
37-
"colorette": "^2.0.19",
3838
"commander": "^10.0.0",
3939
"debug": "^4.3.4",
4040
"execa": "^7.0.0",

0 commit comments

Comments
 (0)