From dc44cbc9f052f4e3c1133fd6e3e730ec5cdd659b Mon Sep 17 00:00:00 2001 From: roberto Date: Tue, 3 Mar 2026 18:04:04 +0100 Subject: [PATCH] refactor: remove Windows prebuilt native module download step and update package handling in build process --- .gitea/workflows/build.yaml | 16 ----------- forge.config.ts | 56 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 3597c8b..b823570 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -37,22 +37,6 @@ jobs: env: WINEDEBUG: '-all' - - name: Download Windows prebuilt native modules - shell: bash - run: | - ELECTRON_VERSION=$(node -e "console.log(require('electron/package.json').version)") - echo "Downloading prebuilt native modules for Electron ${ELECTRON_VERSION} (win32/x64)..." - - # better-sqlite3 - cd node_modules/better-sqlite3 - npx --yes prebuild-install -r electron -t ${ELECTRON_VERSION} --platform win32 --arch x64 --verbose - cd ../.. - - # keytar - cd node_modules/keytar - npx --yes prebuild-install -r electron -t ${ELECTRON_VERSION} --platform win32 --arch x64 --verbose || echo "keytar prebuilt not available, skipping" - cd ../.. - - name: Make App (Windows) run: npm run make -- --platform=win32 --arch=x64 env: diff --git a/forge.config.ts b/forge.config.ts index 2654b89..a85a35a 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -7,15 +7,69 @@ import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-nati import { VitePlugin } from '@electron-forge/plugin-vite'; import { FusesPlugin } from '@electron-forge/plugin-fuses'; import { FuseV1Options, FuseVersion } from '@electron/fuses'; +import path from 'node:path'; +import fs from 'node:fs'; +import { execSync } from 'node:child_process'; + +// Packages externalized in vite.main.config.mts that must be installed at runtime. +// Keep this list in sync with the Vite external array. +const externalPackages = [ + 'better-sqlite3', + 'keytar', + '@github/copilot-sdk', + '@langchain/core', + '@langchain/langgraph', + '@langchain/openai', + '@langchain/anthropic', + 'vectordb', + 'electron-squirrel-startup', + 'electron-store', +]; const config: ForgeConfig = { packagerConfig: { asar: { - unpack: '**/node_modules/{better-sqlite3,keytar}/**', + unpack: '**/{*.node,*.dll,*.so,*.dylib}', }, name: 'adiuva', }, rebuildConfig: {}, + hooks: { + packageAfterCopy: async (_forgeConfig, buildPath) => { + // The VitePlugin's ignore filter only copies .vite/ into the build. + // Externalized packages need to be installed into node_modules here. + // At this point, only .vite/ exists. The VitePlugin writes package.json + // in its own afterCopy hook (which may run after ours). Read from source. + const srcPjPath = path.resolve(__dirname, 'package.json'); + const pjPath = path.resolve(buildPath, 'package.json'); + const pj = JSON.parse(fs.readFileSync(srcPjPath, 'utf-8')); + + // Keep only externalized packages in dependencies + const filtered: Record = {}; + for (const pkg of externalPackages) { + if (pj.dependencies?.[pkg]) { + filtered[pkg] = pj.dependencies[pkg]; + } + } + pj.dependencies = filtered; + delete pj.devDependencies; + fs.writeFileSync(pjPath, JSON.stringify(pj, null, 2)); + + // Copy lockfile for reproducible installs + const lockSrc = path.resolve(buildPath, '..', '..', 'package-lock.json'); + if (fs.existsSync(lockSrc)) { + fs.copyFileSync(lockSrc, path.resolve(buildPath, 'package-lock.json')); + } + + // Install only the externalized runtime deps + console.log('[forge] Installing externalized dependencies...'); + execSync('npm install --omit=dev', { + cwd: buildPath, + stdio: 'inherit', + env: { ...process.env, npm_config_nodedir: '' }, + }); + }, + }, makers: [ new MakerSquirrel({}), new MakerZIP({}, ['darwin']),