Skip to content

Commit 9e35d17

Browse files
committed
refactor(@angular/cli): use Node.js builtin ANSI escape removal helper
Node.js contains a helper function within the `util` builtin that will remove any ANSI escape codes from a string. This removes the need for a custom utility function.
1 parent 4b95aec commit 9e35d17

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

packages/angular/cli/lib/cli/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
import { logging } from '@angular-devkit/core';
10-
import { format } from 'util';
10+
import { format, stripVTControlCharacters } from 'node:util';
1111
import { CommandModuleError } from '../../src/command-builder/command-module';
1212
import { runCommand } from '../../src/command-builder/command-runner';
13-
import { colors, removeColor } from '../../src/utilities/color';
13+
import { colors } from '../../src/utilities/color';
1414
import { ngDebug } from '../../src/utilities/environment-options';
1515
import { writeErrorToLogFile } from '../../src/utilities/log-file';
1616

@@ -51,7 +51,7 @@ export default async function (options: { cliArgs: string[] }) {
5151
return;
5252
}
5353

54-
const color = colors.enabled ? colorLevels[entry.level] : removeColor;
54+
const color = colors.enabled ? colorLevels[entry.level] : stripVTControlCharacters;
5555
const message = color(entry.message);
5656

5757
switch (entry.level) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ function supportColor(): boolean {
3636
return false;
3737
}
3838

39-
export function removeColor(text: string): string {
40-
// This has been created because when colors.enabled is false unstyle doesn't work
41-
// see: https://github.com/doowb/ansi-colors/blob/a4794363369d7b4d1872d248fc43a12761640d8e/index.js#L38
42-
return text.replace(ansiColors.ansiRegex, '');
43-
}
44-
4539
// Create a separate instance to prevent unintended global changes to the color configuration
4640
const colors = ansiColors.create();
4741
colors.enabled = supportColor();

0 commit comments

Comments
 (0)