A simple, polling file watcher for Deno. Probably don't use this. Deno will support fsEvents in the very near future.
import { watch } from "https://denopkg.com/iamnathanj/[email protected]/mod.ts";
// default mode
// use this for directories that don't change rapidly, like src/
watch({
handle: fileChange => {
// fileChange will have the shape:
{
type: "created" | "modified" | "removed",
path: string;
}
}
});
// batch mode
// use this for directories that change often, like dist/
watch({
batch: true,
handle: fileChanges => {
// fileChanges will have the shape:
{
created?: path[],
modified?: path[],
removed?: path[],
}
}
});
(defaults shown)
{
handle: (FileEvent | FileEventBatch) => void,
root?: string; // Deno.cwd()
batch?: boolean // false
interval?: number; // 100
walkOptions?: WalkOptions; // see below
}
walkOptions
are passed directly to std/fs/walk.ts
with the following defaults:
{
includeDirs: false,
exts: [".js", ".ts", ".tsx"]
}