Skip to content

Commit 246167e

Browse files
committed
chore: read subspace from cwd
1 parent ceba916 commit 246167e

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ Object {
11591159
Object {
11601160
"description": "The name of the subspace to use for the bridge package.",
11611161
"environmentVariable": undefined,
1162-
"kind": "String",
1162+
"kind": "StringList",
11631163
"longName": "--subspace",
11641164
"required": false,
11651165
"shortName": undefined,

libraries/rush-lib/src/cli/actions/BridgePackageAction.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import type { CommandLineStringParameter } from '@rushstack/ts-command-line';
4+
import type { CommandLineStringListParameter, CommandLineStringParameter } from '@rushstack/ts-command-line';
55

66
import type { RushCommandLineParser } from '../RushCommandLineParser';
77
import { BaseHotlinkPackageAction } from './BaseHotlinkPackageAction';
88
import type { HotlinkManager } from '../../utilities/HotlinkManager';
99
import { BRIDGE_PACKAGE_ACTION_NAME, LINK_PACKAGE_ACTION_NAME } from '../../utilities/actionNameConstants';
1010
import { RushConstants } from '../../logic/RushConstants';
1111
import type { Subspace } from '../../api/Subspace';
12+
import { Async } from '@rushstack/node-core-library';
13+
import type { RushConfigurationProject } from '../../api/RushConfigurationProject';
1214

1315
export class BridgePackageAction extends BaseHotlinkPackageAction {
1416
private readonly _versionParameter: CommandLineStringParameter;
15-
private readonly _subspaceNameParameter: CommandLineStringParameter;
17+
private readonly _subspaceNamesParameter: CommandLineStringListParameter;
1618

1719
public constructor(parser: RushCommandLineParser) {
1820
super({
@@ -34,24 +36,55 @@ export class BridgePackageAction extends BaseHotlinkPackageAction {
3436
parameterLongName: '--version',
3537
argumentName: 'SEMVER_RANGE',
3638
defaultValue: '*',
37-
description:
38-
'Specify which installed versions should be hotlinked.'
39+
description: 'Specify which installed versions should be hotlinked.'
3940
});
4041

41-
this._subspaceNameParameter = this.defineStringParameter({
42+
this._subspaceNamesParameter = this.defineStringListParameter({
4243
parameterLongName: '--subspace',
44+
required: false,
4345
argumentName: 'SUBSPACE',
44-
defaultValue: RushConstants.defaultSubspaceName,
4546
description: 'The name of the subspace to use for the hotlinked package.'
4647
});
4748
}
4849

50+
private _getSubspacesToBridgeAsync(): Set<Subspace> {
51+
const subspaceToBridge: Set<Subspace> = new Set();
52+
const subspaceNames: readonly string[] = this._subspaceNamesParameter.values;
53+
54+
if (subspaceNames.length > 0) {
55+
for (const subspaceName of subspaceNames) {
56+
const subspace: Subspace | undefined = this.rushConfiguration.tryGetSubspace(subspaceName);
57+
if (!subspace) {
58+
throw new Error(
59+
`The subspace "${subspaceName}" was not found in "${RushConstants.rushPackageName}"`
60+
);
61+
}
62+
subspaceToBridge.add(subspace);
63+
}
64+
} else {
65+
const currentProject: RushConfigurationProject | undefined =
66+
this.rushConfiguration.tryGetProjectForPath(process.cwd());
67+
if (!currentProject) {
68+
throw new Error(`No Rush project was found in the current working directory`);
69+
}
70+
subspaceToBridge.add(currentProject.subspace);
71+
}
72+
73+
return subspaceToBridge;
74+
}
75+
4976
protected async hotlinkPackageAsync(
5077
linkedPackagePath: string,
5178
hotlinkManager: HotlinkManager
5279
): Promise<void> {
5380
const version: string = this._versionParameter.value!;
54-
const subspace: Subspace = this.rushConfiguration.getSubspace(this._subspaceNameParameter.value!);
55-
await hotlinkManager.bridgePackageAsync(this.terminal, subspace, linkedPackagePath, version);
81+
const subspaces: Set<Subspace> = this._getSubspacesToBridgeAsync();
82+
await Async.forEachAsync(
83+
subspaces,
84+
async (subspace) => {
85+
await hotlinkManager.bridgePackageAsync(this.terminal, subspace, linkedPackagePath, version);
86+
},
87+
{ concurrency: 5 }
88+
);
5689
}
5790
}

libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Optional arguments:
179179
Specify which installed versions should be hotlinked.
180180
The default value is \\"*\\".
181181
--subspace SUBSPACE The name of the subspace to use for the bridge
182-
package. The default value is \\"default\\".
182+
package.
183183
"
184184
`;
185185

libraries/rush-lib/src/utilities/HotlinkManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class HotlinkManager {
186186
};
187187
}
188188

189-
private async _parsePackageVersionAsync(
189+
private async _getPackagePathsMatchingNameAndVersionAsync(
190190
consumerPackagePnpmDependenciesFolderPath: string,
191191
packageName: string,
192192
versionRange: string
@@ -220,7 +220,7 @@ export class HotlinkManager {
220220
const consumerPackagePnpmDependenciesFolderPath: string = `${subspace.getSubspaceTempFolderPath()}/${
221221
RushConstants.nodeModulesFolderName
222222
}/${RushConstants.pnpmVirtualStoreFolderName}`;
223-
const sourcePathSet: Set<string> = await this._parsePackageVersionAsync(
223+
const sourcePathSet: Set<string> = await this._getPackagePathsMatchingNameAndVersionAsync(
224224
consumerPackagePnpmDependenciesFolderPath,
225225
packageName,
226226
version

0 commit comments

Comments
 (0)