@@ -38,9 +38,9 @@ export type OutputScanReportConfig = {
3838
3939export type ReportAlertRow = {
4040 alertType : string
41- introducedBy : string
4241 manifest : string
4342 packageName : string
43+ packageVersion : string
4444 policy : string
4545 url : string
4646}
@@ -57,9 +57,9 @@ export function flattenReportAlerts(report: ScanReport): ReportAlertRow[] {
5757 return {
5858 __proto__ : null ,
5959 alertType : type ,
60- introducedBy : keys [ 2 ] || '<unknown>' ,
6160 manifest : joinAnd ( manifest ) ,
6261 packageName : keys [ 1 ] || '<unknown>' ,
62+ packageVersion : keys [ 2 ] || '<unknown>' ,
6363 policy,
6464 url,
6565 }
@@ -76,19 +76,34 @@ export function formatAlertTable(rows: ReportAlertRow[]): string[] {
7676 'POLICY' ,
7777 'ALERT TYPE' ,
7878 'PACKAGE' ,
79- 'INTRODUCED BY ' ,
79+ 'VERSION ' ,
8080 'MANIFEST FILE' ,
8181 ]
8282 const cells = rows . map ( row => [
8383 row . policy ,
8484 row . alertType ,
8585 row . packageName ,
86- row . introducedBy ,
86+ row . packageVersion ,
8787 row . manifest ,
8888 ] )
89- const widths = headers . map ( ( header , i ) =>
90- Math . max ( header . length , ...cells . map ( cell => ( cell [ i ] ?? '' ) . length ) ) ,
91- )
89+ const widths = headers . map ( header => header . length )
90+ for (
91+ let rowIndex = 0 , { length : rowCount } = cells ;
92+ rowIndex < rowCount ;
93+ rowIndex += 1
94+ ) {
95+ const cell = cells [ rowIndex ] !
96+ for (
97+ let cellIndex = 0 , { length : cellLength } = cell ;
98+ cellIndex < cellLength ;
99+ cellIndex += 1
100+ ) {
101+ widths [ cellIndex ] = Math . max (
102+ widths [ cellIndex ] ?? 0 ,
103+ cell [ cellIndex ] ?. length ?? 0 ,
104+ )
105+ }
106+ }
92107 const toRow = ( values : string [ ] ) =>
93108 ` ${ values
94109 . map ( ( value , i ) => value . padEnd ( widths [ i ] ?? 0 ) )
@@ -116,6 +131,12 @@ export function formatLabelledPairs(pairs: Array<[string, string]>): string[] {
116131 )
117132}
118133
134+ export function isFullScanReport (
135+ report : ScanReport | { healthy : boolean } ,
136+ ) : report is ScanReport {
137+ return 'alerts' in report
138+ }
139+
119140export async function outputGeneratedScanReport (
120141 scanReport : Extract < ReturnType < typeof generateReport > , { ok : true } > ,
121142 config : Pick <
@@ -159,10 +180,10 @@ export async function outputGeneratedScanReport(
159180
160181 if ( short ) {
161182 logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
183+ } else if ( isFullScanReport ( scanReport . data ) ) {
184+ logger . log ( toPlainTextReport ( scanReport . data , includeLicensePolicy ) )
162185 } else {
163- logger . log (
164- toPlainTextReport ( scanReport . data as ScanReport , includeLicensePolicy ) ,
165- )
186+ logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
166187 }
167188}
168189
@@ -286,7 +307,7 @@ export function toMarkdownReport(
286307 __proto__ : null ,
287308 'Alert Type' : row . alertType ,
288309 Package : row . packageName ,
289- 'Introduced by' : row . introducedBy ,
310+ Version : row . packageVersion ,
290311 url : row . url ,
291312 'Manifest file' : row . manifest ,
292313 Policy : row . policy ,
334355 'Policy' ,
335356 'Alert Type' ,
336357 'Package' ,
337- 'Introduced by ' ,
358+ 'Version ' ,
338359 'url' ,
339360 'Manifest file' ,
340361 ] )
@@ -401,8 +422,10 @@ export function toPlainTextReport(
401422 lines . push (
402423 ` ${ rows . length } ${ pluralize ( 'alert' , { count : rows . length } ) } with a policy set to at least "${ reportLevel } ".` ,
403424 '' ,
404- ...formatAlertTable ( rows ) ,
405- '' ,
406425 )
426+ for ( const line of formatAlertTable ( rows ) ) {
427+ lines . push ( line )
428+ }
429+ lines . push ( '' )
407430 return lines . join ( '\n' )
408431}
0 commit comments