@neta-art/cohub-cli 6.2.0 → 6.2.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/dist/bootstrap.js +11 -27
- package/dist/commands/run.js +2 -1
- package/dist/self-update.d.ts +3 -0
- package/dist/self-update.js +15 -3
- package/package.json +1 -1
package/dist/bootstrap.js
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { ensureCliSelfUpdated } from "./self-update.js";
|
|
2
|
+
import { ensureCliSelfUpdated, SELF_UPDATE_WORKER_ENV, startCliSelfUpdate } from "./self-update.js";
|
|
4
3
|
const argv = process.argv.slice(2);
|
|
5
4
|
const isVersionRequest = argv.some((arg) => arg === "-v" || arg === "--version");
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
if (!isVersionRequest) {
|
|
9
|
-
shouldRelaunch = await ensureCliSelfUpdated() !== "current";
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
14
|
-
process.stderr.write(`cohub self-update failed: ${message}\n`);
|
|
15
|
-
process.stderr.write("run with --version to skip self-update\n");
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
if (shouldRelaunch) {
|
|
19
|
-
const entrypoint = process.argv[1];
|
|
20
|
-
if (!entrypoint) {
|
|
21
|
-
process.stderr.write("cohub failed to locate its updated entrypoint\n");
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
5
|
+
if (process.env[SELF_UPDATE_WORKER_ENV] === "1") {
|
|
24
6
|
try {
|
|
25
|
-
|
|
7
|
+
await ensureCliSelfUpdated();
|
|
26
8
|
}
|
|
27
|
-
catch
|
|
28
|
-
|
|
29
|
-
process.stderr.write(`cohub failed to launch the updated CLI: ${message}\n`);
|
|
30
|
-
process.exitCode = 1;
|
|
9
|
+
catch {
|
|
10
|
+
// Self-update is best effort and must never affect the foreground command.
|
|
31
11
|
}
|
|
12
|
+
process.exit(0);
|
|
32
13
|
}
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
if (!isVersionRequest) {
|
|
15
|
+
const entrypoint = process.argv[1];
|
|
16
|
+
if (entrypoint)
|
|
17
|
+
process.once("exit", () => startCliSelfUpdate(entrypoint));
|
|
35
18
|
}
|
|
19
|
+
await import("./index.js");
|
package/dist/commands/run.js
CHANGED
|
@@ -161,11 +161,12 @@ function parseRunResult(detail) {
|
|
|
161
161
|
exitCode: typeof terminationRecord.exitCode === "number" ? terminationRecord.exitCode : null,
|
|
162
162
|
...(typeof terminationRecord.timeoutSecs === "number" ? { timeoutSecs: terminationRecord.timeoutSecs } : {}),
|
|
163
163
|
...(typeof terminationRecord.message === "string" ? { message: terminationRecord.message } : {}),
|
|
164
|
+
...(typeof terminationRecord.outputTruncated === "boolean" ? { outputTruncated: terminationRecord.outputTruncated } : {}),
|
|
164
165
|
}
|
|
165
166
|
: undefined,
|
|
166
167
|
durationMs: typeof result?.durationMs === "number" ? result.durationMs : 0,
|
|
167
168
|
output: typeof result?.output === "string" ? result.output : "",
|
|
168
|
-
truncated: Boolean(result?.truncated),
|
|
169
|
+
truncated: Boolean(result?.truncated) || Boolean(result?.outputTruncated) || Boolean(terminationRecord?.outputTruncated),
|
|
169
170
|
};
|
|
170
171
|
}
|
|
171
172
|
function writeOutput(output) {
|
package/dist/self-update.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const SELF_UPDATE_WORKER_ENV = "COHUB_CLI_SELF_UPDATE_WORKER";
|
|
1
2
|
export type CliSelfUpdateResult = "current" | "updated" | "updated-by-peer";
|
|
2
3
|
export declare function resolveSelfUpdateResult(beforeVersion: string | undefined, afterVersion: string | undefined, updatedByPeer: boolean): CliSelfUpdateResult;
|
|
4
|
+
export declare const isCliSelfUpdateDue: () => boolean;
|
|
5
|
+
export declare function startCliSelfUpdate(entrypoint: string): void;
|
|
3
6
|
export declare function ensureCliSelfUpdated(): Promise<CliSelfUpdateResult>;
|
package/dist/self-update.js
CHANGED
|
@@ -3,6 +3,7 @@ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
const PACKAGE_NAME = "@neta-art/cohub-cli";
|
|
6
|
+
export const SELF_UPDATE_WORKER_ENV = "COHUB_CLI_SELF_UPDATE_WORKER";
|
|
6
7
|
const DEFAULT_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
7
8
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
8
9
|
const LOCK_STALE_MS = 5 * 60 * 1000;
|
|
@@ -55,7 +56,7 @@ export function resolveSelfUpdateResult(beforeVersion, afterVersion, updatedByPe
|
|
|
55
56
|
return "current";
|
|
56
57
|
return updatedByPeer ? "updated-by-peer" : "updated";
|
|
57
58
|
}
|
|
58
|
-
const
|
|
59
|
+
export const isCliSelfUpdateDue = () => {
|
|
59
60
|
const state = readState();
|
|
60
61
|
if (!state.lastUpdatedAt)
|
|
61
62
|
return true;
|
|
@@ -127,10 +128,21 @@ const runNpmUpdate = (timeoutMs) => {
|
|
|
127
128
|
});
|
|
128
129
|
});
|
|
129
130
|
};
|
|
131
|
+
export function startCliSelfUpdate(entrypoint) {
|
|
132
|
+
if (process.env.COHUB_CLI_AUTO_UPDATE === "0" || !isCliSelfUpdateDue())
|
|
133
|
+
return;
|
|
134
|
+
const worker = spawn(process.execPath, [entrypoint], {
|
|
135
|
+
detached: true,
|
|
136
|
+
env: { ...process.env, [SELF_UPDATE_WORKER_ENV]: "1" },
|
|
137
|
+
stdio: "ignore",
|
|
138
|
+
});
|
|
139
|
+
worker.on("error", () => undefined);
|
|
140
|
+
worker.unref();
|
|
141
|
+
}
|
|
130
142
|
export async function ensureCliSelfUpdated() {
|
|
131
143
|
if (process.env.COHUB_CLI_AUTO_UPDATE === "0")
|
|
132
144
|
return "current";
|
|
133
|
-
if (!
|
|
145
|
+
if (!isCliSelfUpdateDue())
|
|
134
146
|
return "current";
|
|
135
147
|
const beforeVersion = readInstalledVersion();
|
|
136
148
|
const timeoutMs = getTimeoutMs();
|
|
@@ -141,7 +153,7 @@ export async function ensureCliSelfUpdated() {
|
|
|
141
153
|
try {
|
|
142
154
|
// Another process may have completed the update while this process was
|
|
143
155
|
// waiting for the lock.
|
|
144
|
-
if (!
|
|
156
|
+
if (!isCliSelfUpdateDue()) {
|
|
145
157
|
return resolveSelfUpdateResult(beforeVersion, readInstalledVersion(), true);
|
|
146
158
|
}
|
|
147
159
|
await runNpmUpdate(timeoutMs);
|