bm2 1.0.3 → 1.0.4

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.4",
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
@@ -23,6 +23,8 @@ export const VERSION = "1.0.0";
23
23
  export const BM2_HOME = join(homedir(), ".bm2");
24
24
  export const DAEMON_SOCKET = join(BM2_HOME, "daemon.sock");
25
25
  export const DAEMON_PID_FILE = join(BM2_HOME, "daemon.pid");
26
+ export const DAEMON_OUT_LOG_FILE = join(BM2_HOME, "daemon.out.log");
27
+ export const DAEMON_ERR_LOG_FILE = join(BM2_HOME, "daemon.err.log");
26
28
  export const LOG_DIR = join(BM2_HOME, "logs");
27
29
  export const PID_DIR = join(BM2_HOME, "pids");
28
30
  export const DUMP_FILE = join(BM2_HOME, "dump.json");
package/src/daemon.ts CHANGED
@@ -51,6 +51,7 @@ const metricsInterval = setInterval(() => {
51
51
  }, 2000);
52
52
 
53
53
  async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
54
+ console.log("msg.type===>", msg)
54
55
  try {
55
56
  switch (msg.type) {
56
57
  case "start": {
@@ -183,51 +184,33 @@ async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
183
184
  }
184
185
  }
185
186
 
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
187
 
223
- // Handle uncaught errors to keep daemon alive
224
- process.on("uncaughtException", (err) => {
225
- console.error("[bm2] Uncaught exception:", err);
226
- });
188
+ const server = Bun.serve({
189
+ unix: DAEMON_SOCKET,
190
+ async fetch(req) {
191
+
192
+ if (req.method !== "POST") {
193
+ return Response.json(
194
+ { type: "error", error: "Method Not Allowed", success: false },
195
+ { status: 405 }
196
+ )
197
+ }
227
198
 
228
- process.on("unhandledRejection", (err) => {
229
- console.error("[bm2] Unhandled rejection:", err);
199
+ try {
200
+
201
+ const msg: DaemonMessage = await req.json() as DaemonMessage;
202
+
203
+ const response = await handleMessage(msg);
204
+
205
+ return Response.json(response);
206
+
207
+ } catch (err: any) {
208
+ return Response.json(
209
+ { type: "error", error: err.message, success: false },
210
+ { status: 500 }
211
+ );
212
+ }
213
+ },
230
214
  });
231
215
 
232
- console.log(`[bm2] Daemon running (PID: ${process.pid})`);
233
- console.log(`[bm2] Socket: ${DAEMON_SOCKET}`);
216
+ console.log(`Listening on ${server.url}`);