Comparing version
@@ -83,2 +83,1 @@ import checkCoverages from './check-coverages.js'; | ||
Object.defineProperty(c8js, name, { value }); | ||
@@ -163,48 +163,51 @@ import { spawn } from 'child_process'; | ||
export default function fgExecAsync(command, args, options = { }, process = globalThis.process) | ||
export default async function fgExecAsync | ||
(command, args, options = { }, process = globalThis.process) | ||
{ | ||
function executor(resolve, reject) | ||
{ | ||
try | ||
const callback = | ||
(error, stdio) => | ||
{ | ||
const callback = | ||
(error, stdio) => | ||
callbackError = error; | ||
unproxySignals(); | ||
process.removeListener('exit', childHangup); | ||
if (error && options.failFast) | ||
reject(error); | ||
else | ||
{ | ||
unproxySignals(); | ||
process.removeListener('exit', childHangup); | ||
if (error && options.failFast) | ||
reject(error); | ||
else | ||
const { stderr, stdout } = stdio; | ||
const result = | ||
{ | ||
const { stderr, stdout } = stdio; | ||
const result = | ||
{ | ||
status: child.exitCode, | ||
signal: child.signalCode, | ||
output: [null, stdout, stderr], | ||
pid: child.pid, | ||
stdout, | ||
stderr, | ||
error, | ||
}; | ||
resolve(result); | ||
} | ||
}; | ||
const child = execFileWithStdIO(command, args, options, callback); | ||
const unproxySignals = proxySignals(process, child); | ||
const hangupSignal = process.platform !== 'win32' ? 'SIGHUP' : 'SIGTERM'; | ||
const childHangup = | ||
() => | ||
{ | ||
child.kill(hangupSignal); | ||
}; | ||
process.addListener('exit', childHangup); | ||
} | ||
catch (error) | ||
status: child.exitCode, | ||
signal: child.signalCode, | ||
output: [null, stdout, stderr], | ||
pid: child.pid, | ||
stdout, | ||
stderr, | ||
error, | ||
}; | ||
resolve(result); | ||
} | ||
}; | ||
const child = execFileWithStdIO(command, args, options, callback); | ||
const unproxySignals = proxySignals(process, child); | ||
const hangupSignal = process.platform !== 'win32' ? 'SIGHUP' : 'SIGTERM'; | ||
const childHangup = | ||
() => | ||
{ | ||
reject(error); | ||
} | ||
child.kill(hangupSignal); | ||
}; | ||
process.addListener('exit', childHangup); | ||
} | ||
return new Promise(executor); | ||
function onfinally() | ||
{ | ||
if (callbackError) | ||
Error.captureStackTrace(callbackError, fgExecAsync); | ||
} | ||
let callbackError; | ||
const result = await new Promise(executor).finally(onfinally); | ||
return result; | ||
} | ||
@@ -211,0 +214,0 @@ |
{ | ||
"name": "c8js", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A modern, asynchronous Node.js API for c8", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
38593
0.04%1041
0.19%