From 91579a9eb729aab67841288cc127c810e5f17219 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:00:09 -0400 Subject: [PATCH 1/3] fs: correctly pass dirent to exclude `withFileTypes` --- lib/internal/fs/glob.js | 2 +- test/parallel/test-fs-glob.mjs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index 3c225900301309..ed8dce2a1416e4 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -543,7 +543,7 @@ class Glob { const fromSymlink = pattern.symlinks.has(index); if (current === lazyMinimatch().GLOBSTAR) { - if (entry.name[0] === '.' || (this.#exclude && this.#exclude(entry.name))) { + if (entry.name[0] === '.' || (this.#exclude && this.#exclude(this.#withFileTypes ? entry : entry.name))) { continue; } if (!fromSymlink && entry.isDirectory()) { diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 7dcb8ecc8373a3..d861b0991a18f9 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -342,7 +342,11 @@ describe('glob - withFileTypes', function() { const promisified = promisify(glob); for (const [pattern, expected] of Object.entries(patterns)) { test(pattern, async () => { - const actual = await promisified(pattern, { cwd: fixtureDir, withFileTypes: true }); + const actual = await promisified(pattern, { + cwd: fixtureDir, + withFileTypes: true, + exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + }); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); @@ -353,7 +357,11 @@ describe('glob - withFileTypes', function() { describe('globSync - withFileTypes', function() { for (const [pattern, expected] of Object.entries(patterns)) { test(pattern, () => { - const actual = globSync(pattern, { cwd: fixtureDir, withFileTypes: true }); + const actual = globSync(pattern, { + cwd: fixtureDir, + withFileTypes: true, + exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + }); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); @@ -365,7 +373,11 @@ describe('fsPromises glob - withFileTypes', function() { for (const [pattern, expected] of Object.entries(patterns)) { test(pattern, async () => { const actual = []; - for await (const item of asyncGlob(pattern, { cwd: fixtureDir, withFileTypes: true })) actual.push(item); + for await (const item of asyncGlob(pattern, { + cwd: fixtureDir, + withFileTypes: true, + exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + })) actual.push(item); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); From 59e8fceccb6ca0b3e28d209403eb94f276cc1dcf Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:04:02 -0400 Subject: [PATCH 2/3] Update test-fs-glob.mjs --- test/parallel/test-fs-glob.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index d861b0991a18f9..7a32adc0e7d729 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -360,7 +360,7 @@ describe('globSync - withFileTypes', function() { const actual = globSync(pattern, { cwd: fixtureDir, withFileTypes: true, - exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); @@ -376,7 +376,7 @@ describe('fsPromises glob - withFileTypes', function() { for await (const item of asyncGlob(pattern, { cwd: fixtureDir, withFileTypes: true, - exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + exclude: (dirent) => assert.ok(dirent instanceof Dirent), })) actual.push(item); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); From 0657e79efe84fba5b13e3eb2ce09d7c834b6dd6f Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:37:34 -0400 Subject: [PATCH 3/3] Update test-fs-glob.mjs --- test/parallel/test-fs-glob.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 7a32adc0e7d729..4038c0e165eb69 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -345,7 +345,7 @@ describe('glob - withFileTypes', function() { const actual = await promisified(pattern, { cwd: fixtureDir, withFileTypes: true, - exclude: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)), + exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();