serve-sim 0.1.30 → 0.1.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serve-sim",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Evan Bacon",
@@ -60,9 +60,12 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/bun": "latest",
63
+ "@types/debug": "^4.1.13",
63
64
  "@types/react": "^19.0.0",
64
65
  "@types/react-dom": "^19.0.0",
66
+ "debug": "^4.4.3",
65
67
  "bun-plugin-tailwind": "^0.1.2",
68
+ "commander": "^14.0.1",
66
69
  "preact": "^10.29.1",
67
70
  "react": "^19.0.0",
68
71
  "react-dom": "^19.0.0",
package/src/middleware.ts CHANGED
@@ -6,6 +6,7 @@ import { createServer as createNetServer } from "net";
6
6
  import { randomBytes, timingSafeEqual } from "crypto";
7
7
  import type { IncomingMessage, ServerResponse } from "http";
8
8
  import { createAxStreamerCache } from "./ax";
9
+ import { debugMw } from "./debug";
9
10
 
10
11
  type SimReq = IncomingMessage;
11
12
  type SimRes = ServerResponse;
@@ -211,6 +212,7 @@ function readServeSimStates(): ServeSimState[] {
211
212
  try {
212
213
  process.kill(state.pid, 0);
213
214
  } catch {
215
+ debugMw("helper pid=%d gone, removing %s", state.pid, path);
214
216
  try { unlinkSync(path); } catch {}
215
217
  continue;
216
218
  }
@@ -219,6 +221,11 @@ function readServeSimStates(): ServeSimState[] {
219
221
  // preview stuck on "Connecting...". Recycle the stale state so the
220
222
  // caller can spawn a fresh helper bound to whatever is booted.
221
223
  if (booted && !booted.has(state.device)) {
224
+ debugMw(
225
+ "recycling stale helper pid=%d (device %s no longer booted)",
226
+ state.pid,
227
+ state.device,
228
+ );
222
229
  try { process.kill(state.pid, "SIGTERM"); } catch {}
223
230
  try { unlinkSync(path); } catch {}
224
231
  continue;
@@ -986,6 +993,12 @@ export function simMiddleware(options?: SimMiddlewareOptions) {
986
993
  if (url === base + "/api") {
987
994
  const states = readServeSimStates();
988
995
  const state = selectServeSimState(states, selectedDevice);
996
+ debugMw(
997
+ "GET /api selectedDevice=%s states=%d chose=%s",
998
+ selectedDevice ?? "(any)",
999
+ states.length,
1000
+ state ? `${state.device}@${state.port}` : "none",
1001
+ );
989
1002
  res.writeHead(200, {
990
1003
  "Content-Type": "application/json",
991
1004
  "Cache-Control": "no-store",