Skip to content

Commit fffc479

Browse files
authored
update(docs): mention fs.glob in fast-glob replacements (#947)
1 parent 99a14cf commit fffc479

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎docs/modules/fast-glob.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,34 @@ const files = await glob('**/*.ts', { // [!code ++]
2525
```
2626
2727
Most options from `fast-glob` have direct equivalents in `tinyglobby`. Check the [tinyglobby documentation](https://superchupu.dev/tinyglobby/migration) for the complete list of supported options.
28+
29+
## `fs.glob` (native, since Node 22.x)
30+
31+
[`fs.glob`](https://nodejs.org/api/fs.html#fspromisesglobpattern-options) is built into modern versions of Node.
32+
33+
Example:
34+
35+
<!-- eslint-skip -->
36+
37+
```ts
38+
import fg from 'fast-glob' // [!code --]
39+
import { glob } from 'node:fs/promises' // [!code ++]
40+
41+
const files = await fg('src/**/*.ts', { // [!code --]
42+
const files = await Array.fromAsync(glob('src/**/*.ts', { // [!code ++]
43+
cwd,
44+
}) // [!code --]
45+
})) // [!code ++]
46+
```
47+
48+
You can also iterate over the results asynchronously:
49+
50+
```ts
51+
for await (const result of glob('src/**/*.ts', { cwd })) {
52+
// result is an individual path
53+
console.log(result)
54+
}
55+
```
56+
57+
> [!NOTE]
58+
> Node's built-in `glob` is more minimal and does not support negation patterns or fine-grained options like setting a max depth out of the box.

0 commit comments

Comments
 (0)