Skip to content

Commit

Permalink
feat: support passing URL
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 11, 2024
1 parent c92ab72 commit b34c93d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -152,16 +152,16 @@ 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<T = any>(path: string, parentURL: string): Promise<T>
export async function importTs<T = any>(path: string, parentURL: string | URL): Promise<T>
/**
* Import a TypeScript module at runtime.
*
* @param path The path to the file to import.
* @param options Options
*/
export async function importTs<T = any>(path: string, options: ImportTsOptions): Promise<T>
export async function importTs<T = any>(path: string, options: string | ImportTsOptions): Promise<T> {
if (typeof options === 'string')
export async function importTs<T = any>(path: string, options: string | URL | ImportTsOptions): Promise<T> {
if (typeof options === 'string' || options instanceof URL)
options = { parentURL: options }

const {
Expand Down

0 comments on commit b34c93d

Please sign in to comment.