Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions packages/ngtools/webpack/src/ivy/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,12 @@ import { normalizePath } from './paths';
export class SourceFileCache extends Map<string, ts.SourceFile> {
private readonly angularDiagnostics = new Map<ts.SourceFile, ts.Diagnostic[]>();

invalidate(
fileTimestamps: Map<string, 'ignore' | number | { safeTime: number } | null>,
buildTimestamp: number,
): Set<string> {
const changedFiles = new Set<string>();
for (const [file, timeOrEntry] of fileTimestamps) {
if (timeOrEntry === 'ignore') {
continue;
}

let time;
if (typeof timeOrEntry === 'number') {
time = timeOrEntry;
} else if (timeOrEntry) {
time = timeOrEntry.safeTime;
}

if (!time || time >= buildTimestamp) {
// Cache stores paths using the POSIX directory separator
const normalizedFile = normalizePath(file);
const sourceFile = this.get(normalizedFile);
if (sourceFile) {
this.delete(normalizedFile);
this.angularDiagnostics.delete(sourceFile);
}
changedFiles.add(normalizedFile);
}
invalidate(file: string): void {
const sourceFile = this.get(file);
if (sourceFile) {
this.delete(file);
this.angularDiagnostics.delete(sourceFile);
}

return changedFiles;
}

updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void {
Expand Down
17 changes: 9 additions & 8 deletions packages/ngtools/webpack/src/ivy/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export class AngularWebpackPlugin {
private ngtscNextProgram?: NgtscProgram;
private builder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
private sourceFileCache?: SourceFileCache;
private buildTimestamp!: number;
private readonly fileDependencies = new Map<string, Set<string>>();
private readonly requiredFilesToEmit = new Set<string>();
private readonly requiredFilesToEmitCache = new Map<string, EmitFileResult | undefined>();
Expand Down Expand Up @@ -200,12 +199,15 @@ export class AngularWebpackPlugin {
let cache = this.sourceFileCache;
let changedFiles;
if (cache) {
// Invalidate existing cache based on compiler file timestamps
changedFiles = cache.invalidate(compiler.fileTimestamps, this.buildTimestamp);

// Invalidate file dependencies of changed files
for (const changedFile of changedFiles) {
this.fileDependencies.delete(normalizePath(changedFile));
changedFiles = new Set<string>();
for (const changedFile of [...compiler.modifiedFiles, ...compiler.removedFiles]) {
const normalizedChangedFile = normalizePath(changedFile);
// Invalidate file dependencies
this.fileDependencies.delete(normalizedChangedFile);
// Invalidate existing cache
cache.invalidate(normalizedChangedFile);

changedFiles.add(normalizedChangedFile);
}
} else {
// Initialize a new cache
Expand All @@ -215,7 +217,6 @@ export class AngularWebpackPlugin {
this.sourceFileCache = cache;
}
}
this.buildTimestamp = Date.now();
augmentHostWithCaching(host, cache);

const moduleResolutionCache = ts.createModuleResolutionCache(
Expand Down