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] 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());