UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

46 lines (44 loc) • 1.21 kB
import { execa } from "execa"; //#region src/utils/run.ts async function run(cmd, args, options = {}) { const proc = execa(cmd, args, { cwd: options.cwd, env: options.env ? { ...process.env, ...options.env } : process.env, stdio: options.capture ? "pipe" : "inherit", reject: false }); let capturedStdout = ""; let capturedStderr = ""; if (options.capture && options.onChunk) { proc.stdout?.on("data", (chunk) => { capturedStdout += chunk.toString("utf-8"); options.onChunk("stdout", chunk); }); proc.stderr?.on("data", (chunk) => { capturedStderr += chunk.toString("utf-8"); options.onChunk("stderr", chunk); }); } const result = await proc; const exitCode = result.exitCode ?? (result.failed ? 1 : 0); if (!options.capture) { if (exitCode !== 0) throw new Error(`${cmd} ${args.join(" ")} failed with exit code ${exitCode}`); return; } if (options.onChunk) return { stdout: capturedStdout, stderr: capturedStderr, exitCode }; return { stdout: typeof result.stdout === "string" ? result.stdout : "", stderr: typeof result.stderr === "string" ? result.stderr : "", exitCode }; } //#endregion export { run }; //# sourceMappingURL=run.mjs.map