fix: lockfile v6 should not be corrupted on repeat install (#5905)

* fix: lockfile v6 should not be corrupted on repeat install

* fix: don't add empty specifiers to lockfile v6

* fix: lockfile v6 should be saved to node_modules/.pnpm/lock.yaml

* fix: frozen lockfile with lockfile v6
This commit is contained in:
Zoltan Kochan
2023-01-10 11:41:17 +02:00
committed by GitHub
parent bcbcc47530
commit 0f6e95872a
5 changed files with 18 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/dependency-path": patch
"pnpm": patch
---
The new lockfile format should not be broken on repeat install.

View File

@@ -275,7 +275,10 @@ export async function writeLockfiles (
prefix: opts.wantedLockfileDir,
})
const currentYamlDoc = yamlStringify(opts.currentLockfile, normalizeOpts)
const currentLockfileToStringify = (Boolean(opts.useInlineSpecifiersFormat) || opts.wantedLockfile.lockfileVersion.toString().startsWith('6.'))
? convertToInlineSpecifiersFormat(opts.currentLockfile) as unknown as Lockfile
: opts.currentLockfile
const currentYamlDoc = yamlStringify(currentLockfileToStringify, normalizeOpts)
await Promise.all([
writeFileAtomic(wantedLockfilePath, yamlDoc),

View File

@@ -30,7 +30,7 @@ export function tryGetPackageId (registries: Registries, relDepPath: string) {
if (relDepPath[0] !== '/') {
return null
}
const sepIndex = relDepPath.indexOf('(', relDepPath.lastIndexOf('/'))
const sepIndex = relDepPath.indexOf('(')
if (sepIndex !== -1) {
return resolve(registries, relDepPath.slice(0, sepIndex))
}

View File

@@ -165,5 +165,5 @@ test('depPathToFilename()', () => {
test('tryGetPackageId', () => {
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0_@types+babel__core@7.1.14')).toEqual('registry.npmjs.org/foo/1.0.0')
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0(@types+babel__core@7.1.14)')).toEqual('registry.npmjs.org/foo/1.0.0')
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/foo/1.0.0')
})

View File

@@ -310,7 +310,10 @@ export async function mutateModules (
opts.preferFrozenLockfile &&
(!opts.pruneLockfileImporters || Object.keys(ctx.wantedLockfile.importers).length === Object.keys(ctx.projects).length) &&
ctx.existsWantedLockfile &&
ctx.wantedLockfile.lockfileVersion === LOCKFILE_VERSION &&
(
ctx.wantedLockfile.lockfileVersion === LOCKFILE_VERSION ||
ctx.wantedLockfile.lockfileVersion === LOCKFILE_VERSION_V6
) &&
await allProjectsAreUpToDate(Object.values(ctx.projects), {
autoInstallPeers: opts.autoInstallPeers,
linkWorkspacePackages: opts.linkWorkspacePackagesDepth >= 0,
@@ -360,7 +363,7 @@ export async function mutateModules (
wantedLockfile: ctx.wantedLockfile,
wantedLockfileDir: ctx.lockfileDir,
forceSharedFormat: opts.forceSharedLockfile,
useInlineSpecifiersFormat: opts.useInlineSpecifiersLockfileFormat,
useInlineSpecifiersFormat: opts.useInlineSpecifiersLockfileFormat || opts.useLockfileV6,
useGitBranchLockfile: opts.useGitBranchLockfile,
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
})
@@ -886,7 +889,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
const depsStateCache: DepsStateCache = {}
const lockfileOpts = {
forceSharedFormat: opts.forceSharedLockfile,
useInlineSpecifiersFormat: opts.useInlineSpecifiersLockfileFormat,
useInlineSpecifiersFormat: opts.useInlineSpecifiersLockfileFormat || opts.useLockfileV6,
useGitBranchLockfile: opts.useGitBranchLockfile,
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
}