-
-
Notifications
You must be signed in to change notification settings - Fork 32k
fs: expose glob and globSync #51912
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1069,6 +1069,38 @@ including subdirectories and files. | |
When copying a directory to another directory, globs are not supported and | ||
behavior is similar to `cp dir1/ dir2/`. | ||
|
||
### `fsPromises.glob(pattern[, options])` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental | ||
|
||
* `pattern` {string|string\[]} | ||
* `options` {Object} | ||
* `cwd` {string} current working directory. **Default:** `process.cwd()` | ||
* `exclude` {Function} Function to filter out files/directories. Return | ||
`true` to exclude the item, `false` to include it. **Default:** `undefined`. | ||
* Returns: {AsyncIterator} An AsyncIterator that yields the paths of files | ||
that match the pattern. | ||
|
||
```mjs | ||
import { glob } from 'node:fs/promises'; | ||
|
||
for await (const entry of glob('**/*.js')) | ||
console.log(entry); | ||
``` | ||
|
||
```cjs | ||
const { glob } = require('node:fs/promises'); | ||
|
||
(async () => { | ||
for await (const entry of glob('**/*.js')) | ||
console.log(entry); | ||
})(); | ||
``` | ||
|
||
### `fsPromises.lchmod(path, mode)` | ||
|
||
<!-- YAML | ||
|
@@ -3073,6 +3105,44 @@ changes: | |
Change the file system timestamps of the object referenced by the supplied file | ||
descriptor. See [`fs.utimes()`][]. | ||
|
||
### `fs.glob(pattern[, options], callback)` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental | ||
|
||
* `pattern` {string|string\[]} | ||
|
||
* `options` {Object} | ||
* `cwd` {string} current working directory. **Default:** `process.cwd()` | ||
* `exclude` {Function} Function to filter out files/directories. Return | ||
`true` to exclude the item, `false` to include it. **Default:** `undefined`. | ||
|
||
* `callback` {Function} | ||
* `err` {Error} | ||
|
||
* Retrieves the files matching the specified pattern. | ||
|
||
```mjs | ||
import { glob } from 'node:fs'; | ||
|
||
glob('**/*.js', (err, matches) => { | ||
if (err) throw err; | ||
console.log(matches); | ||
}); | ||
``` | ||
|
||
```cjs | ||
const { glob } = require('node:fs'); | ||
|
||
glob('**/*.js', (err, matches) => { | ||
if (err) throw err; | ||
console.log(matches); | ||
}); | ||
``` | ||
|
||
### `fs.lchmod(path, mode, callback)` | ||
|
||
<!-- YAML | ||
|
@@ -5529,6 +5599,33 @@ changes: | |
|
||
Synchronous version of [`fs.futimes()`][]. Returns `undefined`. | ||
|
||
### `fs.globSync(pattern[, options])` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental | ||
|
||
* `pattern` {string|string\[]} | ||
* `options` {Object} | ||
* `cwd` {string} current working directory. **Default:** `process.cwd()` | ||
* `exclude` {Function} Function to filter out files/directories. Return | ||
`true` to exclude the item, `false` to include it. **Default:** `undefined`. | ||
* Returns: {string\[]} paths of files that match the pattern. | ||
|
||
```mjs | ||
import { globSync } from 'node:fs'; | ||
|
||
console.log(globSync('**/*.js')); | ||
``` | ||
|
||
```cjs | ||
const { globSync } = require('node:fs'); | ||
|
||
console.log(globSync('**/*.js')); | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
### `fs.lchmodSync(path, mode)` | ||
|
||
<!-- YAML | ||
|
Uh oh!
There was an error while loading. Please reload this page.