Skip to content

Commit

Permalink
fix(run): output of scripts running concurrently in one project (#6780)
Browse files Browse the repository at this point in the history
ref #6692
  • Loading branch information
zkochan committed Jul 8, 2023
1 parent 8e8ec9b commit a362a3c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/lemon-maps-clap.md
Original file line number Diff line number Diff line change
@@ -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).
5 changes: 3 additions & 2 deletions exec/plugin-commands-script-runners/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand All @@ -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 })

Expand Down
30 changes: 30 additions & 0 deletions pnpm/test/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit a362a3c

Please sign in to comment.