Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix resolvePath return type #172

Merged
merged 2 commits into from Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/_utils.ts
Expand Up @@ -6,7 +6,10 @@ export function normalizeSlash(string_) {
return string_.replace(/\\/g, "/");
}

export function pcall(function_, ...arguments_) {
export function pcall<TFn extends (...args: any[]) => any>(
function_: TFn,
...arguments_: Parameters<TFn>
): Promise<ReturnType<TFn>> {
try {
return Promise.resolve(function_(...arguments_)).catch((error) =>
perr(error)
Expand Down
7 changes: 5 additions & 2 deletions src/resolve.ts
Expand Up @@ -132,11 +132,14 @@ export function resolve(id: string, options?: ResolveOptions): Promise<string> {
return pcall(resolveSync, id, options);
}

export function resolvePathSync(id: string, options?: ResolveOptions) {
export function resolvePathSync(id: string, options?: ResolveOptions): string {
return fileURLToPath(resolveSync(id, options));
}

export function resolvePath(id: string, options?: ResolveOptions) {
export function resolvePath(
id: string,
options?: ResolveOptions
): Promise<string> {
return pcall(resolvePathSync, id, options);
}

Expand Down