@@ -18,7 +18,7 @@ const schema = require("./options.json");
18
18
/** @typedef {import("webpack").Stats } Stats */
19
19
/** @typedef {import("webpack").MultiStats } MultiStats */
20
20
/** @typedef {import("os").NetworkInterfaceInfo } NetworkInterfaceInfo */
21
- /** @typedef {import("chokidar").ChokidarOptions } WatchOptions */
21
+ /** @typedef {import("chokidar").ChokidarOptions & { disableGlobbing?: boolean } } WatchOptions */
22
22
/** @typedef {import("chokidar").FSWatcher } FSWatcher */
23
23
/** @typedef {import("connect-history-api-fallback").Options } ConnectHistoryApiFallbackOptions */
24
24
/** @typedef {import("bonjour-service").Bonjour } Bonjour */
@@ -3257,30 +3257,64 @@ class Server {
3257
3257
*/
3258
3258
watchFiles ( watchPath , watchOptions = { } ) {
3259
3259
const chokidar = require ( "chokidar" ) ;
3260
- const isGlob = require ( "is-glob" ) ;
3261
3260
3262
3261
const watchPathArr = Array . isArray ( watchPath ) ? watchPath : [ watchPath ] ;
3263
- const watchPathGlobs = watchPathArr . filter ( ( p ) => isGlob ( p ) ) ;
3264
3262
3265
- // No need to do all this work when no globs are used
3266
- if ( watchPathGlobs . length > 0 ) {
3267
- const globParent = require ( "glob-parent" ) ;
3268
- const picomatch = require ( "picomatch" ) ;
3263
+ if ( watchOptions . disableGlobbing !== true ) {
3264
+ const isGlob = require ( "is-glob" ) ;
3265
+ const watchPathGlobs = watchPathArr . filter ( ( p ) => isGlob ( p ) ) ;
3269
3266
3270
- watchPathGlobs . forEach ( ( p ) => {
3271
- watchPathArr [ watchPathArr . indexOf ( p ) ] = globParent ( p ) ;
3272
- } ) ;
3267
+ // No need to do all this work when no globs are used
3268
+ if ( watchPathGlobs . length > 0 ) {
3269
+ const globParent = require ( "glob-parent" ) ;
3270
+ const picomatch = require ( "picomatch" ) ;
3273
3271
3274
- const matcher = picomatch ( watchPathGlobs ) ;
3275
- const ignoreFunc = ( /** @type { string } */ p ) =>
3276
- ! watchPathArr . includes ( p ) && ! matcher ( p ) ;
3272
+ watchPathGlobs . forEach ( ( p ) => {
3273
+ watchPathArr [ watchPathArr . indexOf ( p ) ] = globParent ( p ) ;
3274
+ } ) ;
3277
3275
3278
- if ( Array . isArray ( watchOptions . ignored ) ) {
3279
- watchOptions . ignored . push ( ignoreFunc ) ;
3280
- } else {
3281
- watchOptions . ignored = watchOptions . ignored
3282
- ? [ watchOptions . ignored , ignoreFunc ]
3283
- : ignoreFunc ;
3276
+ const matcher = picomatch ( watchPathGlobs , {
3277
+ cwd : watchOptions . cwd ,
3278
+ dot : true ,
3279
+ } ) ;
3280
+ const ignoreFunc = ( /** @type {string } */ p ) =>
3281
+ ! watchPathArr . includes ( p ) && ! matcher ( p ) ;
3282
+
3283
+ if ( Array . isArray ( watchOptions . ignored ) ) {
3284
+ const ignoredGlobs = [ ] ;
3285
+ for ( let i = 0 ; i < watchOptions . ignored . length ; i ++ ) {
3286
+ const ignored = watchOptions . ignored [ i ] ;
3287
+ if ( typeof ignored === "string" && isGlob ( ignored ) ) {
3288
+ ignoredGlobs . push ( ignored ) ;
3289
+ watchOptions . ignored . splice ( i , 1 ) ;
3290
+ }
3291
+ }
3292
+
3293
+ if ( ignoredGlobs . length > 0 ) {
3294
+ const ignoreMatcher = picomatch ( ignoredGlobs , {
3295
+ dot : true ,
3296
+ cwd : watchOptions . cwd ,
3297
+ } ) ;
3298
+ watchOptions . ignored . push ( ignoreMatcher ) ;
3299
+ }
3300
+
3301
+ watchOptions . ignored . push ( ignoreFunc ) ;
3302
+ } else {
3303
+ if (
3304
+ watchOptions . ignored &&
3305
+ typeof watchOptions . ignored === "string" &&
3306
+ isGlob ( watchOptions . ignored )
3307
+ ) {
3308
+ watchOptions . ignored = picomatch ( watchOptions . ignored , {
3309
+ dot : true ,
3310
+ cwd : watchOptions . cwd ,
3311
+ } ) ;
3312
+ }
3313
+
3314
+ watchOptions . ignored = watchOptions . ignored
3315
+ ? [ watchOptions . ignored , ignoreFunc ]
3316
+ : ignoreFunc ;
3317
+ }
3284
3318
}
3285
3319
}
3286
3320
0 commit comments