openmagic 0.41.0 → 0.41.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 +88 -43
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +1 -1
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2859,6 +2859,10 @@ function checkDependenciesInstalled(cwd = process.cwd()) {
|
|
|
2859
2859
|
|
|
2860
2860
|
// src/cli.ts
|
|
2861
2861
|
import { createRequire as createRequire2 } from "module";
|
|
2862
|
+
try {
|
|
2863
|
+
execSync2("ulimit -n 65536", { shell: true, stdio: "ignore" });
|
|
2864
|
+
} catch {
|
|
2865
|
+
}
|
|
2862
2866
|
var origEmitWarning = process.emitWarning;
|
|
2863
2867
|
process.emitWarning = function(warning, ...args) {
|
|
2864
2868
|
if (typeof warning === "string" && warning.includes("util._extend")) return;
|
|
@@ -2873,6 +2877,24 @@ process.on("uncaughtException", (err) => {
|
|
|
2873
2877
|
console.error(chalk.dim(" Please report this at https://github.com/Kalmuraee/OpenMagic/issues"));
|
|
2874
2878
|
process.exit(1);
|
|
2875
2879
|
});
|
|
2880
|
+
try {
|
|
2881
|
+
const fdLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: true }).trim(), 10);
|
|
2882
|
+
if (fdLimit > 0 && fdLimit < 4096) {
|
|
2883
|
+
try {
|
|
2884
|
+
execSync2("ulimit -n 65536", { shell: true, stdio: "ignore" });
|
|
2885
|
+
} catch {
|
|
2886
|
+
}
|
|
2887
|
+
const newLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: true }).trim(), 10);
|
|
2888
|
+
if (newLimit < 4096) {
|
|
2889
|
+
console.log(chalk.yellow("\n \u26A0 File descriptor limit is " + fdLimit + " (need 4096+)."));
|
|
2890
|
+
console.log(chalk.dim(" This causes EMFILE errors in large Next.js/Turbopack projects."));
|
|
2891
|
+
console.log(chalk.dim(" Fix: add this to your ~/.zshrc (or ~/.bashrc):"));
|
|
2892
|
+
console.log(chalk.cyan(" ulimit -n 65536"));
|
|
2893
|
+
console.log(chalk.dim(" Then restart your terminal.\n"));
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
} catch {
|
|
2897
|
+
}
|
|
2876
2898
|
var childProcesses = [];
|
|
2877
2899
|
var lastDetectedPort = null;
|
|
2878
2900
|
var _require2 = createRequire2(import.meta.url);
|
|
@@ -3016,53 +3038,70 @@ async function healthCheck(proxyPort, _targetPort) {
|
|
|
3016
3038
|
}
|
|
3017
3039
|
var detectedFramework = null;
|
|
3018
3040
|
async function validateAppHealth(targetHost, targetPort) {
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3041
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
3042
|
+
try {
|
|
3043
|
+
const controller = new AbortController();
|
|
3044
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
3045
|
+
const res = await fetch(`http://${targetHost}:${targetPort}/`, {
|
|
3046
|
+
signal: controller.signal,
|
|
3047
|
+
redirect: "manual",
|
|
3048
|
+
headers: { Accept: "text/html" }
|
|
3049
|
+
});
|
|
3050
|
+
clearTimeout(timeout);
|
|
3051
|
+
const status = res.status;
|
|
3052
|
+
if (status >= 200 && status < 400) return true;
|
|
3053
|
+
if (status === 404 && attempt < 6) {
|
|
3054
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
3055
|
+
continue;
|
|
3056
|
+
}
|
|
3057
|
+
if (status === 404) {
|
|
3058
|
+
console.log(chalk.yellow(' \u26A0 Your app returned 404 for the root path ("/").'));
|
|
3059
|
+
console.log(chalk.dim(" The dev server is running, but no page matched."));
|
|
3060
|
+
console.log("");
|
|
3061
|
+
if (detectedFramework === "Next.js") {
|
|
3062
|
+
const strayLockfiles = scanParentLockfiles(process.cwd());
|
|
3063
|
+
if (strayLockfiles.length > 0) {
|
|
3064
|
+
console.log(chalk.yellow(" Found lockfiles in parent directories that confuse Turbopack:"));
|
|
3065
|
+
for (const f of strayLockfiles) {
|
|
3066
|
+
console.log(chalk.dim(` \u2022 ${f}`));
|
|
3067
|
+
}
|
|
3068
|
+
console.log("");
|
|
3069
|
+
console.log(chalk.dim(" Fix: remove them, or add to your next.config:"));
|
|
3070
|
+
console.log(chalk.cyan(" turbopack: { root: __dirname }"));
|
|
3071
|
+
} else {
|
|
3072
|
+
console.log(chalk.dim(" Common Next.js causes:"));
|
|
3073
|
+
console.log(chalk.dim(" \u2022 Missing src/app/page.tsx (App Router) or pages/index.tsx"));
|
|
3074
|
+
console.log(chalk.dim(" \u2022 Middleware redirecting all routes to an auth provider"));
|
|
3040
3075
|
}
|
|
3041
|
-
|
|
3042
|
-
console.log(chalk.dim("
|
|
3043
|
-
|
|
3076
|
+
} else if (detectedFramework === "Angular") {
|
|
3077
|
+
console.log(chalk.dim(" Angular hint: ensure the base href matches the proxy path."));
|
|
3078
|
+
} else if (detectedFramework === "Vite") {
|
|
3079
|
+
console.log(chalk.dim(" Vite hint: check that index.html exists in the project root."));
|
|
3044
3080
|
} else {
|
|
3045
|
-
console.log(chalk.dim("
|
|
3046
|
-
console.log(chalk.dim(" \u2022 Missing src/app/page.tsx (App Router) or pages/index.tsx"));
|
|
3047
|
-
console.log(chalk.dim(" \u2022 Middleware redirecting all routes to an auth provider"));
|
|
3081
|
+
console.log(chalk.dim(" Check your framework's routing configuration."));
|
|
3048
3082
|
}
|
|
3049
|
-
|
|
3050
|
-
console.log(chalk.dim("
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
} else {
|
|
3054
|
-
console.log(chalk.
|
|
3083
|
+
console.log("");
|
|
3084
|
+
console.log(chalk.dim(" The toolbar is still available \u2014 navigate to a working route."));
|
|
3085
|
+
console.log("");
|
|
3086
|
+
return false;
|
|
3087
|
+
} else if (status >= 500) {
|
|
3088
|
+
console.log(chalk.yellow(` \u26A0 Your app returned HTTP ${status} on the root path.`));
|
|
3089
|
+
console.log(chalk.dim(" There may be a server-side error. Check your dev server output."));
|
|
3090
|
+
console.log("");
|
|
3091
|
+
if (attempt < 4) {
|
|
3092
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
3093
|
+
continue;
|
|
3094
|
+
}
|
|
3095
|
+
return false;
|
|
3096
|
+
}
|
|
3097
|
+
} catch {
|
|
3098
|
+
if (attempt < 6) {
|
|
3099
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
3100
|
+
continue;
|
|
3055
3101
|
}
|
|
3056
|
-
console.log("");
|
|
3057
|
-
console.log(chalk.dim(" The toolbar is still available \u2014 navigate to a working route."));
|
|
3058
|
-
console.log("");
|
|
3059
|
-
} else if (status >= 500) {
|
|
3060
|
-
console.log(chalk.yellow(` \u26A0 Your app returned HTTP ${status} on the root path.`));
|
|
3061
|
-
console.log(chalk.dim(" There may be a server-side error. Check your dev server output."));
|
|
3062
|
-
console.log("");
|
|
3063
3102
|
}
|
|
3064
|
-
} catch {
|
|
3065
3103
|
}
|
|
3104
|
+
return false;
|
|
3066
3105
|
}
|
|
3067
3106
|
var program = new Command();
|
|
3068
3107
|
program.name("openmagic").description("AI-powered coding toolbar for any web application").version(VERSION2).option("-p, --port <port>", "Dev server port to proxy", "").option(
|
|
@@ -3225,7 +3264,11 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
|
|
|
3225
3264
|
);
|
|
3226
3265
|
console.log("");
|
|
3227
3266
|
await healthCheck(proxyPort, targetPort);
|
|
3228
|
-
|
|
3267
|
+
console.log(chalk.dim(" Waiting for app to compile..."));
|
|
3268
|
+
const appReady = await validateAppHealth(targetHost, targetPort);
|
|
3269
|
+
if (appReady) {
|
|
3270
|
+
console.log(chalk.green(" \u2713 App is ready."));
|
|
3271
|
+
}
|
|
3229
3272
|
console.log(chalk.dim(" Press Ctrl+C to stop."));
|
|
3230
3273
|
console.log(
|
|
3231
3274
|
chalk.dim(" Errors below are from your dev server, not OpenMagic.")
|
|
@@ -3506,7 +3549,9 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
3506
3549
|
}
|
|
3507
3550
|
let child;
|
|
3508
3551
|
try {
|
|
3509
|
-
|
|
3552
|
+
const escapedArgs = runArgs.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
3553
|
+
const shellCmd = `ulimit -n 65536 2>/dev/null; exec ${runCmd} ${escapedArgs}`;
|
|
3554
|
+
child = spawn5("sh", ["-c", shellCmd], {
|
|
3510
3555
|
cwd: process.cwd(),
|
|
3511
3556
|
stdio: "inherit",
|
|
3512
3557
|
env: {
|