diff --git a/@commitlint/cz-commitlint/package.json b/@commitlint/cz-commitlint/package.json index f4eb26a3ea..536f91703e 100644 --- a/@commitlint/cz-commitlint/package.json +++ b/@commitlint/cz-commitlint/package.json @@ -40,7 +40,7 @@ "@commitlint/ensure": "^18.1.0", "@commitlint/load": "^18.2.0", "@commitlint/types": "^18.1.0", - "chalk": "^4.1.0", + "picocolors": "~1.0.0", "lodash.isplainobject": "^4.0.6", "word-wrap": "^1.2.5" }, diff --git a/@commitlint/format/package.json b/@commitlint/format/package.json index b8e1ec2a04..fe2b04db69 100644 --- a/@commitlint/format/package.json +++ b/@commitlint/format/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@commitlint/types": "^18.1.0", - "chalk": "^4.1.0" + "picocolors": "~1.0.0" }, "gitHead": "d829bf6260304ca8d6811f329fcdd1b6c50e9749" } diff --git a/@commitlint/format/src/format.ts b/@commitlint/format/src/format.ts index e3fa2dd266..9aa79ec7a7 100644 --- a/@commitlint/format/src/format.ts +++ b/@commitlint/format/src/format.ts @@ -1,14 +1,15 @@ -import chalk from 'chalk'; import { - ChalkColor, FormattableReport, FormatOptions, FormattableResult, WithInput, + PcColor, } from '@commitlint/types'; +import pc from 'picocolors'; const DEFAULT_SIGNS = [' ', '⚠', '✖'] as const; -const DEFAULT_COLORS = ['white', 'yellow', 'red'] as const; + +const DEFAULT_COLORS: [PcColor, PcColor, PcColor] = ['white', 'yellow', 'red']; export function format( report: FormattableReport = {}, @@ -41,10 +42,10 @@ function formatInput( } const sign = '⧗'; - const decoration = enabled ? chalk.gray(sign) : sign; + const decoration = enabled ? pc.gray(sign) : sign; const commitText = errors.length > 0 ? input : input.split('\n')[0]; - const decoratedInput = enabled ? chalk.bold(commitText) : commitText; + const decoratedInput = enabled ? pc.bold(commitText) : commitText; const hasProblems = errors.length > 0 || warnings.length > 0; return options.verbose || hasProblems @@ -65,18 +66,16 @@ export function formatResult( const problems = [...errors, ...warnings].map((problem) => { const sign = signs[problem.level] || ''; - const color: ChalkColor = colors[problem.level] || ('white' as const); - const decoration = enabled ? chalk[color](sign) : sign; - const name = enabled - ? chalk.grey(`[${problem.name}]`) - : `[${problem.name}]`; + const color = pc[colors[problem.level]] || pc[DEFAULT_COLORS[0]]; + const decoration = enabled ? color(sign) : sign; + const name = enabled ? pc.gray(`[${problem.name}]`) : `[${problem.name}]`; return `${decoration} ${problem.message} ${name}`; }); const sign = selectSign(result); const color = selectColor(result); - const deco = enabled ? chalk[color](sign) : sign; + const deco = enabled ? color(sign) : sign; const el = errors.length; const wl = warnings.length; const hasProblems = problems.length > 0; @@ -87,7 +86,7 @@ export function formatResult( : undefined; const fmtSummary = - enabled && typeof summary === 'string' ? chalk.bold(summary) : summary; + enabled && typeof summary === 'string' ? pc.bold(summary) : summary; const help = hasProblems && options.helpUrl @@ -112,7 +111,7 @@ function selectSign(result: FormattableResult): string { return (result.warnings || []).length ? '⚠' : '✔'; } -function selectColor(result: FormattableResult): ChalkColor { +function selectColor(result: FormattableResult) { if ((result.errors || []).length > 0) { return 'red'; } diff --git a/@commitlint/load/package.json b/@commitlint/load/package.json index eab90bb451..1538923f15 100644 --- a/@commitlint/load/package.json +++ b/@commitlint/load/package.json @@ -49,7 +49,7 @@ "@commitlint/resolve-extends": "^18.1.0", "@commitlint/types": "^18.1.0", "@types/node": "^18.11.9", - "chalk": "^4.1.0", + "picocolors": "~1.0.0", "cosmiconfig": "^8.0.0", "cosmiconfig-typescript-loader": "^5.0.0", "lodash.isplainobject": "^4.0.6", diff --git a/@commitlint/prompt/package.json b/@commitlint/prompt/package.json index 75dfa2bdd3..6f698a770a 100644 --- a/@commitlint/prompt/package.json +++ b/@commitlint/prompt/package.json @@ -48,7 +48,7 @@ "@commitlint/ensure": "^18.1.0", "@commitlint/load": "^18.2.0", "@commitlint/types": "^18.1.0", - "chalk": "^4.1.0", + "picocolors": "~1.0.0", "inquirer": "^6.5.2" }, "gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc" diff --git a/@commitlint/types/package.json b/@commitlint/types/package.json index 9e3d0e17f5..23c7487776 100644 --- a/@commitlint/types/package.json +++ b/@commitlint/types/package.json @@ -28,7 +28,7 @@ }, "license": "MIT", "dependencies": { - "chalk": "^4.1.0" + "picocolors": "~1.0.0" }, "devDependencies": { "@commitlint/utils": "^18.1.0" diff --git a/@commitlint/types/src/format.ts b/@commitlint/types/src/format.ts index 7180cb3b82..23c8790677 100644 --- a/@commitlint/types/src/format.ts +++ b/@commitlint/types/src/format.ts @@ -1,6 +1,8 @@ -import * as chalk from 'chalk'; import {QualifiedRules} from './load'; import {RuleConfigSeverity} from './rules'; +import pc from 'picocolors'; + +export type PcColor = keyof typeof pc; export type Formatter = ( report: FormattableReport, @@ -26,12 +28,10 @@ export interface FormattableReport { results?: (FormattableResult & WithInput)[]; } -export type ChalkColor = typeof chalk.Color | typeof chalk.Modifiers; - export interface FormatOptions { color?: boolean; signs?: readonly [string, string, string]; - colors?: readonly [ChalkColor, ChalkColor, ChalkColor]; + colors?: readonly [PcColor, PcColor, PcColor]; verbose?: boolean; helpUrl?: string; } diff --git a/yarn.lock b/yarn.lock index 5f500db559..5a340755f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7232,7 +7232,7 @@ path-type@^4.0.0: resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -picocolors@^1.0.0: +picocolors@^1.0.0, picocolors@~1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==