@proagentstore/cli 0.4.149 → 0.4.152
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 +74 -9
- package/dist/chunk-PKMXQJEJ.js +281 -0
- package/dist/index.js +519 -120
- package/package.json +1 -1
- package/dist/chunk-NNA7VZ6W.js +0 -138
package/dist/bootstrap.js
CHANGED
|
@@ -2,13 +2,21 @@
|
|
|
2
2
|
import {
|
|
3
3
|
BOOTSTRAP_ENV,
|
|
4
4
|
NO_SELF_UPDATE_ENV,
|
|
5
|
+
TRIAL_MS,
|
|
6
|
+
badVersions,
|
|
7
|
+
beginTrial,
|
|
5
8
|
cachedPayloads,
|
|
6
9
|
installPayload,
|
|
7
10
|
latestPublishedVersion,
|
|
11
|
+
logUpdateStep,
|
|
12
|
+
markBad,
|
|
8
13
|
newestPayload,
|
|
14
|
+
noteTrialStart,
|
|
9
15
|
olderThan,
|
|
10
|
-
payloadAt
|
|
11
|
-
|
|
16
|
+
payloadAt,
|
|
17
|
+
payloadRoot,
|
|
18
|
+
readTrial
|
|
19
|
+
} from "./chunk-PKMXQJEJ.js";
|
|
12
20
|
|
|
13
21
|
// src/bootstrap.ts
|
|
14
22
|
import { existsSync } from "fs";
|
|
@@ -17,20 +25,41 @@ import { fileURLToPath } from "url";
|
|
|
17
25
|
|
|
18
26
|
// src/bootstrap/stub.ts
|
|
19
27
|
import { pathToFileURL } from "url";
|
|
28
|
+
var STUB_RESTART_EXIT_CODE = 75;
|
|
29
|
+
var RESTARTED_BY = ["PAGS_UP_SUPERVISED", "PAGS_UP_LAUNCHER", "PAGS_SERVICE"];
|
|
30
|
+
function trialApplies(args) {
|
|
31
|
+
const command = args.find((a) => !a.startsWith("-"));
|
|
32
|
+
return command === "up" || command === "runner";
|
|
33
|
+
}
|
|
20
34
|
function checksForUpdate(args) {
|
|
21
35
|
return args.find((a) => !a.startsWith("-")) === "up";
|
|
22
36
|
}
|
|
23
37
|
async function runStub(deps) {
|
|
24
|
-
const log = deps.log ?? ((line) =>
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
const log = deps.log ?? ((line) => {
|
|
39
|
+
process.stderr.write(`${line}
|
|
40
|
+
`);
|
|
41
|
+
logUpdateStep(`stub: ${line}`);
|
|
42
|
+
});
|
|
43
|
+
const root = deps.root ?? payloadRoot();
|
|
44
|
+
const now = deps.now ?? Date.now;
|
|
45
|
+
const env = deps.env ?? process.env;
|
|
46
|
+
const all = () => [...deps.bundled ? [deps.bundled] : [], ...(deps.cached ?? cachedPayloads)()];
|
|
47
|
+
const local = (without = []) => {
|
|
48
|
+
const skip = /* @__PURE__ */ new Set([...Object.keys(badVersions(root)), ...without]);
|
|
49
|
+
return newestPayload(all().filter((p) => !skip.has(p.version))) ?? (without.length ? null : newestPayload(all()));
|
|
50
|
+
};
|
|
27
51
|
let chosen = local();
|
|
28
|
-
if (checksForUpdate(deps.args) && !deps.fromSource &&
|
|
52
|
+
if (checksForUpdate(deps.args) && !deps.fromSource && env[NO_SELF_UPDATE_ENV] !== "1") {
|
|
29
53
|
const latest = await (deps.latest ?? (() => latestPublishedVersion(15e3)))();
|
|
30
|
-
|
|
54
|
+
const bad = latest ? badVersions(root)[latest] : void 0;
|
|
55
|
+
if (latest && bad) {
|
|
56
|
+
log(`pags: ${latest} is published, but this machine rolled back from it (${bad}) \u2014 staying on ${chosen?.version ?? "nothing"}`);
|
|
57
|
+
} else if (latest && (!chosen || olderThan(chosen.version, latest))) {
|
|
31
58
|
log(`pags: updating ${chosen?.version ?? "(none)"} \u2192 ${latest}\u2026`);
|
|
32
59
|
try {
|
|
60
|
+
const previous = chosen?.version ?? null;
|
|
33
61
|
chosen = await (deps.install ?? ((v) => installPayload(v)))(latest);
|
|
62
|
+
beginTrial(root, chosen.version, previous, now());
|
|
34
63
|
log(`pags: now on ${chosen.version}`);
|
|
35
64
|
} catch (e) {
|
|
36
65
|
log(`pags: could not fetch ${latest} (${e instanceof Error ? e.message : String(e)}) \u2014 starting ${chosen?.version ?? "nothing"} instead`);
|
|
@@ -38,10 +67,46 @@ async function runStub(deps) {
|
|
|
38
67
|
}
|
|
39
68
|
}
|
|
40
69
|
if (!chosen) throw new Error("pags: no CLI to run \u2014 reinstall with `npm i -g @proagentstore/cli`");
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
if (trialApplies(deps.args)) {
|
|
71
|
+
const verdict = noteTrialStart(root, chosen.version, now());
|
|
72
|
+
if (verdict.kind === "give-up") {
|
|
73
|
+
const fallback = local([chosen.version]);
|
|
74
|
+
markBad(root, chosen.version, verdict.reason, fallback?.version ?? null, now());
|
|
75
|
+
log(`pags: giving up on ${chosen.version} \u2014 ${verdict.reason}; rolling back to ${fallback?.version ?? "nothing"}`);
|
|
76
|
+
if (fallback) chosen = fallback;
|
|
77
|
+
} else if (verdict.kind === "trial") {
|
|
78
|
+
watchTrial(root, chosen.version, deps, log, now, env);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (trialApplies(deps.args)) logUpdateStep(`stub: running ${chosen.version} for pags ${deps.args.find((a) => !a.startsWith("-"))}`);
|
|
82
|
+
env[BOOTSTRAP_ENV] = deps.self;
|
|
83
|
+
const load = deps.load ?? ((entry) => import(pathToFileURL(entry).href));
|
|
84
|
+
try {
|
|
85
|
+
await load(chosen.entry);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
const fallback = readTrial(root)?.version === chosen.version ? local([chosen.version]) : null;
|
|
88
|
+
if (!fallback) throw e;
|
|
89
|
+
const why = `it crashed on start: ${e instanceof Error ? e.message : String(e)}`;
|
|
90
|
+
markBad(root, chosen.version, why, fallback.version, now());
|
|
91
|
+
log(`pags: giving up on ${chosen.version} \u2014 ${why}; rolling back to ${fallback.version}`);
|
|
92
|
+
chosen = fallback;
|
|
93
|
+
await load(chosen.entry);
|
|
94
|
+
}
|
|
43
95
|
return chosen;
|
|
44
96
|
}
|
|
97
|
+
function watchTrial(root, version, deps, log, now, env) {
|
|
98
|
+
const startedAt = readTrial(root)?.startedAt ?? now();
|
|
99
|
+
const timer = (deps.setTimer ?? ((fn, ms) => setTimeout(fn, ms)))(() => {
|
|
100
|
+
const given = badVersions(root)[version];
|
|
101
|
+
if (readTrial(root)?.version !== version && !given) return;
|
|
102
|
+
const reason = `it did not register with the platform within ${TRIAL_MS / 6e4} minutes of first starting`;
|
|
103
|
+
if (!given) markBad(root, version, reason, readTrial(root)?.previous ?? null, now());
|
|
104
|
+
const supervised = RESTARTED_BY.some((k) => !!env[k]);
|
|
105
|
+
log(`pags: giving up on ${version} \u2014 ${given ?? reason}.${supervised ? " Restarting on the previous version." : ' The next "pags up" runs the previous version.'}`);
|
|
106
|
+
if (supervised) (deps.exit ?? ((code) => process.exit(code)))(STUB_RESTART_EXIT_CODE);
|
|
107
|
+
}, Math.max(0, startedAt + TRIAL_MS - now()));
|
|
108
|
+
timer.unref?.();
|
|
109
|
+
}
|
|
45
110
|
|
|
46
111
|
// src/bootstrap.ts
|
|
47
112
|
var self = fileURLToPath(import.meta.url);
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// src/bootstrap/payload.ts
|
|
2
|
+
import { execFile } from "child_process";
|
|
3
|
+
import { existsSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, readFileSync as readFileSync2, renameSync as renameSync2, rmSync as rmSync2 } from "fs";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { join as join2, win32 } from "path";
|
|
6
|
+
import { promisify } from "util";
|
|
7
|
+
|
|
8
|
+
// src/bootstrap/trial.ts
|
|
9
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
var TRIAL_MS = 5 * 6e4;
|
|
12
|
+
var MAX_TRIAL_STARTS = 6;
|
|
13
|
+
var trialPath = (root) => join(root, ".trial.json");
|
|
14
|
+
var badPath = (root) => join(root, ".bad.json");
|
|
15
|
+
var noticePath = (root) => join(root, ".rollback.json");
|
|
16
|
+
function readJson(path) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function writeJson(root, path, value) {
|
|
24
|
+
mkdirSync(root, { recursive: true });
|
|
25
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
26
|
+
writeFileSync(temp, JSON.stringify(value));
|
|
27
|
+
renameSync(temp, path);
|
|
28
|
+
}
|
|
29
|
+
function readTrial(root) {
|
|
30
|
+
const t = readJson(trialPath(root));
|
|
31
|
+
if (!t || typeof t.version !== "string" || typeof t.installedAt !== "number") return null;
|
|
32
|
+
return {
|
|
33
|
+
version: t.version,
|
|
34
|
+
previous: typeof t.previous === "string" ? t.previous : null,
|
|
35
|
+
installedAt: t.installedAt,
|
|
36
|
+
...typeof t.startedAt === "number" ? { startedAt: t.startedAt } : {},
|
|
37
|
+
starts: typeof t.starts === "number" && t.starts >= 0 ? t.starts : 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function beginTrial(root, version, previous, now = Date.now()) {
|
|
41
|
+
if (version === previous) return;
|
|
42
|
+
try {
|
|
43
|
+
writeJson(root, trialPath(root), { version, previous, installedAt: now, starts: 0 });
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function badVersions(root) {
|
|
48
|
+
const raw = readJson(badPath(root));
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const [v, why] of Object.entries(raw?.versions ?? {})) if (typeof why === "string") out[v] = why;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function markBad(root, version, reason, to, now = Date.now()) {
|
|
54
|
+
try {
|
|
55
|
+
writeJson(root, badPath(root), { versions: { ...badVersions(root), [version]: reason.slice(0, 300) } });
|
|
56
|
+
writeJson(root, noticePath(root), { from: version, to, reason: reason.slice(0, 300), at: now });
|
|
57
|
+
if (readTrial(root)?.version === version) rmSync(trialPath(root), { force: true });
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function markPayloadHealthy(root, version) {
|
|
62
|
+
const trial = readTrial(root);
|
|
63
|
+
if (trial?.version !== version) return false;
|
|
64
|
+
rmSync(trialPath(root), { force: true });
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function takeRollbackNotice(root) {
|
|
68
|
+
const n = readJson(noticePath(root));
|
|
69
|
+
rmSync(noticePath(root), { force: true });
|
|
70
|
+
if (!n || typeof n.from !== "string" || typeof n.reason !== "string") return null;
|
|
71
|
+
return { from: n.from, to: typeof n.to === "string" ? n.to : null, reason: n.reason, at: typeof n.at === "number" ? n.at : 0 };
|
|
72
|
+
}
|
|
73
|
+
function noteTrialStart(root, version, now = Date.now()) {
|
|
74
|
+
const trial = readTrial(root);
|
|
75
|
+
if (!trial || trial.version !== version) return { kind: "none" };
|
|
76
|
+
if (trial.startedAt !== void 0 && now - trial.startedAt >= TRIAL_MS) {
|
|
77
|
+
return { kind: "give-up", reason: `it did not register with the platform within ${TRIAL_MS / 6e4} minutes of first starting` };
|
|
78
|
+
}
|
|
79
|
+
if (trial.starts >= MAX_TRIAL_STARTS) {
|
|
80
|
+
return { kind: "give-up", reason: `it was started ${trial.starts} times without registering with the platform` };
|
|
81
|
+
}
|
|
82
|
+
const next = { ...trial, startedAt: trial.startedAt ?? now, starts: trial.starts + 1 };
|
|
83
|
+
try {
|
|
84
|
+
writeJson(root, trialPath(root), next);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
return { kind: "trial", trial: next };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/bootstrap/payload.ts
|
|
91
|
+
var run = promisify(execFile);
|
|
92
|
+
var CLI_PACKAGE = "@proagentstore/cli";
|
|
93
|
+
var BOOTSTRAP_ENV = "PAGS_BOOTSTRAP";
|
|
94
|
+
var NO_SELF_UPDATE_ENV = "PAGS_NO_SELF_UPDATE";
|
|
95
|
+
var KEEP = 2;
|
|
96
|
+
function payloadRoot() {
|
|
97
|
+
return process.env.PAGS_CLI_CACHE || join2(homedir(), ".config", "proagentstore", "cli");
|
|
98
|
+
}
|
|
99
|
+
function isVersion(v) {
|
|
100
|
+
return typeof v === "string" && /^(\d+)\.(\d+)\.(\d+)/.test(v.trim());
|
|
101
|
+
}
|
|
102
|
+
function olderThan(a, b) {
|
|
103
|
+
const parse = (v) => /^(\d+)\.(\d+)\.(\d+)/.exec(v.trim())?.slice(1).map(Number);
|
|
104
|
+
const x = parse(a);
|
|
105
|
+
const y = parse(b);
|
|
106
|
+
if (!x || !y) return false;
|
|
107
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i];
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
function payloadAt(dir) {
|
|
111
|
+
try {
|
|
112
|
+
const pkg = JSON.parse(readFileSync2(join2(dir, "package.json"), "utf-8"));
|
|
113
|
+
if (pkg.name !== CLI_PACKAGE || !pkg.version) return null;
|
|
114
|
+
const entry = join2(dir, pkg.pagsPayload || "dist/index.js");
|
|
115
|
+
return existsSync(entry) ? { version: pkg.version, entry } : null;
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var installedAt = (prefix) => join2(prefix, "node_modules", ...CLI_PACKAGE.split("/"));
|
|
121
|
+
var packageDir = (root, version) => installedAt(join2(root, version));
|
|
122
|
+
function cachedPayloads(root = payloadRoot()) {
|
|
123
|
+
let names;
|
|
124
|
+
try {
|
|
125
|
+
names = readdirSync(root);
|
|
126
|
+
} catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
return names.flatMap((v) => v.startsWith(".") ? [] : payloadAt(packageDir(root, v)) ?? []);
|
|
130
|
+
}
|
|
131
|
+
function newestPayload(payloads) {
|
|
132
|
+
return payloads.reduce((best, p) => !best || olderThan(best.version, p.version) ? p : best, null);
|
|
133
|
+
}
|
|
134
|
+
var CMD_META = /([()\][%!^"`<>&|;, *?])/g;
|
|
135
|
+
function quoteCmdArg(arg) {
|
|
136
|
+
const quoted = `"${arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
|
|
137
|
+
return quoted.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
|
|
138
|
+
}
|
|
139
|
+
var envVar = (env, name) => env[Object.keys(env).find((k) => k.toUpperCase() === name) ?? name];
|
|
140
|
+
function npmInvocation(args, deps = {}) {
|
|
141
|
+
if ((deps.platform ?? process.platform) !== "win32") return { file: "npm", args };
|
|
142
|
+
const env = deps.env ?? process.env;
|
|
143
|
+
const exists = deps.exists ?? existsSync;
|
|
144
|
+
const execPath = deps.execPath ?? process.execPath;
|
|
145
|
+
const cli = (dir) => win32.join(dir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
146
|
+
const onPath = (envVar(env, "PATH") ?? "").split(";").filter((dir) => dir && exists(win32.join(dir, "npm.cmd")));
|
|
147
|
+
for (const dir of [...onPath, win32.dirname(execPath)]) {
|
|
148
|
+
if (exists(cli(dir))) return { file: execPath, args: [cli(dir), ...args] };
|
|
149
|
+
}
|
|
150
|
+
const line = ["npm", ...args.map(quoteCmdArg)].join(" ");
|
|
151
|
+
return { file: envVar(env, "COMSPEC") || "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], windowsVerbatimArguments: true };
|
|
152
|
+
}
|
|
153
|
+
function runNpm(args, options) {
|
|
154
|
+
const npm = npmInvocation(args);
|
|
155
|
+
return run(npm.file, npm.args, { ...options, ...npm.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {} });
|
|
156
|
+
}
|
|
157
|
+
async function latestPublishedRelease(timeoutMs = 3e4, signal, deps = {}) {
|
|
158
|
+
try {
|
|
159
|
+
const { stdout } = await (deps.runNpm ?? runNpm)(["view", CLI_PACKAGE, "version"], { timeout: timeoutMs, signal });
|
|
160
|
+
const version = String(stdout).trim();
|
|
161
|
+
return version ? { version } : { error: "npm printed no version" };
|
|
162
|
+
} catch (e) {
|
|
163
|
+
return { error: npmFailure(e) };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function npmFailure(e) {
|
|
167
|
+
const err = e;
|
|
168
|
+
const stderr = String(err?.stderr ?? "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
169
|
+
const npmErrors = stderr.filter((l) => /npm (ERR!|error)/i.test(l));
|
|
170
|
+
const why = npmErrors.slice(0, 2).join(" ") || stderr.at(-1) || (err?.killed || err?.signal ? `npm did not answer in time (${String(err.signal ?? "killed")})` : "") || (typeof err?.code === "string" ? `npm could not be started (${err.code}: ${String(err.message ?? "")})` : "") || String(err?.message ?? e);
|
|
171
|
+
return why.replace(/\s+/g, " ").trim().slice(0, 300);
|
|
172
|
+
}
|
|
173
|
+
async function latestPublishedVersion(timeoutMs = 3e4, signal) {
|
|
174
|
+
const r = await latestPublishedRelease(timeoutMs, signal);
|
|
175
|
+
return "version" in r ? r.version : null;
|
|
176
|
+
}
|
|
177
|
+
async function npmInstallInto(dir, version) {
|
|
178
|
+
try {
|
|
179
|
+
await runNpm(["install", "--prefix", dir, "--omit=dev", "--no-audit", "--no-fund", "--no-save", `${CLI_PACKAGE}@${version}`], { timeout: 5 * 6e4 });
|
|
180
|
+
} catch (e) {
|
|
181
|
+
const stderr = String(e.stderr ?? "").trim();
|
|
182
|
+
throw new Error((stderr || (e instanceof Error ? e.message : String(e))).slice(-400));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function installPayload(version, root = payloadRoot(), install = npmInstallInto) {
|
|
186
|
+
const done = payloadAt(packageDir(root, version));
|
|
187
|
+
if (done) return done;
|
|
188
|
+
mkdirSync2(root, { recursive: true });
|
|
189
|
+
const scratch = mkdtempSync(join2(root, `.install-${version}-`));
|
|
190
|
+
try {
|
|
191
|
+
await install(scratch, version);
|
|
192
|
+
if (payloadAt(installedAt(scratch))?.version !== version) throw new Error(`npm installed no ${CLI_PACKAGE}@${version}`);
|
|
193
|
+
try {
|
|
194
|
+
renameSync2(scratch, join2(root, version));
|
|
195
|
+
} catch (e) {
|
|
196
|
+
if (!payloadAt(packageDir(root, version))) throw e;
|
|
197
|
+
}
|
|
198
|
+
} finally {
|
|
199
|
+
rmSync2(scratch, { recursive: true, force: true });
|
|
200
|
+
}
|
|
201
|
+
const payload = payloadAt(packageDir(root, version));
|
|
202
|
+
if (!payload) throw new Error(`${CLI_PACKAGE}@${version} is not usable after install`);
|
|
203
|
+
const bad = badVersions(root);
|
|
204
|
+
const others = cachedPayloads(root).filter((p) => p.version !== version).sort((a, b) => olderThan(a.version, b.version) ? 1 : -1);
|
|
205
|
+
const kept = new Set(others.filter((p) => !bad[p.version]).slice(0, KEEP - 1).map((p) => p.version));
|
|
206
|
+
for (const old of others) if (!kept.has(old.version)) rmSync2(join2(root, old.version), { recursive: true, force: true });
|
|
207
|
+
return payload;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/bootstrap/update-log.ts
|
|
211
|
+
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
212
|
+
import { homedir as homedir2 } from "os";
|
|
213
|
+
import { dirname, join as join3 } from "path";
|
|
214
|
+
var MAX_BYTES = 256 * 1024;
|
|
215
|
+
var UPDATE_LOG_UPLOAD_CHARS = 4e3;
|
|
216
|
+
function updateLogPath(env = process.env) {
|
|
217
|
+
return env.PAGS_UPDATE_LOG?.trim() || join3(env.PAGS_CONFIG_DIR?.trim() || join3(homedir2(), ".config", "proagentstore"), "update.log");
|
|
218
|
+
}
|
|
219
|
+
function logUpdateStep(step, env = process.env, now = /* @__PURE__ */ new Date()) {
|
|
220
|
+
const path = updateLogPath(env);
|
|
221
|
+
try {
|
|
222
|
+
mkdirSync3(dirname(path), { recursive: true });
|
|
223
|
+
if (existsSync2(path) && statSync(path).size > MAX_BYTES) {
|
|
224
|
+
const text = readFileSync3(path, "utf8");
|
|
225
|
+
writeFileSync2(path, text.slice(text.indexOf("\n", text.length / 2) + 1));
|
|
226
|
+
}
|
|
227
|
+
appendFileSync(path, `${now.toISOString()} [${process.pid}] ${step.replace(/\s*\n\s*/g, " | ")}
|
|
228
|
+
`);
|
|
229
|
+
} catch {
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function updateLogTail(env = process.env, maxChars = UPDATE_LOG_UPLOAD_CHARS) {
|
|
233
|
+
try {
|
|
234
|
+
const text = readFileSync3(updateLogPath(env), "utf8").trimEnd();
|
|
235
|
+
if (!text) return null;
|
|
236
|
+
if (text.length <= maxChars) return text;
|
|
237
|
+
const cut = text.slice(-maxChars);
|
|
238
|
+
return cut.slice(cut.indexOf("\n") + 1);
|
|
239
|
+
} catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function updateLogUpload(version, env = process.env) {
|
|
244
|
+
let pending = updateLogTail(env);
|
|
245
|
+
return {
|
|
246
|
+
/** The field for a status report while the upload is pending. */
|
|
247
|
+
body: () => pending ? { updateLog: pending } : {},
|
|
248
|
+
/** The platform answered a report of this start. */
|
|
249
|
+
answered: () => {
|
|
250
|
+
if (pending === null) return;
|
|
251
|
+
pending = null;
|
|
252
|
+
logUpdateStep(`registered: ${version} answered by the platform`, env);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export {
|
|
258
|
+
TRIAL_MS,
|
|
259
|
+
readTrial,
|
|
260
|
+
beginTrial,
|
|
261
|
+
badVersions,
|
|
262
|
+
markBad,
|
|
263
|
+
markPayloadHealthy,
|
|
264
|
+
takeRollbackNotice,
|
|
265
|
+
noteTrialStart,
|
|
266
|
+
CLI_PACKAGE,
|
|
267
|
+
BOOTSTRAP_ENV,
|
|
268
|
+
NO_SELF_UPDATE_ENV,
|
|
269
|
+
payloadRoot,
|
|
270
|
+
isVersion,
|
|
271
|
+
olderThan,
|
|
272
|
+
payloadAt,
|
|
273
|
+
cachedPayloads,
|
|
274
|
+
newestPayload,
|
|
275
|
+
runNpm,
|
|
276
|
+
latestPublishedRelease,
|
|
277
|
+
latestPublishedVersion,
|
|
278
|
+
installPayload,
|
|
279
|
+
logUpdateStep,
|
|
280
|
+
updateLogUpload
|
|
281
|
+
};
|