Skip to content

Commit

Permalink
fix(package-requester): the version in the bundled manifest should be… (
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Nov 24, 2021
1 parent 119b3a9 commit dbd8acf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-zoos-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/package-requester": patch
---

The version in the bundled manifest should always be normalized.
11 changes: 9 additions & 2 deletions packages/package-requester/src/packageRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions packages/package-requester/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
})

0 comments on commit dbd8acf

Please sign in to comment.