Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1x 1x 1x 52x 52x 52x 52x 52x 52x 106x 106x 104x 104x 2x 106x 52x | import { pathToFileURL } from 'node:url';
import { parse, resolve } from '@import-maps/resolve';
import type { ImportMap, ImportMapResolver } from './types';
export function createImportMapResolver(
base: string,
importMap: ImportMap
): ImportMapResolver {
const baseURL = pathToFileURL(base);
const parsedImportMap = parse(importMap, baseURL);
return (specifier: string, scriptURL: string): string | null => {
const result = resolve(specifier, parsedImportMap, new URL(scriptURL));
if (result.resolvedImport) {
return result.resolvedImport.href;
}
return null;
};
}
|