@@ -253,6 +253,131 @@ export default class RushConfiguration {
253253 }
254254 }
255255
256+ /**
257+ * Use RushConfiguration.loadFromConfigurationFile() or Use RushConfiguration.loadFromDefaultLocation()
258+ * instead.
259+ */
260+ private constructor ( rushConfigurationJson : IRushConfigurationJson , rushJsonFilename : string ) {
261+ if ( rushConfigurationJson . nodeSupportedVersionRange ) {
262+ if ( ! semver . validRange ( rushConfigurationJson . nodeSupportedVersionRange ) ) {
263+ throw new Error ( 'Error parsing the node-semver expression in the "nodeSupportedVersionRange"'
264+ + ` field from rush.json: "${ rushConfigurationJson . nodeSupportedVersionRange } "` ) ;
265+ }
266+ if ( ! semver . satisfies ( process . version , rushConfigurationJson . nodeSupportedVersionRange ) ) {
267+ throw new Error ( `Your dev environment is running Node.js version ${ process . version } which does`
268+ + ` not meet the requirements for building this repository. (The rush.json configuration`
269+ + ` requires nodeSupportedVersionRange="${ rushConfigurationJson . nodeSupportedVersionRange } ")` ) ;
270+ }
271+ }
272+
273+ this . _rushJsonFolder = path . dirname ( rushJsonFilename ) ;
274+
275+ this . _commonFolder = path . resolve ( path . join ( this . _rushJsonFolder , RushConstants . commonFolderName ) ) ;
276+
277+ this . _commonRushConfigFolder = path . join ( this . _commonFolder , 'config' , 'rush' ) ;
278+ RushConfiguration . _validateCommonRushConfigFolder ( this . _commonRushConfigFolder ) ;
279+
280+ this . _commonTempFolder = path . join ( this . _commonFolder , RushConstants . rushTempFolderName ) ;
281+ this . _npmCacheFolder = path . resolve ( path . join ( this . _commonTempFolder , 'npm-cache' ) ) ;
282+ this . _npmTmpFolder = path . resolve ( path . join ( this . _commonTempFolder , 'npm-tmp' ) ) ;
283+
284+ this . _committedShrinkwrapFilename = path . join ( this . _commonRushConfigFolder , RushConstants . npmShrinkwrapFilename ) ;
285+ this . _tempShrinkwrapFilename = path . join ( this . _commonTempFolder , RushConstants . npmShrinkwrapFilename ) ;
286+
287+ const unresolvedUserFolder : string = process . env [ ( process . platform === 'win32' ) ? 'USERPROFILE' : 'HOME' ] ;
288+ this . _homeFolder = path . resolve ( unresolvedUserFolder ) ;
289+ if ( ! fsx . existsSync ( this . _homeFolder ) ) {
290+ throw new Error ( 'Unable to determine the current user\'s home directory' ) ;
291+ }
292+
293+ this . _rushLinkJsonFilename = path . join ( this . _commonTempFolder , 'rush-link.json' ) ;
294+
295+ this . _npmToolVersion = rushConfigurationJson . npmVersion ;
296+ this . _npmToolFilename = path . resolve ( path . join ( this . _commonTempFolder ,
297+ 'npm-local' , 'node_modules' , '.bin' , 'npm' ) ) ;
298+
299+ this . _projectFolderMinDepth = rushConfigurationJson . projectFolderMinDepth !== undefined
300+ ? rushConfigurationJson . projectFolderMinDepth : 1 ;
301+ if ( this . _projectFolderMinDepth < 1 ) {
302+ throw new Error ( 'Invalid projectFolderMinDepth; the minimum possible value is 1' ) ;
303+ }
304+
305+ this . _projectFolderMaxDepth = rushConfigurationJson . projectFolderMaxDepth !== undefined
306+ ? rushConfigurationJson . projectFolderMaxDepth : 2 ;
307+ if ( this . _projectFolderMaxDepth < this . _projectFolderMinDepth ) {
308+ throw new Error ( 'The projectFolderMaxDepth cannot be smaller than the projectFolderMinDepth' ) ;
309+ }
310+
311+ this . _approvedPackagesPolicy = new ApprovedPackagesPolicy ( this , rushConfigurationJson ) ;
312+
313+ this . _gitAllowedEmailRegExps = [ ] ;
314+ this . _gitSampleEmail = '' ;
315+ if ( rushConfigurationJson . gitPolicy ) {
316+ if ( rushConfigurationJson . gitPolicy . sampleEmail ) {
317+ this . _gitSampleEmail = rushConfigurationJson . gitPolicy . sampleEmail ;
318+ }
319+
320+ if ( rushConfigurationJson . gitPolicy . allowedEmailRegExps ) {
321+ this . _gitAllowedEmailRegExps = rushConfigurationJson . gitPolicy . allowedEmailRegExps ;
322+
323+ if ( this . _gitSampleEmail . trim ( ) . length < 1 ) {
324+ throw new Error ( 'The rush.json file is missing the "sampleEmail" option, ' +
325+ 'which is required when using "allowedEmailRegExps"' ) ;
326+ }
327+ }
328+ }
329+
330+ this . _telemetryEnabled = ! ! rushConfigurationJson . telemetryEnabled ;
331+ if ( rushConfigurationJson . eventHooks ) {
332+ this . _eventHooks = new EventHooks ( rushConfigurationJson . eventHooks ) ;
333+ }
334+
335+ const versionPolicyConfigFile : string = path . join ( this . _commonRushConfigFolder ,
336+ RushConstants . versionPoliciesFileName ) ;
337+ this . _versionPolicyConfiguration = new VersionPolicyConfiguration ( versionPolicyConfigFile ) ;
338+
339+ this . _projects = [ ] ;
340+ this . _projectsByName = new Map < string , RushConfigurationProject > ( ) ;
341+
342+ // We sort the projects array in alphabetical order. This ensures that the packages
343+ // are processed in a deterministic order by the various Rush algorithms.
344+ const sortedProjectJsons : IRushConfigurationProjectJson [ ] = rushConfigurationJson . projects . slice ( 0 ) ;
345+ sortedProjectJsons . sort (
346+ ( a : IRushConfigurationProjectJson , b : IRushConfigurationProjectJson ) => a . packageName . localeCompare ( b . packageName )
347+ ) ;
348+
349+ const tempNamesByProject : Map < IRushConfigurationProjectJson , string >
350+ = RushConfiguration . _generateTempNamesForProjects ( sortedProjectJsons ) ;
351+
352+ for ( const projectJson of sortedProjectJsons ) {
353+ const tempProjectName : string = tempNamesByProject . get ( projectJson ) ;
354+ const project : RushConfigurationProject = new RushConfigurationProject ( projectJson , this , tempProjectName ) ;
355+ this . _projects . push ( project ) ;
356+ if ( this . _projectsByName . get ( project . packageName ) ) {
357+ throw new Error ( `The project name "${ project . packageName } " was specified more than once`
358+ + ` in the rush.json configuration file.` ) ;
359+ }
360+ this . _projectsByName . set ( project . packageName , project ) ;
361+ }
362+
363+ for ( const project of this . _projects ) {
364+ project . cyclicDependencyProjects . forEach ( ( cyclicDependencyProject : string ) => {
365+ if ( ! this . getProjectByName ( cyclicDependencyProject ) ) {
366+ throw new Error ( `In rush.json, the "${ cyclicDependencyProject } " project does not exist,`
367+ + ` but was referenced by the cyclicDependencyProjects for ${ project . packageName } ` ) ;
368+ }
369+ } ) ;
370+
371+ // Compute the downstream dependencies within the list of Rush projects.
372+ this . _populateDownstreamDependencies ( project . packageJson . dependencies , project . packageName ) ;
373+ this . _populateDownstreamDependencies ( project . packageJson . devDependencies , project . packageName ) ;
374+ }
375+
376+ // Example: "./common/config/rush/pinnedVersions.json"
377+ const pinnedVersionsFile : string = path . join ( this . commonRushConfigFolder , RushConstants . pinnedVersionsFilename ) ;
378+ this . _pinnedVersions = PinnedVersionsConfiguration . tryLoadFromFile ( pinnedVersionsFile ) ;
379+ }
380+
256381 /**
257382 * The folder that contains rush.json for this project.
258383 */
@@ -517,129 +642,4 @@ export default class RushConfiguration {
517642 }
518643 } ) ;
519644 }
520-
521- /**
522- * Use RushConfiguration.loadFromConfigurationFile() or Use RushConfiguration.loadFromDefaultLocation()
523- * instead.
524- */
525- private constructor ( rushConfigurationJson : IRushConfigurationJson , rushJsonFilename : string ) {
526- if ( rushConfigurationJson . nodeSupportedVersionRange ) {
527- if ( ! semver . validRange ( rushConfigurationJson . nodeSupportedVersionRange ) ) {
528- throw new Error ( 'Error parsing the node-semver expression in the "nodeSupportedVersionRange"'
529- + ` field from rush.json: "${ rushConfigurationJson . nodeSupportedVersionRange } "` ) ;
530- }
531- if ( ! semver . satisfies ( process . version , rushConfigurationJson . nodeSupportedVersionRange ) ) {
532- throw new Error ( `Your dev environment is running Node.js version ${ process . version } which does`
533- + ` not meet the requirements for building this repository. (The rush.json configuration`
534- + ` requires nodeSupportedVersionRange="${ rushConfigurationJson . nodeSupportedVersionRange } ")` ) ;
535- }
536- }
537-
538- this . _rushJsonFolder = path . dirname ( rushJsonFilename ) ;
539-
540- this . _commonFolder = path . resolve ( path . join ( this . _rushJsonFolder , RushConstants . commonFolderName ) ) ;
541-
542- this . _commonRushConfigFolder = path . join ( this . _commonFolder , 'config' , 'rush' ) ;
543- RushConfiguration . _validateCommonRushConfigFolder ( this . _commonRushConfigFolder ) ;
544-
545- this . _commonTempFolder = path . join ( this . _commonFolder , RushConstants . rushTempFolderName ) ;
546- this . _npmCacheFolder = path . resolve ( path . join ( this . _commonTempFolder , 'npm-cache' ) ) ;
547- this . _npmTmpFolder = path . resolve ( path . join ( this . _commonTempFolder , 'npm-tmp' ) ) ;
548-
549- this . _committedShrinkwrapFilename = path . join ( this . _commonRushConfigFolder , RushConstants . npmShrinkwrapFilename ) ;
550- this . _tempShrinkwrapFilename = path . join ( this . _commonTempFolder , RushConstants . npmShrinkwrapFilename ) ;
551-
552- const unresolvedUserFolder : string = process . env [ ( process . platform === 'win32' ) ? 'USERPROFILE' : 'HOME' ] ;
553- this . _homeFolder = path . resolve ( unresolvedUserFolder ) ;
554- if ( ! fsx . existsSync ( this . _homeFolder ) ) {
555- throw new Error ( 'Unable to determine the current user\'s home directory' ) ;
556- }
557-
558- this . _rushLinkJsonFilename = path . join ( this . _commonTempFolder , 'rush-link.json' ) ;
559-
560- this . _npmToolVersion = rushConfigurationJson . npmVersion ;
561- this . _npmToolFilename = path . resolve ( path . join ( this . _commonTempFolder ,
562- 'npm-local' , 'node_modules' , '.bin' , 'npm' ) ) ;
563-
564- this . _projectFolderMinDepth = rushConfigurationJson . projectFolderMinDepth !== undefined
565- ? rushConfigurationJson . projectFolderMinDepth : 1 ;
566- if ( this . _projectFolderMinDepth < 1 ) {
567- throw new Error ( 'Invalid projectFolderMinDepth; the minimum possible value is 1' ) ;
568- }
569-
570- this . _projectFolderMaxDepth = rushConfigurationJson . projectFolderMaxDepth !== undefined
571- ? rushConfigurationJson . projectFolderMaxDepth : 2 ;
572- if ( this . _projectFolderMaxDepth < this . _projectFolderMinDepth ) {
573- throw new Error ( 'The projectFolderMaxDepth cannot be smaller than the projectFolderMinDepth' ) ;
574- }
575-
576- this . _approvedPackagesPolicy = new ApprovedPackagesPolicy ( this , rushConfigurationJson ) ;
577-
578- this . _gitAllowedEmailRegExps = [ ] ;
579- this . _gitSampleEmail = '' ;
580- if ( rushConfigurationJson . gitPolicy ) {
581- if ( rushConfigurationJson . gitPolicy . sampleEmail ) {
582- this . _gitSampleEmail = rushConfigurationJson . gitPolicy . sampleEmail ;
583- }
584-
585- if ( rushConfigurationJson . gitPolicy . allowedEmailRegExps ) {
586- this . _gitAllowedEmailRegExps = rushConfigurationJson . gitPolicy . allowedEmailRegExps ;
587-
588- if ( this . _gitSampleEmail . trim ( ) . length < 1 ) {
589- throw new Error ( 'The rush.json file is missing the "sampleEmail" option, ' +
590- 'which is required when using "allowedEmailRegExps"' ) ;
591- }
592- }
593- }
594-
595- this . _telemetryEnabled = ! ! rushConfigurationJson . telemetryEnabled ;
596- if ( rushConfigurationJson . eventHooks ) {
597- this . _eventHooks = new EventHooks ( rushConfigurationJson . eventHooks ) ;
598- }
599-
600- const versionPolicyConfigFile : string = path . join ( this . _commonRushConfigFolder ,
601- RushConstants . versionPoliciesFileName ) ;
602- this . _versionPolicyConfiguration = new VersionPolicyConfiguration ( versionPolicyConfigFile ) ;
603-
604- this . _projects = [ ] ;
605- this . _projectsByName = new Map < string , RushConfigurationProject > ( ) ;
606-
607- // We sort the projects array in alphabetical order. This ensures that the packages
608- // are processed in a deterministic order by the various Rush algorithms.
609- const sortedProjectJsons : IRushConfigurationProjectJson [ ] = rushConfigurationJson . projects . slice ( 0 ) ;
610- sortedProjectJsons . sort (
611- ( a : IRushConfigurationProjectJson , b : IRushConfigurationProjectJson ) => a . packageName . localeCompare ( b . packageName )
612- ) ;
613-
614- const tempNamesByProject : Map < IRushConfigurationProjectJson , string >
615- = RushConfiguration . _generateTempNamesForProjects ( sortedProjectJsons ) ;
616-
617- for ( const projectJson of sortedProjectJsons ) {
618- const tempProjectName : string = tempNamesByProject . get ( projectJson ) ;
619- const project : RushConfigurationProject = new RushConfigurationProject ( projectJson , this , tempProjectName ) ;
620- this . _projects . push ( project ) ;
621- if ( this . _projectsByName . get ( project . packageName ) ) {
622- throw new Error ( `The project name "${ project . packageName } " was specified more than once`
623- + ` in the rush.json configuration file.` ) ;
624- }
625- this . _projectsByName . set ( project . packageName , project ) ;
626- }
627-
628- for ( const project of this . _projects ) {
629- project . cyclicDependencyProjects . forEach ( ( cyclicDependencyProject : string ) => {
630- if ( ! this . getProjectByName ( cyclicDependencyProject ) ) {
631- throw new Error ( `In rush.json, the "${ cyclicDependencyProject } " project does not exist,`
632- + ` but was referenced by the cyclicDependencyProjects for ${ project . packageName } ` ) ;
633- }
634- } ) ;
635-
636- // Compute the downstream dependencies within the list of Rush projects.
637- this . _populateDownstreamDependencies ( project . packageJson . dependencies , project . packageName ) ;
638- this . _populateDownstreamDependencies ( project . packageJson . devDependencies , project . packageName ) ;
639- }
640-
641- // Example: "./common/config/rush/pinnedVersions.json"
642- const pinnedVersionsFile : string = path . join ( this . commonRushConfigFolder , RushConstants . pinnedVersionsFilename ) ;
643- this . _pinnedVersions = PinnedVersionsConfiguration . tryLoadFromFile ( pinnedVersionsFile ) ;
644- }
645645}
0 commit comments