diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 1003caa..4812616 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -36,7 +36,7 @@ pnpm desktop:build `beforeBuildCommand`: 1. Bundles `@prm/api` into `src-tauri/sidecars/prm-api.mjs` (esbuild) and copies a portable **Node** binary + `better-sqlite3` next to it -2. Builds the UI into `apps/ui/dist` +2. Builds the UI into `apps/ui/dist` (Tauri `frontendDist` is `../../ui/dist` from `src-tauri`) At runtime the shell resolves `sidecars/` from the app resource dir (or `PRM_API_SIDECAR_DIR`), spawns bundled Node with the API entry, sets `PRM_LAUNCH_TOKEN` / `PRM_DATA_DIR`, and kills the child on exit — one process from the user’s point of view. diff --git a/apps/desktop/src-tauri/run-hook.mjs b/apps/desktop/src-tauri/run-hook.mjs index 36fc721..fe60fb8 100644 --- a/apps/desktop/src-tauri/run-hook.mjs +++ b/apps/desktop/src-tauri/run-hook.mjs @@ -5,21 +5,32 @@ * when cwd is apps/desktop (CI / tauri-action). */ import { spawnSync } from "node:child_process"; +import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const srcTauri = dirname(fileURLToPath(import.meta.url)); const desktopRoot = join(srcTauri, ".."); const repoRoot = join(desktopRoot, "../.."); +const uiDist = join(repoRoot, "apps/ui/dist"); const hook = process.argv[2] ?? "build"; function run(command, args, opts = {}) { - const result = spawnSync(command, args, { - stdio: "inherit", - cwd: opts.cwd ?? desktopRoot, - shell: process.platform === "win32", - env: process.env, - }); + const isWin = process.platform === "win32"; + // On Windows, prefer a single shell command string so args are not dropped. + const result = isWin && opts.shell !== false + ? spawnSync([command, ...args].map((a) => (/\s/.test(a) ? `"${a}"` : a)).join(" "), { + stdio: "inherit", + cwd: opts.cwd ?? desktopRoot, + shell: true, + env: process.env, + }) + : spawnSync(command, args, { + stdio: "inherit", + cwd: opts.cwd ?? desktopRoot, + shell: false, + env: process.env, + }); if (result.status !== 0) process.exit(result.status ?? 1); } @@ -31,4 +42,9 @@ if (hook === "dev") { shell: false, }); run("pnpm", ["--dir", repoRoot, "--filter", "@prm/ui", "build"], { cwd: desktopRoot }); + if (!existsSync(join(uiDist, "index.html"))) { + console.error("UI build missing — expected", join(uiDist, "index.html")); + process.exit(1); + } + console.log("UI dist ready:", uiDist); } diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json index 552bf3c..909dd26 100644 --- a/apps/desktop/src-tauri/tauri.conf.json +++ b/apps/desktop/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ "beforeDevCommand": "pnpm prepare:dev", "devUrl": "http://localhost:5173", "beforeBuildCommand": "pnpm prepare:build", - "frontendDist": "../ui/dist" + "frontendDist": "../../ui/dist" }, "app": { "windows": [],