Repository navigation
fix(pnpm): restore the lockfile settings a dependency graph was resolved under #10784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zkochan
merged 6 commits into
teambit:master
from
zkochan:pnpm/restore-lockfile-settings
Oct 10, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca0c591
fix(pnpm): restore the lockfile settings a dependency graph was resol…
zkochan 36ad6f9
fix(pnpm): keep the lockfile's checksum and settings when a graph add…
zkochan 1f7671c
Merge branch 'master' into pnpm/restore-lockfile-settings
github-actions[bot] 0006f6d
Merge branch 'master' into pnpm/restore-lockfile-settings
zkochan 6a2ebfd
Merge branch 'master' into pnpm/restore-lockfile-settings
zkochan fab51ea
Merge branch 'master' into pnpm/restore-lockfile-settings
zkochan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,8 +223,9 @@ describe('convertLockfileToGraph simple case', () => { | |
| // The lockfile records no pnpmfileChecksum. Whether the graph then has the | ||
| // property set to undefined or not at all depends on how the class is | ||
| // compiled, so it is checked on its own. | ||
| const { pnpmfileChecksum, ...graphFields } = graph; | ||
| const { pnpmfileChecksum, lockfileSettings, ...graphFields } = graph; | ||
| expect(pnpmfileChecksum).to.equal(undefined); | ||
| expect(lockfileSettings).to.equal(undefined); | ||
| expect({ | ||
| ...graphFields, | ||
| packages: Object.fromEntries(graph.packages.entries()), | ||
|
|
@@ -1249,3 +1250,57 @@ describe('pnpmfileChecksum', () => { | |
| expect(lockfile).not.to.have.property('pnpmfileChecksum'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('lockfile settings', () => { | ||
| const componentDir = 'comps/comp1'; | ||
| const settings = { autoInstallPeers: true, dedupePeers: true, injectWorkspacePackages: true }; | ||
|
|
||
| function createLockfile(lockfileSettings?: BitLockfileFile['settings']): BitLockfileFile { | ||
| return { | ||
| lockfileVersion: '9.0', | ||
| ...(lockfileSettings ? { settings: lockfileSettings } : {}), | ||
| importers: { | ||
| [componentDir]: { | ||
| dependencies: { foo: { version: '1.0.0', specifier: '1.0.0' } }, | ||
| }, | ||
| }, | ||
| packages: { | ||
| '[email protected]': { resolution: { integrity: 'sha512-aaa' } }, | ||
| }, | ||
| snapshots: { | ||
| '[email protected]': {}, | ||
| }, | ||
| } as BitLockfileFile; | ||
| } | ||
|
|
||
| function graphToLockfile(graph: DependenciesGraph) { | ||
| return convertGraphToLockfile(graph, { | ||
| manifests: { | ||
| [path.resolve(componentDir)]: { dependencies: { foo: '1.0.0' } }, | ||
| }, | ||
| rootDir: process.cwd(), | ||
| resolve: () => ({ resolution: { integrity: '0000' } }) as any, | ||
| }); | ||
| } | ||
|
|
||
| it('should be kept from the lockfile to the graph and back', async () => { | ||
| const graph = convertLockfileToGraph(createLockfile(settings), { | ||
| componentRelativeDir: componentDir, | ||
| componentIdByPkgName: new Map(), | ||
| }); | ||
| expect(graph.lockfileSettings).to.eql(settings); | ||
|
|
||
| const lockfile = await graphToLockfile(DependenciesGraph.deserialize(graph.serialize())!); | ||
| expect(lockfile.settings).to.eql(settings); | ||
| }); | ||
|
|
||
| it('should stay unset for a graph saved without them', async () => { | ||
| const graph = convertLockfileToGraph(createLockfile(), { | ||
| componentRelativeDir: componentDir, | ||
| componentIdByPkgName: new Map(), | ||
| }); | ||
|
|
||
| const lockfile = await graphToLockfile(graph); | ||
| expect(lockfile).not.to.have.property('settings'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,16 +81,49 @@ describe('mergeGraphLockfileIntoExisting', () => { | |
| function lockfile(pnpmfileChecksum?: string) { | ||
| return { lockfileVersion: '9.0', importers: {}, ...(pnpmfileChecksum ? { pnpmfileChecksum } : {}) }; | ||
| } | ||
| /** A graph lockfile that adds a resolution to the merge. */ | ||
| function resolved<T extends object>(graphLockfile: T) { | ||
| return { ...graphLockfile, packages: { '[email protected]': { resolution: { integrity: 'sha512-a' } } } }; | ||
| } | ||
| const settings = { autoInstallPeers: true, dedupePeers: true }; | ||
|
|
||
| it('keeps the pnpmfileChecksum both lockfiles were resolved with', () => { | ||
| const merged = mergeGraphLockfileIntoExisting(lockfile('bit-1'), lockfile('bit-1')); | ||
| const merged = mergeGraphLockfileIntoExisting(lockfile('bit-1'), resolved(lockfile('bit-1'))); | ||
| expect(merged.pnpmfileChecksum).to.equal('bit-1'); | ||
| }); | ||
|
|
||
| it('drops a pnpmfileChecksum the lockfiles disagree on', () => { | ||
| expect(mergeGraphLockfileIntoExisting(lockfile('bit-1'), lockfile('bit-2'))).not.to.have.property( | ||
| expect(mergeGraphLockfileIntoExisting(lockfile('bit-1'), resolved(lockfile('bit-2')))).not.to.have.property( | ||
| 'pnpmfileChecksum' | ||
| ); | ||
| expect(mergeGraphLockfileIntoExisting(lockfile('bit-1'), resolved(lockfile()))).not.to.have.property( | ||
| 'pnpmfileChecksum' | ||
| ); | ||
| expect(mergeGraphLockfileIntoExisting(lockfile('bit-1'), lockfile())).not.to.have.property('pnpmfileChecksum'); | ||
| }); | ||
|
|
||
| it('keeps the settings both lockfiles were resolved under', () => { | ||
| const merged = mergeGraphLockfileIntoExisting( | ||
| { ...lockfile(), settings }, | ||
| resolved({ ...lockfile(), settings: { ...settings } }) | ||
| ); | ||
| expect(merged.settings).to.eql(settings); | ||
| }); | ||
|
|
||
| it('drops settings the lockfiles disagree on', () => { | ||
| expect( | ||
| mergeGraphLockfileIntoExisting( | ||
| { ...lockfile(), settings }, | ||
| resolved({ ...lockfile(), settings: { ...settings, dedupePeers: false } }) | ||
| ) | ||
| ).not.to.have.property('settings'); | ||
| expect(mergeGraphLockfileIntoExisting({ ...lockfile(), settings }, resolved(lockfile()))).not.to.have.property( | ||
| 'settings' | ||
| ); | ||
| }); | ||
|
|
||
| it('keeps the checksum and settings of the existing lockfile when the graph adds no resolutions', () => { | ||
| const merged = mergeGraphLockfileIntoExisting({ ...lockfile('bit-1'), settings }, lockfile()); | ||
| expect(merged.pnpmfileChecksum).to.equal('bit-1'); | ||
| expect(merged.settings).to.eql(settings); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,3 +185,53 @@ function rootEdge(neighbours: DependencyEdge['neighbours']): DependencyEdge { | |
| function edge(id: string, neighbours: DependencyEdge['neighbours'] = []): DependencyEdge { | ||
| return { id, neighbours }; | ||
| } | ||
|
|
||
| describe('DependenciesGraph lockfileSettings', () => { | ||
| const settings = { autoInstallPeers: true, dedupePeers: true, injectWorkspacePackages: true }; | ||
|
|
||
| it('survives serialize and deserialize', () => { | ||
| const graph = createGraph([rootEdge([])], []); | ||
| graph.lockfileSettings = settings; | ||
|
|
||
| expect(DependenciesGraph.deserialize(graph.serialize())?.lockfileSettings).to.eql(settings); | ||
| }); | ||
|
|
||
| it('is unset on a graph serialized before the field existed', () => { | ||
| const restored = DependenciesGraph.deserialize( | ||
| JSON.stringify({ schemaVersion: '2.0', packages: {}, edges: [rootEdge([])] }) | ||
| ); | ||
|
|
||
| expect(restored?.lockfileSettings).to.equal(undefined); | ||
| }); | ||
|
|
||
| it('is kept by merge when both graphs were resolved under the same settings', () => { | ||
| const base = createGraph([rootEdge([{ id: '[email protected]', name: 'foo', specifier: '1.0.0' }])], ['[email protected]']); | ||
| base.lockfileSettings = settings; | ||
| const incoming = createGraph([rootEdge([{ id: '[email protected]', name: 'bar', specifier: '1.0.0' }])], ['[email protected]']); | ||
| incoming.lockfileSettings = { ...settings }; | ||
|
|
||
| base.merge(incoming); | ||
|
|
||
| expect(base.lockfileSettings).to.eql(settings); | ||
| }); | ||
|
|
||
| it('is dropped by merge when the graphs were resolved under different settings', () => { | ||
| const base = createGraph([rootEdge([{ id: '[email protected]', name: 'foo', specifier: '1.0.0' }])], ['[email protected]']); | ||
| base.lockfileSettings = settings; | ||
| const incoming = createGraph([rootEdge([{ id: '[email protected]', name: 'bar', specifier: '1.0.0' }])], ['[email protected]']); | ||
| incoming.lockfileSettings = { ...settings, dedupePeers: false }; | ||
|
|
||
| base.merge(incoming); | ||
|
|
||
| expect(base.lockfileSettings).to.equal(undefined); | ||
| }); | ||
|
|
||
| it('is dropped by merge when only one graph has them', () => { | ||
| const base = createGraph([rootEdge([{ id: '[email protected]', name: 'foo', specifier: '1.0.0' }])], ['[email protected]']); | ||
| base.lockfileSettings = settings; | ||
|
|
||
| base.merge(createGraph([rootEdge([{ id: '[email protected]', name: 'bar', specifier: '1.0.0' }])], ['[email protected]'])); | ||
|
|
||
| expect(base.lockfileSettings).to.equal(undefined); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.