@collectui/cli 0.2.7 → 0.2.8
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 +1 -1
- package/src/cli.mjs +26 -13
- package/src/login.mjs +7 -0
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -174,16 +174,29 @@ async function main() {
|
|
|
174
174
|
await command.run(flags, rest, reporter);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
process.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
/** 命令完成后 flush stdout 并退出:一次性进程不留后台尾巴(callback server 的
|
|
178
|
+
* keep-alive socket、undici 连接池等挂住 event loop 时进程会悬死不退)。 */
|
|
179
|
+
function flushAndExit(code = 0) {
|
|
180
|
+
process.stdout.write("", () => process.exit(code));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
main()
|
|
184
|
+
.then(() => {
|
|
185
|
+
flushAndExit(process.exitCode ?? 0);
|
|
186
|
+
})
|
|
187
|
+
.catch((error) => {
|
|
188
|
+
const exitCode = error instanceof CliError ? error.exitCode : 1;
|
|
189
|
+
const message = error instanceof CliError ? error.message : error?.stack || String(error);
|
|
190
|
+
const hint = error instanceof CliError ? error.hint : undefined;
|
|
191
|
+
const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
|
|
192
|
+
if (json) {
|
|
193
|
+
process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`, () =>
|
|
194
|
+
process.exit(exitCode)
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
process.stderr.write(`✖ ${message}\n`, () => {
|
|
198
|
+
if (hint) process.stderr.write(` hint: ${hint}\n`, () => process.exit(exitCode));
|
|
199
|
+
else process.exit(exitCode);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
package/src/login.mjs
CHANGED
|
@@ -189,6 +189,13 @@ export function startCallbackServer({ state } = {}) {
|
|
|
189
189
|
return listening;
|
|
190
190
|
},
|
|
191
191
|
close() {
|
|
192
|
+
// 浏览器对回调的 keep-alive 连接会挂住 event loop(server.close() 只停
|
|
193
|
+
// 接新连接、不断旧连接)——登录完成瞬间强断,否则进程悬死不退
|
|
194
|
+
try {
|
|
195
|
+
server.closeAllConnections?.();
|
|
196
|
+
} catch {
|
|
197
|
+
// Node <18.2 无此方法
|
|
198
|
+
}
|
|
192
199
|
try {
|
|
193
200
|
server.close();
|
|
194
201
|
} catch {
|