From 072fbbad2cd10966ea637f2b7b0585edeae2e3b0 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 29 Dec 2025 11:14:39 -0800 Subject: [PATCH] =?UTF-8?q?fix(service-party-app):=20=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?afterPack=20hook=20=E7=A1=AE=E4=BF=9D=20TSS=20=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E8=A2=AB=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - extraResources 的 ${platform}-${arch} 宏在 from 路径中可能不可靠 - 参考: https://github.com/electron-userland/electron-builder/issues/7891 解决: - 创建 afterPack.js hook 手动复制对应平台/架构的二进制文件 - 移除 extraResources 配置,改用 hook 方式 - 确保 tss-party 二进制文件被正确复制到 resources/bin/ 目录 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 --- .../service-party-app/electron-builder.json | 8 +- .../service-party-app/scripts/afterPack.js | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 backend/mpc-system/services/service-party-app/scripts/afterPack.js diff --git a/backend/mpc-system/services/service-party-app/electron-builder.json b/backend/mpc-system/services/service-party-app/electron-builder.json index c9797bb8..c38ded5b 100644 --- a/backend/mpc-system/services/service-party-app/electron-builder.json +++ b/backend/mpc-system/services/service-party-app/electron-builder.json @@ -11,13 +11,7 @@ "dist/**/*", "dist-electron/**/*" ], - "extraResources": [ - { - "from": "bin/${platform}-${arch}", - "to": "bin", - "filter": ["**/*"] - } - ], + "afterPack": "./scripts/afterPack.js", "extraMetadata": { "main": "dist-electron/main.js" }, diff --git a/backend/mpc-system/services/service-party-app/scripts/afterPack.js b/backend/mpc-system/services/service-party-app/scripts/afterPack.js new file mode 100644 index 00000000..5167123f --- /dev/null +++ b/backend/mpc-system/services/service-party-app/scripts/afterPack.js @@ -0,0 +1,75 @@ +const fs = require('fs'); +const path = require('path'); + +/** + * afterPack hook - 在打包后复制 TSS 二进制文件到正确位置 + * + * 由于 electron-builder 的 extraResources 的 ${platform}/${arch} 宏 + * 在 from 路径中可能不稳定,使用 afterPack hook 确保可靠复制 + * + * 参考: https://github.com/electron-userland/electron-builder/issues/7891 + */ +exports.default = async function afterPack(context) { + const { appOutDir, packager } = context; + const platform = packager.platform.name; // 'mac', 'linux', 'windows' + const arch = context.arch; // 1 = x64, 3 = arm64, etc. + + // 映射 arch 数字到字符串 + const archMap = { + 1: 'x64', + 3: 'arm64', + 0: 'ia32', + }; + const archStr = archMap[arch] || 'x64'; + + // 映射 platform 到 Node.js process.platform 风格 + const platformMap = { + 'windows': 'win32', + 'mac': 'darwin', + 'linux': 'linux', + }; + const platformStr = platformMap[platform] || platform; + + console.log(`[afterPack] Platform: ${platform} (${platformStr}), Arch: ${arch} (${archStr})`); + + // 源目录和目标目录 + const sourceDir = path.join(__dirname, '..', 'bin', `${platformStr}-${archStr}`); + const targetDir = path.join(appOutDir, 'resources', 'bin'); + + console.log(`[afterPack] Source: ${sourceDir}`); + console.log(`[afterPack] Target: ${targetDir}`); + + // 检查源目录是否存在 + if (!fs.existsSync(sourceDir)) { + console.warn(`[afterPack] Source directory not found: ${sourceDir}`); + console.warn(`[afterPack] Skipping binary copy for ${platformStr}-${archStr}`); + return; + } + + // 创建目标目录 + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir, { recursive: true }); + console.log(`[afterPack] Created target directory: ${targetDir}`); + } + + // 复制所有文件 + const files = fs.readdirSync(sourceDir); + for (const file of files) { + const sourcePath = path.join(sourceDir, file); + const targetPath = path.join(targetDir, file); + + // 获取文件信息 + const stat = fs.statSync(sourcePath); + if (stat.isFile()) { + fs.copyFileSync(sourcePath, targetPath); + console.log(`[afterPack] Copied: ${file} (${(stat.size / 1024 / 1024).toFixed(2)} MB)`); + + // 在 Unix 系统上设置可执行权限 + if (platformStr !== 'win32') { + fs.chmodSync(targetPath, 0o755); + } + } + } + + console.log(`[afterPack] Binary copy completed for ${platformStr}-${archStr}`); +};