Skip to content

Commit

Permalink
fs: correctly pass dirent to exclude withFileTypes
Browse files Browse the repository at this point in the history
PR-URL: #53823
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
  • Loading branch information
RedYetiDev authored and targos committed Jul 28, 2024
1 parent c53cf44 commit b377b93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,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()) {
Expand Down
18 changes: 15 additions & 3 deletions test/parallel/test-fs-glob.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: (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());
Expand All @@ -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: (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());
Expand All @@ -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: (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());
Expand Down

0 comments on commit b377b93

Please sign in to comment.