Skip to content

Commit e7de4ed

Browse files
committed
fixup! fix(@angular/build): deduplicate spurious chokidar polling change events
1 parent 301eb0f commit e7de4ed

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎packages/angular/build/src/utils/watcher.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,17 @@ async function createChokidarWatcher(
857857
async next() {
858858
const result = await queue.next();
859859
if (result.value) {
860-
for (const file of [...result.value.added, ...result.value.modified]) {
861-
const stat = fs.statSync(file, { throwIfNoEntry: false });
862-
if (stat?.isFile()) {
863-
const posixPath = toPosixPathNormalized(file);
864-
const lookupKey = toLookupKey(posixPath, isCaseSensitive);
865-
fileStats.set(lookupKey, { mtimeMs: stat.mtimeMs, size: stat.size });
866-
}
867-
}
860+
const files = [...result.value.added, ...result.value.modified];
861+
await Promise.all(
862+
files.map(async (file) => {
863+
const stat = await fs.promises.stat(file).catch(() => undefined);
864+
if (stat?.isFile()) {
865+
const posixPath = toPosixPathNormalized(file);
866+
const lookupKey = toLookupKey(posixPath, isCaseSensitive);
867+
fileStats.set(lookupKey, { mtimeMs: stat.mtimeMs, size: stat.size });
868+
}
869+
}),
870+
);
868871
}
869872

870873
return result;
@@ -879,11 +882,6 @@ async function createChokidarWatcher(
879882
if (!watchedFiles.has(lookupKey)) {
880883
watchedFiles.add(lookupKey);
881884

882-
const stat = fs.statSync(p, { throwIfNoEntry: false });
883-
if (stat?.isFile()) {
884-
fileStats.set(lookupKey, { mtimeMs: stat.mtimeMs, size: stat.size });
885-
}
886-
887885
// For files inside node_modules, register their package directory. Only newly encountered
888886
// package directories need to be added to Chokidar.
889887
const { isPackage, newPkgDir } = nodeModulesManager.registerPackage(posixPath, lookupKey);

0 commit comments

Comments
 (0)