@@ -31,9 +31,12 @@ function rulesToMonitor(watch, ignore, config) {
3131 }
3232
3333 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+ ) ;
3740 }
3841
3942 var cwd = process . cwd ( ) ;
@@ -87,16 +90,16 @@ function rulesToMonitor(watch, ignore, config) {
8790
8891 // if the url ends with * but not **/* and not *.*
8992 // then convert to **/* - somehow it was missed :-\
90- if ( rule . slice ( - 4 ) !== '**/*' &&
93+ if (
94+ rule . slice ( - 4 ) !== '**/*' &&
9195 rule . slice ( - 1 ) === '*' &&
92- rule . indexOf ( '*.' ) === - 1 ) {
93-
96+ rule . indexOf ( '*.' ) === - 1
97+ ) {
9498 if ( rule . slice ( - 2 ) !== '**' ) {
9599 rule += '*/*' ;
96100 }
97101 }
98102
99-
100103 return ( not ? '!' : '' ) + rule ;
101104 } ) ;
102105
@@ -105,7 +108,8 @@ function rulesToMonitor(watch, ignore, config) {
105108
106109function tryBaseDir ( dir ) {
107110 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
109113 try {
110114 var base = path . dirname ( dir . replace ( / ( [ ? * \{ \[ ] + .* $ ) / , 'foo' ) ) ;
111115 stat = fs . statSync ( base ) ;
@@ -123,7 +127,7 @@ function tryBaseDir(dir) {
123127 if ( stat . isFile ( ) || stat . isDirectory ( ) ) {
124128 return dir ;
125129 }
126- } catch ( e ) { }
130+ } catch ( e ) { }
127131 }
128132
129133 return false ;
@@ -133,50 +137,52 @@ function match(files, monitor, ext) {
133137 // sort the rules by highest specificity (based on number of slashes)
134138 // ignore rules (!) get sorted highest as they take precedent
135139 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 ;
144152 }
145153
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+ }
148166
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+ }
155171
156- if ( prefix === '!' ) {
157- if ( s . indexOf ( '!' + cwd ) === 0 ) {
158- return s ;
172+ return '!**' + ( prefix !== path . sep ? path . sep : '' ) + s . slice ( 1 ) ;
159173 }
160174
161175 // 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 ) ;
164178 }
165179
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+ }
177183
178- return '**' + ( prefix !== path . sep ? path . sep : '' ) + s ;
179- } ) ;
184+ return '**' + ( prefix !== path . sep ? path . sep : '' ) + s ;
185+ } ) ;
180186
181187 debug ( 'rules' , rules ) ;
182188
@@ -221,8 +227,10 @@ function match(files, monitor, ext) {
221227 // but *does* match a rule that ends with *.*, then
222228 // white list it - in that we don't run it through
223229 // 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+ ) {
226234 whitelist . push ( file ) ;
227235 } else if ( path . basename ( file ) === path . basename ( rules [ i ] ) ) {
228236 // if the file matches the actual rule, then it's put on whitelist
@@ -231,7 +239,6 @@ function match(files, monitor, ext) {
231239 good . push ( file ) ;
232240 }
233241 matched = true ;
234- break ;
235242 } else {
236243 // utils.log.detail('no match: ' + rules[i], file);
237244 }
@@ -242,8 +249,6 @@ function match(files, monitor, ext) {
242249 }
243250 } ) ;
244251
245- debug ( 'good' , good )
246-
247252 // finally check the good files against the extensions that we're monitoring
248253 if ( ext ) {
249254 if ( ext . indexOf ( ',' ) === - 1 ) {
@@ -256,7 +261,13 @@ function match(files, monitor, ext) {
256261 // only compare the filename to the extension test
257262 return minimatch ( path . basename ( file ) , ext , minimatchOpts ) ;
258263 } ) ;
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 ) ;
260271
261272 var result = good . concat ( whitelist ) ;
262273
0 commit comments