@@ -6,6 +6,7 @@ var asyncDone = require('async-done');
66var defaults = require ( 'object.defaults/immutable' ) ;
77var isNegatedGlob = require ( 'is-negated-glob' ) ;
88var anymatch = require ( 'anymatch' ) ;
9+ var normalize = require ( 'normalize-path' ) ;
910
1011var defaultOpts = {
1112 delay : 200 ,
@@ -71,24 +72,34 @@ function watch(glob, options, cb) {
7172 }
7273 }
7374
74- function shouldBeIgnored ( path ) {
75- var positiveMatch = anymatch ( positives , path , true ) ;
76- var negativeMatch = anymatch ( negatives , path , true ) ;
77- // If negativeMatch is -1, that means it was never negated
78- if ( negativeMatch === - 1 ) {
79- return false ;
75+ var toWatch = positives . filter ( exists ) ;
76+
77+ function joinCwd ( glob ) {
78+ if ( glob && opt . cwd ) {
79+ return normalize ( opt . cwd + '/' + glob ) ;
8080 }
8181
82- // If the negative is "less than" the positive, that means
83- // it came later in the glob array before we reversed them
84- return negativeMatch < positiveMatch ;
82+ return glob ;
8583 }
8684
87- var toWatch = positives . filter ( exists ) ;
88-
8985 // We only do add our custom `ignored` if there are some negative globs
9086 // TODO: I'm not sure how to test this
9187 if ( negatives . some ( exists ) ) {
88+ var normalizedPositives = positives . map ( joinCwd ) ;
89+ var normalizedNegatives = negatives . map ( joinCwd ) ;
90+ var shouldBeIgnored = function ( path ) {
91+ var positiveMatch = anymatch ( normalizedPositives , path , true ) ;
92+ var negativeMatch = anymatch ( normalizedNegatives , path , true ) ;
93+ // If negativeMatch is -1, that means it was never negated
94+ if ( negativeMatch === - 1 ) {
95+ return false ;
96+ }
97+
98+ // If the negative is "less than" the positive, that means
99+ // it came later in the glob array before we reversed them
100+ return negativeMatch < positiveMatch ;
101+ } ;
102+
92103 opt . ignored = [ ] . concat ( opt . ignored , shouldBeIgnored ) ;
93104 }
94105 var watcher = chokidar . watch ( toWatch , opt ) ;
0 commit comments