Skip to content

Commit 4bdb0c4

Browse files
filipesilvaalexeagle
authored andcommitted
fix(@ngtools/webpack): only invalidate related virtual files
1 parent e36cdc0 commit 4bdb0c4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

packages/ngtools/webpack/src/compiler_host.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export class WebpackCompilerHost implements ts.CompilerHost {
3333
private _basePath: Path;
3434
private _resourceLoader?: WebpackResourceLoader;
3535
private _sourceFileCache = new Map<string, ts.SourceFile>();
36+
private _virtualFileExtensions = [
37+
'.js', '.js.map',
38+
'.ngfactory.js', '.ngfactory.js.map',
39+
'.ngstyle.js', '.ngstyle.js.map',
40+
'.ngsummary.json',
41+
];
42+
3643

3744
constructor(
3845
private _options: ts.CompilerOptions,
@@ -79,19 +86,24 @@ export class WebpackCompilerHost implements ts.CompilerHost {
7986

8087
invalidate(fileName: string): void {
8188
const fullPath = this.resolve(fileName);
82-
83-
if (this._memoryHost.exists(fullPath)) {
84-
this._memoryHost.delete(fullPath);
85-
}
86-
8789
this._sourceFileCache.delete(fullPath);
8890

8991
try {
9092
const exists = this._syncHost.isFile(fullPath);
9193
if (exists) {
9294
this._changedFiles.add(fullPath);
9395
}
94-
} catch { }
96+
} catch {
97+
// File doesn't exist anymore, so we should delete the related virtual files.
98+
if (fullPath.endsWith('.ts')) {
99+
this._virtualFileExtensions.forEach(ext => {
100+
const virtualFile = fullPath.replace(/\.ts$/, ext) as Path;
101+
if (this._memoryHost.exists(virtualFile)) {
102+
this._memoryHost.delete(virtualFile);
103+
}
104+
});
105+
}
106+
}
95107
}
96108

97109
fileExists(fileName: string, delegate = true): boolean {

0 commit comments

Comments
 (0)