()
| 26 | * Uses centralized methods for path validation. |
| 27 | */ |
| 28 | export async function startServer(): Promise<void> { |
| 29 | const isDev = !app.isPackaged; |
| 30 | |
| 31 | // Find Node.js executable (handles desktop launcher scenarios) |
| 32 | const nodeResult = findNodeExecutable({ |
| 33 | skipSearch: isDev, |
| 34 | logger: (msg: string) => logger.info(msg), |
| 35 | }); |
| 36 | const command = nodeResult.nodePath; |
| 37 | |
| 38 | // Validate that the found Node executable actually exists |
| 39 | // systemPathExists is used because node-finder returns system paths |
| 40 | if (command !== 'node') { |
| 41 | let exists: boolean; |
| 42 | try { |
| 43 | exists = systemPathExists(command); |
| 44 | } catch (error) { |
| 45 | const originalError = error instanceof Error ? error.message : String(error); |
| 46 | throw new Error( |
| 47 | `Failed to verify Node.js executable at: ${command} (source: ${nodeResult.source}). Reason: ${originalError}` |
| 48 | ); |
| 49 | } |
| 50 | if (!exists) { |
| 51 | throw new Error(`Node.js executable not found at: ${command} (source: ${nodeResult.source})`); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | let args: string[]; |
| 56 | let serverPath: string; |
| 57 | |
| 58 | // __dirname is apps/ui/dist-electron (Vite bundles all into single file) |
| 59 | if (isDev) { |
| 60 | serverPath = path.join(__dirname, '../../server/src/index.ts'); |
| 61 | |
| 62 | const serverNodeModules = path.join(__dirname, '../../server/node_modules/tsx'); |
| 63 | const rootNodeModules = path.join(__dirname, '../../../node_modules/tsx'); |
| 64 | |
| 65 | let tsxCliPath: string; |
| 66 | // Check for tsx in app bundle paths, fallback to require.resolve |
| 67 | const serverTsxPath = path.join(serverNodeModules, 'dist/cli.mjs'); |
| 68 | const rootTsxPath = path.join(rootNodeModules, 'dist/cli.mjs'); |
| 69 | |
| 70 | try { |
| 71 | if (electronAppExists(serverTsxPath)) { |
| 72 | tsxCliPath = serverTsxPath; |
| 73 | } else if (electronAppExists(rootTsxPath)) { |
| 74 | tsxCliPath = rootTsxPath; |
| 75 | } else { |
| 76 | // Fallback to require.resolve |
| 77 | tsxCliPath = require.resolve('tsx/cli.mjs', { |
| 78 | paths: [path.join(__dirname, '../../server')], |
| 79 | }); |
| 80 | } |
| 81 | } catch { |
| 82 | // electronAppExists threw or require.resolve failed |
| 83 | try { |
| 84 | tsxCliPath = require.resolve('tsx/cli.mjs', { |
| 85 | paths: [path.join(__dirname, '../../server')], |
no test coverage detected