Skip to content

Commit f5f9687

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): format post-bundle diagnostic messages for esbuild builders
Any errors or warnings generated from post-bundling steps of the build will now be formatted and displayed in a similar manner to the bundling errors and warnings. This should be most noticeable with bundle budgets. (cherry picked from commit f4aebf5)
1 parent d5ec585 commit f5f9687

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

packages/angular_devkit/build_angular/src/builders/application/execute-build.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ export async function executeBuild(
206206
if (options.budgets) {
207207
const compatStats = generateBudgetStats(metafile, initialFiles);
208208
budgetFailures = [...checkBudgets(options.budgets, compatStats, true)];
209-
for (const { severity, message } of budgetFailures) {
210-
if (severity === 'error') {
211-
context.logger.error(message);
212-
} else {
213-
context.logger.warn(message);
214-
}
209+
if (budgetFailures.length > 0) {
210+
await logMessages(context, {
211+
errors: budgetFailures
212+
.filter((failure) => failure.severity === 'error')
213+
.map((failure) => ({ text: failure.message, location: null })),
214+
warnings: budgetFailures
215+
.filter((failure) => failure.severity !== 'error')
216+
.map((failure) => ({ text: failure.message, location: null })),
217+
});
215218
}
216219
}
217220

@@ -255,7 +258,7 @@ export async function executeBuild(
255258
);
256259
}
257260

258-
printWarningsAndErrorsToConsole(context, warnings, errors);
261+
await printWarningsAndErrorsToConsole(context, warnings, errors);
259262
const changedFiles =
260263
rebuildState && executionResult.findChangedFiles(rebuildState.previousOutputHashes);
261264
logBuildStats(
@@ -279,15 +282,13 @@ export async function executeBuild(
279282
return executionResult;
280283
}
281284

282-
function printWarningsAndErrorsToConsole(
285+
async function printWarningsAndErrorsToConsole(
283286
context: BuilderContext,
284287
warnings: string[],
285288
errors: string[],
286-
): void {
287-
for (const error of errors) {
288-
context.logger.error(error);
289-
}
290-
for (const warning of warnings) {
291-
context.logger.warn(warning);
292-
}
289+
): Promise<void> {
290+
await logMessages(context, {
291+
errors: errors.map((text) => ({ text, location: null })),
292+
warnings: warnings.map((text) => ({ text, location: null })),
293+
});
293294
}

packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function extractMessages(
3737
buildOptions.optimization = false;
3838
buildOptions.sourceMap = { scripts: true, vendor: true };
3939
buildOptions.localize = false;
40+
buildOptions.budgets = undefined;
4041

4142
let build;
4243
if (builderName === '@angular-devkit/build-angular:application') {

tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default async function () {
4343
// Should not show any warnings when extracting
4444
const { stderr: message5 } = await ng('extract-i18n');
4545
if (message5.includes('WARNING')) {
46-
throw new Error('Expected no warnings to be shown');
46+
throw new Error('Expected no warnings to be shown. STDERR:\n' + message5);
4747
}
4848

4949
await expectFileToMatch('messages.xlf', 'Hello world');

0 commit comments

Comments
 (0)