Skip to content

Commit 32eb0d5

Browse files
authored
feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399)
1 parent fd5bb2c commit 32eb0d5

File tree

5 files changed

+29
-47
lines changed

5 files changed

+29
-47
lines changed

.changes/command-shell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-cli": patch
3+
---
4+
5+
Run `beforeDevCommand` and `beforeBuildCommand` in a shell.

cli/core/Cargo.lock

100644100755
Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/core/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,5 @@ serde = { version = "1.0", features = [ "derive" ] }
4040
serde_json = "1.0"
4141
serde_with = "1.6"
4242

43-
[target."cfg(target_os = \"windows\")".dependencies]
44-
which = "4.0"
45-
4643
[target."cfg(target_os = \"linux\")".dependencies]
4744
heck = "0.3"

cli/core/src/build.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,22 @@ impl Build {
6666
}
6767

6868
if let Some(before_build) = &config_.build.before_build_command {
69-
let mut cmd: Option<&str> = None;
70-
let mut args: Vec<&str> = vec![];
71-
for token in before_build.split(' ') {
72-
if cmd.is_none() && !token.is_empty() {
73-
cmd = Some(token);
74-
} else {
75-
args.push(token)
76-
}
77-
}
78-
79-
if let Some(cmd) = cmd {
69+
if !before_build.is_empty() {
8070
logger.log(format!("Running `{}`", before_build));
8171
#[cfg(target_os = "windows")]
82-
let mut command = Command::new(
83-
which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)),
84-
);
72+
execute_with_output(
73+
&mut Command::new("cmd")
74+
.arg("/C")
75+
.arg(before_build)
76+
.current_dir(app_dir()),
77+
)?;
8578
#[cfg(not(target_os = "windows"))]
86-
let mut command = Command::new(cmd);
87-
command.args(args).current_dir(app_dir());
88-
execute_with_output(&mut command)?;
79+
execute_with_output(
80+
&mut Command::new("sh")
81+
.arg("-c")
82+
.arg(before_build)
83+
.current_dir(app_dir()),
84+
)?;
8985
}
9086
}
9187

cli/core/src/dev.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,20 @@ impl Dev {
6565
.build
6666
.before_dev_command
6767
{
68-
let mut cmd: Option<&str> = None;
69-
let mut args: Vec<&str> = vec![];
70-
for token in before_dev.split(' ') {
71-
if cmd.is_none() && !token.is_empty() {
72-
cmd = Some(token);
73-
} else {
74-
args.push(token)
75-
}
76-
}
77-
78-
if let Some(cmd) = cmd {
68+
if !before_dev.is_empty() {
7969
logger.log(format!("Running `{}`", before_dev));
8070
#[cfg(target_os = "windows")]
81-
let mut command = Command::new(
82-
which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)),
83-
);
71+
let child = Command::new("cmd")
72+
.arg("/C")
73+
.arg(before_dev)
74+
.current_dir(app_dir())
75+
.spawn()?;
8476
#[cfg(not(target_os = "windows"))]
85-
let mut command = Command::new(cmd);
86-
let child = command.args(args).current_dir(app_dir()).spawn()?;
77+
let child = Command::new("sh")
78+
.arg("-c")
79+
.arg(before_dev)
80+
.current_dir(app_dir())
81+
.spawn()?;
8782
BEFORE_DEV.set(Mutex::new(child)).unwrap();
8883
}
8984
}

0 commit comments

Comments
 (0)