Skip to content

Commit 317452e

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular-devkit/build-angular): print server builder errors and warnings
Previously server builder errors and warnings were not being printed in the console correctly. Closes #24612 (cherry picked from commit f35e990)
1 parent b27ce5d commit 317452e

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

packages/angular_devkit/build_angular/src/builders/server/index.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ import {
3333
} from '../../utils/webpack-browser-config';
3434
import { getCommonConfig, getStylesConfig } from '../../webpack/configs';
3535
import { isPlatformServerInstalled } from '../../webpack/utils/helpers';
36-
import { webpackStatsLogger } from '../../webpack/utils/stats';
36+
import {
37+
statsErrorsToString,
38+
statsHasErrors,
39+
statsHasWarnings,
40+
statsWarningsToString,
41+
webpackStatsLogger,
42+
} from '../../webpack/utils/stats';
3743
import { Schema as ServerBuilderOptions } from './schema';
3844

3945
/**
@@ -87,12 +93,19 @@ export function execute(
8793
},
8894
}).pipe(
8995
concatMap(async (output) => {
90-
const { emittedFiles = [], outputPath, webpackStats } = output;
96+
const { emittedFiles = [], outputPath, webpackStats, success } = output;
9197
if (!webpackStats) {
9298
throw new Error('Webpack stats build result is required.');
9399
}
94100

95-
if (!output.success) {
101+
if (!success) {
102+
if (statsHasWarnings(webpackStats)) {
103+
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
104+
}
105+
if (statsHasErrors(webpackStats)) {
106+
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));
107+
}
108+
96109
return output;
97110
}
98111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { logging } from '@angular-devkit/core';
10+
import { execute } from '../../index';
11+
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';
12+
13+
describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
14+
describe('Behavior: "Build Error"', () => {
15+
it('emits errors', async () => {
16+
harness.useTarget('server', {
17+
...BASE_OPTIONS,
18+
watch: true,
19+
});
20+
21+
// Generate an error
22+
await harness.appendToFile('src/main.server.ts', `const foo: = 'abc';`);
23+
24+
const { result, logs } = await harness.executeOnce();
25+
26+
expect(result?.success).toBeFalse();
27+
expect(logs).toContain(
28+
jasmine.objectContaining<logging.LogEntry>({
29+
message: jasmine.stringMatching(/TS1110:.*Type expected/),
30+
}),
31+
);
32+
});
33+
});
34+
});

packages/angular_devkit/build_angular/src/builders/server/tests/behavior/web-workers_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';
1212
describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
1313
describe('Behavior: "Errors"', () => {
1414
it('should not try to resolve web-workers', async () => {
15-
harness.useTarget('test', {
15+
harness.useTarget('server', {
1616
...BASE_OPTIONS,
1717
});
1818

1919
await harness.writeFiles({
2020
'src/app/app.worker.ts': `
2121
/// <reference lib="webworker" />
22-
22+
2323
const foo: string = 'hello world';
2424
addEventListener('message', ({ data }) => {
2525
postMessage(foo);

0 commit comments

Comments
 (0)