Skip to content

Commit fa0cd77

Browse files
committed
cwd can be a file:// url
1 parent d03ed0a commit fa0cd77

6 files changed

Lines changed: 20 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ share the previously loaded cache.
205205
anything. See also: "Windows, CWDs, Drive Letters, and UNC
206206
Paths", below.
207207

208+
This option may be eiher a string path or a `file://` URL
209+
object or string.
210+
208211
- `windowsPathsNoEscape` Use `\\` as a path separator _only_, and
209212
_never_ as an escape character. If set, all `\\` characters are
210213
replaced with `/` in the pattern.

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ changes.
4141
`mark:true`.)
4242
- Simplified `cwd` behavior so it is far less magical, and relies
4343
less on platform-specific absolute path representations.
44+
- `cwd` can be a File URL or a string path.
4445
- More efficient handling for absolute patterns. (That is,
4546
patterns that start with `/` on any platform, or start with a
4647
drive letter or UNC path on Windows.)

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"fs.realpath": "^1.0.0",
6262
"minimatch": "^7.2.0",
6363
"minipass": "^4.2.4",
64-
"path-scurry": "^1.4.0"
64+
"path-scurry": "^1.5.0"
6565
},
6666
"devDependencies": {
6767
"@types/mkdirp": "^1.0.2",

src/glob.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PathScurryPosix,
88
PathScurryWin32,
99
} from 'path-scurry'
10+
import {fileURLToPath} from 'url'
1011
import { Ignore } from './ignore.js'
1112
import { Pattern } from './pattern.js'
1213
import { GlobStream, GlobWalker } from './walker.js'
@@ -26,7 +27,7 @@ const defaultPlatform: NodeJS.Platform =
2627
export interface GlobOptions {
2728
absolute?: boolean
2829
allowWindowsEscape?: boolean
29-
cwd?: string
30+
cwd?: string | URL
3031
dot?: boolean
3132
follow?: boolean
3233
ignore?: string | string[] | Ignore
@@ -105,6 +106,11 @@ export class Glob<Opts extends GlobOptions> {
105106
this.dot = !!opts.dot
106107
this.nodir = !!opts.nodir
107108
this.mark = !!opts.mark
109+
if (!opts.cwd) {
110+
this.cwd = ''
111+
} else if (opts.cwd instanceof URL || opts.cwd.startsWith('file://')) {
112+
opts.cwd = fileURLToPath(opts.cwd)
113+
}
108114
this.cwd = opts.cwd || ''
109115
this.nobrace = !!opts.nobrace
110116
this.noext = !!opts.noext

src/walker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Processor } from './processor.js'
1313
export interface GlobWalkerOpts {
1414
absolute?: boolean
1515
allowWindowsEscape?: boolean
16-
cwd?: string
16+
cwd?: string | URL
1717
dot?: boolean
1818
follow?: boolean
1919
ignore?: string | string[] | Ignore

0 commit comments

Comments
 (0)