🌳
pt0/serverF/libFs/watchFilesDebouncedF.mts
1import chokidar from 'chokidar'
3export const watchFilesDebounced = (
4 paths: string | string[],
5 cb: (eventName: string, filePath: string) => void,
6 opts: { stabilityMs?: number, depth?: number } = {}
7) =>
8 chokidar.watch(paths, {
9 ignoreInitial: true,
10 ...(opts.depth !== undefined ? { depth: opts.depth } : {}),
11 ...(opts.stabilityMs !== undefined ? { awaitWriteFinish: { stabilityThreshold: opts.stabilityMs, pollInterval: opts.stabilityMs >= 300 ? 100 : 50 } } : {}),
12 }).on('all', cb)