The TypeScript CLI accepts `--stream`, `--aggregate-output`, `--use-stderr`, `--reporter-hide-prefix`, `--ignore-workspace`, and `--workspace-packages`; pacquet rejected all six. Section 2 of pnpm/pnpm#14101. `--stream` is the substantial one. A recursive `run` inherited the terminal for every project, so pacquet had no way to attribute a line to the project that wrote it, and `--parallel` — which expands to `--stream` in pnpm's `run` shorthand table — produced unreadable interleaved output. `RunScript` grows a `ScriptOutput`: `Inherit` keeps the old path, `Streamed` pipes the child and republishes each line as a `pnpm:lifecycle` event through the new `StreamedScript`, which also absorbs the line pumps `run_lifecycle_hook` already had. The reporter gains `streamLifecycleOutput`, so the lifecycle stream renders append-only while the rest of the frame still redraws in place — the same split pnpm's reporter makes. `--aggregate-output` buffers a script's events until it exits and then renders the run as one block, formatting at flush time so the prefix color wheel advances in print order. `--reporter-hide-prefix` drops the prefix from the script's own output lines only, leaving the `$ <script>` echo and the `Done` / `Failed` line labelled. It is a `run` / `exec` option, so it is scope-validated and hidden like the other command-scoped globals; a recursive `exec` reads its explicit `false` as the signal to start prefixing, matching pnpm's `reporterHidePrefix === false` gate. `--ignore-workspace` stops the workspace search in `Config::current`, so `pnpm-workspace.yaml` contributes neither settings nor sibling projects and a blocked dependency build is not scaffolded into its `allowBuilds`. `--workspace-packages` is resolved into `Config::workspace_package_patterns` alongside the manifest's own `packages`, which `discover_workspace_projects` now takes from the config rather than re-reading the manifest at every call site. The five boolean settings also become readable from `pnpm-workspace.yaml`, the global `config.yaml`, and `PNPM_CONFIG_*`. This is pacquet-only: the TypeScript CLI already has all six.
199 lines
5.1 KiB
TypeScript
199 lines
5.1 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { afterEach, expect, jest, test } from '@jest/globals'
|
|
import { preparePackages } from '@pnpm/prepare'
|
|
import { writeYamlFile } from 'write-yaml-file'
|
|
|
|
import { DEFAULT_OPTS } from './utils/index.js'
|
|
|
|
const debug = jest.fn()
|
|
jest.unstable_mockModule('@pnpm/logger', () => {
|
|
return {
|
|
logger: () => ({ debug }),
|
|
globalInfo: jest.fn(),
|
|
globalWarn: jest.fn(),
|
|
streamParser: jest.fn(),
|
|
}
|
|
})
|
|
|
|
const { filterProjectsBySelectorObjectsFromDir } = await import('@pnpm/workspace.projects-filter')
|
|
const { exec } = await import('@pnpm/exec.commands')
|
|
|
|
afterEach(() => {
|
|
jest.mocked(debug).mockClear()
|
|
})
|
|
|
|
test('pnpm exec --recursive --no-reporter-hide-prefix prints prefixes', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
reporterHidePrefix: false,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
for (const name of ['foo', 'bar']) {
|
|
const loggerOpts = {
|
|
wd: path.resolve('packages', name),
|
|
depPath: name,
|
|
stage: '(exec)',
|
|
}
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: 'hello from stdout',
|
|
stdio: 'stdout',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: 'hello from stderr',
|
|
stdio: 'stderr',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: `name is ${name}`,
|
|
stdio: 'stdout',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
optional: false,
|
|
exitCode: 0,
|
|
})
|
|
}
|
|
})
|
|
|
|
test('pnpm exec --recursive --reporter-hide-prefix does not print prefixes', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
reporterHidePrefix: true,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
expect(debug).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('pnpm exec --recursive does not print prefixes by default', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
expect(debug).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('pnpm exec --recursive --no-reporter-hide-prefix reassembles output split across chunks and drops the CR of a CRLF', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
|
|
// Far past the pipe's chunk size, so both a line and a multi-byte
|
|
// character are guaranteed to straddle a chunk boundary.
|
|
const wide = '€'.repeat(200_000)
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
process.stdout.write(${JSON.stringify(wide)} + '\\r\\n' + 'tail\\n')
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
reporterHidePrefix: false,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
const lines = jest.mocked(debug).mock.calls
|
|
.map(([log]) => (log as { line?: string }).line)
|
|
.filter((line) => line != null)
|
|
expect(lines).toStrictEqual([wide, 'tail'])
|
|
})
|