Skip to content

Commit ceeb292

Browse files
committed
refactor(@angular/cli): remove chalk dependency
1 parent 894e008 commit ceeb292

22 files changed

+1887
-424
lines changed

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds",
4848
"@schematics/angular": "github:angular/schematics-angular-builds",
4949
"@schematics/update": "github:angular/schematics-update-builds",
50-
"chalk": "~2.2.0",
5150
"opn": "~5.1.0",
5251
"resolve": "^1.1.7",
5352
"rxjs": "^6.0.0",

packages/@angular/cli/bin/ng

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
// Due to an obscure Mac bug, do not start this title with any symbol.
66
process.title = 'ng';
77

8-
var red = require('chalk').red;
9-
108
var version = process.version.substr(1).split('.');
119
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
12-
process.stderr.write(red(
10+
process.stderr.write(
1311
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
1412
'The official Node.js version that is supported is 8.9 and greater.\n\n' +
1513
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
16-
));
14+
);
1715

1816
process.exit(3);
1917
}

packages/@angular/cli/commands/add.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { tags } from '@angular-devkit/core';
1+
import { tags, terminal } from '@angular-devkit/core';
22
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
3-
import chalk from 'chalk';
43
import { CommandScope, Option } from '../models/command';
54
import { parseOptions } from '../models/command-runner';
65
import { getPackageManager } from '../utilities/config';
@@ -36,7 +35,7 @@ export default class AddCommand extends SchematicCommand {
3635
if (!collectionName) {
3736
throw new SilentError(
3837
`The "ng ${this.name}" command requires a name argument to be specified eg. `
39-
+ `${chalk.yellow('ng add [name] ')}. For more details, use "ng help".`
38+
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`
4039
);
4140
}
4241

@@ -49,7 +48,7 @@ export default class AddCommand extends SchematicCommand {
4948
if (!collectionName) {
5049
throw new SilentError(
5150
`The "ng ${this.name}" command requires a name argument to be specified eg. `
52-
+ `${chalk.yellow('ng add [name] ')}. For more details, use "ng help".`
51+
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`
5352
);
5453
}
5554

packages/@angular/cli/commands/easter-egg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command, Option } from '../models/command';
2-
import chalk from 'chalk';
2+
import { terminal } from '@angular-devkit/core';
33

44
function pickOne(of: string[]): string {
55
return of[Math.floor(Math.random() * of.length)];
@@ -23,6 +23,6 @@ export default class AwesomeCommand extends Command {
2323
`I spy with my little eye a great developer!`,
2424
`Noop... already awesome.`
2525
]);
26-
this.logger.info(chalk.green(phrase));
26+
this.logger.info(terminal.green(phrase));
2727
}
2828
}

packages/@angular/cli/commands/generate.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { CommandScope, Option } from '../models/command';
2-
import chalk from 'chalk';
32
import { getDefaultSchematicCollection } from '../utilities/config';
43
import {
54
getCollection,
65
getEngineHost
76
} from '../utilities/schematics';
8-
import { tags } from '@angular-devkit/core';
7+
import { tags, terminal } from '@angular-devkit/core';
98
import { SchematicCommand } from '../models/schematic-command';
109

11-
const { cyan } = chalk;
1210

1311
export default class GenerateCommand extends SchematicCommand {
1412
public readonly name = 'generate';
@@ -106,7 +104,7 @@ export default class GenerateCommand extends SchematicCommand {
106104
});
107105

108106
this.logger.warn(`\nTo see help for a schematic run:`);
109-
this.logger.info(cyan(` ng generate <schematic> --help`));
107+
this.logger.info(terminal.cyan(` ng generate <schematic> --help`));
110108
}
111109
}
112110
}

packages/@angular/cli/commands/help.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Command, Option } from '../models/command';
2-
import chalk from 'chalk';
2+
import { terminal } from '@angular-devkit/core';
33

4-
const { cyan } = chalk;
54

65
export default class HelpCommand extends Command {
76
public readonly name = 'help';
@@ -23,7 +22,7 @@ export default class HelpCommand extends Command {
2322
}));
2423
this.logger.info(`Available Commands:`);
2524
commands.forEach(cmd => {
26-
this.logger.info(` ${cyan(cmd.name)} ${cmd.description}`);
25+
this.logger.info(` ${terminal.cyan(cmd.name)} ${cmd.description}`);
2726
});
2827

2928
this.logger.info(`\nFor more detailed help run "ng [command name] --help"`);

packages/@angular/cli/lib/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const packageJson = require('../package.json');
1414
const path = require('path');
1515
const resolve = require('resolve');
1616
const stripIndents = require('@angular-devkit/core').tags.stripIndents;
17-
const yellow = require('chalk').yellow;
17+
const yellow = require('@angular-devkit/core').terminal.yellow;
1818
const SemVer = require('semver').SemVer;
1919
const events = require('events');
2020

packages/@angular/cli/models/command.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { logging } from '@angular-devkit/core';
2-
const { cyan } = require('chalk');
1+
import { logging, terminal } from '@angular-devkit/core';
32

43
export interface CommandConstructor {
54
new(context: CommandContext, logger: logging.Logger): Command;
@@ -66,7 +65,7 @@ export abstract class Command<T = any> {
6665
const aliases = o.aliases && o.aliases.length > 0
6766
? '(' + o.aliases.map(a => `-${a}`).join(' ') + ')'
6867
: '';
69-
this.logger.info(` ${cyan('--' + o.name)} ${aliases}`);
68+
this.logger.info(` ${terminal.cyan('--' + o.name)} ${aliases}`);
7069
this.logger.info(` ${o.description}`);
7170
});
7271
}

packages/@angular/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@angular-devkit/schematics": "0.5.10",
3636
"@schematics/angular": "0.5.10",
3737
"@schematics/update": "0.5.10",
38-
"chalk": "~2.2.0",
3938
"opn": "~5.1.0",
4039
"resolve": "^1.1.7",
4140
"rxjs": "^6.0.0",

packages/@angular/cli/tasks/npm-install.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { ModuleNotFoundException, resolve } from '@angular-devkit/core/node';
2-
3-
import chalk from 'chalk';
42
import { spawn } from 'child_process';
5-
import { logging } from '@angular-devkit/core';
3+
import { logging, terminal } from '@angular-devkit/core';
64

75
const SilentError = require('silent-error');
86

@@ -22,7 +20,7 @@ export default async function (packageName: string,
2220
packageManager = 'npm';
2321
}
2422

25-
logger.info(chalk.green(`Installing packages for tooling via ${packageManager}.`));
23+
logger.info(terminal.green(`Installing packages for tooling via ${packageManager}.`));
2624

2725
const installArgs: string[] = [];
2826
switch (packageManager) {
@@ -68,11 +66,11 @@ export default async function (packageName: string,
6866
spawn(packageManager, installArgs, installOptions)
6967
.on('close', (code: number) => {
7068
if (code === 0) {
71-
logger.info(chalk.green(`Installed packages for tooling via ${packageManager}.`));
69+
logger.info(terminal.green(`Installed packages for tooling via ${packageManager}.`));
7270
resolve();
7371
} else {
7472
const message = 'Package install failed, see above.';
75-
logger.info(chalk.red(message));
73+
logger.info(terminal.red(message));
7674
reject(message);
7775
}
7876
});

packages/@angular/cli/upgrade/version.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { SemVer, satisfies } from 'semver';
2-
import chalk from 'chalk';
3-
import { tags } from '@angular-devkit/core';
2+
import { tags, terminal } from '@angular-devkit/core';
43
import * as path from 'path';
54
import { isWarningEnabled } from '../utilities/config';
65
import { requireProjectModule } from '../utilities/require-project-module';
76

87
const resolve = require('resolve');
98

109

11-
const { bold, red, yellow } = chalk;
12-
13-
1410
export class Version {
1511
private _semver: SemVer = null;
1612
constructor(private _version: string = null) {
@@ -64,14 +60,14 @@ export class Version {
6460
angularPkgJson = requireProjectModule(projectRoot, '@angular/core/package.json');
6561
rxjsPkgJson = requireProjectModule(projectRoot, 'rxjs/package.json');
6662
} catch {
67-
console.error(bold(red(tags.stripIndents`
63+
console.error(terminal.bold(terminal.red(tags.stripIndents`
6864
You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
6965
`)));
7066
process.exit(2);
7167
}
7268

7369
if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) {
74-
console.error(bold(red(tags.stripIndents`
70+
console.error(terminal.bold(terminal.red(tags.stripIndents`
7571
Cannot determine versions of "@angular/core" and/or "rxjs".
7672
This likely means your local installation is broken. Please reinstall your packages.
7773
`)));
@@ -82,12 +78,12 @@ export class Version {
8278
let rxjsVersion = new Version(rxjsPkgJson['version']);
8379

8480
if (angularVersion.isLocal()) {
85-
console.warn(yellow('Using a local version of angular. Proceeding with care...'));
81+
console.warn(terminal.yellow('Using a local version of angular. Proceeding with care...'));
8682
return;
8783
}
8884

8985
if (!angularVersion.isGreaterThanOrEqualTo(new SemVer('5.0.0'))) {
90-
console.error(bold(red(tags.stripIndents`
86+
console.error(terminal.bold(terminal.red(tags.stripIndents`
9187
This version of CLI is only compatible with Angular version 5.0.0 or higher.
9288
9389
Please visit the link below to find instructions on how to update Angular.
@@ -99,7 +95,7 @@ export class Version {
9995
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('5.6.0-forward-compat.0'))
10096
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-beta.0'))
10197
) {
102-
console.error(bold(red(tags.stripIndents`
98+
console.error(terminal.bold(terminal.red(tags.stripIndents`
10399
This project uses version ${rxjsVersion} of RxJs, which is not supported by Angular v6.
104100
The official RxJs version that is supported is 5.6.0-forward-compat.0 and greater.
105101
@@ -111,7 +107,7 @@ export class Version {
111107
angularVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-rc.0'))
112108
&& !rxjsVersion.isGreaterThanOrEqualTo(new SemVer('6.0.0-beta.0'))
113109
) {
114-
console.warn(bold(red(tags.stripIndents`
110+
console.warn(terminal.bold(terminal.red(tags.stripIndents`
115111
This project uses a temporary compatibility version of RxJs (${rxjsVersion}).
116112
117113
Please visit the link below to find instructions on how to update RxJs.
@@ -129,7 +125,7 @@ export class Version {
129125
compilerVersion = requireProjectModule(projectRoot, '@angular/compiler-cli').VERSION.full;
130126
tsVersion = requireProjectModule(projectRoot, 'typescript').version;
131127
} catch {
132-
console.error(bold(red(tags.stripIndents`
128+
console.error(terminal.bold(terminal.red(tags.stripIndents`
133129
Versions of @angular/compiler-cli and typescript could not be determined.
134130
The most common reason for this is a broken npm install.
135131
@@ -153,7 +149,7 @@ export class Version {
153149

154150
if (currentCombo && !satisfies(tsVersion, currentCombo.typescript)) {
155151
// First line of warning looks weird being split in two, disable tslint for it.
156-
console.log((yellow('\n' + tags.stripIndent`
152+
console.log((terminal.yellow('\n' + tags.stripIndent`
157153
@angular/compiler-cli@${compilerVersion} requires typescript@'${
158154
currentCombo.typescript}' but ${tsVersion} was found instead.
159155
Using this version can result in undefined behaviour and difficult to debug problems.

packages/@angular/cli/utilities/check-package-manager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { terminal } from '@angular-devkit/core';
22
import { exec } from 'child_process';
33
import { promisify } from 'util';
44
import { getPackageManager } from './config';
@@ -19,16 +19,16 @@ export function checkYarnOrCNPM() {
1919
.then((data: Array<boolean>) => {
2020
const [isYarnInstalled, isCNPMInstalled] = data;
2121
if (isYarnInstalled && isCNPMInstalled) {
22-
console.log(chalk.yellow('You can `ng config -g cli.packageManager yarn` '
22+
console.log(terminal.yellow('You can `ng config -g cli.packageManager yarn` '
2323
+ 'or `ng config -g cli.packageManager cnpm`.'));
2424
} else if (isYarnInstalled) {
25-
console.log(chalk.yellow('You can `ng config -g cli.packageManager yarn`.'));
25+
console.log(terminal.yellow('You can `ng config -g cli.packageManager yarn`.'));
2626
} else if (isCNPMInstalled) {
27-
console.log(chalk.yellow('You can `ng config -g cli.packageManager cnpm`.'));
27+
console.log(terminal.yellow('You can `ng config -g cli.packageManager cnpm`.'));
2828
} else {
2929
if (packageManager !== 'default' && packageManager !== 'npm') {
30-
console.log(chalk.yellow(`Seems that ${packageManager} is not installed.`));
31-
console.log(chalk.yellow('You can `ng config -g cli.packageManager npm`.'));
30+
console.log(terminal.yellow(`Seems that ${packageManager} is not installed.`));
31+
console.log(terminal.yellow('You can `ng config -g cli.packageManager npm`.'));
3232
}
3333
}
3434
});

scripts/git-builds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const spawnSync = require( 'child_process').spawnSync;
66
const fs = require('fs');
77
const temp = require('temp');
8-
const { blue, green, gray } = require('chalk');
8+
const { blue, green, gray } = require('@angular-devkit/core').terminal;
99

1010
const path = require('path');
1111
const glob = require('glob');

scripts/publish/publish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* eslint-disable no-console */
55
const { packages } = require('../../lib/packages');
6-
const { yellow } = require('chalk');
6+
const { yellow } = require('@angular-devkit/core').terminal;
77
const fs = require('fs');
88
const http = require('http');
99
const path = require('path');

scripts/publish/validate_dependencies.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
/* eslint-disable no-console */
5-
const chalk = require('chalk');
5+
const terminal = require('@angular-devkit/core').terminal;
66
const fs = require('fs');
77
const glob = require('glob');
88
const packages = require('../../lib/packages').packages;
@@ -70,19 +70,19 @@ function listIgnoredModules(source) {
7070

7171
function reportMissingDependencies(missingDeps) {
7272
if (missingDeps.length == 0) {
73-
console.log(chalk.green(' no dependency missing from package.json.'));
73+
console.log(terminal.green(' no dependency missing from package.json.'));
7474
} else {
75-
console.log(chalk.yellow(` ${missingDeps.length} missing from package.json:`));
75+
console.log(terminal.yellow(` ${missingDeps.length} missing from package.json:`));
7676
missingDeps.forEach(md => console.log(` ${md}`));
7777
exitCode = 1;
7878
}
7979
}
8080

8181
function reportExcessiveDependencies(overDeps) {
8282
if (overDeps.length == 0) {
83-
console.log(chalk.green(' no excessive dependencies in package.json.'));
83+
console.log(terminal.green(' no excessive dependencies in package.json.'));
8484
} else {
85-
console.log(chalk.yellow(` ${overDeps.length} excessive dependencies in package.json:`));
85+
console.log(terminal.yellow(` ${overDeps.length} excessive dependencies in package.json:`));
8686
overDeps.forEach(md => console.log(` ${md}`));
8787
exitCode = 1;
8888
}
@@ -91,7 +91,7 @@ function reportExcessiveDependencies(overDeps) {
9191
let exitCode = 0;
9292
const overallDeps = [];
9393
for (const packageName of Object.keys(packages)) {
94-
console.log(chalk.green(`Reading dependencies of "${packageName}".`));
94+
console.log(terminal.green(`Reading dependencies of "${packageName}".`));
9595

9696
const allSources = glob.sync(path.join(__dirname, '../../packages/', packageName, '**/*'))
9797
.filter(p => p.match(/\.(js|ts)$/))
@@ -117,7 +117,7 @@ for (const packageName of Object.keys(packages)) {
117117
.filter(x => NODE_PACKAGES.indexOf(x) == -1);
118118
overallDeps.push(...dependencies);
119119

120-
console.log(chalk.green(` found ${dependencies.length} dependencies...`));
120+
console.log(terminal.green(` found ${dependencies.length} dependencies...`));
121121
const packageJson = JSON.parse(fs.readFileSync(packages[packageName].packageJson, 'utf8'));
122122
const allDeps = []
123123
.concat(Object.keys(packageJson['dependencies'] || {}))
@@ -136,7 +136,7 @@ for (const packageName of Object.keys(packages)) {
136136
console.log('');
137137
}
138138

139-
console.log(chalk.green('Validating root package. [devDependencies ignored]'));
139+
console.log(terminal.green('Validating root package. [devDependencies ignored]'));
140140
const rootPackagePath = path.join(__dirname, '../../package.json');
141141
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackagePath, 'utf8'));
142142
// devDependencies are ignored

scripts/test-commit-messages.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ require('../lib/bootstrap-local');
44

55
const validateCommitMessage = require('./validate-commit-message');
66
const execSync = require('child_process').execSync;
7-
const chalk = require('chalk');
8-
const { logging } = require('@angular-devkit/core');
7+
const { logging, terminal } = require('@angular-devkit/core');
98
const Logger = logging.Logger;
109
const filter = require('rxjs/operators').filter;
1110

1211
// Configure logger
1312
const logger = new Logger('test-commit-messages');
1413

1514
logger.subscribe((entry) => {
16-
let color = chalk.white;
15+
let color = terminal.white;
1716
let output = process.stdout;
1817
switch (entry.level) {
19-
case 'info': color = chalk.white; break;
20-
case 'warn': color = chalk.yellow; break;
21-
case 'error': color = chalk.red; output = process.stderr; break;
22-
case 'fatal': color = (x) => chalk.bold(chalk.red(x)); output = process.stderr; break;
18+
case 'info': color = terminal.white; break;
19+
case 'warn': color = terminal.yellow; break;
20+
case 'error': color = terminal.red; output = process.stderr; break;
21+
case 'fatal': color = (x) => terminal.bold(terminal.red(x)); output = process.stderr; break;
2322
}
2423

2524
output.write(color(entry.message) + '\n');

0 commit comments

Comments
 (0)