authorgravatar for me@t3.ggTheo Browne <me@t3.gg> 2026-07-02 18:57:59-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-07-02 18:57:59-07:00
log6d35a87c5d0e6dcf16be5b1d9a236a1d5e12c8c7
tree95da707102232141b3b5e9b46979ca7fd16b3700
parent7b9eef7ac29f9d4819c6411dfb1c5f04fef50264
signature Signed by PGP key B5690EEEBB952194

fix(dev): Fix electron dev launch and add test (#3662)


2 files changed, 34 insertions(+), 7 deletions(-)

apps/desktop/scripts/electron-launcher.mjs+13-6
...@@ -358,10 +358,7 @@ function resolveLinuxSandboxArgs(electronBinaryPath) {...@@ -358,10 +358,7 @@ function resolveLinuxSandboxArgs(electronBinaryPath) {
358}358}
359359
360export function resolveElectronPath() {360export function resolveElectronPath() {
361 ensureElectronRuntime();361 const electronBinaryPath = resolveElectronBinaryPath();
362
363 const require = NodeModule.createRequire(import.meta.url);
364 const electronBinaryPath = require("electron");
365362
366 if (hostPlatform !== "darwin") {363 if (hostPlatform !== "darwin") {
367 return electronBinaryPath;364 return electronBinaryPath;
...@@ -378,13 +375,23 @@ export function resolveElectronLaunchCommand(args = []) {...@@ -378,13 +375,23 @@ export function resolveElectronLaunchCommand(args = []) {
378 };375 };
379}376}
380377
378export function resolveElectronBinaryPath({
379 ensureRuntime = ensureElectronRuntime,
380 createRequire = NodeModule.createRequire,
381 moduleUrl = import.meta.url,
382} = {}) {
383 ensureRuntime();
384
385 const require = createRequire(moduleUrl);
386 return require("electron");
387}
388
381export function resolveDevProtocolClient() {389export function resolveDevProtocolClient() {
382 if (hostPlatform !== "darwin" || !isDevelopment) {390 if (hostPlatform !== "darwin" || !isDevelopment) {
383 return null;391 return null;
384 }392 }
385393
386 const require = NodeModule.createRequire(import.meta.url);394 const electronBinaryPath = resolveElectronBinaryPath();
387 const electronBinaryPath = require("electron");
388 const launcherBinaryPath = buildMacLauncher(electronBinaryPath);395 const launcherBinaryPath = buildMacLauncher(electronBinaryPath);
389 return {396 return {
390 appBundlePath: NodePath.resolve(launcherBinaryPath, "..", "..", ".."),397 appBundlePath: NodePath.resolve(launcherBinaryPath, "..", "..", ".."),
apps/desktop/scripts/electron-launcher.test.mjs+21-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1import { assert, describe, it } from "vite-plus/test";1import { assert, describe, it } from "vite-plus/test";
22
3import { makeDevelopmentLauncherScript } from "./electron-launcher.mjs";3import { makeDevelopmentLauncherScript, resolveElectronBinaryPath } from "./electron-launcher.mjs";
44
5describe("electron development launcher", () => {5describe("electron development launcher", () => {
6 it("uses captured values only as fallbacks for a live runner environment", () => {6 it("uses captured values only as fallbacks for a live runner environment", () => {
...@@ -25,4 +25,24 @@ describe("electron development launcher", () => {...@@ -25,4 +25,24 @@ describe("electron development launcher", () => {
25 "exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",25 "exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",
26 );26 );
27 });27 });
28
29 it("repairs Electron before loading the package entrypoint", () => {
30 const calls = [];
31 const electronPath = resolveElectronBinaryPath({
32 ensureRuntime: () => {
33 calls.push("ensure");
34 },
35 createRequire: () => (specifier) => {
36 calls.push(`require:${specifier}`);
37 return "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron";
38 },
39 moduleUrl: import.meta.url,
40 });
41
42 assert.equal(
43 electronPath,
44 "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron",
45 );
46 assert.deepEqual(calls, ["ensure", "require:electron"]);
47 });
28});48});