No description
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2023-06-12 23:07:07 +02:00
src esm file extensions 2023-06-12 23:07:07 +02:00
.gitignore 0.0.1 2023-02-12 21:51:23 +01:00
LICENSE Fixed event parsing. Added 'isDir'. 2023-02-13 16:40:55 +01:00
package.json esm file extensions 2023-06-12 23:07:07 +02:00
pnpm-lock.yaml 0.0.1 2023-02-12 21:51:23 +01:00
README.md Watch.stop, Wait.stop, fix recursive bug, docs 2023-03-09 14:02:44 +01:00
tsconfig.json update to ESM 2023-06-12 17:40:21 +02:00

inwatch

Filesystem watcher that spawns inotifywait

I made this because I needed a filesystem watcher that works with bun.

Watch API

Watching files with a chokidar-like API:

import watch from "inwatch"

const watcher = watch("/my/path", {
  recursive: true,
  reject: /node_modules|\.git/,
  ignoreInitial: false,
  ignoreSubsequent: false,
  ignoreDuplicatesMs: 100,
})

watcher.on("add", ({ path }) => {
  console.log(`"${path}" was added!`)
})

watcher.on("change", ({ path }) => {
  console.log(`"${path}" was changed!`)
})

watcher.on("remove", ({ path }) => {
  console.log(`"${path}" was removed!`)
})

await watcher.stop()

Options

  • recursive: watch directories recursively (default: false)
  • allow: only emit events for paths matching the regular expression (default: undefined)
  • reject: do not emit events for paths matching the regular expression (default: undefined)
  • ignoreInitial: do not emit add events for existing files at startup (default: false)
  • ignoreSubsequent: emits add events at startup but disables the watcher (default: false)
  • ignoreDuplicatesMs: ignore duplicate events emitted by inotifywait within the given window (default: undefined)

Wait API

Using the inotifywait wrapper directly:

import { wait } from "inwatch"

const waiter = wait("/my/path", {
  recursive: true,
  exclude: "node_modules|\\.git",
  events: ["modify", "move", "create", "delete"],
  ignoreDuplicatesMs: 100,
})

waiter.on("all", ({ event, watchPath, eventPath }) => {
  console.log(`"${event}" event on "${watchPath}" at "${eventPath}"!`)
})

Thanks