mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 19:13:34 +08:00
refactor(@ngtools/webpack): use Webpack 5 modified/removed file sets for changed list
Webpack 5 directly provides the set of modified and removed files. This feature allows for the removal of the file timestamp logic within the plugin that was previously used to generated the set of changed files on a rebuild.
This commit is contained in:
parent
e8f22ab36d
commit
86754e4750
@ -11,36 +11,12 @@ import { normalizePath } from './paths';
|
|||||||
export class SourceFileCache extends Map<string, ts.SourceFile> {
|
export class SourceFileCache extends Map<string, ts.SourceFile> {
|
||||||
private readonly angularDiagnostics = new Map<ts.SourceFile, ts.Diagnostic[]>();
|
private readonly angularDiagnostics = new Map<ts.SourceFile, ts.Diagnostic[]>();
|
||||||
|
|
||||||
invalidate(
|
invalidate(file: string): void {
|
||||||
fileTimestamps: Map<string, 'ignore' | number | { safeTime: number } | null>,
|
const sourceFile = this.get(file);
|
||||||
buildTimestamp: number,
|
if (sourceFile) {
|
||||||
): Set<string> {
|
this.delete(file);
|
||||||
const changedFiles = new Set<string>();
|
this.angularDiagnostics.delete(sourceFile);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return changedFiles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void {
|
updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void {
|
||||||
|
@ -95,7 +95,6 @@ export class AngularWebpackPlugin {
|
|||||||
private ngtscNextProgram?: NgtscProgram;
|
private ngtscNextProgram?: NgtscProgram;
|
||||||
private builder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
private builder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
||||||
private sourceFileCache?: SourceFileCache;
|
private sourceFileCache?: SourceFileCache;
|
||||||
private buildTimestamp!: number;
|
|
||||||
private readonly fileDependencies = new Map<string, Set<string>>();
|
private readonly fileDependencies = new Map<string, Set<string>>();
|
||||||
private readonly requiredFilesToEmit = new Set<string>();
|
private readonly requiredFilesToEmit = new Set<string>();
|
||||||
private readonly requiredFilesToEmitCache = new Map<string, EmitFileResult | undefined>();
|
private readonly requiredFilesToEmitCache = new Map<string, EmitFileResult | undefined>();
|
||||||
@ -204,12 +203,15 @@ export class AngularWebpackPlugin {
|
|||||||
let cache = this.sourceFileCache;
|
let cache = this.sourceFileCache;
|
||||||
let changedFiles;
|
let changedFiles;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
// Invalidate existing cache based on compiler file timestamps
|
changedFiles = new Set<string>();
|
||||||
changedFiles = cache.invalidate(compiler.fileTimestamps, this.buildTimestamp);
|
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);
|
||||||
|
|
||||||
// Invalidate file dependencies of changed files
|
changedFiles.add(normalizedChangedFile);
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
this.fileDependencies.delete(normalizePath(changedFile));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Initialize a new cache
|
// Initialize a new cache
|
||||||
@ -219,7 +221,6 @@ export class AngularWebpackPlugin {
|
|||||||
this.sourceFileCache = cache;
|
this.sourceFileCache = cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.buildTimestamp = Date.now();
|
|
||||||
augmentHostWithCaching(host, cache);
|
augmentHostWithCaching(host, cache);
|
||||||
|
|
||||||
const moduleResolutionCache = ts.createModuleResolutionCache(
|
const moduleResolutionCache = ts.createModuleResolutionCache(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user