@@ -3259,15 +3259,18 @@ class Server {
3259
3259
const chokidar = require ( "chokidar" ) ;
3260
3260
3261
3261
const watchPathArr = Array . isArray ( watchPath ) ? watchPath : [ watchPath ] ;
3262
+ const ignoredArr = Array . isArray ( watchOptions . ignored )
3263
+ ? watchOptions . ignored
3264
+ : [ ] ;
3262
3265
3263
3266
if ( watchOptions . disableGlobbing !== true ) {
3267
+ const picomatch = require ( "picomatch" ) ;
3264
3268
const isGlob = require ( "is-glob" ) ;
3265
3269
const watchPathGlobs = watchPathArr . filter ( ( p ) => isGlob ( p ) ) ;
3266
3270
3267
- // No need to do all this work when no globs are used
3271
+ // No need to do all this work when no globs are used in watcher
3268
3272
if ( watchPathGlobs . length > 0 ) {
3269
3273
const globParent = require ( "glob-parent" ) ;
3270
- const picomatch = require ( "picomatch" ) ;
3271
3274
3272
3275
watchPathGlobs . forEach ( ( p ) => {
3273
3276
watchPathArr [ watchPathArr . indexOf ( p ) ] = globParent ( p ) ;
@@ -3278,39 +3281,29 @@ class Server {
3278
3281
dot : true ,
3279
3282
} ) ;
3280
3283
3281
- const ignoreFunc = ( /** @type {string } */ p ) =>
3282
- ! watchPathArr . includes ( p ) && ! matcher ( p ) ;
3283
-
3284
- const ignoredArr = Array . isArray ( watchOptions . ignored )
3285
- ? watchOptions . ignored
3286
- : [ ] ;
3287
-
3288
- // Nested ternaries are forbidden by eslint so we end up with this
3289
- if ( watchOptions . ignored && ! Array . isArray ( watchOptions . ignored ) ) {
3290
- ignoredArr . push ( watchOptions . ignored ) ;
3291
- }
3292
-
3293
- const ignoredGlobs = [ ] ;
3294
- for ( let i = 0 ; i < ignoredArr . length ; i ++ ) {
3295
- const ignored = ignoredArr [ i ] ;
3296
- if ( typeof ignored === "string" && isGlob ( ignored ) ) {
3297
- ignoredGlobs . push ( ignored ) ;
3298
- ignoredArr . splice ( i , 1 ) ;
3299
- }
3300
- }
3284
+ // Ignore all paths that don't match any of the globs
3285
+ ignoredArr . push ( ( p ) => ! watchPathArr . includes ( p ) && ! matcher ( p ) ) ;
3286
+ }
3301
3287
3302
- if ( ignoredGlobs . length > 0 ) {
3303
- const ignoreMatcher = picomatch ( ignoredGlobs , {
3304
- dot : true ,
3305
- cwd : watchOptions . cwd ,
3306
- } ) ;
3307
- ignoredArr . push ( ignoreMatcher ) ;
3308
- }
3288
+ // Double filter to satisfy typescript. Otherwise nasty casting is required
3289
+ const ignoredGlobs = ignoredArr
3290
+ . filter ( ( s ) => typeof s === "string" )
3291
+ . filter ( ( s ) => isGlob ( s ) ) ;
3309
3292
3310
- ignoredArr . push ( ignoreFunc ) ;
3293
+ // No need to do all this work when no globs are used in ignored
3294
+ if ( ignoredGlobs . length > 0 ) {
3295
+ const matcher = picomatch ( ignoredGlobs , {
3296
+ cwd : watchOptions . cwd ,
3297
+ dot : true ,
3298
+ } ) ;
3311
3299
3312
- watchOptions . ignored = ignoredArr ;
3300
+ ignoredArr . push ( matcher ) ;
3313
3301
}
3302
+
3303
+ // Filter out all the glob strings
3304
+ watchOptions . ignored = ignoredArr . filter (
3305
+ ( s ) => typeof s === "string" && isGlob ( s ) ,
3306
+ ) ;
3314
3307
}
3315
3308
3316
3309
const watcher = chokidar . watch ( watchPathArr , watchOptions ) ;
0 commit comments