Skip to content

Commit 184588d

Browse files
committed
fix: support ignore globs, enable dotfiles
1 parent 9492a00 commit 184588d

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

Diff for: lib/Server.js

+53-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const schema = require("./options.json");
1818
/** @typedef {import("webpack").Stats} Stats */
1919
/** @typedef {import("webpack").MultiStats} MultiStats */
2020
/** @typedef {import("os").NetworkInterfaceInfo} NetworkInterfaceInfo */
21-
/** @typedef {import("chokidar").ChokidarOptions} WatchOptions */
21+
/** @typedef {import("chokidar").ChokidarOptions & { disableGlobbing?: boolean }} WatchOptions */
2222
/** @typedef {import("chokidar").FSWatcher} FSWatcher */
2323
/** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */
2424
/** @typedef {import("bonjour-service").Bonjour} Bonjour */
@@ -3257,30 +3257,64 @@ class Server {
32573257
*/
32583258
watchFiles(watchPath, watchOptions = {}) {
32593259
const chokidar = require("chokidar");
3260-
const isGlob = require("is-glob");
32613260

32623261
const watchPathArr = Array.isArray(watchPath) ? watchPath : [watchPath];
3263-
const watchPathGlobs = watchPathArr.filter((p) => isGlob(p));
32643262

3265-
// No need to do all this work when no globs are used
3266-
if (watchPathGlobs.length > 0) {
3267-
const globParent = require("glob-parent");
3268-
const picomatch = require("picomatch");
3263+
if (watchOptions.disableGlobbing !== true) {
3264+
const isGlob = require("is-glob");
3265+
const watchPathGlobs = watchPathArr.filter((p) => isGlob(p));
32693266

3270-
watchPathGlobs.forEach((p) => {
3271-
watchPathArr[watchPathArr.indexOf(p)] = globParent(p);
3272-
});
3267+
// No need to do all this work when no globs are used
3268+
if (watchPathGlobs.length > 0) {
3269+
const globParent = require("glob-parent");
3270+
const picomatch = require("picomatch");
32733271

3274-
const matcher = picomatch(watchPathGlobs);
3275-
const ignoreFunc = (/** @type {string} */ p) =>
3276-
!watchPathArr.includes(p) && !matcher(p);
3272+
watchPathGlobs.forEach((p) => {
3273+
watchPathArr[watchPathArr.indexOf(p)] = globParent(p);
3274+
});
32773275

3278-
if (Array.isArray(watchOptions.ignored)) {
3279-
watchOptions.ignored.push(ignoreFunc);
3280-
} else {
3281-
watchOptions.ignored = watchOptions.ignored
3282-
? [watchOptions.ignored, ignoreFunc]
3283-
: ignoreFunc;
3276+
const matcher = picomatch(watchPathGlobs, {
3277+
cwd: watchOptions.cwd,
3278+
dot: true,
3279+
});
3280+
const ignoreFunc = (/** @type {string} */ p) =>
3281+
!watchPathArr.includes(p) && !matcher(p);
3282+
3283+
if (Array.isArray(watchOptions.ignored)) {
3284+
const ignoredGlobs = [];
3285+
for (let i = 0; i < watchOptions.ignored.length; i++) {
3286+
const ignored = watchOptions.ignored[i];
3287+
if (typeof ignored === "string" && isGlob(ignored)) {
3288+
ignoredGlobs.push(ignored);
3289+
watchOptions.ignored.splice(i, 1);
3290+
}
3291+
}
3292+
3293+
if (ignoredGlobs.length > 0) {
3294+
const ignoreMatcher = picomatch(ignoredGlobs, {
3295+
dot: true,
3296+
cwd: watchOptions.cwd,
3297+
});
3298+
watchOptions.ignored.push(ignoreMatcher);
3299+
}
3300+
3301+
watchOptions.ignored.push(ignoreFunc);
3302+
} else {
3303+
if (
3304+
watchOptions.ignored &&
3305+
typeof watchOptions.ignored === "string" &&
3306+
isGlob(watchOptions.ignored)
3307+
) {
3308+
watchOptions.ignored = picomatch(watchOptions.ignored, {
3309+
dot: true,
3310+
cwd: watchOptions.cwd,
3311+
});
3312+
}
3313+
3314+
watchOptions.ignored = watchOptions.ignored
3315+
? [watchOptions.ignored, ignoreFunc]
3316+
: ignoreFunc;
3317+
}
32843318
}
32853319
}
32863320

0 commit comments

Comments
 (0)