bm2 1.0.14 → 1.0.16

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.14",
3
+ "version": "1.0.16",
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/daemon.ts CHANGED
@@ -78,8 +78,8 @@ const handleServerRequests = async (req: Request) => {
78
78
  };
79
79
 
80
80
  const serverOptions = {
81
- unix: DAEMON_SOCKET,
82
- fetch: handleServerRequests
81
+ unix: DAEMON_SOCKET,
82
+ fetch: handleServerRequests
83
83
  }
84
84
 
85
85
  async function handleMessage(msg: DaemonMessage): Promise<DaemonResponse> {
package/src/index.ts CHANGED
@@ -41,7 +41,7 @@ import type {
41
41
  } from "./types";
42
42
  import Table from "cli-table3";
43
43
  import { statusColor } from "./colors";
44
- import { liveWatchProcess, printProcessTable, watchProcesses } from "./process-table";
44
+ import { liveWatchProcess, printProcessTable } from "./process-table";
45
45
 
46
46
  // ---------------------------------------------------------------------------
47
47
  // Ensure directory structure exists
@@ -84,10 +84,12 @@ async function startDaemon(): Promise<void> {
84
84
  // Detach so the daemon outlives the CLI
85
85
  child.unref();
86
86
 
87
+ console.error(colorize("Waiting for daemon..", "green"));
88
+
87
89
  // Wait for socket to appear
88
- for (let i = 0; i < 50; i++) {
90
+ for (let i = 0; i < 100; i++) {
89
91
  if (existsSync(DAEMON_SOCKET)) return;
90
- await Bun.sleep(100);
92
+ await Bun.sleep(500);
91
93
  }
92
94
 
93
95
  throw new Error("Daemon failed to start (socket not found after 5 s)");
@@ -95,35 +97,39 @@ async function startDaemon(): Promise<void> {
95
97
 
96
98
  async function sendToDaemon(msg: DaemonMessage): Promise<DaemonResponse> {
97
99
 
98
- //await startDaemon();
100
+ //start the daemon
101
+ await startDaemon();
99
102
 
100
- let res;
103
+ let res;
101
104
 
102
- try {
103
-
104
- res = await fetch("http://localhost/command", {
105
- unix: DAEMON_SOCKET,
106
- method: "POST",
107
- headers: {
108
- "Content-Type": "application/json",
109
- },
110
- body: JSON.stringify(msg),
111
- });
112
-
113
- if (!res.ok) {
114
- throw new Error(`Daemon error: ${res.status}`);
115
- }
116
-
117
- const resJson: DaemonResponse = await res.json() as DaemonResponse;
118
-
119
- return resJson;
105
+ try {
120
106
 
121
- } catch (e: any) {
122
- console.log("Results returned: " + await res?.text())
123
- console.log()
124
- console.log("sendToDaemon#Error:", e, e.stack)
125
- return { type: "error", error: "Fetch Error", success: false }
107
+ const uri = `http://localhost/command`
108
+
109
+ res = await fetch(uri, {
110
+ unix: DAEMON_SOCKET,
111
+ method: "POST",
112
+ headers: {
113
+ "Content-Type": "application/json",
114
+ },
115
+ body: JSON.stringify(msg),
116
+ });
117
+
118
+ if (!res.ok) {
119
+ throw new Error(`Daemon error: ${res.status}`);
126
120
  }
121
+
122
+ const resJson: DaemonResponse = await res.json() as DaemonResponse;
123
+
124
+ return resJson;
125
+
126
+ } catch (e: any) {
127
+ console.log("Results returned: " + await res?.text())
128
+ console.log()
129
+ console.log("sendToDaemon#Error:", e, e.stack)
130
+ return { type: "error", error: "Fetch Error", success: false }
131
+ }
132
+
127
133
  }
128
134
 
129
135