From 30c743d1705cd170644115fd68e53a1c4bb00745 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 11 May 2024 14:48:49 +0200 Subject: [PATCH] fix: normalize specifier type --- src/import.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/import.ts b/src/import.ts index 2723874..58b72fa 100644 --- a/src/import.ts +++ b/src/import.ts @@ -21,15 +21,15 @@ export function getModuleInfo(mod: any): ImportxModuleInfo | undefined { * @param specifier The path to the file to import. * @param parentURL The URL of the parent module, usually `import.meta.url` or `__filename`. */ -export async function importx(specifier: string, parentURL: string | URL): Promise +export async function importx(specifier: string | URL, parentURL: string | URL): Promise /** * Import a TypeScript module at runtime. * * @param specifier The path to the file to import. * @param options Options */ -export async function importx(specifier: string, options: ImportxOptions): Promise -export async function importx(specifier: string, options: string | URL | ImportxOptions): Promise { +export async function importx(specifier: string | URL, options: ImportxOptions): Promise +export async function importx(_specifier: string | URL, options: string | URL | ImportxOptions): Promise { if (typeof options === 'string' || options instanceof URL) options = { parentURL: options } @@ -41,6 +41,10 @@ export async function importx(specifier: string, options: string | URL ...otherOptions } = options + const specifier = (_specifier instanceof URL) + ? fileURLToPath(_specifier) + : _specifier + let loader = options.loader || 'auto' if (loader === 'auto') loader = await detectLoader(cache, isTypeScriptFile(specifier))