| 6 | * async operations are natural. |
| 7 | * |
| 8 | * Only supports ESM import (not CJS require). |
| 9 | */ |
| 10 |
| 11 | import { createResolve, createLoad } from "./hooks.ts"; |
| 12 | import { fetchModule } from "./fetch.ts"; |
| 13 |
| 14 | export const importMetaUrl = import.meta.url; |
| 15 |
| 16 | let resolveHook = createResolve(fetchModule); |
| 17 | export const load = createLoad(fetchModule); |
| 18 |
| 19 | export function initialize(data: { mainUrl?: string } = {}): void { |
| 20 | resolveHook = createResolve(fetchModule, data.mainUrl); |
| 21 | } |
| 22 |
| 23 | // Node captures exported hook functions before initialize() runs. Keep that |
| 24 | // function identity stable while initialization configures its delegate. |
| 25 | export function resolve(...args: Parameters<typeof resolveHook>) { |
| 26 | return resolveHook(...args); |
| 27 | } |
| 28 |