JSPM

  • Created
  • Published
  • Downloads 4080552
  • Score
    100M100P100Q226745F
  • License MIT

Sane aims to be fast, small, and reliable file system watcher.

Package Exports

  • sane

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sane) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sane

I've been driven to insanity by node filesystem watcher wrappers. Sane aims to be fast, small, and reliable file system watcher. It does that by:

  • Always use fs.watch (unless polling is forced) and sensibly workaround the various issues with it
  • Sane is all JavaScript, no native components
  • Stay away from polling because it's very slow and cpu intensive
  • Support polling for environments like Vagrant shared directory where there are no native filesystem events

Install

Requires node >= v0.10.0.

$ npm install sane

API

sane(dir, globs, options)

Watches a directory and all it's descendant directorys for changes, deletions, and additions on files and directories. Shortcut for new sane.Watcher(files, {globs: globs, options}).

var watcher = sane('path/to/dir', ['**/*.js, '**/*.css']);
watcher.on('ready', function () { console.log('ready') });
watcher.on('change', function (filepath) { console.log('file changed', filepath); });
watcher.on('add', function (filepath) { console.log('file added', filepath); });
watcher.on('delete', function (filepath) { console.log('file deleted', filepath); });
// close
watcher.close();

For options see sane.Watcher.

sane.Watcher(dir, options)

options:

  • persistent: boolean indicating that the process shouldn't die while we're watching files.
  • glob: a single string glob pattern or an array of them.
  • poll: puts the watcher in polling mode. Under the hood that means fs.watchFile.
  • interval: indicates how often the files should be polled. (passed to fs.watchFile)

For the glob pattern documentation, see minimatch.

sane.Watcher#close

Stops watching.

sane.Watcher events

Emits the following events:

All events are passed the file/dir path relative to the root directory

  • ready when the program is ready to detect events in the directory
  • change when a file changes
  • add when a file or directory has been added
  • delete when a file or directory has been deleted

License

MIT