openmagic 0.42.0 → 0.43.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
@@ -2,13 +2,15 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { Command } from "commander";
5
- import chalk from "chalk";
5
+ import pc from "picocolors";
6
6
  import open from "open";
7
7
  import { resolve as resolve3, join as join6 } from "path";
8
8
  import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
9
9
  import { spawn as spawn5, execSync as execSync2 } from "child_process";
10
10
  import http2 from "http";
11
11
  import { createInterface, clearLine, cursorTo } from "readline";
12
+ import { createSpinner } from "nanospinner";
13
+ import terminalLink from "terminal-link";
12
14
 
13
15
  // src/proxy.ts
14
16
  import http from "http";
@@ -2860,7 +2862,7 @@ function checkDependenciesInstalled(cwd = process.cwd()) {
2860
2862
  // src/cli.ts
2861
2863
  import { createRequire as createRequire2 } from "module";
2862
2864
  try {
2863
- execSync2("ulimit -n 65536", { shell: true, stdio: "ignore" });
2865
+ execSync2("ulimit -n 65536", { shell: "/bin/sh", stdio: "ignore" });
2864
2866
  } catch {
2865
2867
  }
2866
2868
  var origEmitWarning = process.emitWarning;
@@ -2883,22 +2885,22 @@ function writeLine(line = "") {
2883
2885
  ` : "\n");
2884
2886
  }
2885
2887
  function formatInfo(message) {
2886
- return chalk.dim(`${INDENT}${message}`);
2888
+ return pc.dim(`${INDENT}${message}`);
2887
2889
  }
2888
2890
  function formatPending(message) {
2889
- return chalk.dim(`${INDENT}\u25CF ${message}`);
2891
+ return pc.dim(`${INDENT}\u25CF ${message}`);
2890
2892
  }
2891
2893
  function formatSuccess(message) {
2892
- return chalk.greenBright(`${INDENT}\u2713 ${message}`);
2894
+ return pc.green(`${INDENT}\u2713 ${message}`);
2893
2895
  }
2894
2896
  function formatReady(seconds = process.uptime()) {
2895
- return chalk.greenBright(`${INDENT}\u2713 Ready in ${seconds.toFixed(1)}s`);
2897
+ return pc.green(`${INDENT}\u2713 Ready in ${seconds.toFixed(1)}s`);
2896
2898
  }
2897
2899
  function formatWarning(message) {
2898
- return chalk.yellow(`${INDENT}\u25B2 ${message}`);
2900
+ return pc.yellow(`${INDENT}\u25B2 ${message}`);
2899
2901
  }
2900
2902
  function formatError(message) {
2901
- return chalk.red(`${INDENT}\u2717 ${message}`);
2903
+ return pc.red(`${INDENT}\u2717 ${message}`);
2902
2904
  }
2903
2905
  function printInfo(message) {
2904
2906
  writeLine(formatInfo(message));
@@ -2912,49 +2914,47 @@ function printWarning(message) {
2912
2914
  function printError(message) {
2913
2915
  writeLine(formatError(message));
2914
2916
  }
2915
- function printDetail(message, formatter = chalk.dim) {
2917
+ function printDetail(message, formatter = pc.dim) {
2916
2918
  writeLine(formatter(`${INDENT} ${message}`));
2917
2919
  }
2918
2920
  function printCommand(message) {
2919
- printDetail(message, chalk.cyan);
2921
+ printDetail(message, pc.cyan);
2920
2922
  }
2921
2923
  function printLocation(label, value, brightValue = false) {
2922
- const prefix = chalk.dim(`${INDENT}\u279C ${`${label}:`.padEnd(LABEL_WIDTH)}`);
2923
- const renderedValue = brightValue ? chalk.whiteBright(value) : chalk.dim(value);
2924
+ const prefix = pc.dim(`${INDENT}\u279C ${`${label}:`.padEnd(LABEL_WIDTH)}`);
2925
+ const linked = value.startsWith("http") ? terminalLink(value, value) : value;
2926
+ const renderedValue = brightValue ? pc.bold(pc.white(linked)) : pc.dim(linked);
2924
2927
  writeLine(`${prefix}${renderedValue}`);
2925
2928
  }
2929
+ var activeSpinner = null;
2926
2930
  function startInlineStatus(message) {
2927
2931
  clearActiveStatus();
2928
- const line = formatPending(message);
2929
- if (!process.stdout.isTTY) {
2930
- writeLine(line);
2931
- return;
2932
- }
2933
- process.stdout.write(line);
2934
- activeStatusLine = true;
2935
- }
2936
- function replaceInlineStatus(line) {
2937
- if (!process.stdout.isTTY) {
2938
- writeLine(line);
2939
- return;
2940
- }
2941
- clearLine(process.stdout, 0);
2942
- cursorTo(process.stdout, 0);
2943
- process.stdout.write(`${line}
2944
- `);
2945
- activeStatusLine = false;
2932
+ activeSpinner = createSpinner(message).start();
2946
2933
  }
2947
2934
  function finishInlineStatus(message) {
2948
- replaceInlineStatus(formatSuccess(message));
2935
+ if (activeSpinner) {
2936
+ activeSpinner.success({ text: message });
2937
+ activeSpinner = null;
2938
+ } else writeLine(formatSuccess(message));
2949
2939
  }
2950
2940
  function warnInlineStatus(message) {
2951
- replaceInlineStatus(formatWarning(message));
2941
+ if (activeSpinner) {
2942
+ activeSpinner.warn({ text: message });
2943
+ activeSpinner = null;
2944
+ } else writeLine(formatWarning(message));
2952
2945
  }
2953
2946
  function failInlineStatus(message) {
2954
- replaceInlineStatus(formatError(message));
2947
+ if (activeSpinner) {
2948
+ activeSpinner.error({ text: message });
2949
+ activeSpinner = null;
2950
+ } else writeLine(formatError(message));
2955
2951
  }
2956
2952
  function finishInlineReady() {
2957
- replaceInlineStatus(formatReady());
2953
+ const msg = `Ready in ${process.uptime().toFixed(1)}s`;
2954
+ if (activeSpinner) {
2955
+ activeSpinner.success({ text: msg });
2956
+ activeSpinner = null;
2957
+ } else writeLine(formatReady());
2958
2958
  }
2959
2959
  function getDetectedFrameworkLabel() {
2960
2960
  if (detectedFramework) return detectedFramework;
@@ -2973,13 +2973,13 @@ process.on("uncaughtException", (err) => {
2973
2973
  process.exit(1);
2974
2974
  });
2975
2975
  try {
2976
- const fdLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: true }).trim(), 10);
2976
+ const fdLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: "/bin/sh" }).trim(), 10);
2977
2977
  if (fdLimit > 0 && fdLimit < 4096) {
2978
2978
  try {
2979
- execSync2("ulimit -n 65536", { shell: true, stdio: "ignore" });
2979
+ execSync2("ulimit -n 65536", { shell: "/bin/sh", stdio: "ignore" });
2980
2980
  } catch {
2981
2981
  }
2982
- const newLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: true }).trim(), 10);
2982
+ const newLimit = parseInt(execSync2("ulimit -n", { encoding: "utf-8", shell: "/bin/sh" }).trim(), 10);
2983
2983
  if (newLimit < 4096) {
2984
2984
  writeLine();
2985
2985
  printWarning(`File descriptor limit is ${fdLimit} (need 4096+).`);
@@ -3087,18 +3087,18 @@ function runCommand(cmd, args, cwd = process.cwd()) {
3087
3087
  const child = spawn5(cmd, args, {
3088
3088
  cwd,
3089
3089
  stdio: ["ignore", "pipe", "pipe"],
3090
- shell: true
3090
+ shell: "/bin/sh"
3091
3091
  });
3092
3092
  child.stdout?.on("data", (data) => {
3093
3093
  const lines = data.toString().trim().split("\n");
3094
3094
  for (const line of lines) {
3095
- if (line.trim()) writeLine(chalk.dim(`${INDENT}\u2502 ${line}`));
3095
+ if (line.trim()) writeLine(pc.dim(`${INDENT}\u2502 ${line}`));
3096
3096
  }
3097
3097
  });
3098
3098
  child.stderr?.on("data", (data) => {
3099
3099
  const lines = data.toString().trim().split("\n");
3100
3100
  for (const line of lines) {
3101
- if (line.trim()) writeLine(chalk.dim(`${INDENT}\u2502 ${line}`));
3101
+ if (line.trim()) writeLine(pc.dim(`${INDENT}\u2502 ${line}`));
3102
3102
  }
3103
3103
  });
3104
3104
  child.on("error", () => resolve4(false));
@@ -3202,7 +3202,7 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
3202
3202
  "Project root directories (defaults to cwd)"
3203
3203
  ).option("--no-open", "Don't auto-open browser").option("--host <host>", "Dev server host", "localhost").action(async (opts) => {
3204
3204
  writeLine();
3205
- writeLine(`${INDENT}${chalk.white("OpenMagic")} ${chalk.dim(`v${VERSION2}`)}`);
3205
+ writeLine(`${INDENT}${pc.white("OpenMagic")} ${pc.dim(`v${VERSION2}`)}`);
3206
3206
  writeLine();
3207
3207
  let targetPort;
3208
3208
  let targetHost = opts.host;
@@ -3281,7 +3281,7 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
3281
3281
  } else if (detected && !detected.fromScripts) {
3282
3282
  finishInlineStatus(`Found dev server on port ${detected.port}`);
3283
3283
  const answer = await ask(
3284
- chalk.yellow(`${INDENT}\u25B2 Found a server on port ${detected.port}. Is this your project's dev server? `) + chalk.dim("(Y/n) ")
3284
+ pc.yellow(`${INDENT}\u25B2 Found a server on port ${detected.port}. Is this your project's dev server? `) + pc.dim("(Y/n) ")
3285
3285
  );
3286
3286
  if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes" || answer === "") {
3287
3287
  targetPort = detected.port;
@@ -3468,7 +3468,7 @@ async function offerToStartDevServer(expectedPort) {
3468
3468
  printInfo("No dev scripts found, but index.html was detected.");
3469
3469
  writeLine();
3470
3470
  const answer = await ask(
3471
- chalk.dim(`${INDENT}Serve this directory as a static site? `) + chalk.dim("(Y/n) ")
3471
+ pc.dim(`${INDENT}Serve this directory as a static site? `) + pc.dim("(Y/n) ")
3472
3472
  );
3473
3473
  if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
3474
3474
  return false;
@@ -3498,7 +3498,7 @@ async function offerToStartDevServer(expectedPort) {
3498
3498
  childProcesses.push(staticChild);
3499
3499
  staticChild.stdout?.on("data", (d) => {
3500
3500
  for (const line of d.toString().trim().split("\n")) {
3501
- if (line.trim()) writeLine(chalk.dim(`${INDENT}\u2502 ${line}`));
3501
+ if (line.trim()) writeLine(pc.dim(`${INDENT}\u2502 ${line}`));
3502
3502
  }
3503
3503
  });
3504
3504
  const up = await waitForPort(staticPort, 5e3);
@@ -3522,7 +3522,7 @@ async function offerToStartDevServer(expectedPort) {
3522
3522
  printWarning("node_modules was not found. Dependencies need to be installed.");
3523
3523
  writeLine();
3524
3524
  const answer = await ask(
3525
- chalk.white(`${INDENT}Run `) + chalk.cyan(deps.installCommand) + chalk.white("? ") + chalk.dim("(Y/n) ")
3525
+ pc.white(`${INDENT}Run `) + pc.cyan(deps.installCommand) + pc.white("? ") + pc.dim("(Y/n) ")
3526
3526
  );
3527
3527
  if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
3528
3528
  writeLine();
@@ -3548,12 +3548,12 @@ async function offerToStartDevServer(expectedPort) {
3548
3548
  printWarning("No dev server detected.");
3549
3549
  writeLine();
3550
3550
  writeLine(
3551
- chalk.white(`${INDENT}Found `) + chalk.cyan(`npm run ${chosen.name}`) + chalk.white(` in ${projectName}`) + chalk.dim(` (${chosen.framework})`)
3551
+ pc.white(`${INDENT}Found `) + pc.cyan(`npm run ${chosen.name}`) + pc.white(` in ${projectName}`) + pc.dim(` (${chosen.framework})`)
3552
3552
  );
3553
3553
  printDetail(`\u279C ${chosen.command}`);
3554
3554
  writeLine();
3555
3555
  const answer = await ask(
3556
- chalk.white(`${INDENT}Start it now? `) + chalk.dim("(Y/n) ")
3556
+ pc.white(`${INDENT}Start it now? `) + pc.dim("(Y/n) ")
3557
3557
  );
3558
3558
  if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
3559
3559
  writeLine();
@@ -3565,18 +3565,18 @@ async function offerToStartDevServer(expectedPort) {
3565
3565
  printWarning("No dev server detected.");
3566
3566
  writeLine();
3567
3567
  writeLine(
3568
- chalk.white(`${INDENT}Found ${scripts.length} dev scripts in ${projectName}:`)
3568
+ pc.white(`${INDENT}Found ${scripts.length} dev scripts in ${projectName}:`)
3569
3569
  );
3570
3570
  writeLine();
3571
3571
  scripts.forEach((s, i) => {
3572
3572
  writeLine(
3573
- chalk.cyan(`${INDENT}${i + 1}. `) + chalk.white(`npm run ${s.name}`) + chalk.dim(` (${s.framework}, port ${s.defaultPort})`)
3573
+ pc.cyan(`${INDENT}${i + 1}. `) + pc.white(`npm run ${s.name}`) + pc.dim(` (${s.framework}, port ${s.defaultPort})`)
3574
3574
  );
3575
3575
  printDetail(s.command);
3576
3576
  });
3577
3577
  writeLine();
3578
3578
  const answer = await ask(
3579
- chalk.white(`${INDENT}Which one should OpenMagic start? `) + chalk.dim(`(1-${scripts.length}, or n to cancel) `)
3579
+ pc.white(`${INDENT}Which one should OpenMagic start? `) + pc.dim(`(1-${scripts.length}, or n to cancel) `)
3580
3580
  );
3581
3581
  if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no" || answer === "") {
3582
3582
  writeLine();
@@ -3595,7 +3595,7 @@ async function offerToStartDevServer(expectedPort) {
3595
3595
  const compat = checkNodeCompatibility(chosen.framework);
3596
3596
  if (!compat.ok) {
3597
3597
  writeLine();
3598
- printError(compat.message);
3598
+ printError(compat.message || "Node.js version incompatible");
3599
3599
  writeLine();
3600
3600
  printInfo("Switch Node.js before running:");
3601
3601
  printCommand("nvm use 20");
@@ -3620,7 +3620,7 @@ async function offerToStartDevServer(expectedPort) {
3620
3620
  }
3621
3621
  writeLine();
3622
3622
  writeLine(
3623
- chalk.dim(`${INDENT}\u25CF Starting `) + chalk.cyan(`npm run ${chosen.name}`) + (portChanged ? chalk.dim(` (port ${port})`) : "") + chalk.dim("...")
3623
+ pc.dim(`${INDENT}\u25CF Starting `) + pc.cyan(`npm run ${chosen.name}`) + (portChanged ? pc.dim(` (port ${port})`) : "") + pc.dim("...")
3624
3624
  );
3625
3625
  const depsInfo = checkDependenciesInstalled();
3626
3626
  const runCmd = depsInfo.packageManager === "yarn" ? "yarn" : depsInfo.packageManager === "pnpm" ? "pnpm" : depsInfo.packageManager === "bun" ? "bun" : "npm";
@@ -3712,13 +3712,13 @@ async function offerToStartDevServer(expectedPort) {
3712
3712
  if (chosen?.framework) {
3713
3713
  const compat2 = checkNodeCompatibility(chosen.framework);
3714
3714
  if (!compat2.ok) {
3715
- printWarning(compat2.message);
3715
+ printWarning(compat2.message || "Node.js version may be incompatible");
3716
3716
  printDetail("Switch with:");
3717
3717
  printCommand("nvm use 20");
3718
3718
  writeLine();
3719
3719
  }
3720
3720
  }
3721
- writeLine(chalk.white(`${INDENT}Options:`));
3721
+ writeLine(pc.white(`${INDENT}Options:`));
3722
3722
  printDetail("1. Fix the error above and try again");
3723
3723
  printDetail("2. Start the server manually, then run:");
3724
3724
  printCommand("npx openmagic --port <your-port>");