* Get the TypeScript types URL from esm.sh's x-typescript-types header. * * esm.sh serves types URL in the `x-typescript-types` header, not at the main URL. * Example: curl -sI 'https://esm.sh/ufo@1.5.0' returns header: * x-typescript-types: https://esm.sh/ufo@1.5.0/dist/index.d.ts
(packageName: string, version: string)
| 161 | * x-typescript-types: https://esm.sh/ufo@1.5.0/dist/index.d.ts |
| 162 | */ |
| 163 | async function getTypesUrl(packageName: string, version: string): Promise<string | null> { |
| 164 | const url = `https://esm.sh/${packageName}@${version}` |
| 165 | |
| 166 | try { |
| 167 | const response = await $fetch.raw(url, { |
| 168 | method: 'HEAD', |
| 169 | timeout: FETCH_TIMEOUT_MS, |
| 170 | }) |
| 171 | return response.headers.get('x-typescript-types') |
| 172 | } catch (e) { |
| 173 | // eslint-disable-next-line no-console |
| 174 | console.error(e) |
| 175 | return null |
| 176 | } |
| 177 | } |