@@ -4,13 +4,15 @@ import * as path from 'path'
44import { spawn , ChildProcessWithoutNullStreams } from 'child_process'
55import stripAnsi from 'strip-ansi'
66import * as winston from 'winston'
7+ import { computeChildProcess } from '../utils/spawn.js'
78
89// Helper: remove non-printable control characters except newline (\n),
910// carriage return (\r), and tab (\t).
1011function removeControlChars ( input : string ) : string {
1112 return input . replace ( / [ \x00 - \x08 \x0B \x0C \x0E - \x1F \x7F ] / g, '' )
1213}
1314
15+
1416export default class Run extends Command {
1517 static description = 'Run a server'
1618 static examples = [
@@ -114,13 +116,7 @@ export default class Run extends Command {
114116 }
115117
116118 // Non-interactive mode using spawn.
117- let childCommand : string
118- if ( process . platform === 'win32' ) {
119- childCommand = 'npx.cmd'
120- } else {
121- childCommand = 'npx'
122- }
123- const childArgs = [ '-y' , ...stringArgs ]
119+ const { childCommand, childArgs } = computeChildProcess ( stringArgs )
124120 const shell = true ; //process.stdout.isTTY ? true : false;
125121
126122 logger . info ( `Spawn: ${ childCommand } ${ childArgs . join ( ' ' ) } ` )
@@ -134,6 +130,15 @@ export default class Run extends Command {
134130 shell : shell
135131 } ) as ChildProcessWithoutNullStreams
136132
133+ child . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
134+ logger . error ( `Failed to spawn ${ childCommand } : ${ err . message } ` )
135+ if ( err . code === 'ENOENT' ) {
136+ this . error ( `${ childCommand } not found. Please install it and try again.` )
137+ } else {
138+ this . error ( `Failed to spawn ${ childCommand } : ${ err . message } ` )
139+ }
140+ } )
141+
137142 child . stdout . on ( 'data' , ( data : Buffer ) => {
138143 handleOutput ( data . toString ( ) , process . stdout )
139144 } )
@@ -145,7 +150,7 @@ export default class Run extends Command {
145150 return new Promise ( ( resolve , reject ) => {
146151 child . on ( 'exit' , ( code : number ) => {
147152 logger . info ( `Process exited with code ${ code } at ${ new Date ( ) . toISOString ( ) } ` )
148- code === 0 ? resolve ( ) : reject ( new Error ( `npx exited with code ${ code } ` ) )
153+ code === 0 ? resolve ( ) : reject ( new Error ( `${ childCommand } exited with code ${ code } ` ) )
149154 } )
150155 } )
151156 }
0 commit comments