From 3b3bb26ef4a7a12e04b4521200c2173684e350d6 Mon Sep 17 00:00:00 2001 From: Mark Benson <41453195+thealternator89@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:41:18 +1200 Subject: [PATCH] feat: add packageAfterCopy hook to install external dependencies --- forge.config.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/forge.config.ts b/forge.config.ts index 1e9a81e..7bbeb99 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -7,6 +7,9 @@ import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-nati import { WebpackPlugin } from '@electron-forge/plugin-webpack'; import { FusesPlugin } from '@electron-forge/plugin-fuses'; import { FuseV1Options, FuseVersion } from '@electron/fuses'; +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; import { mainConfig } from './webpack.main.config'; import { rendererConfig } from './webpack.renderer.config'; @@ -58,6 +61,45 @@ const config: ForgeConfig = { [FuseV1Options.OnlyLoadAppFromAsar]: true, }), ], + hooks: { + packageAfterCopy: async ( + forgeConfig, + buildPath, + _electronVersion, + _platform, + _arch, + ) => { + console.log('Hook: Installing external dependencies...'); + + // 1. Use process.cwd() for ESM/TS compatibility + const rootDir = process.cwd(); + const pkgPath = path.join(rootDir, 'package.json'); + + // 2. Read and parse your app's main package.json + const appPkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); + + // 3. Create a minimal package.json in the packaged app directory + const buildPkgPath = path.join(buildPath, 'package.json'); + const buildPkg = { + name: 'protrack3-externals', + private: true, + dependencies: { + sqlite3: appPkg.dependencies?.['sqlite3'], + 'azure-devops-node-api': appPkg.dependencies?.['azure-devops-node-api'], + }, + }; + + fs.writeFileSync(buildPkgPath, JSON.stringify(buildPkg, null, 2)); + + // 4. Run npm install inside the packaged folder + execSync('npm install --omit=dev', { + cwd: buildPath, + stdio: 'inherit', + }); + + console.log('Hook: External dependencies installed successfully!'); + }, + }, }; export default config;