# watch-module

> A Javascript module watcher to work locally with package

Latest version **4.0.0** (published 2025-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install watch-module
pnpm add watch-module
yarn add watch-module
bun add watch-module
```

Provides the command `watch-module`.

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-10-03 |
| First published | 2019-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 11 |
| Unpacked size | 634.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | jdeniau, badaz, s.gregeois, lpot, cmeiller, bjulien, nickinthebox |

## Links

- npm: https://www.npmjs.com/package/watch-module
- Repository: https://github.com/mapado/watch-module
- Homepage: https://github.com/mapado/watch-module#readme
- Issues: https://github.com/mapado/watch-module/issues
- npm.io page: https://npm.io/package/watch-module

## Dependencies (11)

- [ink](https://npm.io/package/ink.md) ^3.2.0
- [react](https://npm.io/package/react.md) ^17.0.2 || ^18.2.0
- [ink-tab](https://npm.io/package/ink-tab.md) ^4.3.1
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [debounce](https://npm.io/package/debounce.md) ^1.2.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.1.0
- [has-yarn](https://npm.io/package/has-yarn.md) ^3.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.6
- [minimatch](https://npm.io/package/minimatch.md) ^6.0.4
- [ink-spinner](https://npm.io/package/ink-spinner.md) ^4.0.3
- [ink-text-input](https://npm.io/package/ink-text-input.md) ^4.0.3

## Recent versions

- 4.0.0 (latest) — 2025-10-03
- 3.1.0 — 2023-01-30
- 3.0.2 — 2023-01-19
- 3.0.1 — 2023-01-17
- 3.0.0 — 2023-01-17
- 2.2.2 — 2023-01-16
- 2.2.1 — 2023-01-16
- 2.2.0 — 2023-01-16
- 2.1.1 — 2022-04-21
- 2.1.0 — 2022-04-19
- 2.0.0 — 2021-10-08
- 1.3.0 — 2020-10-13
- 1.2.1 — 2020-01-22
- 1.2.0 — 2020-01-15
- 1.1.1 — 2019-12-04
- … 4 more at https://npm.io/package/watch-module/versions

## README

# watch-module

A Javascript module watcher to work locally with packages.

Replace the "not-really-functionnal" npm | yarn link.

## Demo

![Demo](demo.svg)

## Usage

Place yourself at the root of your main package and call:

```sh
npx watch-module /path/to/my/module
```

watch-module will detect code changes in your module, run the `build` script (if available) and copy the code into your `node_modules` folder.
watch-module will not copy the node_modules folder contained inside your module

> watch-module requires a node version >= 16 to work

### Multiple packages

watch-modules does support multiple modules:

```sh
npx watch-module /path/to/my/module ../my-other-module
```

### Configuration

On first launch, watch-module creates an empty configuration file to `{HOME_FOLDER}/.config/watch-module/watch-module.json`
In order to force a different configuration for a specific module, you can add "per module" entries to this file :

```jsonc
{
  // watch the files in the "lib" directory
  // and call "npm run build:prepare" script when there is a change
  "my-awesome-module": {
    "includes": ["lib"],
    "command": "npm run build:prepare"
  },
  // watch all the files in the root directory
  // do not watch the files in the "dist" directory
  // do not call any command before copying the files
  "my-other-module": {
    "command": null,
    "includes": [""], // use "" or "." to watch all files
    "excludes": ["dist"]
  }
}
```

You can override this global configuration by configuring the targeted module's `package.json` file direclty:

```jsonc
{
  "name": "my package",
  "scripts": {
    "build:prod": "touch build.js"
  },
  "watch-module": {
    "command": "yarn run build:prod",
    "includes": ["src"]
  }
}
```

If no configuration is found for a module, watch-module falls back to the default configuration:

```jsonc
{
  "command": "yarn|npm run build", // default configs tries to detect yarn or npm
  "includes": ["src"],
  "excludes": []
}
```

#### API

#### command (default `yarn|npm run build`)

The command that will be triggered when a change is detected.

It can either be:

- a `string` of a command to run
- an object of `{ [pattern: string]: string }` to trigger specific command according to the file changes (ex: `{ "*.js": "npm run build:js", "*.css": "npm run build:css" }`) [experimental]
- `null` if you just want to copy the files and do nothing else

Using an object of `pattern: command` is still experimental and needs some real-world usage.

#### includes

An array of string of files or directory to watch.

Default is `['src/']`

#### excludes

An array of string of files or directory to exclude from included paths.

Default is `[]`

#### outDir

If you want to copy only your out directory, you can specify it there.

Watch out: it is a pretty unused use-case.

Default is `undefined`

#### Partial configuration

If you overrides only some parts of the configuration, then the keys that are not overiden will use the default configuration.

## Alternatives

[npm link | yarn link] : it does work fine until you have dependencies, etc. in your package.

[yalc](https://github.com/whitecolor/yalc) : nice alternative, but too complex for our purpose (it does use a local repository, that you need to push on change, etc.)

## Troubleshooting

### Command not found

If you have the error `Command not found`, you can force npx to use the latest version of the package:

```sh
npx watch-module@latest
```

It should resolve the issue.

## Contributing

You can start a builder in watch mode with `yarn dev`. It will automatically build on each change of file in the `src/` directory.

In another terminal, you can go in the `demo/app` folder and use the build this way:

```sh
cd demo/app
node ../../bin/watch-module.js ../package ../package2 -v
```

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