Skip to content

Commit

Permalink
fix(plugin-commands-script-runner): run --stream should prefix with d…
Browse files Browse the repository at this point in the history
…ir name (#4703)

close #4702
  • Loading branch information
kenrick95 committed May 10, 2022
1 parent 61d102a commit 325ed5c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/sour-peas-prove.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-script-runners": patch
"pnpm": patch
---

fix(plugin-commands-script-runner): run --stream should prefix with dir name
13 changes: 7 additions & 6 deletions packages/plugin-commands-script-runners/src/runRecursive.ts
Expand Up @@ -19,6 +19,7 @@ export type RecursiveRunOpts = Pick<Config,
| 'scriptsPrependNodePath'
| 'scriptShell'
| 'shellEmulator'
| 'stream'
> & Required<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>> &
Partial<Pick<Config, 'extraBinPaths' | 'bail' | 'reverse' | 'sort' | 'workspaceConcurrency'>> &
{
Expand Down Expand Up @@ -46,12 +47,12 @@ export default async (
} as RecursiveSummary

const limitRun = pLimit(opts.workspaceConcurrency ?? 4)
const stdio = (
opts.workspaceConcurrency === 1 ||
packageChunks.length === 1 && packageChunks[0].length === 1
)
? 'inherit'
: 'pipe'
const stdio =
!opts.stream &&
(opts.workspaceConcurrency === 1 ||
(packageChunks.length === 1 && packageChunks[0].length === 1))
? 'inherit'
: 'pipe'
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir)

Expand Down
81 changes: 81 additions & 0 deletions packages/pnpm/test/monorepo/index.ts
Expand Up @@ -1559,3 +1559,84 @@ test('directory filtering', async () => {
expect(output).toContain('project-2')
}
})

test('run --stream should prefix with dir name', async () => {
preparePackages([
{
location: '.',
package: {
name: 'root',
version: '0.0.0',
private: true,
},
},
{
location: 'packages/alfa',
package: {
name: 'alfa',
version: '1.0.0',
scripts: {
test: "node -e \"console.log('OK')\"",
},
},
},
{
location: 'packages/beta',
package: {
name: 'beta',
version: '1.0.0',
scripts: {
test: "node -e \"console.log('OK')\"",
},
},
},
])

process.chdir('..')
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })

const result = execPnpmSync([
'--stream',
'--filter',
'alfa',
'--filter',
'beta',
'run',
'test',
])
expect(
result.stdout
.toString()
.trim()
.split('\n')
.sort()
.join('\n')
).toBe(
`Scope: 2 of 3 workspace projects
packages/alfa test$ node -e "console.log('OK')"
packages/alfa test: Done
packages/alfa test: OK
packages/beta test$ node -e "console.log('OK')"
packages/beta test: Done
packages/beta test: OK`
)
const singleResult = execPnpmSync([
'--stream',
'--filter',
'alfa',
'run',
'test',
])
expect(
singleResult.stdout
.toString()
.trim()
.split('\n')
.sort()
.join('\n')
).toBe(
`packages/alfa test$ node -e "console.log('OK')"
packages/alfa test: Done
packages/alfa test: OK`
)
})

0 comments on commit 325ed5c

Please sign in to comment.