Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

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

Theo Browne6d35a87c5d0e
diff --git a/apps/desktop/scripts/electron-launcher.mjs b/apps/desktop/scripts/electron-launcher.mjs
index cfe110f0e..081ef903a 100644
--- a/apps/desktop/scripts/electron-launcher.mjs
+++ b/apps/desktop/scripts/electron-launcher.mjs
@@ -358,10 +358,7 @@ function resolveLinuxSandboxArgs(electronBinaryPath) {
}
export function resolveElectronPath() {
- ensureElectronRuntime();
-
- const require = NodeModule.createRequire(import.meta.url);
- const electronBinaryPath = require("electron");
+ const electronBinaryPath = resolveElectronBinaryPath();
if (hostPlatform !== "darwin") {
return electronBinaryPath;
@@ -378,13 +375,23 @@ export function resolveElectronLaunchCommand(args = []) {
};
}
+export function resolveElectronBinaryPath({
+ ensureRuntime = ensureElectronRuntime,
+ createRequire = NodeModule.createRequire,
+ moduleUrl = import.meta.url,
+} = {}) {
+ ensureRuntime();
+
+ const require = createRequire(moduleUrl);
+ return require("electron");
+}
+
export function resolveDevProtocolClient() {
if (hostPlatform !== "darwin" || !isDevelopment) {
return null;
}
- const require = NodeModule.createRequire(import.meta.url);
- const electronBinaryPath = require("electron");
+ const electronBinaryPath = resolveElectronBinaryPath();
const launcherBinaryPath = buildMacLauncher(electronBinaryPath);
return {
appBundlePath: NodePath.resolve(launcherBinaryPath, "..", "..", ".."),
diff --git a/apps/desktop/scripts/electron-launcher.test.mjs b/apps/desktop/scripts/electron-launcher.test.mjs
index 5a1df0ec6..36e9429e4 100644
--- a/apps/desktop/scripts/electron-launcher.test.mjs
+++ b/apps/desktop/scripts/electron-launcher.test.mjs
@@ -1,6 +1,6 @@
import { assert, describe, it } from "vite-plus/test";
-import { makeDevelopmentLauncherScript } from "./electron-launcher.mjs";
+import { makeDevelopmentLauncherScript, resolveElectronBinaryPath } from "./electron-launcher.mjs";
describe("electron development launcher", () => {
it("uses captured values only as fallbacks for a live runner environment", () => {
@@ -25,4 +25,24 @@ describe("electron development launcher", () => {
"exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",
);
});
+
+ it("repairs Electron before loading the package entrypoint", () => {
+ const calls = [];
+ const electronPath = resolveElectronBinaryPath({
+ ensureRuntime: () => {
+ calls.push("ensure");
+ },
+ createRequire: () => (specifier) => {
+ calls.push(`require:${specifier}`);
+ return "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron";
+ },
+ moduleUrl: import.meta.url,
+ });
+
+ assert.equal(
+ electronPath,
+ "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron",
+ );
+ assert.deepEqual(calls, ["ensure", "require:electron"]);
+ });
});