Skip to content

Commit

Permalink
Allow to set a custom watchman binary path (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 authored and amasad committed Jan 22, 2018
1 parent 516623b commit e1bcc0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ options:
* `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`.
* `watchman`: makes the watcher use [watchman](https://facebook.github.io/watchman/).
* `watchmanPath`: sets a custom path for `watchman` binary.
* `dot`: enables watching files/directories that start with a dot.
* `ignored`: a glob, regex, function, or array of any combination.

Expand Down Expand Up @@ -91,7 +92,7 @@ All events are passed the file/dir path relative to the root directory
This module includes a simple command line interface, which you can install with `npm install sane -g`.

```
Usage: sane <command> [...directory] [--glob=<filePattern>] [--poll] [--watchman] [--dot] [--wait=<seconds>]
Usage: sane <command> [...directory] [--glob=<filePattern>] [--poll] [--watchman] [--watchman-path=<watchmanBinaryPath>] [--dot] [--wait=<seconds>]
OPTIONS:
--glob=<filePattern>
Expand All @@ -106,6 +107,9 @@ OPTIONS:
--watchman, -w
Use watchman (if available).
--watchman-path=<watchmanBinaryPath>
Sets a custom path for watchman binary (if using this mode).
--dot, -d
Enables watching files/directories that start with a dot.
Expand Down
6 changes: 5 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var execshell = require('exec-sh');
if (argv._.length === 0) {
var msg =
'Usage: sane <command> [...directory] [--glob=<filePattern>] ' +
'[--ignored=<filePattern>] [--poll] [--watchman] [--dot] ' +
'[--ignored=<filePattern>] [--poll] [--watchman] [--watchman-path=<watchmanBinaryPath>] [--dot] ' +
'[--wait=<seconds>]';
console.error(msg);
process.exit();
Expand All @@ -23,6 +23,7 @@ var glob = argv.glob || argv.g;
var ignored = argv.ignored || argv.i;
var poll = argv.poll || argv.p;
var watchman = argv.watchman || argv.w;
var watchmanPath = argv['watchman-path'];

if (dot) {
opts.dot = true;
Expand All @@ -39,6 +40,9 @@ if (poll) {
if (watchman) {
opts.watchman = true;
}
if (watchmanPath) {
opts.watchmanPath = watchmanPath;
}

var wait = false;
var watcher = sane(dir, opts);
Expand Down
5 changes: 5 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ exports.assignOptions = function(watcher, opts) {
: function() {
return false;
};

if (opts.watchman && opts.watchmanPath) {
watcher.watchmanPath = opts.watchmanPath;
}

return opts;
};

Expand Down
4 changes: 3 additions & 1 deletion src/watchman_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ WatchmanWatcher.prototype.init = function() {
}

var self = this;
this.client = new watchman.Client();
this.client = new watchman.Client(
this.watchmanPath ? { watchmanBinaryPath: this.watchmanPath } : {}
);
this.client.on('error', function(error) {
self.emit('error', error);
});
Expand Down

0 comments on commit e1bcc0c

Please sign in to comment.