openmagic 0.31.8 → 0.32.0
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 +38 -109
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +8 -8
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1885,7 +1885,8 @@ var COMMON_DEV_PORTS = [
|
|
|
1885
1885
|
];
|
|
1886
1886
|
function checkPortSingle(port, host) {
|
|
1887
1887
|
return new Promise((resolve4) => {
|
|
1888
|
-
const socket = createConnection({ port, host, timeout:
|
|
1888
|
+
const socket = createConnection({ port, host, timeout: 1e3 });
|
|
1889
|
+
socket.unref();
|
|
1889
1890
|
socket.on("connect", () => {
|
|
1890
1891
|
socket.destroy();
|
|
1891
1892
|
resolve4(true);
|
|
@@ -2097,7 +2098,7 @@ function ask(question) {
|
|
|
2097
2098
|
});
|
|
2098
2099
|
});
|
|
2099
2100
|
}
|
|
2100
|
-
function waitForPort(port, timeoutMs =
|
|
2101
|
+
function waitForPort(port, timeoutMs = 6e4, shouldAbort) {
|
|
2101
2102
|
const start = Date.now();
|
|
2102
2103
|
return new Promise((resolve4) => {
|
|
2103
2104
|
const check = async () => {
|
|
@@ -2109,11 +2110,13 @@ function waitForPort(port, timeoutMs = 3e4, shouldAbort) {
|
|
|
2109
2110
|
resolve4(true);
|
|
2110
2111
|
return;
|
|
2111
2112
|
}
|
|
2112
|
-
|
|
2113
|
+
const elapsed = Date.now() - start;
|
|
2114
|
+
if (elapsed > timeoutMs) {
|
|
2113
2115
|
resolve4(false);
|
|
2114
2116
|
return;
|
|
2115
2117
|
}
|
|
2116
|
-
|
|
2118
|
+
const interval = elapsed < 1e4 ? 300 : 1e3;
|
|
2119
|
+
setTimeout(check, interval);
|
|
2117
2120
|
};
|
|
2118
2121
|
check();
|
|
2119
2122
|
});
|
|
@@ -2170,23 +2173,6 @@ async function healthCheck(proxyPort, _targetPort) {
|
|
|
2170
2173
|
}
|
|
2171
2174
|
console.log("");
|
|
2172
2175
|
}
|
|
2173
|
-
function formatDevServerLine(line) {
|
|
2174
|
-
const trimmed = line.trim();
|
|
2175
|
-
if (!trimmed) return "";
|
|
2176
|
-
if (trimmed.startsWith("Error:") || trimmed.includes("ModuleNotFoundError") || trimmed.includes("Can't resolve")) {
|
|
2177
|
-
return chalk.red(` \u2502 ${trimmed}`);
|
|
2178
|
-
}
|
|
2179
|
-
if (trimmed.includes("EADDRINUSE") || trimmed.includes("address already in use")) {
|
|
2180
|
-
return chalk.red(` \u2502 ${trimmed}`) + "\n" + chalk.yellow(" \u2502 \u2192 Port is already in use. Stop the other process or use --port <different-port>");
|
|
2181
|
-
}
|
|
2182
|
-
if (trimmed.includes("EACCES") || trimmed.includes("permission denied")) {
|
|
2183
|
-
return chalk.red(` \u2502 ${trimmed}`) + "\n" + chalk.yellow(" \u2502 \u2192 Permission denied. Try a different port or check file permissions.");
|
|
2184
|
-
}
|
|
2185
|
-
if (trimmed.includes("Cannot find module") || trimmed.includes("MODULE_NOT_FOUND")) {
|
|
2186
|
-
return chalk.red(` \u2502 ${trimmed}`) + "\n" + chalk.yellow(" \u2502 \u2192 Missing dependency. Try running npm install.");
|
|
2187
|
-
}
|
|
2188
|
-
return chalk.dim(` \u2502 ${trimmed}`);
|
|
2189
|
-
}
|
|
2190
2176
|
var program = new Command();
|
|
2191
2177
|
program.name("openmagic").description("AI-powered coding toolbar for any web application").version(VERSION2).option("-p, --port <port>", "Dev server port to proxy", "").option(
|
|
2192
2178
|
"-l, --listen <port>",
|
|
@@ -2490,9 +2476,7 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2490
2476
|
try {
|
|
2491
2477
|
child = spawn(runCmd, runArgs, {
|
|
2492
2478
|
cwd: process.cwd(),
|
|
2493
|
-
stdio:
|
|
2494
|
-
detached: false,
|
|
2495
|
-
shell: true,
|
|
2479
|
+
stdio: "inherit",
|
|
2496
2480
|
env: {
|
|
2497
2481
|
...process.env,
|
|
2498
2482
|
PORT: String(port),
|
|
@@ -2506,53 +2490,16 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2506
2490
|
}
|
|
2507
2491
|
childProcesses.push(child);
|
|
2508
2492
|
let childExited = false;
|
|
2509
|
-
let detectedPort = null;
|
|
2510
|
-
function parsePortFromOutput(line) {
|
|
2511
|
-
const clean = line.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "").replace(/\x1b[^a-zA-Z]*[a-zA-Z]/g, "").replace(/[\x00-\x1f\x7f]/g, "");
|
|
2512
|
-
const portMatch = clean.match(/https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\]):(\d+)/);
|
|
2513
|
-
if (portMatch && !detectedPort) {
|
|
2514
|
-
const p = parseInt(portMatch[1], 10);
|
|
2515
|
-
if (p > 0 && p < 65536) {
|
|
2516
|
-
if (p === port) {
|
|
2517
|
-
detectedPort = p;
|
|
2518
|
-
return;
|
|
2519
|
-
}
|
|
2520
|
-
detectedPort = p;
|
|
2521
|
-
return;
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
if (!detectedPort) {
|
|
2525
|
-
const fallback = clean.match(/(?:port|Port|PORT)\s+(\d{4,5})/);
|
|
2526
|
-
if (fallback) {
|
|
2527
|
-
const p = parseInt(fallback[1], 10);
|
|
2528
|
-
if (p > 0 && p < 65536 && p !== port) {
|
|
2529
|
-
detectedPort = p;
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
child.stdout?.on("data", (data) => {
|
|
2535
|
-
for (const line of data.toString().trim().split("\n")) {
|
|
2536
|
-
parsePortFromOutput(line);
|
|
2537
|
-
const formatted = formatDevServerLine(line);
|
|
2538
|
-
if (formatted) process.stdout.write(formatted + "\n");
|
|
2539
|
-
}
|
|
2540
|
-
});
|
|
2541
|
-
child.stderr?.on("data", (data) => {
|
|
2542
|
-
for (const line of data.toString().trim().split("\n")) {
|
|
2543
|
-
parsePortFromOutput(line);
|
|
2544
|
-
const formatted = formatDevServerLine(line);
|
|
2545
|
-
if (formatted) process.stdout.write(formatted + "\n");
|
|
2546
|
-
}
|
|
2547
|
-
});
|
|
2548
2493
|
child.on("error", (err) => {
|
|
2549
2494
|
childExited = true;
|
|
2550
|
-
console.log(chalk.red(`
|
|
2495
|
+
console.log(chalk.red(`
|
|
2496
|
+
\u2717 Failed to start: ${err.message}`));
|
|
2551
2497
|
});
|
|
2552
2498
|
child.on("exit", (code) => {
|
|
2553
2499
|
childExited = true;
|
|
2554
2500
|
if (code !== null && code !== 0) {
|
|
2555
|
-
console.log(chalk.red(`
|
|
2501
|
+
console.log(chalk.red(`
|
|
2502
|
+
\u2717 Dev server exited with code ${code}`));
|
|
2556
2503
|
}
|
|
2557
2504
|
});
|
|
2558
2505
|
const cleanup = () => {
|
|
@@ -2575,26 +2522,30 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2575
2522
|
process.on("SIGINT", cleanup);
|
|
2576
2523
|
process.on("SIGTERM", cleanup);
|
|
2577
2524
|
console.log(
|
|
2578
|
-
chalk.dim(` Waiting for dev server...`)
|
|
2525
|
+
chalk.dim(` Waiting for dev server on port ${port}...`)
|
|
2579
2526
|
);
|
|
2580
|
-
const isUp = await waitForPort(port, 6e4, () =>
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2527
|
+
const isUp = await waitForPort(port, 6e4, () => childExited);
|
|
2528
|
+
if (isUp) {
|
|
2529
|
+
lastDetectedPort = port;
|
|
2530
|
+
console.log("");
|
|
2531
|
+
return true;
|
|
2532
|
+
}
|
|
2533
|
+
if (!childExited) {
|
|
2534
|
+
const scanPorts = [port, 3e3, 3001, 3002, 5173, 5174, 4200, 8080, 8e3, 4e3, 1234, 4321, 3333, 8081].filter((p, i, a) => a.indexOf(p) === i);
|
|
2535
|
+
for (const scanPort of scanPorts) {
|
|
2536
|
+
if (await isPortOpen(scanPort)) {
|
|
2537
|
+
const owned = verifyPortOwnership(scanPort, process.cwd());
|
|
2538
|
+
if (owned === false) continue;
|
|
2589
2539
|
console.log(
|
|
2590
|
-
chalk.green(`
|
|
2540
|
+
chalk.green(`
|
|
2541
|
+
\u2713 Dev server found on port ${scanPort}.`)
|
|
2591
2542
|
);
|
|
2543
|
+
lastDetectedPort = scanPort;
|
|
2544
|
+
return true;
|
|
2592
2545
|
}
|
|
2593
|
-
lastDetectedPort = detectedPort;
|
|
2594
|
-
return true;
|
|
2595
2546
|
}
|
|
2596
2547
|
}
|
|
2597
|
-
if (childExited
|
|
2548
|
+
if (childExited) {
|
|
2598
2549
|
console.log(
|
|
2599
2550
|
chalk.red(` \u2717 Dev server failed to start.`)
|
|
2600
2551
|
);
|
|
@@ -2618,37 +2569,15 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2618
2569
|
console.log("");
|
|
2619
2570
|
return false;
|
|
2620
2571
|
}
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
chalk.green(` \u2713 Dev server found on port ${scanPort}.`)
|
|
2629
|
-
);
|
|
2630
|
-
lastDetectedPort = scanPort;
|
|
2631
|
-
return true;
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
console.log(
|
|
2635
|
-
chalk.yellow(` \u26A0 Port ${port} didn't open after 60s.`)
|
|
2636
|
-
);
|
|
2637
|
-
console.log(
|
|
2638
|
-
chalk.dim(` The server might use a different port. Check the output above.`)
|
|
2639
|
-
);
|
|
2640
|
-
console.log("");
|
|
2641
|
-
const detected = await detectDevServer();
|
|
2642
|
-
if (detected) {
|
|
2643
|
-
console.log(
|
|
2644
|
-
chalk.green(` \u2713 Found server on port ${detected.port} instead.`)
|
|
2645
|
-
);
|
|
2646
|
-
return true;
|
|
2647
|
-
}
|
|
2648
|
-
return false;
|
|
2649
|
-
}
|
|
2572
|
+
console.log(
|
|
2573
|
+
chalk.yellow(`
|
|
2574
|
+
\u26A0 Could not find the dev server after 60s.`)
|
|
2575
|
+
);
|
|
2576
|
+
console.log(chalk.dim(` Check the output above for errors.`));
|
|
2577
|
+
console.log(chalk.dim(` Or start the server manually, then run:`));
|
|
2578
|
+
console.log(chalk.cyan(` npx openmagic --port <your-port>`));
|
|
2650
2579
|
console.log("");
|
|
2651
|
-
return
|
|
2580
|
+
return false;
|
|
2652
2581
|
}
|
|
2653
2582
|
program.parse();
|
|
2654
2583
|
//# sourceMappingURL=cli.js.map
|