Skip to content

Commit b377b93

Browse files
avivkellertargos
authored andcommitted
fs: correctly pass dirent to exclude withFileTypes
PR-URL: #53823 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent c53cf44 commit b377b93

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/internal/fs/glob.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class Glob {
542542
const fromSymlink = pattern.symlinks.has(index);
543543

544544
if (current === lazyMinimatch().GLOBSTAR) {
545-
if (entry.name[0] === '.' || (this.#exclude && this.#exclude(entry.name))) {
545+
if (entry.name[0] === '.' || (this.#exclude && this.#exclude(this.#withFileTypes ? entry : entry.name))) {
546546
continue;
547547
}
548548
if (!fromSymlink && entry.isDirectory()) {

test/parallel/test-fs-glob.mjs

+15-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ describe('glob - withFileTypes', function() {
342342
const promisified = promisify(glob);
343343
for (const [pattern, expected] of Object.entries(patterns)) {
344344
test(pattern, async () => {
345-
const actual = await promisified(pattern, { cwd: fixtureDir, withFileTypes: true });
345+
const actual = await promisified(pattern, {
346+
cwd: fixtureDir,
347+
withFileTypes: true,
348+
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
349+
});
346350
assertDirents(actual);
347351
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
348352
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());
@@ -353,7 +357,11 @@ describe('glob - withFileTypes', function() {
353357
describe('globSync - withFileTypes', function() {
354358
for (const [pattern, expected] of Object.entries(patterns)) {
355359
test(pattern, () => {
356-
const actual = globSync(pattern, { cwd: fixtureDir, withFileTypes: true });
360+
const actual = globSync(pattern, {
361+
cwd: fixtureDir,
362+
withFileTypes: true,
363+
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
364+
});
357365
assertDirents(actual);
358366
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
359367
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());
@@ -365,7 +373,11 @@ describe('fsPromises glob - withFileTypes', function() {
365373
for (const [pattern, expected] of Object.entries(patterns)) {
366374
test(pattern, async () => {
367375
const actual = [];
368-
for await (const item of asyncGlob(pattern, { cwd: fixtureDir, withFileTypes: true })) actual.push(item);
376+
for await (const item of asyncGlob(pattern, {
377+
cwd: fixtureDir,
378+
withFileTypes: true,
379+
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
380+
})) actual.push(item);
369381
assertDirents(actual);
370382
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
371383
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());

0 commit comments

Comments
 (0)