@4pm/cli 1.12.0 → 1.12.1-b
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/index.js +36 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32543,16 +32543,48 @@ function readInstalledVersion() {
|
|
|
32543
32543
|
return "0.0.0";
|
|
32544
32544
|
}
|
|
32545
32545
|
}
|
|
32546
|
+
var NPM_INSTALL_TIMEOUT_MS = 18e4;
|
|
32547
|
+
var DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
32548
|
+
function tailReason(raw) {
|
|
32549
|
+
const s3 = raw.trim();
|
|
32550
|
+
return s3.length > 800 ? `\u2026${s3.slice(-800)}` : s3;
|
|
32551
|
+
}
|
|
32546
32552
|
function updateViaNpm(version) {
|
|
32547
32553
|
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version)) {
|
|
32548
32554
|
throw new Error(`Refusing to update: invalid version string "${version}".`);
|
|
32549
32555
|
}
|
|
32550
|
-
|
|
32556
|
+
try {
|
|
32557
|
+
execSync2(`npm i -g @4pm/cli@${version}`, {
|
|
32558
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
32559
|
+
encoding: "utf8",
|
|
32560
|
+
timeout: NPM_INSTALL_TIMEOUT_MS
|
|
32561
|
+
});
|
|
32562
|
+
} catch (err) {
|
|
32563
|
+
const e = err;
|
|
32564
|
+
if (e.killed) {
|
|
32565
|
+
throw new Error(`npm install timed out after ${NPM_INSTALL_TIMEOUT_MS / 1e3}s (\`npm i -g @4pm/cli@${version}\`).`);
|
|
32566
|
+
}
|
|
32567
|
+
const out = `${e.stderr?.toString() ?? ""}
|
|
32568
|
+
${e.stdout?.toString() ?? ""}`;
|
|
32569
|
+
const reason = tailReason(out) || e.message || "npm install failed";
|
|
32570
|
+
throw new Error(`npm install failed: ${reason}`);
|
|
32571
|
+
}
|
|
32551
32572
|
}
|
|
32552
32573
|
async function updateViaDownload(tarballUrl, checksum, signature) {
|
|
32553
|
-
const
|
|
32554
|
-
|
|
32555
|
-
|
|
32574
|
+
const controller = new AbortController();
|
|
32575
|
+
const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS);
|
|
32576
|
+
let buf;
|
|
32577
|
+
try {
|
|
32578
|
+
const res = await fetch(tarballUrl, { signal: controller.signal });
|
|
32579
|
+
if (!res.ok) throw new Error(`Failed to download tarball: HTTP ${res.status}`);
|
|
32580
|
+
buf = Buffer.from(await res.arrayBuffer());
|
|
32581
|
+
} catch (err) {
|
|
32582
|
+
throw new Error(
|
|
32583
|
+
controller.signal.aborted ? `Downloading the update tarball timed out after ${DOWNLOAD_TIMEOUT_MS / 1e3}s.` : `Failed to download tarball: ${String(err)}`
|
|
32584
|
+
);
|
|
32585
|
+
} finally {
|
|
32586
|
+
clearTimeout(timer);
|
|
32587
|
+
}
|
|
32556
32588
|
const actual = createHash2("sha256").update(buf).digest("hex");
|
|
32557
32589
|
if (actual !== checksum) {
|
|
32558
32590
|
throw new Error("Tarball checksum mismatch \u2014 aborting update (ADR-0015).");
|