# inwatch

> Filesystem watcher that spawns inotifywait.

Latest version **0.0.10** (published 2023-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install inwatch
pnpm add inwatch
yarn add inwatch
bun add inwatch
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2023-06-12 |
| First published | 2023-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 90.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | errilaz |
| Maintainers | errilaz |
| Keywords | watch, watcher, inotify, bun |

## Links

- npm: https://www.npmjs.com/package/inwatch
- Repository: https://github.com/errilaz/inwatch
- Homepage: https://github.com/errilaz/inwatch#readme
- Issues: https://github.com/errilaz/inwatch/issues
- npm.io page: https://npm.io/package/inwatch

## Dependencies (2)

- [split](https://npm.io/package/split.md) ^1.0.1
- [typed-emitter](https://npm.io/package/typed-emitter.md) ^2.1.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.10 (latest) — 2023-06-12
- 0.0.9 — 2023-06-12
- 0.0.8 — 2023-06-12
- 0.0.7 — 2023-03-09
- 0.0.6 — 2023-02-26
- 0.0.5 — 2023-02-15
- 0.0.4 — 2023-02-15
- 0.0.3 — 2023-02-13
- 0.0.2 — 2023-02-13
- 0.0.1 — 2023-02-12

## README

# inwatch

<a href="https://www.npmjs.com/package/inwatch"><img src="https://img.shields.io/npm/v/inwatch?style=flat-square"></a>

> Filesystem watcher that spawns inotifywait

I made this because I needed a filesystem watcher that works with [bun](https://github.com/oven-sh/bun).

## Watch API

Watching files with a `chokidar`-like API:

```ts
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:

```ts
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

- [Anadian/regex-translator](https://github.com/Anadian/regex-translator) - adapted code from this library to convert JS RegExps to extended.

---
_Source: https://npm.io/package/inwatch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
