Skip to content

Commit

Permalink
fix: print correctly aggregate output when mixing stages (#7557)
Browse files Browse the repository at this point in the history
close #7556
  • Loading branch information
yjp20 authored and zkochan committed Jan 25, 2024
1 parent 0c38332 commit f12884d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/nice-hairs-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---

`--aggregate-output` should work on scripts executed from the same project [#7556](https://github.com/pnpm/pnpm/issues/7556).
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ function cutLine (line: string, maxLength: number) {

function aggregateOutput (source: Rx.Observable<LifecycleLog>) {
return source.pipe(
groupBy(data => data.depPath),
// The '\0' is a null character which delimits these strings. This works since JS doesn't use
// null-terminated strings.
groupBy((data) => `${data.depPath}\0${data.stage}`),
mergeMap(group => {
return group.pipe(
buffer(
Expand Down
65 changes: 65 additions & 0 deletions cli/default-reporter/test/reportingLifecycleScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,71 @@ ${chalk.cyan('packages/foo')} ${POSTINSTALL}: Done`)
})
})

test('groups lifecycle output when append-only and aggregate-output are used with mixed stages', async () => {
const output$ = toOutput$({
context: { argv: ['install'] },
reportingOptions: {
appendOnly: true,
aggregateOutput: true,
outputMaxWidth: 79,
},
streamParser: createStreamParser(),
})

const fooBuild = {
depPath: 'packages/foo',
stage: 'build',
wd: 'packages/foo',
}

const fooLint = {
depPath: 'packages/foo',
stage: 'lint',
wd: 'packages/foo',
}

const barPostinstall = {
depPath: 'packages/bar',
stage: 'postinstall',
wd: 'packages/bar',
}

const BUILD = hlValue('build')
const LINT = hlValue('lint')

lifecycleLogger.debug({ ...fooBuild, optional: false, script: 'node build' })
lifecycleLogger.debug({ ...fooBuild, line: 'foo build I', stdio: 'stdout' })
lifecycleLogger.debug({ ...fooLint, optional: false, script: 'node lint' })
lifecycleLogger.debug({ ...fooLint, line: 'foo lint I', stdio: 'stdout' })
lifecycleLogger.debug({ ...barPostinstall, optional: false, script: 'node bar' })
lifecycleLogger.debug({ ...barPostinstall, line: 'bar I', stdio: 'stdout' })
lifecycleLogger.debug({ ...fooLint, line: 'foo lint II', stdio: 'stdout' })
lifecycleLogger.debug({ ...fooLint, line: 'foo lint III', stdio: 'stdout' })
lifecycleLogger.debug({ ...fooBuild, line: 'foo build II', stdio: 'stdout' })
lifecycleLogger.debug({ ...fooBuild, exitCode: 1, optional: true })
lifecycleLogger.debug({ ...fooLint, exitCode: 0, optional: true })
lifecycleLogger.debug({ ...barPostinstall, exitCode: 0, optional: false })

await expect(
firstValueFrom(
output$.pipe(map<string, string>(normalizeNewline), take(12), toArray())
)
).resolves.toEqual([
`${chalk.cyan('packages/foo')} ${BUILD}$ node build`,
`${chalk.cyan('packages/foo')} ${BUILD}: foo build I`,
`${chalk.cyan('packages/foo')} ${BUILD}: foo build II`,
`${chalk.cyan('packages/foo')} ${BUILD}: Failed`,
`${chalk.cyan('packages/foo')} ${LINT}$ node lint`,
`${chalk.cyan('packages/foo')} ${LINT}: foo lint I`,
`${chalk.cyan('packages/foo')} ${LINT}: foo lint II`,
`${chalk.cyan('packages/foo')} ${LINT}: foo lint III`,
`${chalk.cyan('packages/foo')} ${LINT}: Done`,
`${chalk.magenta('packages/bar')} ${POSTINSTALL}$ node bar`,
`${chalk.magenta('packages/bar')} ${POSTINSTALL}: bar I`,
`${chalk.magenta('packages/bar')} ${POSTINSTALL}: Done`,
])
})

test('groups lifecycle output when append-only and reporter-hide-prefix are used', async () => {
const output$ = toOutput$({
context: { argv: ['install'] },
Expand Down

0 comments on commit f12884d

Please sign in to comment.