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
66import type { RushCommandLineParser } from '../RushCommandLineParser' ;
77import { BaseHotlinkPackageAction } from './BaseHotlinkPackageAction' ;
88import type { HotlinkManager } from '../../utilities/HotlinkManager' ;
99import { BRIDGE_PACKAGE_ACTION_NAME , LINK_PACKAGE_ACTION_NAME } from '../../utilities/actionNameConstants' ;
1010import { RushConstants } from '../../logic/RushConstants' ;
1111import type { Subspace } from '../../api/Subspace' ;
12+ import { Async } from '@rushstack/node-core-library' ;
13+ import type { RushConfigurationProject } from '../../api/RushConfigurationProject' ;
1214
1315export 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}
0 commit comments