Skip to content

Commit 85ebfe3

Browse files
fix(desktop): launch the dev supervisor without a shell in between
tsdown runs a string onSuccess through /bin/sh -c. dash forks rather than exec'ing the last command, so the supervisor's parent was a resident sh that outlived a killed `vp pack` and its parent-death check never fired. Prefix the command with exec on POSIX, and skip the check on Windows, where parents never reparent and reading process.ppid snapshots the process table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d7af024 commit 85ebfe3

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎apps/desktop/scripts/dev-electron.mjs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,13 @@ process.once("SIGHUP", () => {
274274
void shutdown(129);
275275
});
276276
// A parent killed without forwarding a signal leaves us reparented (to a subreaper on Linux, not
277-
// necessarily PID 1), and nothing else would ever stop the restart loop.
278-
setInterval(() => {
279-
if (process.ppid !== parentPid) {
280-
void shutdown(129);
281-
}
282-
}, parentWatchIntervalMs).unref();
277+
// necessarily PID 1), and nothing else would ever stop the restart loop. This only notices the
278+
// death of our direct parent, so vite.config.ts launches us without a shell in between. Windows
279+
// never reparents, and reading process.ppid there snapshots the process table.
280+
if (hostPlatform !== "win32") {
281+
setInterval(() => {
282+
if (process.ppid !== parentPid) {
283+
void shutdown(129);
284+
}
285+
}, parentWatchIntervalMs).unref();
286+
}

‎apps/desktop/vite.config.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import "vite-plus/test/config";
2+
import * as NodeOS from "node:os";
3+
24
import { defaultInclude, defineConfig } from "vite-plus";
35

46
import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
@@ -12,6 +14,13 @@ const repoEnv = loadRepoEnv();
1214
const isMainProcessExternal = (id: string) =>
1315
id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
1416
const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
17+
// tsdown runs onSuccess through a shell. dash forks instead of exec'ing the last command, which
18+
// would leave an `sh` between `vp pack` and the supervisor and hide `vp pack` dying from it.
19+
const devElectronCommand =
20+
// oxlint-disable-next-line t3code/no-global-process-runtime -- Build config has no Effect runtime.
21+
NodeOS.platform() === "win32"
22+
? "node scripts/dev-electron.mjs"
23+
: "exec node scripts/dev-electron.mjs";
1524
const publicConfigDefine = {
1625
__T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
1726
repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
@@ -66,7 +75,7 @@ export default defineConfig({
6675
neverBundle: isMainProcessExternal,
6776
onlyBundle: false,
6877
},
69-
...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
78+
...(shouldLaunchElectronAfterPack ? { onSuccess: devElectronCommand } : {}),
7079
},
7180
{
7281
format: "cjs",

0 commit comments

Comments
 (0)