Skip to content

Commit ec06f77

Browse files
committed
fix: inline diff table code w/ summary code
1 parent ec77e81 commit ec06f77

File tree

2 files changed

+37
-53
lines changed

2 files changed

+37
-53
lines changed

lib/utils/reify-output.js

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,51 @@ const reifyOutput = (npm, arb) => {
4242
}
4343

4444
if (diff) {
45+
let diffTable
4546
if (npm.config.get('dry-run')) {
46-
printDiff(npm, diff)
47+
diffTable = new Table({
48+
chars: {
49+
top: '',
50+
'top-mid': '',
51+
'top-left': '',
52+
'top-right': '',
53+
bottom: '',
54+
'bottom-mid': '',
55+
'bottom-left': '',
56+
'bottom-right': '',
57+
left: '',
58+
'left-mid': '',
59+
mid: '',
60+
'mid-mid': '',
61+
right: '',
62+
'right-mid': '',
63+
middle: ' ',
64+
},
65+
style: {
66+
'padding-left': 0,
67+
'padding-right': 0,
68+
border: 0,
69+
},
70+
})
4771
}
4872

4973
depth({
5074
tree: diff,
5175
visit: d => {
5276
switch (d.action) {
5377
case 'REMOVE':
78+
diffTable?.push(['remove', d.actual.name, d.actual.package.version])
5479
summary.removed++
5580
break
5681
case 'ADD':
82+
diffTable?.push(['add', d.ideal.name, d.ideal.package.version])
5783
actualTree.inventory.has(d.ideal) && summary.added++
5884
break
5985
case 'CHANGE':
86+
diffTable?.push(['change',
87+
d.actual.name,
88+
d.actual.package.version + ' -> ' + d.ideal.package.version,
89+
])
6090
summary.changed++
6191
break
6292
default:
@@ -67,6 +97,10 @@ const reifyOutput = (npm, arb) => {
6797
},
6898
getChildren: d => d.children,
6999
})
100+
101+
if (diffTable) {
102+
npm.output('\n' + diffTable.toString())
103+
}
70104
}
71105

72106
if (npm.flatOptions.fund) {
@@ -103,56 +137,6 @@ const printAuditReport = (npm, report) => {
103137
npm.output(`\n${res.report}`)
104138
}
105139

106-
// print the diff tree of actions that would be taken
107-
const printDiff = (npm, diff) => {
108-
const table = new Table({
109-
chars: {
110-
top: '',
111-
'top-mid': '',
112-
'top-left': '',
113-
'top-right': '',
114-
bottom: '',
115-
'bottom-mid': '',
116-
'bottom-left': '',
117-
'bottom-right': '',
118-
left: '',
119-
'left-mid': '',
120-
mid: '',
121-
'mid-mid': '',
122-
right: '',
123-
'right-mid': '',
124-
middle: ' ',
125-
},
126-
style: {
127-
'padding-left': 0,
128-
'padding-right': 0,
129-
border: 0,
130-
},
131-
})
132-
133-
for (let i = 0; i < diff.children.length; ++i) {
134-
const child = diff.children[i]
135-
table[i] = [child.action.toLowerCase()]
136-
137-
switch (child.action) {
138-
case 'ADD':
139-
table[i].push(child.ideal.name, child.ideal.package.version)
140-
break
141-
case 'REMOVE':
142-
table[i].push(child.actual.name, child.actual.package.version)
143-
break
144-
case 'CHANGE':
145-
table[i].push(
146-
child.actual.name,
147-
child.actual.package.version + ' -> ' + child.ideal.package.version
148-
)
149-
break
150-
}
151-
}
152-
153-
npm.output('\n' + table.toString())
154-
}
155-
156140
const getAuditReport = (npm, report) => {
157141
if (!report) {
158142
return

tap-snapshots/test/lib/utils/reify-output.js.test.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,9 +1635,9 @@ exports[`test/lib/utils/reify-output.js TAP packages changed message > {"added"
16351635

16361636
exports[`test/lib/utils/reify-output.js TAP prints dedupe difference > diff table 1`] = `
16371637
1638-
add foo 1.0.0
1639-
remove bar 1.0.0
16401638
change bar 1.0.0 -> 2.1.0
1639+
remove bar 1.0.0
1640+
add foo 1.0.0
16411641
16421642
removed 1 package, and changed 1 package in {TIME}
16431643
`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy