MCPcopy Create free account
hub / github.com/MirrowApp/mirrow / watchFile

Function watchFile

packages/cli/src/runner.ts:299–337  ·  view source on GitHub ↗
(
  inputFile: string,
  output: string,
  signal: AbortSignal,
  enqueue: (task: Task) => void
)

Source from the content-addressed store, hash-verified

297}
298
299async function watchFile(
300 inputFile: string,
301 output: string,
302 signal: AbortSignal,
303 enqueue: (task: Task) => void
304): Promise<void> {
305 const watcher = chokidar.watch(inputFile, {
306 persistent: true,
307 ignoreInitial: true,
308 awaitWriteFinish: {
309 stabilityThreshold: WATCH_STABILITY_MS,
310 pollInterval: 50,
311 },
312 });
313
314 const targetFile = resolveOutputFilePath(output);
315
316 const handleEvent = async (event: WatchEvent) => {
317 if (event === "unlink") {
318 await fs.rm(targetFile, { force: true });
319 logRemoval(inputFile, targetFile);
320 return;
321 }
322
323 if (event === "add" || event === "change") {
324 await compileMirrowFile(inputFile, targetFile);
325 }
326 };
327
328 watcher.on("all", (event) => {
329 enqueue(() => handleEvent(event as WatchEvent));
330 });
331
332 watcher.on("error", (error) => {
333 logWatchError(error);
334 });
335
336 await waitForAbort(watcher, signal);
337}
338
339function resolveOutputForRelative(
340 outputRoot: string,

Callers 1

watchMirrowFunction · 0.85

Calls 4

resolveOutputFilePathFunction · 0.85
handleEventFunction · 0.85
logWatchErrorFunction · 0.85
waitForAbortFunction · 0.85

Tested by

no test coverage detected