npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

watch-module

v3.1.0

Published

A Javascript module watcher to work locally with package

Downloads

14

Readme

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