fix(run): output of scripts running concurrently in one project (#6780)

ref #6692
This commit is contained in:
Zoltan Kochan
2023-07-09 01:21:47 +03:00
committed by GitHub
parent 8e8ec9bf1f
commit a362a3ca16
3 changed files with 39 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-script-runners": patch
"pnpm": patch
---
Ensure consistent output for scripts executed concurrently, both within a single project and across multiple projects. Each script's output will now be printed in a separate section of the terminal, when running multiple scripts in a single project [using regex](https://pnpm.io/cli/run#running-multiple-scripts) [#6692](https://github.com/pnpm/pnpm/issues/6692).

View File

@@ -203,6 +203,7 @@ so you may run "pnpm -w run ${scriptName}"`,
hint: buildCommandNotFoundHint(scriptName, manifest.scripts),
})
}
const concurrency = opts.workspaceConcurrency ?? 4
const lifecycleOpts: RunLifecycleHookOptions = {
depPath: dir,
extraBinPaths: opts.extraBinPaths,
@@ -214,7 +215,7 @@ so you may run "pnpm -w run ${scriptName}"`,
scriptShell: opts.scriptShell,
silent: opts.reporter === 'silent',
shellEmulator: opts.shellEmulator,
stdio: 'inherit',
stdio: (specifiedScripts.length > 1 && concurrency > 1) ? 'pipe' : 'inherit',
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
@@ -227,7 +228,7 @@ so you may run "pnpm -w run ${scriptName}"`,
}
}
try {
const limitRun = pLimit(opts.workspaceConcurrency ?? 4)
const limitRun = pLimit(concurrency)
const _runScript = runScript.bind(null, { manifest, lifecycleOpts, runScriptOptions: { enablePrePostScripts: opts.enablePrePostScripts ?? false }, passedThruArgs })

View File

@@ -177,3 +177,33 @@ testOnPosix('pnpm run with preferSymlinkedExecutables and custom virtualStoreDir
expect(result.stdout.toString()).toContain(`${path.sep}foo${path.sep}bar${path.sep}node_modules`)
})
test('collapse output when running multiple scripts in one project', async () => {
prepare({
scripts: {
script1: 'echo 1',
script2: 'echo 2',
},
})
const result = execPnpmSync(['run', '/script[12]/'])
const output = result.stdout.toString()
expect(output).toContain('script1: 1')
expect(output).toContain('script2: 2')
})
test('do not collapse output when running multiple scripts in one project sequentially', async () => {
prepare({
scripts: {
script1: 'echo 1',
script2: 'echo 2',
},
})
const result = execPnpmSync(['--workspace-concurrency=1', 'run', '/script[12]/'])
const output = result.stdout.toString()
expect(output).not.toContain('script1: 1')
expect(output).not.toContain('script2: 2')
})