diff options
| author | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
| commit | 3443c1c65e9f1753e1e656b35d08416c1fa298f2 (patch) | |
| tree | 4e43236f460145a4d75d1b4616dcb7aa6ef08f51 /viewer/tests/importmap-hooks.mjs | |
| download | worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip | |
worldmap-viewer: initial public history
Diffstat (limited to 'viewer/tests/importmap-hooks.mjs')
| -rw-r--r-- | viewer/tests/importmap-hooks.mjs | 11 |
1 files changed, 11 insertions, 0 deletions
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); +} |
