mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
fix: add WSL/Cygwin path translation and improve signal handling
- Add convertPathForBash() function that detects bash variant: - Cygwin: /cygdrive/c/path - WSL: /mnt/c/path - MSYS/Git Bash: /c/path - Update exit handler to properly handle signal termination (exit code 1 when killed by signal vs code from child) Addresses remaining CodeRabbit PR #586 recommendations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,36 @@ const __dirname = dirname(__filename);
|
||||
const isWindows = platform() === 'win32';
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
/**
|
||||
* Convert Windows path to Unix-style for the detected bash variant
|
||||
* @param {string} windowsPath - Windows-style path (e.g., C:\path\to\file)
|
||||
* @param {string} bashCmd - Path to bash executable (used to detect variant)
|
||||
* @returns {string} Unix-style path appropriate for the bash variant
|
||||
*/
|
||||
function convertPathForBash(windowsPath, bashCmd) {
|
||||
let unixPath = windowsPath.replace(/\\/g, '/');
|
||||
if (/^[A-Za-z]:/.test(unixPath)) {
|
||||
const drive = unixPath[0].toLowerCase();
|
||||
const pathPart = unixPath.slice(2);
|
||||
|
||||
// Detect bash type from path
|
||||
if (bashCmd.toLowerCase().includes('cygwin')) {
|
||||
// Cygwin expects /cygdrive/c/path format
|
||||
return `/cygdrive/${drive}${pathPart}`;
|
||||
} else if (
|
||||
bashCmd.toLowerCase().includes('system32') ||
|
||||
bashCmd === 'bash.exe'
|
||||
) {
|
||||
// WSL bash is typically in System32 or just 'bash.exe' in PATH
|
||||
return `/mnt/${drive}${pathPart}`;
|
||||
} else {
|
||||
// MSYS2/Git Bash expects /c/path format
|
||||
return `/${drive}${pathPart}`;
|
||||
}
|
||||
}
|
||||
return unixPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find bash executable on Windows
|
||||
*/
|
||||
@@ -80,14 +110,8 @@ function runBashScript() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Convert Windows path to Unix-style for bash
|
||||
// Handle both C:\path and /c/path styles
|
||||
let unixPath = scriptPath.replace(/\\/g, '/');
|
||||
if (/^[A-Za-z]:/.test(unixPath)) {
|
||||
// Convert C:/path to /c/path for MSYS/Git Bash
|
||||
unixPath = '/' + unixPath[0].toLowerCase() + unixPath.slice(2);
|
||||
}
|
||||
|
||||
// Convert Windows path to appropriate Unix-style for the detected bash variant
|
||||
const unixPath = convertPathForBash(scriptPath, bashCmd);
|
||||
bashArgs = [unixPath, ...args];
|
||||
} else {
|
||||
bashCmd = '/bin/bash';
|
||||
@@ -115,7 +139,12 @@ function runBashScript() {
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
child.on('exit', (code) => {
|
||||
child.on('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
// Process was killed by a signal - exit with 1 to indicate abnormal termination
|
||||
// (Unix convention is 128 + signal number, but we use 1 for simplicity)
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user