aws-runtime-bridge 1.9.105 → 1.9.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-runtime-bridge",
3
- "version": "1.9.105",
3
+ "version": "1.9.107",
4
4
  "description": "AgentsWorkStudio runtime bridge service for machine-level agent runtime integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,11 +11,14 @@
11
11
  * 浏览器内核与系统依赖(libnss3 等)一步到位;--with-deps 失败时回退为仅下载内核。
12
12
  * - Linux 非 root:仅下载内核,缺系统库时输出可操作的 sudo 提示。
13
13
  * - 其他平台(Windows/macOS):`install chromium`(系统库由系统自带)。
14
+ * - 下载源:动态读取当前 npm registry 配置,若为 npmmirror/taobao 系镜像则自动
15
+ * 推导对应的 Playwright 二进制镜像加速下载;官方源或其他源走 playwright 默认 CDN。
16
+ * 用户显式设置 PLAYWRIGHT_DOWNLOAD_HOST 时优先尊重用户选择。
14
17
  * - 幂等:playwright 检测到浏览器已安装时直接跳过,重复安装无副作用。
15
18
  * - 容错:任何失败仅警告并给出手动命令,绝不阻断 npm 安装。
16
19
  * - 跳过:设置环境变量 AWS_BRIDGE_SKIP_PLAYWRIGHT_INSTALL=1。
17
20
  */
18
- import { execFile } from "node:child_process";
21
+ import { execFile, spawnSync } from "node:child_process";
19
22
  import { createRequire } from "node:module";
20
23
  import { dirname, join } from "node:path";
21
24
  import { promisify } from "node:util";
@@ -36,7 +39,47 @@ function resolvePlaywrightCliPath() {
36
39
  }
37
40
  }
38
41
 
39
- async function runInstall(cliPath, args) {
42
+ /**
43
+ * 读取当前 npm 配置中的 registry(综合 npm config get registry 与 .npmrc)。
44
+ * 失败时返回 null,调用方按官方源默认处理。
45
+ */
46
+ function resolveNpmRegistry() {
47
+ try {
48
+ const result = spawnSync("npm", ["config", "get", "registry"], {
49
+ encoding: "utf-8",
50
+ shell: process.platform === "win32",
51
+ stdio: ["ignore", "pipe", "ignore"],
52
+ });
53
+ if (result.status === 0 && result.stdout) {
54
+ const url = result.stdout.trim();
55
+ if (url && !/^undefined$/i.test(url)) return url;
56
+ }
57
+ } catch {
58
+ // 忽略,返回 null
59
+ }
60
+ return null;
61
+ }
62
+
63
+ /**
64
+ * 根据 npm registry 推导 Playwright 二进制镜像下载源。
65
+ *
66
+ * 映射规则:
67
+ * - npmmirror.com / npm.taobao.org 系:返回 https://npmmirror.com/mirrors/playwright
68
+ * (npmmirror 的 binary 镜像路径,已验证可用,与 playwright 的 ${host}/${downloadPath} 拼接格式匹配)
69
+ * - 官方源 registry.npmjs.org 或 null:返回 null,走 playwright 默认 CDN
70
+ * - 其他未知源:返回 null,避免错误覆盖
71
+ */
72
+ function resolvePlaywrightDownloadHost(registry) {
73
+ if (!registry) return null;
74
+ const r = registry.toLowerCase();
75
+ if (r.includes("npmmirror.com") || r.includes("npm.taobao.org")) {
76
+ return "https://npmmirror.com/mirrors/playwright";
77
+ }
78
+ // 其他镜像源不自动推导,避免路径错误
79
+ return null;
80
+ }
81
+
82
+ async function runInstall(cliPath, args, env) {
40
83
  const { stdout, stderr } = await execFileAsync(
41
84
  process.execPath,
42
85
  [cliPath, ...args],
@@ -44,6 +87,7 @@ async function runInstall(cliPath, args) {
44
87
  timeout: INSTALL_TIMEOUT_MS,
45
88
  maxBuffer: 16 * 1024 * 1024,
46
89
  windowsHide: true,
90
+ env,
47
91
  },
48
92
  );
49
93
  return `${stdout ?? ""}${stderr ?? ""}`.trim();
@@ -72,18 +116,33 @@ async function main() {
72
116
  return;
73
117
  }
74
118
 
75
- const isLinux = process.platform === "linux";
76
- const isRoot =
77
- typeof process.getuid === "function" && process.getuid() === 0;
119
+ // 优先级:用户显式 PLAYWRIGHT_DOWNLOAD_HOST > 动态推导(npm registry 镜像) > 走 playwright 默认 CDN
120
+ const userHost = process.env.PLAYWRIGHT_DOWNLOAD_HOST;
121
+ const registry = resolveNpmRegistry();
122
+ const derivedHost = resolvePlaywrightDownloadHost(registry);
123
+ const downloadHost = userHost || derivedHost;
124
+ const downloadSource = downloadHost || "playwright 默认 CDN";
78
125
 
126
+ const env = { ...process.env };
127
+ if (downloadHost) {
128
+ env.PLAYWRIGHT_DOWNLOAD_HOST = downloadHost;
129
+ }
130
+
131
+ const sourceDesc =
132
+ (userHost ? "用户设置" : derivedHost ? `镜像加速(${registry})` : "playwright 默认 CDN");
79
133
  console.log(
80
- "[aws-runtime-bridge] 正在准备 Playwright Chromium(首次安装需下载约 150MB,请耐心等待)...",
134
+ `[aws-runtime-bridge] 正在准备 Playwright Chromium(首次安装需下载约 150MB,请耐心等待)...` +
135
+ `\n[aws-runtime-bridge] 下载源:${downloadSource}(${sourceDesc};如需切换可设 PLAYWRIGHT_DOWNLOAD_HOST)`,
81
136
  );
82
137
 
138
+ const isLinux = process.platform === "linux";
139
+ const isRoot =
140
+ typeof process.getuid === "function" && process.getuid() === 0;
141
+
83
142
  // Linux + root:连系统依赖一起装(sudo npm install -g 场景一步到位)
84
143
  if (isLinux && isRoot) {
85
144
  try {
86
- await runInstall(cliPath, ["install", "--with-deps", "chromium"]);
145
+ await runInstall(cliPath, ["install", "--with-deps", "chromium"], env);
87
146
  console.log("[aws-runtime-bridge] Playwright Chromium 与系统依赖安装完成");
88
147
  return;
89
148
  } catch (error) {
@@ -98,7 +157,7 @@ async function main() {
98
157
  }
99
158
 
100
159
  try {
101
- await runInstall(cliPath, ["install", "chromium"]);
160
+ await runInstall(cliPath, ["install", "chromium"], env);
102
161
  console.log("[aws-runtime-bridge] Playwright Chromium 安装完成");
103
162
  } catch (error) {
104
163
  console.warn(