Skip to content

Commit

Permalink
fix(@ngtools/webpack): don't show loader errors after compilation fai…
Browse files Browse the repository at this point in the history
…ls (#7575)
  • Loading branch information
filipesilva committed Sep 6, 2017
1 parent 57d7246 commit 6bcdcfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/@ngtools/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,14 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
});

const result = refactor.transpile(compilerOptions);
cb(null, result.outputText, result.sourceMap);

if (plugin.failedCompilation) {
// Return an empty string to prevent extra loader errors (missing imports etc).
// Plugin errors were already pushed to the compilation errors.
cb(null, '');
} else {
cb(null, result.outputText, result.sourceMap);
}
})
.catch(err => cb(err));
} else {
Expand Down
12 changes: 10 additions & 2 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class AotPlugin implements Tapable {
private _donePromise: Promise<void> | null;
private _compiler: any = null;
private _compilation: any = null;
private _failedCompilation = false;

private _typeCheck = true;
private _skipCodeGeneration = false;
Expand All @@ -87,6 +88,7 @@ export class AotPlugin implements Tapable {
get compilerHost() { return this._compilerHost; }
get compilerOptions() { return this._compilerOptions; }
get done() { return this._donePromise; }
get failedCompilation() { return this._failedCompilation; }
get entryModule() {
const splitted = this._entryModule.split('#');
const path = splitted[0];
Expand Down Expand Up @@ -374,11 +376,14 @@ export class AotPlugin implements Tapable {

compiler.plugin('make', (compilation: any, cb: any) => this._make(compilation, cb));
compiler.plugin('after-emit', (compilation: any, cb: any) => {
this._donePromise = null;
this._compilation = null;
compilation._ngToolsWebpackPluginInstance = null;
cb();
});
compiler.plugin('done', () => {
this._donePromise = null;
this._compilation = null;
this._failedCompilation = false;
});

compiler.plugin('after-resolvers', (compiler: any) => {
// Virtual file system.
Expand Down Expand Up @@ -578,10 +583,13 @@ export class AotPlugin implements Tapable {
.then(() => {
if (this._compilation.errors == 0) {
this._compilerHost.resetChangedFileTracker();
} else {
this._failedCompilation = true;
}

cb();
}, (err: any) => {
this._failedCompilation = true;
compilation.errors.push(err.stack);
cb();
});
Expand Down

0 comments on commit 6bcdcfb

Please sign in to comment.