diff --git a/src/bundler.rs b/src/bundler.rs index 972cc75..0a83eff 100644 --- a/src/bundler.rs +++ b/src/bundler.rs @@ -1089,7 +1089,7 @@ fn resolve_output_path( } let ext = if Platform::current().is_windows() { - ".exe" + ".bat" } else { "" }; diff --git a/src/executable.rs b/src/executable.rs index 61370bc..6bf072c 100644 --- a/src/executable.rs +++ b/src/executable.rs @@ -137,7 +137,8 @@ __DATA__ /// Create a Windows-compatible self-extracting executable fn create_windows_executable(out: &Path, zip_data: Vec, build_id: &str) -> Result<()> { - let mut file = fs::File::create(out).context("Failed to create output executable")?; + let bat_path = out.with_extension("bat"); + let mut file = fs::File::create(&bat_path).context("Failed to create output batch file")?; let script = format!( r#"@echo off diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0e48bde..4ced8ab 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -556,7 +556,7 @@ impl BundlerTestHelper { // Find the created executable let executable_name = custom_name.unwrap_or("test-project"); let executable_path = output_dir.join(if cfg!(windows) { - format!("{executable_name}.exe") + format!("{executable_name}.bat") } else { executable_name.to_string() }); @@ -564,7 +564,7 @@ impl BundlerTestHelper { // Check if collision avoidance was used if !executable_path.exists() || !executable_path.is_file() { let bundle_executable_path = output_dir.join(if cfg!(windows) { - format!("{executable_name}-bundle.exe") + format!("{executable_name}-bundle.bat") } else { format!("{executable_name}-bundle") }); @@ -600,8 +600,17 @@ impl BundlerTestHelper { fs::set_permissions(executable_path, perms)?; } - let mut cmd = Command::new(executable_path); - cmd.args(args); + let mut cmd = if cfg!(windows) { + // On Windows, run batch files through cmd.exe + let mut cmd = Command::new("cmd"); + cmd.args(["/C", executable_path.to_str().unwrap()]); + cmd.args(args); + cmd + } else { + let mut cmd = Command::new(executable_path); + cmd.args(args); + cmd + }; for (key, value) in env_vars { cmd.env(key, value); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index b536bb2..4d44f43 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -123,7 +123,7 @@ process.exit(0);"#; // Find the created executable let executable_path = temp_dir.path().join(if cfg!(windows) { - "integration-test-app.exe" + "integration-test-app.bat" } else { "integration-test-app" }); @@ -289,7 +289,7 @@ process.exit(0);"#; // Find and run the created executable to verify it uses the correct Node version let executable_name = if cfg!(target_os = "windows") { - "nvmrc-test-app.exe" + "nvmrc-test-app.bat" } else { "nvmrc-test-app" }; @@ -413,7 +413,7 @@ async fn test_output_path_collision_handling() -> Result<(), Box