openmagic 0.41.0 → 0.41.1

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
@@ -3016,53 +3016,70 @@ async function healthCheck(proxyPort, _targetPort) {
3016
3016
  }
3017
3017
  var detectedFramework = null;
3018
3018
  async function validateAppHealth(targetHost, targetPort) {
3019
- try {
3020
- const controller = new AbortController();
3021
- const timeout = setTimeout(() => controller.abort(), 8e3);
3022
- const res = await fetch(`http://${targetHost}:${targetPort}/`, {
3023
- signal: controller.signal,
3024
- redirect: "manual",
3025
- headers: { Accept: "text/html" }
3026
- });
3027
- clearTimeout(timeout);
3028
- const status = res.status;
3029
- if (status >= 200 && status < 400) return;
3030
- if (status === 404) {
3031
- console.log(chalk.yellow(' \u26A0 Your app returned 404 for the root path ("/").'));
3032
- console.log(chalk.dim(" The dev server is running, but no page matched."));
3033
- console.log("");
3034
- if (detectedFramework === "Next.js") {
3035
- const strayLockfiles = scanParentLockfiles(process.cwd());
3036
- if (strayLockfiles.length > 0) {
3037
- console.log(chalk.yellow(" Found lockfiles in parent directories that confuse Turbopack:"));
3038
- for (const f of strayLockfiles) {
3039
- console.log(chalk.dim(` \u2022 ${f}`));
3019
+ for (let attempt = 0; attempt < 10; attempt++) {
3020
+ try {
3021
+ const controller = new AbortController();
3022
+ const timeout = setTimeout(() => controller.abort(), 3e3);
3023
+ const res = await fetch(`http://${targetHost}:${targetPort}/`, {
3024
+ signal: controller.signal,
3025
+ redirect: "manual",
3026
+ headers: { Accept: "text/html" }
3027
+ });
3028
+ clearTimeout(timeout);
3029
+ const status = res.status;
3030
+ if (status >= 200 && status < 400) return true;
3031
+ if (status === 404 && attempt < 6) {
3032
+ await new Promise((r) => setTimeout(r, 1500));
3033
+ continue;
3034
+ }
3035
+ if (status === 404) {
3036
+ console.log(chalk.yellow(' \u26A0 Your app returned 404 for the root path ("/").'));
3037
+ console.log(chalk.dim(" The dev server is running, but no page matched."));
3038
+ console.log("");
3039
+ if (detectedFramework === "Next.js") {
3040
+ const strayLockfiles = scanParentLockfiles(process.cwd());
3041
+ if (strayLockfiles.length > 0) {
3042
+ console.log(chalk.yellow(" Found lockfiles in parent directories that confuse Turbopack:"));
3043
+ for (const f of strayLockfiles) {
3044
+ console.log(chalk.dim(` \u2022 ${f}`));
3045
+ }
3046
+ console.log("");
3047
+ console.log(chalk.dim(" Fix: remove them, or add to your next.config:"));
3048
+ console.log(chalk.cyan(" turbopack: { root: __dirname }"));
3049
+ } else {
3050
+ console.log(chalk.dim(" Common Next.js causes:"));
3051
+ console.log(chalk.dim(" \u2022 Missing src/app/page.tsx (App Router) or pages/index.tsx"));
3052
+ console.log(chalk.dim(" \u2022 Middleware redirecting all routes to an auth provider"));
3040
3053
  }
3041
- console.log("");
3042
- console.log(chalk.dim(" Fix: remove them, or add to your next.config:"));
3043
- console.log(chalk.cyan(" turbopack: { root: __dirname }"));
3054
+ } else if (detectedFramework === "Angular") {
3055
+ console.log(chalk.dim(" Angular hint: ensure the base href matches the proxy path."));
3056
+ } else if (detectedFramework === "Vite") {
3057
+ console.log(chalk.dim(" Vite hint: check that index.html exists in the project root."));
3044
3058
  } else {
3045
- console.log(chalk.dim(" Common Next.js causes:"));
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"));
3059
+ console.log(chalk.dim(" Check your framework's routing configuration."));
3048
3060
  }
3049
- } else if (detectedFramework === "Angular") {
3050
- console.log(chalk.dim(" Angular hint: ensure the base href matches the proxy path."));
3051
- } else if (detectedFramework === "Vite") {
3052
- console.log(chalk.dim(" Vite hint: check that index.html exists in the project root."));
3053
- } else {
3054
- console.log(chalk.dim(" Check your framework's routing configuration."));
3061
+ console.log("");
3062
+ console.log(chalk.dim(" The toolbar is still available \u2014 navigate to a working route."));
3063
+ console.log("");
3064
+ return false;
3065
+ } else if (status >= 500) {
3066
+ console.log(chalk.yellow(` \u26A0 Your app returned HTTP ${status} on the root path.`));
3067
+ console.log(chalk.dim(" There may be a server-side error. Check your dev server output."));
3068
+ console.log("");
3069
+ if (attempt < 4) {
3070
+ await new Promise((r) => setTimeout(r, 2e3));
3071
+ continue;
3072
+ }
3073
+ return false;
3074
+ }
3075
+ } catch {
3076
+ if (attempt < 6) {
3077
+ await new Promise((r) => setTimeout(r, 1500));
3078
+ continue;
3055
3079
  }
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
3080
  }
3064
- } catch {
3065
3081
  }
3082
+ return false;
3066
3083
  }
3067
3084
  var program = new Command();
3068
3085
  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 +3242,11 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
3225
3242
  );
3226
3243
  console.log("");
3227
3244
  await healthCheck(proxyPort, targetPort);
3228
- await validateAppHealth(targetHost, targetPort);
3245
+ console.log(chalk.dim(" Waiting for app to compile..."));
3246
+ const appReady = await validateAppHealth(targetHost, targetPort);
3247
+ if (appReady) {
3248
+ console.log(chalk.green(" \u2713 App is ready."));
3249
+ }
3229
3250
  console.log(chalk.dim(" Press Ctrl+C to stop."));
3230
3251
  console.log(
3231
3252
  chalk.dim(" Errors below are from your dev server, not OpenMagic.")