Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions providers/fetch/packagistFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,25 @@ class PackagistFetch extends AbstractFetch {
async _getRegistryData(spec) {
let registryData
const baseUrl = providerMap.packagist
const { body, statusCode } = await requestRetry.get(`${baseUrl}/p/${spec.namespace}/${spec.name}.json`, {
const { body, statusCode } = await requestRetry.get(`${baseUrl}p2/${spec.namespace}/${spec.name}.json`, {
json: true
})
if (statusCode !== 200 || !body) return null
registryData = body

// Some PHP package versions begin with a 'v' for example v1.0.0 so check for that case
const packages = registryData.packages[`${spec.namespace}/${spec.name}`]
registryData.manifest = packages[`v${spec.revision}`] || packages[`${spec.revision}`]
// Get the array of versions for this package
const packageVersions = registryData.packages[`${spec.namespace}/${spec.name}`]
if (!packageVersions || !Array.isArray(packageVersions)) return null

// Find the specific version in the array - handle both 'v1.0.0' and '1.0.0' formats
const targetVersion = spec.revision
const targetVersionWithV = `v${spec.revision}`

registryData.manifest = packageVersions.find(
versionObj => versionObj.version === targetVersion || versionObj.version === targetVersionWithV
)

if (!registryData.manifest) return null

registryData.releaseDate = get(registryData, 'manifest.time')
delete registryData['packages']
Expand Down
Loading