Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

watch-module

Package Overview
Dependencies
Maintainers
5
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watch-module

A Javascript module watcher to work locally with package

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
5
Weekly downloads
 
Created
Source

watch-module

A Javascript module watcher to work locally with packages.

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

Demo

Demo

Usage

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

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

Multiple packages

watch-modules does support multiple modules:

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 :

{
  // 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:

{
  "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:

{
  "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 []

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

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:

cd demo/app
node ../../build/watch-module.js ../package ../package2 -v

FAQs

Package last updated on 30 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc