From b34c93d7b6fbcf96507585d685ed05ad14416615 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 11 May 2024 06:09:20 +0200 Subject: [PATCH] feat: support passing URL --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9823730..3d0cfb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,7 +77,7 @@ export interface ImportTsOptions { * The URL of the parent module. * Usually you pass `import.meta.url` or `__filename` of the module you are doing the importing. */ - parentURL: string + parentURL: string | URL /** * The `with` option for native `import()` call. * @@ -152,7 +152,7 @@ export function isTypeScriptFile(path: string) { * @param path The path to the file to import. * @param parentURL The URL of the parent module, usually `import.meta.url` or `__filename`. */ -export async function importTs(path: string, parentURL: string): Promise +export async function importTs(path: string, parentURL: string | URL): Promise /** * Import a TypeScript module at runtime. * @@ -160,8 +160,8 @@ export async function importTs(path: string, parentURL: string): Promis * @param options Options */ export async function importTs(path: string, options: ImportTsOptions): Promise -export async function importTs(path: string, options: string | ImportTsOptions): Promise { - if (typeof options === 'string') +export async function importTs(path: string, options: string | URL | ImportTsOptions): Promise { + if (typeof options === 'string' || options instanceof URL) options = { parentURL: options } const {