Skip to content

Commit 236358a

Browse files
committed
doc(fs): clarify glob pattern examples per review feedback
Add note about +(spec|test) pattern matching behavior and provide more precise alternative using brace expansion. Also clarify that returned paths use forward slashes and are relative to cwd. Refs: #58988
1 parent 1f9519b commit 236358a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/api/fs.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,11 @@ for await (const entry of glob('src/{components,utils}/**/*.js'))
11491149
// Extended glob patterns
11501150
for await (const entry of glob('test/**/*.+(spec|test).js'))
11511151
console.log(entry); // Test files ending with .spec.js or .test.js
1152+
// Note: This also matches files like 'foo.spectest.js'
1153+
1154+
// More precise pattern using brace expansion
1155+
for await (const entry of glob('test/**/*.{spec,test}.js'))
1156+
console.log(entry); // Only matches .spec.js or .test.js files
11521157
11531158
// Excluding patterns
11541159
for await (const entry of glob('**/*.js', { exclude: ['node_modules/**'] }))
@@ -1174,6 +1179,9 @@ const { glob } = require('node:fs/promises');
11741179
case-sensitive on other platforms
11751180
* **Path separators**: Forward slashes (`/`) are used in patterns regardless of
11761181
platform; they are automatically converted to the appropriate separator
1182+
* **Returned paths**: Results always use forward slashes (`/`) as path separators,
1183+
even on Windows. Paths are relative to `options.cwd` if provided, otherwise
1184+
relative to the current working directory
11771185
* **Symlinks**: Symbolic links are followed and their targets are included in results
11781186
* **Hidden files**: Files starting with `.` are included in results when explicitly
11791187
matched, but not when using `*` or `**` patterns

0 commit comments

Comments
 (0)