Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): always normalize AOT file referen…
Browse files Browse the repository at this point in the history
…ce 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 1d82a7c)
  • Loading branch information
clydin committed Nov 20, 2023
1 parent 7c7c0ac commit 0236451
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -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>>();

Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 0236451

Please sign in to comment.