fix: save the lockfile in the new format even if it is up-to-date (#7984)

This commit is contained in:
Zoltan Kochan
2024-04-21 23:01:54 +02:00
committed by GitHub
parent 2cbf7b767b
commit 6b6ca69e1f
3 changed files with 12 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/core": patch
"pnpm": patch
"@pnpm/lockfile-file": patch
---
The lockfile should be saved in the new format even if it is up-to-date.

View File

@@ -19,6 +19,7 @@ import _mapValues from 'ramda/src/map'
import omit from 'ramda/src/omit'
import pickBy from 'ramda/src/pickBy'
import pick from 'ramda/src/pick'
import { LOCKFILE_VERSION } from '@pnpm/constants'
export interface NormalizeLockfileOpts {
forceSharedFormat: boolean
@@ -57,7 +58,7 @@ export function convertToLockfileFile (lockfile: Lockfile, opts: NormalizeLockfi
...lockfile,
snapshots,
packages,
lockfileVersion: lockfile.lockfileVersion.toString(),
lockfileVersion: LOCKFILE_VERSION,
importers: mapValues(lockfile.importers, convertProjectSnapshotToInlineSpecifiersFormat),
}
return normalizeLockfile(newLockfile, opts)

View File

@@ -351,9 +351,10 @@ export async function mutateModules (
throw new LockfileConfigMismatchError(outdatedLockfileSettingName!)
}
}
const upToDateLockfileMajorVersion = ctx.wantedLockfile.lockfileVersion.toString().startsWith(`${LOCKFILE_MAJOR_VERSION}.`)
let needsFullResolution = outdatedLockfileSettings ||
opts.fixLockfile ||
!ctx.wantedLockfile.lockfileVersion.toString().startsWith(`${LOCKFILE_MAJOR_VERSION}.`) && ctx.wantedLockfile.lockfileVersion !== LOCKFILE_VERSION_V6 ||
!upToDateLockfileMajorVersion && ctx.wantedLockfile.lockfileVersion !== LOCKFILE_VERSION_V6 ||
opts.forceFullResolution
if (needsFullResolution) {
ctx.wantedLockfile.settings = {
@@ -470,7 +471,7 @@ Note that in CI environments, this setting is enabled by default.`,
wantedLockfile: maybeOpts.ignorePackageManifest ? undefined : ctx.wantedLockfile,
useLockfile: opts.useLockfile && ctx.wantedLockfileIsModified,
})
if (opts.useLockfile && opts.saveLockfile && opts.mergeGitBranchLockfiles) {
if (opts.useLockfile && opts.saveLockfile && opts.mergeGitBranchLockfiles || !upToDateLockfileMajorVersion) {
await writeLockfiles({
currentLockfile: ctx.currentLockfile,
currentLockfileDir: ctx.virtualStoreDir,