sign-windows-hook.cjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { spawnSync } = require("node:child_process");
  2. const { resolve } = require("node:path");
  3. const signScriptPath = resolve(__dirname, "../../../scripts/sign-windows.ps1");
  4. async function sign(configuration) {
  5. if (configuration.isNest) {
  6. // Bugfix: electron-builder 会按 sha1/sha256 多次调用 Windows signer,
  7. // 但 vsigntool 这套封装本身会完成完整签名流程,重复再签只会增加不确定性。
  8. // 这里跳过嵌套签名,统一以首轮调用为准,避免同一文件被重复处理。
  9. return;
  10. }
  11. const result = spawnSync(
  12. "powershell.exe",
  13. [
  14. "-NoProfile",
  15. "-ExecutionPolicy",
  16. "Bypass",
  17. "-File",
  18. signScriptPath,
  19. "-FilePath",
  20. configuration.path,
  21. ],
  22. {
  23. stdio: "inherit",
  24. env: process.env,
  25. },
  26. );
  27. if (result.error) {
  28. throw result.error;
  29. }
  30. if (result.status !== 0) {
  31. throw new Error(
  32. `[sign-windows-hook] vsigntool failed for ${configuration.path} with code ${result.status ?? "unknown"}`,
  33. );
  34. }
  35. }
  36. module.exports = sign;
  37. module.exports.sign = sign;