diff --git a/.changeset/sour-peas-prove.md b/.changeset/sour-peas-prove.md new file mode 100644 index 00000000000..166e15d824c --- /dev/null +++ b/.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 diff --git a/packages/plugin-commands-script-runners/src/runRecursive.ts b/packages/plugin-commands-script-runners/src/runRecursive.ts index d3718f8145b..6122028888f 100644 --- a/packages/plugin-commands-script-runners/src/runRecursive.ts +++ b/packages/plugin-commands-script-runners/src/runRecursive.ts @@ -19,6 +19,7 @@ export type RecursiveRunOpts = Pick & Required> & Partial> & { @@ -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) diff --git a/packages/pnpm/test/monorepo/index.ts b/packages/pnpm/test/monorepo/index.ts index 18d0f53517c..490fa2c5a3c 100644 --- a/packages/pnpm/test/monorepo/index.ts +++ b/packages/pnpm/test/monorepo/index.ts @@ -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` + ) +})