Skip to content

Commit

Permalink
fix: simply logic of ignored files
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzyma committed Dec 13, 2024
1 parent 184588d commit 970c353
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3277,44 +3277,37 @@ class Server {
cwd: watchOptions.cwd,
dot: true,
});

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

if (ignoredGlobs.length > 0) {
const ignoreMatcher = picomatch(ignoredGlobs, {
dot: true,
cwd: watchOptions.cwd,
});
watchOptions.ignored.push(ignoreMatcher);
}
// Nested ternaries are forbidden by eslint so we end up with this
if (watchOptions.ignored && !Array.isArray(watchOptions.ignored)) {
ignoredArr.push(watchOptions.ignored);
}

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,
});
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);
}
}

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

ignoredArr.push(ignoreFunc);
}
}

Expand Down

0 comments on commit 970c353

Please # to comment.