Skip to content

Commit

Permalink
feat(rootDir): Add file URL support to rootDir option
Browse files Browse the repository at this point in the history
Please note, this only supports the URL with 'file:' protocol. Attempting to use other than 'file:' protocol will causing an error.
  • Loading branch information
mitsuki31 committed Apr 26, 2024
1 parent f578589 commit 2ba4a20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/lsfnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ export async function ls(
+ (Array.isArray(options) ? 'array' : typeof options));
}

// Resolve its absolute and relative path
// Check and resolve the `rootDir` option
if (options.rootDir && (options.rootDir instanceof URL
|| (typeof options.rootDir === 'string' && /^[a-zA-Z]+:/.test(options.rootDir))
)) {
options.rootDir = fileUrlToPath(options.rootDir);
}

// Resolve the absolute and relative of the dirpath argument
absdirpath = path.isAbsolute(<StringPath> dirpath)
? <StringPath> dirpath
: path.posix.resolve(<StringPath> dirpath);
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export declare interface LsOptions {
* @defaultValue `'.'` or `process.cwd()`
* @since 1.0.0
*/
rootDir?: StringPath | undefined;
rootDir?: StringPath | URL | undefined;
/**
* Determines whether to return absolute paths for all entries.
*
Expand Down Expand Up @@ -249,7 +249,7 @@ export declare interface DefaultLsOptions {
readonly recursive: false;
readonly match: RegExp;
readonly exclude: undefined;
readonly rootDir: StringPath;
readonly rootDir: StringPath | URL;
readonly absolute: false;
readonly basename: false;
}
Expand Down

0 comments on commit 2ba4a20

Please sign in to comment.