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