Skip to content

Commit 7969fd4

Browse files
committed
fix: support ignore globs, enable dotfiles
1 parent 5629ac3 commit 7969fd4

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

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 */
@@ -3256,30 +3256,64 @@ class Server {
32563256
*/
32573257
watchFiles(watchPath, watchOptions = {}) {
32583258
const chokidar = require("chokidar");
3259-
const isGlob = require("is-glob");
32603259

32613260
const watchPathArr = Array.isArray(watchPath) ? watchPath : [watchPath];
3262-
const watchPathGlobs = watchPathArr.filter((p) => isGlob(p));
32633261

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

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

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

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

0 commit comments

Comments
 (0)