fix(exec): skip deps auto-install without manifest (#12301)

This commit is contained in:
Scarab Systems
2026-06-10 05:46:23 -04:00
committed by GitHub
parent 46fd26afc9
commit 2c0b91d6b9
3 changed files with 83 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/exec.commands": patch
"pnpm": patch
---
Avoid running dependency-status auto-install when the dependency status is unavailable without a project manifest.

View File

@@ -18,7 +18,8 @@ export async function runDepsStatusCheck (opts: RunDepsStatusCheckOptions): Prom
opts.ignoredWorkspaceStateSettings = ignoredWorkspaceStateSettings
const { upToDate, issue, workspaceState } = await checkDepsStatus(opts)
if (upToDate) return
if (upToDate === true) return
if (upToDate === undefined && opts.allProjects == null && opts.rootProjectManifest == null) return
const command = ['install', ...createInstallArgs(workspaceState?.settings)]
const install = runPnpmCli.bind(null, command, { cwd: opts.dir, reporter: opts.reporter })

View File

@@ -0,0 +1,75 @@
import { beforeEach, expect, jest, test } from '@jest/globals'
import type { checkDepsStatus as checkDepsStatusFn } from '@pnpm/deps.status'
import type { runPnpmCli as runPnpmCliFn } from '@pnpm/exec.pnpm-cli-runner'
const checkDepsStatus = jest.fn<typeof checkDepsStatusFn>()
const runPnpmCli = jest.fn<typeof runPnpmCliFn>()
jest.unstable_mockModule('@pnpm/deps.status', () => ({
checkDepsStatus,
}))
jest.unstable_mockModule('@pnpm/exec.pnpm-cli-runner', () => ({
runPnpmCli,
}))
jest.unstable_mockModule('@pnpm/logger', () => ({
globalWarn: jest.fn(),
}))
jest.unstable_mockModule('@inquirer/prompts', () => ({
confirm: jest.fn(),
}))
const { runDepsStatusCheck } = await import('../src/runDepsStatusCheck.js')
beforeEach(() => {
checkDepsStatus.mockReset()
runPnpmCli.mockReset()
})
test('does not install when dependency status is unavailable without a project manifest', async () => {
checkDepsStatus.mockResolvedValue({
upToDate: undefined,
issue: 'No package manifest found. Skipping check.',
workspaceState: undefined,
})
await runDepsStatusCheck({
dir: process.cwd(),
excludeLinksFromLockfile: false,
linkWorkspacePackages: false,
preferWorkspacePackages: false,
pnpmfile: [],
rootProjectManifestDir: process.cwd(),
verifyDepsBeforeRun: 'install',
})
expect(runPnpmCli).not.toHaveBeenCalled()
})
test('installs when dependency status is unavailable for an unexpected reason', async () => {
checkDepsStatus.mockResolvedValue({
upToDate: undefined,
issue: 'Cannot verify dependency status',
workspaceState: undefined,
})
await runDepsStatusCheck({
dir: process.cwd(),
excludeLinksFromLockfile: false,
linkWorkspacePackages: false,
pnpmfile: [],
preferWorkspacePackages: false,
rootProjectManifest: {
name: 'root',
},
rootProjectManifestDir: process.cwd(),
verifyDepsBeforeRun: 'install',
})
expect(runPnpmCli).toHaveBeenCalledWith(['install'], {
cwd: process.cwd(),
reporter: undefined,
})
})