Files
ForgeFlow-Public/src/main/process-runner.cjs
T
NuklearRabbit f60b269686
ForgeFlow quality gate / quality (push) Successful in 4m12s
ForgeFlow quality gate / secret-scan (push) Successful in 7s
Publish curated ForgeFlow source from 2ed1787c0b52
2026-09-29 22:50:57 +02:00

51 lines
1.5 KiB
JavaScript

'use strict';
const { execFile } = require('node:child_process');
function run(command, args = [], options = {}) {
const {
cwd,
timeout = 60_000,
maxBuffer = 8 * 1024 * 1024,
env,
input = null,
allowExitCodes = []
} = options;
return new Promise((resolve, reject) => {
const child = execFile(command, args, {
cwd,
timeout,
maxBuffer,
windowsHide: true,
encoding: 'utf8',
env: { ...process.env, ...(env || {}) }
}, (error, stdout, stderr) => {
if (error && !allowExitCodes.includes(error.code)) {
const message = (stderr || stdout || error.message).trim();
const wrapped = new Error(message);
wrapped.code = error.code;
if (/\.git[\\/]index\.lock[\s\S]*File exists/i.test(message) || /Unable to create .*index\.lock/i.test(message)) {
wrapped.code = 'GIT_INDEX_LOCKED';
wrapped.recoverable = true;
} else if (error.code === 'ENAMETOOLONG') {
wrapped.code = 'GIT_ARGUMENT_LIST_TOO_LONG';
wrapped.recoverable = true;
}
wrapped.stdout = stdout;
wrapped.stderr = stderr;
wrapped.command = `${command} ${args.join(' ')}`;
reject(wrapped);
return;
}
resolve({ stdout: stdout || '', stderr: stderr || '', exitCode: error?.code || 0 });
});
if (input !== null && input !== undefined) {
child.stdin.on('error', () => {});
child.stdin.end(input);
}
});
}
module.exports = { run };