From d93584141c21fceff7eda1ae5d256eed6dd5f74f Mon Sep 17 00:00:00 2001 From: lahiruudayakumara <79270918+lahiruudayakumara@users.noreply.github.com> Date: Wed, 3 Jun 2026 15:31:23 +0530 Subject: [PATCH] fix: recrusive run --- apps/desktop/scripts/verify-electron.mjs | 95 ++++++++++++++++++++---- docs/development/local-development.md | 2 +- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/apps/desktop/scripts/verify-electron.mjs b/apps/desktop/scripts/verify-electron.mjs index fd5582f..7a48a3c 100644 --- a/apps/desktop/scripts/verify-electron.mjs +++ b/apps/desktop/scripts/verify-electron.mjs @@ -1,3 +1,4 @@ +import { spawnSync } from "node:child_process"; import { existsSync, readFileSync } from "node:fs"; import { createRequire } from "node:module"; import path from "node:path"; @@ -19,6 +20,76 @@ function fail(message) { process.exit(1); } +function inspectElectronRuntime(electronPackageDir) { + const pathFile = path.join(electronPackageDir, "path.txt"); + + if (!existsSync(pathFile)) { + return { + message: + "Electron package metadata exists, but the downloaded binary marker file path.txt is missing.", + ok: false, + }; + } + + const executableRelativePath = readFileSync(pathFile, "utf8").trim(); + + if (!executableRelativePath) { + return { + message: "Electron path.txt is empty, so the runtime executable cannot be located.", + ok: false, + }; + } + + const executablePath = path.join(electronPackageDir, "dist", executableRelativePath); + + if (!existsSync(executablePath)) { + return { + message: `Electron expected a runtime executable at ${executablePath}, but it was not found.`, + ok: false, + }; + } + + return { ok: true }; +} + +function attemptRepair(electronPackageDir, reason) { + const installScript = path.join(electronPackageDir, "install.js"); + + if (!existsSync(installScript)) { + return { + message: `Automatic repair could not start because ${installScript} does not exist.`, + ok: false, + }; + } + + console.warn(""); + console.warn("[Corexa desktop] Electron runtime is incomplete."); + console.warn(`[Corexa desktop] ${reason}`); + console.warn("[Corexa desktop] Attempting an automatic Electron repair..."); + console.warn(""); + + const result = spawnSync(process.execPath, [installScript], { + cwd: electronPackageDir, + stdio: "inherit", + }); + + if (result.error) { + return { + message: `Automatic Electron repair failed to start: ${result.error.message}`, + ok: false, + }; + } + + if (result.status !== 0) { + return { + message: `Automatic Electron repair exited with status ${result.status ?? "unknown"}.`, + ok: false, + }; + } + + return { ok: true }; +} + let electronPackageDir; try { @@ -27,22 +98,18 @@ try { fail("The electron package could not be resolved from apps/desktop/node_modules."); } -const pathFile = path.join(electronPackageDir, "path.txt"); +let runtimeState = inspectElectronRuntime(electronPackageDir); -if (!existsSync(pathFile)) { - fail( - "Electron package metadata exists, but the downloaded binary marker file path.txt is missing.", - ); -} +if (!runtimeState.ok) { + const repairResult = attemptRepair(electronPackageDir, runtimeState.message); -const executableRelativePath = readFileSync(pathFile, "utf8").trim(); - -if (!executableRelativePath) { - fail("Electron path.txt is empty, so the runtime executable cannot be located."); -} + if (!repairResult.ok) { + fail(repairResult.message); + } -const executablePath = path.join(electronPackageDir, "dist", executableRelativePath); + runtimeState = inspectElectronRuntime(electronPackageDir); -if (!existsSync(executablePath)) { - fail(`Electron expected a runtime executable at ${executablePath}, but it was not found.`); + if (!runtimeState.ok) { + fail(`Automatic repair completed, but Electron is still incomplete. ${runtimeState.message}`); + } } diff --git a/docs/development/local-development.md b/docs/development/local-development.md index 7e1c47f..41e8e98 100644 --- a/docs/development/local-development.md +++ b/docs/development/local-development.md @@ -34,7 +34,7 @@ cargo test --manifest-path native/tree-sitter-indexer/Cargo.toml ## Desktop Troubleshooting -If Electron is installed but the binary payload is missing: +If Electron is installed but the binary payload is missing, the desktop preflight now attempts an automatic repair before it exits. If you still need to repair it manually: ```bash pnpm --filter @corexa/desktop run repair:electron