@@ -695,18 +695,24 @@ export async function getShellScriptEnvironment(kit: Kit, opts?: expand.Expansio
695695 let script = '' ;
696696 let run_command = '' ;
697697
698- let environmentSetupScript = kit . environmentSetupScript ? .trim ( ) ;
698+ let environmentSetupScript = kit . environmentSetupScript ! . trim ( ) ;
699699 if ( opts ) {
700- environmentSetupScript = await expand . expandString ( environmentSetupScript ! , opts ) ;
700+ environmentSetupScript = await expand . expandString ( environmentSetupScript , opts ) ;
701+ }
702+
703+ // If the string doesn't start with a quote, assume it is a path to a script file, so we quote it in case there are spaces in the path.
704+ // Otherwise, assume it is in form of `"script path" [arg ...]`, we will not add extra quotes, to avoid breaking the command.
705+ if ( ! environmentSetupScript . startsWith ( '"' ) ) {
706+ environmentSetupScript = `"${ environmentSetupScript } "` ;
701707 }
702708
703709 if ( process . platform === 'win32' ) { // windows
704- script += `call " ${ environmentSetupScript } " \r\n` ; // call the user batch script
710+ script += `call ${ environmentSetupScript } \r\n` ; // call the user batch script
705711 script += `set >> "${ environment_path } "` ; // write env vars to temp file
706712 // Quote the script file path before running it, in case there are spaces.
707713 run_command = `call "${ script_path } "` ;
708714 } else { // non-windows
709- script += `source " ${ environmentSetupScript } " \n` ; // run the user shell script
715+ script += `source ${ environmentSetupScript } \n` ; // run the user shell script
710716 script += `printenv >> ${ environment_path } ` ; // write env vars to temp file
711717 run_command = `/bin/bash -c "source ${ script_path } "` ; // run script in bash to enable bash-builtin commands like 'source'
712718 }
0 commit comments