Skip to content

Commit 26a0d7c

Browse files
committed
refactor: replace chalk with ansi-colors
1 parent 37e87f8 commit 26a0d7c

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"@rollup/plugin-json": "^4.0.0",
3232
"@rollup/plugin-node-resolve": "^9.0.0",
3333
"ajv": "^6.12.3",
34+
"ansi-colors": "^4.1.1",
3435
"autoprefixer": "^9.6.5",
3536
"browserslist": "^4.7.0",
36-
"chalk": "^4.0.0",
3737
"chokidar": "^3.2.1",
3838
"commander": "^6.0.0",
3939
"cssnano-preset-default": "^4.0.7",

src/lib/ng-package/entry-point/init-tsconfig.transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ParsedConfiguration } from '@angular/compiler-cli';
2-
import * as chalk from 'chalk';
2+
import { colors } from '../../utils/color';
33
import { Transform, transformFromPromise } from '../../graph/transform';
44
import { isEntryPoint, EntryPointNode } from '../nodes';
55
import { initializeTsConfig } from '../../ts/tsconfig';
@@ -18,7 +18,7 @@ export const initTsConfigTransformFactory = (defaultTsConfig: ParsedConfiguratio
1818
'Read more here: https://v9.angular.io/guide/ivy#maintaining-library-compatibility\n' +
1919
'******************************************************************************';
2020

21-
msg(chalk.yellow(ivyMsg));
21+
msg(colors.yellow(ivyMsg));
2222
}
2323

2424
return graph;

src/lib/utils/color.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as ansiColors from 'ansi-colors';
2+
import { WriteStream } from 'tty';
3+
4+
type AnsiColors = typeof ansiColors;
5+
6+
// Typings do not contain the function call (added in Node.js v9.9.0)
7+
const supportsColor =
8+
process.stdout instanceof WriteStream &&
9+
((process.stdout as unknown) as { getColorDepth(): number }).getColorDepth() > 1;
10+
11+
// Create a separate instance to prevent unintended global changes to the color configuration
12+
// Create function is not defined in the typings. See: https://github.com/doowb/ansi-colors/pull/44
13+
const colors = (ansiColors as AnsiColors & { create: () => AnsiColors }).create();
14+
colors.enabled = supportsColor;
15+
16+
export { colors };

src/lib/utils/log.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import * as chalk from 'chalk';
1+
import { colors } from './color';
22

33
export const error = (err: string | Error) => {
44
if (err instanceof Error) {
5-
console.error(chalk.red('ERROR: ' + err.message));
5+
console.error(colors.red('ERROR: ' + err.message));
66

77
if (process.env.DEBUG) {
8-
console.error(chalk.red(err.stack) + '\n');
8+
console.error(colors.red(err.stack) + '\n');
99
}
1010
} else {
11-
console.error(chalk.red(err));
11+
console.error(colors.red(err));
1212
}
1313
};
1414

1515
export const warn = (msg: string) => {
16-
console.warn(chalk.yellow('WARNING: ' + msg));
16+
console.warn(colors.yellow('WARNING: ' + msg));
1717
};
1818

1919
export const success = (msg: string) => {
20-
console.log(chalk.green(msg));
20+
console.log(colors.green(msg));
2121
};
2222

2323
export const info = (msg: string) => {
24-
console.log(chalk.blue(msg));
24+
console.log(colors.blue(msg));
2525
};
2626

2727
export const msg = (msg: string) => {
28-
console.log(chalk.white(msg));
28+
console.log(colors.white(msg));
2929
};
3030

3131
export const debug = (msg: string) => {
3232
if (process.env.DEBUG) {
33-
console.log(chalk.inverse.cyan(`[debug] ${msg}`));
33+
console.log(colors.inverse.cyan(`[debug] ${msg}`));
3434
}
3535
};

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ alphanum-sort@^1.0.0:
538538
resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
539539
integrity sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=
540540

541-
541+
[email protected], ansi-colors@^4.1.1:
542542
version "4.1.1"
543543
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
544544
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==

0 commit comments

Comments
 (0)