From d39cb4868ecdfc71d2f11b6ba49f2f79f32ce1eb Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:53:09 -0800 Subject: [PATCH] Rename SubspaceConfiguration -> SubspacesConfugration to clarify that it represents the overall subspaces.json, not the configuration of one subspace --- common/reviews/api/rush-lib.api.md | 10 +++++----- .../rush-lib/src/api/RushConfiguration.ts | 18 +++++++++--------- ...figuration.ts => SubspacesConfiguration.ts} | 18 +++++++++--------- .../src/cli/RushPnpmCommandLineParser.ts | 2 +- .../src/cli/actions/BaseInstallAction.ts | 2 +- .../rush-lib/src/cli/actions/UpdateAction.ts | 2 +- .../cli/scriptActions/PhasedScriptAction.ts | 2 +- libraries/rush-lib/src/index.ts | 2 +- .../rush-lib/src/logic/PackageJsonUpdater.ts | 4 ++-- .../src/logic/base/BaseInstallManager.ts | 8 ++++---- .../installManager/WorkspaceInstallManager.ts | 6 +++--- .../pnpm/SubspacePnpmfileConfiguration.ts | 8 ++++---- .../src/test/__snapshots__/script.test.ts.snap | 2 +- 13 files changed, 42 insertions(+), 42 deletions(-) rename libraries/rush-lib/src/api/{SubspaceConfiguration.ts => SubspacesConfiguration.ts} (86%) diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 88ed12d1347..bd8a7745fbf 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -1143,10 +1143,10 @@ export class RushConfiguration { readonly shrinkwrapFilename: string; get shrinkwrapFilePhrase(): string; // @beta - readonly subspaceConfiguration?: SubspaceConfiguration; - // @beta get subspaceNames(): Iterable; // @beta + readonly subspacesConfiguration?: SubspacesConfiguration; + // @beta subspaceShrinkwrapFilenames(subspaceName: string): string; readonly suppressNodeLtsWarning: boolean; // @beta @@ -1332,7 +1332,7 @@ export class RushUserConfiguration { } // @beta -export class SubspaceConfiguration { +export class SubspacesConfiguration { // (undocumented) static belongsInSubspace(rushProject: RushConfigurationProject, subspaceName: string): boolean; readonly enabled: boolean; @@ -1341,9 +1341,9 @@ export class SubspaceConfiguration { readonly subspaceJsonFilePath: string; readonly subspaceNames: Set; // (undocumented) - static tryLoadFromConfigurationFile(subspaceJsonFilePath: string): SubspaceConfiguration | undefined; + static tryLoadFromConfigurationFile(subspaceJsonFilePath: string): SubspacesConfiguration | undefined; // (undocumented) - static tryLoadFromDefaultLocation(rushConfiguration: RushConfiguration): SubspaceConfiguration | undefined; + static tryLoadFromDefaultLocation(rushConfiguration: RushConfiguration): SubspacesConfiguration | undefined; } // @public diff --git a/libraries/rush-lib/src/api/RushConfiguration.ts b/libraries/rush-lib/src/api/RushConfiguration.ts index 031e2a8c986..59de6a47ff6 100644 --- a/libraries/rush-lib/src/api/RushConfiguration.ts +++ b/libraries/rush-lib/src/api/RushConfiguration.ts @@ -42,7 +42,7 @@ import schemaJson from '../schemas/rush.schema.json'; import type * as DependencyAnalyzerModuleType from '../logic/DependencyAnalyzer'; import type { PackageManagerOptionsConfigurationBase } from '../logic/base/BasePackageManagerOptionsConfiguration'; import { CustomTipsConfiguration } from './CustomTipsConfiguration'; -import { SubspaceConfiguration } from './SubspaceConfiguration'; +import { SubspacesConfiguration } from './SubspacesConfiguration'; const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0'; const DEFAULT_BRANCH: string = 'main'; @@ -353,7 +353,7 @@ export class RushConfiguration { * The object that specifies subspace configurations if they are provided in the rush workspace. * @beta */ - public readonly subspaceConfiguration?: SubspaceConfiguration; + public readonly subspacesConfiguration?: SubspacesConfiguration; /** * The filename of the variant dependency data file. By default this is @@ -630,7 +630,7 @@ export class RushConfiguration { this.ensureConsistentVersions = !!rushConfigurationJson.ensureConsistentVersions; // Try getting a subspace configuration - this.subspaceConfiguration = SubspaceConfiguration.tryLoadFromDefaultLocation(this); + this.subspacesConfiguration = SubspacesConfiguration.tryLoadFromDefaultLocation(this); this._rushProjectsBySubspaceName = new Map(); this._subspaceConfigFolderBySubspace = new Map(); @@ -885,7 +885,7 @@ export class RushConfiguration { ); } this._projectsByName.set(project.packageName, project); - if (this.subspaceConfiguration?.enabled) { + if (this.subspacesConfiguration?.enabled) { let subspaceName: string; if (projectJson.subspaceName) { subspaceName = projectJson.subspaceName; @@ -1176,7 +1176,7 @@ export class RushConfiguration { let subspaceConfigFolder: string = `${this.commonFolder}/config/subspaces/${subspaceName}`; if ( !FileSystem.exists(subspaceConfigFolder) && - this.subspaceConfiguration?.splitWorkspaceCompatibility + this.subspacesConfiguration?.splitWorkspaceCompatibility ) { // Look in the project folder const rushProjectsInSubspace: RushConfigurationProject[] | undefined = @@ -1258,10 +1258,10 @@ export class RushConfiguration { if (!this._projects) { this._initializeAndValidateLocalProjects(); } - if (!this.subspaceConfiguration) { + if (!this.subspacesConfiguration) { throw new Error(`Subspaces is not enabled!`); } - if (!this.subspaceConfiguration.isValidSubspaceName(subspaceName)) { + if (!this.subspacesConfiguration.isValidSubspaceName(subspaceName)) { throw new Error(`Received an invalid subspace name: ${subspaceName}`); } } @@ -1350,7 +1350,7 @@ export class RushConfiguration { * Returns the subspace name that a project belongs to. Returns undefined if subspaces is not enabled. */ public getProjectSubspace(project: RushConfigurationProject): string | undefined { - if (!this.subspaceConfiguration?.enabled) { + if (!this.subspacesConfiguration?.enabled) { return undefined; } if (!this._projects) { @@ -1367,7 +1367,7 @@ export class RushConfiguration { * Returns a list of unique subspace names that the given projects belong to */ public getProjectsSubspaceSet(projects: Set): string[] { - if (!this.subspaceConfiguration?.enabled) { + if (!this.subspacesConfiguration?.enabled) { return []; } if (!this._projects) { diff --git a/libraries/rush-lib/src/api/SubspaceConfiguration.ts b/libraries/rush-lib/src/api/SubspacesConfiguration.ts similarity index 86% rename from libraries/rush-lib/src/api/SubspaceConfiguration.ts rename to libraries/rush-lib/src/api/SubspacesConfiguration.ts index dddb8cbd426..9779573fe4b 100644 --- a/libraries/rush-lib/src/api/SubspaceConfiguration.ts +++ b/libraries/rush-lib/src/api/SubspacesConfiguration.ts @@ -18,7 +18,7 @@ export const SUBSPACE_NAME_REGEXP: RegExp = /^[a-z0-9]*([-+_a-z0-9]+)*$/; * This represents the JSON data structure for the "subspaces.json" configuration file. * See subspace.schema.json for documentation. */ -interface ISubspaceConfigurationJson { +interface ISubspacesConfigurationJson { enabled: boolean; splitWorkspaceCompatibility?: boolean; subspaceNames: string[]; @@ -29,7 +29,7 @@ interface ISubspaceConfigurationJson { * configuration file. * @beta */ -export class SubspaceConfiguration { +export class SubspacesConfiguration { private static _jsonSchema: JsonSchema = JsonSchema.fromLoadedObject(schemaJson); /** @@ -52,7 +52,7 @@ export class SubspaceConfiguration { */ public readonly subspaceNames: Set; - private constructor(configuration: Readonly, subspaceJsonFilePath: string) { + private constructor(configuration: Readonly, subspaceJsonFilePath: string) { this.subspaceJsonFilePath = subspaceJsonFilePath; this.enabled = configuration.enabled; this.splitWorkspaceCompatibility = !!configuration.splitWorkspaceCompatibility; @@ -79,27 +79,27 @@ export class SubspaceConfiguration { public static tryLoadFromConfigurationFile( subspaceJsonFilePath: string - ): SubspaceConfiguration | undefined { - let configuration: Readonly | undefined; + ): SubspacesConfiguration | undefined { + let configuration: Readonly | undefined; try { - configuration = JsonFile.loadAndValidate(subspaceJsonFilePath, SubspaceConfiguration._jsonSchema); + configuration = JsonFile.loadAndValidate(subspaceJsonFilePath, SubspacesConfiguration._jsonSchema); } catch (e) { if (!FileSystem.isNotExistError(e)) { throw e; } } if (configuration) { - return new SubspaceConfiguration(configuration, subspaceJsonFilePath); + return new SubspacesConfiguration(configuration, subspaceJsonFilePath); } } public static tryLoadFromDefaultLocation( rushConfiguration: RushConfiguration - ): SubspaceConfiguration | undefined { + ): SubspacesConfiguration | undefined { const commonRushConfigFolder: string = rushConfiguration.getCommonRushConfigFolder(); if (commonRushConfigFolder) { const subspaceJsonLocation: string = `${commonRushConfigFolder}/${RushConstants.subspacesConfigFilename}`; - return SubspaceConfiguration.tryLoadFromConfigurationFile(subspaceJsonLocation); + return SubspacesConfiguration.tryLoadFromConfigurationFile(subspaceJsonLocation); } } diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 2613fc62842..5fb5cdb1ae2 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -447,7 +447,7 @@ export class RushPnpmCommandLineParser { } private async _doRushUpdateAsync(): Promise { - if (this._rushConfiguration.subspaceConfiguration?.enabled) { + if (this._rushConfiguration.subspacesConfiguration?.enabled) { this._terminal.writeLine(Colors.red('Rush Pnpm is currently unsupported with subspaces.')); throw new AlreadyReportedError(); } diff --git a/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts b/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts index f62afd721ca..98ef0ea3616 100644 --- a/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts @@ -115,7 +115,7 @@ export abstract class BaseInstallAction extends BaseRushAction { let subspaceNames: string[] | undefined; if ( installManagerOptions.pnpmFilterArguments.length && - this.rushConfiguration.subspaceConfiguration?.enabled + this.rushConfiguration.subspacesConfiguration?.enabled ) { const selectedProjects: Set | undefined = await this._selectionParameters?.getSelectedProjectsAsync(this._terminal); diff --git a/libraries/rush-lib/src/cli/actions/UpdateAction.ts b/libraries/rush-lib/src/cli/actions/UpdateAction.ts index d6bdefbc68c..c966ab791b9 100644 --- a/libraries/rush-lib/src/cli/actions/UpdateAction.ts +++ b/libraries/rush-lib/src/cli/actions/UpdateAction.ts @@ -33,7 +33,7 @@ export class UpdateAction extends BaseInstallAction { parser }); - if (this.rushConfiguration?.subspaceConfiguration?.enabled) { + if (this.rushConfiguration?.subspacesConfiguration?.enabled) { // Partial update is supported only when subspaces is enabled. this._selectionParameters = new SelectionParameterSet(this.rushConfiguration, this, { // Include lockfile processing since this expands the selection, and we need to select diff --git a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts index ce2ac67214c..dec3fb89610 100644 --- a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts +++ b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts @@ -265,7 +265,7 @@ export class PhasedScriptAction extends BaseScriptAction { // TODO: Replace with last-install.flag when "rush link" and "rush unlink" are removed const lastLinkFlag: LastLinkFlag = LastLinkFlagFactory.getCommonTempFlag(this.rushConfiguration); // Only check for a valid link flag when subspaces is not enabled - if (!lastLinkFlag.isValid() && !this.rushConfiguration.subspaceConfiguration?.enabled) { + if (!lastLinkFlag.isValid() && !this.rushConfiguration.subspacesConfiguration?.enabled) { const useWorkspaces: boolean = this.rushConfiguration.pnpmOptions && this.rushConfiguration.pnpmOptions.useWorkspaces; if (useWorkspaces) { diff --git a/libraries/rush-lib/src/index.ts b/libraries/rush-lib/src/index.ts index 6f7415cde29..be57668c1e3 100644 --- a/libraries/rush-lib/src/index.ts +++ b/libraries/rush-lib/src/index.ts @@ -10,7 +10,7 @@ export { ApprovedPackagesPolicy } from './api/ApprovedPackagesPolicy'; export { RushConfiguration, ITryFindRushJsonLocationOptions } from './api/RushConfiguration'; -export { SubspaceConfiguration } from './api/SubspaceConfiguration'; +export { SubspacesConfiguration } from './api/SubspacesConfiguration'; export { IPackageManagerOptionsJsonBase, diff --git a/libraries/rush-lib/src/logic/PackageJsonUpdater.ts b/libraries/rush-lib/src/logic/PackageJsonUpdater.ts index 8a515c78f85..96990aca522 100644 --- a/libraries/rush-lib/src/logic/PackageJsonUpdater.ts +++ b/libraries/rush-lib/src/logic/PackageJsonUpdater.ts @@ -242,7 +242,7 @@ export class PackageJsonUpdater { } if (!skipUpdate) { - if (this._rushConfiguration.subspaceConfiguration?.enabled) { + if (this._rushConfiguration.subspacesConfiguration?.enabled) { const subspaceNames: string[] = this._rushConfiguration.getProjectsSubspaceSet( new Set(options.projects) ); @@ -272,7 +272,7 @@ export class PackageJsonUpdater { } if (!skipUpdate) { - if (this._rushConfiguration.subspaceConfiguration?.enabled) { + if (this._rushConfiguration.subspacesConfiguration?.enabled) { const subspaceNames: string[] = this._rushConfiguration.getProjectsSubspaceSet( new Set(options.projects) ); diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts index a021424577e..b9683bde66e 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts @@ -90,7 +90,7 @@ export abstract class BaseInstallManager { ); this.subspaceInstallFlags = new Map(); - if (rushConfiguration.subspaceConfiguration?.enabled) { + if (rushConfiguration.subspacesConfiguration?.enabled) { for (const subspaceName of rushConfiguration.subspaceNames) { this.subspaceInstallFlags.set( subspaceName, @@ -128,7 +128,7 @@ export abstract class BaseInstallManager { // Ensure that subspaces is enabled const subspaceName: string | undefined = this.options.subspaceName; - if (this.rushConfiguration.subspaceConfiguration?.enabled && !this.options.subspaceName) { + if (this.rushConfiguration.subspacesConfiguration?.enabled && !this.options.subspaceName) { // Temporarily ensure that a subspace is provided // eslint-disable-next-line no-console console.log(); @@ -139,9 +139,9 @@ export abstract class BaseInstallManager { ) ); throw new AlreadyReportedError(); - } else if (this.options.subspaceName && !this.rushConfiguration.subspaceConfiguration?.enabled) { + } else if (this.options.subspaceName && !this.rushConfiguration.subspacesConfiguration?.enabled) { // Ensure that subspaces is enabled - if (!this.rushConfiguration.subspaceConfiguration?.enabled) { + if (!this.rushConfiguration.subspacesConfiguration?.enabled) { // eslint-disable-next-line no-console console.log(); // eslint-disable-next-line no-console diff --git a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index 8644b7e7222..2c04aec7b32 100644 --- a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -33,7 +33,7 @@ import { EnvironmentConfiguration } from '../../api/EnvironmentConfiguration'; import { ShrinkwrapFileFactory } from '../ShrinkwrapFileFactory'; import { BaseProjectShrinkwrapFile } from '../base/BaseProjectShrinkwrapFile'; import { type CustomTipId, type ICustomTipInfo, PNPM_CUSTOM_TIPS } from '../../api/CustomTipsConfiguration'; -import { SubspaceConfiguration } from '../../api/SubspaceConfiguration'; +import { SubspacesConfiguration } from '../../api/SubspacesConfiguration'; import type { PnpmShrinkwrapFile } from '../pnpm/PnpmShrinkwrapFile'; import { objectsAreDeepEqual } from '../../utilities/objectUtilities'; @@ -152,7 +152,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { // Loop through the projects and add them to the workspace file. While we're at it, also validate that // referenced workspace projects are valid, and check if the shrinkwrap file is already up-to-date. for (const rushProject of this.rushConfiguration.projects) { - if (subspaceName && !SubspaceConfiguration.belongsInSubspace(rushProject, subspaceName)) { + if (subspaceName && !SubspacesConfiguration.belongsInSubspace(rushProject, subspaceName)) { // skip processing any project that isn't in this subspace continue; } @@ -271,7 +271,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { // get the relative path from common temp folder to repo root folder const relativeFromTempFolderToRootFolder: string = path.relative(commonTempFolder, rushJsonFolder); for (const rushProject of this.rushConfiguration.projects) { - if (subspaceName && !SubspaceConfiguration.belongsInSubspace(rushProject, subspaceName)) { + if (subspaceName && !SubspacesConfiguration.belongsInSubspace(rushProject, subspaceName)) { // skip processing any project that isn't in this subspace continue; } diff --git a/libraries/rush-lib/src/logic/pnpm/SubspacePnpmfileConfiguration.ts b/libraries/rush-lib/src/logic/pnpm/SubspacePnpmfileConfiguration.ts index 7e6e174b580..3a844b11c92 100644 --- a/libraries/rush-lib/src/logic/pnpm/SubspacePnpmfileConfiguration.ts +++ b/libraries/rush-lib/src/logic/pnpm/SubspacePnpmfileConfiguration.ts @@ -9,7 +9,7 @@ import { subspacePnpmfileShimFilename, scriptsFolderPath } from '../../utilities import type { IPnpmfileContext, ISubspacePnpmfileShimSettings, IWorkspaceProjectInfo } from './IPnpmfile'; import type { RushConfiguration } from '../../api/RushConfiguration'; import type { PnpmPackageManager } from '../../api/packageManager/PnpmPackageManager'; -import { SubspaceConfiguration } from '../../api/SubspaceConfiguration'; +import { SubspacesConfiguration } from '../../api/SubspacesConfiguration'; import { RushConstants } from '../RushConstants'; /** @@ -86,9 +86,9 @@ export class SubspacePnpmfileConfiguration { projectRelativeFolder, packageVersion: packageJson.version }; - (SubspaceConfiguration.belongsInSubspace(project, subspaceName) ? subspaceProjects : workspaceProjects)[ - packageName - ] = workspaceProjectInfo; + (SubspacesConfiguration.belongsInSubspace(project, subspaceName) + ? subspaceProjects + : workspaceProjects)[packageName] = workspaceProjectInfo; } const settings: ISubspacePnpmfileShimSettings = { diff --git a/libraries/rush-sdk/src/test/__snapshots__/script.test.ts.snap b/libraries/rush-sdk/src/test/__snapshots__/script.test.ts.snap index 27342158e6b..20e28cfdb3e 100644 --- a/libraries/rush-sdk/src/test/__snapshots__/script.test.ts.snap +++ b/libraries/rush-sdk/src/test/__snapshots__/script.test.ts.snap @@ -49,7 +49,7 @@ Loaded @microsoft/rush-lib from process.env._RUSH_LIB_PATH 'RushProjectConfiguration', 'RushSession', 'RushUserConfiguration', - 'SubspaceConfiguration', + 'SubspacesConfiguration', 'VersionPolicy', 'VersionPolicyConfiguration', 'VersionPolicyDefinitionName',