MCPcopy
hub / github.com/dotenvx/dotenvx / executeCommand

Function executeCommand

src/lib/helpers/executeCommand.js:7–179  ·  view source on GitHub ↗
(commandArgs, env)

Source from the content-addressed store, hash-verified

5const Errors = require('./errors')
6
7async function executeCommand (commandArgs, env) {
8 const FORWARD_SIGNAL_GRACE_MS = 1000
9 const FORCE_KILL_GRACE_MS = 1000
10 const signals = [
11 'SIGHUP', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
12 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2'
13 ]
14
15 logger.debug(`executing process command [${commandArgs.join(' ')}]`)
16
17 let child
18 let signalSent
19 let sigintCount = 0
20 const signalForwardTimers = new Set()
21 const otherSignalHandlers = new Map()
22 const isInteractiveTTY = Boolean(process.stdin && process.stdin.isTTY)
23
24 const isChildRunning = () => {
25 return child && child.exitCode === null && child.signalCode === null
26 }
27
28 const queueSignalForward = (signal) => {
29 logger.debug(`queueing ${signal} to command process after ${FORWARD_SIGNAL_GRACE_MS}ms`)
30 const timer = setTimeout(() => {
31 signalForwardTimers.delete(timer)
32
33 if (!isChildRunning()) {
34 logger.debug(`skipping ${signal} forward because command process is already exiting`)
35 return
36 }
37
38 logger.debug(`sending ${signal} to command process`)
39 signalSent = signal
40 child.kill(signal)
41 }, FORWARD_SIGNAL_GRACE_MS)
42
43 if (typeof timer.unref === 'function') timer.unref()
44 signalForwardTimers.add(timer)
45 }
46
47 const queueForceKill = () => {
48 logger.debug(`queueing SIGKILL to command process after ${FORCE_KILL_GRACE_MS}ms`)
49 const timer = setTimeout(() => {
50 signalForwardTimers.delete(timer)
51
52 if (!isChildRunning()) {
53 logger.debug('skipping SIGKILL because command process is already exiting')
54 return
55 }
56
57 logger.debug('sending SIGKILL to command process')
58 child.kill('SIGKILL')
59 }, FORCE_KILL_GRACE_MS)
60
61 if (typeof timer.unref === 'function') timer.unref()
62 signalForwardTimers.add(timer)
63 }
64

Callers 2

runFunction · 0.85

Calls 2

setMethod · 0.80
commandExitedWithCodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…