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

onchange

v7.1.0

Published

Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.

Downloads

682,517

Readme

onchange

Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.

Install

npm install onchange

Usage

# On every change run `npm test`.
onchange 'app/**/*.js' 'test/**/*.js' -- npm test

# On every change restart `server.js` (by killing the running process).
onchange -i -k '**/*.js' -- node server.js

# On every change `echo` file change.
onchange '**/*.js' -- echo '{{event}} to {{file}}'

NOTE: Windows users may need to use double quotes rather than single quotes. If used in an npm script, remember to escape the double quotes.

You can match as many glob patterns as you like, just put the command you want to run after the -- and it will run any time a file matching any of the globs is added changed or deleted.

Other available replacement variables are fileExt (path.extname(file)), fileBase (path.basename(file)), fileBaseNoExt (basename, without extension), and fileDir (path.dirname(file)).

Options

Add (-a, --add)

To execute the command for all initially added paths:

onchange -a 'config.json' -- microservice-proxy -c {{file}} -p 9000

Initial (-i, --initial)

To execute the command once on load without any event:

onchange -i '**/*.js' -- npm start

Exclude (-e, --exclude)

To exclude matches:

onchange '**/*.ts' -e 'dist/**/*.js' -- tslint

No Exclude (--no-exclude)

**/node_modules/** and **/.git/** are excluded by default, use --no-exclude to disable:

onchange 'node_modules/**' --no-exclude -- tslint

Exclude Path (--exclude-path)

Excludes all paths in a file following the .gitignore specification.

onchange '**' --exclude-path .gitignore -- prettier

Kill (-k, --kill)

To kill current and pending processes between changes:

onchange -k '**/*.js' -- npm test

Jobs (-j <n>, --jobs <n>)

Set the maximum concurrent processes to run (default is 1):

onchange -j2 '**/*.js' -- cp -v -r '{{file}}' 'test/{{file}}'

Delay (-d, --delay)

To set the amount of delay (in ms) between process changes:

onchange -d 1000 '**/*.js' -- npm start

Await Write Finish (--await-write-finish <ms>)

To hold the events until the size does not change for a configurable amount of time (in ms, default is 2000):

onchange --await-write-finish 1500 '**/*.js' -- npm test

Poll (-p <ms>, --poll <ms>)

Use polling to monitor for changes. This option is useful if you're watching an NFS volume.

onchange -p 100 '**/*.js' -- npm test

Outpipe (-o, --outpipe)

Shell command to execute every change:

onchange -o '> .changelog' 'src/**/*.js' -- echo '{{event}} to {{file}}'

P.S. When a command is used with --outpipe, the stdout from the command will be piped into outpipe.

Filter (-f, --filter)

By default, onchange watches for all events from chokidar. Use this option to watch only for events you need:

onchange -f add -f change '**/*.js' -- npm start

Verbose (-v, --verbose)

Enable if you want verbose logging from onchange (useful for debugging). For example:

onchange -v 'app/**/*.js' 'test/**/*.js' -- npm test

TypeScript

Includes types for TypeScript users.

Related

  • cli-error-notifier - Send native desktop notifications if a command exits with an exit code other than 0.

License

MIT