From 89216c01e57a6b66e7a9e7b015f0f8cf8220acee Mon Sep 17 00:00:00 2001 From: trueheads Date: Sat, 13 Dec 2025 11:23:58 -0600 Subject: [PATCH] fixes for windows, but maybe breaking linux --- apps/app/electron/main.js | 40 ++++++++++++++++++++++++++++++++++----- apps/server/package.json | 2 +- package-lock.json | 22 ++++++++++----------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/apps/app/electron/main.js b/apps/app/electron/main.js index 9ae31c32..0fd95d97 100644 --- a/apps/app/electron/main.js +++ b/apps/app/electron/main.js @@ -7,6 +7,7 @@ const path = require("path"); const { spawn } = require("child_process"); +const fs = require("fs"); // Load environment variables from .env file require("dotenv").config({ path: path.join(__dirname, "../.env") }); @@ -30,10 +31,39 @@ function getIconPath() { async function startServer() { const isDev = !app.isPackaged; - // Server entry point - const serverPath = isDev - ? path.join(__dirname, "../../server/dist/index.js") - : path.join(process.resourcesPath, "server", "index.js"); + // Server entry point - use tsx in dev, compiled version in production + let command, args, serverPath; + if (isDev) { + // In development, use tsx to run TypeScript directly + // Use the node executable that's running Electron + command = process.execPath; // This is the path to node.exe + serverPath = path.join(__dirname, "../../server/src/index.ts"); + + // Find tsx CLI - check server node_modules first, then root + const serverNodeModules = path.join(__dirname, "../../server/node_modules/tsx"); + const rootNodeModules = path.join(__dirname, "../../../node_modules/tsx"); + + let tsxCliPath; + if (fs.existsSync(path.join(serverNodeModules, "dist/cli.mjs"))) { + tsxCliPath = path.join(serverNodeModules, "dist/cli.mjs"); + } else if (fs.existsSync(path.join(rootNodeModules, "dist/cli.mjs"))) { + tsxCliPath = path.join(rootNodeModules, "dist/cli.mjs"); + } else { + // Last resort: try require.resolve + try { + tsxCliPath = require.resolve("tsx/cli.mjs", { paths: [path.join(__dirname, "../../server")] }); + } catch { + throw new Error("Could not find tsx. Please run 'npm install' in the server directory."); + } + } + + args = [tsxCliPath, "watch", serverPath]; + } else { + // In production, use compiled JavaScript + command = "node"; + serverPath = path.join(process.resourcesPath, "server", "index.js"); + args = [serverPath]; + } // Set environment variables for server const env = { @@ -44,7 +74,7 @@ async function startServer() { console.log("[Electron] Starting backend server..."); - serverProcess = spawn("node", [serverPath], { + serverProcess = spawn(command, args, { env, stdio: ["ignore", "pipe", "pipe"], }); diff --git a/apps/server/package.json b/apps/server/package.json index 113595a1..9dce2d38 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -16,7 +16,7 @@ "cors": "^2.8.5", "dotenv": "^17.2.3", "express": "^5.1.0", - "node-pty": "^1.0.0", + "node-pty": "1.1.0-beta41", "ws": "^8.18.0" }, "devDependencies": { diff --git a/package-lock.json b/package-lock.json index f27451ed..3268efa5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10260,7 +10260,7 @@ "cors": "^2.8.5", "dotenv": "^17.2.3", "express": "^5.1.0", - "node-pty": "^1.0.0", + "node-pty": "1.1.0-beta41", "ws": "^8.18.0" }, "devDependencies": { @@ -13465,12 +13465,6 @@ "dev": true, "license": "MIT" }, - "node_modules/nan": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.24.0.tgz", - "integrity": "sha512-Vpf9qnVW1RaDkoNKFUvfxqAbtI8ncb8OJlqZ9wwpXzWPEsvsB1nvdUi6oYrHIkQ1Y/tMDnr1h4nczS0VB9Xykg==", - "license": "MIT" - }, "node_modules/nanoid": { "version": "3.3.11", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", @@ -13552,14 +13546,20 @@ } } }, + "node_modules/node-addon-api": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "license": "MIT" + }, "node_modules/node-pty": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-pty/-/node-pty-1.0.0.tgz", - "integrity": "sha512-wtBMWWS7dFZm/VgqElrTvtfMq4GzJ6+edFI0Y0zyzygUSZMgZdraDUMUhCIvkjhJjme15qWmbyJbtAx4ot4uZA==", + "version": "1.1.0-beta41", + "resolved": "https://registry.npmjs.org/node-pty/-/node-pty-1.1.0-beta41.tgz", + "integrity": "sha512-OUT29KMnzh1IS0b2YcUwVz56D4iAXDsl2PtIKP3zHMljiUBq2WcaHEFfhzQfgkhWs2SExcXvfdlBPANDVU9SnQ==", "hasInstallScript": true, "license": "MIT", "dependencies": { - "nan": "^2.17.0" + "node-addon-api": "^7.1.0" } }, "node_modules/npm-run-path": {