# monorepo-watch

> A package for monorepos that watches a specific package and it's dependencies.

Latest version **0.3.0** (published 2021-11-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

Provides the command `watcher`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2021-11-27 |
| First published | 2021-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 11 |
| Unpacked size | 117.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Utkarsh Kumar |
| Maintainers | utkarshk384 |
| Keywords | monorepo-watch, file-watcher, lerna-watcher |

## Links

- npm: https://www.npmjs.com/package/monorepo-watch
- Repository: https://github.com/utkarshk384/monorepo-watch
- Issues: https://github.com/Utkarshk384/monorepo-watch/issues
- npm.io page: https://npm.io/package/monorepo-watch

## Dependencies (11)

- [ora](https://npm.io/package/ora.md) ^6.0.0
- [glob](https://npm.io/package/glob.md) ^7.1.7
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [yargs](https://npm.io/package/yargs.md) ^17.1.1
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.2
- [async-lock](https://npm.io/package/async-lock.md) ^1.3.0
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.3
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.2.8
- [lodash.mergewith](https://npm.io/package/lodash.mergewith.md) ^4.6.2
- [@manypkg/find-root](https://npm.io/package/@manypkg/find-root.md) ^1.1.0
- [@manypkg/get-packages](https://npm.io/package/@manypkg/get-packages.md) ^1.1.1

## Recent versions

- 0.3.0 (latest) — 2021-11-27
- 0.2.1 — 2021-09-07
- 0.2.0 — 2021-09-07
- 0.1.0 — 2021-08-17
- 0.0.3 — 2021-08-14
- 0.0.2 — 2021-08-14
- 0.0.1 — 2021-08-14

## README

# Monorepo Watch

NOTE: This is a work in progress. Currently it's in its beta state.
Any suggestions are warmly welcomed 😄.
<br/>
<br />
A asynchronous, customizable file watcher for projects using lerna, yarn workspaces, and monorepos.

<br/>
<br/>

## Recommended Usage
It is recommended to use terminals that has a at least level=2 support for colors([256 color support](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode))

Terminals that support colors are:

1. [Gitbash](https://git-scm.com/download/win)
2. [Windows Terminal](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701#activetab=pivot:overviewtab)
3. [zsh](https://ohmyz.sh/#install)
4. [bash](https://www.gnu.org/software/bash/)

## Installation

```sh
npm install --save monorepo-watch
```

or

```sh
yarn add monorepo-watch
```

<br/>
<br/>

## Usage

1. Create a config file in the root of the project directory.
   </br>
   Eg:

```
packages
├── pkg1
│   ├── src
│   └── package.json
└── pkg2
    ├── src
    └── package.json
package.json
lerna.json
watcher.config.js <--root
```

See [configuration](https://https://github.com/Utkarshk384/monorepo-watch#Configuration) section below on how to configure your watcher.

2. Now run the follow command from any of your packages to get the watcher running.
   <br/>
   As a example, I am running the command from `packages/pkg1`

```sh
npm run watcher -c ../../watcher.config.js -i src
```

The `-c` flag is the config file path and `-i` is the dirs to include.
For multiple dirs use `-i={"src","lib", etc...}`

<br />

This will watch the `src` directory and resolve all it's dependencies and watch its `src` directory as well.

<br/>
<br/>

## Configuration

NOTE: Only [CommonJS](https://medium.com/@cgcrutch18/commonjs-what-why-and-how-64ed9f31aa46) is supported for the config file

```typescript
//watcher.config.js


/**
 * Include types for ease of use
 * @type {import('monorepo-watch/dist/types/types').IConfig}
 */

module.exports = {
    /**
     * @required
     * @default process.cwd()
     * 
     * The root of the current pacakge.
    */
    packageRoot: string,

    /**
     * @optional
     * @default {`name` Field taken from one of the `package.json` 
     * from the packages}
     * 
     * The scoped package name.
     * Eg: @mypackage/pkg1, the prefix here is `@mypackge`
    */
    prefix: string,

    /**
     * @optional
     * @default ["src"]
     * 
     * The directories to be watched inside the package folder.
     * 
     * Globbing supported
    */
    include: string[],

    /**
     * @optional
     * @default {}
     * 
     * Options that is directly passed to the `chokidar.watch` method.
     * Please refer to the https://github.com/paulmillr/chokidar#api
     * to see all the available options
    */
    options: chokidar.WatchOptions,

    /**
     * @optional
     * @type {
     *  add: (path: string, stats: fs.Stats) => any
     *  addDir: (path: string, stats: fs.Stats) => any
     *  change: (path: string, stats: fs.Stats) => any
     *  unlink: (path: string) => any
     *  unlinkDir: (path: string) => any
     * }
     * 
     * This is the action that is to be performed when different events 
     * occur.
    */
    actions: EventActionWatchActions,

    /**
     * @optional
     * @default []
     * 
     * A command that will be ran on all file event changes.
     * 
     */
    runScripts: string | string[],

    /**
     * @optional
     * @default true
     * 
     * If true, the watcher will resolve dev dependencies and watch
     * those as well. 
     * 
     * Note: The watcher will only resolve dependencies that are within
     *       the package. It won't resolve any node_modules.
     */
    resolveDevDependencies: boolean,
    
    /**
     * @optional
     * @default true
     * 
     * If true, the watcher will resolve peer dependencies and watch
     * those as well. 
     * 
     * Note: The watcher will only resolve dependencies that are within
     *       the package. It won't resolve any node_modules.
     */
    resolvePeerDependencies: boolean,

    /**
     * @optional
     * @default true
     * 
     * If true, the watcher will not pipe any logs to process.stdout 
     * and set the stdio to "ignore". Only applicable for situations  
     * where `runScripts` is defined.
     * 
     */
    noChildProcessLogs: boolean,

}
```

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