Member Junction
    Preparing search index...

    Cross-platform child process runner with streaming output, timeout support, and process tree cleanup.

    Key behaviors:

    • On Windows, spawns with shell: true to resolve .cmd shims.
    • Supports configurable timeouts with full process tree kill on expiry.
    • Streams stdout/stderr line-by-line via callbacks for real-time progress.
    • Provides killByPort for port-based process cleanup (used by smoke test).
    const runner = new ProcessRunner();

    // Simple command
    const version = await runner.RunSimple('node', ['--version']);

    // Long-running command with streaming and timeout
    const result = await runner.Run('npm', ['run', 'build'], {
    Cwd: '/path/to/repo',
    TimeoutMs: 1_800_000,
    OnStdout: (line) => emitter.Emit('step:progress', { ... }),
    });
    Index

    Constructors

    Methods

    • Check whether a command exists on the system PATH.

      Uses where on Windows or which on Unix to locate the executable.

      Parameters

      • command: string

        The command name to look up (e.g., 'npm', 'git').

      Returns Promise<boolean>

      true if the command is found, false otherwise.

    • Kill all processes listening on a given TCP port.

      Used by SmokeTestPhase to clean up MJAPI and Explorer service processes after smoke test health checks complete. Without port-based cleanup, turbo/node grandchild processes survive parent shell termination and block future starts with EADDRINUSE.

      • Windows: Uses netstat -ano to find listening PIDs, then taskkill /F /T to kill each process tree.
      • Unix: Uses lsof -ti:<port> | xargs kill -9.

      Parameters

      • port: number

        TCP port number to scan for listening processes.

      Returns void

    • Kill a process and its entire process tree.

      On Windows, child.kill() with shell: true only terminates the top-level cmd.exe shell, leaving turbo/node grandchild processes running as orphans. This method uses taskkill /F /T /PID on Windows and process group signals (SIGTERM then SIGKILL) on Unix to ensure the full process tree is terminated.

      Parameters

      • pid: number

        Process ID of the root process to kill. No-op if undefined.

      Returns void

    • Spawn a child process and return the full result after it exits.

      The process is spawned with shell: true on Windows (for .cmd shim resolution) and shell: false on Unix. Stdout and stderr are accumulated in memory and optionally streamed line-by-line via callbacks.

      If ProcessOptions.TimeoutMs is set and the process exceeds it, the entire process tree is killed and { TimedOut: true } is returned.

      Parameters

      • command: string

        The command to execute (e.g., 'npm', 'npx').

      • args: string[]

        Command arguments (e.g., ['install', '--legacy-peer-deps']).

      • Optionaloptions: ProcessOptions

        Execution options (cwd, env, timeout, streaming callbacks).

      Returns Promise<ProcessResult>

      The process result with exit code, output, and timeout status.

      const result = await runner.Run('npx', ['mj', 'codegen'], {
      Cwd: dir,
      TimeoutMs: 600_000,
      OnStdout: (line) => console.log(line),
      });
    • Run a command and return just the trimmed stdout.

      Convenience wrapper around Run for simple commands where you only need the output text. Throws an Error if the process exits with a non-zero code.

      Parameters

      • command: string

        The command to execute.

      • args: string[]

        Command arguments.

      • Optionalcwd: string

        Optional working directory.

      Returns Promise<string>

      Trimmed stdout output.

      Error if the process exits with a non-zero exit code.

      const npmVersion = await runner.RunSimple('npm', ['--version']);
      // "10.9.0"