MCPcopy
hub / github.com/angular/angular-cli / WebpackResourceLoader

Class WebpackResourceLoader

packages/ngtools/webpack/src/resource_loader.ts:29–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29export class WebpackResourceLoader {
30 private _parentCompilation?: Compilation;
31 private _fileDependencies = new Map<string, Set<string>>();
32 private _reverseDependencies = new Map<string, Set<string>>();
33
34 private fileCache?: Map<string, CompilationOutput>;
35 private assetCache?: Map<string, Asset>;
36
37 private modifiedResources = new Set<string>();
38 private outputPathCounter = 1;
39
40 private readonly inlineDataLoaderPath = InlineAngularResourceLoaderPath;
41
42 constructor(shouldCache: boolean) {
43 if (shouldCache) {
44 this.fileCache = new Map();
45 this.assetCache = new Map();
46 }
47 }
48
49 update(parentCompilation: Compilation, changedFiles?: Iterable<string>): void {
50 this._parentCompilation = parentCompilation;
51
52 // Update resource cache and modified resources
53 this.modifiedResources.clear();
54
55 if (changedFiles) {
56 for (const changedFile of changedFiles) {
57 const changedFileNormalized = normalizePath(changedFile);
58 this.assetCache?.delete(changedFileNormalized);
59
60 for (const affectedResource of this.getAffectedResources(changedFile)) {
61 const affectedResourceNormalized = normalizePath(affectedResource);
62 this.fileCache?.delete(affectedResourceNormalized);
63 this.modifiedResources.add(affectedResource);
64
65 for (const effectedDependencies of this.getResourceDependencies(
66 affectedResourceNormalized,
67 )) {
68 this.assetCache?.delete(normalizePath(effectedDependencies));
69 }
70 }
71 }
72 } else {
73 this.fileCache?.clear();
74 this.assetCache?.clear();
75 }
76
77 // Re-emit all assets for un-effected files
78 if (this.assetCache) {
79 for (const [, { name, source, info }] of this.assetCache) {
80 this._parentCompilation.emitAsset(name, source, info);
81 }
82 }
83 }
84
85 clearParentCompilation(): void {
86 this._parentCompilation = undefined;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected