asaihost-nodejs 0.0.2 → 0.0.3

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.
@@ -1847,12 +1847,6 @@ __name(setupHttpConnectionMonitor, "setupHttpConnectionMonitor");
1847
1847
  import { execSync } from "child_process";
1848
1848
  import process2 from "process";
1849
1849
  var OWN_PID = process2.pid;
1850
- function sleepMs(ms) {
1851
- const deadline = Date.now() + ms;
1852
- while (Date.now() < deadline) {
1853
- }
1854
- }
1855
- __name(sleepMs, "sleepMs");
1856
1850
  function findListeningPids(port) {
1857
1851
  if (!Number.isInteger(port) || port < 1 || port > 65535) return [];
1858
1852
  try {
@@ -1888,32 +1882,20 @@ function findListeningPids(port) {
1888
1882
  }
1889
1883
  }
1890
1884
  __name(findListeningPids, "findListeningPids");
1891
- function killPid(pid) {
1892
- if (!pid || pid === OWN_PID || pid <= 4) return false;
1893
- try {
1894
- if (process2.platform === "win32") {
1895
- execSync(`taskkill /PID ${pid} /F`, { stdio: "ignore" });
1896
- } else {
1897
- execSync(`kill -9 ${pid}`, { stdio: "ignore" });
1898
- }
1899
- return true;
1900
- } catch {
1901
- return false;
1902
- }
1885
+ function formatOccupants(port, exclude) {
1886
+ const occupants = findListeningPids(port).filter((p) => p !== exclude && p !== OWN_PID);
1887
+ return [...new Set(occupants)].join(", ");
1903
1888
  }
1904
- __name(killPid, "killPid");
1889
+ __name(formatOccupants, "formatOccupants");
1905
1890
  function releasePort(port, opts) {
1906
1891
  const exclude = opts?.excludePid ?? OWN_PID;
1907
- const occupants = findListeningPids(port).filter((p) => p !== exclude && p !== OWN_PID);
1908
- if (!occupants.length) return true;
1892
+ const occupants = formatOccupants(port, exclude);
1893
+ if (!occupants) return true;
1909
1894
  const label = opts?.label ? `[${opts.label}] ` : "";
1910
- console.warn(`[AsaiHostNodejs] ${label}\u7AEF\u53E3 ${port} \u88AB\u5360\u7528\uFF0C\u6B63\u5728\u7ED3\u675F\u8FDB\u7A0B: ${occupants.join(", ")}`);
1911
- for (const pid of occupants) {
1912
- killPid(pid);
1913
- }
1914
- sleepMs(500);
1915
- const remaining = findListeningPids(port).filter((p) => p !== exclude && p !== OWN_PID);
1916
- return remaining.length === 0;
1895
+ console.warn(
1896
+ `[AsaiHostNodejs] ${label}\u7AEF\u53E3 ${port} \u88AB\u5360\u7528\uFF08PID: ${occupants}\uFF09\uFF0C\u8BF7\u624B\u52A8\u7ED3\u675F\u5360\u7528\u8FDB\u7A0B\u540E\u91CD\u8BD5`
1897
+ );
1898
+ return false;
1917
1899
  }
1918
1900
  __name(releasePort, "releasePort");
1919
1901
  function collectStartupPorts($asai) {
@@ -2066,7 +2048,6 @@ function startHTTPServer($asai, hostdir) {
2066
2048
  ${err.stack}` : err);
2067
2049
  }
2068
2050
  });
2069
- releasePort(hostcfg.port, { excludePid: process.pid, label: hostdir });
2070
2051
  if ($asai.hostconfig.ip === "asai" || !hostcfg.ip && !$asai.hostconfig.ip) {
2071
2052
  server.listen(hostcfg.port, () => {
2072
2053
  console.log(`[${hostdir}] Start At ${getNowTime()}.`);
@@ -2122,15 +2103,9 @@ function asaiGuard($asai, failedHostdir = "asai") {
2122
2103
  );
2123
2104
  return;
2124
2105
  }
2125
- const released = releasePort(port, { excludePid: process.pid, label: failedHostdir });
2106
+ releasePort(port, { excludePid: process.pid, label: failedHostdir });
2126
2107
  $asai.hostconfig.asaiport = conflictPorts.filter((p) => p !== port);
2127
- if (released) {
2128
- console.warn(`[AsaiHostNodejs] \u7AEF\u53E3 ${port} \u5DF2\u91CA\u653E\uFF0C\u6B63\u5728\u91CD\u65B0\u542F\u52A8 [${failedHostdir}]`);
2129
- scheduleHttpRetry($asai, failedHostdir);
2130
- return;
2131
- }
2132
- console.error(`[AsaiHostNodejs] \u7AEF\u53E3 ${port} \u65E0\u6CD5\u91CA\u653E\uFF0C\u542F\u52A8\u5931\u8D25\uFF08netstat -ano | findstr :${port}\uFF09`);
2133
- process.exit(1);
2108
+ scheduleHttpRetry($asai, failedHostdir);
2134
2109
  }
2135
2110
  __name(asaiGuard, "asaiGuard");
2136
2111
 
@@ -2231,21 +2206,17 @@ function startProxyServer($asai, proxyhostdir) {
2231
2206
  if (err.code === "EADDRINUSE") {
2232
2207
  $asai.$log("PROXY", `\x1B[41mPort ${proxycfg.proxyport} is already start!\x1B[0m`);
2233
2208
  delete $asai.serversproxy?.[proxyhostdir];
2234
- const released = releasePort(proxycfg.proxyport, {
2209
+ releasePort(proxycfg.proxyport, {
2235
2210
  excludePid: process.pid,
2236
2211
  label: proxyhostdir
2237
2212
  });
2238
- if (released) {
2239
- console.warn(`[AsaiHostNodejs] \u4EE3\u7406\u7AEF\u53E3 ${proxycfg.proxyport} \u5DF2\u91CA\u653E\uFF0C\u6B63\u5728\u91CD\u65B0\u542F\u52A8 [${proxyhostdir}]`);
2240
- setTimeout(() => startProxyServer($asai, proxyhostdir), $asai.hostconfig.tm?.d || 2e3);
2241
- }
2213
+ setTimeout(() => startProxyServer($asai, proxyhostdir), $asai.hostconfig.tm?.d || 2e3);
2242
2214
  } else {
2243
2215
  $asai.$log("PROXY", "Proxy server error:", err);
2244
2216
  }
2245
2217
  });
2246
2218
  if (!$asai.serversproxy) $asai.serversproxy = {};
2247
2219
  $asai.serversproxy[proxyhostdir] = proxyServer;
2248
- releasePort(proxycfg.proxyport, { excludePid: process.pid, label: proxyhostdir });
2249
2220
  const listenIp = getHostIP(proxycfg.proxyip, $asai);
2250
2221
  const listenCallback = /* @__PURE__ */ __name(() => {
2251
2222
  console.log(`[${proxyhostdir}] Start At ${getNowTime()}.`);
@@ -6600,7 +6571,7 @@ var initAsaiHostNodejs2 = {
6600
6571
  createTransportDataHandler,
6601
6572
  wireTransportConnectionLogs
6602
6573
  };
6603
- var PLUGIN_VERSION = true ? "0.0.2" : "0.0.1";
6574
+ var PLUGIN_VERSION = true ? "0.0.3" : "0.0.1";
6604
6575
  var index_default = initAsaiHostNodejs2;
6605
6576
  export {
6606
6577
  Index_default as AsaiCommon,