Skip to content

Commit 4bd8bd2

Browse files
committed
fix(@ngtools/webpack): when an error happens rediagnose the file
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 #4810 Fixes #5404
1 parent 9b52253 commit 4bd8bd2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/@ngtools/webpack/src/plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ export class AotPlugin implements Tapable {
410410
this._program = ts.createProgram(
411411
this._rootFilePath, this._compilerOptions, this._compilerHost, this._program);
412412
})
413+
.then(() => {
414+
// Re-diagnose changed files.
415+
const changedFilePaths = this._compilerHost.getChangedFilePaths();
416+
changedFilePaths.forEach(filePath => this.diagnose(filePath));
417+
})
413418
.then(() => {
414419
if (this._typeCheck) {
415420
const diagnostics = this._program.getGlobalDiagnostics();
@@ -461,7 +466,9 @@ export class AotPlugin implements Tapable {
461466
});
462467
})
463468
.then(() => {
464-
this._compilerHost.resetChangedFileTracker();
469+
if (this._compilation.errors == 0) {
470+
this._compilerHost.resetChangedFileTracker();
471+
}
465472

466473
cb();
467474
}, (err: any) => {

tests/e2e/tests/build/rebuild-deps-type-check.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function() {
4040
`))
4141
// Should trigger a rebuild, no error expected.
4242
.then(() => waitForAnyProcessOutputToMatch(doneRe, 10000))
43-
// Create and import files.
43+
// Make an invalid version of the file.
4444
.then(() => wait(2000))
4545
.then(() => writeFile('src/funky2.ts', `
4646
export function funky(value: number): number {
@@ -54,6 +54,18 @@ export default function() {
5454
throw new Error('Expected an error but none happened.');
5555
}
5656
})
57+
// Change an UNRELATED file and the error should still happen.
58+
.then(() => wait(2000))
59+
.then(() => appendToFile('src/app/app.module.ts', `
60+
function anything(): number {}
61+
`))
62+
// Should trigger a rebuild, this time an error is expected.
63+
.then(() => waitForAnyProcessOutputToMatch(doneRe, 10000))
64+
.then(({ stdout }) => {
65+
if (!/ERROR in .*\/src\/main\.ts \(/.test(stdout)) {
66+
throw new Error('Expected an error but none happened.');
67+
}
68+
})
5769
// Fix the error!
5870
.then(() => writeFile('src/funky2.ts', `
5971
export function funky(value: string): string {

0 commit comments

Comments
 (0)