Skip to content

Commit

Permalink
fix(@ngtools/webpack): implement getModifiedResourceFiles for Ivy AOT
Browse files Browse the repository at this point in the history
This method enables the Ivy incremental compiler to track changes to resource files and their requisites.
  • Loading branch information
clydin authored and kyliau committed Jun 13, 2019
1 parent 3d25d4c commit 0e339ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
private _syncHost: virtualFs.SyncDelegateHost;
private _memoryHost: virtualFs.SyncDelegateHost;
private _changedFiles = new Set<string>();
private _readResourceFiles = new Set<string>();
private _basePath: Path;
private _resourceLoader?: WebpackResourceLoader;
private _sourceFileCache = new Map<string, ts.SourceFile>();
Expand Down Expand Up @@ -341,6 +342,8 @@ export class WebpackCompilerHost implements ts.CompilerHost {
}

readResource(fileName: string) {
this._readResourceFiles.add(fileName);

if (this.directTemplateLoading &&
(fileName.endsWith('.html') || fileName.endsWith('.svg'))) {
return this.readFile(fileName);
Expand All @@ -356,6 +359,25 @@ export class WebpackCompilerHost implements ts.CompilerHost {
}
}

getModifiedResourceFiles(): Set<string> {
const modifiedFiles = new Set<string>();

for (const changedFile of this._changedFiles) {
if (this._readResourceFiles.has(changedFile)) {
modifiedFiles.add(changedFile);
}

if (!this._resourceLoader) {
continue;
}
for (const resourcePath of this._resourceLoader.getAffectedResources(changedFile)) {
modifiedFiles.add(resourcePath);
}
}

return modifiedFiles;
}

trace(message: string) {
console.log(message);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/ngtools/webpack/src/resource_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class WebpackResourceLoader {
private _parentCompilation: any;
private _context: string;
private _fileDependencies = new Map<string, string[]>();
private _reverseDependencies = new Map<string, string[]>();
private _cachedSources = new Map<string, string>();
private _cachedEvaluatedSources = new Map<string, RawSource>();

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

getAffectedResources(file: string) {
return this._reverseDependencies.get(file) || [];
}

private _compile(filePath: string): Promise<CompilationOutput> {

if (!this._parentCompilation) {
Expand Down Expand Up @@ -117,6 +122,14 @@ export class WebpackResourceLoader {

// Save the dependencies for this resource.
this._fileDependencies.set(filePath, childCompilation.fileDependencies);
for (const file of childCompilation.fileDependencies) {
const entry = this._reverseDependencies.get(file);
if (entry) {
entry.push(filePath);
} else {
this._reverseDependencies.set(file, [filePath]);
}
}

const compilationHash = childCompilation.fullHash;
const maybeSource = this._cachedSources.get(compilationHash);
Expand Down

0 comments on commit 0e339ee

Please sign in to comment.