fix: install --fix-lockfile error when package has no dependencies (#5918)

close #5878
This commit is contained in:
Candy
2023-01-17 10:29:09 +08:00
committed by GitHub
parent 00d86db161
commit 6c7ac6320f
3 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
`pnpm install --fix-lockfile` should not fail if the package has no dependencies [#5878](https://github.com/pnpm/pnpm/issues/5878).

View File

@@ -233,3 +233,28 @@ test('--fix-lockfile should preserve all locked dependencies version', async ()
})
expect(lockfile.packages?.['/regenerator-runtime/0.13.9']?.dev).toBeFalsy()
})
test(
'--fix-lockfile should install successfully when package has no dependencies but has peer dependencies with version like 1.0.0_@pnpm+y@1.0.0',
async () => {
prepareEmpty()
const packages = {
dependencies: {
// @pnpm.e2e/has-has-y-peer-peer has no dependencies but has peer dependencies @pnpm.e2e/has-y-peer
// the version of @pnpm.e2e/has-y-peer will be 1.0.0_@pnpm+y@1.0.0
// version 1.0.0_@pnpm+y@1.0.0 should be parsed correctly
'@pnpm.e2e/has-has-y-peer-peer': '1.0.0',
'@pnpm.e2e/has-y-peer': '^1.0.0',
'@pnpm/y': '^1.0.0',
},
}
// install first time to generate lock file
await install(packages, await testDefaults())
// install second time to check whether install successfully with lockfileOnly
await install(packages, await testDefaults({
fixLockfile: true,
}))
}
)

View File

@@ -1128,6 +1128,9 @@ async function resolveDependency (
let prepare!: boolean
let hasBin!: boolean
let pkg: PackageManifest = await getManifestFromResponse(pkgResponse, wantedDependency)
if (!pkg.dependencies) {
pkg.dependencies = {}
}
if (ctx.readPackageHook != null) {
pkg = await ctx.readPackageHook(pkg)
}