sindresorhus / globby

User-friendly glob matching
MIT License
2.51k stars 130 forks source link

Accept `URL` as `options.cwd`? #176

Closed fisker closed 2 years ago

fisker commented 3 years ago
import globby from 'globby';
const dir = new URL('./src', import.meta.url);

console.log(await globby('*', {cwd: dir}));

// TypeError: Expected `cwd` to be of type `string` but received type `object`

Currently, I have to

+ import {fileURLToPath} from 'node:url';
  import globby from 'globby';
  const dir = new URL('./src', import.meta.url);

- console.log(await globby('*', {cwd: dir}));
+ console.log(await globby('*', {cwd: fileURLToPath(dir)}));
sindresorhus commented 3 years ago

Yup. I want to support URL anywhere I accept paths.

TriMoon commented 2 years ago

@fisker

// TypeError: Expected cwd to be of type string but received type object

I was just browsing in this repo and came accross this and wanted to comment. Not sure how you guys implemented this yet but why not do something like this everywhere a URL is accepted?

if (cwd instanceof URL){
  cwd = cwd.toString()
}

eg. check if it is an URL object and if so use it's .toString() method to convert it into a string...