diff --git a/index.js b/index.js index cf8b763..317ac01 100755 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const NodeWatcher = require('./src/node_watcher'); const PollWatcher = require('./src/poll_watcher'); const WatchmanWatcher = require('./src/watchman_watcher'); const FSEventsWatcher = require('./src/fsevents_watcher'); +const WatchDetector = require('watch-detector'); function sane(dir, options) { options = options || {}; @@ -16,6 +17,18 @@ function sane(dir, options) { return new WatchmanWatcher(dir, options); } else if (options.fsevents) { return new FSEventsWatcher(dir, options); + } else if (options.auto) { + delete options.auto; + const detector = new WatchDetector({ + fs: require('fs'), + root: dir, + ui: { + writeLine(message) { + console.log(message); + }, + }, + }); + return sane(dir, detector.findBestWatcherOption(options)); } else { return new NodeWatcher(dir, options); } diff --git a/package.json b/package.json index f23c518..37dd91b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "micromatch": "^3.1.4", "minimist": "^1.1.1", "walker": "~1.0.5", - "watch": "~0.18.0" + "watch": "~0.18.0", + "watch-detector": "^0.1.0" }, "devDependencies": { "eslint": "^3.19.0",