fix: omit the major version matching restriction when filtering latest dist-tags in pkg metadata (#10130)

close #10100

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Daiki Nishikawa
2025-10-29 01:05:36 +09:00
committed by GitHub
parent 6c3dcb8bf7
commit 0152a51061
4 changed files with 56 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/registry.pkg-metadata-filter": patch
"pnpm": patch
---
When the `latest` version doesn't satisfy the maturity requirement configured by `minimumReleaseAge`, pick the highest version that is mature enough, even if it has a different major version [#10100](https://github.com/pnpm/pnpm/issues/10100).

View File

@@ -38,7 +38,7 @@ export function filterPkgMetadataByPublishDate (
distTagsWithinDate[tag] = distTagVersion
continue
}
// Repopulate the tag to the highest version available within date that has the same major as the original tag's version
// Repopulate the tag to the highest version available within date
const originalSemVer = tryParseSemver(distTagVersion)
if (!originalSemVer) continue
const originalIsPrerelease = (originalSemVer.prerelease.length > 0)
@@ -48,7 +48,7 @@ export function filterPkgMetadataByPublishDate (
const candidateParsed = tryParseSemver(candidate)
if (
!candidateParsed ||
candidateParsed.major !== originalSemVer.major ||
(tag !== 'latest' && candidateParsed.major !== originalSemVer.major) ||
(candidateParsed.prerelease.length > 0) !== originalIsPrerelease
) continue
if (!bestVersion) {

View File

@@ -41,3 +41,26 @@ exports[`filterPkgMetadataByPublishDate 1`] = `
},
}
`;
exports[`filterPkgMetadataByPublishDate 2`] = `
{
"dist-tags": {
"latest": "2.9.9",
},
"name": "dist-tag-date",
"time": {
"2.9.9": "2020-03-01T00:00:00.000Z",
"3.0.0": "2020-05-01T00:00:00.000Z",
},
"versions": {
"2.9.9": {
"dist": {
"shasum": "",
"tarball": "https://registry.npmjs.org/dist-tag-date/-/dist-tag-date-2.9.9.tgz",
},
"name": "dist-tag-date",
"version": "2.9.9",
},
},
}
`;

View File

@@ -38,4 +38,28 @@ test('filterPkgMetadataByPublishDate', () => {
'3.2.0': '2020-05-01T00:00:00.000Z',
},
}, cutoff)).toMatchSnapshot()
expect(filterPkgMetadataByPublishDate({
name,
versions: {
'3.0.0': {
name,
version: '3.0.0',
dist: { tarball: `https://registry.npmjs.org/${name}/-/${name}-3.0.0.tgz`, shasum: '' },
},
'2.9.9': {
name,
version: '2.9.9',
dist: { tarball: `https://registry.npmjs.org/${name}/-/${name}-2.9.9.tgz`, shasum: '' },
},
},
'dist-tags': {
latest: '3.0.0',
stable: '3.0.0',
},
time: {
'2.9.9': '2020-03-01T00:00:00.000Z',
'3.0.0': '2020-05-01T00:00:00.000Z',
},
}, cutoff)).toMatchSnapshot()
})