| 1 | import { execFileSync } from "node:child_process"; |
| 2 | import { mkdtempSync, rmSync } from "node:fs"; |
| 3 | import { createRequire } from "node:module"; |
| 4 | import { tmpdir } from "node:os"; |
| 5 | import { dirname, join, resolve } from "node:path"; |
| 6 | import { fileURLToPath } from "node:url"; |
| 7 | import { build } from "esbuild"; |
| 8 | |
| 9 | const require = createRequire(import.meta.url); |
| 10 | const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); |
| 11 | const scratch = mkdtempSync(join(tmpdir(), "reasonix-window-geometry-")); |
| 12 | try { |
| 13 | const entry = join(scratch, "main.cjs"); |
| 14 | await build({ entryPoints: [join(root, "src/main/windowGeometry.native.ts")], outfile: entry, |
| 15 | bundle: true, platform: "node", format: "cjs", external: ["electron"] }); |
| 16 | const env = { ...process.env }; |
| 17 | delete env.ELECTRON_RUN_AS_NODE; |
| 18 | execFileSync(require("electron"), [entry, `--user-data-dir=${join(scratch, "data")}`], |
| 19 | { env, stdio: "inherit", timeout: 60_000 }); |
| 20 | } finally { |
| 21 | rmSync(scratch, { recursive: true, force: true }); |
| 22 | } |
| 23 |