bm2 1.0.3 → 1.0.5

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": "bm2",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A blazing-fast, full-featured process manager built entirely on Bun native APIs. The modern PM2 replacement — zero Node.js dependencies, pure Bun performance.",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
package/src/constants.ts CHANGED
@@ -16,13 +16,17 @@
16
16
 
17
17
  import { homedir } from "os";
18
18
  import { join } from "path";
19
+ import packageJson from '../package.json' assert { type: 'json' };
19
20
 
20
- export const APP_NAME = "bm2";
21
- export const VERSION = "1.0.0";
21
+
22
+ export const APP_NAME = packageJson.name;
23
+ export const VERSION = packageJson.version;
22
24
 
23
25
  export const BM2_HOME = join(homedir(), ".bm2");
24
26
  export const DAEMON_SOCKET = join(BM2_HOME, "daemon.sock");
25
27
  export const DAEMON_PID_FILE = join(BM2_HOME, "daemon.pid");
28
+ export const DAEMON_OUT_LOG_FILE = join(BM2_HOME, "daemon.out.log");
29
+ export const DAEMON_ERR_LOG_FILE = join(BM2_HOME, "daemon.err.log");
26
30
  export const LOG_DIR = join(BM2_HOME, "logs");
27
31
  export const PID_DIR = join(BM2_HOME, "pids");
28
32
  export const DUMP_FILE = join(BM2_HOME, "dump.json");
package/src/daemon.ts CHANGED
@@ -183,51 +183,33 @@ async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
183
183
  }
184
184
  }
185
185
 
186
- // Unix socket server
187
- const server = Bun.serve({
188
- unix: DAEMON_SOCKET,
189
- fetch(req, server) {
190
- if (server.upgrade(req)) return;
191
- return new Response("bm2 daemon");
192
- },
193
- websocket: {
194
- async message(ws: ServerWebSocket<unknown>, message) {
195
- try {
196
- const msg: DaemonMessage = JSON.parse(String(message));
197
- const response = await handleMessage(msg);
198
- ws.send(JSON.stringify(response));
199
- } catch (err: any) {
200
- ws.send(JSON.stringify({ type: "error", error: err.message, success: false }));
201
- }
202
- },
203
- open(ws) {},
204
- close(ws) {},
205
- },
206
- });
207
-
208
- // Signal handlers
209
- const shutdown = async () => {
210
- console.log("\n[bm2] Shutting down daemon...");
211
- await pm.stopAll();
212
- dashboard.stop();
213
- clearInterval(metricsInterval);
214
- try { unlinkSync(DAEMON_SOCKET); } catch {}
215
- try { unlinkSync(DAEMON_PID_FILE); } catch {}
216
- process.exit(0);
217
- };
218
-
219
- process.on("SIGTERM", shutdown);
220
- process.on("SIGINT", shutdown);
221
- process.on("SIGHUP", shutdown);
222
186
 
223
- // Handle uncaught errors to keep daemon alive
224
- process.on("uncaughtException", (err) => {
225
- console.error("[bm2] Uncaught exception:", err);
226
- });
187
+ const server = Bun.serve({
188
+ unix: DAEMON_SOCKET,
189
+ async fetch(req) {
190
+
191
+ if (req.method !== "POST") {
192
+ return Response.json(
193
+ { type: "error", error: "Method Not Allowed", success: false },
194
+ { status: 405 }
195
+ )
196
+ }
227
197
 
228
- process.on("unhandledRejection", (err) => {
229
- console.error("[bm2] Unhandled rejection:", err);
198
+ try {
199
+
200
+ const msg: DaemonMessage = await req.json() as DaemonMessage;
201
+
202
+ const response = await handleMessage(msg);
203
+
204
+ return Response.json(response);
205
+
206
+ } catch (err: any) {
207
+ return Response.json(
208
+ { type: "error", error: err.message, success: false },
209
+ { status: 500 }
210
+ );
211
+ }
212
+ },
230
213
  });
231
214
 
232
- console.log(`[bm2] Daemon running (PID: ${process.pid})`);
233
- console.log(`[bm2] Socket: ${DAEMON_SOCKET}`);
215
+ console.log(`Listening on ${server.url}`);