From a7272803dff49d52b8fcf95d1fb834ccdcf88f9c Mon Sep 17 00:00:00 2001 From: roberto Date: Tue, 3 Mar 2026 18:14:11 +0100 Subject: [PATCH] feat: enhance packageAfterCopy hook to remove non-target prebuilt binaries --- forge.config.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/forge.config.ts b/forge.config.ts index a85a35a..81eaff2 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -35,7 +35,7 @@ const config: ForgeConfig = { }, rebuildConfig: {}, hooks: { - packageAfterCopy: async (_forgeConfig, buildPath) => { + packageAfterCopy: async (_forgeConfig, buildPath, _electronVersion, platform, arch) => { // 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 @@ -68,6 +68,37 @@ const config: ForgeConfig = { stdio: 'inherit', env: { ...process.env, npm_config_nodedir: '' }, }); + + // Remove cross-platform prebuilt binaries that don't match the target. + // Packages like @github/copilot ship prebuilds for all platforms; + // keeping foreign-arch .node files breaks rpmbuild's strip step. + const targetDir = `${platform}-${arch}`; + const nmPath = path.join(buildPath, 'node_modules'); + const findPrebuilds = (dir: string): string[] => { + const results: string[] = []; + if (!fs.existsSync(dir)) return results; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) { + if (entry.name === 'prebuilds') { + results.push(full); + } else { + results.push(...findPrebuilds(full)); + } + } + } + return results; + }; + + for (const prebuildsDir of findPrebuilds(nmPath)) { + for (const entry of fs.readdirSync(prebuildsDir)) { + if (entry !== targetDir) { + const fullPath = path.join(prebuildsDir, entry); + fs.rmSync(fullPath, { recursive: true, force: true }); + console.log(`[forge] Removed non-target prebuild: ${entry}`); + } + } + } }, }, makers: [