Repository navigation
Expand file tree
/
Copy pathstart.ts
More file actions
102 lines (80 loc) · 3.99 KB
/
Copy pathstart.ts
File metadata and controls
102 lines (80 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
// We're using a path-based import here to minimize the amount of code that is evaluated before
// we check to see if the Node.js version is too old. If, for whatever reason, Rush crashes with
// an old Node.js version when evaluating one of the more complex imports, we'll at least
// shown a meaningful error message.
// eslint-disable-next-line import/order
import { NodeJsCompatibility } from '@microsoft/rush-lib/lib/logic/NodeJsCompatibility';
if (NodeJsCompatibility.reportAncientIncompatibleVersion()) {
// The Node.js version is known to have serious incompatibilities. In that situation, the user
// should downgrade Rush to an older release that supported their Node.js version.
process.exit(1);
}
const alreadyReportedNodeTooNewError: boolean = NodeJsCompatibility.warnAboutVersionTooNew({
isRushLib: false,
alreadyReportedNodeTooNewError: false
});
import * as os from 'node:os';
import * as semver from 'semver';
import { Text, PackageJsonLookup } from '@rushstack/node-core-library';
import { Colorize, ConsoleTerminalProvider, type ITerminalProvider } from '@rushstack/terminal';
import { EnvironmentVariableNames } from '@microsoft/rush-lib';
import type { ILaunchOptions } from '@microsoft/rush-lib';
import * as rushLib from '@microsoft/rush-lib';
import { MinimalRushConfiguration } from './MinimalRushConfiguration';
import { launchRushFrontendAsync } from './RushFrontend';
import { getRushPreviewVersion } from './RushPreviewVersion';
// Load the configuration
const configuration: MinimalRushConfiguration | undefined =
MinimalRushConfiguration.loadFromDefaultLocation();
const currentPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname).version;
let rushVersionToLoad: string | undefined = undefined;
const previewVersion: string | undefined = getRushPreviewVersion();
if (previewVersion) {
if (!semver.valid(previewVersion, false)) {
console.error(
Colorize.red(`Invalid value for RUSH_PREVIEW_VERSION environment variable: "${previewVersion}"`)
);
process.exit(1);
}
rushVersionToLoad = previewVersion;
const lines: string[] = [];
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) => Colorize.black(Colorize.yellowBackground(line))).join(os.EOL));
} else if (configuration) {
rushVersionToLoad = configuration.rushVersion;
}
// If we are previewing an older Rush that doesn't understand the RUSH_PREVIEW_VERSION variable,
// then unset it.
if (rushVersionToLoad && semver.lt(rushVersionToLoad, '5.0.0-dev.18')) {
delete process.env[EnvironmentVariableNames.RUSH_PREVIEW_VERSION];
}
// Rush is "managed" if its version and configuration are dictated by a repo's rush.json
const isManaged: boolean = !!configuration;
const terminalProvider: ITerminalProvider = new ConsoleTerminalProvider();
const launchOptions: ILaunchOptions = { isManaged, alreadyReportedNodeTooNewError, terminalProvider };
launchRushFrontendAsync({
currentPackageVersion,
rushVersionToLoad,
configuration,
launchOptions,
currentRushLib: rushLib
}).catch((error: Error) => {
process.exitCode = 1;
console.error(Colorize.red(`Error: ${error.message}`));
});