@@ -257,26 +257,27 @@ Gaze.prototype._addToWatched = function (files) {
257
257
for ( var i = 0 ; i < files . length ; i ++ ) {
258
258
var file = files [ i ] ;
259
259
var filepath = path . resolve ( this . options . cwd , file ) ;
260
+ var isDir = helper . isDir ( file ) ;
260
261
261
- var dirname = ( helper . isDir ( file ) ) ? filepath : path . dirname ( filepath ) ;
262
+ var dirname = isDir ? filepath : path . dirname ( filepath ) ;
262
263
dirname = helper . markDir ( dirname ) ;
263
264
264
265
// If a new dir is added
265
- if ( helper . isDir ( file ) && ! ( filepath in this . _watched ) ) {
266
- helper . objectPush ( this . _watched , filepath , [ ] ) ;
266
+ if ( ! ( dirname in this . _watched ) ) {
267
+ helper . objectPush ( this . _watched , dirname , [ ] ) ;
268
+
269
+ // add folders into the mix
270
+ var readdir = fs . readdirSync ( dirname ) ;
271
+ for ( var j = 0 ; j < readdir . length ; j ++ ) {
272
+ var dirfile = path . join ( dirname , readdir [ j ] ) ;
273
+ if ( fs . lstatSync ( dirfile ) . isDirectory ( ) ) {
274
+ helper . objectPush ( this . _watched , dirname , dirfile + path . sep ) ;
275
+ }
276
+ }
267
277
}
268
278
269
279
if ( file . slice ( - 1 ) === '/' ) { filepath += path . sep ; }
270
280
helper . objectPush ( this . _watched , path . dirname ( filepath ) + path . sep , filepath ) ;
271
-
272
- // add folders into the mix
273
- var readdir = fs . readdirSync ( dirname ) ;
274
- for ( var j = 0 ; j < readdir . length ; j ++ ) {
275
- var dirfile = path . join ( dirname , readdir [ j ] ) ;
276
- if ( fs . lstatSync ( dirfile ) . isDirectory ( ) ) {
277
- helper . objectPush ( this . _watched , dirname , dirfile + path . sep ) ;
278
- }
279
- }
280
281
}
281
282
return this ;
282
283
} ;
0 commit comments