Skip to content

Commit

Permalink
fix: normalize specifier type
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 11, 2024
1 parent d76fe19 commit 30c743d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = any>(specifier: string, parentURL: string | URL): Promise<T>
export async function importx<T = any>(specifier: string | URL, parentURL: string | URL): Promise<T>
/**
* Import a TypeScript module at runtime.
*
* @param specifier The path to the file to import.
* @param options Options
*/
export async function importx<T = any>(specifier: string, options: ImportxOptions): Promise<T>
export async function importx<T = any>(specifier: string, options: string | URL | ImportxOptions): Promise<T> {
export async function importx<T = any>(specifier: string | URL, options: ImportxOptions): Promise<T>
export async function importx<T = any>(_specifier: string | URL, options: string | URL | ImportxOptions): Promise<T> {
if (typeof options === 'string' || options instanceof URL)
options = { parentURL: options }

Expand All @@ -41,6 +41,10 @@ export async function importx<T = any>(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))
Expand Down

0 comments on commit 30c743d

Please sign in to comment.