1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | const path = require("path");
|
6 | const semver = require("semver");
|
7 | const node_core_library_1 = require("@microsoft/node-core-library");
|
8 | const Utilities_1 = require("@microsoft/rush-lib/lib/utilities/Utilities");
|
9 | const rush_lib_1 = require("@microsoft/rush-lib");
|
10 | const RushCommandSelector_1 = require("./RushCommandSelector");
|
11 | const MAX_INSTALL_ATTEMPTS = 3;
|
12 | class RushVersionSelector {
|
13 | constructor(currentPackageVersion) {
|
14 | this._rushGlobalFolder = new rush_lib_1._RushGlobalFolder();
|
15 | this._currentPackageVersion = currentPackageVersion;
|
16 | }
|
17 | ensureRushVersionInstalled(version, configuration, executeOptions) {
|
18 | const isLegacyRushVersion = semver.lt(version, '4.0.0');
|
19 | const expectedRushPath = path.join(this._rushGlobalFolder.nodeSpecificPath, `rush-${version}`);
|
20 | const installMarker = new rush_lib_1._LastInstallFlag(expectedRushPath, { node: process.versions.node });
|
21 | let installPromise = Promise.resolve();
|
22 | if (!installMarker.isValid()) {
|
23 | installPromise = installPromise.then(() => {
|
24 |
|
25 | console.log(`Rush version ${version} is not currently installed. Installing...`);
|
26 | const resourceName = `rush-${version}`;
|
27 | console.log(`Trying to acquire lock for ${resourceName}`);
|
28 | return node_core_library_1.LockFile.acquire(expectedRushPath, resourceName)
|
29 | .then((lock) => {
|
30 | if (installMarker.isValid()) {
|
31 | console.log('Another process performed the installation.');
|
32 | }
|
33 | else {
|
34 | Utilities_1.Utilities.installPackageInDirectory({
|
35 | directory: expectedRushPath,
|
36 | packageName: isLegacyRushVersion ? '@microsoft/rush' : '@microsoft/rush-lib',
|
37 | version: version,
|
38 | tempPackageTitle: 'rush-local-install',
|
39 | maxInstallAttempts: MAX_INSTALL_ATTEMPTS,
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | commonRushConfigFolder: configuration ? configuration.commonRushConfigFolder : undefined,
|
47 | suppressOutput: true
|
48 | });
|
49 | console.log(`Successfully installed Rush version ${version} in ${expectedRushPath}.`);
|
50 |
|
51 | installMarker.create();
|
52 | lock.release();
|
53 | }
|
54 | });
|
55 | });
|
56 | }
|
57 | return installPromise.then(() => {
|
58 | if (semver.lt(version, '3.0.20')) {
|
59 |
|
60 |
|
61 | RushCommandSelector_1.RushCommandSelector.failIfNotInvokedAsRush(version);
|
62 | require(path.join(expectedRushPath, 'node_modules', '@microsoft', 'rush', 'lib', 'rush'));
|
63 | }
|
64 | else if (semver.lt(version, '4.0.0')) {
|
65 |
|
66 |
|
67 | RushCommandSelector_1.RushCommandSelector.failIfNotInvokedAsRush(version);
|
68 | require(path.join(expectedRushPath, 'node_modules', '@microsoft', 'rush', 'lib', 'start'));
|
69 | }
|
70 | else {
|
71 |
|
72 |
|
73 | const rushCliEntrypoint = require(path.join(expectedRushPath, 'node_modules', '@microsoft', 'rush-lib', 'lib', 'index'));
|
74 | RushCommandSelector_1.RushCommandSelector.execute(this._currentPackageVersion, rushCliEntrypoint, executeOptions);
|
75 | }
|
76 | });
|
77 | }
|
78 | }
|
79 | exports.RushVersionSelector = RushVersionSelector;
|
80 |
|
\ | No newline at end of file |