From f409b02452cf3dacceccda145a547fa0c6173647 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 6 Oct 2022 14:24:31 -0700 Subject: [PATCH] Fix remaining tests --- lib/eslint/eslint-helpers.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/eslint/eslint-helpers.js b/lib/eslint/eslint-helpers.js index b288a780819..4f8e1578de9 100644 --- a/lib/eslint/eslint-helpers.js +++ b/lib/eslint/eslint-helpers.js @@ -17,6 +17,7 @@ const hash = require("../cli-engine/hash"); const minimatch = require("minimatch"); const util = require("util"); const fswalk = require("@nodelib/fs.walk"); +const { Minimatch } = require("minimatch"); //----------------------------------------------------------------------------- // Fix fswalk @@ -124,7 +125,13 @@ async function globSearch({ cwd, patterns, configs }) { return []; } - const matchers = patterns.map(pattern => new minimatch.Minimatch(pattern)); + const matchers = patterns.map(pattern => { + const patternToUse = path.isAbsolute(pattern) + ? normalizeToPosix(path.relative(cwd, pattern)) + : pattern; + + return new minimatch.Minimatch(patternToUse); + }); return (await doFsWalk(cwd, { @@ -161,11 +168,18 @@ async function globSearch({ cwd, patterns, configs }) { function globMatch({ cwd, pattern }) { let found = false; + const patternToUse = path.isAbsolute(pattern) + ? normalizeToPosix(path.relative(cwd, pattern)) + : pattern; + + const matcher = new Minimatch(patternToUse); const fsWalkSettings = { - deepFilter() { - return !found; + deepFilter(entry) { + const relativePath = normalizeToPosix(path.relative(cwd, entry.path)); + + return !found && matcher.match(relativePath, true); }, entryFilter(entry) { @@ -175,7 +189,7 @@ function globMatch({ cwd, pattern }) { const relativePath = normalizeToPosix(path.relative(cwd, entry.path)); - if (minimatch(relativePath, pattern)) { + if (matcher.match(relativePath)) { found = true; return true; } @@ -233,7 +247,6 @@ async function findFiles({ // check to see if we have explicit files and directories const filePaths = patterns.map(filePath => path.resolve(cwd, filePath)); - const relativePatterns = filePaths.map(filePath => path.relative(cwd, filePath)); const stats = await Promise.all( filePaths.map( filePath => fsp.stat(filePath).catch(() => { }) @@ -243,7 +256,7 @@ async function findFiles({ stats.forEach((stat, index) => { const filePath = filePaths[index]; - const pattern = normalizeToPosix(relativePatterns[index]); + const pattern = normalizeToPosix(patterns[index]); if (stat) {