Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 22 additions & 6 deletions apps/desktop/src-tauri/run-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"beforeDevCommand": "pnpm prepare:dev",
"devUrl": "http://localhost:5173",
"beforeBuildCommand": "pnpm prepare:build",
"frontendDist": "../ui/dist"
"frontendDist": "../../ui/dist"
},
"app": {
"windows": [],
Expand Down
Loading