fix: silence verify-deps auto-install output (#11679)

* fix: silence verify-deps auto-install output

* fix: pass reporter to dependency status install

---------

Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
This commit is contained in:
Rayan Salhab
2026-05-18 02:57:46 +03:00
committed by GitHub
parent f46757d732
commit 247d70b40c
6 changed files with 54 additions and 6 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/exec.commands": patch
"@pnpm/exec.pnpm-cli-runner": patch
"pnpm": patch
---
Honor `--silent` when `verifyDepsBeforeRun: install` auto-installs dependencies before `pnpm run` or `pnpm exec`, preventing install output from being written to stdout [#11636](https://github.com/pnpm/pnpm/issues/11636).

View File

@@ -156,6 +156,7 @@ export type ExecOpts = Required<Pick<ConfigContext, 'selectedProjectsGraph'>> &
| 'nodeOptions'
| 'pnpmHomeDir'
| 'recursive'
| 'reporter'
| 'reporterHidePrefix'
| 'userAgent'
| 'verifyDepsBeforeRun'

View File

@@ -1,4 +1,4 @@
import type { VerifyDepsBeforeRun } from '@pnpm/config.reader'
import type { Config, VerifyDepsBeforeRun } from '@pnpm/config.reader'
import { checkDepsStatus, type CheckDepsStatusOptions, type WorkspaceStateSettings } from '@pnpm/deps.status'
import { PnpmError } from '@pnpm/error'
import { runPnpmCli } from '@pnpm/exec.pnpm-cli-runner'
@@ -7,6 +7,7 @@ import enquirer from 'enquirer'
export interface RunDepsStatusCheckOptions extends CheckDepsStatusOptions {
dir: string
reporter?: Config['reporter']
verifyDepsBeforeRun?: VerifyDepsBeforeRun
}
@@ -20,7 +21,7 @@ export async function runDepsStatusCheck (opts: RunDepsStatusCheckOptions): Prom
if (upToDate) return
const command = ['install', ...createInstallArgs(workspaceState?.settings)]
const install = runPnpmCli.bind(null, command, { cwd: opts.dir })
const install = runPnpmCli.bind(null, command, { cwd: opts.dir, reporter: opts.reporter })
switch (opts.verifyDepsBeforeRun) {
case 'install':

View File

@@ -2,17 +2,23 @@ import path from 'node:path'
import { sync as execSync } from 'execa'
export function runPnpmCli (command: string[], { cwd }: { cwd: string }): void {
export interface RunPnpmCliOptions {
cwd: string
reporter?: string
}
export function runPnpmCli (command: string[], { cwd, reporter }: RunPnpmCliOptions): void {
const execOpts = {
cwd,
stdio: 'inherit' as const,
}
const cliCommand = reporter ? [...command, `--reporter=${reporter}`] : command
const execFileName = path.basename(process.execPath).toLowerCase()
if (execFileName === 'pnpm' || execFileName === 'pnpm.exe') {
execSync(process.execPath, command, execOpts)
execSync(process.execPath, cliCommand, execOpts)
} else if (path.basename(process.argv[1]) === 'pnpm.mjs') {
execSync(process.execPath, [process.argv[1], ...command], execOpts)
execSync(process.execPath, [process.argv[1], ...cliCommand], execOpts)
} else {
execSync('pnpm', command, execOpts)
execSync('pnpm', cliCommand, execOpts)
}
}

View File

@@ -3,6 +3,7 @@ import path from 'node:path'
import { expect, test } from '@jest/globals'
import { prepare } from '@pnpm/prepare'
import { writeYamlFileSync } from 'write-yaml-file'
import { execPnpm, execPnpmSync } from './utils/index.js'
@@ -30,3 +31,17 @@ test("exec should respect the caller's current working directory", async () => {
expect(fs.readFileSync(cmdFilePath, 'utf8')).toBe(subdirPath)
})
test('silent exec does not print verifyDepsBeforeRun install output', async () => {
prepare({})
writeYamlFileSync('pnpm-workspace.yaml', {
verifyDepsBeforeRun: 'install',
})
const result = execPnpmSync(['--silent', 'exec', 'node', '-e', 'process.stdout.write("hi")'], {
expectSuccess: true,
omitEnvDefaults: ['pnpm_config_silent'],
})
expect(result.stdout.toString()).toBe('hi')
})

View File

@@ -140,6 +140,24 @@ test('silent run only prints the output of the child process', async () => {
expect(result.stdout.toString().trim()).toBe('hi')
})
test('silent run does not print verifyDepsBeforeRun install output', async () => {
prepare({
scripts: {
hi: 'echo hi',
},
})
writeYamlFileSync('pnpm-workspace.yaml', {
verifyDepsBeforeRun: 'install',
})
const result = execPnpmSync(['run', '--silent', 'hi'], {
expectSuccess: true,
omitEnvDefaults: ['pnpm_config_silent'],
})
expect(result.stdout.toString().trim()).toBe('hi')
})
testOnPosix('pnpm run with preferSymlinkedExecutables true', async () => {
prepare({
scripts: {