0.3.0 ā€¢ Published 2 years ago

monorepo-watch v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Monorepo Watch

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.

Recommended Usage

It is recommended to use terminals that has a at least level=2 support for colors(256 color support)

Terminals that support colors are:

  1. Gitbash
  2. Windows Terminal
  3. zsh
  4. bash

Installation

npm install --save monorepo-watch

or

yarn add monorepo-watch

Usage

  1. 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.

  1. Now run the follow command from any of your packages to get the watcher running. As a example, I am running the command from packages/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.

Configuration

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,

}