Skip to content

Commit

Permalink
fix(@ngtools/webpack): gracefully show error when compiling broken co…
Browse files Browse the repository at this point in the history
…mponent styles

Fixes #15240
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Aug 6, 2019
1 parent fd2c264 commit c18ba5f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,32 @@ describe('Browser Builder AOT', () => {
expect(logs.join()).toContain('WARNING in Invalid selector');
await run.stop();
});

it('shows error when component stylesheet contains SCSS syntax error', async () => {
const overrides = {
aot: true,
};

host.replaceInFile(
'src/app/app.component.ts',
'app.component.css',
'app.component.scss',
);

host.writeMultipleFiles({
'src/app/app.component.scss': `
.foo {
`,
});

const logger = new logging.Logger('');
const logs: string[] = [];
logger.subscribe(e => logs.push(e.message));

const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
const output = await run.result;
expect(output.success).toBe(false);
expect(logs.join()).toContain(`Expected "}".`);
await run.stop();
});
});
8 changes: 6 additions & 2 deletions packages/ngtools/webpack/src/resource_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export class WebpackResourceLoader {
// Compile and return a promise
return new Promise((resolve, reject) => {
childCompiler.compile((err: Error, childCompilation: any) => {
if (err) {
reject(err);

return;
}

// Resolve / reject the promise
const { warnings, errors } = childCompilation;

Expand All @@ -114,8 +120,6 @@ export class WebpackResourceLoader {
.join('\n');

reject(new Error('Child compilation failed:\n' + errorDetails));
} else if (err) {
reject(err);
} else {
Object.keys(childCompilation.assets).forEach(assetName => {
// Add all new assets to the parent compilation, with the exception of
Expand Down

0 comments on commit c18ba5f

Please sign in to comment.