diff --git a/lib/config/index.js b/lib/config/index.js index b1f9ef1..60607e9 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -4,6 +4,7 @@ * * This is *not* the user's config. */ +var debug = require('debug')('nodemon'); var load = require('./load'); var rules = require('../rules'); var utils = require('../utils'); @@ -24,9 +25,6 @@ var config = { run: false, system: { cwd: process.cwd(), - useFind: false, - useWatch: false, - useWatchFile: false, }, required: false, dirs: [], @@ -70,6 +68,7 @@ config.load = function (settings, ready) { options.monitor = rulesToMonitor(options.watch, options.ignore, config); var cwd = process.cwd(); + debug('config: dirs', config.dirs); if (config.dirs.length === 0) { config.dirs.unshift(cwd); } diff --git a/lib/monitor/match.js b/lib/monitor/match.js index 089fdac..e3612fb 100644 --- a/lib/monitor/match.js +++ b/lib/monitor/match.js @@ -61,11 +61,8 @@ function rulesToMonitor(watch, ignore, config) { } rule += '**/*'; - // only needed for mac, because on mac we use `find` and it needs some - // narrowing down otherwise it tries to find on the entire drive...which - // is a bit batty. // `!not` ... sorry. - if (config.system.useFind && !not) { + if (!not) { config.dirs.push(dir); } } else { @@ -75,7 +72,7 @@ function rulesToMonitor(watch, ignore, config) { } } catch (e) { var base = tryBaseDir(dir); - if (config.system.useFind && !not && base) { + if (!not && base) { if (config.dirs.indexOf(base) === -1) { config.dirs.push(base); } diff --git a/lib/monitor/watch.js b/lib/monitor/watch.js index 6e45681..b962fc9 100644 --- a/lib/monitor/watch.js +++ b/lib/monitor/watch.js @@ -1,6 +1,7 @@ module.exports = watch; var debug = require('debug')('nodemon'); +var Promise = require('es6-promise').Promise; // jshint ignore:line var chokidar = require('chokidar'); var undefsafe = require('undefsafe'); var config = require('../config'); @@ -29,19 +30,40 @@ function watch() { debug('start watch on: %s', dirs.join(', ')); + var promises = []; + dirs.forEach(function (dir) { - var watcher = chokidar.watch(dir, { - // ignore our files, but also ignore dotfiles - ignored: [config.options.ignore.re, /[\/\\]\./], - persistent: true, - }); + var promise = new Promise(function (resolve) { + var watcher = chokidar.watch(dir, { + // ignore our files, but also ignore dotfiles + ignored: [config.options.ignore.re, /[\/\\]\./], + persistent: true, + }); + var total = 0; - watcher.on('change', filterAndRestart); - watcher.on('addDir', function (arg) { - debug('watching dir: %s', arg); + watcher.on('change', filterAndRestart); + watcher.on('add', function (arg) { + total++; + debug('watching dir: %s', arg); + }); + watcher.on('ready', function () { + resolve(total); + }); + + watchers.push(watcher); }); - watchers.push(watcher); + promises.push(promise); + }); + + Promise.all(promises).then(function (res) { + var total = res.reduce(function (acc, curr) { + acc += curr; + return acc; + }, 0); + + var count = total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); + utils.log.detail('watching ' + count + ' files'); }); } diff --git a/package.json b/package.json index 7124212..eb6e6ff 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "dependencies": { "chokidar": "^1.0.5", "debug": "^2.2.0", + "es6-promise": "^3.0.2", "lodash.defaults": "^3.1.2", "minimatch": "~0.3.0", "ps-tree": "~0.0.3", diff --git a/test/rules/index.test.js b/test/rules/index.test.js index 2ed5c37..b9c3dd1 100644 --- a/test/rules/index.test.js +++ b/test/rules/index.test.js @@ -19,7 +19,7 @@ describe('nodemon rules', function () { regexp: loadfixtures('regexp'), default: loadfixtures('default'), simple: loadfixtures('simple'), - simplejson: loadfixtures('simple.json') + simplejson: loadfixtures('simple.json'), }; beforeEach(function (done) {