Skip to content

Commit b0b3212

Browse files
clydinmgechev
authored andcommitted
fix(@ngtools/webpack): cleanup more resources after modules are loaded (#15292)
* feat(@angular-devkit/core): support resetting a memory host * fix(@ngtools/webpack): cleanup more resources after modules are loaded Followup to #12994
1 parent 64ff17d commit b0b3212

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

etc/api/angular_devkit/core/src/_golden-api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ export declare class SimpleMemoryHost implements Host<{}> {
992992
list(path: Path): Observable<PathFragment[]>;
993993
read(path: Path): Observable<FileBuffer>;
994994
rename(from: Path, to: Path): Observable<void>;
995+
reset(): void;
995996
stat(path: Path): Observable<Stats<{}> | null> | null;
996997
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null;
997998
write(path: Path, content: FileBuffer): Observable<void>;

packages/angular_devkit/core/src/virtual-fs/host/memory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,9 @@ export class SimpleMemoryHost implements Host<{}> {
371371
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null {
372372
return this._watch(path, options);
373373
}
374+
375+
reset(): void {
376+
this._cache.clear();
377+
this._watchers.clear();
378+
}
374379
}

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ export class AngularCompilerPlugin {
672672
this._program = null;
673673
this._transformers = [];
674674
this._resourceLoader = undefined;
675+
this._compilerHost.reset();
675676
}
676677
});
677678
});

packages/ngtools/webpack/src/compiler_host.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const dev = Math.floor(Math.random() * 10000);
2020

2121
export class WebpackCompilerHost implements ts.CompilerHost {
2222
private _syncHost: virtualFs.SyncDelegateHost;
23+
private _innerMemoryHost: virtualFs.SimpleMemoryHost;
2324
private _memoryHost: virtualFs.SyncDelegateHost;
2425
private _changedFiles = new Set<string>();
2526
private _readResourceFiles = new Set<string>();
@@ -49,14 +50,23 @@ export class WebpackCompilerHost implements ts.CompilerHost {
4950
private readonly moduleResolutionCache?: ts.ModuleResolutionCache,
5051
) {
5152
this._syncHost = new virtualFs.SyncDelegateHost(host);
52-
this._memoryHost = new virtualFs.SyncDelegateHost(new virtualFs.SimpleMemoryHost());
53+
this._innerMemoryHost = new virtualFs.SimpleMemoryHost();
54+
this._memoryHost = new virtualFs.SyncDelegateHost(this._innerMemoryHost);
5355
this._basePath = normalize(basePath);
5456
}
5557

5658
private get virtualFiles(): Path[] {
5759
return [...((this._memoryHost.delegate as {}) as { _cache: Map<Path, {}> })._cache.keys()];
5860
}
5961

62+
reset() {
63+
this._innerMemoryHost.reset();
64+
this._changedFiles.clear();
65+
this._readResourceFiles.clear();
66+
this._sourceFileCache.clear();
67+
this._resourceLoader = undefined;
68+
}
69+
6070
denormalizePath(path: string) {
6171
return getSystemPath(normalize(path));
6272
}

0 commit comments

Comments
 (0)