Skip to content

Commit ded4068

Browse files
Add RUSH_QUIET_MODE environment variable equivalent to --quiet (#5700)
* Initial plan * Add RUSH_QUIET_MODE environment variable Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> * Remove erroneous @microsoft/rush-lib change file Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> * Deduplicate quiet mode handling in install-run-rush; fix reset() method Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> * Update rush-lib.api.md with quietMode and RUSH_QUIET_MODE API entries Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> * Fix RUSH_QUIET_MODE position in rush-lib.api.md to match source declaration order Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent ac69e07 commit ded4068

6 files changed

Lines changed: 70 additions & 7 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"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`",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

common/reviews/api/rush-lib.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ export class EnvironmentConfiguration {
239239
static parseBooleanEnvironmentVariable(name: string, value: string | undefined): boolean | undefined;
240240
static get pnpmStorePathOverride(): string | undefined;
241241
static get pnpmVerifyStoreIntegrity(): boolean | undefined;
242+
static get quietMode(): boolean;
242243
static reset(): void;
243244
static get rushGlobalFolderOverride(): string | undefined;
244245
static get rushTempFolderOverride(): string | undefined;
@@ -273,6 +274,7 @@ export const EnvironmentVariableNames: {
273274
readonly _RUSH_LIB_PATH: "_RUSH_LIB_PATH";
274275
readonly RUSH_INVOKED_FOLDER: "RUSH_INVOKED_FOLDER";
275276
readonly RUSH_INVOKED_ARGS: "RUSH_INVOKED_ARGS";
277+
readonly RUSH_QUIET_MODE: "RUSH_QUIET_MODE";
276278
};
277279

278280
// @beta

libraries/rush-lib/src/api/EnvironmentConfiguration.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,14 @@ export const EnvironmentVariableNames = {
245245
* Other lifecycle scripts should not make assumptions about Rush's command line syntax
246246
* if Rush did not explicitly pass along command-line parameters to their process.
247247
*/
248-
RUSH_INVOKED_ARGS: 'RUSH_INVOKED_ARGS'
248+
RUSH_INVOKED_ARGS: 'RUSH_INVOKED_ARGS',
249+
250+
/**
251+
* When set to `1` or `true`, this environment variable is equivalent to passing the `--quiet` flag
252+
* to `rush`, `rushx`, and `install-run-rush.ts`. It suppresses informational startup messages
253+
* while preserving error output.
254+
*/
255+
RUSH_QUIET_MODE: 'RUSH_QUIET_MODE'
249256
} as const;
250257

251258
/**
@@ -293,6 +300,8 @@ export class EnvironmentConfiguration {
293300

294301
private static _tarBinaryPath: string | undefined;
295302

303+
private static _quietMode: boolean = false;
304+
296305
/**
297306
* If true, the environment configuration has been validated and initialized.
298307
*/
@@ -456,6 +465,15 @@ export class EnvironmentConfiguration {
456465
return EnvironmentConfiguration._tarBinaryPath;
457466
}
458467

468+
/**
469+
* If `true`, Rush will suppress informational startup messages, equivalent to passing `--quiet`.
470+
* See {@link EnvironmentVariableNames.RUSH_QUIET_MODE}
471+
*/
472+
public static get quietMode(): boolean {
473+
EnvironmentConfiguration._ensureValidated();
474+
return EnvironmentConfiguration._quietMode;
475+
}
476+
459477
/**
460478
* The front-end RushVersionSelector relies on `RUSH_GLOBAL_FOLDER`, so its value must be read before
461479
* `EnvironmentConfiguration` is initialized (and actually before the correct version of `EnvironmentConfiguration`
@@ -606,6 +624,20 @@ export class EnvironmentConfiguration {
606624
break;
607625
}
608626

627+
case EnvironmentVariableNames.RUSH_QUIET_MODE: {
628+
// Accept both "true"/"false" string values and the standard "1"/"0" values
629+
if (value === 'true' || value === 'false') {
630+
EnvironmentConfiguration._quietMode = value === 'true';
631+
} else {
632+
EnvironmentConfiguration._quietMode =
633+
EnvironmentConfiguration.parseBooleanEnvironmentVariable(
634+
EnvironmentVariableNames.RUSH_QUIET_MODE,
635+
value
636+
) ?? false;
637+
}
638+
break;
639+
}
640+
609641
case EnvironmentVariableNames.RUSH_PARALLELISM:
610642
case EnvironmentVariableNames.RUSH_PREVIEW_VERSION:
611643
case EnvironmentVariableNames.RUSH_VARIANT:
@@ -661,7 +693,9 @@ export class EnvironmentConfiguration {
661693
*/
662694
public static reset(): void {
663695
EnvironmentConfiguration._rushTempFolderOverride = undefined;
664-
696+
EnvironmentConfiguration._quietMode = false;
697+
EnvironmentConfiguration._gitBinaryPath = undefined;
698+
EnvironmentConfiguration._tarBinaryPath = undefined;
665699
EnvironmentConfiguration._hasBeenValidated = false;
666700
}
667701

libraries/rush-lib/src/cli/RushCommandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { InitSubspaceAction } from './actions/InitSubspaceAction';
6363
import { RushAlerts } from '../utilities/RushAlerts';
6464
import { initializeDotEnv } from '../logic/dotenv';
6565
import { measureAsyncFn } from '../utilities/performance';
66+
import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration';
6667

6768
/**
6869
* Options for `RushCommandLineParser`.
@@ -220,6 +221,12 @@ export class RushCommandLineParser extends CommandLineParser {
220221
}
221222
}
222223

224+
const quietModeValue: string | undefined =
225+
process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
226+
if (quietModeValue === '1' || quietModeValue === 'true') {
227+
return true;
228+
}
229+
223230
return false;
224231
}
225232

libraries/rush-lib/src/cli/RushXCommandLine.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ export class RushXCommandLine {
295295
}
296296
}
297297

298+
const quietModeValue: string | undefined =
299+
process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
300+
if (quietModeValue === '1' || quietModeValue === 'true') {
301+
quiet = true;
302+
}
303+
298304
if (!commandName) {
299305
help = true;
300306
}

libraries/rush-lib/src/scripts/install-run-rush.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { ILogger } from '../utilities/npmrcUtilities';
1616

1717
const PACKAGE_NAME: string = '@microsoft/rush';
1818
const RUSH_PREVIEW_VERSION: string = 'RUSH_PREVIEW_VERSION';
19+
const RUSH_QUIET_MODE: string = 'RUSH_QUIET_MODE';
1920
const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE: 'INSTALL_RUN_RUSH_LOCKFILE_PATH' =
2021
'INSTALL_RUN_RUSH_LOCKFILE_PATH';
2122

@@ -72,7 +73,9 @@ function _run(): void {
7273
}
7374

7475
let commandFound: boolean = false;
75-
let logger: ILogger = { info: console.log, error: console.error };
76+
77+
const quietModeEnvValue: string | undefined = process.env[RUSH_QUIET_MODE];
78+
let quiet: boolean = quietModeEnvValue === '1' || quietModeEnvValue === 'true';
7679

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

108+
const logger: ILogger = quiet
109+
? { info: () => {}, error: console.error }
110+
: { info: console.log, error: console.error };
111+
108112
runWithErrorAndStatusCode(logger, () => {
109113
const version: string = _getRushVersion(logger);
110114
logger.info(`The ${RUSH_JSON_FILENAME} configuration requests Rush version ${version}`);

0 commit comments

Comments
 (0)