Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const schema = require("./options.json");
/** @typedef {import("webpack").Stats} Stats */
/** @typedef {import("webpack").MultiStats} MultiStats */
/** @typedef {import("os").NetworkInterfaceInfo} NetworkInterfaceInfo */
/** @typedef {import("chokidar").WatchOptions} WatchOptions */
/** @typedef {import("chokidar").ChokidarOptions} WatchOptions */
/** @typedef {import("chokidar").FSWatcher} FSWatcher */
/** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */
/** @typedef {import("bonjour-service").Bonjour} Bonjour */
Expand Down Expand Up @@ -833,7 +833,7 @@ class Server {

const usePolling = getPolling();
const interval = getInterval();
const { poll, ...rest } = watchOptions;
const { poll: _poll, interval: _interval, ...rest } = watchOptions;

return {
ignoreInitial: true,
Expand All @@ -844,9 +844,7 @@ class Server {
ignorePermissionErrors: true,
// Respect options from compiler watchOptions
usePolling,
interval,
ignored: watchOptions.ignored,
// 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
...(interval !== undefined ? { interval } : {}),
...rest,
};
};
Expand Down Expand Up @@ -3188,10 +3186,30 @@ class Server {
* @param {string | string[]} watchPath watch path
* @param {WatchOptions=} watchOptions watch options
*/
watchFiles(watchPath, watchOptions) {
watchFiles(watchPath, watchOptions = {}) {
const chokidar = require("chokidar");
const { globSync, isDynamicPattern } = require("tinyglobby");

const watcher = chokidar.watch(watchPath, watchOptions);
const resolveGlobs = (/** @type {string | string[]} */ input) =>
(Array.isArray(input) ? input : [input]).flatMap((path) =>
typeof path === "string" && isDynamicPattern(path)
? globSync(path, { cwd: watchOptions.cwd, absolute: true })
: path,
);

const resolvedPaths = resolveGlobs(watchPath);

if (typeof watchOptions.ignored === "string") {
watchOptions.ignored = resolveGlobs(watchOptions.ignored);
} else if (Array.isArray(watchOptions.ignored)) {
watchOptions.ignored = watchOptions.ignored.flatMap((item) =>
typeof item === "string" && isDynamicPattern(item)
? globSync(item, { cwd: watchOptions.cwd, absolute: true })
: item,
);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it? Can you provide cases where we broken without it?


const watcher = chokidar.watch(resolvedPaths, watchOptions);

// disabling refreshing on changing the content
if (this.options.liveReload) {
Expand Down
156 changes: 103 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/ws": "^8.18.1",
"ansi-html-community": "^0.0.8",
"bonjour-service": "^1.3.0",
"chokidar": "^3.6.0",
"chokidar": "^4.0.3",
"compression": "^1.8.1",
"connect-history-api-fallback": "^2.0.0",
"express": "^5.2.1",
Expand All @@ -66,6 +66,7 @@
"schema-utils": "^4.3.3",
"selfsigned": "^5.5.0",
"serve-index": "^1.9.2",
"tinyglobby": "^0.2.15",
"webpack-dev-middleware": "^8.0.2",
"ws": "^8.20.0"
},
Expand All @@ -85,6 +86,7 @@
"@types/graceful-fs": "^4.1.9",
"@types/node": "^24.0.14",
"@types/node-forge": "^1.3.1",
"@types/picomatch": "^4.0.2",
"@types/trusted-types": "^2.0.7",
"acorn": "^8.14.0",
"babel-jest": "^30.0.4",
Expand Down
Loading
Loading