Skip to content

Commit 58c801b

Browse files
committed
Fix electron dev launch and add test
1 parent 7b9eef7 commit 58c801b

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ function resolveLinuxSandboxArgs(electronBinaryPath) {
358358
}
359359

360360
export function resolveElectronPath() {
361-
ensureElectronRuntime();
362-
363-
const require = NodeModule.createRequire(import.meta.url);
364-
const electronBinaryPath = require("electron");
361+
const electronBinaryPath = resolveElectronBinaryPath();
365362

366363
if (hostPlatform !== "darwin") {
367364
return electronBinaryPath;
@@ -378,13 +375,23 @@ export function resolveElectronLaunchCommand(args = []) {
378375
};
379376
}
380377

378+
export 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+
381389
export function resolveDevProtocolClient() {
382390
if (hostPlatform !== "darwin" || !isDevelopment) {
383391
return null;
384392
}
385393

386-
const require = NodeModule.createRequire(import.meta.url);
387-
const electronBinaryPath = require("electron");
394+
const electronBinaryPath = resolveElectronBinaryPath();
388395
const launcherBinaryPath = buildMacLauncher(electronBinaryPath);
389396
return {
390397
appBundlePath: NodePath.resolve(launcherBinaryPath, "..", "..", ".."),

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, describe, it } from "vite-plus/test";
22

3-
import { makeDevelopmentLauncherScript } from "./electron-launcher.mjs";
3+
import { makeDevelopmentLauncherScript, resolveElectronBinaryPath } from "./electron-launcher.mjs";
44

55
describe("electron development launcher", () => {
66
it("uses captured values only as fallbacks for a live runner environment", () => {
@@ -25,4 +25,24 @@ describe("electron development launcher", () => {
2525
"exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",
2626
);
2727
});
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+
});
2848
});

0 commit comments

Comments
 (0)