Skip to content
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

Merged
merged 3 commits into from
Mar 3, 2024
Merged

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Feb 28, 2024

Fixes #40731
This PR introduces fs.globand fsPromises.glob.

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Feb 28, 2024
@MoLow
Copy link
Member Author

MoLow commented Feb 28, 2024

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.
there have been recent discussions regarding the primordials and whether or not they are a must for 100% of core code.
My personal opinion is primordials should be used to prevent catastrophic failures and such an addition to core has more benefits than drawbacks.
this will also not be precedential - we have some dependencies that don't use primordials, such as undici
we might want to add tsc-agenda Issues and PRs to discuss during the meetings of the TSC. to discuss this

@MoLow MoLow added semver-minor PRs that contain new features and should be released in the next minor version. notable-change PRs with changes that should be highlighted in changelogs. labels Feb 28, 2024
Copy link
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @MoLow.

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.

@MoLow MoLow linked an issue Feb 28, 2024 that may be closed by this pull request
@@ -376,6 +412,194 @@ class Glob {
}
}
}


async* glob() {
Copy link
Member Author

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

Copy link
Member

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

lib/internal/fs/glob.js Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
@MoLow
Copy link
Member Author

MoLow commented Feb 29, 2024

CC @nodejs/fs

doc/api/fs.md Outdated Show resolved Hide resolved
Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for experimental

lib/internal/fs/glob.js Outdated Show resolved Hide resolved
lib/internal/fs/glob.js Outdated Show resolved Hide resolved
lib/internal/fs/glob.js Outdated Show resolved Hide resolved
lib/internal/fs/glob.js Show resolved Hide resolved
lib/internal/fs/promises.js Outdated Show resolved Hide resolved
@aduh95
Copy link
Contributor

aduh95 commented Mar 2, 2024

/cc @nodejs/fs

@atlowChemi
Copy link
Member

cc @nodejs/primordials

@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 3, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 3, 2024
@nodejs-github-bot
Copy link
Collaborator

const { globSync } = require('node:fs');

console.log(globSync('**/*.js'));
```
Copy link
Contributor

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 *)

hail2u added a commit to hail2u/hail2u.net that referenced this pull request Apr 25, 2024
@marco-ippolito marco-ippolito added the backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. label May 1, 2024
@jonschlinkert
Copy link

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.

@styfle
Copy link
Member

styfle commented May 2, 2024

@jonschlinkert Looks like the tests are in test/parallel/test-fs-glob.mjs

import { test, describe } from 'node:test';

@jonschlinkert
Copy link

thanks @styfle, don't know how I missed those.

@jonschlinkert
Copy link

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.

@marco-ippolito marco-ippolito added baking-for-lts PRs that need to wait before landing in a LTS release. and removed backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. labels May 2, 2024
@styfle
Copy link
Member

styfle commented May 4, 2024

@jonschlinkert It might be worth creating a new issue since this one is closed

@marco-ippolito marco-ippolito added backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. and removed baking-for-lts PRs that need to wait before landing in a LTS release. labels Jun 17, 2024
danielbayley added a commit to danielbayley/node that referenced this pull request Jun 22, 2024
danielbayley added a commit to danielbayley/node that referenced this pull request Jun 22, 2024
@danielbayley
Copy link
Contributor

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.

danielbayley added a commit to danielbayley/node that referenced this pull request Jun 23, 2024
sonsurim added a commit to sonsurim/node that referenced this pull request Aug 29, 2024
sonsurim added a commit to sonsurim/node that referenced this pull request Aug 29, 2024
aduh95 pushed a commit that referenced this pull request Sep 27, 2024
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet