fix(@angular-devkit/build-angular): always normalize AOT file reference tracker paths

The path comparisons for the TypeScript and AOT file reference tracking now use the native path normalization
functions. This avoids issues where the TypeScript paths which use POSIX separators may not correct match
system paths. The file reference tracking is used to trigger updates to both web workers as well as component
stylesheets that have preprocessor (Sass/Less/etc.) dependencies.
This commit is contained in:
Charles Lyding 2023-11-19 12:12:07 -05:00 committed by Charles
parent 6c7c012307
commit 1d82a7c200

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import { normalize } from 'node:path';
export class FileReferenceTracker {
#referencingFiles = new Map<string, Set<string>>();
@ -14,17 +16,19 @@ export class FileReferenceTracker {
}
add(containingFile: string, referencedFiles: Iterable<string>): void {
const normalizedContainingFile = normalize(containingFile);
for (const file of referencedFiles) {
if (file === containingFile) {
const normalizedReferencedFile = normalize(file);
if (normalizedReferencedFile === normalizedContainingFile) {
// Containing file is already known to the AOT compiler
continue;
}
const referencing = this.#referencingFiles.get(file);
const referencing = this.#referencingFiles.get(normalizedReferencedFile);
if (referencing === undefined) {
this.#referencingFiles.set(file, new Set([containingFile]));
this.#referencingFiles.set(normalizedReferencedFile, new Set([normalizedContainingFile]));
} else {
referencing.add(containingFile);
referencing.add(normalizedContainingFile);
}
}
}
@ -39,14 +43,15 @@ export class FileReferenceTracker {
// Add referencing files to fully notify the AOT compiler of required component updates
for (const modifiedFile of changed) {
const referencing = this.#referencingFiles.get(modifiedFile);
const normalizedModifiedFile = normalize(modifiedFile);
const referencing = this.#referencingFiles.get(normalizedModifiedFile);
if (referencing) {
allChangedFiles ??= new Set(changed);
for (const referencingFile of referencing) {
allChangedFiles.add(referencingFile);
}
// Cleanup the stale record which will be updated by new resource transforms
this.#referencingFiles.delete(modifiedFile);
this.#referencingFiles.delete(normalizedModifiedFile);
}
}