Skip to content

Commit f0d0ec6

Browse files
committed
fs: correctly pass direct to exclude withFileTypes
1 parent 24648b5 commit f0d0ec6

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/internal/fs/glob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class Glob {
543543
const fromSymlink = pattern.symlinks.has(index);
544544

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

test/parallel/test-fs-glob.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ 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, { cwd: fixtureDir, withFileTypes: true, exclude: (dirent) => assert.ok(dirent instanceof Dirent) });
346346
assertDirents(actual);
347347
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
348348
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());
@@ -353,7 +353,7 @@ describe('glob - withFileTypes', function() {
353353
describe('globSync - withFileTypes', function() {
354354
for (const [pattern, expected] of Object.entries(patterns)) {
355355
test(pattern, () => {
356-
const actual = globSync(pattern, { cwd: fixtureDir, withFileTypes: true });
356+
const actual = globSync(pattern, { cwd: fixtureDir, withFileTypes: true, exclude: (dirent) => assert.ok(dirent instanceof Dirent) });
357357
assertDirents(actual);
358358
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
359359
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());
@@ -365,7 +365,7 @@ describe('fsPromises glob - withFileTypes', function() {
365365
for (const [pattern, expected] of Object.entries(patterns)) {
366366
test(pattern, async () => {
367367
const actual = [];
368-
for await (const item of asyncGlob(pattern, { cwd: fixtureDir, withFileTypes: true })) actual.push(item);
368+
for await (const item of asyncGlob(pattern, { cwd: fixtureDir, withFileTypes: true, exclude: (dirent) => assert.ok(dirent instanceof Dirent) })) actual.push(item);
369369
assertDirents(actual);
370370
const normalized = expected.filter(Boolean).map((item) => basename(item)).sort();
371371
assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort());

0 commit comments

Comments
 (0)