Skip to content

Commit

Permalink
fix(@ngtools/webpack): only invalidate related virtual files
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and alexeagle committed Oct 19, 2018
1 parent 4a4cfb0 commit 231b62e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export class WebpackCompilerHost implements ts.CompilerHost {
private _basePath: Path;
private _resourceLoader?: WebpackResourceLoader;
private _sourceFileCache = new Map<string, ts.SourceFile>();
private _virtualFileExtensions = [
'.js', '.js.map',
'.ngfactory.js', '.ngfactory.js.map',
'.ngstyle.js', '.ngstyle.js.map',
'.ngsummary.json',
];


constructor(
private _options: ts.CompilerOptions,
Expand Down Expand Up @@ -79,19 +86,24 @@ export class WebpackCompilerHost implements ts.CompilerHost {

invalidate(fileName: string): void {
const fullPath = this.resolve(fileName);

if (this._memoryHost.exists(fullPath)) {
this._memoryHost.delete(fullPath);
}

this._sourceFileCache.delete(fullPath);

try {
const exists = this._syncHost.isFile(fullPath);
if (exists) {
this._changedFiles.add(fullPath);
}
} catch { }
} catch {
// File doesn't exist anymore, so we should delete the related virtual files.
if (fullPath.endsWith('.ts')) {
this._virtualFileExtensions.forEach(ext => {
const virtualFile = fullPath.replace(/\.ts$/, ext) as Path;
if (this._memoryHost.exists(virtualFile)) {
this._memoryHost.delete(virtualFile);
}
});
}
}
}

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

0 comments on commit 231b62e

Please sign in to comment.