@@ -42,21 +42,51 @@ const reifyOutput = (npm, arb) => {
42
42
}
43
43
44
44
if ( diff ) {
45
+ let diffTable
45
46
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
+ } )
47
71
}
48
72
49
73
depth ( {
50
74
tree : diff ,
51
75
visit : d => {
52
76
switch ( d . action ) {
53
77
case 'REMOVE' :
78
+ diffTable ?. push ( [ 'remove' , d . actual . name , d . actual . package . version ] )
54
79
summary . removed ++
55
80
break
56
81
case 'ADD' :
82
+ diffTable ?. push ( [ 'add' , d . ideal . name , d . ideal . package . version ] )
57
83
actualTree . inventory . has ( d . ideal ) && summary . added ++
58
84
break
59
85
case 'CHANGE' :
86
+ diffTable ?. push ( [ 'change' ,
87
+ d . actual . name ,
88
+ d . actual . package . version + ' -> ' + d . ideal . package . version ,
89
+ ] )
60
90
summary . changed ++
61
91
break
62
92
default :
@@ -67,6 +97,10 @@ const reifyOutput = (npm, arb) => {
67
97
} ,
68
98
getChildren : d => d . children ,
69
99
} )
100
+
101
+ if ( diffTable ) {
102
+ npm . output ( '\n' + diffTable . toString ( ) )
103
+ }
70
104
}
71
105
72
106
if ( npm . flatOptions . fund ) {
@@ -103,56 +137,6 @@ const printAuditReport = (npm, report) => {
103
137
npm . output ( `\n${ res . report } ` )
104
138
}
105
139
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
-
156
140
const getAuditReport = ( npm , report ) => {
157
141
if ( ! report ) {
158
142
return
0 commit comments