galaxy-opc 0.5.20 → 0.5.22
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/cli.mjs +21 -5
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -110,14 +110,25 @@ function deepMerge(target, source) {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function runCommand(cmd, args, options = {}) {
|
|
113
|
+
const { timeout: timeoutMs, ...spawnOptions } = options;
|
|
113
114
|
return new Promise((resolve, reject) => {
|
|
114
115
|
const proc = spawn(cmd, args, {
|
|
115
116
|
stdio: "inherit",
|
|
116
117
|
shell: process.platform === "win32",
|
|
117
|
-
...
|
|
118
|
+
...spawnOptions,
|
|
118
119
|
});
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
let timer;
|
|
121
|
+
if (timeoutMs) {
|
|
122
|
+
timer = setTimeout(() => {
|
|
123
|
+
proc.kill();
|
|
124
|
+
reject(new Error(`超时(${timeoutMs / 1000}s)`));
|
|
125
|
+
}, timeoutMs);
|
|
126
|
+
}
|
|
127
|
+
proc.on("close", (code) => {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
code === 0 ? resolve() : reject(new Error(`exit ${code}`));
|
|
130
|
+
});
|
|
131
|
+
proc.on("error", (err) => { clearTimeout(timer); reject(err); });
|
|
121
132
|
});
|
|
122
133
|
}
|
|
123
134
|
|
|
@@ -165,18 +176,23 @@ async function installOpenclawWithFallback() {
|
|
|
165
176
|
{
|
|
166
177
|
label: "官方源",
|
|
167
178
|
args: ["install", "-g", "openclaw@latest"],
|
|
179
|
+
timeout: 120_000, // 120s 超时
|
|
168
180
|
},
|
|
169
181
|
{
|
|
170
182
|
label: "国内镜像(npmmirror)",
|
|
171
183
|
args: ["install", "-g", "openclaw@latest", "--registry", "https://registry.npmmirror.com"],
|
|
184
|
+
timeout: 180_000, // 镜像给 180s
|
|
172
185
|
},
|
|
173
186
|
];
|
|
174
187
|
|
|
175
188
|
let lastErr = null;
|
|
176
189
|
for (const attempt of attempts) {
|
|
177
|
-
|
|
190
|
+
// 清理上次失败/中断留下的残留目录,防止 ENOTEMPTY 报错
|
|
191
|
+
try { execSync("npm uninstall -g openclaw", { stdio: "ignore" }); } catch { /* ignore */ }
|
|
192
|
+
|
|
193
|
+
console.log(dim(` 尝试 ${attempt.label} 安装 OpenClaw...(超时 ${attempt.timeout / 1000}s 自动切换)\n`));
|
|
178
194
|
try {
|
|
179
|
-
await runCommand("npm", attempt.args, { env });
|
|
195
|
+
await runCommand("npm", attempt.args, { env, timeout: attempt.timeout });
|
|
180
196
|
return;
|
|
181
197
|
} catch (e) {
|
|
182
198
|
lastErr = e;
|