fix(reporter): don't print empty sections in summary

This commit is contained in:
Zoltan Kochan
2023-04-17 19:04:14 +03:00
parent 8f7e99477b
commit 31ca5a218b
3 changed files with 23 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/default-reporter": patch
---
Don't print empty sections in the summary, when results are filtered.

View File

@@ -44,7 +44,7 @@ export function reportSummary (
const pkgsDiff$ = getPkgsDiff(log$, { prefix: opts.cwd })
const summaryLog$ = log$.summary.pipe(take(1))
const _printDiffs = printDiffs.bind(null, { prefix: opts.cwd, filterPkgsDiff: opts.filterPkgsDiff })
const _printDiffs = printDiffs.bind(null, { prefix: opts.cwd })
return Rx.combineLatest(
pkgsDiff$,
@@ -55,7 +55,12 @@ export function reportSummary (
map(([pkgsDiff]) => {
let msg = ''
for (const depType of ['prod', 'optional', 'peer', 'dev', 'nodeModulesOnly'] as const) {
const diffs: PackageDiff[] = Object.values(pkgsDiff[depType as keyof typeof pkgsDiff])
let diffs: PackageDiff[] = Object.values(pkgsDiff[depType as keyof typeof pkgsDiff])
if (opts.filterPkgsDiff) {
// This filtering is only used by Bit CLI currently.
// Related PR: https://github.com/teambit/bit/pull/7176
diffs = diffs.filter((pkgDiff) => opts.filterPkgsDiff!(pkgDiff))
}
if (diffs.length > 0) {
msg += EOL
if (opts.pnpmConfig?.global) {
@@ -85,15 +90,9 @@ export type FilterPkgsDiff = (pkgsDiff: PackageDiff) => boolean
function printDiffs (
opts: {
prefix: string
filterPkgsDiff?: FilterPkgsDiff
},
pkgsDiff: PackageDiff[]
) {
// This filtering is only used by Bit CLI currently.
// Related PR: https://github.com/teambit/bit/pull/7176
if (opts.filterPkgsDiff) {
pkgsDiff = pkgsDiff.filter((pkgDiff) => opts.filterPkgsDiff!(pkgDiff))
}
// Sorts by alphabet then by removed/added
// + ava 0.10.0
// - chalk 1.0.0

View File

@@ -265,6 +265,17 @@ test('prints summary without the filtered out entries', (done) => {
},
prefix,
})
rootLogger.debug({
added: {
dependencyType: 'dev',
id: 'registry.npmjs.org/qar/2.0.0',
latest: '1.0.0', // this won't be printed in summary because latest is less than current version
name: 'qar',
realName: 'qar',
version: '2.0.0',
},
prefix,
})
packageManifestLogger.debug({
prefix,
updated: {