-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: expose glob and globSync #51912
fs: expose glob and globSync #51912
Conversation
this capability was originally added to core for the use of the test runner, and we did not expose it since some dependencies don't use primordials. |
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
@@ -376,6 +412,194 @@ class Glob { | |||
} | |||
} | |||
} | |||
|
|||
|
|||
async* glob() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is pretty much the same implementation as globSync
except using yield
instead if this.#results.push
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementations can be unified probably if you yield
where you await and then do sync/async I/O depending on the path not sure if it's worth it
CC @nodejs/fs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm for experimental
/cc @nodejs/fs |
cc @nodejs/primordials |
const { globSync } = require('node:fs'); | ||
|
||
console.log(globSync('**/*.js')); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have more details here about what glob patterns are supported, like there is in https://github.com/isaacs/node-glob?tab=readme-ov-file#glob-primer
Since glob implementations can vary and it may not be obvious if a certain pattern is supported (that is not just **
and *
)
Sorry to repeat myself, but I'm interested in finding the unit tests for this, can someone point me in the right direction? If there are no unit tests, that brings another set of questions. |
@jonschlinkert Looks like the tests are in node/test/parallel/test-fs-glob.mjs Line 6 in b876e00
|
thanks @styfle, don't know how I missed those. |
I see that his is actually depending on minimatch, I would have preferred to see picomatch or micromatch given that minimatch is subject to catastrophic backtracking, and both picomatch and micromatch are more performant, support more patterns, and are better tested. Picomatch also has a tokenizer that can be used. Is there a reason minimatch is being used or can we do a PR to swap in micromatch? Here are the benchmarks. I know this isn't the issue for this, I'd be happy to open a new one. |
@jonschlinkert It might be worth creating a new issue since this one is closed |
@jonschlinkert @styfle See: #53547. |
Refs: #51912 PR-URL: #54644 Reviewed-By: Daeyeon Jeong <[email protected]>
Refs: nodejs#51912 PR-URL: nodejs#54644 Reviewed-By: Daeyeon Jeong <[email protected]>
Refs: nodejs#51912 PR-URL: nodejs#54644 Reviewed-By: Daeyeon Jeong <[email protected]>
Fixes #40731
This PR introduces
fs.glob
andfsPromises.glob
.