import { spawnSync, execFileSync } from "node:child_process"; import { cpSync, mkdtempSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); export const fixtures = join(here, "fixtures"); export const toolsDir = join(here, ".."); export function run(script, args = [], env = {}) { const r = spawnSync("node", [join(toolsDir, script), ...args], { encoding: "utf8", env: { ...process.env, ...env }, }); return { code: r.status, out: (r.stdout || "") + (r.stderr || "") }; } export function copyFixture(name) { const dir = mkdtempSync(join(tmpdir(), "sdc-")); cpSync(join(fixtures, name), dir, { recursive: true }); return dir; } export function git(cwd, ...args) { return execFileSync( "git", ["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd, encoding: "utf8" }, ); }