diff --git a/bin/lint-staged.js b/bin/lint-staged.js index ff8c0d919..cf74b5389 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -4,7 +4,7 @@ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' -import { isColorSupported } from 'colorette' +import { supportsColor } from 'chalk' import { Option, program } from 'commander' import debug from 'debug' @@ -12,8 +12,8 @@ import lintStaged from '../lib/index.js' import { CONFIG_STDIN_ERROR } from '../lib/messages.js' // Force colors for packages that depend on https://www.npmjs.com/package/supports-color -if (isColorSupported) { - process.env.FORCE_COLOR = '1' +if (supportsColor) { + process.env.FORCE_COLOR = supportsColor.level.toString() } // Do not terminate main Listr process on SIGINT diff --git a/lib/figures.js b/lib/figures.js index 7f08e2b8e..ebf3a5c08 100644 --- a/lib/figures.js +++ b/lib/figures.js @@ -1,8 +1,8 @@ -import { blue, redBright, yellow } from 'colorette' +import chalk from 'chalk' import { figures } from 'listr2' -export const info = blue(figures.arrowRight) +export const info = chalk.blue(figures.arrowRight) -export const error = redBright(figures.cross) +export const error = chalk.redBright(figures.cross) -export const warning = yellow(figures.warning) +export const warning = chalk.yellow(figures.warning) diff --git a/lib/messages.js b/lib/messages.js index 2be1d5b87..7e730ac84 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -1,23 +1,23 @@ -import { redBright, bold, yellow } from 'colorette' +import chalk from 'chalk' import inspect from 'object-inspect' import { error, info, warning } from './figures.js' export const configurationError = (opt, helpMsg, value) => - `${redBright(`${error} Validation Error:`)} + `${chalk.redBright(`${error} Validation Error:`)} - Invalid value for '${bold(opt)}': ${bold( + Invalid value for '${chalk.bold(opt)}': ${chalk.bold( inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY }) )} ${helpMsg}` -export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`) +export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`) -export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`) +export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`) export const incorrectBraces = (before, after) => - yellow( + chalk.yellow( `${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\` ` ) @@ -36,10 +36,10 @@ export const skippingBackup = (hasInitialCommit, diff) => { ? '`--no-stash` was used' : 'there’s no initial commit yet' - return yellow(`${warning} Skipping backup because ${reason}.\n`) + return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`) } -export const DEPRECATED_GIT_ADD = yellow( +export const DEPRECATED_GIT_ADD = chalk.yellow( `${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. ` ) @@ -48,18 +48,20 @@ export const TASK_ERROR = 'Skipped because of errors from tasks.' export const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.' -export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}` +export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}` -export const invalidOption = (name, value, message) => `${redBright(`${error} Validation Error:`)} +export const invalidOption = (name, value, message) => `${chalk.redBright( + `${error} Validation Error:` +)} - Invalid value for option '${bold(name)}': ${bold(value)} + Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)} ${message} See https://github.com/okonet/lint-staged#command-line-flags` export const PREVENTED_EMPTY_COMMIT = ` - ${yellow(`${warning} lint-staged prevented an empty git commit. + ${chalk.yellow(`${warning} lint-staged prevented an empty git commit. Use the --allow-empty option to continue, or check your task configuration`)} ` diff --git a/lib/resolveTaskFn.js b/lib/resolveTaskFn.js index 7b83a008d..71f468fbb 100644 --- a/lib/resolveTaskFn.js +++ b/lib/resolveTaskFn.js @@ -1,4 +1,4 @@ -import { redBright, dim } from 'colorette' +import chalk from 'chalk' import { execa, execaCommand } from 'execa' import debug from 'debug' import { parseArgsStringToArgv } from 'string-argv' @@ -32,7 +32,7 @@ const handleOutput = (command, result, ctx, isError = false) => { const hasOutput = !!stderr || !!stdout if (hasOutput) { - const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:` + const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:` const output = [] .concat(ctx.quiet ? [] : ['', outputTitle]) .concat(stderr ? stderr : []) @@ -41,7 +41,7 @@ const handleOutput = (command, result, ctx, isError = false) => { } else if (isError) { // Show generic error when task had no output const tag = getTag(result) - const message = redBright(`\n${error} ${command} failed without output (${tag}).`) + const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`) if (!ctx.quiet) ctx.output.push(message) } } @@ -116,7 +116,7 @@ const makeErr = (command, result, ctx) => { handleOutput(command, result, ctx, true) const tag = getTag(result) - return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`) + return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`) } /** diff --git a/lib/runAll.js b/lib/runAll.js index f74774226..aee972bcf 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -2,7 +2,7 @@ import path from 'node:path' -import { dim } from 'colorette' +import chalk from 'chalk' import debug from 'debug' import { Listr } from 'listr2' import normalize from 'normalize-path' @@ -204,7 +204,7 @@ export const runAll = async ( const fileCount = task.fileList.length return { - title: `${task.pattern}${dim( + title: `${task.pattern}${chalk.dim( ` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}` )}`, task: async (ctx, task) => @@ -216,7 +216,7 @@ export const runAll = async ( skip: () => { // Skip task when no files matched if (fileCount === 0) { - return `${task.pattern}${dim(' — no files')}` + return `${task.pattern}${chalk.dim(' — no files')}` } return false }, @@ -227,15 +227,15 @@ export const runAll = async ( listrTasks.push({ title: - `${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` + - (chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''), + `${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` + + (chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''), task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }), skip: () => { // Skip if the first step (backup) failed if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR // Skip chunk when no every task is skipped (due to no matches) if (chunkListrTasks.every((task) => task.skip())) { - return `${configName}${dim(' — no tasks to run')}` + return `${configName}${chalk.dim(' — no tasks to run')}` } return false }, diff --git a/package-lock.json b/package-lock.json index 82a3f580e..ee7621958 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.0.0-development", "license": "MIT", "dependencies": { + "chalk": "5.2.0", "cli-truncate": "^3.1.0", - "colorette": "^2.0.19", "commander": "^10.0.0", "debug": "^4.3.4", "execa": "^7.0.0", @@ -512,6 +512,32 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/highlight/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/parser": { "version": "7.21.2", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.2.tgz", @@ -3242,17 +3268,14 @@ ] }, "node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", + "integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==", "engines": { - "node": ">=4" + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, "node_modules/char-regex": { @@ -8445,18 +8468,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", diff --git a/package.json b/package.json index df45be677..51f80ac12 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "test:watch": "jest --watch" }, "dependencies": { + "chalk": "5.2.0", "cli-truncate": "^3.1.0", - "colorette": "^2.0.19", "commander": "^10.0.0", "debug": "^4.3.4", "execa": "^7.0.0",