Skip to content

Commit ad2d836

Browse files
committed
fix(config): preserve nullish declaration pruning
1 parent 2c134d6 commit ad2d836

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎pnpm11/installing/commands/src/resolvedPackageVersionsForPrune.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async function withEnvPackageVersions (
9292
if (rootDir == null) return resolved
9393
const envLockfile = await readEnvLockfile(rootDir)
9494
if (envLockfile != null) {
95-
retainConfigDependencies(envLockfile, (name) => Object.hasOwn(opts.configDependencies ?? {}, name))
95+
retainConfigDependencies(envLockfile, (name) =>
96+
Object.hasOwn(opts.configDependencies ?? {}, name) && opts.configDependencies?.[name] != null
97+
)
9698
pruneEnvLockfile(envLockfile)
9799
mergeResolvedPackageVersions(resolved, resolvedPackageVersionsFromLockfile({
98100
...envLockfile,

‎pnpm11/installing/commands/test/resolvedPackageVersionsForPrune.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os from 'node:os'
33
import path from 'node:path'
44

55
import { expect, jest, test } from '@jest/globals'
6-
import type { DepPath } from '@pnpm/types'
6+
import type { ConfigDependencies, DepPath } from '@pnpm/types'
77

88
const actualLockfileFs = await import('@pnpm/lockfile.fs')
99

@@ -122,6 +122,22 @@ test('ignores a malformed env document when exclusion pruning is disabled', asyn
122122
})
123123
})
124124

125+
test.each([null, undefined])('ignores nullish config dependency declarations (%s)', async (declaration) => {
126+
await withWorkspaceDir(async (workspaceDir) => {
127+
const env = actualLockfileFs.createEnvLockfile()
128+
env.importers['.'].configDependencies = { 'unused-plugin': { specifier: '1.0.0', version: '1.0.0' } }
129+
env.packages = { '[email protected]': { resolution: { integrity: 'AAA' } } }
130+
env.snapshots = { '[email protected]': {} }
131+
await actualLockfileFs.writeEnvLockfile(workspaceDir, env)
132+
133+
expect(await resolvedPackageVersionsForPrune({
134+
workspaceDir,
135+
minimumReleaseAgeExcludePrune: true,
136+
configDependencies: { 'unused-plugin': declaration } as unknown as ConfigDependencies,
137+
}, newLockfile)).toEqual(new Map([['foo', new Set(['1.0.0'])]]))
138+
})
139+
})
140+
125141
test('no versions when a project has no lockfile', async () => {
126142
await withWorkspaceDir(async (workspaceDir) => {
127143
const projectDirs = writeProjectLockfiles(workspaceDir, { a: '[email protected]' })

0 commit comments

Comments
 (0)