Swadhin Biswas feat(api): add runner, analytics, packages, and security services · 3/6/2026
28f7954
32 lines · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * Promisified exec utility
 */

import { exec } from "child_process";
import { promisify } from "util";

const execPromise = promisify(exec);

export interface ExecOptions {
  cwd?: string;
  timeout?: number;
  env?: NodeJS.ProcessEnv;
  maxBuffer?: number;
}

/**
 * Execute a shell command and return stdout/stderr.
 * Throws on non-zero exit code.
 */
export async function execAsync(
  command: string,
  options: ExecOptions = {},
): Promise<{ stdout: string; stderr: string }> {
  return execPromise(command, {
    cwd: options.cwd,
    timeout: options.timeout || 0,
    env: options.env || process.env,
    maxBuffer: options.maxBuffer || 50 * 1024 * 1024, // 50MB
  });
}