MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / refreshWatchers

Function refreshWatchers

packages/node/src/dev/hotStateReload.ts:471–512  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

469 }
470
471 function refreshWatchers(): void {
472 if (!running) return;
473 const desiredDirs = new Set<string>();
474
475 for (const target of watchTargets) {
476 const root = toWatchDirectory(target);
477 if (containsIgnoredDir(root)) continue;
478 const dirs = collectWatchDirectories(root);
479 for (const dir of dirs) {
480 desiredDirs.add(dir);
481 }
482 }
483
484 for (const watchedDir of watchers.keys()) {
485 if (desiredDirs.has(watchedDir)) continue;
486 const watcher = watchers.get(watchedDir);
487 watchers.delete(watchedDir);
488 try {
489 watcher?.close();
490 } catch {
491 // ignore watcher close races
492 }
493 }
494
495 for (const dir of desiredDirs) {
496 if (watchers.has(dir)) continue;
497 try {
498 const watcher = watch(dir, { persistent: true }, (eventType, filename) => {
499 onWatchEvent(dir, eventType, filename ?? null);
500 });
501 watcher.on("error", (error: unknown) => {
502 emitError(error, { phase: "watch", changedPath: dir });
503 log({ level: "warn", message: "HSR watcher reported an error", changedPath: dir });
504 scheduleWatchRefresh();
505 });
506 watchers.set(dir, watcher);
507 } catch (error: unknown) {
508 emitError(error, { phase: "watch", changedPath: dir });
509 log({ level: "warn", message: "HSR failed to watch path", changedPath: dir });
510 }
511 }
512 }
513
514 async function start(): Promise<void> {
515 if (running) return;

Callers 2

scheduleWatchRefreshFunction · 0.85
startFunction · 0.85

Calls 14

toWatchDirectoryFunction · 0.85
containsIgnoredDirFunction · 0.85
collectWatchDirectoriesFunction · 0.85
onWatchEventFunction · 0.85
emitErrorFunction · 0.85
scheduleWatchRefreshFunction · 0.85
keysMethod · 0.65
onMethod · 0.65
addMethod · 0.45
hasMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected