@@ -708,12 +708,8 @@ class PackageManager {
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// Determine shell based on OS
|
||||
const isWindows = process.platform === 'win32';
|
||||
const shell = isWindows ? 'cmd' : 'sh';
|
||||
const shellFlag = isWindows ? '/c' : '-c';
|
||||
|
||||
const childProcess = spawn(shell, [shellFlag, script], {
|
||||
// Use cross-platform approach
|
||||
const childProcess = spawn(script, [], {
|
||||
cwd: this.projectRoot,
|
||||
stdio: options.silent ? 'pipe' : 'inherit',
|
||||
shell: true,
|
||||
@@ -724,11 +720,12 @@ class PackageManager {
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize output variables for silent mode
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
// Handle silent mode
|
||||
if (options.silent) {
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
if (childProcess.stdout) {
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
@@ -740,34 +737,60 @@ class PackageManager {
|
||||
stderr += data.toString();
|
||||
});
|
||||
}
|
||||
|
||||
childProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
if (stdout.trim()) {
|
||||
console.log(stdout.trim());
|
||||
}
|
||||
resolve();
|
||||
} else {
|
||||
if (stderr.trim()) {
|
||||
console.error(stderr.trim());
|
||||
}
|
||||
reject(new Error(`Script "${scriptName}" exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
childProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(chalk.green(`✓ Script "${scriptName}" completed successfully`));
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Script "${scriptName}" exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handle process completion
|
||||
let completed = false;
|
||||
|
||||
const handleCompletion = (code, signal) => {
|
||||
if (completed) return;
|
||||
completed = true;
|
||||
|
||||
if (options.silent) {
|
||||
if (stdout && stdout.trim()) {
|
||||
console.log(stdout.trim());
|
||||
}
|
||||
if (stderr && stderr.trim()) {
|
||||
console.error(stderr.trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (code === 0) {
|
||||
if (!options.silent) {
|
||||
console.log(chalk.green(`✓ Script "${scriptName}" completed successfully`));
|
||||
}
|
||||
resolve();
|
||||
} else {
|
||||
const errorMsg = signal
|
||||
? `Script "${scriptName}" was terminated by signal ${signal}`
|
||||
: `Script "${scriptName}" exited with code ${code}`;
|
||||
reject(new Error(errorMsg));
|
||||
}
|
||||
};
|
||||
|
||||
childProcess.on('close', handleCompletion);
|
||||
childProcess.on('exit', handleCompletion);
|
||||
|
||||
childProcess.on('error', (error) => {
|
||||
if (completed) return;
|
||||
completed = true;
|
||||
reject(new Error(`Failed to run script "${scriptName}": ${error.message}`));
|
||||
});
|
||||
|
||||
// Handle process termination signals
|
||||
const cleanup = () => {
|
||||
if (!completed && !childProcess.killed) {
|
||||
childProcess.kill('SIGTERM');
|
||||
setTimeout(() => {
|
||||
if (!childProcess.killed) {
|
||||
childProcess.kill('SIGKILL');
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
process.on('SIGINT', cleanup);
|
||||
process.on('SIGTERM', cleanup);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Referencia en una nueva incidencia
Block a user