Skip to content

Commit ca98b2b

Browse files
filipesilvahansl
authored andcommitted
fix(@angular/cli): show warnings on serve
Errors and warnings neet to be printed separately. Followup to #6989 Fix #7213
1 parent 90a14d5 commit ca98b2b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

packages/@angular/cli/tasks/build.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
77
import { NgCliWebpackConfig } from '../models/webpack-config';
88
import { getWebpackStatsConfig } from '../models/webpack-configs/utils';
99
import { CliConfig } from '../models/config';
10-
import {statsToString} from '../utilities/stats';
10+
import { statsToString, statsWarningsToString, statsErrorsToString } from '../utilities/stats';
1111

1212
const Task = require('../ember-cli/lib/models/task');
1313
const SilentError = require('silent-error');
@@ -47,6 +47,13 @@ export default Task.extend({
4747
this.ui.writeLine(statsToString(json, statsConfig));
4848
}
4949

50+
if (stats.hasWarnings()) {
51+
this.ui.writeLine(statsWarningsToString(json, statsConfig));
52+
}
53+
if (stats.hasErrors()) {
54+
this.ui.writeError(statsErrorsToString(json, statsConfig));
55+
}
56+
5057
if (runTaskOptions.watch) {
5158
return;
5259
} else if (runTaskOptions.statsJson) {

packages/@angular/cli/tasks/serve.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
99
import { ServeTaskOptions } from '../commands/serve';
1010
import { CliConfig } from '../models/config';
1111
import { getAppFromConfig } from '../utilities/app-utils';
12-
import {statsToString} from '../utilities/stats';
12+
import { statsToString, statsWarningsToString, statsErrorsToString } from '../utilities/stats';
1313

1414
const WebpackDevServer = require('webpack-dev-server');
1515
const Task = require('../ember-cli/lib/models/task');
@@ -215,13 +215,13 @@ export default Task.extend({
215215
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
216216
if (!serveTaskOptions.verbose) {
217217
webpackCompiler.plugin('done', (stats: any) => {
218-
const str = statsToString(stats.toJson(), statsConfig);
218+
const json = stats.toJson('verbose');
219+
this.ui.writeLine(statsToString(json, statsConfig));
220+
if (stats.hasWarnings()) {
221+
this.ui.writeLine(statsWarningsToString(json, statsConfig));
222+
}
219223
if (stats.hasErrors()) {
220-
this.ui.writeError(str);
221-
} else if (stats.hasWarnings()) {
222-
this.ui.writeWarnLine(str);
223-
} else {
224-
this.ui.writeLine(str);
224+
this.ui.writeError(statsErrorsToString(json, statsConfig));
225225
}
226226
});
227227
}

packages/@angular/cli/utilities/stats.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold, green, reset, white, yellow } from 'chalk';
1+
import { bold, green, red, reset, white, yellow } from 'chalk';
22
import { stripIndents } from 'common-tags';
33

44

@@ -16,12 +16,12 @@ function _formatSize(size: number): string {
1616

1717
export function statsToString(json: any, statsConfig: any) {
1818
const colors = statsConfig.colors;
19-
const r = (x: string) => colors ? reset(x) : x;
19+
const rs = (x: string) => colors ? reset(x) : x;
2020
const w = (x: string) => colors ? bold(white(x)) : x;
2121
const g = (x: string) => colors ? bold(green(x)) : x;
2222
const y = (x: string) => colors ? bold(yellow(x)) : x;
2323

24-
return r(stripIndents`
24+
return rs(stripIndents`
2525
Date: ${w(new Date().toISOString())}
2626
Hash: ${w(json.hash)}
2727
Time: ${w('' + json.time)}ms
@@ -38,8 +38,21 @@ export function statsToString(json: any, statsConfig: any) {
3838
3939
return `chunk {${y(chunk.id)}} ${g(files)}${names}${size}${parents} ${initial}${flags}`;
4040
}).join('\n')}
41-
42-
${json.warnings.map((warning: any) => y(`WARNING in ${warning}`)).join('\n\n')}
43-
${json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n')}
4441
`);
4542
}
43+
44+
export function statsWarningsToString(json: any, statsConfig: any) {
45+
const colors = statsConfig.colors;
46+
const rs = (x: string) => colors ? reset(x) : x;
47+
const y = (x: string) => colors ? bold(yellow(x)) : x;
48+
49+
return rs('\n' + json.warnings.map((warning: any) => y(`WARNING in ${warning}`)).join('\n\n'));
50+
}
51+
52+
export function statsErrorsToString(json: any, statsConfig: any) {
53+
const colors = statsConfig.colors;
54+
const rs = (x: string) => colors ? reset(x) : x;
55+
const r = (x: string) => colors ? bold(red(x)) : x;
56+
57+
return rs('\n' + json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n'));
58+
}

0 commit comments

Comments
 (0)