Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f481ba4

Browse files
committedAug 14, 2020
fix(@angular-devkit/build-angular): don't log blank warnings in console
Closes #18524 (cherry picked from commit 155707a)
1 parent e82adfc commit f481ba4

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed
 

‎packages/angular_devkit/build_angular/src/angular-cli-files/utilities/stats.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ export function statsToString(json: any, statsConfig: any) {
8787
}
8888

8989
// TODO(#16193): Don't emit this warning in the first place rather than just suppressing it.
90-
const ERRONEOUS_WARNINGS = [
90+
const ERRONEOUS_WARNINGS_FILTER = (warning: string) => ![
9191
/multiple assets emit different content.*3rdpartylicenses\.txt/i,
92-
];
93-
export function statsWarningsToString(json: any, statsConfig: any) {
92+
].some(msg => msg.test(warning));
93+
94+
export function statsWarningsToString(json: any, statsConfig: any): string {
9495
const colors = statsConfig.colors;
9596
const rs = (x: string) => colors ? reset(x) : x;
9697
const y = (x: string) => colors ? bold(yellow(x)) : x;
@@ -104,12 +105,12 @@ export function statsWarningsToString(json: any, statsConfig: any) {
104105

105106
return rs('\n' + warnings
106107
.map((warning: any) => `${warning}`)
107-
.filter((warning: string) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
108+
.filter(ERRONEOUS_WARNINGS_FILTER)
108109
.map((warning: string) => y(`WARNING in ${warning}`))
109110
.join('\n\n'));
110111
}
111112

112-
export function statsErrorsToString(json: any, statsConfig: any) {
113+
export function statsErrorsToString(json: any, statsConfig: any): string {
113114
const colors = statsConfig.colors;
114115
const rs = (x: string) => colors ? reset(x) : x;
115116
const r = (x: string) => colors ? bold(red(x)) : x;
@@ -120,16 +121,18 @@ export function statsErrorsToString(json: any, statsConfig: any) {
120121
.reduce((a: string[], b: string[]) => [...a, ...b], [])
121122
);
122123
}
124+
123125
return rs('\n' + errors
124126
.map((error: any) => r(`ERROR in ${error}`))
125127
.join('\n\n')
126128
);
127129
}
128130

129131
export function statsHasErrors(json: any): boolean {
130-
return json.errors.length > 0 || !!json.children?.some((c: any) => c.errors.length);
132+
return json.errors.length || !!json.children?.some((c: any) => c.errors.length);
131133
}
132134

133135
export function statsHasWarnings(json: any): boolean {
134-
return json.warnings.length > 0 || !!json.children?.some((c: any) => c.warnings.length);
136+
return json.warnings.filter(ERRONEOUS_WARNINGS_FILTER).length ||
137+
!!json.children?.some((c: any) => c.warnings.filter(ERRONEOUS_WARNINGS_FILTER).length);
135138
}

‎packages/angular_devkit/build_angular/src/browser/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export function createBrowserLoggingCallback(
101101
logger.info(statsToString(json, config.stats));
102102
}
103103

104-
if (stats.hasWarnings()) {
104+
if (statsHasWarnings(json)) {
105105
logger.warn(statsWarningsToString(json, config.stats));
106106
}
107-
if (stats.hasErrors()) {
107+
if (statsHasErrors(json)) {
108108
logger.error(statsErrorsToString(json, config.stats));
109109
}
110110
};

‎packages/angular_devkit/build_angular/src/extract-i18n/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
getStatsConfig,
2121
getStylesConfig,
2222
} from '../angular-cli-files/models/webpack-configs';
23-
import { statsErrorsToString, statsWarningsToString } from '../angular-cli-files/utilities/stats';
23+
import { statsErrorsToString, statsHasErrors, statsHasWarnings, statsWarningsToString } from '../angular-cli-files/utilities/stats';
2424
import { Schema as BrowserBuilderOptions } from '../browser/schema';
2525
import { createI18nOptions } from '../utils/i18n-options';
2626
import { assertCompatibleAngularVersion } from '../utils/version';
@@ -127,11 +127,11 @@ export async function execute(
127127
const logging: WebpackLoggingCallback = (stats, config) => {
128128
const json = stats.toJson({ errors: true, warnings: true });
129129

130-
if (stats.hasWarnings()) {
130+
if (statsHasWarnings(json)) {
131131
context.logger.warn(statsWarningsToString(json, config.stats));
132132
}
133133

134-
if (stats.hasErrors()) {
134+
if (statsHasErrors(json)) {
135135
context.logger.error(statsErrorsToString(json, config.stats));
136136
}
137137
};

0 commit comments

Comments
 (0)
Please sign in to comment.