File
Blob: worker/dev/register-aliases.mjs
| 1 | import { registerHooks } from 'node:module'; |
| 2 | import { pathToFileURL } from 'node:url'; |
| 3 | import { aliases } from './aliases.ts'; |
| 4 | |
| 5 | const roots = Object.entries(aliases).map(([alias, directory]) => [ |
| 6 | `${alias}/`, |
| 7 | pathToFileURL(`${directory}/`), |
| 8 | ]); |
| 9 | |
| 10 | registerHooks({ |
| 11 | resolve(specifier, context, nextResolve) { |
| 12 | for (const [prefix, root] of roots) { |
| 13 | if (specifier.startsWith(prefix)) { |
| 14 | return nextResolve(new URL(specifier.slice(prefix.length), root).href, context); |
| 15 | } |
| 16 | } |
| 17 | return nextResolve(specifier, context); |
| 18 | }, |
| 19 | }); |