Skip to content

Commit

Permalink
cwd can be a file:// url
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 27, 2023
1 parent d03ed0a commit fa0cd77
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -205,6 +205,9 @@ share the previously loaded cache.
anything. See also: "Windows, CWDs, Drive Letters, and UNC
Paths", below.

This option may be eiher a string path or a `file://` URL
object or string.

- `windowsPathsNoEscape` Use `\\` as a path separator _only_, and
_never_ as an escape character. If set, all `\\` characters are
replaced with `/` in the pattern.
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -41,6 +41,7 @@ changes.
`mark:true`.)
- Simplified `cwd` behavior so it is far less magical, and relies
less on platform-specific absolute path representations.
- `cwd` can be a File URL or a string path.
- More efficient handling for absolute patterns. (That is,
patterns that start with `/` on any platform, or start with a
drive letter or UNC path on Windows.)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -61,7 +61,7 @@
"fs.realpath": "^1.0.0",
"minimatch": "^7.2.0",
"minipass": "^4.2.4",
"path-scurry": "^1.4.0"
"path-scurry": "^1.5.0"
},
"devDependencies": {
"@types/mkdirp": "^1.0.2",
Expand Down
8 changes: 7 additions & 1 deletion src/glob.ts
Expand Up @@ -7,6 +7,7 @@ import {
PathScurryPosix,
PathScurryWin32,
} from 'path-scurry'
import {fileURLToPath} from 'url'
import { Ignore } from './ignore.js'
import { Pattern } from './pattern.js'
import { GlobStream, GlobWalker } from './walker.js'
Expand All @@ -26,7 +27,7 @@ const defaultPlatform: NodeJS.Platform =
export interface GlobOptions {
absolute?: boolean
allowWindowsEscape?: boolean
cwd?: string
cwd?: string | URL
dot?: boolean
follow?: boolean
ignore?: string | string[] | Ignore
Expand Down Expand Up @@ -105,6 +106,11 @@ export class Glob<Opts extends GlobOptions> {
this.dot = !!opts.dot
this.nodir = !!opts.nodir
this.mark = !!opts.mark
if (!opts.cwd) {
this.cwd = ''
} else if (opts.cwd instanceof URL || opts.cwd.startsWith('file://')) {
opts.cwd = fileURLToPath(opts.cwd)
}
this.cwd = opts.cwd || ''
this.nobrace = !!opts.nobrace
this.noext = !!opts.noext
Expand Down
2 changes: 1 addition & 1 deletion src/walker.ts
Expand Up @@ -13,7 +13,7 @@ import { Processor } from './processor.js'
export interface GlobWalkerOpts {
absolute?: boolean
allowWindowsEscape?: boolean
cwd?: string
cwd?: string | URL
dot?: boolean
follow?: boolean
ignore?: string | string[] | Ignore
Expand Down

0 comments on commit fa0cd77

Please sign in to comment.