Skip to content

Commit

Permalink
fix: store integrity check when the lockfile is updated (#4580)
Browse files Browse the repository at this point in the history
close #4566
close #4565
  • Loading branch information
zkochan committed Apr 16, 2022
1 parent 88289a4 commit 7cdca5e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-maps-unite.md
@@ -0,0 +1,6 @@
---
"@pnpm/package-requester": patch
"pnpm": patch
---

Don't check the integrity of the store with the package version from the lockfile, when the package was updated [#4580](https://github.com/pnpm/pnpm/pull/4580).
6 changes: 4 additions & 2 deletions packages/package-requester/src/packageRequester.ts
Expand Up @@ -244,7 +244,7 @@ async function resolveAndFetch (
}
}

const pkg = pick(['name', 'version'], manifest ?? {})
const pkg: PkgNameVersion = pick(['name', 'version'], manifest ?? {})
const fetchResult = ctx.fetchPackageToStore({
fetchRawManifest: true,
force: forceFetch,
Expand All @@ -254,7 +254,9 @@ async function resolveAndFetch (
id,
resolution,
},
expectedPkg: options.expectedPkg?.name != null ? options.expectedPkg : pkg,
expectedPkg: options.expectedPkg?.name != null
? (updated ? { name: options.expectedPkg.name, version: pkg.version } : options.expectedPkg)
: pkg,
})

return {
Expand Down
46 changes: 46 additions & 0 deletions packages/package-requester/test/index.ts
Expand Up @@ -973,6 +973,52 @@ test('throw exception if the package data in the store differs from the expected
}
})

test("don't throw an error if the package was updated, so the expectedPkg has a different version than the version in the store", async () => {
const storeDir = tempy.directory()
const cafs = createCafsStore(storeDir)
{
const requestPackage = createPackageRequester({
resolve,
fetchers,
cafs,
networkConcurrency: 1,
storeDir,
verifyStoreIntegrity: true,
})

const projectDir = tempy.directory()
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '3.1.0' }, {
downloadPriority: 0,
lockfileDir: projectDir,
preferredVersions: {},
projectDir,
registry,
})
await pkgResponse.finishing!()
}
const requestPackage = createPackageRequester({
resolve,
fetchers,
cafs,
networkConcurrency: 1,
storeDir,
verifyStoreIntegrity: true,
})
const projectDir = tempy.directory()
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '3.1.0' }, {
downloadPriority: 0,
lockfileDir: tempy.directory(),
preferredVersions: {},
projectDir,
registry,
expectedPkg: {
name: 'is-positive',
version: '3.0.0',
},
})
await expect(pkgResponse.files!()).resolves.toStrictEqual(expect.anything())
})

test('the version in the bundled manifest should be normalized', async () => {
const storeDir = tempy.directory()
const cafs = createCafsStore(storeDir)
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cdca5e

Please sign in to comment.