@@ -708,12 +708,8 @@ class PackageManager {
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Determine shell based on OS
|
// Use cross-platform approach
|
||||||
const isWindows = process.platform === 'win32';
|
const childProcess = spawn(script, [], {
|
||||||
const shell = isWindows ? 'cmd' : 'sh';
|
|
||||||
const shellFlag = isWindows ? '/c' : '-c';
|
|
||||||
|
|
||||||
const childProcess = spawn(shell, [shellFlag, script], {
|
|
||||||
cwd: this.projectRoot,
|
cwd: this.projectRoot,
|
||||||
stdio: options.silent ? 'pipe' : 'inherit',
|
stdio: options.silent ? 'pipe' : 'inherit',
|
||||||
shell: true,
|
shell: true,
|
||||||
@@ -724,11 +720,12 @@ class PackageManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle silent mode
|
// Initialize output variables for silent mode
|
||||||
if (options.silent) {
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
|
|
||||||
|
// Handle silent mode
|
||||||
|
if (options.silent) {
|
||||||
if (childProcess.stdout) {
|
if (childProcess.stdout) {
|
||||||
childProcess.stdout.on('data', (data) => {
|
childProcess.stdout.on('data', (data) => {
|
||||||
stdout += data.toString();
|
stdout += data.toString();
|
||||||
@@ -740,34 +737,60 @@ class PackageManager {
|
|||||||
stderr += data.toString();
|
stderr += data.toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
childProcess.on('close', (code) => {
|
// Handle process completion
|
||||||
if (code === 0) {
|
let completed = false;
|
||||||
if (stdout.trim()) {
|
|
||||||
|
const handleCompletion = (code, signal) => {
|
||||||
|
if (completed) return;
|
||||||
|
completed = true;
|
||||||
|
|
||||||
|
if (options.silent) {
|
||||||
|
if (stdout && stdout.trim()) {
|
||||||
console.log(stdout.trim());
|
console.log(stdout.trim());
|
||||||
}
|
}
|
||||||
resolve();
|
if (stderr && stderr.trim()) {
|
||||||
} else {
|
|
||||||
if (stderr.trim()) {
|
|
||||||
console.error(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}`));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) => {
|
childProcess.on('error', (error) => {
|
||||||
|
if (completed) return;
|
||||||
|
completed = true;
|
||||||
reject(new Error(`Failed to run script "${scriptName}": ${error.message}`));
|
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