Skip to content

Commit f2f7d7c

Browse files
committedDec 12, 2023
fix(@angular-devkit/build-angular): file is missing from the TypeScript compilation with JIT
Before this update, removing the modified file entry from `typeScriptFileCache` when a file was saved but unmodified created an issue. The TypeScript compiler didn't re-emit the file using `emitNextAffectedFile` because the file hashes remained unchanged. Consequently, this led to missing files in the esbuild compilation process. In the current update, we no longer delete entries from typeScriptFileCache. This adjustment resolves the problem by ensuring the proper handling of file recompilation and prevents files from going missing during the esbuild compilation. Closes #26635 (cherry picked from commit 0f253a1)
1 parent 3623fe9 commit f2f7d7c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { concatMap, count, take, timeout } from 'rxjs';
10+
import { buildApplication } from '../../index';
11+
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
12+
13+
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
14+
describe('Behavior: "Rebuilds when touching file"', () => {
15+
for (const aot of [true, false]) {
16+
it(`Rebuild correctly when file is touched with ${aot ? 'AOT' : 'JIT'}`, async () => {
17+
harness.useTarget('build', {
18+
...BASE_OPTIONS,
19+
watch: true,
20+
aot,
21+
});
22+
23+
const buildCount = await harness
24+
.execute({ outputLogsOnFailure: false })
25+
.pipe(
26+
timeout(30_000),
27+
concatMap(async ({ result }, index) => {
28+
switch (index) {
29+
case 0:
30+
expect(result?.success).toBeTrue();
31+
// Touch a file without doing any changes.
32+
await harness.modifyFile('src/app/app.component.ts', (content) => content);
33+
break;
34+
case 1:
35+
expect(result?.success).toBeTrue();
36+
await harness.removeFile('src/app/app.component.ts');
37+
break;
38+
case 2:
39+
expect(result?.success).toBeFalse();
40+
break;
41+
}
42+
}),
43+
take(3),
44+
count(),
45+
)
46+
.toPromise();
47+
48+
expect(buildCount).toBe(3);
49+
});
50+
}
51+
});
52+
});

‎packages/angular_devkit/build_angular/src/tools/esbuild/angular/source-file-cache.ts

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class SourceFileCache extends Map<string, ts.SourceFile> {
3131
}
3232
for (let file of files) {
3333
file = path.normalize(file);
34-
this.typeScriptFileCache.delete(file);
3534
this.loadResultCache.invalidate(file);
3635

3736
// Normalize separators to allow matching TypeScript Host paths

0 commit comments

Comments
 (0)
Please sign in to comment.