@@ -1090,7 +1090,7 @@ changes:
10901090 description: Add support for ` withFileTypes` as an option.
10911091-->
10921092
1093- * ` pattern` {string|string\[ ]}
1093+ * ` pattern` {string|string\[ ]} The glob pattern(s) to match against.
10941094* ` options` {Object}
10951095 * ` cwd` {string} current working directory. **Default:** ` process .cwd ()`
10961096 * ` exclude` {Function|string\[ ]} Function to filter out files/directories or a
@@ -1101,6 +1101,49 @@ changes:
11011101* Returns: {AsyncIterator} An AsyncIterator that yields the paths of files
11021102 that match the pattern.
11031103
1104+ Retrieves the file paths matching the specified pattern(s).
1105+
1106+ #### Pattern Syntax
1107+
1108+ The glob implementation supports the following pattern syntax:
1109+
1110+ **Basic Wildcards:**
1111+
1112+ | Pattern | Description |
1113+ | -------------------- | -------------------------------------------------------------- |
1114+ | ` * ` | Matches any number of characters within a single path segment. |
1115+ | ` ? ` | Matches exactly one character. |
1116+ | ` [abc]` | Matches any character in the brackets. |
1117+ | ` [a- z]` | Matches any character in the range. |
1118+ | ` [! abc]` or ` [^ abc]` | Matches any character not in the brackets. |
1119+ | ` [! a- z]` or ` [^ a- z]` | Matches any character not in the range. |
1120+
1121+ **Globstar:**
1122+
1123+ | Pattern | Description |
1124+ | --------- | --------------------------------------------- |
1125+ | ` ** ` | Matches zero or more directories recursively. |
1126+ | ` ** /* .js` | Matches all `.js` files in any subdirectory. |
1127+
1128+ **Brace Expansion:**
1129+
1130+ | Pattern | Description |
1131+ | ----------- | ------------------------------------------------ |
1132+ | `{a,b,c}` | Matches any of the comma-separated patterns. |
1133+ | `{1..5}` | Matches any number in the range (1, 2, 3, 4, 5). |
1134+ | `*.{js,ts}` | Matches files with `.js` or `.ts` extensions. |
1135+
1136+ **Extended Glob Patterns:**
1137+
1138+ | Pattern | Description |
1139+ | ------------ | ------------------------------------------------ |
1140+ | `+(pattern)` | Matches one or more occurrences of the pattern. |
1141+ | `*(pattern)` | Matches zero or more occurrences of the pattern. |
1142+ | `?(pattern)` | Matches zero or one occurrence of the pattern. |
1143+ | `!(pattern)` | Matches anything except the pattern. |
1144+
1145+ #### Examples
1146+
11041147```mjs
11051148import { glob } from 'node:fs/promises';
11061149
@@ -1117,6 +1160,39 @@ const { glob } = require('node:fs/promises');
11171160})();
11181161```
11191162
1163+ To collect all results into an array, use `Array.fromAsync`:
1164+
1165+ ```mjs
1166+ const files = await Array.fromAsync(glob('src/**/ * .js ' ));
1167+ ```
1168+
1169+ **Common patterns:**
1170+
1171+ | Pattern | Description |
1172+ | --------------------------------------------------- | ------------------------------------------------ |
1173+ | `glob(' * .js ' )` | All `.js` files in the current directory. |
1174+ | `glob(' ** /* .{js,ts}')` | All `.js` and `.ts` files recursively. |
1175+ | `glob('src/{components,utils}/**/ * .js ' )` | `.js` files in `src/components` or `src/utils`. |
1176+ | `glob(' test/* */ * .{spec,test}.js ' )` | Test files ending with `.spec.js` or `.test.js`. |
1177+ | `glob(' ** /* .js', { exclude: ['node_modules/**'] })` | All `.js` files except those in `node_modules`. |
1178+ | `glob(['src/**/ * .js ' , ' lib/* */ * .js ' ])` | `.js` files in both `src` and `lib` directories. |
1179+
1180+ #### Platform Considerations
1181+
1182+ * **Case sensitivity**: Glob patterns are case-insensitive on Windows and macOS,
1183+ case-sensitive on other platforms.
1184+ * **Path separators**: Forward slashes (`/`) are used in patterns regardless of
1185+ platform; they are automatically converted to the appropriate separator.
1186+ * **Returned paths**: Results use platform-specific path separators (`\` on Windows,
1187+ `/` on POSIX). Paths are relative to `options.cwd` if provided, otherwise
1188+ relative to the current working directory.
1189+ * **Symlinks**: Symbolic links are followed and their targets are included in results.
1190+ * **Hidden files**: Files starting with `.` are included in results when explicitly
1191+ matched, but not when using `*` or `**` patterns.
1192+
1193+ [`path.matchesGlob()`][] supports the same basic glob pattern syntax for
1194+ in-memory path matching, but does not include the `exclude` option.
1195+
11201196### `fsPromises.lchmod(path, mode)`
11211197
11221198<!-- YAML
@@ -3149,20 +3225,25 @@ changes:
31493225 description: Add support for ` withFileTypes` as an option.
31503226-->
31513227
3152- * `pattern` {string|string\[ ]}
3153-
3228+ * ` pattern` {string|string\[ ]} The glob pattern(s) to match against.
31543229* ` options` {Object}
31553230 * ` cwd` {string} current working directory. **Default:** ` process .cwd ()`
31563231 * ` exclude` {Function|string\[ ]} Function to filter out files/directories or a
31573232 list of glob patterns to be excluded. If a function is provided, return
31583233 ` true ` to exclude the item, ` false ` to include it. **Default:** ` undefined ` .
31593234 * ` withFileTypes` {boolean} ` true ` if the glob should return paths as Dirents,
31603235 ` false ` otherwise. **Default:** ` false ` .
3161-
31623236* ` callback` {Function}
31633237 * ` err` {Error}
3238+ * ` matches` {string\[ ]|fs.Dirent\[ ]} An array of paths or Dirent objects that
3239+ match the pattern. String paths use platform-specific separators (` \` on
3240+ Windows, ` / ` on POSIX) and are relative to ` options .cwd ` if provided,
3241+ otherwise relative to the current working directory.
3242+
3243+ Retrieves the file paths matching the specified pattern(s).
31643244
3165- * Retrieves the files matching the specified pattern.
3245+ See ` fsPromises .glob ()` for detailed information about pattern syntax,
3246+ examples, and behavior.
31663247
31673248` ` ` mjs
31683249import { glob } from ' node:fs' ;
@@ -5702,15 +5783,23 @@ changes:
57025783 description: Add support for `withFileTypes` as an option.
57035784-->
57045785
5705- * ` pattern` {string|string\[ ]}
5786+ * `pattern` {string|string\[ ]} The glob pattern(s) to match against.
57065787* `options` {Object}
57075788 * `cwd` {string} current working directory. **Default:** `process.cwd()`
57085789 * `exclude` {Function|string\[ ]} Function to filter out files/directories or a
57095790 list of glob patterns to be excluded. If a function is provided, return
57105791 `true` to exclude the item, `false` to include it. **Default:** `undefined`.
57115792 * `withFileTypes` {boolean} `true` if the glob should return paths as Dirents,
57125793 `false` otherwise. **Default:** `false`.
5713- * Returns: {string\[ ]} paths of files that match the pattern.
5794+ * Returns: {string\[ ]|fs.Dirent\[ ]} An array of paths or Dirent objects that
5795+ match the pattern. String paths use platform-specific separators (`\` on
5796+ Windows, `/` on POSIX) and are relative to `options.cwd` if provided,
5797+ otherwise relative to the current working directory.
5798+
5799+ Retrieves the file paths matching the specified pattern(s).
5800+
5801+ See `fsPromises.glob()` for detailed information about pattern syntax,
5802+ examples, and behavior.
57145803
57155804```mjs
57165805import { globSync } from 'node:fs';
@@ -8464,6 +8553,7 @@ the file contents.
84648553[`fsPromises.utimes()`]: #fspromisesutimespath-atime-mtime
84658554[`inotify(7)`]: https://man7.org/linux/man-pages/man7/inotify.7.html
84668555[`kqueue(2)`]: https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
8556+ [`path.matchesGlob()`]: path.md#pathmatchesglobpath-pattern
84678557[`util.promisify()`]: util.md#utilpromisifyoriginal
84688558[bigints]: https://tc39.github.io/proposal-bigint
84698559[caveats]: #caveats
0 commit comments