Skip to content

Commit

Permalink
fix: mergeGitBranchLockfiles when merged lockfile is up-to-date (#5233)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Aug 18, 2022
1 parent d7a61ae commit f4cc2d7
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-rivers-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/core": patch
---

fix mergeGitBranchLockfiles when merged lockfile is up-to-date
12 changes: 12 additions & 0 deletions packages/core/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
74 changes: 73 additions & 1 deletion packages/core/test/install/gitBranchLockfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
})

0 comments on commit f4cc2d7

Please sign in to comment.