@oh-my-pi/pi-utils 6.9.0 → 7.0.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/postmortem.ts +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "6.9.0",
3
+ "version": "7.0.0",
4
4
  "description": "Shared utilities for pi packages",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/postmortem.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * allow reliably releasing resources or shutting down subprocesses, files, sockets, etc.
7
7
  */
8
8
 
9
+ import inspector from "node:inspector";
9
10
  import { isMainThread } from "node:worker_threads";
10
11
  import { logger } from ".";
11
12
 
@@ -65,12 +66,21 @@ function runCleanup(reason: Reason): Promise<void> {
65
66
  // Register signal and error event handlers to trigger cleanup before exit.
66
67
  // Main thread: full signal handling (SIGINT, SIGTERM, SIGHUP) + exceptions + exit
67
68
  // Worker thread: exit only (workers use self.addEventListener for exceptions)
69
+ let inspectorOpened = false;
70
+
68
71
  if (isMainThread) {
69
72
  process
70
73
  .on("SIGINT", async () => {
71
74
  await runCleanup(Reason.SIGINT);
72
75
  process.exit(130); // 128 + SIGINT (2)
73
76
  })
77
+ .on("SIGUSR1", () => {
78
+ if (inspectorOpened) return;
79
+ inspectorOpened = true;
80
+ inspector.open(undefined, undefined, false);
81
+ const url = inspector.url();
82
+ process.stderr.write(`Inspector opened: ${url}\n`);
83
+ })
74
84
  .on("uncaughtException", async (err) => {
75
85
  logger.error("Uncaught exception", { err, stack: err.stack });
76
86
  await runCleanup(Reason.UNCAUGHT_EXCEPTION);