mirror of
https://github.com/zhom/banderole.git
synced 2026-07-25 04:20:52 +02:00
refactor: simplify node binary execution
This commit is contained in:
@@ -337,28 +337,13 @@ fn run_app(app_dir: &Path, args: &[String]) -> Result<()> {
|
||||
let max_attempts: u32 = 8;
|
||||
let mut status: Option<std::process::ExitStatus> = None;
|
||||
for attempt in 1..=max_attempts {
|
||||
// Prepend Node's directory to PATH and launch via program name to avoid path parsing quirks
|
||||
let node_bin_dir = node_executable
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid node executable path: {}", node_executable.display()))?
|
||||
.to_path_buf();
|
||||
let program_name = if cfg!(windows) { "node.exe" } else { "node" };
|
||||
let mut cmd = Command::new(program_name);
|
||||
// Ensure PATH includes the Node directory first
|
||||
let mut new_path = std::env::var_os("PATH").unwrap_or_default();
|
||||
let sep = if cfg!(windows) { ";" } else { ":" };
|
||||
let mut prefixed: OsString = OsString::new();
|
||||
prefixed.push(node_bin_dir.as_os_str());
|
||||
prefixed.push(sep);
|
||||
prefixed.push(&new_path);
|
||||
cmd.env("PATH", prefixed);
|
||||
match cmd
|
||||
let status_res = Command::new(&node_executable)
|
||||
.args(&cmd_args)
|
||||
.stdin(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.status()
|
||||
{
|
||||
.status();
|
||||
match status_res {
|
||||
Ok(s) => {
|
||||
status = Some(s);
|
||||
break;
|
||||
|
||||
+4
-23
@@ -697,27 +697,8 @@ impl BundlerTestHelper {
|
||||
fs::set_permissions(executable_path, perms)?;
|
||||
}
|
||||
|
||||
// Build command to run the executable.
|
||||
let exec_path_owned = executable_path.to_path_buf();
|
||||
// Use verbatim long-path prefix on Windows to avoid MAX_PATH issues,
|
||||
// otherwise use the original path.
|
||||
#[cfg(windows)]
|
||||
let exec_cmd = {
|
||||
use std::ffi::OsString;
|
||||
let abs = exec_path_owned
|
||||
.canonicalize()
|
||||
.unwrap_or_else(|_| exec_path_owned.clone());
|
||||
let mut s: OsString = OsString::from(r"\\?\");
|
||||
s.push(&abs);
|
||||
s
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
let exec_cmd = exec_path_owned.as_os_str().to_os_string();
|
||||
|
||||
let mut cmd = Command::new(&exec_cmd);
|
||||
if let Some(parent) = exec_path_owned.parent() {
|
||||
cmd.current_dir(parent);
|
||||
}
|
||||
// Build command to run the executable (match queue_ordering test behavior)
|
||||
let mut cmd = Command::new(executable_path);
|
||||
|
||||
cmd.args(args);
|
||||
|
||||
@@ -727,14 +708,14 @@ impl BundlerTestHelper {
|
||||
|
||||
println!(
|
||||
"Executing: {} with args: {:?}",
|
||||
exec_path_owned.display(),
|
||||
executable_path.display(),
|
||||
args
|
||||
);
|
||||
|
||||
let output = cmd.output().with_context(|| {
|
||||
format!(
|
||||
"Failed to execute command: {}\nArgs: {:?}\nEnv vars: {:?}\nWorking directory: {:?}",
|
||||
exec_path_owned.display(),
|
||||
executable_path.display(),
|
||||
args,
|
||||
env_vars,
|
||||
std::env::current_dir().unwrap_or_else(|_| "<unknown>".into())
|
||||
|
||||
Reference in New Issue
Block a user