@evandu/super-pi 0.1.57 → 0.1.58
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/server/http-server.js +18 -7
- package/package.json +1 -1
|
@@ -201,13 +201,19 @@ export function createHttpServer(options) {
|
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
203
|
response.writeHead(202, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ status: "updating" }));
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
// Use npm directly instead of `pi update` to avoid Windows detached+shell exit timing issues.
|
|
205
|
+
// npm's exit code correctly reflects whether the update succeeded.
|
|
206
|
+
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
207
|
+
const child = spawn(npmCmd, ["install", "-g", "@evandu/super-pi"], { stdio: "ignore", shell: process.platform === "win32", env: process.env });
|
|
206
208
|
child.on("close", (code) => {
|
|
207
|
-
if (code
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
if (code === 0 || code === null) {
|
|
210
|
+
console.log("Super Pi: npm install completed, triggering restart.");
|
|
211
|
+
const restart = spawn(process.execPath, [join(rootDir, "scripts", "restart-server.mjs")], { cwd: rootDir, detached: true, stdio: "ignore", env: process.env });
|
|
212
|
+
restart.unref();
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.error(`Super Pi: npm install failed with code ${code}`);
|
|
216
|
+
}
|
|
211
217
|
});
|
|
212
218
|
child.on("error", (error) => { console.warn(`Super Pi: update spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
|
|
213
219
|
child.unref();
|
|
@@ -220,7 +226,12 @@ export function createHttpServer(options) {
|
|
|
220
226
|
}
|
|
221
227
|
try {
|
|
222
228
|
const current = checkDiskVersion(rootDir);
|
|
223
|
-
|
|
229
|
+
// Query the npm registry for the latest @evandu/super-pi version.
|
|
230
|
+
const remoteVersion = await fetch("https://registry.npmjs.org/@evandu/super-pi/latest").then(async (result) => {
|
|
231
|
+
if (!result.ok)
|
|
232
|
+
throw new Error(`npm registry HTTP ${result.status}`);
|
|
233
|
+
return result.json();
|
|
234
|
+
});
|
|
224
235
|
const latestVersion = typeof remoteVersion.version === "string" ? remoteVersion.version : undefined;
|
|
225
236
|
response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ ...current, latestVersion, updateAvailable: Boolean(latestVersion && latestVersion !== current.diskVersion) }));
|
|
226
237
|
}
|