@@ -17,7 +17,7 @@ const schema = require("./options.json");
1717/** @typedef {import("webpack").Stats } Stats */
1818/** @typedef {import("webpack").MultiStats } MultiStats */
1919/** @typedef {import("os").NetworkInterfaceInfo } NetworkInterfaceInfo */
20- /** @typedef {import("chokidar").WatchOptions } WatchOptions */
20+ /** @typedef {import("chokidar").ChokidarOptions } WatchOptions */
2121/** @typedef {import("chokidar").FSWatcher } FSWatcher */
2222/** @typedef {import("connect-history-api-fallback").Options } ConnectHistoryApiFallbackOptions */
2323/** @typedef {import("bonjour-service").Bonjour } Bonjour */
@@ -833,7 +833,7 @@ class Server {
833833
834834 const usePolling = getPolling ( ) ;
835835 const interval = getInterval ( ) ;
836- const { poll, ...rest } = watchOptions ;
836+ const { poll : _poll , interval : _interval , ...rest } = watchOptions ;
837837
838838 return {
839839 ignoreInitial : true ,
@@ -844,9 +844,7 @@ class Server {
844844 ignorePermissionErrors : true ,
845845 // Respect options from compiler watchOptions
846846 usePolling,
847- interval,
848- ignored : watchOptions . ignored ,
849- // TODO: we respect these options for all watch options and allow developers to pass them to chokidar, but chokidar doesn't have these options maybe we need revisit that in future
847+ ...( interval !== undefined ? { interval } : { } ) ,
850848 ...rest ,
851849 } ;
852850 } ;
@@ -3188,10 +3186,42 @@ class Server {
31883186 * @param {string | string[] } watchPath watch path
31893187 * @param {WatchOptions= } watchOptions watch options
31903188 */
3191- watchFiles ( watchPath , watchOptions ) {
3189+ watchFiles ( watchPath , watchOptions = { } ) {
31923190 const chokidar = require ( "chokidar" ) ;
3191+ const path = require ( "node:path" ) ;
3192+ const { globSync, isDynamicPattern } = require ( "tinyglobby" ) ;
3193+
3194+ const isWin = path . sep === "\\" ;
3195+ const toPosix = ( /** @type {string } */ filePath ) =>
3196+ isWin ? filePath . split ( path . sep ) . join ( "/" ) : filePath ;
3197+ const toNative = ( /** @type {string } */ filePath ) =>
3198+ isWin ? filePath . split ( "/" ) . join ( path . sep ) : filePath ;
3199+
3200+ const cwd = watchOptions . cwd ? toPosix ( watchOptions . cwd ) : undefined ;
3201+
3202+ const expand = ( /** @type {string } */ item ) => {
3203+ const posix = toPosix ( item ) ;
3204+ return isDynamicPattern ( posix )
3205+ ? globSync ( posix , { cwd, absolute : true } ) . map ( toNative )
3206+ : item ;
3207+ } ;
3208+
3209+ const resolveGlobs = ( /** @type {string | string[] } */ input ) =>
3210+ ( Array . isArray ( input ) ? input : [ input ] ) . flatMap ( ( item ) =>
3211+ typeof item === "string" ? expand ( item ) : item ,
3212+ ) ;
3213+
3214+ const resolvedPaths = resolveGlobs ( watchPath ) ;
3215+
3216+ if ( typeof watchOptions . ignored === "string" ) {
3217+ watchOptions . ignored = resolveGlobs ( watchOptions . ignored ) ;
3218+ } else if ( Array . isArray ( watchOptions . ignored ) ) {
3219+ watchOptions . ignored = watchOptions . ignored . flatMap ( ( item ) =>
3220+ typeof item === "string" ? expand ( item ) : item ,
3221+ ) ;
3222+ }
31933223
3194- const watcher = chokidar . watch ( watchPath , watchOptions ) ;
3224+ const watcher = chokidar . watch ( resolvedPaths , watchOptions ) ;
31953225
31963226 // disabling refreshing on changing the content
31973227 if ( this . options . liveReload ) {
0 commit comments