diff --git a/.changes/command-shell.md b/.changes/command-shell.md new file mode 100644 index 000000000..f411c179c --- /dev/null +++ b/.changes/command-shell.md @@ -0,0 +1,5 @@ +--- +"tauri-cli": patch +--- + +Run `beforeDevCommand` and `beforeBuildCommand` in a shell. diff --git a/cli/core/Cargo.lock b/cli/core/Cargo.lock old mode 100644 new mode 100755 index 8110c3c95..59abcbf7c --- a/cli/core/Cargo.lock +++ b/cli/core/Cargo.lock @@ -1963,7 +1963,6 @@ dependencies = [ "toml_edit", "ureq", "valico", - "which", ] [[package]] @@ -2370,16 +2369,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a32b378380f4e9869b22f0b5177c68a5519f03b3454fde0b291455ddbae266c" -[[package]] -name = "which" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" -dependencies = [ - "either", - "libc", -] - [[package]] name = "wildmatch" version = "1.1.0" diff --git a/cli/core/Cargo.toml b/cli/core/Cargo.toml index ff6551dc4..48333af4d 100644 --- a/cli/core/Cargo.toml +++ b/cli/core/Cargo.toml @@ -40,8 +40,5 @@ serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" serde_with = "1.6" -[target."cfg(target_os = \"windows\")".dependencies] -which = "4.0" - [target."cfg(target_os = \"linux\")".dependencies] heck = "0.3" diff --git a/cli/core/src/build.rs b/cli/core/src/build.rs index 1a9c2855c..907a81ad3 100644 --- a/cli/core/src/build.rs +++ b/cli/core/src/build.rs @@ -66,26 +66,22 @@ impl Build { } if let Some(before_build) = &config_.build.before_build_command { - let mut cmd: Option<&str> = None; - let mut args: Vec<&str> = vec![]; - for token in before_build.split(' ') { - if cmd.is_none() && !token.is_empty() { - cmd = Some(token); - } else { - args.push(token) - } - } - - if let Some(cmd) = cmd { + if !before_build.is_empty() { logger.log(format!("Running `{}`", before_build)); #[cfg(target_os = "windows")] - let mut command = Command::new( - which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)), - ); + execute_with_output( + &mut Command::new("cmd") + .arg("/C") + .arg(before_build) + .current_dir(app_dir()), + )?; #[cfg(not(target_os = "windows"))] - let mut command = Command::new(cmd); - command.args(args).current_dir(app_dir()); - execute_with_output(&mut command)?; + execute_with_output( + &mut Command::new("sh") + .arg("-c") + .arg(before_build) + .current_dir(app_dir()), + )?; } } diff --git a/cli/core/src/dev.rs b/cli/core/src/dev.rs index a7ce67250..2c6638422 100644 --- a/cli/core/src/dev.rs +++ b/cli/core/src/dev.rs @@ -65,25 +65,20 @@ impl Dev { .build .before_dev_command { - let mut cmd: Option<&str> = None; - let mut args: Vec<&str> = vec![]; - for token in before_dev.split(' ') { - if cmd.is_none() && !token.is_empty() { - cmd = Some(token); - } else { - args.push(token) - } - } - - if let Some(cmd) = cmd { + if !before_dev.is_empty() { logger.log(format!("Running `{}`", before_dev)); #[cfg(target_os = "windows")] - let mut command = Command::new( - which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)), - ); + let child = Command::new("cmd") + .arg("/C") + .arg(before_dev) + .current_dir(app_dir()) + .spawn()?; #[cfg(not(target_os = "windows"))] - let mut command = Command::new(cmd); - let child = command.args(args).current_dir(app_dir()).spawn()?; + let child = Command::new("sh") + .arg("-c") + .arg(before_dev) + .current_dir(app_dir()) + .spawn()?; BEFORE_DEV.set(Mutex::new(child)).unwrap(); } }