(url: string)
| 470 | } |
| 471 | |
| 472 | function matchUrlToFixture(url: string): FixtureMatchWithVersion | null { |
| 473 | const urlObj = URL.parse(url) |
| 474 | if (!urlObj) return null |
| 475 | |
| 476 | const { host, pathname, searchParams } = urlObj |
| 477 | |
| 478 | // npm registry (registry.npmjs.org) |
| 479 | if (host === 'registry.npmjs.org') { |
| 480 | // Search endpoint |
| 481 | if (pathname === '/-/v1/search') { |
| 482 | const query = searchParams.get('text') |
| 483 | if (query) { |
| 484 | const maintainerMatch = query.match(/^maintainer:(.+)$/) |
| 485 | if (maintainerMatch?.[1]) { |
| 486 | return { type: 'user', name: maintainerMatch[1] } |
| 487 | } |
| 488 | return { type: 'search', name: query } |
| 489 | } |
| 490 | return { type: 'search', name: '' } |
| 491 | } |
| 492 | |
| 493 | // Org packages |
| 494 | const orgMatch = pathname.match(/^\/-\/org\/([^/]+)\/package$/) |
| 495 | if (orgMatch?.[1]) { |
| 496 | return { type: 'org', name: orgMatch[1] } |
| 497 | } |
| 498 | |
| 499 | // Packument - handle both full packument and version manifest requests |
| 500 | let packagePath = decodeURIComponent(pathname.slice(1)) |
| 501 | if (packagePath && !packagePath.startsWith('-/')) { |
| 502 | let version: string | undefined |
| 503 | |
| 504 | if (packagePath.startsWith('@')) { |
| 505 | const parts = packagePath.split('/') |
| 506 | if (parts.length > 2) { |
| 507 | // @scope/name/version or @scope/name/latest |
| 508 | version = parts[2] |
| 509 | packagePath = `${parts[0]}/${parts[1]}` |
| 510 | } |
| 511 | // else just @scope/name - full packument |
| 512 | } else { |
| 513 | const slashIndex = packagePath.indexOf('/') |
| 514 | if (slashIndex !== -1) { |
| 515 | // name/version or name/latest |
| 516 | version = packagePath.slice(slashIndex + 1) |
| 517 | packagePath = packagePath.slice(0, slashIndex) |
| 518 | } |
| 519 | // else just name - full packument |
| 520 | } |
| 521 | |
| 522 | return { type: 'packument', name: packagePath, version } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | // npm API (api.npmjs.org) |
| 527 | if (host === 'api.npmjs.org') { |
| 528 | const downloadsMatch = pathname.match(/^\/downloads\/point\/[^/]+\/(.+)$/) |
| 529 | if (downloadsMatch?.[1]) { |
no test coverage detected