import { mkdir } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { spawn } from "node:child_process"; const dataPath = resolve(process.cwd(), ".local/pglite"); await mkdir(dirname(dataPath), { recursive: true }); const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm"; const child = spawn( command, [ "dlx", "@electric-sql/pglite-socket@0.2.7", `--db=${dataPath}`, "--port=15432", "--host=127.0.0.1", "--max-connections=20", "--extensions=pgcrypto", ], { stdio: "inherit" } ); let terminating = false; for (const signal of ["SIGINT", "SIGTERM"]) { process.on(signal, () => { if (!terminating) { terminating = true; child.kill(signal); } }); } child.on("exit", (code, signal) => { if (signal) { process.exit(signal === "SIGINT" ? 130 : 143); } process.exitCode = code ?? 1; });