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 {
5- CommandLineStringListParameter ,
6- IRequiredCommandLineStringParameter
7- } from '@rushstack/ts-command-line' ;
4+ import type { IRequiredCommandLineStringParameter } from '@rushstack/ts-command-line' ;
85import path from 'path' ;
9- import type { RushConfigurationProject } from '../../api/RushConfigurationProject' ;
106import { HotlinkManager } from '../../utilities/HotlinkManager' ;
117import { BaseRushAction , type IBaseRushActionOptions } from './BaseRushAction' ;
12- import { Async } from '@rushstack/node-core-library' ;
13- import { RushConstants } from '../../logic/RushConstants' ;
148
159export abstract class BaseHotlinkPackageAction extends BaseRushAction {
16- protected readonly _projectList : CommandLineStringListParameter ;
1710 protected readonly _pathParameter : IRequiredCommandLineStringParameter ;
1811
1912 protected constructor ( options : IBaseRushActionOptions ) {
@@ -27,59 +20,16 @@ export abstract class BaseHotlinkPackageAction extends BaseRushAction {
2720 'The path of folder of a project outside of this Rush repo, whose installation will be simulated using' +
2821 ' node_modules symlinks ("hotlinks"). This folder is the symlink target.'
2922 } ) ;
30-
31- this . _projectList = this . defineStringListParameter ( {
32- parameterLongName : '--project' ,
33- required : false ,
34- argumentName : 'PROJECT' ,
35- description :
36- 'A list of Rush project names that will be hotlinked to the "--path" folder. ' +
37- 'If not specified, the default is the project of the current working directory.'
38- } ) ;
3923 }
4024
4125 protected abstract connectPackageAsync (
42- consumerPackage : RushConfigurationProject ,
4326 linkedPackagePath : string ,
4427 hotlinkManager : HotlinkManager
4528 ) : Promise < void > ;
4629
47- protected async getProjectsToLinkAsync ( ) : Promise < Set < RushConfigurationProject > > {
48- const projectsToLink : Set < RushConfigurationProject > = new Set ( ) ;
49- const projectNames : readonly string [ ] = this . _projectList . values ;
50-
51- if ( projectNames . length > 0 ) {
52- for ( const projectName of projectNames ) {
53- const project : RushConfigurationProject | undefined =
54- this . rushConfiguration . getProjectByName ( projectName ) ;
55- if ( ! project ) {
56- throw new Error ( `The project "${ projectName } " was not found in "${ RushConstants . rushPackageName } "` ) ;
57- }
58- projectsToLink . add ( project ) ;
59- }
60- } else {
61- const currentProject : RushConfigurationProject | undefined =
62- this . rushConfiguration . tryGetProjectForPath ( process . cwd ( ) ) ;
63- if ( ! currentProject ) {
64- throw new Error ( `No Rush project was found in the current working directory` ) ;
65- }
66- projectsToLink . add ( currentProject ) ;
67- }
68-
69- return projectsToLink ;
70- }
71-
7230 protected async runAsync ( ) : Promise < void > {
7331 const hotlinkManager : HotlinkManager = HotlinkManager . loadFromRushConfiguration ( this . rushConfiguration ) ;
7432 const linkedPackagePath : string = path . resolve ( process . cwd ( ) , this . _pathParameter . value ) ;
75- const projectsToLink : Set < RushConfigurationProject > = await this . getProjectsToLinkAsync ( ) ;
76-
77- await Async . forEachAsync (
78- projectsToLink ,
79- async ( project ) => {
80- await this . connectPackageAsync ( project , linkedPackagePath , hotlinkManager ) ;
81- } ,
82- { concurrency : 5 }
83- ) ;
33+ await this . connectPackageAsync ( linkedPackagePath , hotlinkManager ) ;
8434 }
8535}
0 commit comments