From 02364518571a2b73be945a0036bbfa39e336330c Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:12:07 -0500 Subject: [PATCH] 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. (cherry picked from commit 1d82a7c2009bcccca68f18984cbd4fe2911bc5fe) --- .../esbuild/angular/file-reference-tracker.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/file-reference-tracker.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/file-reference-tracker.ts index 9af8471af844..feaa5d713b23 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/file-reference-tracker.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/file-reference-tracker.ts @@ -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>(); @@ -14,17 +16,19 @@ export class FileReferenceTracker { } add(containingFile: string, referencedFiles: Iterable): 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); } }