Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Add support for RUSH_OVERRIDE_PATH environment variable #5003

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

witcher112
Copy link
Contributor

Summary

While contributing to Rush, I've discovered that there's no easy way to test it with my company's repo as we heavily use VSCode tasks.json that hardcode "rush" command for many operations (so using method described in https://rushjs.io/pages/contributing/#testing-rush-builds is not possible as it would involve replacing all "rush" occurrences with "testrush").

Details

This PR introduces support for the RUSH_OVERRIDE_PATH environment variable, which can specify the path to the custom Rush installation. This way, contributors can override the Rush installation used by the repository and test any changes that are being made to Rush, even if the rush command is hardcoded somewhere.

If RUSH_OVERRIDE_PATH is present, the user is presented with a warning similar to the one displayed when using the RUSH_PREVIEW_VERSION environment variable.

image

How it was tested

I've set RUSH_OVERRIDE_PATH that points to custom Rush installation and executed node apps\rush\bin\rush build --help - seems to be working.

Impacted documentation

https://rushjs.io/pages/contributing

}
}

if (semver.lt(version, '3.0.20')) {
// In old versions, requiring the entry point invoked the command-line parser immediately,
// so fail if "rushx" or "rush-pnpm" was used
RushCommandSelector.failIfNotInvokedAsRush(version);
require(path.join(expectedRushPath, 'node_modules', '@microsoft', 'rush', 'lib', 'rush'));
require(path.join(rushPath, 'lib', 'rush'));
} else if (semver.lt(version, '4.0.0')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is checked twice now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks like it's checked in a few places.

"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add support for overriding rush with custom installation path through RUSH_OVERRIDE_PATH environment variable",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"comment": "Add support for overriding rush with custom installation path through RUSH_OVERRIDE_PATH environment variable",
"comment": "Add support for overriding Rush with a custom installation path through a new `RUSH_OVERRIDE_PATH` environment variable. This environment variable is intended to be used for development of Rush itself.",

installIsValid = await installMarker.isValidAsync();
if (installIsValid) {
console.log('Another process performed the installation.');
if (semver.lt(version, '4.0.0')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (semver.lt(version, '4.0.0')) {
if (isLegacyRushVersion) {


const overrideVersion: string = overridePackageJson.version;

// If we are overriding with an older Rush that doesn't understand the RUSH_OVERRIDE_PATH variable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If we are overriding with an older Rush that doesn't understand the RUSH_OVERRIDE_PATH variable,
// If we are overriding with an older version of Rush that doesn't understand the RUSH_OVERRIDE_PATH variable,

const overridePackageJson: IPackageJson | undefined = PackageJsonLookup.instance.tryLoadPackageJsonFor(overridePath);

if (overridePackageJson === undefined) {
terminal.writeErrorLine(`Cannot use version specified with "RUSH_OVERRIDE_PATH" environment variable as it doesn't point to valid Rush package: ${overridePath}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
terminal.writeErrorLine(`Cannot use version specified with "RUSH_OVERRIDE_PATH" environment variable as it doesn't point to valid Rush package: ${overridePath}`);
terminal.writeErrorLine(`Unable to load the a copy of `rush-lib` specified with ` +
`the "${EnvironmentVariableNames.RUSH_OVERRIDE_PATH}" environment ` +
`variable: ${overridePath}`);

// If we are overriding with an older Rush that doesn't understand the RUSH_OVERRIDE_PATH variable,
// then unset it.
if (semver.lt(overrideVersion, '5.141.0')) {
delete process.env[EnvironmentVariableNames.RUSH_OVERRIDE_PATH];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just always delete the env var here?


PrintUtilities.printMessageInBox(
[
`WARNING! THE "RUSH_OVERRIDE_PATH" ENVIRONMENT VARIABLE IS SET.`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`WARNING! THE "RUSH_OVERRIDE_PATH" ENVIRONMENT VARIABLE IS SET.`,
`WARNING! THE "${EnvironmentVariableNames.RUSH_OVERRIDE_PATH}" ENVIRONMENT VARIABLE IS SET.`,

...(
configuration
? [
`The rush.json configuration asks for: @${configuration.rushVersion}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`The rush.json configuration asks for: @${configuration.rushVersion}`,
`The ${RushConstants.rushJsonFilename} configuration asks for v${configuration.rushVersion}`,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants