Skip to content

Commit f62a102

Browse files
committed
refactor(@angular/cli): use Node.js styleText for color helpers
Replaces listr2 re-exports in the CLI color helper with Node.js built-in `styleText` utilities from `node:util`. Previously, importing colors from `utilities/color.ts` eagerly pulled in `listr2` along with its transitive dependencies (`wrap-ansi`, `string-width`, `get-east-asian-width`), introducing synchronous ESM module evaluation and ANSI formatting overhead during early CLI startup.
1 parent 1c00edc commit f62a102

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/angular/cli/src/commands/update/utilities/migration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import {
1313
FileSystemSchematicDescription,
1414
NodeWorkflow,
1515
} from '@angular-devkit/schematics/tools';
16+
import { figures } from 'listr2';
1617
import { SpawnSyncReturns } from 'node:child_process';
1718
import * as semver from 'semver';
1819
import { subscribeToWorkflow } from '../../../command-builder/utilities/schematic-workflow';
19-
import { colors, figures } from '../../../utilities/color';
20+
import { colors } from '../../../utilities/color';
2021
import { assertIsError } from '../../../utilities/error';
2122
import { writeErrorToLogFile } from '../../../utilities/log-file';
2223
import { formatFiles } from '../../../utilities/prettier';

packages/angular/cli/src/utilities/color.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77
*/
88

99
import { WriteStream } from 'node:tty';
10+
import { styleText } from 'node:util';
1011

11-
export { color as colors, figures } from 'listr2';
12+
export const colors = Object.freeze({
13+
black: (text: string) => styleText('black', text),
14+
blue: (text: string) => styleText('blue', text),
15+
bold: (text: string) => styleText('bold', text),
16+
cyan: (text: string) => styleText('cyan', text),
17+
dim: (text: string) => styleText('dim', text),
18+
gray: (text: string) => styleText('gray', text),
19+
green: (text: string) => styleText('green', text),
20+
italic: (text: string) => styleText('italic', text),
21+
magenta: (text: string) => styleText('magenta', text),
22+
red: (text: string) => styleText('red', text),
23+
underline: (text: string) => styleText('underline', text),
24+
white: (text: string) => styleText('white', text),
25+
yellow: (text: string) => styleText('yellow', text),
26+
});
1227

1328
export function supportColor(stream: NodeJS.WritableStream = process.stdout): boolean {
1429
if (stream instanceof WriteStream) {

0 commit comments

Comments
 (0)