fix: summary reporting (#5031)

This commit is contained in:
Zoltan Kochan
2022-07-14 02:03:42 +03:00
committed by GitHub
parent 701f15819b
commit c71215041d
4 changed files with 47 additions and 17 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---
Do not print a package with unchanged version in the installation summary.

View File

@@ -11,7 +11,6 @@
"scripts": {
"start": "tsc --watch",
"lint": "eslint src/**/*.ts test/**/*.ts",
"pretty-test": "ts-node test | tap-diff",
"just-test-preview": "ts-node test --type-check",
"_test": "jest",
"test": "pnpm run compile && pnpm run _test",

View File

@@ -56,26 +56,33 @@ export default function (
scan((pkgsDiff, args) => {
const rootLog = args[0]
const deprecationSet = args[1] as Set<string>
let action: '-' | '+' | undefined
let log!: any // eslint-disable-line
if (rootLog['added']) {
pkgsDiff[rootLog['added'].dependencyType || 'nodeModulesOnly'][`+${rootLog['added'].name as string}`] = {
added: true,
deprecated: deprecationSet.has(rootLog['added'].id),
from: rootLog['added'].linkedFrom,
latest: rootLog['added'].latest,
name: rootLog['added'].name,
realName: rootLog['added'].realName,
version: rootLog['added'].version,
}
action = '+'
log = rootLog['added']
} else if (rootLog['removed']) {
action = '-'
log = rootLog['removed']
} else {
return pkgsDiff
}
if (rootLog['removed']) {
pkgsDiff[rootLog['removed'].dependencyType || 'nodeModulesOnly'][`-${rootLog['removed'].name as string}`] = {
added: false,
name: rootLog['removed'].name,
version: rootLog['removed'].version,
}
const depType = log.dependencyType || 'nodeModulesOnly'
const oppositeKey = `${action === '-' ? '+' : '-'}${log.name as string}`
const previous = pkgsDiff[depType][oppositeKey]
if (previous && previous.version === log.version) {
delete pkgsDiff[depType][oppositeKey]
return pkgsDiff
}
pkgsDiff[depType][`${action}${log.name as string}`] = {
added: action === '+',
deprecated: deprecationSet.has(log.id),
from: log.linkedFrom,
latest: log.latest,
name: log.name,
realName: log.realName,
version: log.version,
}
return pkgsDiff
}, {
dev: {},

View File

@@ -34,7 +34,7 @@ const h1 = chalk.cyanBright
const EOL = '\n'
test('prints summary (of current package only)', (done) => {
test.only('prints summary (of current package only)', (done) => {
const prefix = '/home/jane/project'
const output$ = toOutput$({
context: {
@@ -98,6 +98,24 @@ test('prints summary (of current package only)', (done) => {
version: '0.1.0',
},
})
rootLogger.debug({
prefix,
removed: {
dependencyType: 'prod',
name: 'no-changes',
version: '1.0.0',
},
})
rootLogger.debug({
added: {
dependencyType: 'prod',
id: 'registry.npmjs.org/no-changes/2.0.0',
name: 'no-changes',
realName: 'no-changes',
version: '1.0.0',
},
prefix,
})
rootLogger.debug({
added: {
dependencyType: 'dev',