@@ -105,11 +105,58 @@ export interface IRushRepositoryJson {
105
105
*/
106
106
export type PnpmStoreOptions = 'local' | 'global' ;
107
107
108
+ /**
109
+ * Options for the package manager.
110
+ * @public
111
+ */
112
+ export interface IPackageManagerOptionsJsonBase {
113
+ /**
114
+ * Enviroment variables for the package manager
115
+ */
116
+ environmentVariables ?: IConfigurationEnvironment
117
+ }
118
+
119
+ /**
120
+ * A collection of environment variables
121
+ * @public
122
+ */
123
+ export interface IConfigurationEnvironment {
124
+ /**
125
+ * Environment variables
126
+ */
127
+ [ environmentVariableName : string ] : IConfigurationEnvironmentVariable ;
128
+ }
129
+
130
+ /**
131
+ * Represents the value of an environment variable, and if the value should be overridden if the variable is set
132
+ * in the parent environment.
133
+ * @public
134
+ */
135
+ export interface IConfigurationEnvironmentVariable {
136
+ /**
137
+ * Value of the environment variable
138
+ */
139
+ value : string ;
140
+
141
+ /**
142
+ * Set to true to override the environment variable even if it is set in the parent environment.
143
+ * The default value is false.
144
+ */
145
+ override ?: boolean ;
146
+ }
147
+
108
148
/**
109
149
* Part of IRushConfigurationJson.
110
150
* @internal
111
151
*/
112
- export interface IPnpmOptionsJson {
152
+ export interface INpmOptionsJson extends IPackageManagerOptionsJsonBase {
153
+ }
154
+
155
+ /**
156
+ * Part of IRushConfigurationJson.
157
+ * @internal
158
+ */
159
+ export interface IPnpmOptionsJson extends IPackageManagerOptionsJsonBase {
113
160
/**
114
161
* The store resolution method for PNPM to use
115
162
*/
@@ -126,8 +173,16 @@ export interface IPnpmOptionsJson {
126
173
127
174
/**
128
175
* Part of IRushConfigurationJson.
176
+ * @internal
129
177
*/
130
- export interface IYarnOptionsJson {
178
+ export interface IYarnOptionsJson extends IPackageManagerOptionsJsonBase {
179
+ /**
180
+ * If true, then Rush will add the "--ignore-engines" option when invoking Yarn.
181
+ * This allows "rush install" to succeed if there are dependencies with engines defined in
182
+ * package.json which do not match the current environment.
183
+ *
184
+ * The default value is false.
185
+ */
131
186
ignoreEngines ?: boolean ;
132
187
}
133
188
@@ -160,6 +215,7 @@ export interface IRushConfigurationJson {
160
215
projects : IRushConfigurationProjectJson [ ] ;
161
216
eventHooks ?: IEventHooksJson ;
162
217
hotfixChangeEnabled ?: boolean ;
218
+ npmOptions ?: INpmOptionsJson ;
163
219
pnpmOptions ?: IPnpmOptionsJson ;
164
220
yarnOptions ?: IYarnOptionsJson ;
165
221
ensureConsistentVersions ?: boolean ;
@@ -182,6 +238,39 @@ export interface ICurrentVariantJson {
182
238
variant : string | null ; // Use `null` instead of `undefined` because `undefined` is not handled by JSON.
183
239
}
184
240
241
+ /**
242
+ * Options that all package managers share.
243
+ *
244
+ * @public
245
+ */
246
+ export abstract class PackageManagerOptionsConfigurationBase implements IPackageManagerOptionsJsonBase {
247
+ /**
248
+ * Enviroment variables for the package manager
249
+ */
250
+ public readonly environmentVariables ?: IConfigurationEnvironment
251
+
252
+ /** @internal */
253
+ protected constructor ( json : IPackageManagerOptionsJsonBase ) {
254
+ this . environmentVariables = json . environmentVariables ;
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Options that are only used when the NPM package manager is selected.
260
+ *
261
+ * @remarks
262
+ * It is valid to define these options in rush.json even if the NPM package manager
263
+ * is not being used.
264
+ *
265
+ * @public
266
+ */
267
+ export class NpmOptionsConfiguration extends PackageManagerOptionsConfigurationBase {
268
+ /** @internal */
269
+ public constructor ( json : INpmOptionsJson ) {
270
+ super ( json ) ;
271
+ }
272
+ }
273
+
185
274
/**
186
275
* Options that are only used when the PNPM package manager is selected.
187
276
*
@@ -191,7 +280,7 @@ export interface ICurrentVariantJson {
191
280
*
192
281
* @public
193
282
*/
194
- export class PnpmOptionsConfiguration {
283
+ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfigurationBase {
195
284
/**
196
285
* The method used to resolve the store used by PNPM.
197
286
*
@@ -240,6 +329,7 @@ export class PnpmOptionsConfiguration {
240
329
241
330
/** @internal */
242
331
public constructor ( json : IPnpmOptionsJson , commonTempFolder : string ) {
332
+ super ( json ) ;
243
333
this . pnpmStore = json . pnpmStore || 'local' ;
244
334
if ( EnvironmentConfiguration . pnpmStorePathOverride ) {
245
335
this . pnpmStorePath = EnvironmentConfiguration . pnpmStorePathOverride ;
@@ -262,7 +352,7 @@ export class PnpmOptionsConfiguration {
262
352
*
263
353
* @public
264
354
*/
265
- export class YarnOptionsConfiguration {
355
+ export class YarnOptionsConfiguration extends PackageManagerOptionsConfigurationBase {
266
356
/**
267
357
* If true, then Rush will add the "--ignore-engines" option when invoking Yarn.
268
358
* This allows "rush install" to succeed if there are dependencies with engines defined in
@@ -274,6 +364,7 @@ export class YarnOptionsConfiguration {
274
364
275
365
/** @internal */
276
366
public constructor ( json : IYarnOptionsJson ) {
367
+ super ( json ) ;
277
368
this . ignoreEngines = ! ! json . ignoreEngines ;
278
369
}
279
370
}
@@ -351,6 +442,7 @@ export class RushConfiguration {
351
442
private _repositoryDefaultBranch : string ;
352
443
private _repositoryDefaultRemote : string ;
353
444
445
+ private _npmOptions : NpmOptionsConfiguration ;
354
446
private _pnpmOptions : PnpmOptionsConfiguration ;
355
447
private _yarnOptions : YarnOptionsConfiguration ;
356
448
@@ -420,6 +512,7 @@ export class RushConfiguration {
420
512
) ;
421
513
this . _experimentsConfiguration = new ExperimentsConfiguration ( experimentsConfigFile ) ;
422
514
515
+ this . _npmOptions = new NpmOptionsConfiguration ( rushConfigurationJson . npmOptions || { } ) ;
423
516
this . _pnpmOptions = new PnpmOptionsConfiguration ( rushConfigurationJson . pnpmOptions || { } ,
424
517
this . _commonTempFolder ) ;
425
518
this . _yarnOptions = new YarnOptionsConfiguration ( rushConfigurationJson . yarnOptions || { } ) ;
@@ -463,10 +556,10 @@ export class RushConfiguration {
463
556
this . _shrinkwrapFilename = this . _packageManagerWrapper . shrinkwrapFilename ;
464
557
465
558
this . _tempShrinkwrapFilename = path . join (
466
- this . _commonTempFolder , this . _shrinkwrapFilename
559
+ this . _commonTempFolder , this . _shrinkwrapFilename
467
560
) ;
468
561
this . _packageManagerToolFilename = path . resolve ( path . join (
469
- this . _commonTempFolder , `${ this . packageManager } -local` , 'node_modules' , '.bin' , `${ this . packageManager } `
562
+ this . _commonTempFolder , `${ this . packageManager } -local` , 'node_modules' , '.bin' , `${ this . packageManager } `
470
563
) ) ;
471
564
472
565
/// From "C:\repo\common\temp\pnpm-lock.yaml" --> "C:\repo\common\temp\pnpm-lock-preinstall.yaml"
@@ -475,9 +568,9 @@ export class RushConfiguration {
475
568
parsedPath . name + '-preinstall' + parsedPath . ext ) ;
476
569
477
570
RushConfiguration . _validateCommonRushConfigFolder (
478
- this . _commonRushConfigFolder ,
479
- this . packageManager ,
480
- this . _shrinkwrapFilename
571
+ this . _commonRushConfigFolder ,
572
+ this . packageManager ,
573
+ this . _shrinkwrapFilename
481
574
) ;
482
575
483
576
this . _projectFolderMinDepth = rushConfigurationJson . projectFolderMinDepth !== undefined
@@ -642,11 +735,11 @@ export class RushConfiguration {
642
735
if ( semver . major ( Rush . version ) !== semver . major ( expectedRushVersion )
643
736
|| semver . minor ( Rush . version ) !== semver . minor ( expectedRushVersion ) ) {
644
737
645
- // If the major/minor are different, then make sure it's an older version.
646
- if ( semver . lt ( Rush . version , expectedRushVersion ) ) {
647
- throw new Error ( `Unable to load ${ rushJsonBaseName } because its RushVersion is`
648
- + ` ${ rushConfigurationJson . rushVersion } , whereas @microsoft/rush-lib is version ${ Rush . version } .`
649
- + ` Consider upgrading the library.` ) ;
738
+ // If the major/minor are different, then make sure it's an older version.
739
+ if ( semver . lt ( Rush . version , expectedRushVersion ) ) {
740
+ throw new Error ( `Unable to load ${ rushJsonBaseName } because its RushVersion is`
741
+ + ` ${ rushConfigurationJson . rushVersion } , whereas @microsoft/rush-lib is version ${ Rush . version } .`
742
+ + ` Consider upgrading the library.` ) ;
650
743
}
651
744
}
652
745
}
@@ -741,9 +834,9 @@ export class RushConfiguration {
741
834
* recognized config files.
742
835
*/
743
836
private static _validateCommonRushConfigFolder (
744
- commonRushConfigFolder : string ,
745
- packageManager : PackageManagerName ,
746
- shrinkwrapFilename : string
837
+ commonRushConfigFolder : string ,
838
+ packageManager : PackageManagerName ,
839
+ shrinkwrapFilename : string
747
840
) : void {
748
841
if ( ! FileSystem . exists ( commonRushConfigFolder ) ) {
749
842
console . log ( `Creating folder: ${ commonRushConfigFolder } ` ) ;
@@ -1136,6 +1229,13 @@ export class RushConfiguration {
1136
1229
return this . _projectsByName ;
1137
1230
}
1138
1231
1232
+ /**
1233
+ * {@inheritDoc NpmOptionsConfiguration }
1234
+ */
1235
+ public get npmOptions ( ) : NpmOptionsConfiguration {
1236
+ return this . _npmOptions ;
1237
+ }
1238
+
1139
1239
/**
1140
1240
* {@inheritDoc PnpmOptionsConfiguration }
1141
1241
*/
0 commit comments