Skip to content

Commit 14c60e6

Browse files
roli-lpciclaude
andauthored
chore(deps): replace chalk with native util.styleText (#3029)
Replace the `chalk` dependency with Node.js built-in `util.styleText` across all three packages (core, orval, query). The `styleText` API is stable in Node >=22.18.0 which is already the minimum engine version. - Migrate all chalk color/style calls to styleText equivalents - Use array syntax for chained styles (e.g. `['cyan', 'bold']`) - Remove chalk from dependencies in all 3 package.json files - Update yarn.lock accordingly Closes #2982 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0485f7f commit 14c60e6

File tree

12 files changed

+59
-45
lines changed

12 files changed

+59
-45
lines changed

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"dependencies": {
2525
"@scalar/openapi-types": "catalog:",
2626
"acorn": "^8.15.0",
27-
"chalk": "^5.6.2",
2827
"compare-versions": "^6.1.1",
2928
"debug": "^4.4.3",
3029
"esbuild": "^0.27.3",

packages/core/src/generators/mutator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
2+
import { styleText } from 'node:util';
23

3-
import chalk from 'chalk';
44
import fs from 'fs-extra';
55

66
import type { GeneratorMutator, NormalizedMutator, Tsconfig } from '../types';
@@ -44,7 +44,10 @@ export async function generateMutator({
4444

4545
if (mutatorInfoName === undefined) {
4646
throw new Error(
47-
chalk.red(`Mutator ${importPath} must have a named or default export.`),
47+
styleText(
48+
'red',
49+
`Mutator ${importPath} must have a named or default export.`,
50+
),
4851
);
4952
}
5053

@@ -77,7 +80,8 @@ export async function generateMutator({
7780

7881
if (!mutatorInfo) {
7982
throw new Error(
80-
chalk.red(
83+
styleText(
84+
'red',
8185
`Your mutator file doesn't have the ${mutatorInfoName} exported function`,
8286
),
8387
);

packages/core/src/utils/logger.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import readline from 'node:readline';
2-
3-
import chalk from 'chalk';
2+
import { styleText } from 'node:util';
43

54
import { isString } from './assertion';
65

@@ -29,7 +28,7 @@ export function startMessage({
2928
version: string;
3029
description: string;
3130
}): string {
32-
return `🍻 ${chalk.cyan.bold(name)} ${chalk.green(`v${version}`)}${
31+
return `🍻 ${styleText(['cyan', 'bold'], name)} ${styleText('green', `v${version}`)}${
3332
description ? ` - ${description}` : ''
3433
}`;
3534
}
@@ -53,15 +52,17 @@ export function logError(err: unknown, tag?: string) {
5352
}
5453

5554
log(
56-
chalk.red(
55+
styleText(
56+
'red',
5757
['🛑', tag ? `${tag} -` : undefined, message].filter(Boolean).join(' '),
5858
),
5959
);
6060
}
6161

6262
export function mismatchArgsMessage(mismatchArgs: string[]) {
6363
log(
64-
chalk.yellow(
64+
styleText(
65+
'yellow',
6566
`${mismatchArgs.join(', ')} ${
6667
mismatchArgs.length === 1 ? 'is' : 'are'
6768
} not defined in your configuration!`,
@@ -72,7 +73,7 @@ export function mismatchArgsMessage(mismatchArgs: string[]) {
7273
export function createSuccessMessage(backend?: string) {
7374
log(
7475
`🎉 ${
75-
backend ? `${chalk.green(backend)} - ` : ''
76+
backend ? `${styleText('green', backend)} - ` : ''
7677
}Your OpenAPI spec has been converted into ready to use orval!`,
7778
);
7879
}
@@ -138,19 +139,19 @@ export function createLogger(
138139
if (options.timestamp) {
139140
const tag =
140141
type === 'info'
141-
? chalk.cyan.bold(prefix)
142+
? styleText(['cyan', 'bold'], prefix)
142143
: type === 'warn'
143-
? chalk.yellow.bold(prefix)
144-
: chalk.red.bold(prefix);
145-
return `${chalk.dim(new Date().toLocaleTimeString())} ${tag} ${msg}`;
144+
? styleText(['yellow', 'bold'], prefix)
145+
: styleText(['red', 'bold'], prefix);
146+
return `${styleText('dim', new Date().toLocaleTimeString())} ${tag} ${msg}`;
146147
} else {
147148
return msg;
148149
}
149150
};
150151
if (type === lastType && msg === lastMsg) {
151152
sameCount++;
152153
clear();
153-
console[method](format(), chalk.yellow(`(x${sameCount + 1})`));
154+
console[method](format(), styleText('yellow', `(x${sameCount + 1})`));
154155
} else {
155156
sameCount = 0;
156157
lastMsg = msg;

packages/orval/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"@scalar/json-magic": "^0.11.4",
7676
"@scalar/openapi-parser": "^0.24.13",
7777
"@scalar/openapi-types": "catalog:",
78-
"chalk": "^5.6.2",
7978
"chokidar": "^5.0.0",
8079
"commander": "^14.0.2",
8180
"enquirer": "^2.4.1",

packages/orval/src/formatters/prettier.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
3+
import { styleText } from 'node:util';
34

45
import { log } from '@orval/core';
5-
import chalk from 'chalk';
66
import { execa } from 'execa';
77

88
/**
@@ -37,14 +37,16 @@ export async function formatWithPrettier(
3737
// https://prettier.io/docs/options#parser
3838
} else {
3939
log(
40-
chalk.yellow(
40+
styleText(
41+
'yellow',
4142
`⚠️ ${projectTitle ? `${projectTitle} - ` : ''}Failed to format file ${filePath}: ${error.toString()}`,
4243
),
4344
);
4445
}
4546
} else {
4647
log(
47-
chalk.yellow(
48+
styleText(
49+
'yellow',
4850
`⚠️ ${projectTitle ? `${projectTitle} - ` : ''}Failed to format file ${filePath}: unknown error}`,
4951
),
5052
);
@@ -61,7 +63,8 @@ export async function formatWithPrettier(
6163
await execa('prettier', ['--write', ...paths]);
6264
} catch {
6365
log(
64-
chalk.yellow(
66+
styleText(
67+
'yellow',
6568
`⚠️ ${projectTitle ? `${projectTitle} - ` : ''}prettier not found. Install it as a project dependency or globally.`,
6669
),
6770
);

packages/orval/src/utils/execute-hook.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { styleText } from 'node:util';
2+
13
import {
24
type Hook,
35
type HookOption,
@@ -8,7 +10,6 @@ import {
810
logError,
911
type NormalizedHookCommand,
1012
} from '@orval/core';
11-
import chalk from 'chalk';
1213
import { execa } from 'execa';
1314
import { parseArgsStringToArgv } from 'string-argv';
1415

@@ -17,7 +18,7 @@ export const executeHook = async (
1718
commands: NormalizedHookCommand = [],
1819
args: string[] = [],
1920
) => {
20-
log(chalk.white(`Running ${name} hook...`));
21+
log(styleText('white', `Running ${name} hook...`));
2122

2223
for (const command of commands) {
2324
try {

packages/orval/src/utils/options.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { styleText } from 'node:util';
2+
13
import {
24
type ClientMockBuilder,
35
type ConfigExternal,
@@ -42,7 +44,6 @@ import {
4244
upath,
4345
} from '@orval/core';
4446
import { DEFAULT_MOCK_OPTIONS } from '@orval/mock';
45-
import chalk from 'chalk';
4647

4748
import pkg from '../../package.json';
4849
import { loadPackageJson } from './package-json';
@@ -122,11 +123,11 @@ export async function normalizeOptions(
122123
: optionsExport);
123124

124125
if (!options.input) {
125-
throw new Error(chalk.red(`Config require an input`));
126+
throw new Error(styleText('red', `Config require an input`));
126127
}
127128

128129
if (!options.output) {
129-
throw new Error(chalk.red(`Config require an output`));
130+
throw new Error(styleText('red', `Config require an output`));
130131
}
131132

132133
const inputOptions = isString(options.input)
@@ -410,11 +411,13 @@ export async function normalizeOptions(
410411
};
411412

412413
if (!normalizedOptions.input.target) {
413-
throw new Error(chalk.red(`Config require an input target`));
414+
throw new Error(styleText('red', `Config require an input target`));
414415
}
415416

416417
if (!normalizedOptions.output.target && !normalizedOptions.output.schemas) {
417-
throw new Error(chalk.red(`Config require an output target or schemas`));
418+
throw new Error(
419+
styleText('red', `Config require an output target or schemas`),
420+
);
418421
}
419422

420423
return normalizedOptions;
@@ -426,7 +429,7 @@ function normalizeMutator(
426429
): NormalizedMutator | undefined {
427430
if (isObject(mutator)) {
428431
if (!mutator.path) {
429-
throw new Error(chalk.red(`Mutator need a path`));
432+
throw new Error(styleText('red', `Mutator need a path`));
430433
}
431434

432435
return {
@@ -599,7 +602,9 @@ function normalizeOutputMode(mode?: OutputMode): OutputMode {
599602
}
600603

601604
if (!Object.values(OutputMode).includes(mode)) {
602-
createLogger().warn(chalk.yellow(`Unknown the provided mode => ${mode}`));
605+
createLogger().warn(
606+
styleText('yellow', `Unknown the provided mode => ${mode}`),
607+
);
603608
return OutputMode.SINGLE;
604609
}
605610

packages/orval/src/utils/package-json.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { styleText } from 'node:util';
2+
13
import {
24
dynamicImport,
35
isObject,
@@ -7,7 +9,6 @@ import {
79
type PackageJson,
810
resolveInstalledVersions,
911
} from '@orval/core';
10-
import chalk from 'chalk';
1112
import { findUp, findUpMultiple } from 'find-up';
1213
import fs from 'fs-extra';
1314
import yaml from 'js-yaml';
@@ -81,7 +82,10 @@ const resolveAndAttachVersions = (
8182
resolvedCache.set(cacheKey, resolved);
8283
for (const [name, version] of Object.entries(resolved)) {
8384
logVerbose(
84-
chalk.dim(`Detected ${chalk.white(name)} v${chalk.white(version)}`),
85+
styleText(
86+
'dim',
87+
`Detected ${styleText('white', name)} v${styleText('white', version)}`,
88+
),
8589
);
8690
}
8791
}
@@ -168,7 +172,7 @@ const maybeReplaceCatalog = async (
168172

169173
if (!catalogData) {
170174
log(
171-
`⚠️ ${chalk.yellow('package.json contains catalog: references, but no catalog source was found (checked: pnpm-workspace.yaml, package.json, .yarnrc.yml).')}`,
175+
`⚠️ ${styleText('yellow', 'package.json contains catalog: references, but no catalog source was found (checked: pnpm-workspace.yaml, package.json, .yarnrc.yml).')}`,
172176
);
173177
return pkg;
174178
}
@@ -189,14 +193,14 @@ const performSubstitution = (
189193
if (version === 'catalog:' || version === 'catalog:default') {
190194
if (!catalogData.catalog) {
191195
log(
192-
`⚠️ ${chalk.yellow(`catalog: substitution for the package '${packageName}' failed as there is no default catalog.`)}`,
196+
`⚠️ ${styleText('yellow', `catalog: substitution for the package '${packageName}' failed as there is no default catalog.`)}`,
193197
);
194198
continue;
195199
}
196200
const sub = catalogData.catalog[packageName];
197201
if (!sub) {
198202
log(
199-
`⚠️ ${chalk.yellow(`catalog: substitution for the package '${packageName}' failed as there is no matching package in the default catalog.`)}`,
203+
`⚠️ ${styleText('yellow', `catalog: substitution for the package '${packageName}' failed as there is no matching package in the default catalog.`)}`,
200204
);
201205
continue;
202206
}
@@ -206,14 +210,14 @@ const performSubstitution = (
206210
const catalog = catalogData.catalogs?.[catalogName];
207211
if (!catalog) {
208212
log(
209-
`⚠️ ${chalk.yellow(`'${version}' substitution for the package '${packageName}' failed as there is no matching catalog named '${catalogName}'. (available named catalogs are: ${Object.keys(catalogData.catalogs ?? {}).join(', ')})`)}`,
213+
`⚠️ ${styleText('yellow', `'${version}' substitution for the package '${packageName}' failed as there is no matching catalog named '${catalogName}'. (available named catalogs are: ${Object.keys(catalogData.catalogs ?? {}).join(', ')})`)}`,
210214
);
211215
continue;
212216
}
213217
const sub = catalog[packageName];
214218
if (!sub) {
215219
log(
216-
`⚠️ ${chalk.yellow(`'${version}' substitution for the package '${packageName}' failed as there is no package in the catalog named '${catalogName}'. (packages in the catalog are: ${Object.keys(catalog).join(', ')})`)}`,
220+
`⚠️ ${styleText('yellow', `'${version}' substitution for the package '${packageName}' failed as there is no package in the catalog named '${catalogName}'. (packages in the catalog are: ${Object.keys(catalog).join(', ')})`)}`,
217221
);
218222
continue;
219223
}

packages/orval/src/write-specs.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { styleText } from 'node:util';
2+
13
import {
24
createSuccessMessage,
35
fixCrossDirectoryImports,
@@ -20,7 +22,6 @@ import {
2022
writeSplitTagsMode,
2123
writeTagsMode,
2224
} from '@orval/core';
23-
import chalk from 'chalk';
2425
import { execa, ExecaError } from 'execa';
2526
import fs from 'fs-extra';
2627
import { unique } from 'remeda';
@@ -388,7 +389,7 @@ export async function writeSpecs(
388389
if (error instanceof ExecaError && error.exitCode === 1)
389390
message = error.message;
390391

391-
log(chalk.yellow(message));
392+
log(styleText('yellow', message));
392393
}
393394
}
394395

@@ -440,7 +441,7 @@ export async function writeSpecs(
440441
? error.message
441442
: `⚠️ ${projectTitle ? `${projectTitle} - ` : ''}Unable to generate docs`;
442443

443-
log(chalk.yellow(message));
444+
log(styleText('yellow', message));
444445
}
445446
}
446447

packages/query/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"dependencies": {
2525
"@orval/core": "workspace:*",
2626
"@orval/fetch": "workspace:*",
27-
"chalk": "^5.6.2",
2827
"remeda": "^2.33.6"
2928
},
3029
"devDependencies": {

0 commit comments

Comments
 (0)