Skip to content

Commit 28bd549

Browse files
alan-agius4vikerman
authored andcommitted
fix(@ngtools/webpack): retain child compilation warnings and errors
At the moment child compilation warnings and errors are being lost as they are not passed to the root compilation. This means that any errors that are being set by clean-css for component styles are being lost.
1 parent 21cd079 commit 28bd549

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

packages/angular_devkit/build_angular/test/browser/aot_spec_large.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { join, normalize, virtualFs } from '@angular-devkit/core';
10+
import { join, logging, normalize, virtualFs } from '@angular-devkit/core';
1111
import { BrowserBuilderOutput } from '../../src/browser';
1212
import { createArchitect, host, ivyEnabled } from '../utils';
1313

@@ -39,4 +39,28 @@ describe('Browser Builder AOT', () => {
3939

4040
await run.stop();
4141
});
42+
43+
it('shows warnings for component styles', async () => {
44+
const overrides = {
45+
aot: true,
46+
optimization: true,
47+
};
48+
49+
host.writeMultipleFiles({
50+
'src/app/app.component.css': `
51+
.foo { color: white; padding: 1px; };
52+
.buz { color: white; padding: 2px; };
53+
`,
54+
});
55+
56+
const logger = new logging.Logger('');
57+
const logs: string[] = [];
58+
logger.subscribe(e => logs.push(e.message));
59+
60+
const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
61+
const output = await run.result;
62+
expect(output.success).toBe(true);
63+
expect(logs.join()).toContain('WARNING in Invalid selector');
64+
await run.stop();
65+
});
4266
});

packages/ngtools/webpack/src/resource_loader.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,19 @@ export class WebpackResourceLoader {
100100
return new Promise((resolve, reject) => {
101101
childCompiler.compile((err: Error, childCompilation: any) => {
102102
// Resolve / reject the promise
103-
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
104-
const errorDetails = childCompilation.errors.map(function (error: any) {
105-
return error.message + (error.error ? ':\n' + error.error : '');
106-
}).join('\n');
103+
const { warnings, errors } = childCompilation;
104+
105+
if (warnings && warnings.length) {
106+
this._parentCompilation.warnings.push(...warnings);
107+
}
108+
109+
if (errors && errors.length) {
110+
this._parentCompilation.errors.push(...errors);
111+
112+
const errorDetails = errors
113+
.map((error: any) => error.message + (error.error ? ':\n' + error.error : ''))
114+
.join('\n');
115+
107116
reject(new Error('Child compilation failed:\n' + errorDetails));
108117
} else if (err) {
109118
reject(err);

0 commit comments

Comments
 (0)