terminal-bridge-setup 3.3.1 → 3.3.3
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 +32 -14
- package/files/extension/manifest.json +1 -1
- package/files/proxy/server.js +12 -1
- package/package.json +1 -1
package/bin/setup.mjs
CHANGED
|
@@ -107,34 +107,46 @@ function releaseFiles() {
|
|
|
107
107
|
|
|
108
108
|
// ===================== 步骤 2:装代理依赖 =====================
|
|
109
109
|
function installProxyDeps() {
|
|
110
|
-
step(2, STEPS, "安装代理依赖 (ws)");
|
|
110
|
+
step(2, STEPS, "安装代理依赖 (ws + @msgpack/msgpack)");
|
|
111
111
|
|
|
112
|
-
//
|
|
112
|
+
// 跳过条件:两个依赖都存在才跳过。只查 ws 会漏掉 @msgpack/msgpack——
|
|
113
|
+
// 旧版本装的 node_modules 只有 ws,升级后代理启动即 ERR_MODULE_NOT_FOUND
|
|
113
114
|
const wsPath = join(INSTALL_DIR, "proxy", "node_modules", "ws");
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const msgpackPath = join(INSTALL_DIR, "proxy", "node_modules", "@msgpack", "msgpack");
|
|
116
|
+
if (existsSync(wsPath) && existsSync(msgpackPath)) {
|
|
117
|
+
ok("依赖已存在(ws + @msgpack/msgpack),跳过");
|
|
116
118
|
return;
|
|
117
119
|
}
|
|
120
|
+
if (existsSync(wsPath) && !existsSync(msgpackPath)) {
|
|
121
|
+
console.log(c.yellow(" 检测到 ws 存在但 @msgpack/msgpack 缺失(旧版本残留),补装"));
|
|
122
|
+
}
|
|
118
123
|
|
|
119
124
|
const proxyDir = join(INSTALL_DIR, "proxy");
|
|
120
125
|
|
|
121
126
|
// 支持 --registry 透传(国内网络/公司内网常用)
|
|
122
127
|
// 用法:npx terminal-bridge-setup --registry=https://registry.npmmirror.com
|
|
123
128
|
const registryArg = process.argv.find(a => a.startsWith("--registry="));
|
|
124
|
-
const
|
|
129
|
+
const baseArgs = ["install", "--no-audit", "--no-fund"];
|
|
130
|
+
const runNpm = (args) => {
|
|
131
|
+
console.log(c.dim(` 运行 npm ${args.join(" ")} ...`));
|
|
132
|
+
return spawnSync("npm", args, { cwd: proxyDir, stdio: "inherit" });
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
let result;
|
|
125
136
|
if (registryArg) {
|
|
126
|
-
npmArgs.push(registryArg);
|
|
127
137
|
console.log(c.dim(` 使用 registry: ${registryArg.split("=")[1]}`));
|
|
138
|
+
result = runNpm([...baseArgs, registryArg]);
|
|
128
139
|
} else {
|
|
129
|
-
|
|
140
|
+
// 不加 --silent:私有源缺包/认证失败等真实错误必须可见,不能吞掉
|
|
141
|
+
result = runNpm(baseArgs);
|
|
142
|
+
if (result.status !== 0) {
|
|
143
|
+
// 内网镜像未同步/缺包是高频原因(verdaccio 同步延迟实测踩过),
|
|
144
|
+
// 自动用官方源兜底重试一次再判失败
|
|
145
|
+
console.log(c.yellow(" 默认 registry 安装失败,用官方源 npmjs.org 重试..."));
|
|
146
|
+
result = runNpm([...baseArgs, "--registry=https://registry.npmjs.org"]);
|
|
147
|
+
}
|
|
130
148
|
}
|
|
131
149
|
|
|
132
|
-
console.log(c.dim(" 运行 npm install ..."));
|
|
133
|
-
const result = spawnSync("npm", npmArgs, {
|
|
134
|
-
cwd: proxyDir,
|
|
135
|
-
stdio: "inherit",
|
|
136
|
-
});
|
|
137
|
-
|
|
138
150
|
if (result.status !== 0) {
|
|
139
151
|
// 失败时给出明确的排查建议
|
|
140
152
|
console.error("");
|
|
@@ -153,7 +165,13 @@ function installProxyDeps() {
|
|
|
153
165
|
console.error("");
|
|
154
166
|
fail("npm install 失败(见上方排查建议)");
|
|
155
167
|
}
|
|
156
|
-
|
|
168
|
+
// 装完验证两个依赖真实落盘(防 npm 静默半装/registry 缺包)
|
|
169
|
+
if (!existsSync(wsPath) || !existsSync(msgpackPath)) {
|
|
170
|
+
console.error(c.red(" ✗ 依赖验证失败:ws 或 @msgpack/msgpack 未落盘"));
|
|
171
|
+
console.error(c.yellow(` 手动修复:cd "${join(INSTALL_DIR, "proxy")}" && npm install`));
|
|
172
|
+
fail("依赖安装不完整");
|
|
173
|
+
}
|
|
174
|
+
ok("依赖安装完成(已验证 ws + @msgpack/msgpack)");
|
|
157
175
|
}
|
|
158
176
|
|
|
159
177
|
// ===================== 步骤 3:注册 native host =====================
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "JumpServer 终端桥接",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.3",
|
|
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"],
|
package/files/proxy/server.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
import { WebSocketServer } from "ws";
|
|
15
15
|
import { randomBytes } from "node:crypto";
|
|
16
|
-
import { decode as msgpackDecode } from "@msgpack/msgpack";
|
|
17
16
|
import { writeFileSync, unlinkSync } from "node:fs";
|
|
18
17
|
import { fileURLToPath } from "node:url";
|
|
19
18
|
|
|
@@ -34,6 +33,17 @@ const PROBE_LOG = process.env.PROBE_LOG !== "0"; // 默认开探针日志
|
|
|
34
33
|
|
|
35
34
|
const TAG = "[proxy]";
|
|
36
35
|
|
|
36
|
+
// msgpack 只有 Yearning 结果解析用到,终端桥接(JumpServer/Arthas)不需要。
|
|
37
|
+
// 按需动态加载:缺依赖时降级为告警 + Yearning 功能不可用,而不是整个代理
|
|
38
|
+
// 启动崩溃(Windows 用户 npm install 缺包时曾把终端功能一起拖死,实测踩过)。
|
|
39
|
+
let msgpackDecode = null;
|
|
40
|
+
try {
|
|
41
|
+
({ decode: msgpackDecode } = await import("@msgpack/msgpack"));
|
|
42
|
+
} catch {
|
|
43
|
+
console.warn(TAG, "⚠ @msgpack/msgpack 未安装:Yearning 查询结果解析不可用(终端命令不受影响)");
|
|
44
|
+
console.warn(TAG, "⚠ 修复:cd ~/.terminal-bridge/proxy && npm install");
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
// ===================== 客户端管理 =====================
|
|
38
48
|
// 一个端点两类客户端:插件(唯一)和 Agent(多个)。
|
|
39
49
|
// 我们不严格区分谁连进来,靠消息 type 路由。
|
|
@@ -151,6 +161,7 @@ function feedYearningWaiters(payload) {
|
|
|
151
161
|
const opcode = payload && payload.opcode;
|
|
152
162
|
const data = payload && payload.data;
|
|
153
163
|
if (opcode !== 2 || typeof data !== "string") return;
|
|
164
|
+
if (!msgpackDecode) return; // msgpack 缺失时 Yearning 解析不可用(启动时已告警)
|
|
154
165
|
let obj = null;
|
|
155
166
|
try {
|
|
156
167
|
obj = msgpackDecode(Buffer.from(data, "base64"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "terminal-bridge-setup",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "一次性安装器:释放终端桥接(JumpServer / Arthas / Yearning)的本地代理 + Chrome 插件,并注册 native messaging host。让 Agent 能通过浏览器 xterm 终端执行命令并拿回输出。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "encorearon",
|