Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): don't log blank warnings in console
Browse files Browse the repository at this point in the history
Closes #18524

(cherry picked from commit 155707a)
  • Loading branch information
alan-agius4 committed Aug 14, 2020
1 parent e82adfc commit f481ba4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ export function statsToString(json: any, statsConfig: any) {
}

// TODO(#16193): Don't emit this warning in the first place rather than just suppressing it.
const ERRONEOUS_WARNINGS = [
const ERRONEOUS_WARNINGS_FILTER = (warning: string) => ![
/multiple assets emit different content.*3rdpartylicenses\.txt/i,
];
export function statsWarningsToString(json: any, statsConfig: any) {
].some(msg => msg.test(warning));

export function statsWarningsToString(json: any, statsConfig: any): string {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const y = (x: string) => colors ? bold(yellow(x)) : x;
Expand All @@ -104,12 +105,12 @@ export function statsWarningsToString(json: any, statsConfig: any) {

return rs('\n' + warnings
.map((warning: any) => `${warning}`)
.filter((warning: string) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
.filter(ERRONEOUS_WARNINGS_FILTER)
.map((warning: string) => y(`WARNING in ${warning}`))
.join('\n\n'));
}

export function statsErrorsToString(json: any, statsConfig: any) {
export function statsErrorsToString(json: any, statsConfig: any): string {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const r = (x: string) => colors ? bold(red(x)) : x;
Expand All @@ -120,16 +121,18 @@ export function statsErrorsToString(json: any, statsConfig: any) {
.reduce((a: string[], b: string[]) => [...a, ...b], [])
);
}

return rs('\n' + errors
.map((error: any) => r(`ERROR in ${error}`))
.join('\n\n')
);
}

export function statsHasErrors(json: any): boolean {
return json.errors.length > 0 || !!json.children?.some((c: any) => c.errors.length);
return json.errors.length || !!json.children?.some((c: any) => c.errors.length);
}

export function statsHasWarnings(json: any): boolean {
return json.warnings.length > 0 || !!json.children?.some((c: any) => c.warnings.length);
return json.warnings.filter(ERRONEOUS_WARNINGS_FILTER).length ||
!!json.children?.some((c: any) => c.warnings.filter(ERRONEOUS_WARNINGS_FILTER).length);
}
4 changes: 2 additions & 2 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ export function createBrowserLoggingCallback(
logger.info(statsToString(json, config.stats));
}

if (stats.hasWarnings()) {
if (statsHasWarnings(json)) {
logger.warn(statsWarningsToString(json, config.stats));
}
if (stats.hasErrors()) {
if (statsHasErrors(json)) {
logger.error(statsErrorsToString(json, config.stats));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getStatsConfig,
getStylesConfig,
} from '../angular-cli-files/models/webpack-configs';
import { statsErrorsToString, statsWarningsToString } from '../angular-cli-files/utilities/stats';
import { statsErrorsToString, statsHasErrors, statsHasWarnings, statsWarningsToString } from '../angular-cli-files/utilities/stats';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { createI18nOptions } from '../utils/i18n-options';
import { assertCompatibleAngularVersion } from '../utils/version';
Expand Down Expand Up @@ -127,11 +127,11 @@ export async function execute(
const logging: WebpackLoggingCallback = (stats, config) => {
const json = stats.toJson({ errors: true, warnings: true });

if (stats.hasWarnings()) {
if (statsHasWarnings(json)) {
context.logger.warn(statsWarningsToString(json, config.stats));
}

if (stats.hasErrors()) {
if (statsHasErrors(json)) {
context.logger.error(statsErrorsToString(json, config.stats));
}
};
Expand Down

0 comments on commit f481ba4

Please sign in to comment.