Skip to content

Commit e53e0c3

Browse files
committed
refactor(@angular-devkit/schematics-cli): replace ansi-colors with node:util.styleText
This commit removes the external dependency 'ansi-colors' from the `@angular-devkit/schematics-cli` package and replaces its usage with the native 'node:util.styleText' function for console output styling. This change reduces the project's dependency footprint and leverages built-in Node.js functionality.
1 parent f1ab1d3 commit e53e0c3

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

packages/angular_devkit/schematics_cli/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ ts_project(
4848
":node_modules/@angular-devkit/core",
4949
":node_modules/@angular-devkit/schematics",
5050
":node_modules/@inquirer/prompts",
51-
":node_modules/ansi-colors",
5251
"//:node_modules/@types/node",
5352
],
5453
)

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { JsonValue, logging, schema } from '@angular-devkit/core';
1111
import { ProcessOutput, createConsoleLogger } from '@angular-devkit/core/node';
1212
import { UnsuccessfulWorkflowExecution, strings } from '@angular-devkit/schematics';
1313
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
14-
import ansiColors from 'ansi-colors';
1514
import { existsSync } from 'node:fs';
1615
import * as path from 'node:path';
17-
import { parseArgs } from 'node:util';
16+
import { parseArgs, styleText } from 'node:util';
1817

1918
/**
2019
* Parse the name of schematic passed in argument, and return a {collection, schematic} named
@@ -223,16 +222,13 @@ export async function main({
223222
}: MainOptions): Promise<0 | 1> {
224223
const { cliOptions, schematicOptions, _ } = parseOptions(args);
225224

226-
// Create a separate instance to prevent unintended global changes to the color configuration
227-
const colors = ansiColors.create();
228-
229225
/** Create the DevKit Logger used through the CLI. */
230226
const logger = createConsoleLogger(!!cliOptions.verbose, stdout, stderr, {
231227
info: (s) => s,
232228
debug: (s) => s,
233-
warn: (s) => colors.bold.yellow(s),
234-
error: (s) => colors.bold.red(s),
235-
fatal: (s) => colors.bold.red(s),
229+
warn: (s) => styleText(['bold', 'yellow'], s),
230+
error: (s) => styleText(['bold', 'red'], s),
231+
fatal: (s) => styleText(['bold', 'red'], s),
236232
});
237233

238234
if (cliOptions.help) {
@@ -315,21 +311,21 @@ export async function main({
315311
case 'update':
316312
loggingQueue.push(
317313
// TODO: `as unknown` was necessary during TS 5.9 update. Figure out a long-term solution.
318-
`${colors.cyan('UPDATE')} ${eventPath} (${(event.content as unknown as Buffer).length} bytes)`,
314+
`${styleText(['cyan'], 'UPDATE')} ${eventPath} (${(event.content as unknown as Buffer).length} bytes)`,
319315
);
320316
break;
321317
case 'create':
322318
loggingQueue.push(
323319
// TODO: `as unknown` was necessary during TS 5.9 update. Figure out a long-term solution.
324-
`${colors.green('CREATE')} ${eventPath} (${(event.content as unknown as Buffer).length} bytes)`,
320+
`${styleText(['green'], 'CREATE')} ${eventPath} (${(event.content as unknown as Buffer).length} bytes)`,
325321
);
326322
break;
327323
case 'delete':
328-
loggingQueue.push(`${colors.yellow('DELETE')} ${eventPath}`);
324+
loggingQueue.push(`${styleText(['yellow'], 'DELETE')} ${eventPath}`);
329325
break;
330326
case 'rename':
331327
loggingQueue.push(
332-
`${colors.blue('RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`,
328+
`${styleText(['blue'], 'RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`,
333329
);
334330
break;
335331
}

packages/angular_devkit/schematics_cli/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"dependencies": {
1919
"@angular-devkit/core": "workspace:0.0.0-PLACEHOLDER",
2020
"@angular-devkit/schematics": "workspace:0.0.0-PLACEHOLDER",
21-
"@inquirer/prompts": "7.10.1",
22-
"ansi-colors": "4.1.3"
21+
"@inquirer/prompts": "7.10.1"
2322
}
2423
}

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)