diff --git a/lib/gaze.js b/lib/gaze.js index 1f00567..b5b6bde 100644 --- a/lib/gaze.js +++ b/lib/gaze.js @@ -270,6 +270,8 @@ Gaze.prototype.relative = function (dir, unixify) { // Adds files and dirs to watched Gaze.prototype._addToWatched = function (files) { + var dirs = []; + for (var i = 0; i < files.length; i++) { var file = files[i]; var filepath = path.resolve(this.options.cwd, file); @@ -285,6 +287,13 @@ Gaze.prototype._addToWatched = function (files) { if (file.slice(-1) === '/') { filepath += path.sep; } helper.objectPush(this._watched, path.dirname(filepath) + path.sep, filepath); + dirs.push(dirname); + } + + dirs = helper.unique(dirs); + + for (var k = 0; k < dirs.length; k++) { + dirname = dirs[k]; // add folders into the mix var readdir = fs.readdirSync(dirname); for (var j = 0; j < readdir.length; j++) { @@ -294,6 +303,7 @@ Gaze.prototype._addToWatched = function (files) { } } } + return this; };