@@ -153,6 +153,7 @@ export function printSuggestedFixCommands(findings: Finding[], scanInput: ScanIn
153153 if ( ! plan ) return ;
154154 if ( plan . sections . length === 0 ) return ;
155155 const sharedDirectTableWidths = computeSharedDirectTableWidths ( plan . sections ) ;
156+ const sharedParentUpgradeTableWidths = computeSharedParentUpgradeTableWidths ( plan . sections ) ;
156157
157158 console . log ( "" ) ;
158159 console . log ( chalk . bold . yellow ( "🛠 Copy And Run These Fix Commands" ) ) ;
@@ -169,6 +170,8 @@ export function printSuggestedFixCommands(findings: Finding[], scanInput: ScanIn
169170 for ( const note of remainingNotes ) {
170171 console . log ( chalk . gray ( ` Note: ${ note } ` ) ) ;
171172 }
173+ } else if ( shouldRenderParentUpgradeTable ( section . targets ) ) {
174+ printParentUpgradeTargetsTable ( section . targets , sharedParentUpgradeTableWidths ) ;
172175 }
173176 console . log ( renderCommandCallout ( section . command ) ) ;
174177 }
@@ -662,6 +665,38 @@ function printDirectTargetsTable(
662665 console . log ( line ( "└" , "┴" , "┘" ) ) ;
663666}
664667
668+ function printParentUpgradeTargetsTable (
669+ targets : Array < {
670+ package : string ;
671+ currentVersion ?: string ;
672+ targetVersion : string ;
673+ kind : "direct" | "parent-upgrade" ;
674+ reason : string ;
675+ } > ,
676+ widthsOverride ?: number [ ] ,
677+ ) : void {
678+ const headers = [ "Package" , "Current" , "Recommended target" , "Context" ] ;
679+ const rows = targets . map ( target => [
680+ target . package ,
681+ target . currentVersion ?? "-" ,
682+ chalk . cyan ( target . targetVersion ) ,
683+ chalk . gray ( target . reason ) ,
684+ ] ) ;
685+ if ( rows . length === 0 ) return ;
686+
687+ const widths = widthsOverride ?? computeTableWidths ( headers , rows ) ;
688+ const line = ( left : string , mid : string , right : string ) =>
689+ left + widths . map ( w => "─" . repeat ( w + 2 ) ) . join ( mid ) + right ;
690+
691+ console . log ( line ( "┌" , "┬" , "┐" ) ) ;
692+ console . log ( renderRow ( headers , widths ) ) ;
693+ console . log ( line ( "├" , "┼" , "┤" ) ) ;
694+ for ( const row of rows ) {
695+ console . log ( renderRow ( row . map ( value => String ( value ) ) , widths ) ) ;
696+ }
697+ console . log ( line ( "└" , "┴" , "┘" ) ) ;
698+ }
699+
665700function computeTableWidths ( headers : string [ ] , rows : string [ ] [ ] ) : number [ ] {
666701 return headers . map ( ( header , index ) =>
667702 Math . min ( 40 , Math . max ( header . length , ...rows . map ( row => stripAnsi ( String ( row [ index ] ) ) . length ) ) ) ,
@@ -703,3 +738,40 @@ function computeSharedDirectTableWidths(
703738
704739 return computeTableWidths ( headers , rows ) ;
705740}
741+
742+ function shouldRenderParentUpgradeTable (
743+ targets : Array < { kind : "direct" | "parent-upgrade" } > ,
744+ ) : boolean {
745+ return targets . length > 0 && targets . every ( target => target . kind === "parent-upgrade" ) ;
746+ }
747+
748+ function computeSharedParentUpgradeTableWidths (
749+ sections : Array < {
750+ kind : "urgent" | "direct" | "direct-adjusted" | "parent-upgrade" ;
751+ targets : Array < {
752+ package : string ;
753+ currentVersion ?: string ;
754+ targetVersion : string ;
755+ kind : "direct" | "parent-upgrade" ;
756+ reason : string ;
757+ } > ;
758+ } > ,
759+ ) : number [ ] | undefined {
760+ const parentSections = sections . filter ( section => shouldRenderParentUpgradeTable ( section . targets ) ) ;
761+ if ( parentSections . length === 0 ) return undefined ;
762+
763+ const headers = [ "Package" , "Current" , "Recommended target" , "Context" ] ;
764+ const rows : string [ ] [ ] = [ ] ;
765+ for ( const section of parentSections ) {
766+ for ( const target of section . targets ) {
767+ rows . push ( [
768+ target . package ,
769+ target . currentVersion ?? "-" ,
770+ target . targetVersion ,
771+ target . reason ,
772+ ] ) ;
773+ }
774+ }
775+
776+ return computeTableWidths ( headers , rows ) ;
777+ }
0 commit comments