Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): show child compilation errors
Browse files Browse the repository at this point in the history
Closes #17565

(cherry picked from commit 64a2686)
  • Loading branch information
alan-agius4 committed Jul 3, 2020
1 parent 00f74ce commit f7cbea5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ export function statsWarningsToString(json: any, statsConfig: any) {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const y = (x: string) => colors ? bold(yellow(x)) : x;
const warnings = [...json.warnings];
if (json.children) {
warnings.push(...json.children.map((c: any) => c.warnings));
}

return rs('\n' + json.warnings
return rs('\n' + warnings
.map((warning: any) => `${warning}`)
.filter((warning: string) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
.map((warning: string) => y(`WARNING in ${warning}`))
Expand All @@ -106,6 +110,18 @@ export function statsErrorsToString(json: any, statsConfig: any) {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const r = (x: string) => colors ? bold(red(x)) : x;
const errors = [...json.errors];
if (json.children) {
errors.push(...json.children.map((c: any) => c.errors));
}

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

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

return rs('\n' + json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n'));
export function statsHasWarnings(json: any): boolean {
return json.warnings.length > 0 || !!json.children?.some((c: any) => c.warnings.length);
}
11 changes: 6 additions & 5 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
generateBuildStats,
generateBundleStats,
statsErrorsToString,
statsHasErrors,
statsHasWarnings,
statsToString,
statsWarningsToString,
} from '../angular-cli-files/utilities/stats';
Expand Down Expand Up @@ -302,10 +304,10 @@ export function buildWebpackBrowser(
if (!success && useBundleDownleveling) {
// If using bundle downleveling then there is only one build
// If it fails show any diagnostic messages and bail
if (webpackStats && webpackStats.warnings.length > 0) {
if (statsHasWarnings(webpackStats)) {
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
}
if (webpackStats && webpackStats.errors.length > 0) {
if (statsHasErrors(webpackStats)) {
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));
}

Expand Down Expand Up @@ -662,14 +664,13 @@ export function buildWebpackBrowser(
break;
default:
assertNever(severity);
break;
}
}

if (webpackStats && webpackStats.warnings.length > 0) {
if (statsHasWarnings(webpackStats)) {
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
}
if (webpackStats && webpackStats.errors.length > 0) {
if (statsHasErrors(webpackStats)) {
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));

return { success: false };
Expand Down

0 comments on commit f7cbea5

Please sign in to comment.