瀏覽代碼

feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399)

Lucas Fernandes Nogueira 4 年之前
父節點
當前提交
32eb0d562b
共有 5 個文件被更改,包括 29 次插入47 次删除
  1. 5 0
      .changes/command-shell.md
  2. 0 11
      cli/core/Cargo.lock
  3. 0 3
      cli/core/Cargo.toml
  4. 13 17
      cli/core/src/build.rs
  5. 11 16
      cli/core/src/dev.rs

+ 5 - 0
.changes/command-shell.md

@@ -0,0 +1,5 @@
+---
+"tauri-cli": patch
+---
+
+Run `beforeDevCommand` and `beforeBuildCommand` in a shell.

+ 0 - 11
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"

+ 0 - 3
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"

+ 13 - 17
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()),
+        )?;
       }
     }
 

+ 11 - 16
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();
       }
     }