Skip to content

Commit 80604a4

Browse files
committed
fix: 🚑 commands now executed in shells
Should fix bugs with finding `rollup`.
1 parent 1b6ef16 commit 80604a4

File tree

1 file changed

+16
-6
lines changed
  • packages/perseus-cli/src

1 file changed

+16
-6
lines changed

packages/perseus-cli/src/cmd.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@ pub static FAILURE: Emoji<'_, '_> = Emoji("❌", "failed!");
1111

1212
/// Runs the given command conveniently, returning the exit code. Notably, this parses the given command by separating it on spaces.
1313
/// Returns the command's output and the exit code.
14-
pub fn run_cmd(raw_cmd: String, dir: &Path, pre_dump: impl Fn()) -> Result<(String, String, i32)> {
15-
let mut cmd_args: Vec<&str> = raw_cmd.split(' ').collect();
16-
let cmd = cmd_args.remove(0);
14+
pub fn run_cmd(cmd: String, dir: &Path, pre_dump: impl Fn()) -> Result<(String, String, i32)> {
15+
// let mut cmd_args: Vec<&str> = raw_cmd.split(' ').collect();
16+
// let cmd = cmd_args.remove(0);
17+
18+
// We run the command in a shell so that NPM/Yarn binaries can be recognized (see #5)
19+
#[cfg(unix)]
20+
let shell_exec = "sh";
21+
#[cfg(windows)]
22+
let shell_exec = "powershell";
23+
#[cfg(unix)]
24+
let shell_param = "-c";
25+
#[cfg(windows)]
26+
let shell_param = "-command";
1727

1828
// This will NOT pipe output/errors to the console
19-
let output = Command::new(&cmd)
20-
.args(cmd_args)
29+
let output = Command::new(shell_exec)
30+
.args([shell_param, &cmd])
2131
.current_dir(dir)
2232
.output()
23-
.map_err(|err| ErrorKind::CmdExecFailed(raw_cmd.clone(), err.to_string()))?;
33+
.map_err(|err| ErrorKind::CmdExecFailed(cmd.clone(), err.to_string()))?;
2434

2535
let exit_code = match output.status.code() {
2636
Some(exit_code) => exit_code, // If we have an exit code, use it

0 commit comments

Comments
 (0)