Skip to content

Commit d808469

Browse files
committed
Address comments
1 parent 71c4f38 commit d808469

11 files changed

Lines changed: 119 additions & 37 deletions

File tree

‎apps/rush-lib/src/api/RushConfiguration.ts‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,32 @@ export interface IRushRepositoryJson {
106106
export type PnpmStoreOptions = 'local' | 'global';
107107

108108
/**
109-
* Part of IRushConfigurationJson.
110-
* @internal
109+
* Options for the package manager.
110+
* @public
111111
*/
112112
export interface IPackageManagerOptions {
113+
/**
114+
* Enviroment variables for the package manager
115+
*/
113116
environmentVariables?: {
114-
[name: string]: string
115-
};
117+
[environmentVariableName: string]: IEnvironmentVariable;
118+
}
119+
}
120+
121+
/**
122+
* Represents an environment variable
123+
* @public
124+
*/
125+
export interface IEnvironmentVariable {
126+
/**
127+
* Value of the environment variable
128+
*/
129+
value: string;
130+
131+
/**
132+
* Set to true to override the environment variable even if it is set on the device
133+
*/
134+
override?: boolean; //
116135
}
117136

118137
/**
@@ -1039,6 +1058,9 @@ export class RushConfiguration {
10391058
return this._projectFolderMaxDepth;
10401059
}
10411060

1061+
/**
1062+
* {@inheritDoc IPackageManagerOptions}
1063+
*/
10421064
public get packageManagerOptions(): IPackageManagerOptions | undefined {
10431065
return this._packageManagerOptions;
10441066
}

‎apps/rush-lib/src/cli/actions/BaseInstallAction.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { StandardScriptUpdater } from '../../logic/StandardScriptUpdater';
1919
import { Stopwatch } from '../../utilities/Stopwatch';
2020
import { VersionMismatchFinder } from '../../logic/versionMismatch/VersionMismatchFinder';
2121
import { Variants } from '../../api/Variants';
22+
import { RushConstants } from '../../logic/RushConstants';
2223

2324
/**
2425
* This is the common base class for InstallAction and UpdateAction.
@@ -63,7 +64,8 @@ export abstract class BaseInstallAction extends BaseRushAction {
6364
this._maxInstallAttempts = this.defineIntegerParameter({
6465
parameterLongName: '--max-install-attempts',
6566
argumentName: 'NUMBER',
66-
description: 'Overrides the default maximum number of install attempts. The default value is 3.'
67+
description: `Overrides the default maximum number of install attempts.`
68+
+ ` The default value is ${RushConstants.defaultMaxInstallAttempts}.`
6769
});
6870
this._variant = this.defineStringParameter(Variants.VARIANT_PARAMETER);
6971
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { BaseInstallAction } from './BaseInstallAction';
55
import { IInstallManagerOptions } from '../../logic/InstallManager';
66
import { RushCommandLineParser } from '../RushCommandLineParser';
7+
import { RushConstants } from '../../logic/RushConstants';
78

89
export class InstallAction extends BaseInstallAction {
910
public constructor(parser: RushCommandLineParser) {
@@ -35,7 +36,8 @@ export class InstallAction extends BaseInstallAction {
3536
networkConcurrency: this._networkConcurrencyParameter.value,
3637
collectLogFile: this._debugPackageManagerParameter.value!,
3738
variant: this._variant.value,
38-
maxInstallAttempts: this._maxInstallAttempts.value
39+
maxInstallAttempts: this._maxInstallAttempts.value ? this._maxInstallAttempts.value :
40+
RushConstants.defaultMaxInstallAttempts
3941
};
4042
}
4143
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CommandLineFlagParameter } from '@microsoft/ts-command-line';
66
import { BaseInstallAction } from './BaseInstallAction';
77
import { IInstallManagerOptions } from '../../logic/InstallManager';
88
import { RushCommandLineParser } from '../RushCommandLineParser';
9+
import { RushConstants } from '../../logic/RushConstants';
910

1011
export class UpdateAction extends BaseInstallAction {
1112
private _fullParameter: CommandLineFlagParameter;
@@ -62,7 +63,9 @@ export class UpdateAction extends BaseInstallAction {
6263
recheckShrinkwrap: this._recheckParameter.value!,
6364
networkConcurrency: this._networkConcurrencyParameter.value,
6465
collectLogFile: this._debugPackageManagerParameter.value!,
65-
variant: this._variant.value
66+
variant: this._variant.value,
67+
maxInstallAttempts: this._maxInstallAttempts.value ? this._maxInstallAttempts.value :
68+
RushConstants.defaultMaxInstallAttempts
6669
};
6770
}
6871
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ Optional arguments:
337337
You will probably want to pipe the output of Rush to
338338
a file when using this command.
339339
--max-install-attempts NUMBER
340-
Attempts command the specified number of times.
340+
Overrides the default maximum number of install
341+
attempts. The default value is 3.
341342
--variant VARIANT Run command using a variant installation
342343
configuration. This parameter may alternatively
343344
specified via the RUSH_VARIANT environment variable.
@@ -600,7 +601,8 @@ Optional arguments:
600601
You will probably want to pipe the output of Rush to
601602
a file when using this command.
602603
--max-install-attempts NUMBER
603-
Attempts command the specified number of times.
604+
Overrides the default maximum number of install
605+
attempts. The default value is 3.
604606
--variant VARIANT Run command using a variant installation
605607
configuration. This parameter may alternatively
606608
specified via the RUSH_VARIANT environment variable.

‎apps/rush-lib/src/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export {
1515
ITryFindRushJsonLocationOptions,
1616
ResolutionStrategy,
1717
PnpmOptionsConfiguration,
18-
IPackageManagerOptions as _IPackageManagerOptions,
18+
IPackageManagerOptions,
19+
IEnvironmentVariable,
1920
IPnpmOptionsJson as _IPnpmOptionsJson,
2021
PnpmStoreOptions,
2122
YarnOptionsConfiguration

‎apps/rush-lib/src/logic/InstallManager.ts‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export interface IInstallManagerOptions {
123123
/**
124124
* Retry the install the specified number of times
125125
*/
126-
maxInstallAttempts?: number | undefined
126+
maxInstallAttempts: number
127127
}
128128

129129
/**
@@ -134,7 +134,7 @@ export class InstallManager {
134134
private _rushGlobalFolder: RushGlobalFolder;
135135
private _commonNodeModulesMarker: LastInstallFlag;
136136
private _commonTempFolderRecycler: AsyncRecycler;
137-
private _maxInstallAttempts: number = 3;
137+
private _maxInstallAttempts: number;
138138

139139
private _options: IInstallManagerOptions;
140140

@@ -161,9 +161,7 @@ export class InstallManager {
161161

162162
this._commonNodeModulesMarker = new LastInstallFlag(this._rushConfiguration.commonTempFolder, lastInstallState);
163163

164-
if (options.maxInstallAttempts) {
165-
this._maxInstallAttempts = options.maxInstallAttempts;
166-
}
164+
this._maxInstallAttempts = options.maxInstallAttempts;
167165
}
168166

169167
/**
@@ -911,9 +909,38 @@ export class InstallManager {
911909
this._rushConfiguration.packageManagerOptions &&
912910
this._rushConfiguration.packageManagerOptions.environmentVariables
913911
) {
912+
for (const envVar in this._rushConfiguration.packageManagerOptions.environmentVariables) {
913+
if ({}.hasOwnProperty.call(this._rushConfiguration.packageManagerOptions.environmentVariables, envVar)) {
914+
let setEnvironmentVariable: boolean = true;
915+
const envVarValueInRushConfig: string =
916+
this._rushConfiguration.packageManagerOptions.environmentVariables[envVar].value;
917+
918+
console.log(`\nProcessing definition for environment variable: ${envVar}`);
919+
920+
if (process.env[envVar]) {
921+
setEnvironmentVariable = false;
922+
console.log(colors.yellow(`WARNING: Environment variable already defined on the device:`));
923+
console.log(` Name: ${envVar}`);
924+
console.log(` Value set on the device: ${process.env[envVar]}`);
925+
console.log(` Value set in Rush config: ${envVarValueInRushConfig}`);
926+
if (
927+
this._rushConfiguration.packageManagerOptions.environmentVariables[envVar].override &&
928+
this._rushConfiguration.packageManagerOptions.environmentVariables[envVar].override === true
929+
) {
930+
setEnvironmentVariable = true;
931+
console.log(colors.yellow(`WARNING: Overriding the environment variable with the value set in Rush config.`));
932+
} else {
933+
console.log(colors.yellow(`WARNING: Not overriding the value of the environment variable.`));
934+
}
935+
}
914936

915-
for (const envVar of Object.keys(this._rushConfiguration.packageManagerOptions.environmentVariables)) {
916-
packageManagerEnv[envVar] = this._rushConfiguration.packageManagerOptions.environmentVariables[envVar];
937+
if (setEnvironmentVariable === true) {
938+
console.log(`Setting environment variable for package manager.`);
939+
console.log(` Name: ${envVar}`);
940+
console.log(` Value: ${envVarValueInRushConfig}`);
941+
packageManagerEnv[envVar] = envVarValueInRushConfig;
942+
}
943+
}
917944
}
918945
}
919946

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { RushGlobalFolder } from '../api/RushGlobalFolder';
1717
import { RushConfigurationProject } from '../api/RushConfigurationProject';
1818
import { VersionMismatchFinderEntity } from './versionMismatch/VersionMismatchFinderEntity';
1919
import { VersionMismatchFinderProject } from './versionMismatch/VersionMismatchFinderProject';
20+
import { RushConstants } from './RushConstants';
2021

2122
/**
2223
* The type of SemVer range specifier that is prepended to the version
@@ -141,7 +142,8 @@ export class PackageJsonUpdater {
141142
recheckShrinkwrap: false,
142143
networkConcurrency: undefined,
143144
collectLogFile: false,
144-
variant: variant
145+
variant: variant,
146+
maxInstallAttempts: RushConstants.defaultMaxInstallAttempts
145147
};
146148
const installManager: InstallManager = new InstallManager(
147149
this._rushConfiguration,

‎apps/rush-lib/src/logic/RushConstants.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export class RushConstants {
7575
*/
7676
public static readonly pnpmV1ShrinkwrapFilename: string = 'shrinkwrap.yaml';
7777

78+
/**
79+
* Number of installation attempts
80+
*/
81+
public static readonly defaultMaxInstallAttempts: number = 3;
82+
7883
/**
7984
* The filename ("pnpm-lock.yaml") used to store an installation plan for the PNPM package manger
8085
* (PNPM version 3.x and later).

‎apps/rush-lib/src/schemas/rush.schema.json‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,26 @@
33
"title": "Rush main config File",
44
"description": "The main configuration file for the Rush multi-project build tool. See http://rushjs.io for details.",
55
"type": "object",
6-
76
"properties": {
87
"$schema": {
98
"description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.",
109
"type": "string"
1110
},
12-
1311
"npmVersion": {
1412
"description": "If specified, selects NPM as the package manager and specifies the deterministic version to be installed by Rush.",
1513
"type": "string",
1614
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9a-zA-Z.+\\-]+$"
1715
},
18-
1916
"pnpmVersion": {
2017
"description": "If specified, selects PNPM as the package manager and specifies the deterministic version to be installed by Rush.",
2118
"type": "string",
2219
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9a-zA-Z.+\\-]+$"
2320
},
24-
2521
"yarnVersion": {
2622
"description": "If specified, selects Yarn as the package manager and specifies the deterministic version to be installed by Rush.",
2723
"type": "string",
2824
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9a-zA-Z.+\\-]+$"
2925
},
30-
3126
"rushVersion": {
3227
"description": "The version of the Rush tool that will be used to build this repository.",
3328
"type": "string",
@@ -60,9 +55,22 @@
6055
"environmentVariables": {
6156
"description": "Enviroment variables for the package manager",
6257
"type": "object",
63-
"additionalProperties": {
64-
"type": "string"
65-
}
58+
"additionalProperties": {
59+
"type": "object",
60+
"properties": {
61+
"value": {
62+
"type": "string"
63+
}
64+
},
65+
"additionalProperties": {
66+
"type": "boolean",
67+
"properties": {
68+
"override": {
69+
"type": "boolean"
70+
}
71+
}
72+
}
73+
}
6674
}
6775
}
6876
},
@@ -73,7 +81,10 @@
7381
"pnpmStore": {
7482
"description": "Specifies the location of the PNPM store. There are two possible values:\n\n\"local\" - use the \"pnpm-store\" folder in the current configured temp folder: \"common/temp/pnpm-store\" by default.\n\"global\" - use PNPM's global store, which has the benefit of being shared across multiple repo folders, but the disadvantage of less isolation for builds (e.g. bugs or incompatibilities when two repos use different releases of PNPM)\n\nIn all cases, the store path will be overridden by the environment variable RUSH_PNPM_STORE_PATH.\n\nThe default value is \"local\".",
7583
"type": "string",
76-
"enum": ["local", "global"]
84+
"enum": [
85+
"local",
86+
"global"
87+
]
7788
},
7889
"strictPeerDependencies": {
7990
"description": "If true, then Rush will add the \"--strict-peer-dependencies\" option when invoking PNPM. This causes \"rush install\" to fail if there are unsatisfied peer dependencies, which is an invalid state that can cause build failures or incompatible dependency versions. (For historical reasons, JavaScript package managers generally do not treat this invalid state as an error.) The default value is false.",
@@ -82,7 +93,10 @@
8293
"resolutionStrategy": {
8394
"description": "Configures the strategy used to select versions during installation. This feature requires PNPM version 3.1 or newer. It corresponds to the \"--resolution-strategy\" command-line option for PNPM. Possible values are \"fast\" and \"fewer-dependencies\". PNPM's default is \"fast\", but this may be incompatible with certain packages, for example the \"@types\" packages from DefinitelyTyped. Rush's default is \"fewer-dependencies\", which causes PNPM to avoid installing a newer version if an already installed version can be reused; this is more similar to NPM's algorithm.",
8495
"type": "string",
85-
"enum": ["fewer-dependencies", "fast"]
96+
"enum": [
97+
"fewer-dependencies",
98+
"fast"
99+
]
86100
}
87101
},
88102
"additionalProperties": false
@@ -276,4 +290,4 @@
276290
"rushVersion",
277291
"projects"
278292
]
279-
}
293+
}

0 commit comments

Comments
 (0)