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
28 changes: 28 additions & 0 deletions apps/rush-lib/src/api/EnvironmentConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const enum EnvironmentVariableNames {
*/
RUSH_ALLOW_UNSUPPORTED_NODEJS = 'RUSH_ALLOW_UNSUPPORTED_NODEJS',

/**
* Setting this environment variable overrides the value of `allowWarningsInSuccessfulBuild`
* in the `command-line.json` configuration file. Specify `1` to allow warnings in a successful build,
* or `0` to disallow them. (See the comments in the command-line.json file for more information).
*/
RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD = 'RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD',

/**
* This variable selects a specific installation variant for Rush to use when installing
* and linking package dependencies.
Expand Down Expand Up @@ -156,6 +163,8 @@ export class EnvironmentConfiguration {

private static _allowUnsupportedNodeVersion: boolean = false;

private static _allowWarningsInSuccessfulBuild: boolean = false;

private static _pnpmStorePathOverride: string | undefined;

private static _rushGlobalFolderOverride: string | undefined;
Expand Down Expand Up @@ -197,6 +206,16 @@ export class EnvironmentConfiguration {
return EnvironmentConfiguration._allowUnsupportedNodeVersion;
}

/**
* Setting this environment variable overrides the value of `allowWarningsInSuccessfulBuild`
* in the `command-line.json` configuration file. Specify `1` to allow warnings in a successful build,
* or `0` to disallow them. (See the comments in the command-line.json file for more information).
*/
public static get allowWarningsInSuccessfulBuild(): boolean {
EnvironmentConfiguration._ensureInitialized();
return EnvironmentConfiguration._allowWarningsInSuccessfulBuild;
}

/**
* An override for the PNPM store path, if `pnpmStore` configuration is set to 'path'
* See {@link EnvironmentVariableNames.RUSH_PNPM_STORE_PATH}
Expand Down Expand Up @@ -312,6 +331,15 @@ export class EnvironmentConfiguration {
break;
}

case EnvironmentVariableNames.RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD: {
EnvironmentConfiguration._allowWarningsInSuccessfulBuild =
EnvironmentConfiguration.parseBooleanEnvironmentVariable(
EnvironmentVariableNames.RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD,
value
) ?? false;
break;
}

case EnvironmentVariableNames.RUSH_PNPM_STORE_PATH: {
EnvironmentConfiguration._pnpmStorePathOverride =
value && !options.doNotNormalizePaths
Expand Down
6 changes: 5 additions & 1 deletion apps/rush-lib/src/cli/RushCommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { Telemetry } from '../logic/Telemetry';
import { RushGlobalFolder } from '../api/RushGlobalFolder';
import { NodeJsCompatibility } from '../logic/NodeJsCompatibility';
import { SetupAction } from './actions/SetupAction';
import { EnvironmentConfiguration } from '../api/EnvironmentConfiguration';

/**
* Options for `RushCommandLineParser`.
Expand Down Expand Up @@ -248,6 +249,9 @@ export class RushCommandLineParser extends CommandLineParser {

this._validateCommandLineConfigCommand(command);

const overrideAllowWarnings: boolean =
this.rushConfiguration && EnvironmentConfiguration.allowWarningsInSuccessfulBuild;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this.rushConfiguration && here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was working with Emmanuel on this one... this is early enough in the command line parser that it's possible rush.json doesn't exist (for example, we might be preparing to run "rush init" in an empty folder).

Because we don't know what command we are about to run, it's possible that rush configuration is undefined at this point, and if rush configuration is undefined then the EnvironmentConfiguration is not initialized.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes a assumption that rushConfiguration !== undefined implies that EnvironmentConfiguration is initialized, which seems brittle. (Is that guaranteed? Is that the only way it can be initialized?)

Maybe a simpler solution is to ensure that the EnvironmentConfiguration is initialized before we access it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was chatting more about this offline and I agree, and I think what we might do is:

  1. Change EnvironmentConfiguration so that it initializes itself if it hasn't been initialized yet.
  2. Continue to initialize (without reset) at key narrow paths like RushConfiguration, where it makes sense to capture and error on the majority of possible configuration errors.
  3. Possibly some other small tweaks to the error behavior of EnvironmentConfiguration.

These changes (especially #3) probably deserve their own dedicated review, so if it's cool with you we can make those changes in a follow-up PR.


switch (command.commandKind) {
case RushConstants.bulkCommandKind:
this.addAction(
Expand All @@ -269,7 +273,7 @@ export class RushCommandLineParser extends CommandLineParser {
ignoreMissingScript: command.ignoreMissingScript || false,
ignoreDependencyOrder: command.ignoreDependencyOrder || false,
incremental: command.incremental || false,
allowWarningsInSuccessfulBuild: !!command.allowWarningsInSuccessfulBuild,
allowWarningsInSuccessfulBuild: overrideAllowWarnings || !!command.allowWarningsInSuccessfulBuild,

watchForChanges: command.watchForChanges || false,
disableBuildCache: command.disableBuildCache || false
Expand Down
11 changes: 11 additions & 0 deletions common/changes/@microsoft/rush/AllowWarnings_2021-05-21-18-05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD environment variable",
"type": "none"
}
],
"packageName": "@microsoft/rush",
"email": "EmmanuelOluyomi@users.noreply.github.com"
}
1 change: 1 addition & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const enum DependencyType {
export const enum EnvironmentVariableNames {
RUSH_ABSOLUTE_SYMLINKS = "RUSH_ABSOLUTE_SYMLINKS",
RUSH_ALLOW_UNSUPPORTED_NODEJS = "RUSH_ALLOW_UNSUPPORTED_NODEJS",
RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD = "RUSH_ALLOW_WARNINGS_IN_SUCCESSFUL_BUILD",
RUSH_BUILD_CACHE_CREDENTIAL = "RUSH_BUILD_CACHE_CREDENTIAL",
RUSH_BUILD_CACHE_ENABLED = "RUSH_BUILD_CACHE_ENABLED",
RUSH_BUILD_CACHE_WRITE_ALLOWED = "RUSH_BUILD_CACHE_WRITE_ALLOWED",
Expand Down