chore: on windows, create .bat instead of .exe

This commit is contained in:
zhom
2025-07-28 03:12:37 +04:00
parent 7067f8db75
commit c22eb4f39c
4 changed files with 27 additions and 17 deletions
+1 -1
View File
@@ -1089,7 +1089,7 @@ fn resolve_output_path(
}
let ext = if Platform::current().is_windows() {
".exe"
".bat"
} else {
""
};
+2 -1
View File
@@ -137,7 +137,8 @@ __DATA__
/// Create a Windows-compatible self-extracting executable
fn create_windows_executable(out: &Path, zip_data: Vec<u8>, 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
+13 -4
View File
@@ -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);
+11 -11
View File
@@ -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<dyn std::error:
// Verify that a bundle was created with collision-avoided name
let expected_executable = temp_dir.path().join(if cfg!(windows) {
"collision-test-app-bundle.exe"
"collision-test-app-bundle.bat"
} else {
"collision-test-app-bundle"
});
@@ -546,7 +546,7 @@ try {
// Find the created executable (may have collision avoidance suffix)
let mut executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-test-app.exe"
"ts-test-app.bat"
} else {
"ts-test-app"
});
@@ -554,7 +554,7 @@ try {
// Check if collision avoidance was used (need to check if it's a file, not just exists)
if !executable_path.exists() || !executable_path.is_file() {
executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-test-app-bundle.exe"
"ts-test-app-bundle.bat"
} else {
"ts-test-app-bundle"
});
@@ -693,7 +693,7 @@ try {
// Find the created executable (may have collision avoidance suffix)
let mut executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-outdir-test.exe"
"ts-outdir-test.bat"
} else {
"ts-outdir-test"
});
@@ -701,7 +701,7 @@ try {
// Check if collision avoidance was used (need to check if it's a file, not just exists)
if !executable_path.exists() || !executable_path.is_file() {
executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-outdir-test-bundle.exe"
"ts-outdir-test-bundle.bat"
} else {
"ts-outdir-test-bundle"
});
@@ -840,7 +840,7 @@ try {
// Find the created executable (may have collision avoidance suffix)
let mut executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-extends-test.exe"
"ts-extends-test.bat"
} else {
"ts-extends-test"
});
@@ -848,7 +848,7 @@ try {
// Check if collision avoidance was used (need to check if it's a file, not just exists)
if !executable_path.exists() || !executable_path.is_file() {
executable_path = temp_dir.path().join(if cfg!(windows) {
"ts-extends-test-bundle.exe"
"ts-extends-test-bundle.bat"
} else {
"ts-extends-test-bundle"
});
@@ -1058,7 +1058,7 @@ packages:
// Find the created executable
let mut executable_path = temp_dir.path().join(if cfg!(windows) {
"pnpm-test-app.exe"
"pnpm-test-app.bat"
} else {
"pnpm-test-app"
});
@@ -1066,7 +1066,7 @@ packages:
// Check if collision avoidance was used
if !executable_path.exists() || !executable_path.is_file() {
executable_path = temp_dir.path().join(if cfg!(windows) {
"pnpm-test-app-bundle.exe"
"pnpm-test-app-bundle.bat"
} else {
"pnpm-test-app-bundle"
});