@@ -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-
156140const getAuditReport = ( npm , report ) => {
157141 if ( ! report ) {
158142 return
0 commit comments