@@ -31,9 +31,12 @@ function rulesToMonitor(watch, ignore, config) {
31
31
}
32
32
33
33
if ( ignore ) {
34
- [ ] . push . apply ( monitor , ( ignore || [ ] ) . map ( function ( rule ) {
35
- return '!' + rule ;
36
- } ) ) ;
34
+ [ ] . push . apply (
35
+ monitor ,
36
+ ( ignore || [ ] ) . map ( function ( rule ) {
37
+ return '!' + rule ;
38
+ } )
39
+ ) ;
37
40
}
38
41
39
42
var cwd = process . cwd ( ) ;
@@ -87,16 +90,16 @@ function rulesToMonitor(watch, ignore, config) {
87
90
88
91
// if the url ends with * but not **/* and not *.*
89
92
// then convert to **/* - somehow it was missed :-\
90
- if ( rule . slice ( - 4 ) !== '**/*' &&
93
+ if (
94
+ rule . slice ( - 4 ) !== '**/*' &&
91
95
rule . slice ( - 1 ) === '*' &&
92
- rule . indexOf ( '*.' ) === - 1 ) {
93
-
96
+ rule . indexOf ( '*.' ) === - 1
97
+ ) {
94
98
if ( rule . slice ( - 2 ) !== '**' ) {
95
99
rule += '*/*' ;
96
100
}
97
101
}
98
102
99
-
100
103
return ( not ? '!' : '' ) + rule ;
101
104
} ) ;
102
105
@@ -105,7 +108,8 @@ function rulesToMonitor(watch, ignore, config) {
105
108
106
109
function tryBaseDir ( dir ) {
107
110
var stat ;
108
- if ( / [ ? * \{ \[ ] + / . test ( dir ) ) { // if this is pattern, then try to find the base
111
+ if ( / [ ? * \{ \[ ] + / . test ( dir ) ) {
112
+ // if this is pattern, then try to find the base
109
113
try {
110
114
var base = path . dirname ( dir . replace ( / ( [ ? * \{ \[ ] + .* $ ) / , 'foo' ) ) ;
111
115
stat = fs . statSync ( base ) ;
@@ -123,7 +127,7 @@ function tryBaseDir(dir) {
123
127
if ( stat . isFile ( ) || stat . isDirectory ( ) ) {
124
128
return dir ;
125
129
}
126
- } catch ( e ) { }
130
+ } catch ( e ) { }
127
131
}
128
132
129
133
return false ;
@@ -133,50 +137,52 @@ function match(files, monitor, ext) {
133
137
// sort the rules by highest specificity (based on number of slashes)
134
138
// ignore rules (!) get sorted highest as they take precedent
135
139
const cwd = process . cwd ( ) ;
136
- var rules = monitor . sort ( function ( a , b ) {
137
- var r = b . split ( path . sep ) . length - a . split ( path . sep ) . length ;
138
- var aIsIgnore = a . slice ( 0 , 1 ) === '!' ;
139
- var bIsIgnore = b . slice ( 0 , 1 ) === '!' ;
140
-
141
- if ( aIsIgnore || bIsIgnore ) {
142
- if ( aIsIgnore ) {
143
- return - 1 ;
140
+ var rules = monitor
141
+ . sort ( function ( a , b ) {
142
+ var r = b . split ( path . sep ) . length - a . split ( path . sep ) . length ;
143
+ var aIsIgnore = a . slice ( 0 , 1 ) === '!' ;
144
+ var bIsIgnore = b . slice ( 0 , 1 ) === '!' ;
145
+
146
+ if ( aIsIgnore || bIsIgnore ) {
147
+ if ( aIsIgnore ) {
148
+ return - 1 ;
149
+ }
150
+
151
+ return 1 ;
144
152
}
145
153
146
- return 1 ;
147
- }
154
+ if ( r === 0 ) {
155
+ return b . length - a . length ;
156
+ }
157
+ return r ;
158
+ } )
159
+ . map ( function ( s ) {
160
+ var prefix = s . slice ( 0 , 1 ) ;
161
+
162
+ if ( prefix === '!' ) {
163
+ if ( s . indexOf ( '!' + cwd ) === 0 ) {
164
+ return s ;
165
+ }
148
166
149
- if ( r === 0 ) {
150
- return b . length - a . length ;
151
- }
152
- return r ;
153
- } ) . map ( function ( s ) {
154
- var prefix = s . slice ( 0 , 1 ) ;
167
+ // if it starts with a period, then let's get the relative path
168
+ if ( s . indexOf ( '!.' ) === 0 ) {
169
+ return '!' + path . resolve ( cwd , s . substring ( 1 ) ) ;
170
+ }
155
171
156
- if ( prefix === '!' ) {
157
- if ( s . indexOf ( '!' + cwd ) === 0 ) {
158
- return s ;
172
+ return '!**' + ( prefix !== path . sep ? path . sep : '' ) + s . slice ( 1 ) ;
159
173
}
160
174
161
175
// if it starts with a period, then let's get the relative path
162
- if ( s . indexOf ( '! .' ) === 0 ) {
163
- return '!' + path . resolve ( cwd , s . substring ( 1 ) ) ;
176
+ if ( s . indexOf ( '.' ) === 0 ) {
177
+ return path . resolve ( cwd , s ) ;
164
178
}
165
179
166
- return '!**' + ( prefix !== path . sep ? path . sep : '' ) + s . slice ( 1 ) ;
167
- }
168
-
169
- // if it starts with a period, then let's get the relative path
170
- if ( s . indexOf ( '.' ) === 0 ) {
171
- return path . resolve ( cwd , s ) ;
172
- }
173
-
174
- if ( s . indexOf ( cwd ) === 0 ) {
175
- return s ;
176
- }
180
+ if ( s . indexOf ( cwd ) === 0 ) {
181
+ return s ;
182
+ }
177
183
178
- return '**' + ( prefix !== path . sep ? path . sep : '' ) + s ;
179
- } ) ;
184
+ return '**' + ( prefix !== path . sep ? path . sep : '' ) + s ;
185
+ } ) ;
180
186
181
187
debug ( 'rules' , rules ) ;
182
188
@@ -221,8 +227,10 @@ function match(files, monitor, ext) {
221
227
// but *does* match a rule that ends with *.*, then
222
228
// white list it - in that we don't run it through
223
229
// the extension check too.
224
- if ( rules [ i ] !== '**' + path . sep + '*.*' &&
225
- rules [ i ] . slice ( - 3 ) === '*.*' ) {
230
+ if (
231
+ rules [ i ] !== '**' + path . sep + '*.*' &&
232
+ rules [ i ] . slice ( - 3 ) === '*.*'
233
+ ) {
226
234
whitelist . push ( file ) ;
227
235
} else if ( path . basename ( file ) === path . basename ( rules [ i ] ) ) {
228
236
// if the file matches the actual rule, then it's put on whitelist
@@ -231,7 +239,6 @@ function match(files, monitor, ext) {
231
239
good . push ( file ) ;
232
240
}
233
241
matched = true ;
234
- break ;
235
242
} else {
236
243
// utils.log.detail('no match: ' + rules[i], file);
237
244
}
@@ -242,8 +249,6 @@ function match(files, monitor, ext) {
242
249
}
243
250
} ) ;
244
251
245
- debug ( 'good' , good )
246
-
247
252
// finally check the good files against the extensions that we're monitoring
248
253
if ( ext ) {
249
254
if ( ext . indexOf ( ',' ) === - 1 ) {
@@ -256,7 +261,13 @@ function match(files, monitor, ext) {
256
261
// only compare the filename to the extension test
257
262
return minimatch ( path . basename ( file ) , ext , minimatchOpts ) ;
258
263
} ) ;
259
- } // else assume *.*
264
+ debug ( 'good (filtered by ext)' , good ) ;
265
+ } else {
266
+ // else assume *.*
267
+ debug ( 'good' , good ) ;
268
+ }
269
+
270
+ if ( whitelist . length ) debug ( 'whitelist' , whitelist ) ;
260
271
261
272
var result = good . concat ( whitelist ) ;
262
273
0 commit comments