Skip to content

Commit 970c353

Browse files
committed
fix: simply logic of ignored files
1 parent 184588d commit 970c353

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

lib/Server.js

+23-30
Original file line numberDiff line numberDiff line change
@@ -3277,44 +3277,37 @@ class Server {
32773277
cwd: watchOptions.cwd,
32783278
dot: true,
32793279
});
3280+
32803281
const ignoreFunc = (/** @type {string} */ p) =>
32813282
!watchPathArr.includes(p) && !matcher(p);
32823283

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-
}
3284+
const ignoredArr = Array.isArray(watchOptions.ignored)
3285+
? watchOptions.ignored
3286+
: [];
32923287

3293-
if (ignoredGlobs.length > 0) {
3294-
const ignoreMatcher = picomatch(ignoredGlobs, {
3295-
dot: true,
3296-
cwd: watchOptions.cwd,
3297-
});
3298-
watchOptions.ignored.push(ignoreMatcher);
3299-
}
3288+
// Nested ternaries are forbidden by eslint so we end up with this
3289+
if (watchOptions.ignored && !Array.isArray(watchOptions.ignored)) {
3290+
ignoredArr.push(watchOptions.ignored);
3291+
}
33003292

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-
});
3293+
const ignoredGlobs = [];
3294+
for (let i = 0; i < ignoredArr.length; i++) {
3295+
const ignored = ignoredArr[i];
3296+
if (typeof ignored === "string" && isGlob(ignored)) {
3297+
ignoredGlobs.push(ignored);
3298+
ignoredArr.splice(i, 1);
33123299
}
3300+
}
33133301

3314-
watchOptions.ignored = watchOptions.ignored
3315-
? [watchOptions.ignored, ignoreFunc]
3316-
: ignoreFunc;
3302+
if (ignoredGlobs.length > 0) {
3303+
const ignoreMatcher = picomatch(ignoredGlobs, {
3304+
dot: true,
3305+
cwd: watchOptions.cwd,
3306+
});
3307+
ignoredArr.push(ignoreMatcher);
33173308
}
3309+
3310+
ignoredArr.push(ignoreFunc);
33183311
}
33193312
}
33203313

0 commit comments

Comments
 (0)