Skip to content

Commit 7016cee

Browse files
clydindgp1130
authored andcommitted
fix(@angular-devkit/build-angular): normalize paths in loader cache with esbuild
When using the esbuild-based application builder, some plugins may return watch file lists that contain POSIX paths on Windows systems. This can cause the file watcher to not correctly invalidate files that need to be processed during a rebuild. All watch files are now normalized prior to being added to the in-memory cache to avoid this problem. (cherry picked from commit 93b743a)
1 parent d3310b2 commit 7016cee

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/global-scripts.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ export function createGlobalScriptsBundleOptions(
8989
let fileContent;
9090
try {
9191
// Attempt to read as a relative path from the workspace root
92-
fileContent = await readFile(path.join(workspaceRoot, filename), 'utf-8');
93-
watchFiles.push(filename);
92+
const fullPath = path.join(workspaceRoot, filename);
93+
fileContent = await readFile(fullPath, 'utf-8');
94+
watchFiles.push(fullPath);
9495
} catch (e) {
9596
assertIsError(e);
9697
if (e.code !== 'ENOENT') {
9798
throw e;
9899
}
99100

100-
// If not found attempt to resolve as a module specifier
101+
// If not found, attempt to resolve as a module specifier
101102
const resolveResult = await build.resolve(filename, {
102103
kind: 'entry-point',
103104
resolveDir: workspaceRoot,
@@ -114,7 +115,7 @@ export function createGlobalScriptsBundleOptions(
114115
};
115116
}
116117

117-
watchFiles.push(path.relative(resolveResult.path, workspaceRoot));
118+
watchFiles.push(resolveResult.path);
118119
fileContent = await readFile(resolveResult.path, 'utf-8');
119120
}
120121

packages/angular_devkit/build_angular/src/tools/esbuild/load-result-cache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import type { OnLoadResult, PluginBuild } from 'esbuild';
10+
import { normalize } from 'node:path';
1011

1112
export interface LoadResultCache {
1213
get(path: string): OnLoadResult | undefined;
@@ -50,10 +51,12 @@ export class MemoryLoadResultCache implements LoadResultCache {
5051
this.#loadResults.set(path, result);
5152
if (result.watchFiles) {
5253
for (const watchFile of result.watchFiles) {
53-
let affected = this.#fileDependencies.get(watchFile);
54+
// Normalize the watch file path to ensure OS consistent paths
55+
const normalizedWatchFile = normalize(watchFile);
56+
let affected = this.#fileDependencies.get(normalizedWatchFile);
5457
if (affected === undefined) {
5558
affected = new Set();
56-
this.#fileDependencies.set(watchFile, affected);
59+
this.#fileDependencies.set(normalizedWatchFile, affected);
5760
}
5861
affected.add(path);
5962
}

0 commit comments

Comments
 (0)