(
root: string,
path: string,
servePath = `/${join("_import", path)}`,
getHash?: (path: string) => string
)
| 488 | * with the resolveImport returned by getResolvers (assuming caching). |
| 489 | */ |
| 490 | export function getModuleResolver( |
| 491 | root: string, |
| 492 | path: string, |
| 493 | servePath = `/${join("_import", path)}`, |
| 494 | getHash?: (path: string) => string |
| 495 | ): (specifier: string) => Promise<string> { |
| 496 | return async (specifier) => { |
| 497 | return isPathImport(specifier) |
| 498 | ? relativePath(servePath, resolveImportPath(root, resolvePath(path, specifier), getHash)) |
| 499 | : builtins.has(specifier) || specifier.startsWith("observablehq:") |
| 500 | ? relativePath(servePath, resolveBuiltin(specifier)) |
| 501 | : specifier.startsWith("npm:") |
| 502 | ? relativePath(servePath, await resolveNpmImport(root, specifier.slice("npm:".length))) |
| 503 | : specifier.startsWith("jsr:") |
| 504 | ? relativePath(servePath, await resolveJsrImport(root, specifier.slice("jsr:".length))) |
| 505 | : !/^\w+:/.test(specifier) |
| 506 | ? relativePath(servePath, await resolveNodeImport(root, specifier)) |
| 507 | : specifier; |
| 508 | }; |
| 509 | } |
| 510 | |
| 511 | export function resolveBuiltin(specifier: string): string { |
| 512 | if (builtins.has(specifier)) return builtins.get(specifier)!; |
no test coverage detected