( inputFile: string, output: string, signal: AbortSignal, enqueue: (task: Task) => void )
| 297 | } |
| 298 | |
| 299 | async 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 | |
| 339 | function resolveOutputForRelative( |
| 340 | outputRoot: string, |
no test coverage detected