mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
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:
6
.changeset/great-beers-develop.md
Normal file
6
.changeset/great-beers-develop.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/dependency-path": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
The new lockfile format should not be broken on repeat install.
|
||||
@@ -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),
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user