@@ -6,6 +6,7 @@ var asyncDone = require('async-done');
6
6
var defaults = require ( 'object.defaults/immutable' ) ;
7
7
var isNegatedGlob = require ( 'is-negated-glob' ) ;
8
8
var anymatch = require ( 'anymatch' ) ;
9
+ var normalize = require ( 'normalize-path' ) ;
9
10
10
11
var defaultOpts = {
11
12
delay : 200 ,
@@ -71,24 +72,34 @@ function watch(glob, options, cb) {
71
72
}
72
73
}
73
74
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 ) ;
80
80
}
81
81
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 ;
85
83
}
86
84
87
- var toWatch = positives . filter ( exists ) ;
88
-
89
85
// We only do add our custom `ignored` if there are some negative globs
90
86
// TODO: I'm not sure how to test this
91
87
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
+
92
103
opt . ignored = [ ] . concat ( opt . ignored , shouldBeIgnored ) ;
93
104
}
94
105
var watcher = chokidar . watch ( toWatch , opt ) ;
0 commit comments