@@ -11,19 +11,22 @@ import { VersionMismatchFinderEntity } from './VersionMismatchFinderEntity';
11
11
import { VersionMismatchFinderProject } from './VersionMismatchFinderProject' ;
12
12
import { VersionMismatchFinderCommonVersions } from './VersionMismatchFinderCommonVersions' ;
13
13
14
- export interface IVersionMismatchFinderRushCheckOptions {
15
- variant ?: string | undefined ;
16
- printAsJson ?: boolean | undefined ;
17
- }
14
+ const TRUNCATE_AFTER_PACKAGE_NAME_COUNT : number = 5 ;
18
15
19
- export interface IVersionMismatchFinderEnsureConsistentVersionsOptions {
16
+ export interface IVersionMismatchFinderOptions {
20
17
variant ?: string | undefined ;
21
18
}
22
19
23
- export interface IVersionMismatchFinderGetMismatchesOptions {
24
- variant ?: string | undefined ;
20
+ export interface IVersionMismatchFinderRushCheckOptions extends IVersionMismatchFinderOptions {
21
+ printAsJson ?: boolean | undefined ;
22
+ truncateLongPackageNameLists ?: boolean | undefined ;
25
23
}
26
24
25
+ export interface IVersionMismatchFinderEnsureConsistentVersionsOptions
26
+ extends IVersionMismatchFinderOptions { }
27
+
28
+ export interface IVersionMismatchFinderGetMismatchesOptions extends IVersionMismatchFinderOptions { }
29
+
27
30
export interface IMismatchDependency {
28
31
dependencyName : string ;
29
32
versions : IMismatchDependencyVersion [ ] ;
@@ -76,7 +79,8 @@ export class VersionMismatchFinder {
76
79
) : void {
77
80
VersionMismatchFinder . _checkForInconsistentVersions ( rushConfiguration , {
78
81
...options ,
79
- isRushCheckCommand : false
82
+ isRushCheckCommand : false ,
83
+ truncateLongPackageNameLists : true
80
84
} ) ;
81
85
}
82
86
@@ -86,18 +90,21 @@ export class VersionMismatchFinder {
86
90
*/
87
91
public static getMismatches (
88
92
rushConfiguration : RushConfiguration ,
89
- options : IVersionMismatchFinderRushCheckOptions = { }
93
+ options : IVersionMismatchFinderOptions = { }
90
94
) : VersionMismatchFinder {
91
95
const commonVersions : CommonVersionsConfiguration = rushConfiguration . getCommonVersions ( options . variant ) ;
92
96
93
- const projects : VersionMismatchFinderEntity [ ] = rushConfiguration . projects . map ( ( project ) => {
94
- return new VersionMismatchFinderProject ( project ) ;
95
- } ) ;
97
+ const projects : VersionMismatchFinderEntity [ ] = [ ] ;
96
98
97
99
// Create an object for the purposes of reporting conflicts with preferredVersions
98
100
// 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
99
102
projects . push ( new VersionMismatchFinderCommonVersions ( commonVersions ) ) ;
100
103
104
+ for ( const project of rushConfiguration . projects ) {
105
+ projects . push ( new VersionMismatchFinderProject ( project ) ) ;
106
+ }
107
+
101
108
return new VersionMismatchFinder ( projects , commonVersions . allowedAlternativeVersions ) ;
102
109
}
103
110
@@ -107,6 +114,7 @@ export class VersionMismatchFinder {
107
114
isRushCheckCommand : boolean ;
108
115
variant ?: string | undefined ;
109
116
printAsJson ?: boolean | undefined ;
117
+ truncateLongPackageNameLists ?: boolean | undefined ;
110
118
}
111
119
) : void {
112
120
if ( rushConfiguration . ensureConsistentVersions || options . isRushCheckCommand ) {
@@ -118,10 +126,17 @@ export class VersionMismatchFinder {
118
126
if ( options . printAsJson ) {
119
127
mismatchFinder . printAsJson ( ) ;
120
128
} else {
121
- mismatchFinder . print ( ) ;
129
+ mismatchFinder . print ( options . truncateLongPackageNameLists ) ;
122
130
123
131
if ( mismatchFinder . numberOfMismatches > 0 ) {
124
132
console . 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
+
125
140
throw new AlreadyReportedError ( ) ;
126
141
} else {
127
142
if ( options . isRushCheckCommand ) {
@@ -188,15 +203,34 @@ export class VersionMismatchFinder {
188
203
console . log ( JSON . stringify ( output , undefined , 2 ) ) ;
189
204
}
190
205
191
- public print ( ) : void {
206
+ public print ( truncateLongPackageNameLists : boolean = false ) : void {
192
207
// Iterate over the list. For any dependency with mismatching versions, print the projects
193
208
this . getMismatches ( ) . forEach ( ( dependency : string ) => {
194
209
console . log ( colors . yellow ( dependency ) ) ;
195
210
this . getVersionsOfMismatch ( dependency ) ! . forEach ( ( version : string ) => {
196
211
console . 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
+ }
200
234
} ) ;
201
235
console . log ( ) ;
202
236
} ) ;
0 commit comments