Skip to content

Commit 1cccfef

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@ngtools/webpack): implement getModifiedResourceFiles for Ivy AOT
This method enables the Ivy incremental compiler to track changes to resource files and their requisites.
1 parent d0c6181 commit 1cccfef

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/compiler_host.ts

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
3232
private _syncHost: virtualFs.SyncDelegateHost;
3333
private _memoryHost: virtualFs.SyncDelegateHost;
3434
private _changedFiles = new Set<string>();
35+
private _readResourceFiles = new Set<string>();
3536
private _basePath: Path;
3637
private _resourceLoader?: WebpackResourceLoader;
3738
private _sourceFileCache = new Map<string, ts.SourceFile>();
@@ -341,6 +342,8 @@ export class WebpackCompilerHost implements ts.CompilerHost {
341342
}
342343

343344
readResource(fileName: string) {
345+
this._readResourceFiles.add(fileName);
346+
344347
if (this.directTemplateLoading &&
345348
(fileName.endsWith('.html') || fileName.endsWith('.svg'))) {
346349
return this.readFile(fileName);
@@ -356,6 +359,25 @@ export class WebpackCompilerHost implements ts.CompilerHost {
356359
}
357360
}
358361

362+
getModifiedResourceFiles(): Set<string> {
363+
const modifiedFiles = new Set<string>();
364+
365+
for (const changedFile of this._changedFiles) {
366+
if (this._readResourceFiles.has(changedFile)) {
367+
modifiedFiles.add(changedFile);
368+
}
369+
370+
if (!this._resourceLoader) {
371+
continue;
372+
}
373+
for (const resourcePath of this._resourceLoader.getAffectedResources(changedFile)) {
374+
modifiedFiles.add(resourcePath);
375+
}
376+
}
377+
378+
return modifiedFiles;
379+
}
380+
359381
trace(message: string) {
360382
console.log(message);
361383
}

src/resource_loader.ts

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class WebpackResourceLoader {
2727
private _parentCompilation: any;
2828
private _context: string;
2929
private _fileDependencies = new Map<string, string[]>();
30+
private _reverseDependencies = new Map<string, string[]>();
3031
private _cachedSources = new Map<string, string>();
3132
private _cachedEvaluatedSources = new Map<string, RawSource>();
3233

@@ -41,6 +42,10 @@ export class WebpackResourceLoader {
4142
return this._fileDependencies.get(filePath) || [];
4243
}
4344

45+
getAffectedResources(file: string) {
46+
return this._reverseDependencies.get(file) || [];
47+
}
48+
4449
private _compile(filePath: string): Promise<CompilationOutput> {
4550

4651
if (!this._parentCompilation) {
@@ -117,6 +122,14 @@ export class WebpackResourceLoader {
117122

118123
// Save the dependencies for this resource.
119124
this._fileDependencies.set(filePath, childCompilation.fileDependencies);
125+
for (const file of childCompilation.fileDependencies) {
126+
const entry = this._reverseDependencies.get(file);
127+
if (entry) {
128+
entry.push(filePath);
129+
} else {
130+
this._reverseDependencies.set(file, [filePath]);
131+
}
132+
}
120133

121134
const compilationHash = childCompilation.fullHash;
122135
const maybeSource = this._cachedSources.get(compilationHash);

0 commit comments

Comments
 (0)