diff --git a/AgentCompany-New/electron.vite.config.ts b/AgentCompany-New/electron.vite.config.ts index 71056e1c..d90ddbd8 100644 --- a/AgentCompany-New/electron.vite.config.ts +++ b/AgentCompany-New/electron.vite.config.ts @@ -1,10 +1,19 @@ -import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { dirname, resolve } from "node:path"; import { defineConfig, externalizeDepsPlugin } from "electron-vite"; import react from "@vitejs/plugin-react"; +const __dirname = dirname(fileURLToPath(import.meta.url)); + export default defineConfig({ main: { plugins: [externalizeDepsPlugin()], + resolve: { + alias: { + "@shared": resolve(__dirname, "src/shared"), + "@main": resolve(__dirname, "src/main"), + }, + }, build: { rollupOptions: { input: resolve(__dirname, "src/main/index.ts"), @@ -13,6 +22,12 @@ export default defineConfig({ }, preload: { plugins: [externalizeDepsPlugin()], + resolve: { + alias: { + "@shared": resolve(__dirname, "src/shared"), + "@preload": resolve(__dirname, "src/preload"), + }, + }, build: { rollupOptions: { input: resolve(__dirname, "src/preload/index.ts"), @@ -25,6 +40,12 @@ export default defineConfig({ }, renderer: { root: resolve(__dirname, "src/renderer"), + resolve: { + alias: { + "@shared": resolve(__dirname, "src/shared"), + "@renderer": resolve(__dirname, "src/renderer"), + }, + }, plugins: [react()], }, }); diff --git a/AgentCompany-New/package.json b/AgentCompany-New/package.json index e3fe3b09..6d3da6b5 100644 --- a/AgentCompany-New/package.json +++ b/AgentCompany-New/package.json @@ -27,7 +27,8 @@ "package:mac:arm": "pnpm build && electron-builder --mac --arm64 --publish never", "package:mac:x64": "pnpm build && electron-builder --mac --x64 --publish never", "package:mac": "pnpm build && electron-builder --mac --x64 --arm64 --publish never", - "package:linux": "pnpm build && electron-builder --linux --x64 --publish never" + "package:linux": "pnpm build && electron-builder --linux --x64 --publish never", + "postinstall": "node scripts/ensure-electron.cjs" }, "dependencies": { "lucide-react": "0.468.0", diff --git a/AgentCompany-New/scripts/ensure-electron.cjs b/AgentCompany-New/scripts/ensure-electron.cjs new file mode 100644 index 00000000..5db9c902 --- /dev/null +++ b/AgentCompany-New/scripts/ensure-electron.cjs @@ -0,0 +1,98 @@ +#!/usr/bin/env node +/* + * Ensures the Electron binary exists after `pnpm install`. + * + * On some Windows/Node combos electron's own install script dies silently: + * its extract-zip dependency drops the event loop mid-extraction and the + * process exits 0 with a partial `dist/` and no `path.txt`, which later makes + * electron-vite fail with "Error: Electron uninstall". The download/cache + * layer (@electron/get) is unaffected, so when that happens we fetch the zip + * through it and extract with the OS-native unzipper instead. + * + * No-op when the binary is already in place (the normal case on macOS/Linux). + */ +const { createRequire } = require('node:module'); +const { execFileSync } = require('node:child_process'); +const fs = require('node:fs'); +const path = require('node:path'); + +const electronPkgJson = require.resolve('electron/package.json'); +const electronDir = path.dirname(electronPkgJson); +const electronRequire = createRequire(electronPkgJson); + +const platformPath = { + win32: 'electron.exe', + darwin: 'Electron.app/Contents/MacOS/Electron', + mas: 'Electron.app/Contents/MacOS/Electron', +}[process.platform] || 'electron'; + +function isInstalled() { + try { + return ( + fs.readFileSync(path.join(electronDir, 'path.txt'), 'utf8') === platformPath && + fs.existsSync(path.join(electronDir, 'dist', platformPath)) + ); + } catch { + return false; + } +} + +function extractNatively(zipPath, dist) { + if (process.platform === 'win32') { + execFileSync('powershell.exe', [ + '-NoProfile', '-NonInteractive', '-Command', + `Expand-Archive -LiteralPath "${zipPath}" -DestinationPath "${dist}" -Force`, + ], { stdio: 'inherit' }); + } else if (process.platform === 'darwin') { + // ditto preserves the Electron.app symlinks and executable bits + execFileSync('ditto', ['-xk', zipPath, dist], { stdio: 'inherit' }); + } else { + execFileSync('unzip', ['-oq', zipPath, '-d', dist], { stdio: 'inherit' }); + } +} + +async function main() { + if (isInstalled()) return; + + // Normal route: electron's own installer (covers the case where pnpm + // skipped its build script). + try { + execFileSync(process.execPath, [path.join(electronDir, 'install.js')], { stdio: 'inherit' }); + } catch { + // fall through to the manual route + } + if (isInstalled()) return; + + console.log('[ensure-electron] electron install script left no binary; extracting manually...'); + const { downloadArtifact } = electronRequire('@electron/get'); + const { version } = electronRequire('./package.json'); + const zipPath = await downloadArtifact({ + version, + artifactName: 'electron', + cacheRoot: process.env.electron_config_cache, + checksums: electronRequire('./checksums.json'), + platform: process.platform, + arch: process.arch, + }); + + const dist = path.join(electronDir, 'dist'); + fs.rmSync(dist, { recursive: true, force: true }); + fs.mkdirSync(dist, { recursive: true }); + extractNatively(zipPath, dist); + + const typeDef = path.join(dist, 'electron.d.ts'); + if (fs.existsSync(typeDef)) { + fs.renameSync(typeDef, path.join(electronDir, 'electron.d.ts')); + } + fs.writeFileSync(path.join(electronDir, 'path.txt'), platformPath); + + if (!isInstalled()) { + throw new Error('Electron binary still missing after manual extraction'); + } + console.log('[ensure-electron] Electron binary restored.'); +} + +main().catch((err) => { + console.error('[ensure-electron] failed:', err); + process.exit(1); +});