Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): print server builder errors and w…
Browse files Browse the repository at this point in the history
…arnings

Previously server builder errors and warnings were not being printed in the console correctly.

Closes #24612

(cherry picked from commit f35e990)
  • Loading branch information
alan-agius4 authored and clydin committed Jan 26, 2023
1 parent b27ce5d commit 317452e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
19 changes: 16 additions & 3 deletions packages/angular_devkit/build_angular/src/builders/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ import {
} from '../../utils/webpack-browser-config';
import { getCommonConfig, getStylesConfig } from '../../webpack/configs';
import { isPlatformServerInstalled } from '../../webpack/utils/helpers';
import { webpackStatsLogger } from '../../webpack/utils/stats';
import {
statsErrorsToString,
statsHasErrors,
statsHasWarnings,
statsWarningsToString,
webpackStatsLogger,
} from '../../webpack/utils/stats';
import { Schema as ServerBuilderOptions } from './schema';

/**
Expand Down Expand Up @@ -87,12 +93,19 @@ export function execute(
},
}).pipe(
concatMap(async (output) => {
const { emittedFiles = [], outputPath, webpackStats } = output;
const { emittedFiles = [], outputPath, webpackStats, success } = output;
if (!webpackStats) {
throw new Error('Webpack stats build result is required.');
}

if (!output.success) {
if (!success) {
if (statsHasWarnings(webpackStats)) {
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
}
if (statsHasErrors(webpackStats)) {
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));
}

return output;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { logging } from '@angular-devkit/core';
import { execute } from '../../index';
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';

describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
describe('Behavior: "Build Error"', () => {
it('emits errors', async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
watch: true,
});

// Generate an error
await harness.appendToFile('src/main.server.ts', `const foo: = 'abc';`);

const { result, logs } = await harness.executeOnce();

expect(result?.success).toBeFalse();
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching(/TS1110:.*Type expected/),
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';
describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
describe('Behavior: "Errors"', () => {
it('should not try to resolve web-workers', async () => {
harness.useTarget('test', {
harness.useTarget('server', {
...BASE_OPTIONS,
});

await harness.writeFiles({
'src/app/app.worker.ts': `
/// <reference lib="webworker" />
const foo: string = 'hello world';
addEventListener('message', ({ data }) => {
postMessage(foo);
Expand Down

0 comments on commit 317452e

Please sign in to comment.