33
44import * as path from 'node:path' ;
55
6+ import type { IDaemonConfigurationJson } from '@microsoft/rush-lib' ;
7+ // A deep import keeps the warm connect path from evaluating the @microsoft /rush-lib entry point.
68import {
79 daemonEnvironmentVariables ,
8- resolveDaemonConfiguration ,
9- type IDaemonConfigurationJson
10+ resolveDaemonConfiguration
1011} from '@microsoft/rush-lib/lib/api/DaemonConfiguration' ;
11- import { tryFindRushJsonLocation } from '@microsoft/rush-lib/lib/api/RushJsonLocation' ;
1212import { JsonFile } from '@rushstack/node-core-library' ;
1313import {
1414 DaemonClientError ,
@@ -21,15 +21,19 @@ import {
2121} from '@rushstack/rush-client-core' ;
2222import type { DaemonVerbosity , IDaemonRequestEnvelope } from '@rushstack/rush-daemon-protocol' ;
2323import { ConsoleTerminalProvider } from '@rushstack/terminal' ;
24- import { DaemonLauncherUnavailableError } from '@rushstack/rush-daemon/lib/DaemonLaunchCommand' ;
2524
26- import { BUNDLED_RUSH_VERSION } from './bundledRushVersion' ;
2725import { executeDaemonCommandAsync } from './daemonCommands' ;
2826import { formatAdmissionFailure , getConfiguredAdmission } from './ClientAdmissionControls' ;
2927import { ClientOperationRenderer } from './ClientOperationRenderer' ;
3028import { getDaemonConnectionOptionsAsync } from './daemonConnectionOptions' ;
3129import { selectClientRoute , type IClientRoute } from './routing' ;
3230import { writeStreamAsync } from './writeStreamAsync' ;
31+ import {
32+ getBundledRushVersion ,
33+ loadMinimalRushConfiguration ,
34+ loadVersionSelectedDaemonLauncher ,
35+ tryFindRushJsonLocation
36+ } from './lazyRushModules' ;
3337
3438interface IWorkspaceJson {
3539 readonly rushVersion : string ;
@@ -39,7 +43,7 @@ interface IWorkspaceJson {
3943export async function launchClientAsync ( rushx : boolean ) : Promise < void > {
4044 const cwd : string = process . cwd ( ) ;
4145 const environment : Readonly < NodeJS . ProcessEnv > = Object . freeze ( { ...process . env } ) ;
42- const rushJsonPath : string | undefined = tryFindRushJsonLocation ( { startingFolder : cwd } ) ;
46+ const rushJsonPath : string | undefined = tryFindRushJsonLocation ( cwd ) ;
4347 const workspace : IWorkspaceJson | undefined = rushJsonPath ? JsonFile . load ( rushJsonPath ) : undefined ;
4448 const config : Readonly < Required < IDaemonConfigurationJson > > = resolveDaemonConfiguration (
4549 workspace ?. daemon ,
@@ -53,7 +57,7 @@ export async function launchClientAsync(rushx: boolean): Promise<void> {
5357 hasTerminal : ! ! ( process . stdin . isTTY || process . stdout . isTTY || process . stderr . isTTY )
5458 } ) ;
5559 const selectedVersion : string =
56- environment . RUSH_PREVIEW_VERSION ?? workspace ?. rushVersion ?? BUNDLED_RUSH_VERSION ;
60+ environment . RUSH_PREVIEW_VERSION ?? workspace ?. rushVersion ?? getBundledRushVersion ( ) ;
5761 if ( ! rushx && route . commandName === 'daemon' ) {
5862 if ( ( route . argv [ 1 ] === 'start' || route . argv [ 1 ] === 'restart' ) && process . argv . includes ( '--no-daemon' ) ) {
5963 throw new Error ( `--no-daemon cannot be combined with daemon ${ route . argv [ 1 ] } .` ) ;
@@ -120,7 +124,10 @@ export async function launchClientAsync(rushx: boolean): Promise<void> {
120124 } ;
121125 client = await connectOrStartDaemonAsync ( connection ) ;
122126 } catch ( error ) {
123- if ( ! ( error instanceof DaemonClientError ) && ! ( error instanceof DaemonLauncherUnavailableError ) )
127+ if (
128+ ! ( error instanceof DaemonClientError ) &&
129+ ! ( error instanceof loadVersionSelectedDaemonLauncher ( ) . DaemonLauncherUnavailableError )
130+ )
124131 throw error ;
125132 process . stderr . write ( `rush-client: ${ error . message } Using in-process Rush.\n` ) ;
126133 launchInProcess ( route . argv , rushx , selectedVersion ) ;
@@ -154,9 +161,9 @@ export async function launchClientAsync(rushx: boolean): Promise<void> {
154161 } ;
155162 try {
156163 if ( rushx ) {
157- // Rushx discovery output needs the frontend's configuration loader, which loads the engine.
158- const { MinimalRushConfiguration } = await import ( '@microsoft/rush/lib/MinimalRushConfiguration' ) ;
159- MinimalRushConfiguration . loadFromDefaultLocation ( ( line ) => discoveryLines . push ( line ) ) ;
164+ loadMinimalRushConfiguration ( ) . MinimalRushConfiguration . loadFromDefaultLocation ( ( line ) =>
165+ discoveryLines . push ( line )
166+ ) ;
160167 }
161168 await renderer . initializeAsync ( ) ;
162169 outcome = await executeWithDaemonRestartAsync ( client , connection , {
@@ -219,7 +226,7 @@ function launchInProcess(argv: ReadonlyArray<string>, rushx: boolean, selectedVe
219226 const executable : string = rushx ? 'rushx' : 'rush' ;
220227 const rushFolder : string = path . dirname ( require . resolve ( '@microsoft/rush/package.json' ) ) ;
221228 process . argv = [ process . execPath , path . join ( rushFolder , 'bin' , executable ) , ...argv ] ;
222- if ( selectedVersion !== BUNDLED_RUSH_VERSION ) {
229+ if ( selectedVersion !== getBundledRushVersion ( ) ) {
223230 // Old Rush releases reject new RUSH_* names. Only strip this launcher's own inputs;
224231 // the request snapshot was captured earlier and is never mutated.
225232 for ( const name of [ ...Object . values ( daemonEnvironmentVariables ) , 'RUSH_DAEMON_EXPERIMENTAL' ] ) {
0 commit comments