( url: string, storage: ReturnType<typeof useStorage>, )
| 552 | } |
| 553 | |
| 554 | async function handleJsdelivrDataApi( |
| 555 | url: string, |
| 556 | storage: ReturnType<typeof useStorage>, |
| 557 | ): Promise<MockResult | null> { |
| 558 | const urlObj = URL.parse(url) |
| 559 | if (!urlObj) return null |
| 560 | |
| 561 | if (urlObj.host !== 'data.jsdelivr.com') return null |
| 562 | |
| 563 | const packageMatch = decodeURIComponent(urlObj.pathname).match(/^\/v1\/packages\/npm\/(.+)$/) |
| 564 | if (!packageMatch?.[1]) return null |
| 565 | |
| 566 | const parsed = parseScopedPackageWithVersion(packageMatch[1]) |
| 567 | |
| 568 | // Try per-package fixture first |
| 569 | const fixturePath = getFixturePath('jsdelivr', parsed.name) |
| 570 | const fixture = await storage.getItem<unknown>(fixturePath) |
| 571 | if (fixture) { |
| 572 | return { data: fixture } |
| 573 | } |
| 574 | |
| 575 | // Fall back to generic stub (no declaration files) |
| 576 | return { |
| 577 | data: { |
| 578 | type: 'npm', |
| 579 | name: parsed.name, |
| 580 | version: parsed.version || 'latest', |
| 581 | files: [ |
| 582 | { name: 'package.json', hash: 'abc123', size: 1000 }, |
| 583 | { name: 'index.js', hash: 'def456', size: 500 }, |
| 584 | { name: 'README.md', hash: 'ghi789', size: 2000 }, |
| 585 | ], |
| 586 | }, |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Shared fixture-backed fetch implementation. |
no test coverage detected