Skip to content

Commit

Permalink
fs: correctly pass dirent to exclude withFileTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Jul 12, 2024
1 parent 24648b5 commit 91579a9
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 @@ -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()) {
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: common.mustCall((dirent) => assert.ok(dirent instanceof Dirent)),

Check failure on line 348 in test/parallel/test-fs-glob.mjs

View workflow job for this annotation

GitHub Actions / test-asan

--- stderr --- (node:143834) ExperimentalWarning: glob is an experimental feature and might change at any time (Use `node --trace-warnings ...` to show where the warning was created) (node:143834) ExperimentalWarning: globSync is an experimental feature and might change at any time --- stdout --- β–Ά glob βœ” a/c/d/*/b (37.295822ms) ::debug::starting to run glob ::debug::starting to run a/c/d/*/b ::debug::completed running a/c/d/*/b βœ” a//c//d//*//b (4.173805ms) ::debug::starting to run a//c//d//*//b ::debug::completed running a//c//d//*//b βœ” a/*/d/*/b (7.961235ms) ::debug::starting to run a/*/d/*/b ::debug::completed running a/*/d/*/b βœ” a/*/+(c|g)/./d (6.571866ms) ::debug::starting to run a/*/+(c|g)/./d ::debug::completed running a/*/+(c|g)/./d βœ” a/**/[cg]/../[cg] (6.019259ms) ::debug::starting to run a/**/[cg]/../[cg] ::debug::completed running a/**/[cg]/../[cg] βœ” a/{b,c,d,e,f}/**/g (5.656719ms) ::debug::starting to run a/{b,c,d,e,f}/**/g ::debug::completed running a/{b,c,d,e,f}/**/g βœ” a/b/** (1.20919ms) ::debug::starting to run a/b/** ::debug::completed running a/b/** βœ” a/{b/**,b/c} (3.864891ms) ::debug::starting to run a/{b/**,b/c} ::debug::completed running a/{b/**,b/c} βœ” ./**/g (9.941723ms) ::debug::starting to run ./**/g ::debug::completed running ./**/g βœ” a/abc{fed,def}/g/h (3.288353ms) ::debug::starting to run a/abc{fed,def}/g/h ::debug::completed running a/abc{fed,def}/g/h βœ” a/abc{fed/g,def}/**/ (2.249764ms) ::debug::starting to run a/abc{fed/g,def}/**/ ::debug::completed running a/abc{fed/g,def}/**/ βœ” a/abc{fed/g,def}/**///**/ (2.500454ms) ::debug::starting to run a/abc{fed/g,def}/**///**/ ::debug::completed running a/abc{fed/g,def}/**///**/ βœ” **/a (4.95912ms) ::debug::starting to run **/a ::debug::completed running **/a βœ” **/a/** (12.344894ms) ::debug::starting to run **/a/** ::debug::completed running **/a/** βœ” ./**/a (30.473335ms) ::debug::starting to run ./**/a ::debug::completed running ./**/a βœ” ./**/a/**/ (6.406977ms) ::debug::starting to run ./**/a/**/ ::debug::completed running ./**/a/**/ βœ” ./**/a/** (15.654818ms) ::debug::starting to run ./**/a/** ::debug::completed running ./**/a/** βœ” ./**/a/**/a/**/ (26.007291ms) ::debug::starting to run ./**/a/**/a/**/ ::debug::completed running ./**/a/**/a/**/ βœ” +(a|b|c)/a{/,bc*}/** (10.596952ms) ::debug::starting to run +(a|b|c)/a{/,bc*}/** ::debug::completed running +(a|b|c)/a{/,bc*}/** βœ” */*/*/f (5.329855ms) ::debug::starting to run */*/*/f ::debug::completed running */*/*/f βœ” ./**/f (12.113249ms) ::debug::starting to run ./**/f ::debug::completed running ./**/f βœ” a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** (5.512948ms) ::debug::starting to run a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** ::debug::completed running a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** βœ” {./*/*,/home/runner/work/node/node/test/.tmp.1039/abs/*} (3.736283ms) ::debug::starting to run {./*/*,/home/runner/work/node/node/test/.tmp.1039/abs/*} ::debug::completed running {./*/*,/home/runner/work/node/node/test/.tmp.1039/abs/*} βœ” {/home/runner/work/node/node/test/.tmp.1039/abs/*,*} (11.69832ms) ::debug::starting to run {/home/runner/work/node/node/test/.tmp.1039/abs/*,*} ::debug::completed running {/home/runner/work/node/node/test/.tmp.1039/abs/*,*} βœ” a/!(symlink)/** (4.381795ms) ::debug::starting to run a/!(symlink)/** ::debug::completed running a/!(symlink)/** βœ” a/symlink/a/**/* (2.056269ms) ::debug::starting to run a/symlink/a/**/* ::debug::completed running a/symlink/a/**/* βœ” a/!(symlink)/**/.. (15.361446ms) ::debug::starting to run a/!(symlink)/**/.. ::debug::completed running a/!(symlink)/**/.. βœ” a/!(symlink)/**/../ (10.641642ms) ::debug::starting to run a/!(symlink)/**/../ ::debug::completed running a/!(symlink)/**/../ βœ” a/!(symlink)/**/../* (27.301826ms) ::debug::starting to run a/!(symlink)/**/../* ::debug::completed running a/!(symlink)/**/../* βœ” a/!(symlink)/**/../*/* (4.983886ms) β–Ά glob (312.306368ms) ::debug::starting to run a/!(symlink)/**/../*/* ::debug::completed running a/!(symlink)/**/../*/* ::deb

Check failure on line 348 in test/parallel/test-fs-glob.mjs

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- (node:63593) ExperimentalWarning: glob is an experimental feature and might change at any time (Use `node --trace-warnings ...` to show where the warning was created) (node:63593) ExperimentalWarning: globSync is an experimental feature and might change at any time --- stdout --- β–Ά glob βœ” a/c/d/*/b (6.703083ms) ::debug::starting to run glob ::debug::starting to run a/c/d/*/b ::debug::completed running a/c/d/*/b βœ” a//c//d//*//b (1.117416ms) ::debug::starting to run a//c//d//*//b ::debug::completed running a//c//d//*//b βœ” a/*/d/*/b (1.300458ms) ::debug::starting to run a/*/d/*/b ::debug::completed running a/*/d/*/b βœ” a/*/+(c|g)/./d (2.604916ms) ::debug::starting to run a/*/+(c|g)/./d ::debug::completed running a/*/+(c|g)/./d βœ” a/**/[cg]/../[cg] (1.571458ms) ::debug::starting to run a/**/[cg]/../[cg] ::debug::completed running a/**/[cg]/../[cg] βœ” a/{b,c,d,e,f}/**/g (1.124208ms) ::debug::starting to run a/{b,c,d,e,f}/**/g ::debug::completed running a/{b,c,d,e,f}/**/g βœ” a/b/** (0.365167ms) ::debug::starting to run a/b/** ::debug::completed running a/b/** βœ” a/{b/**,b/c} (0.789792ms) ::debug::starting to run a/{b/**,b/c} ::debug::completed running a/{b/**,b/c} βœ” ./**/g (2.162791ms) ::debug::starting to run ./**/g ::debug::completed running ./**/g βœ” a/abc{fed,def}/g/h (0.749167ms) ::debug::starting to run a/abc{fed,def}/g/h ::debug::completed running a/abc{fed,def}/g/h βœ” a/abc{fed/g,def}/**/ (0.496334ms) ::debug::starting to run a/abc{fed/g,def}/**/ ::debug::completed running a/abc{fed/g,def}/**/ βœ” a/abc{fed/g,def}/**///**/ (0.598959ms) ::debug::starting to run a/abc{fed/g,def}/**///**/ ::debug::completed running a/abc{fed/g,def}/**///**/ βœ” **/a (1.309375ms) ::debug::starting to run **/a ::debug::completed running **/a βœ” **/a/** (1.336875ms) ::debug::starting to run **/a/** ::debug::completed running **/a/** βœ” ./**/a (3.171083ms) ::debug::starting to run ./**/a ::debug::completed running ./**/a βœ” ./**/a/**/ (5.317291ms) ::debug::starting to run ./**/a/**/ ::debug::completed running ./**/a/**/ βœ” ./**/a/** (3.171917ms) ::debug::starting to run ./**/a/** ::debug::completed running ./**/a/** βœ” ./**/a/**/a/**/ (2.174166ms) ::debug::starting to run ./**/a/**/a/**/ ::debug::completed running ./**/a/**/a/**/ βœ” +(a|b|c)/a{/,bc*}/** (0.96975ms) ::debug::starting to run +(a|b|c)/a{/,bc*}/** ::debug::completed running +(a|b|c)/a{/,bc*}/** βœ” */*/*/f (1.041ms) ::debug::starting to run */*/*/f ::debug::completed running */*/*/f βœ” ./**/f (1.794292ms) ::debug::starting to run ./**/f ::debug::completed running ./**/f βœ” a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** (1.304958ms) ::debug::starting to run a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** ::debug::completed running a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** βœ” {./*/*,/Users/runner/work/node/node/test/.tmp.850/abs/*} (0.859041ms) ::debug::starting to run {./*/*,/Users/runner/work/node/node/test/.tmp.850/abs/*} ::debug::completed running {./*/*,/Users/runner/work/node/node/test/.tmp.850/abs/*} βœ” {/Users/runner/work/node/node/test/.tmp.850/abs/*,*} (0.546041ms) ::debug::starting to run {/Users/runner/work/node/node/test/.tmp.850/abs/*,*} ::debug::completed running {/Users/runner/work/node/node/test/.tmp.850/abs/*,*} βœ” a/!(symlink)/** (2.140583ms) ::debug::starting to run a/!(symlink)/** ::debug::completed running a/!(symlink)/** βœ” a/symlink/a/**/* (0.462208ms) ::debug::starting to run a/symlink/a/**/* ::debug::completed running a/symlink/a/**/* βœ” a/!(symlink)/**/.. (2.396541ms) ::debug::starting to run a/!(symlink)/**/.. ::debug::completed running a/!(symlink)/**/.. βœ” a/!(symlink)/**/../ (1.612292ms) ::debug::starting to run a/!(symlink)/**/../ ::debug::completed running a/!(symlink)/**/../ βœ” a/!(symlink)/**/../* (2.455333ms) ::debug::starting to run a/!(symlink)/**/../* ::debug::completed running a/!(symlink)/**/../* βœ” a/!(symlink)/**/../*/* (1.569459ms) β–Ά glob (55.660542ms) ::debug::starting to run a/!(symlink)/**/../*/* ::debug::completed running a/!(symlink)/**/../*/* ::debug::completed r

Check failure on line 348 in test/parallel/test-fs-glob.mjs

View workflow job for this annotation

GitHub Actions / test-linux

--- stderr --- (node:147183) ExperimentalWarning: glob is an experimental feature and might change at any time (Use `node --trace-warnings ...` to show where the warning was created) (node:147183) ExperimentalWarning: globSync is an experimental feature and might change at any time --- stdout --- β–Ά glob βœ” a/c/d/*/b (11.888892ms) ::debug::starting to run glob ::debug::starting to run a/c/d/*/b ::debug::completed running a/c/d/*/b βœ” a//c//d//*//b (1.775626ms) ::debug::starting to run a//c//d//*//b ::debug::completed running a//c//d//*//b βœ” a/*/d/*/b (2.808532ms) ::debug::starting to run a/*/d/*/b ::debug::completed running a/*/d/*/b βœ” a/*/+(c|g)/./d (5.061797ms) ::debug::starting to run a/*/+(c|g)/./d ::debug::completed running a/*/+(c|g)/./d βœ” a/**/[cg]/../[cg] (3.615232ms) ::debug::starting to run a/**/[cg]/../[cg] ::debug::completed running a/**/[cg]/../[cg] βœ” a/{b,c,d,e,f}/**/g (2.773345ms) ::debug::starting to run a/{b,c,d,e,f}/**/g ::debug::completed running a/{b,c,d,e,f}/**/g βœ” a/b/** (0.923931ms) ::debug::starting to run a/b/** ::debug::completed running a/b/** βœ” a/{b/**,b/c} (1.348917ms) ::debug::starting to run a/{b/**,b/c} ::debug::completed running a/{b/**,b/c} βœ” ./**/g (5.890324ms) ::debug::starting to run ./**/g ::debug::completed running ./**/g βœ” a/abc{fed,def}/g/h (2.139358ms) ::debug::starting to run a/abc{fed,def}/g/h ::debug::completed running a/abc{fed,def}/g/h βœ” a/abc{fed/g,def}/**/ (1.646434ms) ::debug::starting to run a/abc{fed/g,def}/**/ ::debug::completed running a/abc{fed/g,def}/**/ βœ” a/abc{fed/g,def}/**///**/ (1.786907ms) ::debug::starting to run a/abc{fed/g,def}/**///**/ ::debug::completed running a/abc{fed/g,def}/**///**/ βœ” **/a (3.609902ms) ::debug::starting to run **/a ::debug::completed running **/a βœ” **/a/** (3.845664ms) ::debug::starting to run **/a/** ::debug::completed running **/a/** βœ” ./**/a (11.514239ms) ::debug::starting to run ./**/a ::debug::completed running ./**/a βœ” ./**/a/**/ (5.022774ms) ::debug::starting to run ./**/a/**/ ::debug::completed running ./**/a/**/ βœ” ./**/a/** (2.80364ms) ::debug::starting to run ./**/a/** ::debug::completed running ./**/a/** βœ” ./**/a/**/a/**/ (3.211336ms) ::debug::starting to run ./**/a/**/a/**/ ::debug::completed running ./**/a/**/a/**/ βœ” +(a|b|c)/a{/,bc*}/** (1.632298ms) ::debug::starting to run +(a|b|c)/a{/,bc*}/** ::debug::completed running +(a|b|c)/a{/,bc*}/** βœ” */*/*/f (2.377764ms) ::debug::starting to run */*/*/f ::debug::completed running */*/*/f βœ” ./**/f (3.927838ms) ::debug::starting to run ./**/f ::debug::completed running ./**/f βœ” a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** (2.426386ms) ::debug::starting to run a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** ::debug::completed running a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/** βœ” {./*/*,/home/runner/work/node/node/test/.tmp.1175/abs/*} (1.577515ms) ::debug::starting to run {./*/*,/home/runner/work/node/node/test/.tmp.1175/abs/*} ::debug::completed running {./*/*,/home/runner/work/node/node/test/.tmp.1175/abs/*} βœ” {/home/runner/work/node/node/test/.tmp.1175/abs/*,*} (1.901134ms) ::debug::starting to run {/home/runner/work/node/node/test/.tmp.1175/abs/*,*} ::debug::completed running {/home/runner/work/node/node/test/.tmp.1175/abs/*,*} βœ” a/!(symlink)/** (3.450001ms) ::debug::starting to run a/!(symlink)/** ::debug::completed running a/!(symlink)/** βœ” a/symlink/a/**/* (0.987369ms) ::debug::starting to run a/symlink/a/**/* ::debug::completed running a/symlink/a/**/* βœ” a/!(symlink)/**/.. (3.937287ms) ::debug::starting to run a/!(symlink)/**/.. ::debug::completed running a/!(symlink)/**/.. βœ” a/!(symlink)/**/../ (2.423058ms) ::debug::starting to run a/!(symlink)/**/../ ::debug::completed running a/!(symlink)/**/../ βœ” a/!(symlink)/**/../* (5.92542ms) ::debug::starting to run a/!(symlink)/**/../* ::debug::completed running a/!(symlink)/**/../* βœ” a/!(symlink)/**/../*/* (2.905975ms) β–Ά glob (110.388009ms) ::debug::starting to run a/!(symlink)/**/../*/* ::debug::completed running a/!(symlink)/**/../*/* ::debug::comp
});
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: 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());
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: 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());
Expand Down

0 comments on commit 91579a9

Please sign in to comment.