terminal-bridge-setup 2.5.0 → 2.6.1

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/bin/setup.mjs CHANGED
@@ -88,14 +88,41 @@ function installProxyDeps() {
88
88
  }
89
89
 
90
90
  const proxyDir = join(INSTALL_DIR, "proxy");
91
+
92
+ // 支持 --registry 透传(国内网络/公司内网常用)
93
+ // 用法:npx terminal-bridge-setup --registry=https://registry.npmmirror.com
94
+ const registryArg = process.argv.find(a => a.startsWith("--registry="));
95
+ const npmArgs = ["install", "--no-audit", "--no-fund"];
96
+ if (registryArg) {
97
+ npmArgs.push(registryArg);
98
+ console.log(c.dim(` 使用 registry: ${registryArg.split("=")[1]}`));
99
+ } else {
100
+ npmArgs.push("--silent");
101
+ }
102
+
91
103
  console.log(c.dim(" 运行 npm install ..."));
92
- const result = spawnSync("npm", ["install", "--silent", "--no-audit", "--no-fund"], {
104
+ const result = spawnSync("npm", npmArgs, {
93
105
  cwd: proxyDir,
94
106
  stdio: "inherit",
95
107
  });
96
108
 
97
109
  if (result.status !== 0) {
98
- fail("npm install 失败,请检查网络后重试");
110
+ // 失败时给出明确的排查建议
111
+ console.error("");
112
+ console.error(c.red(" ✗ npm install 失败"));
113
+ console.error(c.yellow(" 常见原因和解决方法:"));
114
+ console.error("");
115
+ console.error(" 1. 网络不通/防火墙拦截:");
116
+ console.error(" 检查:curl -I https://registry.npmjs.org/ws");
117
+ console.error("");
118
+ console.error(" 2. 公司内网/国内网络慢:换国内镜像重试");
119
+ console.error(" 命令:npx terminal-bridge-setup --registry=https://registry.npmmirror.com");
120
+ console.error("");
121
+ console.error(" 3. 需要代理:");
122
+ console.error(" 命令:npm config set proxy http://your-proxy:port");
123
+ console.error(" 然后重跑 npx terminal-bridge-setup");
124
+ console.error("");
125
+ fail("npm install 失败(见上方排查建议)");
99
126
  }
100
127
  ok("依赖安装完成");
101
128
  }
@@ -30,9 +30,18 @@ function run(cmd, timeoutMs = 10000) {
30
30
  const reqId = randomBytes(4).toString("hex");
31
31
  let settled = false;
32
32
 
33
+ // 兜底超时定时器。关键:finish 时必须 clearTimeout——
34
+ // 否则即使结果 100ms 就到了,这个挂着的定时器会让 node 进程
35
+ // 一直活到定时器触发才退出,每次调用墙钟时间恒等于 timeoutMs+5000。
36
+ const fallbackTimer = setTimeout(
37
+ () => finish({ ok: false, error: "client timeout" }),
38
+ timeoutMs + 5000
39
+ );
40
+
33
41
  const finish = (result) => {
34
42
  if (settled) return;
35
43
  settled = true;
44
+ clearTimeout(fallbackTimer);
36
45
  try { ws.close(); } catch {}
37
46
  resolve(result);
38
47
  };
@@ -57,7 +66,6 @@ function run(cmd, timeoutMs = 10000) {
57
66
  });
58
67
 
59
68
  ws.on("error", (err) => finish({ ok: false, error: "ws error: " + err.message }));
60
- setTimeout(() => finish({ ok: false, error: "client timeout" }), timeoutMs + 5000);
61
69
  });
62
70
  }
63
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminal-bridge-setup",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "一次性安装器:释放终端桥接(JumpServer / Arthas)的本地代理 + Chrome 插件,并注册 native messaging host。让 Agent 能通过浏览器 xterm 终端执行命令并拿回输出。",
5
5
  "license": "MIT",
6
6
  "author": "encorearon",