mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: mergeGitBranchLockfiles when merged lockfile is up-to-date (#5233)
* fix: mergeGitBranchLockfiles when merged lockfile is up-to-date * chore: test install with --merge-git-branch-lockfiles when merged lockfile is up to date * chore: changeset * chore: test add also frozenLockfile: true+ close #5212 Co-authored-by: Cheng Liu <liucheng.leo@bytedance> Co-authored-by: Cheng Liu <chengcyber@users.noreply.github.com>
This commit is contained in:
5
.changeset/tidy-rivers-marry.md
Normal file
5
.changeset/tidy-rivers-marry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/core": patch
|
||||
---
|
||||
|
||||
fix mergeGitBranchLockfiles when merged lockfile is up-to-date
|
||||
@@ -330,6 +330,18 @@ export async function mutateModules (
|
||||
pruneVirtualStore,
|
||||
wantedLockfile: maybeOpts.ignorePackageManifest ? undefined : ctx.wantedLockfile,
|
||||
})
|
||||
if (opts.useLockfile && opts.saveLockfile && opts.mergeGitBranchLockfiles) {
|
||||
await writeLockfiles({
|
||||
currentLockfile: ctx.currentLockfile,
|
||||
currentLockfileDir: ctx.virtualStoreDir,
|
||||
wantedLockfile: ctx.wantedLockfile,
|
||||
wantedLockfileDir: ctx.lockfileDir,
|
||||
forceSharedFormat: opts.forceSharedLockfile,
|
||||
useInlineSpecifiersFormat: opts.useInlineSpecifiersLockfileFormat,
|
||||
useGitBranchLockfile: opts.useGitBranchLockfile,
|
||||
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
|
||||
})
|
||||
}
|
||||
return projects
|
||||
} catch (error: any) { // eslint-disable-line
|
||||
if (
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from 'path'
|
||||
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
|
||||
import { install, mutateModules } from '@pnpm/core'
|
||||
import { testDefaults } from '../utils'
|
||||
import { WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import { ProjectManifest } from '@pnpm/types'
|
||||
import { getCurrentBranch } from '@pnpm/git-utils'
|
||||
import writeYamlFile from 'write-yaml-file'
|
||||
@@ -144,3 +144,75 @@ test('install with --merge-git-branch-lockfiles', async () => {
|
||||
expect(fs.existsSync(otherLockfilePath)).toBe(false)
|
||||
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
||||
})
|
||||
|
||||
test('install with --merge-git-branch-lockfiles when merged lockfile is up to date', async () => {
|
||||
const project = prepareEmpty()
|
||||
|
||||
// @types/semver installed in the main branch
|
||||
await writeYamlFile(WANTED_LOCKFILE, {
|
||||
dependencies: {
|
||||
'@types/semver': '5.3.31',
|
||||
},
|
||||
lockfileVersion: LOCKFILE_VERSION,
|
||||
packages: {
|
||||
'/@types/semver/5.3.31': {
|
||||
resolution: {
|
||||
integrity: 'sha512-WBv5F9HrWTyG800cB9M3veCVkFahqXN7KA7c3VUCYZm/xhNzzIFiXiq+rZmj75j7GvWelN3YNrLX7FjtqBvhMw==',
|
||||
},
|
||||
},
|
||||
},
|
||||
specifiers: {
|
||||
'@types/semver': '5.3.31',
|
||||
},
|
||||
}, { lineWidth: 1000 })
|
||||
|
||||
const branchName: string = 'main-branch'
|
||||
getCurrentBranch['mockReturnValue'](branchName)
|
||||
|
||||
// is-positive installed in the other branch
|
||||
const otherLockfilePath: string = path.resolve('pnpm-lock.other.yaml')
|
||||
const otherLockfileContent = {
|
||||
dependencies: {
|
||||
'@types/semver': '5.3.31',
|
||||
'is-positive': '3.1.0',
|
||||
},
|
||||
lockfileVersion: LOCKFILE_VERSION,
|
||||
packages: {
|
||||
'/@types/semver/5.3.31': {
|
||||
resolution: {
|
||||
integrity: 'sha512-WBv5F9HrWTyG800cB9M3veCVkFahqXN7KA7c3VUCYZm/xhNzzIFiXiq+rZmj75j7GvWelN3YNrLX7FjtqBvhMw==',
|
||||
},
|
||||
},
|
||||
'/is-positive/3.1.0': {
|
||||
resolution: {
|
||||
integrity: 'sha512-8ND1j3y9/HP94TOvGzr69/FgbkX2ruOldhLEsTWwcJVfo4oRjwemJmJxt7RJkKYH8tz7vYBP9JcKQY8CLuJ90Q==',
|
||||
},
|
||||
},
|
||||
},
|
||||
specifiers: {
|
||||
'@types/semver': '5.3.31',
|
||||
'is-positive': '^3.1.0',
|
||||
},
|
||||
}
|
||||
await writeYamlFile(otherLockfilePath, otherLockfileContent, { lineWidth: 1000 })
|
||||
|
||||
// the other branch merged to the main branch
|
||||
const projectManifest: ProjectManifest = {
|
||||
dependencies: {
|
||||
'@types/semver': '5.3.31',
|
||||
'is-positive': '^3.1.0',
|
||||
},
|
||||
}
|
||||
const opts = await testDefaults({
|
||||
useGitBranchLockfile: true,
|
||||
mergeGitBranchLockfiles: true,
|
||||
frozenLockfile: true,
|
||||
})
|
||||
await install(projectManifest, opts)
|
||||
|
||||
expect(fs.existsSync(otherLockfilePath)).toBe(false)
|
||||
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
||||
|
||||
const wantedLockfileAfterMergeOther = await project.readLockfile()
|
||||
expect(wantedLockfileAfterMergeOther).toEqual(otherLockfileContent)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user