NOTE: This is a work in progress. Currently it's in its beta state.
Any suggestions are warmly welcomed 😄.
A asynchronous, customizable file watcher for projects using lerna, yarn workspaces, and monorepos.
It is recommended to use terminals that has a at least level=2 support for colors(256 color support)
Terminals that support colors are:
npm install --save monorepo-watch
or
yarn add monorepo-watch
- Create a config file in the root of the project directory.
Eg:
packages
├── pkg1
│ ├── src
│ └── package.json
└── pkg2
├── src
└── package.json
package.json
lerna.json
watcher.config.js <--root
See configuration section below on how to configure your watcher.
- Now run the follow command from any of your packages to get the watcher running.
As a example, I am running the command frompackages/pkg1
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...}
This will watch the src
directory and resolve all it's dependencies and watch its src
directory as well.
NOTE: Only CommonJS is supported for the config file
//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,
}