Skip to content

Commit 72c8531

Browse files
Copilotdmichon-msft
andcommitted
address Ian's post-merge feedback on RUSH_QUIET_MODE handling from PR #5700
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/rushstack/sessions/df565d26-3d49-47c6-8291-66cfb9e2c946
1 parent 1a4e287 commit 72c8531

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,10 @@ export class EnvironmentConfiguration {
625625
}
626626

627627
case EnvironmentVariableNames.RUSH_QUIET_MODE: {
628-
// Accept both "true"/"false" string values and the standard "1"/"0" values
628+
// Accept "true"/"false" string values in addition to the standard "1"/"0" values because
629+
// install-run-rush.ts, RushCommandLineParser, and RushXCommandLine read this variable
630+
// directly from process.env (before EnvironmentConfiguration is initialized) and also
631+
// accept "true" as a truthy value. The two code paths must agree on accepted values.
629632
if (value === 'true' || value === 'false') {
630633
EnvironmentConfiguration._quietMode = value === 'true';
631634
} else {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +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';
66+
import { EnvironmentConfiguration, EnvironmentVariableNames } from '../api/EnvironmentConfiguration';
6767

6868
/**
6969
* Options for `RushCommandLineParser`.
@@ -221,10 +221,18 @@ export class RushCommandLineParser extends CommandLineParser {
221221
}
222222
}
223223

224-
const quietModeValue: string | undefined =
225-
process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
226-
if (quietModeValue === '1' || quietModeValue === 'true') {
227-
return true;
224+
// If EnvironmentConfiguration has already been initialized, use it to get the quiet mode value.
225+
// Otherwise, read directly from process.env because this method may be called before dotenv
226+
// files are loaded and EnvironmentConfiguration is validated (e.g. from Rush.launch()).
227+
if (EnvironmentConfiguration.hasBeenValidated) {
228+
if (EnvironmentConfiguration.quietMode) {
229+
return true;
230+
}
231+
} else {
232+
const quietModeValue: string | undefined = process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
233+
if (quietModeValue === '1' || quietModeValue === 'true') {
234+
return true;
235+
}
228236
}
229237

230238
return false;

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

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

298+
// This method is called at the start of launchRushXAsync(), before RushConfiguration.loadFromConfigurationFile()
299+
// initializes EnvironmentConfiguration. We must read process.env directly here.
298300
const quietModeValue: string | undefined =
299301
process.env[EnvironmentVariableNames.RUSH_QUIET_MODE];
300302
if (quietModeValue === '1' || quietModeValue === 'true') {

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

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

1717
const PACKAGE_NAME: string = '@microsoft/rush';
18-
const RUSH_PREVIEW_VERSION: string = 'RUSH_PREVIEW_VERSION';
19-
const RUSH_QUIET_MODE: string = 'RUSH_QUIET_MODE';
18+
const RUSH_PREVIEW_VERSION_ENV_VAR_NAME: string = 'RUSH_PREVIEW_VERSION';
19+
const RUSH_QUIET_MODE_ENV_VAR_NAME: string = 'RUSH_QUIET_MODE';
2020
const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE: 'INSTALL_RUN_RUSH_LOCKFILE_PATH' =
2121
'INSTALL_RUN_RUSH_LOCKFILE_PATH';
2222

2323
function _getRushVersion(logger: ILogger): string {
24-
const rushPreviewVersion: string | undefined = process.env[RUSH_PREVIEW_VERSION];
24+
const rushPreviewVersion: string | undefined = process.env[RUSH_PREVIEW_VERSION_ENV_VAR_NAME];
2525
if (rushPreviewVersion !== undefined) {
26-
logger.info(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
26+
logger.info(
27+
`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION_ENV_VAR_NAME}=${rushPreviewVersion}`
28+
);
2729
return rushPreviewVersion;
2830
}
2931

@@ -74,7 +76,9 @@ function _run(): void {
7476

7577
let commandFound: boolean = false;
7678

77-
const quietModeEnvValue: string | undefined = process.env[RUSH_QUIET_MODE];
79+
// This is a bootstrap script that runs before rush-lib is loaded. EnvironmentConfiguration is not
80+
// available here, so we read the environment variable directly.
81+
const quietModeEnvValue: string | undefined = process.env[RUSH_QUIET_MODE_ENV_VAR_NAME];
7882
let quiet: boolean = quietModeEnvValue === '1' || quietModeEnvValue === 'true';
7983

8084
for (const arg of packageBinArgs) {

0 commit comments

Comments
 (0)