Skip to content

Commit 114edd5

Browse files
authored
Merge pull request microsoft#2902 from chengcyber/feat-rush-install-check-only
[rush] Feat rush install check only
2 parents 379f669 + 2b8bc21 commit 114edd5

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { CommandLineFlagParameter } from '@rushstack/ts-command-line';
5+
46
import { BaseInstallAction } from './BaseInstallAction';
57
import { IInstallManagerOptions } from '../../logic/base/BaseInstallManager';
68
import { RushCommandLineParser } from '../RushCommandLineParser';
79
import { SelectionParameterSet } from '../SelectionParameterSet';
810

911
export class InstallAction extends BaseInstallAction {
12+
private _checkOnlyParameter!: CommandLineFlagParameter;
13+
1014
public constructor(parser: RushCommandLineParser) {
1115
super({
1216
actionName: 'install',
@@ -33,6 +37,11 @@ export class InstallAction extends BaseInstallAction {
3337
super.onDefineParameters();
3438

3539
this._selectionParameters = new SelectionParameterSet(this.rushConfiguration, this);
40+
41+
this._checkOnlyParameter = this.defineFlagParameter({
42+
parameterLongName: '--check-only',
43+
description: `Only check the validity of the shrinkwrap file without performing an install.`
44+
});
3645
}
3746

3847
protected buildInstallOptions(): IInstallManagerOptions {
@@ -50,7 +59,8 @@ export class InstallAction extends BaseInstallAction {
5059
// it is safe to assume that the value is not null
5160
maxInstallAttempts: this._maxInstallAttempts.value!,
5261
// These are derived independently of the selection for command line brevity
53-
pnpmFilterArguments: this._selectionParameters!.getPnpmFilterArguments()
62+
pnpmFilterArguments: this._selectionParameters!.getPnpmFilterArguments(),
63+
checkOnly: this._checkOnlyParameter.value
5464
};
5565
}
5666
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class UpdateAction extends BaseInstallAction {
7070
// Because the 'defaultValue' option on the _maxInstallAttempts parameter is set,
7171
// it is safe to assume that the value is not null
7272
maxInstallAttempts: this._maxInstallAttempts.value!,
73-
pnpmFilterArguments: []
73+
pnpmFilterArguments: [],
74+
checkOnly: false
7475
};
7576
}
7677
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ exports[`CommandLineHelp prints the help for each action: install 1`] = `
535535
[--variant VARIANT] [-t PROJECT] [-T PROJECT] [-f PROJECT]
536536
[-o PROJECT] [-i PROJECT] [-I PROJECT]
537537
[--to-version-policy VERSION_POLICY_NAME]
538-
[--from-version-policy VERSION_POLICY_NAME]
538+
[--from-version-policy VERSION_POLICY_NAME] [--check-only]
539539
540540
541541
The \\"rush install\\" command installs package dependencies for all your
@@ -656,6 +656,8 @@ Optional arguments:
656656
each of the projects belonging to VERSION_POLICY_NAME.
657657
For details, refer to the website article \\"Selecting
658658
subsets of projects\\".
659+
--check-only Only check the validity of the shrinkwrap file
660+
without performing an install.
659661
"
660662
`;
661663

apps/rush-lib/src/logic/PackageJsonUpdater.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export class PackageJsonUpdater {
138138
collectLogFile: false,
139139
variant: variant,
140140
maxInstallAttempts: RushConstants.defaultMaxInstallAttempts,
141-
pnpmFilterArguments: []
141+
pnpmFilterArguments: [],
142+
checkOnly: false
142143
};
143144
const installManager: BaseInstallManager = InstallManagerFactory.getInstallManager(
144145
this._rushConfiguration,

apps/rush-lib/src/logic/base/BaseInstallManager.ts

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export interface IInstallManagerOptions {
4949
*/
5050
allowShrinkwrapUpdates: boolean;
5151

52+
/**
53+
* Whether to check the validation before install only, without actually installing anything.
54+
*/
55+
checkOnly: boolean;
56+
5257
/**
5358
* Whether to skip policy checks.
5459
*/
@@ -180,6 +185,10 @@ export abstract class BaseInstallManager {
180185

181186
const { shrinkwrapIsUpToDate, variantIsUpToDate } = await this.prepareAsync();
182187

188+
if (this.options.checkOnly) {
189+
return;
190+
}
191+
183192
console.log(
184193
os.EOL + colors.bold(`Checking installation in "${this.rushConfiguration.commonTempFolder}"`)
185194
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Add a \"--check-only\" parameter to \"rush install\" to check the validity of the shrinkwrap without performing a full install.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "[email protected]"
11+
}

0 commit comments

Comments
 (0)