1
- import { InternalError } from '@rushstack/node-core-library' ;
2
1
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
2
// See LICENSE in the project root for license information.
4
3
@@ -155,7 +154,7 @@ export const enum EnvironmentVariableNames {
155
154
* Initialize will throw if any unknown parameters are present.
156
155
*/
157
156
export class EnvironmentConfiguration {
158
- private static _hasBeenInitialized : boolean = false ;
157
+ private static _hasBeenValidated : boolean = false ;
159
158
160
159
private static _rushTempFolderOverride : string | undefined ;
161
160
@@ -181,7 +180,7 @@ export class EnvironmentConfiguration {
181
180
* An override for the common/temp folder path.
182
181
*/
183
182
public static get rushTempFolderOverride ( ) : string | undefined {
184
- EnvironmentConfiguration . _ensureInitialized ( ) ;
183
+ EnvironmentConfiguration . _ensureValidated ( ) ;
185
184
return EnvironmentConfiguration . _rushTempFolderOverride ;
186
185
}
187
186
@@ -190,7 +189,7 @@ export class EnvironmentConfiguration {
190
189
* See {@link EnvironmentVariableNames.RUSH_ABSOLUTE_SYMLINKS}
191
190
*/
192
191
public static get absoluteSymlinks ( ) : boolean {
193
- EnvironmentConfiguration . _ensureInitialized ( ) ;
192
+ EnvironmentConfiguration . _ensureValidated ( ) ;
194
193
return EnvironmentConfiguration . _absoluteSymlinks ;
195
194
}
196
195
@@ -202,7 +201,7 @@ export class EnvironmentConfiguration {
202
201
* See {@link EnvironmentVariableNames.RUSH_ALLOW_UNSUPPORTED_NODEJS}.
203
202
*/
204
203
public static get allowUnsupportedNodeVersion ( ) : boolean {
205
- EnvironmentConfiguration . _ensureInitialized ( ) ;
204
+ EnvironmentConfiguration . _ensureValidated ( ) ;
206
205
return EnvironmentConfiguration . _allowUnsupportedNodeVersion ;
207
206
}
208
207
@@ -212,7 +211,7 @@ export class EnvironmentConfiguration {
212
211
* or `0` to disallow them. (See the comments in the command-line.json file for more information).
213
212
*/
214
213
public static get allowWarningsInSuccessfulBuild ( ) : boolean {
215
- EnvironmentConfiguration . _ensureInitialized ( ) ;
214
+ EnvironmentConfiguration . _ensureValidated ( ) ;
216
215
return EnvironmentConfiguration . _allowWarningsInSuccessfulBuild ;
217
216
}
218
217
@@ -221,7 +220,7 @@ export class EnvironmentConfiguration {
221
220
* See {@link EnvironmentVariableNames.RUSH_PNPM_STORE_PATH}
222
221
*/
223
222
public static get pnpmStorePathOverride ( ) : string | undefined {
224
- EnvironmentConfiguration . _ensureInitialized ( ) ;
223
+ EnvironmentConfiguration . _ensureValidated ( ) ;
225
224
return EnvironmentConfiguration . _pnpmStorePathOverride ;
226
225
}
227
226
@@ -230,7 +229,7 @@ export class EnvironmentConfiguration {
230
229
* See {@link EnvironmentVariableNames.RUSH_GLOBAL_FOLDER}
231
230
*/
232
231
public static get rushGlobalFolderOverride ( ) : string | undefined {
233
- EnvironmentConfiguration . _ensureInitialized ( ) ;
232
+ EnvironmentConfiguration . _ensureValidated ( ) ;
234
233
return EnvironmentConfiguration . _rushGlobalFolderOverride ;
235
234
}
236
235
@@ -239,7 +238,7 @@ export class EnvironmentConfiguration {
239
238
* See {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_CREDENTIAL}
240
239
*/
241
240
public static get buildCacheCredential ( ) : string | undefined {
242
- EnvironmentConfiguration . _ensureInitialized ( ) ;
241
+ EnvironmentConfiguration . _ensureValidated ( ) ;
243
242
return EnvironmentConfiguration . _buildCacheCredential ;
244
243
}
245
244
@@ -248,7 +247,7 @@ export class EnvironmentConfiguration {
248
247
* See {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_ENABLED}
249
248
*/
250
249
public static get buildCacheEnabled ( ) : boolean | undefined {
251
- EnvironmentConfiguration . _ensureInitialized ( ) ;
250
+ EnvironmentConfiguration . _ensureValidated ( ) ;
252
251
return EnvironmentConfiguration . _buildCacheEnabled ;
253
252
}
254
253
@@ -257,7 +256,7 @@ export class EnvironmentConfiguration {
257
256
* See {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_WRITE_ALLOWED}
258
257
*/
259
258
public static get buildCacheWriteAllowed ( ) : boolean | undefined {
260
- EnvironmentConfiguration . _ensureInitialized ( ) ;
259
+ EnvironmentConfiguration . _ensureValidated ( ) ;
261
260
return EnvironmentConfiguration . _buildCacheWriteAllowed ;
262
261
}
263
262
@@ -266,7 +265,7 @@ export class EnvironmentConfiguration {
266
265
* See {@link EnvironmentVariableNames.RUSH_GIT_BINARY_PATH}
267
266
*/
268
267
public static get gitBinaryPath ( ) : string | undefined {
269
- EnvironmentConfiguration . _ensureInitialized ( ) ;
268
+ EnvironmentConfiguration . _ensureValidated ( ) ;
270
269
return EnvironmentConfiguration . _gitBinaryPath ;
271
270
}
272
271
@@ -288,7 +287,7 @@ export class EnvironmentConfiguration {
288
287
/**
289
288
* Reads and validates environment variables. If any are invalid, this function will throw.
290
289
*/
291
- public static initialize ( options : IEnvironmentConfigurationInitializeOptions = { } ) : void {
290
+ public static validate ( options : IEnvironmentConfigurationInitializeOptions = { } ) : void {
292
291
EnvironmentConfiguration . reset ( ) ;
293
292
294
293
const unknownEnvVariables : string [ ] = [ ] ;
@@ -411,7 +410,7 @@ export class EnvironmentConfiguration {
411
410
EnvironmentConfiguration . _rushGlobalFolderOverride =
412
411
EnvironmentConfiguration . _getRushGlobalFolderOverride ( process . env ) ;
413
412
414
- EnvironmentConfiguration . _hasBeenInitialized = true ;
413
+ EnvironmentConfiguration . _hasBeenValidated = true ;
415
414
}
416
415
417
416
/**
@@ -420,14 +419,12 @@ export class EnvironmentConfiguration {
420
419
public static reset ( ) : void {
421
420
EnvironmentConfiguration . _rushTempFolderOverride = undefined ;
422
421
423
- EnvironmentConfiguration . _hasBeenInitialized = false ;
422
+ EnvironmentConfiguration . _hasBeenValidated = false ;
424
423
}
425
424
426
- private static _ensureInitialized ( ) : void {
427
- if ( ! EnvironmentConfiguration . _hasBeenInitialized ) {
428
- throw new InternalError (
429
- 'The EnvironmentConfiguration must be initialized before values can be accessed.'
430
- ) ;
425
+ private static _ensureValidated ( ) : void {
426
+ if ( ! EnvironmentConfiguration . _hasBeenValidated ) {
427
+ EnvironmentConfiguration . validate ( ) ;
431
428
}
432
429
}
433
430
0 commit comments