MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / defaultExecutor

Function defaultExecutor

src/utils/command.ts:14–251  ·  view source on GitHub ↗
(
  command: string[],
  logPrefix?: string,
  useShell: boolean = false,
  opts?: CommandExecOptions,
  detached: boolean = false,
)

Source from the content-addressed store, hash-verified

12export type { FileSystemExecutor } from './FileSystemExecutor.ts';
13
14async function defaultExecutor(
15 command: string[],
16 logPrefix?: string,
17 useShell: boolean = false,
18 opts?: CommandExecOptions,
19 detached: boolean = false,
20): Promise<CommandResponse> {
21 let escapedCommand = command;
22 if (useShell) {
23 const commandString = command.map((arg) => shellEscapeArg(arg)).join(' ');
24
25 escapedCommand = ['/bin/sh', '-c', commandString];
26 }
27
28 return new Promise((resolve, reject) => {
29 let executable = escapedCommand[0];
30 let args = escapedCommand.slice(1);
31
32 if (!useShell && executable === 'xcodebuild') {
33 const xcrunPath = '/usr/bin/xcrun';
34 if (existsSync(xcrunPath)) {
35 executable = xcrunPath;
36 args = ['xcodebuild', ...args];
37 }
38 }
39
40 const displayCommand =
41 useShell && escapedCommand.length === 3 ? escapedCommand[2] : [executable, ...args].join(' ');
42 log('debug', `Executing ${logPrefix ?? ''} command: ${displayCommand}`);
43
44 const emitTranscript = transcriptEmitterStorage.getStore();
45 if (emitTranscript) {
46 emitTranscript({ kind: 'transcript', fragment: 'process-command', displayCommand });
47 }
48
49 const spawnOpts: Parameters<typeof spawn>[2] = {
50 stdio: ['ignore', 'pipe', 'pipe'],
51 env: opts?.env ? { ...process.env, ...opts.env } : process.env,
52 cwd: opts?.cwd,
53 };
54
55 log('debug', `defaultExecutor PATH: ${process.env.PATH ?? ''}`);
56
57 const logSpawnError = (err: Error): void => {
58 const errnoErr = err as NodeJS.ErrnoException & { spawnargs?: string[] };
59 const errorDetails = {
60 code: errnoErr.code,
61 errno: errnoErr.errno,
62 syscall: errnoErr.syscall,
63 path: errnoErr.path,
64 spawnargs: errnoErr.spawnargs,
65 stack: errnoErr.stack,
66 };
67 log('error', `Spawn error details: ${JSON.stringify(errorDetails, null, 2)}`);
68 };
69
70 const childProcess = spawn(executable, args, spawnOpts);
71

Callers

nothing calls this directly

Calls 13

shellEscapeArgFunction · 0.90
logFunction · 0.90
existsSyncFunction · 0.85
logSpawnErrorFunction · 0.85
resolveFunction · 0.85
attachStreamFunction · 0.85
maybeSettleAfterExitFunction · 0.85
scheduleExitSettleFunction · 0.85
clearExitSettleTimerFunction · 0.85
settleFunction · 0.85
onStdoutMethod · 0.65
onStderrMethod · 0.65

Tested by

no test coverage detected