fs: add support for `URL` for `fs.glob`'s `cwd` option · nodejs/node@5c36510 · GitHub
Skip to content

Commit 5c36510

Browse files
committed
fs: add support for URL for fs.glob's cwd option
PR-URL: #58182 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
1 parent 4cc4195 commit 5c36510

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

doc/api/fs.md

Lines changed: 12 additions & 3 deletions

lib/internal/fs/glob.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const {
3838
hideStackFrames,
3939
} = require('internal/errors');
4040
const assert = require('internal/assert');
41+
const { toPathIfFileURL } = require('internal/url');
4142

4243
let minimatch;
4344
function lazyMinimatch() {
@@ -268,7 +269,7 @@ class Glob {
268269
constructor(pattern, options = kEmptyObject) {
269270
validateObject(options, 'options');
270271
const { exclude, cwd, withFileTypes } = options;
271-
this.#root = cwd ?? '.';
272+
this.#root = toPathIfFileURL(cwd) ?? '.';
272273
this.#withFileTypes = !!withFileTypes;
273274
if (exclude != null) {
274275
validateStringArrayOrFunction(exclude, 'options.exclude');

test/parallel/test-fs-glob.mjs

Lines changed: 34 additions & 0 deletions

0 commit comments

Comments
 (0)