Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions benchmark/fs/bench-glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ const configs = {
dir: ['lib'],
pattern: ['**/*', '*.js', '**/**.js'],
mode: ['sync', 'promise', 'callback'],
maxDepth: ['default', '2'],
recursive: ['true', 'false'],
};

const bench = common.createBenchmark(main, configs);

async function main(config) {
const fullPath = path.resolve(benchmarkDirectory, config.dir);
const { pattern, recursive, mode } = config;
const { pattern, recursive, mode, maxDepth } = config;
const options = { cwd: fullPath, recursive };
if (maxDepth !== 'default') {
options.maxDepth = Number(maxDepth);
}
const callback = (resolve, reject) => {
glob(pattern, options, (err, matches) => {
if (err) {
Expand All @@ -44,7 +48,10 @@ async function main(config) {
noDead = globSync(pattern, options);
break;
case 'promise':
noDead = await globAsync(pattern, options);
noDead = [];
for await (const match of globAsync(pattern, options)) {
noDead.push(match);
}
break;
case 'callback':
noDead = await new Promise(callback);
Expand Down
6 changes: 6 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,8 @@ changes:
not supported.
* `followSymlinks` {boolean} When `true`, symbolic links to directories are
followed while expanding `**` patterns. **Default:** `false`.
* `maxDepth` {integer} Maximum number of directory levels to traverse.
The `cwd` directory has a depth of `0`. **Default:** `Infinity`.
* `withFileTypes` {boolean} `true` if the glob should return paths as Dirents,
`false` otherwise. **Default:** `false`.
* Returns: {AsyncIterator} An AsyncIterator that yields the paths of files
Expand Down Expand Up @@ -3590,6 +3592,8 @@ changes:
`true` to exclude the item, `false` to include it. **Default:** `undefined`.
* `followSymlinks` {boolean} When `true`, symbolic links to directories are
followed while expanding `**` patterns. **Default:** `false`.
* `maxDepth` {integer} Maximum number of directory levels to traverse.
The `cwd` directory has a depth of `0`. **Default:** `Infinity`.
* `withFileTypes` {boolean} `true` if the glob should return paths as Dirents,
`false` otherwise. **Default:** `false`.

Expand Down Expand Up @@ -6220,6 +6224,8 @@ changes:
`true` to exclude the item, `false` to include it. **Default:** `undefined`.
* `followSymlinks` {boolean} When `true`, symbolic links to directories are
followed while expanding `**` patterns. **Default:** `false`.
* `maxDepth` {integer} Maximum number of directory levels to traverse.
The `cwd` directory has a depth of `0`. **Default:** `Infinity`.
* `withFileTypes` {boolean} `true` if the glob should return paths as Dirents,
`false` otherwise. **Default:** `false`.
* Returns: {string\[]} paths of files that match the pattern.
Expand Down
Loading
Loading