* Create a module resolver for @deno/doc. * * Handles resolving relative imports and esm.sh redirects.
()
| 130 | * Handles resolving relative imports and esm.sh redirects. |
| 131 | */ |
| 132 | function createResolver(): (specifier: string, referrer: string) => string { |
| 133 | return (specifier: string, referrer: string) => { |
| 134 | // Handle relative imports |
| 135 | if (specifier.startsWith('.') || specifier.startsWith('/')) { |
| 136 | return new URL(specifier, referrer).toString() |
| 137 | } |
| 138 | |
| 139 | // Handle bare specifiers - resolve through esm.sh |
| 140 | if ( |
| 141 | !specifier.startsWith('http://') && |
| 142 | !specifier.startsWith('https://') && |
| 143 | !isBuiltin(specifier) |
| 144 | ) { |
| 145 | // Try to resolve bare specifier relative to esm.sh base |
| 146 | const baseUrl = new URL(referrer) |
| 147 | if (baseUrl.hostname === 'esm.sh') { |
| 148 | return `https://esm.sh/${specifier}` |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return specifier |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Get the TypeScript types URL from esm.sh's x-typescript-types header. |
no outgoing calls
no test coverage detected