Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add RUSH_QUIET_MODE environment variable that, when set to `1` or `true`, is equivalent to passing `--quiet` for `rush`, `rushx`, and `install-run-rush.ts`",
"type": "minor"
}
],
"packageName": "@microsoft/rush"
}
2 changes: 2 additions & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export class EnvironmentConfiguration {
static parseBooleanEnvironmentVariable(name: string, value: string | undefined): boolean | undefined;
static get pnpmStorePathOverride(): string | undefined;
static get pnpmVerifyStoreIntegrity(): boolean | undefined;
static get quietMode(): boolean;
static reset(): void;
static get rushGlobalFolderOverride(): string | undefined;
static get rushTempFolderOverride(): string | undefined;
Expand Down Expand Up @@ -273,6 +274,7 @@ export const EnvironmentVariableNames: {
readonly _RUSH_LIB_PATH: "_RUSH_LIB_PATH";
readonly RUSH_INVOKED_FOLDER: "RUSH_INVOKED_FOLDER";
readonly RUSH_INVOKED_ARGS: "RUSH_INVOKED_ARGS";
readonly RUSH_QUIET_MODE: "RUSH_QUIET_MODE";
};

// @beta
Expand Down
38 changes: 36 additions & 2 deletions libraries/rush-lib/src/api/EnvironmentConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ export const EnvironmentVariableNames = {
* Other lifecycle scripts should not make assumptions about Rush's command line syntax
* if Rush did not explicitly pass along command-line parameters to their process.
*/
RUSH_INVOKED_ARGS: 'RUSH_INVOKED_ARGS'
RUSH_INVOKED_ARGS: 'RUSH_INVOKED_ARGS',

/**
* When set to `1` or `true`, this environment variable is equivalent to passing the `--quiet` flag
* to `rush`, `rushx`, and `install-run-rush.ts`. It suppresses informational startup messages
* while preserving error output.
*/
RUSH_QUIET_MODE: 'RUSH_QUIET_MODE'
} as const;

/**
Expand Down Expand Up @@ -293,6 +300,8 @@ export class EnvironmentConfiguration {

private static _tarBinaryPath: string | undefined;

private static _quietMode: boolean = false;

/**
* If true, the environment configuration has been validated and initialized.
*/
Expand Down Expand Up @@ -456,6 +465,15 @@ export class EnvironmentConfiguration {
return EnvironmentConfiguration._tarBinaryPath;
}

/**
* If `true`, Rush will suppress informational startup messages, equivalent to passing `--quiet`.
* See {@link EnvironmentVariableNames.RUSH_QUIET_MODE}
*/
public static get quietMode(): boolean {
EnvironmentConfiguration._ensureValidated();
return EnvironmentConfiguration._quietMode;
}

/**
* The front-end RushVersionSelector relies on `RUSH_GLOBAL_FOLDER`, so its value must be read before
* `EnvironmentConfiguration` is initialized (and actually before the correct version of `EnvironmentConfiguration`
Expand Down Expand Up @@ -606,6 +624,20 @@ export class EnvironmentConfiguration {
break;
}

case EnvironmentVariableNames.RUSH_QUIET_MODE: {
// Accept both "true"/"false" string values and the standard "1"/"0" values
if (value === 'true' || value === 'false') {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we also accepting true/false?

EnvironmentConfiguration._quietMode = value === 'true';
} else {
EnvironmentConfiguration._quietMode =
EnvironmentConfiguration.parseBooleanEnvironmentVariable(
EnvironmentVariableNames.RUSH_QUIET_MODE,
value
) ?? false;
}
break;
}

case EnvironmentVariableNames.RUSH_PARALLELISM:
case EnvironmentVariableNames.RUSH_PREVIEW_VERSION:
case EnvironmentVariableNames.RUSH_VARIANT:
Expand Down Expand Up @@ -661,7 +693,9 @@ export class EnvironmentConfiguration {
*/
public static reset(): void {
EnvironmentConfiguration._rushTempFolderOverride = undefined;

EnvironmentConfiguration._quietMode = false;
EnvironmentConfiguration._gitBinaryPath = undefined;
EnvironmentConfiguration._tarBinaryPath = undefined;
EnvironmentConfiguration._hasBeenValidated = false;
}

Expand Down
7 changes: 7 additions & 0 deletions libraries/rush-lib/src/cli/RushCommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { InitSubspaceAction } from './actions/InitSubspaceAction';
import { RushAlerts } from '../utilities/RushAlerts';
import { initializeDotEnv } from '../logic/dotenv';
import { measureAsyncFn } from '../utilities/performance';
import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration';

/**
* Options for `RushCommandLineParser`.
Expand Down Expand Up @@ -220,6 +221,12 @@ export class RushCommandLineParser extends CommandLineParser {
}
}

const quietModeValue: string | undefined =
Copy link
Member

Choose a reason for hiding this comment

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

Leave a comment about why this is checked outside of EnvironmentConfiguration.

process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
if (quietModeValue === '1' || quietModeValue === 'true') {
return true;
}

return false;
}

Expand Down
6 changes: 6 additions & 0 deletions libraries/rush-lib/src/cli/RushXCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ export class RushXCommandLine {
}
}

const quietModeValue: string | undefined =
Copy link
Member

Choose a reason for hiding this comment

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

Leave a comment about why this is checked outside of EnvironmentConfiguration.

process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
if (quietModeValue === '1' || quietModeValue === 'true') {
quiet = true;
}

if (!commandName) {
help = true;
}
Expand Down
14 changes: 9 additions & 5 deletions libraries/rush-lib/src/scripts/install-run-rush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { ILogger } from '../utilities/npmrcUtilities';

const PACKAGE_NAME: string = '@microsoft/rush';
const RUSH_PREVIEW_VERSION: string = 'RUSH_PREVIEW_VERSION';
const RUSH_QUIET_MODE: string = 'RUSH_QUIET_MODE';
Comment on lines 18 to +19
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
const RUSH_PREVIEW_VERSION: string = 'RUSH_PREVIEW_VERSION';
const RUSH_QUIET_MODE: string = 'RUSH_QUIET_MODE';
const RUSH_PREVIEW_VERSION_ENV_VAR_NAME: string = 'RUSH_PREVIEW_VERSION';
const RUSH_QUIET_MODE_ENV_VAR_NAME: string = 'RUSH_QUIET_MODE';

Also can we get the type from EnvironmentConfiguration to ensure that the value is correct?

const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE: 'INSTALL_RUN_RUSH_LOCKFILE_PATH' =
'INSTALL_RUN_RUSH_LOCKFILE_PATH';

Expand Down Expand Up @@ -72,7 +73,9 @@ function _run(): void {
}

let commandFound: boolean = false;
let logger: ILogger = { info: console.log, error: console.error };

const quietModeEnvValue: string | undefined = process.env[RUSH_QUIET_MODE];
Copy link
Member

Choose a reason for hiding this comment

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

Leave a comment about why this is checked outside of EnvironmentConfiguration.

let quiet: boolean = quietModeEnvValue === '1' || quietModeEnvValue === 'true';

for (const arg of packageBinArgs) {
if (arg === '-q' || arg === '--quiet') {
Expand All @@ -82,10 +85,7 @@ function _run(): void {
// To maintain the same user experience, the install-run* scripts pass along this
// flag but also use it to suppress any diagnostic information normally printed
// to stdout.
logger = {
info: () => {},
error: console.error
};
quiet = true;
} else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
// We either found something that looks like a command (i.e. - doesn't start with a "-"),
// or we found the -h/--help flag, which can be run without a command
Expand All @@ -105,6 +105,10 @@ function _run(): void {
process.exit(1);
}

const logger: ILogger = quiet
? { info: () => {}, error: console.error }
: { info: console.log, error: console.error };

runWithErrorAndStatusCode(logger, () => {
const version: string = _getRushVersion(logger);
logger.info(`The ${RUSH_JSON_FILENAME} configuration requests Rush version ${version}`);
Expand Down
Loading