From 3443c1c65e9f1753e1e656b35d08416c1fa298f2 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 00:14:38 +0200 Subject: worldmap-viewer: initial public history --- viewer/tests/importmap-hooks.mjs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 viewer/tests/importmap-hooks.mjs (limited to 'viewer/tests/importmap-hooks.mjs') diff --git a/viewer/tests/importmap-hooks.mjs b/viewer/tests/importmap-hooks.mjs new file mode 100644 index 0000000..3769c21 --- /dev/null +++ b/viewer/tests/importmap-hooks.mjs @@ -0,0 +1,11 @@ +// Node module-resolution hook: resolve bare specifiers with the page's import map. +let map; +export function initialize(data) { map = data; } +export async function resolve(spec, ctx, next) { + for (const [k, v] of Object.entries(map.imports)) { + if (spec === k || (k.endsWith('/') && spec.startsWith(k))) { + return { url: new URL(v + spec.slice(k.length), map.base).href, shortCircuit: true }; + } + } + return next(spec, ctx); +} -- cgit