@tolinax/ayoune-cli 2026.7.0 → 2026.7.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/lib/helpers/updateNotifier.js +28 -12
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { localStorage } from "./localStorage.js";
|
|
4
4
|
const PKG_NAME = "@tolinax/ayoune-cli";
|
|
5
5
|
const CHECK_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours
|
|
6
6
|
/**
|
|
7
|
-
* Non-blocking update check.
|
|
8
|
-
*
|
|
7
|
+
* Non-blocking update check. Only uses cached data — never spawns child processes
|
|
8
|
+
* during the CLI invocation. A detached background script refreshes the cache.
|
|
9
9
|
*/
|
|
10
10
|
export function checkForUpdates(currentVersion) {
|
|
11
11
|
try {
|
|
@@ -20,16 +20,32 @@ export function checkForUpdates(currentVersion) {
|
|
|
20
20
|
const lastCheck = localStorage.getItem("updateCheckTimestamp");
|
|
21
21
|
if (lastCheck && Date.now() - parseInt(lastCheck, 10) < CHECK_INTERVAL_MS)
|
|
22
22
|
return;
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// Mark as checked immediately to prevent duplicate spawns
|
|
24
|
+
localStorage.setItem("updateCheckTimestamp", String(Date.now()));
|
|
25
|
+
// Spawn a fully detached node process that fetches the version and writes to localStorage.
|
|
26
|
+
// detached + unref + stdio:ignore ensures no file locks are held by the parent.
|
|
27
|
+
const storagePath = localStorage._location || "";
|
|
28
|
+
const script = `
|
|
29
|
+
const https = require("https");
|
|
30
|
+
const fs = require("fs");
|
|
31
|
+
const path = require("path");
|
|
32
|
+
const url = "https://registry.npmjs.org/${PKG_NAME}/latest";
|
|
33
|
+
https.get(url, { headers: { "Accept": "application/json" }, timeout: 5000 }, (res) => {
|
|
34
|
+
let data = "";
|
|
35
|
+
res.on("data", (c) => data += c);
|
|
36
|
+
res.on("end", () => {
|
|
37
|
+
try {
|
|
38
|
+
const ver = JSON.parse(data).version;
|
|
39
|
+
if (ver) fs.writeFileSync(path.join("${storagePath.replace(/\\/g, "\\\\")}", "updateCheckLatest"), ver);
|
|
40
|
+
} catch {}
|
|
32
41
|
});
|
|
42
|
+
}).on("error", () => {});
|
|
43
|
+
`;
|
|
44
|
+
const child = spawn(process.execPath, ["-e", script], {
|
|
45
|
+
detached: true,
|
|
46
|
+
stdio: "ignore",
|
|
47
|
+
});
|
|
48
|
+
child.unref();
|
|
33
49
|
}
|
|
34
50
|
catch (_a) {
|
|
35
51
|
// Silently ignore
|