Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update chokidar to v4 #5374

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
examples/**/main.js
examples/client/trusted-types-overlay/app.js
test/fixtures/reload-config/foo.js
test/fixtures/worker-config-dev-server-false/public/worker-bundle.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ yarn-error.log

test/fixtures/static-config/public/assets/non-exist.txt
test/fixtures/watch-files-config/public/assets/non-exist.txt
test/fixtures/watch-files-config/public/non-existant/non-exist.txt
test/fixtures/reload-config/main.css
test/fixtures/reload-config-2/main.css
test/fixtures/worker-config-dev-server-false/public
Expand Down
67 changes: 64 additions & 3 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 & { disableGlobbing?: boolean }} WatchOptions */
/** @typedef {import("chokidar").FSWatcher} FSWatcher */
/** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */
/** @typedef {import("bonjour-service").Bonjour} Bonjour */
Expand Down Expand Up @@ -3255,9 +3255,70 @@ class Server {
* @param {string | string[]} watchPath
* @param {WatchOptions} [watchOptions]
*/
watchFiles(watchPath, watchOptions) {
watchFiles(watchPath, watchOptions = {}) {
const chokidar = require("chokidar");
const watcher = chokidar.watch(watchPath, watchOptions);

const watchPathArr = Array.isArray(watchPath) ? watchPath : [watchPath];

if (watchOptions.disableGlobbing !== true) {
const isGlob = require("is-glob");
const watchPathGlobs = watchPathArr.filter((p) => isGlob(p));

// No need to do all this work when no globs are used
if (watchPathGlobs.length > 0) {
const globParent = require("glob-parent");
const picomatch = require("picomatch");

watchPathGlobs.forEach((p) => {
watchPathArr[watchPathArr.indexOf(p)] = globParent(p);
});

const matcher = picomatch(watchPathGlobs, {
cwd: watchOptions.cwd,
dot: true,
alexander-akait marked this conversation as resolved.
Show resolved Hide resolved
});
const ignoreFunc = (/** @type {string} */ p) =>
!watchPathArr.includes(p) && !matcher(p);

if (Array.isArray(watchOptions.ignored)) {
const ignoredGlobs = [];
for (let i = 0; i < watchOptions.ignored.length; i++) {
const ignored = watchOptions.ignored[i];
if (typeof ignored === "string" && isGlob(ignored)) {
ignoredGlobs.push(ignored);
watchOptions.ignored.splice(i, 1);
}
}

if (ignoredGlobs.length > 0) {
const ignoreMatcher = picomatch(ignoredGlobs, {
dot: true,
cwd: watchOptions.cwd,
});
watchOptions.ignored.push(ignoreMatcher);
}

watchOptions.ignored.push(ignoreFunc);
} else {
if (
watchOptions.ignored &&
typeof watchOptions.ignored === "string" &&
isGlob(watchOptions.ignored)
) {
watchOptions.ignored = picomatch(watchOptions.ignored, {
dot: true,
cwd: watchOptions.cwd,
});
}
Fuzzyma marked this conversation as resolved.
Show resolved Hide resolved

watchOptions.ignored = watchOptions.ignored
? [watchOptions.ignored, ignoreFunc]
: ignoreFunc;
}
}
}

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

// disabling refreshing on changing the content
if (this.options.liveReload) {
Expand Down
Loading