Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): file is missing from the TypeScri…
Browse files Browse the repository at this point in the history
…pt 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)
  • Loading branch information
alan-agius4 committed Dec 12, 2023
1 parent 3623fe9 commit f2f7d7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
@@ -0,0 +1,52 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { concatMap, count, take, timeout } from 'rxjs';
import { buildApplication } from '../../index';
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';

describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
describe('Behavior: "Rebuilds when touching file"', () => {
for (const aot of [true, false]) {
it(`Rebuild correctly when file is touched with ${aot ? 'AOT' : 'JIT'}`, async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
watch: true,
aot,
});

const buildCount = await harness
.execute({ outputLogsOnFailure: false })
.pipe(
timeout(30_000),
concatMap(async ({ result }, index) => {
switch (index) {
case 0:
expect(result?.success).toBeTrue();
// Touch a file without doing any changes.
await harness.modifyFile('src/app/app.component.ts', (content) => content);
break;
case 1:
expect(result?.success).toBeTrue();
await harness.removeFile('src/app/app.component.ts');
break;
case 2:
expect(result?.success).toBeFalse();
break;
}
}),
take(3),
count(),
)
.toPromise();

expect(buildCount).toBe(3);
});
}
});
});
Expand Up @@ -31,7 +31,6 @@ export class SourceFileCache extends Map<string, ts.SourceFile> {
}
for (let file of files) {
file = path.normalize(file);
this.typeScriptFileCache.delete(file);
this.loadResultCache.invalidate(file);

// Normalize separators to allow matching TypeScript Host paths
Expand Down

0 comments on commit f2f7d7c

Please sign in to comment.