prepare-runtime-assets.mjs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env node
  2. import process from "node:process";
  3. import { dirname, resolve } from "node:path";
  4. import { fileURLToPath } from "node:url";
  5. import { resolveNativeSearchReleasePlan } from "../../../scripts/native-search-tools-config.mjs";
  6. import { runCommand } from "../../../scripts/spawn-command.mjs";
  7. import { getTargetPlatform } from "./target-platform.mjs";
  8. import { isRealComputerUseProducerInstalled } from "./computer-use-producer.mjs";
  9. const scriptDir = dirname(fileURLToPath(import.meta.url));
  10. const desktopRoot = resolve(scriptDir, "..");
  11. const pnpmCommand = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
  12. const target = getTargetPlatform();
  13. const nativeSearchReleasePlan = resolveNativeSearchReleasePlan({
  14. platform: target.os,
  15. arch: target.arch,
  16. });
  17. // Windows Chrome 导入入口未启用,默认构建继续编译 helper 会增加 CI 时间和发布签名面。
  18. // 保留显式开关,后续恢复入口时仍可复用既有原生实现和供应链校验。
  19. const shouldPrepareWindowsBrowserImportHelper =
  20. target.os === "win32" && process.env.ZCODE_ENABLE_WINDOWS_BROWSER_IMPORT === "1";
  21. // Windows Computer Use Helper 由真实 producer 提供;开源占位包没有 Helper runtime,跳过准备。
  22. const shouldPrepareWindowsCuaHelper =
  23. target.os === "win32" && isRealComputerUseProducerInstalled({ desktopPackageRoot: desktopRoot });
  24. // CUA 权限浮窗的吸附数据源。仅 macOS;缺 swiftc 时脚本内部自行降级为跳过(浮窗 fail-open
  25. // 到屏幕底部,仍可用),所以无条件挂在 darwin 上不会让构建变脆。
  26. const shouldPrepareMacosWindowBounds = target.os === "darwin";
  27. // 本机桌面包不再内置 glm 原生二进制(prepare:glm),改为内置 agent 的 JS bundle(prepare:agent-bundle),
  28. // 运行时由 app 的 Electron Node runtime 执行。Source Server 资源由独立 stage:remote-assets 入口负责。
  29. const localRuntimeScripts = [
  30. "prepare:agent-bundle",
  31. ...(target.os === "win32" ? ["prepare:windows-runtime-host"] : []),
  32. ...(shouldPrepareWindowsCuaHelper ? ["prepare:windows-cua-helper"] : []),
  33. ...(nativeSearchReleasePlan.enabled ? ["prepare:native-search"] : []),
  34. ...(shouldPrepareWindowsBrowserImportHelper ? ["prepare:browser-import-helper"] : []),
  35. // 预装工具的 Windows 入口都由这个 shim 提供;缺失时入口无法写入。
  36. ...(target.os === "win32" ? ["prepare:preinstalled-entry-shim"] : []),
  37. ...(shouldPrepareMacosWindowBounds ? ["prepare:macos-window-bounds"] : []),
  38. ];
  39. function runTimedPnpmScript(scriptName) {
  40. const startMs = Date.now();
  41. console.log(`[ci][timer] prepare-runtime-assets:${scriptName} start`);
  42. try {
  43. runCommand(pnpmCommand, [scriptName], {
  44. cwd: desktopRoot,
  45. env: process.env,
  46. });
  47. } finally {
  48. console.log(
  49. `[ci][timer] prepare-runtime-assets:${scriptName} end duration_ms=${Date.now() - startMs}`,
  50. );
  51. }
  52. }
  53. for (const scriptName of localRuntimeScripts) {
  54. runTimedPnpmScript(scriptName);
  55. }