(
command: string,
args: string[],
options: ExecutionOptions,
filenameTransform?: FilenameTransformFunc,
)
| 91 | } |
| 92 | |
| 93 | export async function executeDirect( |
| 94 | command: string, |
| 95 | args: string[], |
| 96 | options: ExecutionOptions, |
| 97 | filenameTransform?: FilenameTransformFunc, |
| 98 | ): Promise<UnprocessedExecResult> { |
| 99 | options = options || {}; |
| 100 | const maxOutput = Math.min(options.maxOutput || 1024 * 1024, buffer.constants.MAX_STRING_LENGTH); |
| 101 | const timeoutMs = options.timeoutMs || 0; |
| 102 | const env = {...process.env, ...options.env}; |
| 103 | |
| 104 | if (options.ldPath) { |
| 105 | env.LD_LIBRARY_PATH = options.ldPath.join(path.delimiter); |
| 106 | } |
| 107 | |
| 108 | if (options.wrapper) { |
| 109 | args = args.slice(0); // prevent mutating the caller's arguments |
| 110 | args.unshift(command); |
| 111 | command = options.wrapper; |
| 112 | |
| 113 | if (command.startsWith('./')) command = path.join(process.cwd(), command); |
| 114 | } |
| 115 | |
| 116 | let okToCache = true; |
| 117 | let timedOut = false; |
| 118 | // In WSL; run Windows-volume executables in a temp directory. |
| 119 | const cwd = options.customCwd || (command.startsWith('/mnt') && process.env.wsl ? os.tmpdir() : undefined); |
| 120 | logger.debug('Execution', {type: 'executing', command: command, args: args, env: env, cwd: cwd}); |
| 121 | const startTime = process.hrtime.bigint(); |
| 122 | |
| 123 | const child = child_process.spawn(command, args, { |
| 124 | cwd: cwd, |
| 125 | env: env, |
| 126 | detached: process.platform === 'linux', |
| 127 | }); |
| 128 | let running = true; |
| 129 | |
| 130 | const kill = |
| 131 | options.killChild || |
| 132 | (() => { |
| 133 | if (running && child?.pid) { |
| 134 | // Close the stdin pipe on our end, otherwise we'll get an EPIPE |
| 135 | child.stdin.destroy(); |
| 136 | treeKill(child.pid); |
| 137 | } |
| 138 | }); |
| 139 | |
| 140 | const streams = { |
| 141 | stderr: [] as Buffer[], |
| 142 | stdout: [] as Buffer[], |
| 143 | truncated: false, |
| 144 | }; |
| 145 | let timeout: NodeJS.Timeout | undefined; |
| 146 | if (timeoutMs) |
| 147 | timeout = setTimeout(() => { |
| 148 | logger.warn(`Timeout for ${command} ${args} after ${timeoutMs}ms`); |
| 149 | okToCache = false; |
| 150 | timedOut = true; |
no test coverage detected