diff --git a/etc/api/angular_devkit/core/src/_golden-api.d.ts b/etc/api/angular_devkit/core/src/_golden-api.d.ts index bd578e135b04..6e2467db8a5f 100644 --- a/etc/api/angular_devkit/core/src/_golden-api.d.ts +++ b/etc/api/angular_devkit/core/src/_golden-api.d.ts @@ -992,6 +992,7 @@ export declare class SimpleMemoryHost implements Host<{}> { list(path: Path): Observable; read(path: Path): Observable; rename(from: Path, to: Path): Observable; + reset(): void; stat(path: Path): Observable | null> | null; watch(path: Path, options?: HostWatchOptions): Observable | null; write(path: Path, content: FileBuffer): Observable; diff --git a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts index 02fb40b869d2..ca80bc7ea916 100644 --- a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts +++ b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts @@ -371,4 +371,9 @@ export class SimpleMemoryHost implements Host<{}> { watch(path: Path, options?: HostWatchOptions): Observable | null { return this._watch(path, options); } + + reset(): void { + this._cache.clear(); + this._watchers.clear(); + } } diff --git a/packages/ngtools/webpack/src/angular_compiler_plugin.ts b/packages/ngtools/webpack/src/angular_compiler_plugin.ts index 7a9e642d2d94..45f6a0c5af11 100644 --- a/packages/ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/ngtools/webpack/src/angular_compiler_plugin.ts @@ -672,6 +672,7 @@ export class AngularCompilerPlugin { this._program = null; this._transformers = []; this._resourceLoader = undefined; + this._compilerHost.reset(); } }); }); diff --git a/packages/ngtools/webpack/src/compiler_host.ts b/packages/ngtools/webpack/src/compiler_host.ts index 042195b96e32..ff943bc5256c 100644 --- a/packages/ngtools/webpack/src/compiler_host.ts +++ b/packages/ngtools/webpack/src/compiler_host.ts @@ -20,6 +20,7 @@ const dev = Math.floor(Math.random() * 10000); export class WebpackCompilerHost implements ts.CompilerHost { private _syncHost: virtualFs.SyncDelegateHost; + private _innerMemoryHost: virtualFs.SimpleMemoryHost; private _memoryHost: virtualFs.SyncDelegateHost; private _changedFiles = new Set(); private _readResourceFiles = new Set(); @@ -49,7 +50,8 @@ export class WebpackCompilerHost implements ts.CompilerHost { private readonly moduleResolutionCache?: ts.ModuleResolutionCache, ) { this._syncHost = new virtualFs.SyncDelegateHost(host); - this._memoryHost = new virtualFs.SyncDelegateHost(new virtualFs.SimpleMemoryHost()); + this._innerMemoryHost = new virtualFs.SimpleMemoryHost(); + this._memoryHost = new virtualFs.SyncDelegateHost(this._innerMemoryHost); this._basePath = normalize(basePath); } @@ -57,6 +59,14 @@ export class WebpackCompilerHost implements ts.CompilerHost { return [...((this._memoryHost.delegate as {}) as { _cache: Map })._cache.keys()]; } + reset() { + this._innerMemoryHost.reset(); + this._changedFiles.clear(); + this._readResourceFiles.clear(); + this._sourceFileCache.clear(); + this._resourceLoader = undefined; + } + denormalizePath(path: string) { return getSystemPath(normalize(path)); }