Skip to content

Commit

Permalink
Switch to Chokidar.
Browse files Browse the repository at this point in the history
Hey there.

This commits switches `watch` to a better file watcher, chokidar.

To summarize: chokidar is *very* stable, doesn't have [52 open issues](https://github.com/shama/gaze/issues) and is much faster on OSX, with less CPU usage because of `fsevents`.

Chokidar has been downloaded over 1.2M times last month and is used by very popular projects.
  • Loading branch information
paulmillr authored and indexzero committed Jul 23, 2015
1 parent fa99473 commit 12e35fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions lib/forever-monitor/plugins/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var fs = require('fs'),
path = require('path'),
minimatch = require('minimatch'),
watch = require('watch');
chokidar = require('chokidar');

exports.name = 'watch';

Expand Down Expand Up @@ -62,20 +62,17 @@ exports.attach = function () {
Array.prototype.push.apply(monitor.watchIgnorePatterns, data.split('\n').filter(Boolean));
});

watch.watchTree(this.watchDirectory, function (f, curr, prev) {
if (!(curr === null && prev === null && typeof f === 'object')) {
//
// `curr` == null && `prev` == null && typeof f == "object" when watch
// finishes walking the tree to add listeners. We don't need to know
// about it, so we simply ignore it (anything different means that
// some file changed/was removed/created - that's what we want to know).
//
if (watchFilter.call(monitor, f)) {
monitor.emit('watch:restart', { file: f, stat: curr });
monitor.restart();
} else {
monitor.emit('watch:ignore', { file: f });
}
var opts = {
ignoreInitial: true,
ignored: function(fileName) {
return !watchFilter.call(monitor, fileName);
}
});
};
// Or, ignore: function(fileName) { return !watchFilter(fileName) }
chokidar
.watch(this.watchDirectory, opts)
.on('all', function(f, stat) {
monitor.emit('watch:restart', { file: f, stat: stat });
monitor.restart();
})
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
],
"dependencies": {
"broadway": "~0.3.6",
"chokidar": "^1.0.1",
"minimatch": "~2.0.0",
"ps-tree": "0.0.x",
"watch": "~0.13.0",
"utile": "~0.2.1"
},
"devDependencies": {
Expand Down

0 comments on commit 12e35fc

Please sign in to comment.