Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@ngtools/webpack): don't show loader errors after compilation fails #7575

Merged
merged 1 commit into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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