Skip to content

Commit 0d4c023

Browse files
authored
feat(install): add package info to json output (#8234)
This was removed in npm 7 and never got re-added. In order for this not to be a breaking change the info was added to new fields, since the old fields are already being used to return counts. This differs slightly from the npm 6 output, as "changed" now has a "from" and "to" field instead of a tacked on "previousVersion" field. Closes: #6558
1 parent c561a33 commit 0d4c023

File tree

3 files changed

+2426
-208
lines changed

3 files changed

+2426
-208
lines changed

lib/utils/reify-output.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ const reifyOutput = (npm, arb) => {
3333
}
3434

3535
const summary = {
36+
add: [],
3637
added: 0,
37-
removed: 0,
38-
changed: 0,
38+
// audit gets added later
3939
audited: auditReport && !auditReport.error ? actualTree.inventory.size : 0,
40+
change: [],
41+
changed: 0,
4042
funding: 0,
43+
remove: [],
44+
removed: 0,
4145
}
4246

4347
if (diff) {
@@ -53,18 +57,42 @@ const reifyOutput = (npm, arb) => {
5357
output.standard(`${chalk.blue('remove')} ${d.actual.name} ${d.actual.package.version}`)
5458
}
5559
summary.removed++
60+
summary.remove.push({
61+
name: d.actual.name,
62+
version: d.actual.package.version,
63+
path: d.actual.path,
64+
})
5665
break
5766
case 'ADD':
5867
if (showDiff) {
5968
output.standard(`${chalk.green('add')} ${d.ideal.name} ${d.ideal.package.version}`)
6069
}
61-
actualTree.inventory.has(d.ideal) && summary.added++
70+
if (actualTree.inventory.has(d.ideal)) {
71+
summary.added++
72+
summary.add.push({
73+
name: d.ideal.name,
74+
version: d.ideal.package.version,
75+
path: d.ideal.path,
76+
})
77+
}
6278
break
6379
case 'CHANGE':
6480
if (showDiff) {
6581
output.standard(`${chalk.cyan('change')} ${d.actual.name} ${d.actual.package.version} => ${d.ideal.package.version}`)
6682
}
6783
summary.changed++
84+
summary.change.push({
85+
from: {
86+
name: d.actual.name,
87+
version: d.actual.package.version,
88+
path: d.actual.path,
89+
},
90+
to: {
91+
name: d.ideal.name,
92+
version: d.ideal.package.version,
93+
path: d.ideal.path,
94+
},
95+
})
6896
break
6997
default:
7098
return

0 commit comments

Comments
 (0)