Skip to content

Commit

Permalink
fix(@ngtools/webpack): when an error happens rediagnose the file
Browse files Browse the repository at this point in the history
Before there was a bug that the file wasnt forced to rediagnose.

If the file changed, we wont diagnose it twice because we keep a hash table per compilation anyway.

Fixes angular#4810
Fixes angular#5404
  • Loading branch information
hansl committed Mar 17, 2017
1 parent 9b52253 commit 1a5c369
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ export class AotPlugin implements Tapable {
this._program = ts.createProgram(
this._rootFilePath, this._compilerOptions, this._compilerHost, this._program);
})
.then(() => {
// Re-diagnose changed files.
const changedFilePaths = this._compilerHost.getChangedFilePaths();
changedFilePaths.forEach(filePath => this.diagnose(filePath));
})
.then(() => {
if (this._typeCheck) {
const diagnostics = this._program.getGlobalDiagnostics();
Expand Down Expand Up @@ -461,7 +466,9 @@ export class AotPlugin implements Tapable {
});
})
.then(() => {
this._compilerHost.resetChangedFileTracker();
if (this._compilation.errors == 0) {
this._compilerHost.resetChangedFileTracker();
}

cb();
}, (err: any) => {
Expand Down
14 changes: 13 additions & 1 deletion tests/e2e/tests/build/rebuild-deps-type-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function() {
`))
// Should trigger a rebuild, no error expected.
.then(() => waitForAnyProcessOutputToMatch(doneRe, 10000))
// Create and import files.
// Make an invalid version of the file.
.then(() => wait(2000))
.then(() => writeFile('src/funky2.ts', `
export function funky(value: number): number {
Expand All @@ -54,6 +54,18 @@ export default function() {
throw new Error('Expected an error but none happened.');
}
})
// Change an UNRELATED file and the error should still happen.
.then(() => wait(2000))
.then(() => appendToFile('src/app/app.module.ts', `
function anything(): number {}
`))
// Should trigger a rebuild, this time an error is expected.
.then(() => waitForAnyProcessOutputToMatch(doneRe, 10000))
.then(({ stdout }) => {
if (!/ERROR in .*\/src\/main\.ts \(/.test(stdout)) {
throw new Error('Expected an error but none happened.');
}
})
// Fix the error!
.then(() => writeFile('src/funky2.ts', `
export function funky(value: string): string {
Expand Down

0 comments on commit 1a5c369

Please sign in to comment.