Skip to content

Commit b1c0943

Browse files
committed
Update packagist to API p2
fix cache test to work with packagist p2 endpoint data remove name from packagist test since it is not in the raw data fix linter issues
1 parent e05fce6 commit b1c0943

File tree

4 files changed

+106
-57
lines changed

4 files changed

+106
-57
lines changed

providers/fetch/packagistFetch.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,25 @@ class PackagistFetch extends AbstractFetch {
4242
async _getRegistryData(spec) {
4343
let registryData
4444
const baseUrl = providerMap.packagist
45-
const { body, statusCode } = await requestRetry.get(`${baseUrl}/p/${spec.namespace}/${spec.name}.json`, {
45+
const { body, statusCode } = await requestRetry.get(`${baseUrl}/p2/${spec.namespace}/${spec.name}.json`, {
4646
json: true
4747
})
4848
if (statusCode !== 200 || !body) return null
4949
registryData = body
5050

51-
// Some PHP package versions begin with a 'v' for example v1.0.0 so check for that case
52-
const packages = registryData.packages[`${spec.namespace}/${spec.name}`]
53-
registryData.manifest = packages[`v${spec.revision}`] || packages[`${spec.revision}`]
51+
// Get the array of versions for this package
52+
const packageVersions = registryData.packages[`${spec.namespace}/${spec.name}`]
53+
if (!packageVersions || !Array.isArray(packageVersions)) return null
54+
55+
// Find the specific version in the array - handle both 'v1.0.0' and '1.0.0' formats
56+
const targetVersion = spec.revision
57+
const targetVersionWithV = `v${spec.revision}`
58+
59+
registryData.manifest = packageVersions.find(
60+
versionObj => versionObj.version === targetVersion || versionObj.version === targetVersionWithV
61+
)
62+
63+
if (!registryData.manifest) return null
5464

5565
registryData.releaseDate = get(registryData, 'manifest.time')
5666
delete registryData['packages']

0 commit comments

Comments
 (0)