Skip to content

Commit

Permalink
Grab the currently installed variant in a few cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton committed Sep 20, 2024
1 parent 41272f0 commit 1259fdc
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 24 deletions.
13 changes: 9 additions & 4 deletions libraries/rush-lib/src/api/Variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ export const VARIANT_PARAMETER: ICommandLineStringDefinition = {
environmentVariable: EnvironmentVariableNames.RUSH_VARIANT
};

export function getVariant(
export async function getVariantAsync(
variantsParameter: CommandLineStringParameter,
rushConfiguration: RushConfiguration
): string | undefined {
const variant: string | undefined = variantsParameter.value;
rushConfiguration: RushConfiguration,
defaultToCurrentlyInstalledVariant: boolean
): Promise<string | undefined> {
let variant: string | undefined = variantsParameter.value;
if (variant && !rushConfiguration.variants.has(variant)) {
throw new Error(`The variant "${variant}" is not defined in ${RushConstants.rushJsonFilename}`);
}

if (!variant && defaultToCurrentlyInstalledVariant) {
variant = await rushConfiguration.getCurrentlyInstalledVariantAsync();
}

return variant;
}
10 changes: 7 additions & 3 deletions libraries/rush-lib/src/cli/actions/AddAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type IPackageJsonUpdaterRushAddOptions,
SemVerStyle
} from '../../logic/PackageJsonUpdaterTypes';
import { getVariant, VARIANT_PARAMETER } from '../../api/Variants';
import { getVariantAsync, VARIANT_PARAMETER } from '../../api/Variants';

export class AddAction extends BaseAddAndRemoveAction {
protected readonly _allFlag: CommandLineFlagParameter;
Expand Down Expand Up @@ -94,7 +94,7 @@ export class AddAction extends BaseAddAndRemoveAction {
this._variantParameter = this.defineStringParameter(VARIANT_PARAMETER);
}

public getUpdateOptions(): IPackageJsonUpdaterRushAddOptions {
public async getUpdateOptionsAsync(): Promise<IPackageJsonUpdaterRushAddOptions> {
const projects: RushConfigurationProject[] = super.getProjects();

if (this._caretFlag.value && this._exactFlag.value) {
Expand Down Expand Up @@ -157,7 +157,11 @@ export class AddAction extends BaseAddAndRemoveAction {
packagesToAdd.push({ packageName, version, rangeStyle });
}

const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
true
);

return {
projects: projects,
Expand Down
5 changes: 3 additions & 2 deletions libraries/rush-lib/src/cli/actions/BaseAddAndRemoveAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export abstract class BaseAddAndRemoveAction extends BaseRushAction {
});
}

protected abstract getUpdateOptions(): IPackageJsonUpdaterRushBaseUpdateOptions;
protected abstract getUpdateOptionsAsync(): Promise<IPackageJsonUpdaterRushBaseUpdateOptions>;

protected getProjects(): RushConfigurationProject[] {
if (this._allFlag.value) {
Expand Down Expand Up @@ -83,6 +83,7 @@ export abstract class BaseAddAndRemoveAction extends BaseRushAction {
this.rushGlobalFolder
);

await updater.doRushUpdateAsync(this.getUpdateOptions());
const updateOptions: IPackageJsonUpdaterRushBaseUpdateOptions = await this.getUpdateOptionsAsync();
await updater.doRushUpdateAsync(updateOptions);
}
}
8 changes: 6 additions & 2 deletions libraries/rush-lib/src/cli/actions/BaseInstallAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { RushConstants } from '../../logic/RushConstants';
import { SUBSPACE_LONG_ARG_NAME, type SelectionParameterSet } from '../parsing/SelectionParameterSet';
import type { RushConfigurationProject } from '../../api/RushConfigurationProject';
import type { Subspace } from '../../api/Subspace';
import { getVariant, VARIANT_PARAMETER } from '../../api/Variants';
import { getVariantAsync, VARIANT_PARAMETER } from '../../api/Variants';

/**
* Temporary data structure used by `BaseInstallAction.runAsync()`
Expand Down Expand Up @@ -169,7 +169,11 @@ export abstract class BaseInstallAction extends BaseRushAction {
}
}

const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
false
);
if (selectedSubspaces) {
// Check each subspace for version inconsistencies
for (const subspace of selectedSubspaces) {
Expand Down
8 changes: 6 additions & 2 deletions libraries/rush-lib/src/cli/actions/CheckAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Colorize, type ITerminal } from '@rushstack/terminal';
import type { RushCommandLineParser } from '../RushCommandLineParser';
import { BaseRushAction } from './BaseRushAction';
import { VersionMismatchFinder } from '../../logic/versionMismatch/VersionMismatchFinder';
import { getVariant, VARIANT_PARAMETER } from '../../api/Variants';
import { getVariantAsync, VARIANT_PARAMETER } from '../../api/Variants';

export class CheckAction extends BaseRushAction {
private readonly _terminal: ITerminal;
Expand Down Expand Up @@ -60,7 +60,11 @@ export class CheckAction extends BaseRushAction {

const currentlyInstalledVariant: string | undefined =
await this.rushConfiguration.getCurrentlyInstalledVariantAsync();
const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
true
);
if (!variant && currentlyInstalledVariant) {
this._terminal.writeWarningLine(
Colorize.yellow(
Expand Down
8 changes: 6 additions & 2 deletions libraries/rush-lib/src/cli/actions/InstallAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { RushCommandLineParser } from '../RushCommandLineParser';
import { SelectionParameterSet } from '../parsing/SelectionParameterSet';
import type { RushConfigurationProject } from '../../api/RushConfigurationProject';
import type { Subspace } from '../../api/Subspace';
import { getVariant } from '../../api/Variants';
import { getVariantAsync } from '../../api/Variants';

export class InstallAction extends BaseInstallAction {
private readonly _checkOnlyParameter: CommandLineFlagParameter;
Expand Down Expand Up @@ -62,7 +62,11 @@ export class InstallAction extends BaseInstallAction {
(await this._selectionParameters?.getSelectedProjectsAsync(this._terminal)) ??
new Set(this.rushConfiguration.projects);

const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
false
);

return {
debug: this.parser.isDebug,
Expand Down
10 changes: 7 additions & 3 deletions libraries/rush-lib/src/cli/actions/RemoveAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
IPackageForRushRemove,
IPackageJsonUpdaterRushRemoveOptions
} from '../../logic/PackageJsonUpdaterTypes';
import { getVariant, VARIANT_PARAMETER } from '../../api/Variants';
import { getVariantAsync, VARIANT_PARAMETER } from '../../api/Variants';

export class RemoveAction extends BaseAddAndRemoveAction {
protected readonly _allFlag: CommandLineFlagParameter;
Expand Down Expand Up @@ -54,7 +54,7 @@ export class RemoveAction extends BaseAddAndRemoveAction {
this._variantParameter = this.defineStringParameter(VARIANT_PARAMETER);
}

public getUpdateOptions(): IPackageJsonUpdaterRushRemoveOptions {
public async getUpdateOptionsAsync(): Promise<IPackageJsonUpdaterRushRemoveOptions> {
const projects: RushConfigurationProject[] = super.getProjects();

const packagesToRemove: IPackageForRushRemove[] = [];
Expand Down Expand Up @@ -83,7 +83,11 @@ export class RemoveAction extends BaseAddAndRemoveAction {
packagesToRemove.push({ packageName });
}

const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
true
);

return {
projects: projects,
Expand Down
8 changes: 6 additions & 2 deletions libraries/rush-lib/src/cli/actions/UpdateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { RushCommandLineParser } from '../RushCommandLineParser';
import { SelectionParameterSet } from '../parsing/SelectionParameterSet';
import type { RushConfigurationProject } from '../../api/RushConfigurationProject';
import type { Subspace } from '../../api/Subspace';
import { getVariant } from '../../api/Variants';
import { getVariantAsync } from '../../api/Variants';

export class UpdateAction extends BaseInstallAction {
private readonly _fullParameter: CommandLineFlagParameter;
Expand Down Expand Up @@ -85,7 +85,11 @@ export class UpdateAction extends BaseInstallAction {
(await this._selectionParameters?.getSelectedProjectsAsync(this._terminal)) ??
new Set(this.rushConfiguration.projects);

const variant: string | undefined = getVariant(this._variantParameter, this.rushConfiguration);
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
false
);

return {
debug: this.parser.isDebug,
Expand Down
10 changes: 6 additions & 4 deletions libraries/rush-lib/src/cli/actions/UpgradeInteractiveAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BaseRushAction } from './BaseRushAction';

import type * as PackageJsonUpdaterType from '../../logic/PackageJsonUpdater';
import type * as InteractiveUpgraderType from '../../logic/InteractiveUpgrader';
import { getVariant, VARIANT_PARAMETER } from '../../api/Variants';
import { getVariantAsync, VARIANT_PARAMETER } from '../../api/Variants';

export class UpgradeInteractiveAction extends BaseRushAction {
private _makeConsistentFlag: CommandLineFlagParameter;
Expand Down Expand Up @@ -62,9 +62,11 @@ export class UpgradeInteractiveAction extends BaseRushAction {
this.rushConfiguration
);

const variant: string | undefined =
getVariant(this._variantParameter, this.rushConfiguration) ??
(await this.rushConfiguration.getCurrentlyInstalledVariantAsync());
const variant: string | undefined = await getVariantAsync(
this._variantParameter,
this.rushConfiguration,
true
);
const shouldMakeConsistent: boolean =
this.rushConfiguration.defaultSubspace.shouldEnsureConsistentVersions(variant) ||
this._makeConsistentFlag.value;
Expand Down

0 comments on commit 1259fdc

Please sign in to comment.