@@ -74,13 +74,11 @@ export interface Host {
7474 /**
7575 * Spawns a child process and returns a promise that resolves with the process's
7676 * output or rejects with a structured error.
77- * @param command The command to run.
7877 * @param args The arguments to pass to the command.
7978 * @param options Options for the child process.
8079 * @returns A promise that resolves with the standard output and standard error of the command.
8180 */
82- runCommand (
83- command : string ,
81+ executeNgCommand (
8482 args : readonly string [ ] ,
8583 options ?: {
8684 timeout ?: number ;
@@ -92,13 +90,11 @@ export interface Host {
9290
9391 /**
9492 * Spawns a long-running child process and returns the `ChildProcess` object.
95- * @param command The command to run.
9693 * @param args The arguments to pass to the command.
9794 * @param options Options for the child process.
9895 * @returns The spawned `ChildProcess` instance.
9996 */
100- spawn (
101- command : string ,
97+ startNgProcess (
10298 args : readonly string [ ] ,
10399 options ?: {
104100 stdio ?: 'pipe' | 'ignore' ;
@@ -123,13 +119,13 @@ export interface Host {
123119 setRoots ( roots : string [ ] ) : void ;
124120}
125121
126- function resolveCommand (
127- command : string ,
122+ function resolveNgCommand (
128123 args : readonly string [ ] ,
129124 cwd ?: string ,
130125) : { command : string ; args : readonly string [ ] } {
131- if ( command !== 'ng' || ! cwd ) {
132- return { command, args } ;
126+ const defaultCommand = { command : 'ng' , args } ;
127+ if ( ! cwd ) {
128+ return defaultCommand ;
133129 }
134130
135131 try {
@@ -150,7 +146,7 @@ function resolveCommand(
150146 // Failed to resolve the CLI binary, fall back to assuming `ng` is on PATH.
151147 }
152148
153- return { command , args } ;
149+ return defaultCommand ;
154150}
155151
156152/**
@@ -170,8 +166,7 @@ export const LocalWorkspaceHost: Host = {
170166 return nodeGlob ( pattern , { ...options , withFileTypes : true } ) ;
171167 } ,
172168
173- runCommand : async (
174- command : string ,
169+ executeNgCommand : async (
175170 args : readonly string [ ] ,
176171 options : {
177172 timeout ?: number ;
@@ -180,7 +175,7 @@ export const LocalWorkspaceHost: Host = {
180175 env ?: Record < string , string > ;
181176 } = { } ,
182177 ) : Promise < { logs : string [ ] } > => {
183- const resolved = resolveCommand ( command , args , options . cwd ) ;
178+ const resolved = resolveNgCommand ( args , options . cwd ) ;
184179 const signal = options . timeout ? AbortSignal . timeout ( options . timeout ) : undefined ;
185180
186181 return new Promise ( ( resolve , reject ) => {
@@ -221,16 +216,15 @@ export const LocalWorkspaceHost: Host = {
221216 } ) ;
222217 } ,
223218
224- spawn (
225- command : string ,
219+ startNgProcess (
226220 args : readonly string [ ] ,
227221 options : {
228222 stdio ?: 'pipe' | 'ignore' ;
229223 cwd ?: string ;
230224 env ?: Record < string , string > ;
231225 } = { } ,
232226 ) : ChildProcess {
233- const resolved = resolveCommand ( command , args , options . cwd ) ;
227+ const resolved = resolveNgCommand ( args , options . cwd ) ;
234228
235229 return spawn ( resolved . command , resolved . args , {
236230 shell : false ,
@@ -370,23 +364,17 @@ export function createRootRestrictedHost(
370364
371365 return baseHost . glob ( pattern , options ) ;
372366 } ,
373- runCommand ( command : string , args : readonly string [ ] , options : { cwd ?: string } = { } ) {
374- const effectiveCwd = options . cwd ?? process . cwd ( ) ;
367+ executeNgCommand ( args : readonly string [ ] , options : Parameters < Host [ 'executeNgCommand' ] > [ 1 ] = { } ) {
368+ const effectiveCwd = options ? .cwd ?? process . cwd ( ) ;
375369 checkPath ( effectiveCwd ) ;
376- if ( command . includes ( '/' ) || command . includes ( '\\' ) ) {
377- checkPath ( resolve ( effectiveCwd , command ) ) ;
378- }
379370
380- return baseHost . runCommand ( command , args , options ) ;
371+ return baseHost . executeNgCommand ( args , options ) ;
381372 } ,
382- spawn ( command : string , args : readonly string [ ] , options : { cwd ?: string } = { } ) {
383- const effectiveCwd = options . cwd ?? process . cwd ( ) ;
373+ startNgProcess ( args : readonly string [ ] , options : Parameters < Host [ 'startNgProcess' ] > [ 1 ] = { } ) {
374+ const effectiveCwd = options ? .cwd ?? process . cwd ( ) ;
384375 checkPath ( effectiveCwd ) ;
385- if ( command . includes ( '/' ) || command . includes ( '\\' ) ) {
386- checkPath ( resolve ( effectiveCwd , command ) ) ;
387- }
388376
389- return baseHost . spawn ( command , args , options ) ;
377+ return baseHost . startNgProcess ( args , options ) ;
390378 } ,
391379 } ;
392380}
0 commit comments