-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore(deps): update chokidar to v4 #5374
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
9492a00
184588d
970c353
d883a1a
3dd2b4b
a34faf6
7b113cf
b01a2c3
3374234
5d42bac
c5539b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
|
@@ -3255,9 +3255,65 @@ 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, | ||
}); | ||
|
||
const ignoreFunc = (/** @type {string} */ p) => | ||
!watchPathArr.includes(p) && !matcher(p); | ||
|
||
const ignoredArr = Array.isArray(watchOptions.ignored) | ||
? watchOptions.ignored | ||
: []; | ||
|
||
// Nested ternaries are forbidden by eslint so we end up with this | ||
if (watchOptions.ignored && !Array.isArray(watchOptions.ignored)) { | ||
ignoredArr.push(watchOptions.ignored); | ||
} | ||
|
||
const ignoredGlobs = []; | ||
for (let i = 0; i < ignoredArr.length; i++) { | ||
const ignored = ignoredArr[i]; | ||
if (typeof ignored === "string" && isGlob(ignored)) { | ||
ignoredGlobs.push(ignored); | ||
ignoredArr.splice(i, 1); | ||
} | ||
Fuzzyma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (ignoredGlobs.length > 0) { | ||
const ignoreMatcher = picomatch(ignoredGlobs, { | ||
dot: true, | ||
cwd: watchOptions.cwd, | ||
}); | ||
ignoredArr.push(ignoreMatcher); | ||
} | ||
|
||
ignoredArr.push(ignoreFunc); | ||
|
||
watchOptions.ignored = ignoredArr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Fuzzyma Can we simplify this and rewrite it into a more understandable logic, here one array is derived from the second and the second from the third, it is very difficult to read, I mean:
This is an approximate pseudocode, but it is easy to understand where everything comes from and how it is formed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to finish this soon and make a release There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do! As long as chokidar is not handling the issue linked in the first post, this is blocked anyway. As alternative we have to filter out undefined options ourselves before passing them to chokidar. Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexander-akait I tried it your way. But there is one detail that might end up being performance sensitive. I tried to simplify the code further and think the code that I have now is easy enough to understand. I made it so that everything ends up in the ignoreArr. We need tests for the ignore case though! I am not quite sure how to do the ignore case. I need to take a look. Also I made the snapshots break because ignore is an array now when passied to chokidar. Need to fix that as well |
||
} | ||
} | ||
|
||
const watcher = chokidar.watch(watchPathArr, watchOptions); | ||
|
||
// disabling refreshing on changing the content | ||
if (this.options.liveReload) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.