Skip to content

Commit 61da545

Browse files
committed
Implement RUSH_PREVIEW_VERSION
1 parent cdae48c commit 61da545

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

apps/rush/src/start.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See LICENSE in the project root for license information.
33

44
import * as colors from 'colors';
5+
import * as os from 'os';
56
import * as semver from 'semver';
67

78
const nodeVersion: string = process.versions.node;
@@ -35,10 +36,7 @@ else if (!semver.satisfies(nodeVersion, '^6.9.0')
3536
import * as path from 'path';
3637
import { JsonFile, IPackageJson } from '@microsoft/node-core-library';
3738

38-
import {
39-
RushConfiguration,
40-
Rush
41-
} from '@microsoft/rush-lib';
39+
import { Rush, EnvironmentVariableNames } from '@microsoft/rush-lib';
4240
import { Utilities } from '@microsoft/rush-lib/lib/utilities/Utilities';
4341

4442
import { MinimalRushConfiguration } from './MinimalRushConfiguration';
@@ -47,7 +45,7 @@ import { RushVersionSelector } from './RushVersionSelector';
4745
const RUSH_PURGE_OPTION_NAME: string = 'purge';
4846

4947
if (process.argv[2] === RUSH_PURGE_OPTION_NAME) {
50-
const rushDirectory: string = path.join(RushConfiguration.getHomeDirectory(), '.rush');
48+
const rushDirectory: string = path.join(Utilities.getHomeDirectory(), '.rush');
5149
console.log(`Deleting ${rushDirectory} directory...`);
5250
Utilities.dangerouslyDeletePath(rushDirectory);
5351
console.log('done');
@@ -56,23 +54,48 @@ if (process.argv[2] === RUSH_PURGE_OPTION_NAME) {
5654
const configuration: MinimalRushConfiguration | undefined = MinimalRushConfiguration.loadFromDefaultLocation();
5755
const currentPackageJson: IPackageJson = JsonFile.load(path.join(__dirname, '..', 'package.json'));
5856

57+
let rushVersionToLoad: string | undefined = undefined;
58+
59+
const previewVersion: string | undefined = process.env[EnvironmentVariableNames.RUSH_PREVIEW_VERSION];
60+
let usingPreviewVersion: boolean = false;
61+
62+
if (previewVersion && semver.valid(previewVersion, false)) {
63+
rushVersionToLoad = previewVersion;
64+
usingPreviewVersion = true;
65+
} else if (configuration) {
66+
rushVersionToLoad = configuration.rushVersion;
67+
}
68+
69+
if (usingPreviewVersion) {
70+
console.error(colors.yellow(
71+
os.EOL + os.EOL +
72+
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' + os.EOL +
73+
' WARNING! THE "RUSH_PREVIEW_VERSION" ENVIRONMENT VARIABLE IS SET.' + os.EOL +
74+
' You are previewing version 1.2.3 of Rush as an experiment.' + os.EOL +
75+
' The rush.json configuration for this repo requests version 3.2.1.' + os.EOL +
76+
' To restore the normal behavior, unset the RUSH_PREVIEW_VERSION' + os.EOL +
77+
' environment variable.' + os.EOL +
78+
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' +
79+
os.EOL + os.EOL
80+
));
81+
}
82+
5983
// If we're inside a repo folder, and it's requesting a different version, then use the RushVersionManager to
6084
// install it
61-
if (configuration && configuration.rushVersion !== currentPackageJson.version) {
85+
if (rushVersionToLoad && rushVersionToLoad !== currentPackageJson.version) {
6286
const versionSelector: RushVersionSelector = new RushVersionSelector(
63-
configuration.homeFolder,
6487
currentPackageJson.version
6588
);
66-
versionSelector.ensureRushVersionInstalled(configuration.rushVersion)
89+
versionSelector.ensureRushVersionInstalled(rushVersionToLoad)
6790
.catch((error: Error) => {
6891
console.log(colors.red('Error: ' + error.message));
6992
});
7093
} else {
7194
// Otherwise invoke the rush-lib that came with this rush package
72-
const isManaged: boolean = !!configuration && configuration.rushVersion === currentPackageJson.version;
73-
Rush.launch(
74-
currentPackageJson.version,
75-
isManaged // Rush is "managed" if its version and configuration are dictated by a repo's rush.json
76-
);
95+
96+
// Rush is "managed" if its version and configuration are dictated by a repo's rush.json
97+
const isManaged: boolean = !!configuration;
98+
99+
Rush.launch(currentPackageJson.version, isManaged);
77100
}
78101
}

0 commit comments

Comments
 (0)