Skip to content

Commit ef3e3ab

Browse files
committed
fix(@angular-devkit/build-angular): ensure watch file paths from TypeScript are normalized
The TypeScript compiler converts all paths to use POSIX path separators. When on Windows, this can cause problems when comparing paths from other parts of the build system including the file watching provided by `chokidar`. The referenced files returned from the TypeScript compiler are now normalized to the native path format to mitigate this problem. This also avoids an issue where the same files but with differing path separators were included in the watch files list on Windows due to the bundler using native paths and TypeScript using converted paths. (cherry picked from commit 08a6e46)
1 parent 3b99980 commit ef3e3ab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/bundler-execution-result.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import type { Message, PartialMessage } from 'esbuild';
10+
import { normalize } from 'node:path';
1011
import type { ChangedFiles } from '../../tools/esbuild/watcher';
1112
import type { SourceFileCache } from './angular/source-file-cache';
1213
import type { BuildOutputFile, BuildOutputFileType, BundlerContext } from './bundler-context';
@@ -88,11 +89,15 @@ export class ExecutionResult {
8889
}
8990

9091
get watchFiles() {
92+
// Bundler contexts internally normalize file dependencies
9193
const files = this.rebuildContexts.flatMap((context) => [...context.watchFiles]);
9294
if (this.codeBundleCache?.referencedFiles) {
93-
files.push(...this.codeBundleCache.referencedFiles);
95+
// These files originate from TS/NG and can have POSIX path separators even on Windows.
96+
// To ensure path comparisons are valid, all these paths must be normalized.
97+
files.push(...this.codeBundleCache.referencedFiles.map(normalize));
9498
}
9599
if (this.codeBundleCache?.loadResultCache) {
100+
// Load result caches internally normalize file dependencies
96101
files.push(...this.codeBundleCache.loadResultCache.watchFiles);
97102
}
98103

0 commit comments

Comments
 (0)