fix(package-requester): the version in the bundled manifest should be… (#4037)

This commit is contained in:
Zoltan Kochan
2021-11-24 11:37:31 +02:00
committed by GitHub
parent 119b3a9085
commit dbd8acfe99
3 changed files with 40 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/package-requester": patch
---
The version in the bundled manifest should always be normalized.

View File

@@ -68,6 +68,13 @@ const pickBundledManifest = pick([
'version',
])
function normalizeBundledManifest (manifest: DependencyManifest): BundledManifest {
return {
...pickBundledManifest(manifest),
version: semver.clean(manifest.version ?? '0.0.0', { loose: true }) ?? manifest.version,
}
}
export default function (
opts: {
engineStrict?: boolean
@@ -458,7 +465,7 @@ Actual package in the store by the given integrity: ${pkgFilesIndex.name}@${pkgF
})
if (manifest != null) {
manifest()
.then((manifest) => bundledManifest.resolve(pickBundledManifest(manifest)))
.then((manifest) => bundledManifest.resolve(normalizeBundledManifest(manifest)))
.catch(bundledManifest.reject)
}
finishing.resolve(undefined)
@@ -485,7 +492,7 @@ Actual package in the store by the given integrity: ${pkgFilesIndex.name}@${pkgF
: undefined
if (fetchManifest != null) {
fetchManifest()
.then((manifest) => bundledManifest.resolve(pickBundledManifest(manifest)))
.then((manifest) => bundledManifest.resolve(normalizeBundledManifest(manifest)))
.catch(bundledManifest.reject)
}
const fetchedPackage = await ctx.requestsQueue.add(async () => ctx.fetch(

View File

@@ -945,3 +945,29 @@ test('throw exception if the package data in the store differs from the expected
await expect(files()).resolves.toStrictEqual(expect.anything())
}
})
test('the version in the bundled manifest should be normalized', async () => {
const storeDir = tempy.directory()
const cafs = createCafsStore(storeDir)
const requestPackage = createPackageRequester({
resolve,
fetchers,
cafs,
networkConcurrency: 1,
storeDir,
verifyStoreIntegrity: true,
})
const pkgResponse = await requestPackage({ alias: 'react-terminal', pref: '1.2.1' }, {
downloadPriority: 0,
lockfileDir: tempy.directory(),
preferredVersions: {},
projectDir: tempy.directory(),
registry,
})
await expect(pkgResponse.bundledManifest!()).resolves.toStrictEqual(expect.objectContaining({
version: '1.2.1',
}))
await pkgResponse.finishing!()
})