diff --git a/src/_utils.ts b/src/_utils.ts index a511257..87b9065 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -6,26 +6,6 @@ export function normalizeSlash(string_) { return string_.replace(/\\/g, "/"); } -export function pcall any>( - function_: TFn, - ...arguments_: Parameters -): Promise> { - try { - return Promise.resolve(function_(...arguments_)).catch((error) => - perr(error), - ); - } catch (error) { - return perr(error); - } -} - -export function perr(_error) { - const error = new Error(_error); - error.code = _error.code; - Error.captureStackTrace(error, pcall); - return Promise.reject(error); -} - export function isObject(value) { return value !== null && typeof value === "object"; } diff --git a/src/resolve.ts b/src/resolve.ts index 24bcdac..bd505d7 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -5,7 +5,7 @@ import { isAbsolute, normalize } from "pathe"; import { moduleResolve } from "import-meta-resolve"; import { PackageJson, readPackageJSON } from "pkg-types"; import { fileURLToPath, normalizeid } from "./utils"; -import { pcall, BUILTIN_MODULES } from "./_utils"; +import { BUILTIN_MODULES } from "./_utils"; const DEFAULT_CONDITIONS_SET = new Set(["node", "import"]); const DEFAULT_URL = pathToFileURL(process.cwd()); @@ -136,7 +136,11 @@ export function resolveSync(id: string, options?: ResolveOptions): string { } export function resolve(id: string, options?: ResolveOptions): Promise { - return pcall(resolveSync, id, options); + try { + return Promise.resolve(resolveSync(id, options)); + } catch (error) { + return Promise.reject(error); + } } export function resolvePathSync(id: string, options?: ResolveOptions): string { @@ -147,7 +151,11 @@ export function resolvePath( id: string, options?: ResolveOptions, ): Promise { - return pcall(resolvePathSync, id, options); + try { + return Promise.resolve(resolvePathSync(id, options)); + } catch (error) { + return Promise.reject(error); + } } export function createResolve(defaults?: ResolveOptions) {