bgrun 3.12.14 → 3.12.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/dist/index.js CHANGED
@@ -1321,33 +1321,22 @@ async function cleanupPort(port) {
1321
1321
  if (process.platform !== "win32")
1322
1322
  return port;
1323
1323
  try {
1324
- const proc = Bun.spawn([
1325
- "powershell",
1326
- "-NoProfile",
1327
- "-Command",
1328
- `Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess`
1329
- ], { stdout: "pipe", stderr: "pipe" });
1330
- const text = await new Response(proc.stdout).text();
1331
- const pid = parseInt(text.trim(), 10);
1332
- if (!pid || pid === process.pid)
1324
+ const occupiedBefore = !await isPortFree(port);
1325
+ if (!occupiedBefore)
1333
1326
  return port;
1334
- const checkProc = Bun.spawn([
1335
- "powershell",
1336
- "-NoProfile",
1337
- "-Command",
1338
- `Get-Process -Id ${pid} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id`
1339
- ], { stdout: "pipe", stderr: "pipe" });
1340
- const checkText = await new Response(checkProc.stdout).text();
1341
- if (checkText.trim()) {
1342
- console.log(`[server] Killing PID ${pid} holding port ${port}`);
1343
- Bun.spawn(["taskkill", "/F", "/PID", String(pid)], { stdout: "pipe", stderr: "pipe" });
1344
- await Bun.sleep(1000);
1327
+ console.log(`[server] Reclaiming port ${port} before dashboard start`);
1328
+ await killProcessOnPort(port);
1329
+ const freed = await waitForPortFree(port, 8000);
1330
+ if (freed)
1345
1331
  return port;
1346
- } else {
1347
- const fallback = port + 1;
1348
- console.log(`[server] \u26A0 Port ${port} held by zombie PID ${pid} \u2014 falling back to port ${fallback}`);
1349
- return fallback;
1350
- }
1332
+ console.warn(`[server] Port ${port} still busy after first cleanup; retrying`);
1333
+ await killProcessOnPort(port);
1334
+ const freedAfterRetry = await waitForPortFree(port, 5000);
1335
+ if (freedAfterRetry)
1336
+ return port;
1337
+ const fallback = port + 1;
1338
+ console.warn(`[server] \u26A0 Could not reclaim port ${port}; falling back to port ${fallback}`);
1339
+ return fallback;
1351
1340
  } catch {
1352
1341
  return port;
1353
1342
  }
package/dist/server.js CHANGED
@@ -1320,33 +1320,22 @@ async function cleanupPort(port) {
1320
1320
  if (process.platform !== "win32")
1321
1321
  return port;
1322
1322
  try {
1323
- const proc = Bun.spawn([
1324
- "powershell",
1325
- "-NoProfile",
1326
- "-Command",
1327
- `Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess`
1328
- ], { stdout: "pipe", stderr: "pipe" });
1329
- const text = await new Response(proc.stdout).text();
1330
- const pid = parseInt(text.trim(), 10);
1331
- if (!pid || pid === process.pid)
1323
+ const occupiedBefore = !await isPortFree(port);
1324
+ if (!occupiedBefore)
1332
1325
  return port;
1333
- const checkProc = Bun.spawn([
1334
- "powershell",
1335
- "-NoProfile",
1336
- "-Command",
1337
- `Get-Process -Id ${pid} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id`
1338
- ], { stdout: "pipe", stderr: "pipe" });
1339
- const checkText = await new Response(checkProc.stdout).text();
1340
- if (checkText.trim()) {
1341
- console.log(`[server] Killing PID ${pid} holding port ${port}`);
1342
- Bun.spawn(["taskkill", "/F", "/PID", String(pid)], { stdout: "pipe", stderr: "pipe" });
1343
- await Bun.sleep(1000);
1326
+ console.log(`[server] Reclaiming port ${port} before dashboard start`);
1327
+ await killProcessOnPort(port);
1328
+ const freed = await waitForPortFree(port, 8000);
1329
+ if (freed)
1344
1330
  return port;
1345
- } else {
1346
- const fallback = port + 1;
1347
- console.log(`[server] \u26A0 Port ${port} held by zombie PID ${pid} \u2014 falling back to port ${fallback}`);
1348
- return fallback;
1349
- }
1331
+ console.warn(`[server] Port ${port} still busy after first cleanup; retrying`);
1332
+ await killProcessOnPort(port);
1333
+ const freedAfterRetry = await waitForPortFree(port, 5000);
1334
+ if (freedAfterRetry)
1335
+ return port;
1336
+ const fallback = port + 1;
1337
+ console.warn(`[server] \u26A0 Could not reclaim port ${port}; falling back to port ${fallback}`);
1338
+ return fallback;
1350
1339
  } catch {
1351
1340
  return port;
1352
1341
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bgrun",
3
- "version": "3.12.14",
3
+ "version": "3.12.16",
4
4
  "description": "bgrun — A lightweight process manager for Bun",
5
5
  "type": "module",
6
6
  "main": "./dist/api.js",