openmagic 0.8.0 → 0.8.2

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/cli.js CHANGED
@@ -1514,7 +1514,7 @@ function createOpenMagicServer(proxyPort, roots) {
1514
1514
  "Content-Type": "application/json",
1515
1515
  "Access-Control-Allow-Origin": "*"
1516
1516
  });
1517
- res.end(JSON.stringify({ status: "ok", version: "0.8.0" }));
1517
+ res.end(JSON.stringify({ status: "ok", version: "0.8.2" }));
1518
1518
  return;
1519
1519
  }
1520
1520
  res.writeHead(404);
@@ -1572,7 +1572,7 @@ async function handleMessage(ws, msg, state, roots, _proxyPort) {
1572
1572
  id: msg.id,
1573
1573
  type: "handshake.ok",
1574
1574
  payload: {
1575
- version: "0.8.0",
1575
+ version: "0.8.2",
1576
1576
  roots,
1577
1577
  config: {
1578
1578
  provider: config.provider,
@@ -1795,16 +1795,6 @@ async function detectDevServer() {
1795
1795
  async function isPortOpen(port) {
1796
1796
  return checkPort(port);
1797
1797
  }
1798
- async function findAvailablePort(startPort) {
1799
- let port = startPort;
1800
- while (await isPortOpen(port)) {
1801
- port++;
1802
- if (port > startPort + 100) {
1803
- throw new Error(`Could not find an available port near ${startPort}`);
1804
- }
1805
- }
1806
- return port;
1807
- }
1808
1798
  var FRAMEWORK_PATTERNS = [
1809
1799
  { match: /\bnext\b/, framework: "Next.js", defaultPort: 3e3 },
1810
1800
  { match: /\bvite\b/, framework: "Vite", defaultPort: 5173 },
@@ -1913,7 +1903,7 @@ process.on("uncaughtException", (err) => {
1913
1903
  process.exit(1);
1914
1904
  });
1915
1905
  var childProcesses = [];
1916
- var VERSION = "0.8.0";
1906
+ var VERSION = "0.8.2";
1917
1907
  function ask(question) {
1918
1908
  const rl = createInterface({ input: process.stdin, output: process.stdout });
1919
1909
  return new Promise((resolve3) => {
@@ -2081,16 +2071,21 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
2081
2071
  saveConfig({ ...config, roots, targetPort });
2082
2072
  const token = generateSessionToken();
2083
2073
  let proxyPort = parseInt(opts.listen, 10);
2084
- if (await isPortOpen(proxyPort)) {
2085
- proxyPort = await findAvailablePort(proxyPort);
2074
+ while (await isPortOpen(proxyPort) || await isPortOpen(proxyPort + 1)) {
2075
+ proxyPort++;
2076
+ if (proxyPort > parseInt(opts.listen, 10) + 100) {
2077
+ console.log(chalk.red(" Could not find two consecutive free ports."));
2078
+ process.exit(1);
2079
+ }
2086
2080
  }
2087
- const { httpServer: omServer } = createOpenMagicServer(proxyPort, roots);
2088
- omServer.listen(proxyPort + 1, "127.0.0.1", () => {
2081
+ const companionPort = proxyPort + 1;
2082
+ const { httpServer: omServer } = createOpenMagicServer(companionPort, roots);
2083
+ omServer.listen(companionPort, "127.0.0.1", () => {
2089
2084
  });
2090
2085
  const proxyServer = createProxyServer(
2091
2086
  targetHost,
2092
2087
  targetPort,
2093
- proxyPort + 1
2088
+ companionPort
2094
2089
  );
2095
2090
  proxyServer.listen(proxyPort, "127.0.0.1", async () => {
2096
2091
  console.log("");