import { NodeJsCompatibility } from '@microsoft/rush-lib/lib/logic/NodeJsCompatibility' ; if ( NodeJsCompatibility . reportAncientIncompatibleVersion ( ) ) { process . exit ( 1 ) ; } const alreadyReportedNodeTooNewError = NodeJsCompatibility . warnAboutVersionTooNew ( { isRushLib : false , alreadyReportedNodeTooNewError : false } ) ; import colors from 'colors/safe' ; import * as os from 'os' ; import * as semver from 'semver' ; import { Text , PackageJsonLookup } from '@rushstack/node-core-library' ; import { EnvironmentVariableNames } from '@microsoft/rush-lib' ; import * as rushLib from '@microsoft/rush-lib' ; import { RushCommandSelector } from './RushCommandSelector' ; import { RushVersionSelector } from './RushVersionSelector' ; import { MinimalRushConfiguration } from './MinimalRushConfiguration' ; const configuration = MinimalRushConfiguration . loadFromDefaultLocation ( ) ; const currentPackageVersion = PackageJsonLookup . loadOwnPackageJson ( __dirname ) . version ; let rushVersionToLoad = undefined ; const previewVersion = process . env [ EnvironmentVariableNames . RUSH_PREVIEW_VERSION ] ; if ( previewVersion ) { if ( ! semver . valid ( previewVersion , false ) ) { console . error ( colors . red ( `Invalid value for RUSH_PREVIEW_VERSION environment variable: "${ previewVersion }"` ) ) ; process . exit ( 1 ) ; } rushVersionToLoad = previewVersion ; const lines = [ ] ; lines . push ( `*********************************************************************` , `* WARNING! THE "RUSH_PREVIEW_VERSION" ENVIRONMENT VARIABLE IS SET.  *` , `*                                                                   *` , `* You are previewing Rush version:        ${ Text . padEnd ( previewVersion , 25 ) } *` ) ; if ( configuration ) { lines . push ( `* The rush.json configuration asks for:   ${ Text . padEnd ( configuration . rushVersion , 25 ) } *` ) ; } lines . push ( `*                                                                   *` , `* To restore the normal behavior, unset the RUSH_PREVIEW_VERSION    *` , `* environment variable.                                             *` , `*********************************************************************` ) ; console . error ( lines . map ( ( line ) => colors . black ( colors . bgYellow ( line ) ) ) . join ( os . EOL ) ) ; } else if ( configuration ) { rushVersionToLoad = configuration . rushVersion ; } if ( rushVersionToLoad && semver . lt ( rushVersionToLoad , '5.0.0-dev.18' ) ) { delete process . env [ EnvironmentVariableNames . RUSH_PREVIEW_VERSION ] ; } const isManaged = ! ! configuration ; const launchOptions = { isManaged , alreadyReportedNodeTooNewError } ; if ( rushVersionToLoad && rushVersionToLoad !== currentPackageVersion ) { const versionSelector = new RushVersionSelector ( currentPackageVersion ) ; versionSelector . ensureRushVersionInstalledAsync ( rushVersionToLoad , configuration , launchOptions ) . catch ( ( error ) => { console . log ( colors . red ( 'Error: ' + error . message ) ) ; } ) ; } else { RushCommandSelector . execute ( currentPackageVersion , rushLib , launchOptions ) ; }