@evandu/super-pi 0.1.81 → 0.1.82

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/bin/super-pi.js CHANGED
@@ -3,6 +3,8 @@ import { spawn } from "node:child_process";
3
3
  import { resolve } from "node:path";
4
4
 
5
5
  const entry = resolve(import.meta.dirname, "../dist/server/index.js");
6
+ const packageRoot = resolve(import.meta.dirname, "..");
7
+ const packagePrefix = packageRoot.match(/^(.*)[\\/]node_modules[\\/]/i)?.[1];
6
8
 
7
9
  const sub = process.argv[2]?.toLowerCase();
8
10
  const port = Number(process.env.SUPER_PI_PORT ?? 3080);
@@ -61,7 +63,8 @@ if (sub === "update") {
61
63
  // the user's shell isn't tied to the upgrade.
62
64
  console.log("Updating @evandu/super-pi via npm...");
63
65
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
64
- const updater = spawn(npmCmd, ["install", "-g", "@evandu/super-pi"], {
66
+ const updateArgs = packagePrefix ? ["install", "--prefix", packagePrefix, "@evandu/super-pi"] : ["install", "-g", "@evandu/super-pi"];
67
+ const updater = spawn(npmCmd, updateArgs, {
65
68
  stdio: "inherit",
66
69
  shell: process.platform === "win32",
67
70
  env: process.env,
@@ -21,5 +21,5 @@
21
21
  "src/client/types.ts": "11fd40e5784a2e765635f4f57d6edd5c97ad0eae85b1825b9da32a88d25b4db9",
22
22
  "src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5"
23
23
  },
24
- "recordedAt": "2026-10-18T00:09:25.847Z"
24
+ "recordedAt": "2026-10-18T00:14:15.331Z"
25
25
  }
@@ -1,5 +1,6 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { join } from "node:path";
3
+ import { packageUpdateArgs } from "./update.js";
3
4
  /**
4
5
  * Routes client commands to appropriate application services and converts results or errors.
5
6
  */
@@ -259,7 +260,8 @@ export class CommandHandler {
259
260
  // /api/update endpoint uses runs detached. The user sees npm's output stream in their
260
261
  // terminal because stdio: inherit is what makes a CLI feel like a CLI.
261
262
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
262
- const updater = spawn(npmCmd, ["install", "-g", "@evandu/super-pi"], { stdio: "inherit", shell: process.platform === "win32", env: process.env });
263
+ const update = packageUpdateArgs(this.rootDir ?? import.meta.dirname);
264
+ const updater = spawn(npmCmd, update.args, { stdio: "inherit", shell: process.platform === "win32", env: process.env });
263
265
  updater.on("error", (error) => { console.error(`Super Pi: npm install failed: ${error instanceof Error ? error.message : "unknown error"}`); });
264
266
  updater.on("close", (code) => {
265
267
  if (code !== 0) {
@@ -9,6 +9,7 @@ import { findUploadFile, MAX_UPLOAD_BODY_BYTES, saveUpload } from "./upload.js";
9
9
  import { checkDiskVersion } from "./version.js";
10
10
  import { gitDiff, gitLog, gitStatus } from "./git.js";
11
11
  import { verifyCapability } from "./capability.js";
12
+ import { packageUpdateArgs } from "./update.js";
12
13
  const MIME_TYPES = {
13
14
  ".css": "text/css; charset=utf-8",
14
15
  ".html": "text/html; charset=utf-8",
@@ -427,11 +428,13 @@ export function createHttpServer(options) {
427
428
  // Use npm directly instead of `pi update` to avoid Windows detached+shell exit timing issues.
428
429
  // npm's exit code correctly reflects whether the update succeeded.
429
430
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
430
- const child = spawn(npmCmd, ["install", "-g", "@evandu/super-pi"], { stdio: "ignore", shell: process.platform === "win32", env: process.env });
431
+ const update = packageUpdateArgs(rootDir);
432
+ const child = spawn(npmCmd, update.args, { stdio: "ignore", shell: process.platform === "win32", env: process.env });
431
433
  child.on("close", (code) => {
432
434
  if (code === 0 || code === null) {
433
435
  console.log("Super Pi: npm install completed, triggering restart.");
434
436
  const restart = spawn(process.execPath, [join(rootDir, "scripts", "restart-server.mjs")], { cwd: rootDir, detached: true, stdio: "ignore", env: process.env });
437
+ restart.on("error", (restartError) => console.error(`Super Pi: restart after update failed: ${restartError instanceof Error ? restartError.message : String(restartError)}`));
435
438
  restart.unref();
436
439
  }
437
440
  else {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Return npm's install arguments for the package that is actually running.
3
+ *
4
+ * Pi can keep Super Pi in its own npm prefix, separate from the user's normal
5
+ * global npm prefix. A bare `npm install -g` therefore may update a different
6
+ * copy while this process keeps serving the old one. Installed package roots
7
+ * contain `node_modules/@evandu/super-pi`; walking back to the prefix makes the
8
+ * update target unambiguous. Source checkouts retain the global fallback.
9
+ */
10
+ export declare function packageUpdateArgs(rootDir: string): {
11
+ args: string[];
12
+ prefix?: string;
13
+ };
@@ -0,0 +1,20 @@
1
+ import { sep } from "node:path";
2
+ /**
3
+ * Return npm's install arguments for the package that is actually running.
4
+ *
5
+ * Pi can keep Super Pi in its own npm prefix, separate from the user's normal
6
+ * global npm prefix. A bare `npm install -g` therefore may update a different
7
+ * copy while this process keeps serving the old one. Installed package roots
8
+ * contain `node_modules/@evandu/super-pi`; walking back to the prefix makes the
9
+ * update target unambiguous. Source checkouts retain the global fallback.
10
+ */
11
+ export function packageUpdateArgs(rootDir) {
12
+ const marker = `${sep}node_modules${sep}`;
13
+ const lower = rootDir.toLowerCase();
14
+ const index = lower.lastIndexOf(marker);
15
+ if (index >= 0) {
16
+ const prefix = rootDir.slice(0, index);
17
+ return { prefix, args: ["install", "--prefix", prefix, "@evandu/super-pi"] };
18
+ }
19
+ return { args: ["install", "-g", "@evandu/super-pi"] };
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.81",
3
+ "version": "0.1.82",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",