terminal-bridge-setup 3.3.0 → 3.3.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
@@ -42,6 +42,33 @@ const step = (n, total, msg) => console.log(`\n${c.bold(c.cyan(`[${n}/${total}]`
42
42
  const STEPS = 5;
43
43
 
44
44
  // ===================== 步骤 1:释放文件 =====================
45
+ // 升级安装前停掉旧代理实例:读 .proxy.pid 杀进程(跨平台 process.kill)。
46
+ // 不停的话旧实例一直占 8787,新代理启动即 EADDRINUSE 异常退出(Windows 实测踩过)
47
+ function stopOldProxy() {
48
+ const pidFile = join(INSTALL_DIR, "proxy", ".proxy.pid");
49
+ if (!existsSync(pidFile)) return;
50
+ let pid;
51
+ try {
52
+ pid = Number(String(readFileSync(pidFile, "utf8")).trim());
53
+ } catch { return; }
54
+ if (!Number.isInteger(pid) || pid <= 0) return;
55
+ try {
56
+ process.kill(pid, "SIGTERM");
57
+ console.log(c.yellow(` 已停止旧代理实例 (pid ${pid})`));
58
+ // 给旧进程一点退出时间,避免端口未释放
59
+ const deadline = Date.now() + 2000;
60
+ while (Date.now() < deadline) {
61
+ try { process.kill(pid, 0); Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100); }
62
+ catch { break; } // 进程已退出
63
+ }
64
+ } catch (err) {
65
+ // ESRCH=进程不存在(正常);EPERM=权限不足(尽力而为,不阻断安装)
66
+ if (err.code !== "ESRCH") {
67
+ console.log(c.yellow(` 旧代理 (pid ${pid}) 停止失败(${err.code || err.message}),如新代理启动报端口占用请手动结束 node 进程`));
68
+ }
69
+ }
70
+ }
71
+
45
72
  function releaseFiles() {
46
73
  step(1, STEPS, `释放文件到 ${c.dim(INSTALL_DIR)}`);
47
74
 
@@ -54,10 +81,12 @@ function releaseFiles() {
54
81
  if (existsSync(INSTALL_DIR)) {
55
82
  if (isForce) {
56
83
  console.log(c.yellow(" 已存在 ~/.terminal-bridge/,--force 模式:覆盖"));
84
+ stopOldProxy();
57
85
  rmSync(INSTALL_DIR, { recursive: true, force: true });
58
86
  } else {
59
87
  // 不强制覆盖时,仍然更新文件(保留 .proxy.pid/.proxy.log 等运行时产物)
60
88
  console.log(c.yellow(" ~/.terminal-bridge/ 已存在,将更新文件(运行时产物保留)"));
89
+ stopOldProxy();
61
90
  }
62
91
  }
63
92
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "JumpServer 终端桥接",
4
- "version": "3.3.0",
4
+ "version": "3.3.1",
5
5
  "description": "终端桥接:JumpServer / Arthas / Yearning,让 Agent 能通过浏览器执行命令、收结果与查数据",
6
6
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtsnqR6PcFUueZwYria79tVbstvjk+tM7PpvIXILm5xbd6bAdjDIhzg3lsnKioVfvxjfvT+s6vJsiOYa9ojVZyJMFc5m/05TYqr770ovYwQmz0e88fmiy6dUoSulbtKvBCSLbN6OOL7u+ul8ixLZ/HautxSmou/eNgAFPmhE+4UueE7wfCqcgMYvjLvEzlqTVumMW+5LKw9YsRk6WhHPghY1a3MVUn3eQOWXBtQTEUy3wBM3v4wHxLwDeinVOR4f/P87IlUNo84C5DeimoFit0qCj3K04hS8MIYCLCYZc3v9ftRJDJBkAoah6Eaqj7JajbS3KvLR1ctOYfDhubgmURQIDAQAB",
7
7
  "permissions": ["debugger", "tabs", "alarms", "webNavigation", "nativeMessaging", "scripting", "downloads", "storage"],
@@ -917,6 +917,17 @@ function finalizeOutput(entry) {
917
917
 
918
918
  // ===================== WebSocket 服务 =====================
919
919
  const wss = new WebSocketServer({ host: HOST, port: PORT });
920
+ // 绑定失败(典型:升级安装时旧代理实例还在占端口)必须给出可读原因再退出,
921
+ // 否则 Windows 上表现为"node 抛异常退出",用户无从下手
922
+ wss.on("error", (err) => {
923
+ if (err && err.code === "EADDRINUSE") {
924
+ console.error(TAG, `端口 ${PORT} 已被占用:很可能有一个旧代理实例还在运行。`);
925
+ console.error(TAG, "请先停止旧代理(插件 popup「停止代理」,或任务管理器结束对应 node 进程)后重试。");
926
+ } else {
927
+ console.error(TAG, "代理启动失败:", err && (err.stack || err.message || err));
928
+ }
929
+ process.exit(1);
930
+ });
920
931
 
921
932
  wss.on("connection", (ws, req) => {
922
933
  const url = req.url || "/ssh";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminal-bridge-setup",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "一次性安装器:释放终端桥接(JumpServer / Arthas / Yearning)的本地代理 + Chrome 插件,并注册 native messaging host。让 Agent 能通过浏览器 xterm 终端执行命令并拿回输出。",
5
5
  "license": "MIT",
6
6
  "author": "encorearon",