8000 Merge pull request #3315 from iclanton/rush-check-summary · psy-repos-typescript/rushstack@9635919 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9635919

Browse files
authored
Merge pull request microsoft#3315 from iclanton/rush-check-summary
[rush] By default, truncate long lists of package names when running rush check.
2 parents 3d660bc + d9c3084 commit 9635919

File tree

4 files changed

+74
-19
lines changed

4 files changed

+74
-19
lines changed

apps/rush-lib/src/cli/actions/CheckAction.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Variants } from '../../api/Variants';
1212
export class CheckAction extends BaseRushAction {
1313
private _variant!: CommandLineStringParameter;
1414
private _jsonFlag!: CommandLineFlagParameter;
15+
private _verboseFlag!: CommandLineFlagParameter;
1516

1617
public constructor(parser: RushCommandLineParser) {
1718
super({
@@ -33,6 +34,12 @@ export class CheckAction extends BaseRushAction {
3334
parameterLongName: '--json',
3435
description: 'If this flag is specified, output will be in JSON format.'
3536
});
37+
this._verboseFlag = this.defineFlagParameter({
38+
parameterLongName: '--verbose',
39+
description:
40+
'If this flag is specified, long lists of package names will not be truncated. ' +
41+
`This has no effect if the ${this._jsonFlag.longName} flag is also specified.`
42+
});
3643
}
3744

3845
protected async runAsync(): Promise<void> {
@@ -49,7 +56,8 @@ export class CheckAction extends BaseRushAction {
4956

5057
VersionMismatchFinder.rushCheck(this.rushConfiguration, {
5158
variant: this._variant.value,
52-
printAsJson: this._jsonFlag.value
59+
printAsJson: this._jsonFlag.value,
60+
truncateLongPackageNameLists: !this._verboseFlag.value
5361
});
5462
}
5563
}

apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Optional arguments:
303303
`;
304304
305305
exports[`CommandLineHelp prints the help for each action: check 1`] = `
306-
"usage: rush check [-h] [--variant VARIANT] [--json]
306+
"usage: rush check [-h] [--variant VARIANT] [--json] [--verbose]
307307
308308
Checks each project's package.json files and ensures that all dependencies
309309
are of the same version throughout the repository.
@@ -314,6 +314,9 @@ Optional arguments:
314314
This parameter may alternatively be specified via the
315315
RUSH_VARIANT environment variable.
316316
--json If this flag is specified, output will be in JSON format.
317+
--verbose If this flag is specified, long lists of package names
318+
will not be truncated. This has no effect if the --json
319+
flag is also specified.
317320
"
318321
`;
319322

apps/rush-lib/src/logic/versionMismatch/VersionMismatchFinder.ts

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ import { VersionMismatchFinderEntity } from './VersionMismatchFinderEntity';
1111
import { VersionMismatchFinderProject } from './VersionMismatchFinderProject';
1212
import { 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 {
2017
variant?: 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+
2730
export interface IMismatchDependency {
2831
dependencyName: string;
2932
versions: IMismatchDependencyVersion[];
@@ -76,7 +79,8 @@ export class VersionMismatchFinder {
7679
): void {
7780
VersionMismatchFinder._checkForInconsistentVersions(rushConfiguration, {
7881
...options,
79-
isRushCheckCommand: false
82+
isRushCheckCommand: false,
83+
truncateLongPackageNameLists: true
8084
});
8185
}
8286

@@ -86,18 +90,21 @@ export class VersionMismatchFinder {
8690
*/
8791
public static getMismatches(
8892
rushConfiguration: RushConfiguration,
89-
options: IVersionMismatchFinderRushCheckOptions = {}
93+
options: IVersionMismatchFinderOptions = {}
9094
): VersionMismatchFinder {
9195
const 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
99102
projects.push(new VersionMismatchFinderCommonVersions(commonVersions));
100103

104+
for (const project of rushConfiguration.projects) {
105+
projects.push(new VersionMismatchFinderProject(project));
106+
}
107+
101108
return new VersionMismatchFinder(projects, commonVersions.allowedAlternativeVersions);
102109
}
103110

@@ -107,6 +114,7 @@ export class VersionMismatchFinder {
107114
isRushCheckCommand: boolean;
108115
variant?: string | undefined;
109116
printAsJson?: boolean | undefined;
117+
truncateLongPackageNameLists?: boolean | undefined;
110118
}
111119
): void {
112120
if (rushConfiguration.ensureConsistentVersions || options.isRushCheckCommand) {
@@ -118,10 +126,17 @@ export class VersionMismatchFinder {
118126
if (options.printAsJson) {
119127
mismatchFinder.printAsJson();
120128
} else {
121-
mismatchFinder.print();
129+
mismatchFinder.print(options.truncateLongPackageNameLists);
122130

123131
if (mismatchFinder.numberOfMismatches > 0) {
124132
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+
125140
throw new AlreadyReportedError();
126141
} else {
127142
if (options.isRushCheckCommand) {
@@ -188,15 +203,34 @@ export class VersionMismatchFinder {
188203
console.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
193208
this.getMismatches().forEach((dependency: string) => {
194209
console.log(colors.yellow(dependency));
195210
this.getVersionsOfMismatch(dependency)!.forEach((version: string) => {
196211
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+
}
200234
});
201235
console.log();
202236
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Change the way \"rush change\" prints long lists of package names to include an \"(and <count> more)\" line after the first five listed by name.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

0 commit comments

Comments
 (0)
0