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

watchy

v0.10.1

Published

Run commands when paths change.

Downloads

1,587

Readme

Watchy

Run commands when paths change.

Install

You'll need to install Node.js to use Watchy. Node comes packaged with npm, which is Node's package manager, and the preferred method of installing Watchy. After installing Node, simply type

npm install -g watchy

and you should have the watchy command available!

Usage

Usage: watchy [options] -- command arg1 arg2 ...

Run commands when paths change.

Options:
  -V, --version                   output the version number
  -d, --debounce [seconds]        trigger a change at most every [seconds] seconds
  -k, --keep-alive                restart the process if it exits
  -p, --use-polling               use file polling even if fsevents or inotify is available
  -r, --restart [string]          send [string] to STDIN to restart the process
  -R, --no-restart-after-signal   disable process restart after being signaled and exited
  -s, --silent                    only output errors
  -S, --no-init-spawn             prevent spawn when the watcher is created
  -t, --shutdown-signal [signal]  use [signal] to shut down the process (default: "SIGTERM")
  -T, --reload-signal [signal]    use [signal] to reload the process (defaults to shutdown signal)
  -w, --watch [pattern]           watch [pattern] for changes, can be specified multiple times
  -W, --wait [seconds]            send SIGKILL to the process after [seconds] if it hasn't exited
  -h, --help                      output usage information

The watch patterns are extglob format.

Examples

# The simple case
watchy -w 'lib/**/*' -- say "The lib directory changed."

# Piping works as well
watchy -w 'styles/**/*.less' -- bash -c "lessc styles/main.less | autoprefixer -o .tmp/styles/main.css"

# Keep a process alive, restarting it as soon as it exits or "server.js"
# changes.
watchy -kw server.js -- node server.js

# Watch every file except dotfiles, the node_modules folder, and JSON files.
# NOTE: Listen to as few files as possible for better performance.
watchy -w . -i '/\.|/node_modules|\.json$' -- node server.js

# Tick tock!
watchy -ks -- bash -c 'date && sleep 1'

# Tick tock (annoying version)!
watchy -ks -- bash -c 'say "In case you were wondering, it is `date`" && sleep 5'

# $WATCHY_ACTION and $WATCHY_PATH are passed to the process.
watchy -w '**/*' -- bash -c 'echo $WATCHY_ACTION $WATCHY_PATH'
# => modified /Users/casey/Documents/code/watchy/README.md

Note: If you're using watchy for help with preprocessing, I'd recommend checking out my cogs project that is highly optimized for that case with in-memory processed file caching, directives, AMD support, and much more.

SIGTERM

By default, watchy will send SIGTERM to the running process after a change and wait for it to exit gracefully. By sending the --wait|-W n option, you can tell watchy to forcefully SIGKILL the process after n seconds. In general, you should try to clean up connections in your processes like so:

process.on('SIGTERM', function () {
  server.close();
  db.disconnect();
  redis.quit();
  // etc...
});

Node API

As of 0.9.0 watchy exposes a Node.js API.

const watchy = require('watchy');

watchy({
  patterns: ['js/**/*.js', 'css/**/*.css'],
  onError: error => console.error(error),
  onChange: ({action, path}) => console.log(action, path),
  usePolling: true // defaults to `false`, but will fallback when fsevents are not available
}).catch(er => {
  console.error(er);
  process.exit(1);
});