@@ -61,6 +61,16 @@ export function shouldUseShellForCommand(cmd, platform = process.platform) {
6161 return WINDOWS_SHELL_EXTENSIONS . has ( extension ) ;
6262}
6363
64+ export function quoteWindowsShellCommand ( cmd , platform = process . platform ) {
65+ if ( ! shouldUseShellForCommand ( cmd , platform ) || ! / \s / . test ( cmd ) ) {
66+ return cmd ;
67+ }
68+ if ( cmd . startsWith ( '"' ) && cmd . endsWith ( '"' ) ) {
69+ return cmd ;
70+ }
71+ return `"${ cmd } "` ;
72+ }
73+
6474export function assertSafeWindowsShellArgs ( args , platform = process . platform ) {
6575 if ( platform !== "win32" ) {
6676 return ;
@@ -91,8 +101,9 @@ function createSpawnOptions(cmd, args, envOverride) {
91101
92102function run ( cmd , args ) {
93103 let child ;
104+ const actualCmd = quoteWindowsShellCommand ( cmd ) ;
94105 try {
95- child = spawn ( cmd , args , createSpawnOptions ( cmd , args ) ) ;
106+ child = spawn ( actualCmd , args , createSpawnOptions ( cmd , args ) ) ;
96107 } catch ( err ) {
97108 console . error ( `Failed to launch ${ cmd } :` , err ) ;
98109 process . exit ( 1 ) ;
@@ -112,8 +123,9 @@ function run(cmd, args) {
112123
113124function runSync ( cmd , args , envOverride ) {
114125 let result ;
126+ const actualCmd = quoteWindowsShellCommand ( cmd ) ;
115127 try {
116- result = spawnSync ( cmd , args , createSpawnOptions ( cmd , args , envOverride ) ) ;
128+ result = spawnSync ( actualCmd , args , createSpawnOptions ( cmd , args , envOverride ) ) ;
117129 } catch ( err ) {
118130 console . error ( `Failed to launch ${ cmd } :` , err ) ;
119131 process . exit ( 1 ) ;
@@ -184,10 +196,7 @@ export function main(argv = process.argv.slice(2)) {
184196 }
185197
186198 if ( ! depsInstalled ( action === "test" ? "test" : "build" ) ) {
187- const installEnv =
188- action === "build" ? { ...process . env , NODE_ENV : "production" } : process . env ;
189- const installArgs = action === "build" ? [ "install" , "--prod" ] : [ "install" ] ;
190- runSync ( runner . cmd , installArgs , installEnv ) ;
199+ runSync ( runner . cmd , [ "install" ] ) ;
191200 }
192201
193202 run ( runner . cmd , [ "run" , script , ...rest ] ) ;
0 commit comments