@@ -11,19 +11,22 @@ import { VersionMismatchFinderEntity } from './VersionMismatchFinderEntity';
1111import { VersionMismatchFinderProject } from './VersionMismatchFinderProject' ;
1212import { VersionMismatchFinderCommonVersions } from './VersionMismatchFinderCommonVersions' ;
1313
14- export interface IVersionMismatchFinderRushCheckOptions {
15- variant ?:string | undefined ;
16- printAsJson ?:boolean | undefined ;
17- }
14+ const TRUNCATE_AFTER_PACKAGE_NAME_COUNT :number = 5 ;
1815
19- export interface IVersionMismatchFinderEnsureConsistentVersionsOptions {
16+ export interface IVersionMismatchFinderOptions {
2017variant ?:string | undefined ;
2118}
2219
23- export interface IVersionMismatchFinderGetMismatchesOptions {
24- variant ?:string | undefined ;
20+ export interface IVersionMismatchFinderRushCheckOptions extends IVersionMismatchFinderOptions {
21+ printAsJson ?:boolean | undefined ;
22+ truncateLongPackageNameLists ?:boolean | undefined ;
2523}
2624
25+ export interface IVersionMismatchFinderEnsureConsistentVersionsOptions
26+ extends IVersionMismatchFinderOptions { }
27+
28+ export interface IVersionMismatchFinderGetMismatchesOptions extends IVersionMismatchFinderOptions { }
29+
2730export interface IMismatchDependency {
2831dependencyName :string ;
2932versions :IMismatchDependencyVersion [ ] ;
@@ -76,7 +79,8 @@ export class VersionMismatchFinder {
7679) :void {
7780VersionMismatchFinder . _checkForInconsistentVersions ( rushConfiguration , {
7881 ...options ,
79- isRushCheckCommand :false
82+ isRushCheckCommand :false ,
83+ truncateLongPackageNameLists :true
8084} ) ;
8185}
8286
@@ -86,18 +90,21 @@ export class VersionMismatchFinder {
8690 */
8791public static getMismatches (
8892rushConfiguration :RushConfiguration ,
89- options :IVersionMismatchFinderRushCheckOptions = { }
93+ options :IVersionMismatchFinderOptions = { }
9094) :VersionMismatchFinder {
9195const commonVersions :CommonVersionsConfiguration = rushConfiguration . getCommonVersions ( options . variant ) ;
9296
93- const projects :VersionMismatchFinderEntity [ ] = rushConfiguration . projects . map ( ( project ) => {
94- return new VersionMismatchFinderProject ( project ) ;
95- } ) ;
97+ const projects :VersionMismatchFinderEntity [ ] = [ ] ;
9698
9799// Create an object for the purposes of reporting conflicts with preferredVersions
98100// or xstitchPreferredVersions from common-versions.json
101+ // Make sure this one is first so it doesn't get truncated when a long list is printed
99102projects . push ( new VersionMismatchFinderCommonVersions ( commonVersions ) ) ;
100103
104+ for ( const project of rushConfiguration . projects ) {
105+ projects . push ( new VersionMismatchFinderProject ( project ) ) ;
106+ }
107+
101108return new VersionMismatchFinder ( projects , commonVersions . allowedAlternativeVersions ) ;
102109}
103110
@@ -107,6 +114,7 @@ export class VersionMismatchFinder {
107114isRushCheckCommand :boolean ;
108115variant ?:string | undefined ;
109116printAsJson ?:boolean | undefined ;
117+ truncateLongPackageNameLists ?:boolean | undefined ;
110118}
111119) :void {
112120if ( rushConfiguration . ensureConsistentVersions || options . isRushCheckCommand ) {
@@ -118,10 +126,17 @@ export class VersionMismatchFinder {
118126if ( options . printAsJson ) {
119127mismatchFinder . printAsJson ( ) ;
120128} else {
121- mismatchFinder . print ( ) ;
129+ mismatchFinder . print ( options . truncateLongPackageNameLists ) ;
122130
123131if ( mismatchFinder . numberOfMismatches > 0 ) {
124132console . log ( colors . red ( `Found${ mismatchFinder . numberOfMismatches } mis-matching dependencies!` ) ) ;
133+ if ( ! options . isRushCheckCommand && options . truncateLongPackageNameLists ) {
134+ // There isn't a --verbose flag in `rush install`/`rush update`, so a long list will always be truncated.
135+ console . log (
136+ 'For more detailed reporting about these version mismatches, use the "rush check --verbose" command.'
137+ ) ;
138+ }
139+
125140throw new AlreadyReportedError ( ) ;
126141} else {
127142if ( options . isRushCheckCommand ) {
@@ -188,15 +203,34 @@ export class VersionMismatchFinder {
188203console . log ( JSON . stringify ( output , undefined , 2 ) ) ;
189204}
190205
191- public print ( ) :void {
206+ public print ( truncateLongPackageNameLists : boolean = false ) :void {
192207// Iterate over the list. For any dependency with mismatching versions, print the projects
193208this . getMismatches ( ) . forEach ( ( dependency :string ) => {
194209console . log ( colors . yellow ( dependency ) ) ;
195210this . getVersionsOfMismatch ( dependency ) ! . forEach ( ( version :string ) => {
196211console . log ( `${ version } ` ) ;
197- this . getConsumersOfMismatch ( dependency , version ) ! . forEach ( ( project :VersionMismatchFinderEntity ) => {
198- console . log ( ` -${ project . friendlyName } ` ) ;
199- } ) ;
212+ const consumersOfMismatch :VersionMismatchFinderEntity [ ] = this . getConsumersOfMismatch (
213+ dependency ,
214+ version
215+ ) ! ;
216+
217+ let numberToPrint :number = truncateLongPackageNameLists
218+ ?TRUNCATE_AFTER_PACKAGE_NAME_COUNT
219+ :consumersOfMismatch . length ;
220+ let numberRemaining :number = consumersOfMismatch . length ;
221+ for ( const { friendlyName} of consumersOfMismatch ) {
222+ if ( numberToPrint -- === 0 ) {
223+ break ;
224+ }
225+
226+ numberRemaining -- ;
227+
228+ console . log ( ` -${ friendlyName } ` ) ;
229+ }
230+
231+ if ( numberRemaining > 0 ) {
232+ console . log ( ` (and${ numberRemaining } others)` ) ;
233+ }
200234} ) ;
201235console . log ( ) ;
202236} ) ;