@oxog/react-check 1.3.0 → 1.3.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +42 -19
  3. package/dist/browser-inject.global.js +5 -5
  4. package/dist/chain.d.cts +1 -1
  5. package/dist/chain.d.ts +1 -1
  6. package/dist/{chunk-7YYMP3PP.js → chunk-35I3PLS3.js} +33 -5
  7. package/dist/chunk-35I3PLS3.js.map +1 -0
  8. package/dist/{chunk-GE2ZX7I7.cjs → chunk-DSXOHC6R.cjs} +34 -6
  9. package/dist/chunk-DSXOHC6R.cjs.map +1 -0
  10. package/dist/{chunk-G7YVIPS7.cjs → chunk-LFY7MUHJ.cjs} +10 -2
  11. package/dist/chunk-LFY7MUHJ.cjs.map +1 -0
  12. package/dist/{chunk-3K2AER5M.cjs → chunk-NLWGB4IE.cjs} +27 -3
  13. package/dist/chunk-NLWGB4IE.cjs.map +1 -0
  14. package/dist/{chunk-27R56V2S.js → chunk-PIXJPQO7.js} +10 -2
  15. package/dist/chunk-PIXJPQO7.js.map +1 -0
  16. package/dist/{chunk-IM6OG2IC.js → chunk-REEPUD73.js} +27 -3
  17. package/dist/chunk-REEPUD73.js.map +1 -0
  18. package/dist/cli.js +236 -109
  19. package/dist/cli.js.map +1 -1
  20. package/dist/detect.cjs +6 -6
  21. package/dist/detect.d.cts +1 -1
  22. package/dist/detect.d.ts +1 -1
  23. package/dist/detect.js +1 -1
  24. package/dist/fix.cjs +2 -2
  25. package/dist/fix.d.cts +7 -1
  26. package/dist/fix.d.ts +7 -1
  27. package/dist/fix.js +1 -1
  28. package/dist/index.cjs +134 -60
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +77 -13
  31. package/dist/index.d.ts +77 -13
  32. package/dist/index.js +110 -36
  33. package/dist/index.js.map +1 -1
  34. package/dist/{scanner-D0mBQGTx.d.ts → scanner-BJFA0354.d.ts} +11 -2
  35. package/dist/{scanner-DUBgwztZ.d.cts → scanner-DZL2rIFv.d.cts} +11 -2
  36. package/dist/scanner.cjs +3 -3
  37. package/dist/scanner.d.cts +2 -2
  38. package/dist/scanner.d.ts +2 -2
  39. package/dist/scanner.js +2 -2
  40. package/dist/{types-BZ3OeZ-5.d.ts → types-BMDemwIs.d.cts} +7 -0
  41. package/dist/{types-BZ3OeZ-5.d.cts → types-BMDemwIs.d.ts} +7 -0
  42. package/package.json +1 -1
  43. package/dist/chunk-27R56V2S.js.map +0 -1
  44. package/dist/chunk-3K2AER5M.cjs.map +0 -1
  45. package/dist/chunk-7YYMP3PP.js.map +0 -1
  46. package/dist/chunk-G7YVIPS7.cjs.map +0 -1
  47. package/dist/chunk-GE2ZX7I7.cjs.map +0 -1
  48. package/dist/chunk-IM6OG2IC.js.map +0 -1
package/dist/cli.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFile, stat, access, writeFile, mkdir, rm, readdir } from 'fs/promises';
3
- import { constants } from 'fs';
4
- import { resolve, join, extname, basename, dirname } from 'path';
3
+ import { mkdirSync, existsSync, writeFileSync, constants } from 'fs';
4
+ import { join, resolve, extname, basename, dirname } from 'path';
5
5
  import { createServer, request as request$1 } from 'http';
6
6
  import { createHash } from 'crypto';
7
+ import { createRequire } from 'module';
8
+ import { homedir } from 'os';
7
9
  import { URL as URL$1, fileURLToPath } from 'url';
8
10
  import { request } from 'https';
9
- import { exec, execSync } from 'child_process';
11
+ import { execSync, exec } from 'child_process';
10
12
  import * as readline from 'readline';
11
13
 
12
14
  var __defProp = Object.defineProperty;
@@ -1124,8 +1126,9 @@ var FLAG_DEFINITIONS = {
1124
1126
  },
1125
1127
  tui: {
1126
1128
  short: "t",
1127
- description: "Terminal UI only (no browser)",
1128
- default: false
1129
+ description: "Not supported",
1130
+ default: false,
1131
+ unsupported: "Option --tui (-t) is not supported. The terminal UI starts automatically when the scan runs in an interactive terminal; to scan without launching Chrome use --proxy and open the proxied URL in your own browser."
1129
1132
  },
1130
1133
  silent: {
1131
1134
  short: "s",
@@ -1195,8 +1198,9 @@ var FLAG_DEFINITIONS = {
1195
1198
  },
1196
1199
  watch: {
1197
1200
  short: "w",
1198
- description: "Watch mode - keep scanning until quit",
1199
- default: false
1201
+ description: "Not supported",
1202
+ default: false,
1203
+ unsupported: "Option --watch (-w) is not supported. Without --duration a scan already keeps running until you quit (q or Ctrl+C)."
1200
1204
  },
1201
1205
  webui: {
1202
1206
  short: "W",
@@ -1402,6 +1406,11 @@ function validateArgs(args) {
1402
1406
  for (const flag of args.unknown ?? []) {
1403
1407
  errors.push(`Unknown option: ${flag}`);
1404
1408
  }
1409
+ for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
1410
+ if (def.unsupported !== void 0 && (args.provided?.has(name) ?? args.flags.get(name) === true)) {
1411
+ errors.push(def.unsupported);
1412
+ }
1413
+ }
1405
1414
  for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
1406
1415
  if (def.takesValue && args.flags.get(name) === true) {
1407
1416
  errors.push(`Option --${name} requires a value`);
@@ -1410,10 +1419,20 @@ function validateArgs(args) {
1410
1419
  if (args.command === "scan" && !args.target) {
1411
1420
  errors.push("Target URL is required for scan command");
1412
1421
  }
1422
+ let targetIsCommandTypo = false;
1423
+ if (args.command === "scan" && args.target !== void 0 && looksLikeCommandWord(args.target)) {
1424
+ targetIsCommandTypo = true;
1425
+ errors.push(
1426
+ `Unknown command: ${args.target} (commands: scan, detect, report, init, help, version). To scan a host named "${args.target}", write http://${args.target}`
1427
+ );
1428
+ }
1429
+ if (args.command === "scan" && !targetIsCommandTypo && args.positional.length > 0) {
1430
+ errors.push(`Unexpected argument: ${args.positional.join(" ")} (scan takes a single URL)`);
1431
+ }
1413
1432
  if (args.command === "report" && args.positional.length === 0) {
1414
1433
  errors.push("Input JSON report path is required for report command");
1415
1434
  }
1416
- if (args.target) {
1435
+ if (args.target && !targetIsCommandTypo) {
1417
1436
  try {
1418
1437
  const url = new URL(normalizeTarget(args.target));
1419
1438
  if (url.protocol !== "http:" && url.protocol !== "https:") {
@@ -1458,6 +1477,9 @@ function validateArgs(args) {
1458
1477
  }
1459
1478
  return errors;
1460
1479
  }
1480
+ function looksLikeCommandWord(target) {
1481
+ return /^[a-z][a-z0-9_-]*$/i.test(target) && target.toLowerCase() !== "localhost";
1482
+ }
1461
1483
  function getHelpText() {
1462
1484
  const lines = [
1463
1485
  "",
@@ -1476,7 +1498,7 @@ function getHelpText() {
1476
1498
  ];
1477
1499
  const groups = {
1478
1500
  "General": ["help", "version", "verbose", "config", "json"],
1479
- "Mode": ["proxy", "tui", "silent", "headless", "watch", "webui", "webui-port"],
1501
+ "Mode": ["proxy", "silent", "headless", "webui", "webui-port"],
1480
1502
  "Report": ["report", "format", "output", "fix"],
1481
1503
  "Thresholds": ["threshold-critical", "threshold-warning", "fps-threshold"],
1482
1504
  "Network": ["port", "duration"]
@@ -3452,6 +3474,14 @@ var FixSuggester = class extends EventEmitter {
3452
3474
  getSuggestions(componentName) {
3453
3475
  return this.suggestions.get(componentName) ?? [];
3454
3476
  }
3477
+ /**
3478
+ * Whether suggestions have been generated (and cached) for a component
3479
+ * @param componentName - Component name
3480
+ * @returns true when {@link analyze} ran for the component
3481
+ */
3482
+ hasSuggestions(componentName) {
3483
+ return this.suggestions.has(componentName);
3484
+ }
3455
3485
  /**
3456
3486
  * Get all cached suggestions
3457
3487
  * @returns All suggestions
@@ -3561,6 +3591,8 @@ var Scanner = class extends EventEmitter {
3561
3591
  chainAnalyzer;
3562
3592
  /** Fix suggester */
3563
3593
  fixSuggester;
3594
+ /** Components whose stats changed since their suggestions were last generated */
3595
+ staleSuggestions = /* @__PURE__ */ new Set();
3564
3596
  /** Scanner configuration */
3565
3597
  config;
3566
3598
  /** Whether scanner is currently running */
@@ -3594,6 +3626,7 @@ var Scanner = class extends EventEmitter {
3594
3626
  */
3595
3627
  setupEventForwarding() {
3596
3628
  this.stats.on("update", (stats) => {
3629
+ this.staleSuggestions.add(stats.name);
3597
3630
  this.emit("stats", stats);
3598
3631
  });
3599
3632
  this.stats.on("severityChange", (change) => {
@@ -3642,20 +3675,26 @@ var Scanner = class extends EventEmitter {
3642
3675
  this.stats.reset();
3643
3676
  this.chainAnalyzer.reset();
3644
3677
  this.fixSuggester.clearSuggestions();
3678
+ this.staleSuggestions.clear();
3645
3679
  this.renderBatch = [];
3646
3680
  this.emit("reset", void 0);
3647
3681
  }
3648
3682
  /**
3649
3683
  * Process a render event
3650
3684
  * @param render - Render information
3651
- * @param parent - Optional parent component name
3685
+ * @param parent - Optional parent component name (defaults to `render.parent`,
3686
+ * which the injected browser script fills in from the fiber tree)
3652
3687
  */
3653
3688
  addRender(render, parent) {
3654
3689
  if (!this.running) return;
3655
3690
  if (!this.isComponentIncluded(render.componentName)) return;
3691
+ const parentName = parent ?? (typeof render.parent === "string" && render.parent !== "" ? render.parent : void 0);
3656
3692
  this.renderBatch.push(render);
3657
3693
  this.stats.addRender(render);
3658
- this.chainAnalyzer.addRender(render, parent);
3694
+ if (parentName !== void 0) {
3695
+ this.stats.setComponentParent(render.componentName, parentName);
3696
+ }
3697
+ this.chainAnalyzer.addRender(render, parentName);
3659
3698
  this.emit("render", render);
3660
3699
  this.scheduleBatchProcessing();
3661
3700
  }
@@ -3857,14 +3896,33 @@ var Scanner = class extends EventEmitter {
3857
3896
  * @returns All suggestions
3858
3897
  */
3859
3898
  getSuggestions() {
3899
+ this.refreshSuggestions();
3860
3900
  return this.fixSuggester.getAllSuggestions();
3861
3901
  }
3902
+ /**
3903
+ * Re-generate cached suggestions whose component received renders since they
3904
+ * were created, so their text, numbers and severity match the current stats
3905
+ * @param componentName - Only refresh this component (all when omitted)
3906
+ */
3907
+ refreshSuggestions(componentName) {
3908
+ const names = componentName !== void 0 ? [componentName] : [...this.staleSuggestions];
3909
+ for (const name of names) {
3910
+ if (!this.staleSuggestions.has(name)) continue;
3911
+ this.staleSuggestions.delete(name);
3912
+ if (!this.fixSuggester.hasSuggestions(name)) continue;
3913
+ const stats = this.stats.getComponentStats(name);
3914
+ if (stats) {
3915
+ this.fixSuggester.analyze(stats);
3916
+ }
3917
+ }
3918
+ }
3862
3919
  /**
3863
3920
  * Get suggestions for a specific component
3864
3921
  * @param componentName - Component name
3865
3922
  * @returns Component suggestions
3866
3923
  */
3867
3924
  getComponentSuggestions(componentName) {
3925
+ this.refreshSuggestions(componentName);
3868
3926
  return this.fixSuggester.getSuggestions(componentName);
3869
3927
  }
3870
3928
  /**
@@ -5761,6 +5819,38 @@ function handleBrowserMessages(client, handler) {
5761
5819
  handler(message);
5762
5820
  });
5763
5821
  }
5822
+ function getPuppeteerInstallDir(env = process.env, platform = process.platform, home = homedir()) {
5823
+ const explicit = env["REACTCHECK_PUPPETEER_DIR"];
5824
+ if (explicit !== void 0 && explicit !== "") return explicit;
5825
+ const cacheRoot = platform === "win32" ? env["LOCALAPPDATA"] !== void 0 && env["LOCALAPPDATA"] !== "" ? env["LOCALAPPDATA"] : join(home, "AppData", "Local") : env["XDG_CACHE_HOME"] !== void 0 && env["XDG_CACHE_HOME"] !== "" ? env["XDG_CACHE_HOME"] : join(home, ".cache");
5826
+ return join(cacheRoot, "react-check", "puppeteer");
5827
+ }
5828
+ function toPuppeteer(loaded) {
5829
+ const candidates = [
5830
+ loaded?.default,
5831
+ loaded,
5832
+ loaded?.default?.default
5833
+ ];
5834
+ for (const candidate of candidates) {
5835
+ if (candidate !== null && typeof candidate === "object" && typeof candidate.launch === "function") {
5836
+ return candidate;
5837
+ }
5838
+ }
5839
+ return null;
5840
+ }
5841
+ async function loadPuppeteer(installDir = getPuppeteerInstallDir()) {
5842
+ try {
5843
+ const found = toPuppeteer(await import('puppeteer'));
5844
+ if (found) return found;
5845
+ } catch {
5846
+ }
5847
+ try {
5848
+ const requireFromDir = createRequire(join(installDir, "package.json"));
5849
+ return toPuppeteer(requireFromDir("puppeteer"));
5850
+ } catch {
5851
+ return null;
5852
+ }
5853
+ }
5764
5854
 
5765
5855
  // src/server/browser.ts
5766
5856
  var logger3 = new Logger({ prefix: "browser", level: 1 /* INFO */ });
@@ -5802,7 +5892,10 @@ var BrowserLauncher = class extends EventEmitter {
5802
5892
  */
5803
5893
  async launch() {
5804
5894
  try {
5805
- const puppeteer = await import('puppeteer');
5895
+ const puppeteer = await loadPuppeteer();
5896
+ if (!puppeteer) {
5897
+ throw new Error("Puppeteer is not installed. Install it with: npm install puppeteer");
5898
+ }
5806
5899
  const args = [
5807
5900
  "--no-sandbox",
5808
5901
  "--disable-setuid-sandbox",
@@ -5813,7 +5906,7 @@ var BrowserLauncher = class extends EventEmitter {
5813
5906
  `--window-size=${this.options.width},${this.options.height}`,
5814
5907
  ...this.options.args
5815
5908
  ];
5816
- this.browser = await puppeteer.default.launch({
5909
+ this.browser = await puppeteer.launch({
5817
5910
  headless: this.options.headless,
5818
5911
  args,
5819
5912
  slowMo: this.options.slowMo,
@@ -5966,14 +6059,16 @@ var BrowserLauncher = class extends EventEmitter {
5966
6059
  return this.browser !== null && this.browser.connected;
5967
6060
  }
5968
6061
  /**
5969
- * Get the page instance (for advanced usage)
6062
+ * Get the page instance (for advanced usage). The return type is a
6063
+ * structural subset of Puppeteer's `Page`; pass the real type for the full
6064
+ * API: `getPage<import('puppeteer').Page>()`.
5970
6065
  * @returns Puppeteer page or null
5971
6066
  */
5972
6067
  getPage() {
5973
6068
  return this.page;
5974
6069
  }
5975
6070
  /**
5976
- * Get the browser instance (for advanced usage)
6071
+ * Get the browser instance (for advanced usage); see {@link getPage}
5977
6072
  * @returns Puppeteer browser or null
5978
6073
  */
5979
6074
  getBrowser() {
@@ -5981,12 +6076,7 @@ var BrowserLauncher = class extends EventEmitter {
5981
6076
  }
5982
6077
  };
5983
6078
  async function isPuppeteerAvailable() {
5984
- try {
5985
- await import('puppeteer');
5986
- return true;
5987
- } catch {
5988
- return false;
5989
- }
6079
+ return await loadPuppeteer() !== null;
5990
6080
  }
5991
6081
  var INJECTION_SCRIPT_FILE = "browser-inject.global.js";
5992
6082
  function getInjectionScriptCandidates() {
@@ -7482,7 +7572,7 @@ var WebUIServer = class extends EventEmitter {
7482
7572
  };
7483
7573
 
7484
7574
  // src/version.ts
7485
- var VERSION = "1.3.0";
7575
+ var VERSION = "1.3.1";
7486
7576
 
7487
7577
  // src/cli/commands/scan.ts
7488
7578
  var logger5 = new Logger({ prefix: "scan", level: 1 /* INFO */ });
@@ -7492,52 +7582,52 @@ function canAutoInstall(env = process.env, isTTY = process.stdin.isTTY === true
7492
7582
  if (env["REACTCHECK_NO_INSTALL"] !== void 0 && env["REACTCHECK_NO_INSTALL"] !== "") return false;
7493
7583
  return true;
7494
7584
  }
7495
- async function installPuppeteer(wsServer) {
7496
- console.log("");
7497
- console.log(colors.cyan + "\u{1F4E6} Puppeteer is required for browser automation." + colors.reset);
7498
- console.log(colors.gray + " Installing puppeteer... (this may take a minute)" + colors.reset);
7499
- console.log("");
7585
+ function defaultInstallDeps() {
7586
+ return {
7587
+ installDir: getPuppeteerInstallDir(),
7588
+ run: (command, cwd) => {
7589
+ execSync(command, { cwd, stdio: "inherit", timeout: 3e5 });
7590
+ },
7591
+ isAvailable: isPuppeteerAvailable,
7592
+ // eslint-disable-next-line no-console
7593
+ print: (line) => console.log(line)
7594
+ };
7595
+ }
7596
+ async function installPuppeteer(deps = defaultInstallDeps()) {
7597
+ const { installDir, print } = deps;
7598
+ print("");
7599
+ print(colors.cyan + "\u{1F4E6} Puppeteer is required for browser automation." + colors.reset);
7600
+ print(colors.gray + ` Installing puppeteer into ${installDir} (this may take a minute)` + colors.reset);
7601
+ print("");
7500
7602
  try {
7501
- execSync("npm install puppeteer --no-save", {
7502
- stdio: "inherit",
7503
- timeout: 3e5
7504
- // 5 minutes timeout
7505
- });
7506
- console.log("");
7507
- console.log(colors.green + "\u2713 Puppeteer installed successfully!" + colors.reset);
7508
- console.log("");
7509
- console.log(colors.cyan + "\u{1F504} Restarting scan..." + colors.reset);
7510
- console.log("");
7511
- if (wsServer) {
7512
- await wsServer.stop();
7513
- }
7514
- const args = process.argv.slice(1);
7515
- const { spawn } = await import('child_process');
7516
- const isWindows = process.platform === "win32";
7517
- const child = spawn(process.execPath, args, {
7518
- stdio: "inherit",
7519
- env: process.env,
7520
- shell: isWindows,
7521
- detached: false
7522
- });
7523
- await new Promise((resolve3) => {
7524
- child.on("exit", (code) => {
7525
- process.exit(code ?? 0);
7526
- });
7527
- child.on("error", (err) => {
7528
- console.error("Spawn error:", err);
7529
- resolve3();
7530
- });
7531
- });
7532
- return false;
7603
+ mkdirSync(installDir, { recursive: true });
7604
+ const manifest = join(installDir, "package.json");
7605
+ if (!existsSync(manifest)) {
7606
+ writeFileSync(manifest, JSON.stringify({ name: "react-check-puppeteer", private: true }, null, 2) + "\n");
7607
+ }
7608
+ deps.run("npm install puppeteer --no-audit --no-fund", installDir);
7533
7609
  } catch (error) {
7534
- console.log("");
7535
- console.error("Puppeteer installation error:", error);
7536
- logger5.error("Failed to install puppeteer automatically.");
7537
- logger5.info("Please install it manually: npm install puppeteer");
7538
- logger5.info("Or use --proxy mode: react-check scan --proxy <url>");
7610
+ print("");
7611
+ logger5.error(`Failed to install puppeteer automatically: ${error instanceof Error ? error.message : String(error)}`);
7612
+ printManualInstallHelp();
7539
7613
  return false;
7540
7614
  }
7615
+ if (!await deps.isAvailable()) {
7616
+ print("");
7617
+ logger5.error(`Puppeteer was installed into ${installDir} but still cannot be loaded.`);
7618
+ printManualInstallHelp();
7619
+ return false;
7620
+ }
7621
+ print("");
7622
+ print(colors.green + "\u2713 Puppeteer installed successfully!" + colors.reset);
7623
+ print("");
7624
+ return true;
7625
+ }
7626
+ function printManualInstallHelp() {
7627
+ logger5.info("Install it in your project and run react-check from there: npm install --save-dev puppeteer @oxog/react-check");
7628
+ logger5.info("Or install both globally: npm install -g @oxog/react-check puppeteer");
7629
+ logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
7630
+ logger5.info("Set REACTCHECK_NO_INSTALL=1 to skip the automatic install.");
7541
7631
  }
7542
7632
  function toFormats(value) {
7543
7633
  return parseFormatList(value).filter(
@@ -7556,7 +7646,6 @@ function parseScanOptions(args) {
7556
7646
  return {
7557
7647
  target: normalizeTarget(args.target ?? "localhost:3000"),
7558
7648
  proxy: getBooleanFlag(args, "proxy"),
7559
- tui: getBooleanFlag(args, "tui"),
7560
7649
  silent: getBooleanFlag(args, "silent"),
7561
7650
  report: reportRequested,
7562
7651
  format,
@@ -7570,7 +7659,6 @@ function parseScanOptions(args) {
7570
7659
  fpsThreshold: getNumberFlag(args, "fps-threshold") ?? 30,
7571
7660
  headless: getBooleanFlag(args, "headless"),
7572
7661
  duration: toSeconds(getStringFlag(args, "duration")),
7573
- watch: getBooleanFlag(args, "watch"),
7574
7662
  configPath: getStringFlag(args, "config"),
7575
7663
  webui: getBooleanFlag(args, "webui"),
7576
7664
  webuiPort: getNumberFlag(args, "webui-port") ?? 3199
@@ -7626,6 +7714,17 @@ async function runScanCommand(args) {
7626
7714
  browserClients: /* @__PURE__ */ new Set(),
7627
7715
  proxy: null
7628
7716
  };
7717
+ if (!mergedOptions.proxy && !await isPuppeteerAvailable()) {
7718
+ if (!canAutoInstall()) {
7719
+ logger5.error("Puppeteer is required to launch a browser but is not installed.");
7720
+ logger5.info("Install it with: npm install --save-dev puppeteer");
7721
+ logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
7722
+ return 2;
7723
+ }
7724
+ if (!await installPuppeteer()) {
7725
+ return 2;
7726
+ }
7727
+ }
7629
7728
  setupScannerEvents(session);
7630
7729
  const useTUI = !mergedOptions.silent && !mergedOptions.proxy && !mergedOptions.webui && process.stdin.isTTY;
7631
7730
  if (useTUI) {
@@ -7666,8 +7765,16 @@ async function runScanCommand(args) {
7666
7765
  session.scanner.recordFps(message.payload);
7667
7766
  break;
7668
7767
  case "ready":
7669
- logger5.info(`React detected: ${message.payload.reactVersion}`);
7768
+ if (message.payload.reactVersion.startsWith("unknown")) {
7769
+ logger5.info("Browser script ready, waiting for React to load");
7770
+ } else {
7771
+ logger5.info(`React detected: ${message.payload.reactVersion}`);
7772
+ }
7670
7773
  client.send(JSON.stringify({ type: "start" }));
7774
+ client.send(JSON.stringify({
7775
+ type: "config",
7776
+ payload: { thresholds: { warning: mergedOptions.thresholdWarning, critical: mergedOptions.thresholdCritical } }
7777
+ }));
7671
7778
  client.send(JSON.stringify({ type: "toggle-overlay", payload: { enabled: session.overlayEnabled } }));
7672
7779
  break;
7673
7780
  case "error":
@@ -7715,20 +7822,6 @@ async function runScanCommand(args) {
7715
7822
  console.log(` Press ${colors.bold}Ctrl+C${colors.reset} to stop scanning`);
7716
7823
  console.log("");
7717
7824
  } else {
7718
- const hasPuppeteer = await isPuppeteerAvailable();
7719
- if (!hasPuppeteer && !canAutoInstall()) {
7720
- logger5.error("Puppeteer is required to launch a browser but is not installed.");
7721
- logger5.info("Install it with: npm install --save-dev puppeteer");
7722
- logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
7723
- await cleanupSession(session);
7724
- return 2;
7725
- }
7726
- if (!hasPuppeteer) {
7727
- const installed = await installPuppeteer(session.wsServer ?? void 0);
7728
- if (!installed) {
7729
- return 2;
7730
- }
7731
- }
7732
7825
  const injectionScript = await loadInjectionScript(mergedOptions.port);
7733
7826
  session.browser = new BrowserLauncher({
7734
7827
  url: mergedOptions.target,
@@ -7765,12 +7858,15 @@ async function runScanCommand(args) {
7765
7858
  }
7766
7859
  printSummary(session);
7767
7860
  if (mergedOptions.fix && !mergedOptions.silent) {
7768
- printFixSuggestions(session.suggestions);
7861
+ printFixSuggestions(session.scanner.getSuggestions());
7769
7862
  }
7770
7863
  const summary = session.scanner.getSummary();
7771
7864
  return summary.criticalIssues > 0 ? 1 : 0;
7772
7865
  } catch (error) {
7773
7866
  await cleanupSession(session);
7867
+ if (useTUI) {
7868
+ logger5.setLevel(1 /* INFO */);
7869
+ }
7774
7870
  const errorMessage = error instanceof Error ? error.message : String(error);
7775
7871
  if (errorMessage.includes("ERR_CONNECTION_REFUSED")) {
7776
7872
  logger5.error(`Could not connect to ${mergedOptions.target}`);
@@ -7827,13 +7923,16 @@ function setupScannerEvents(session) {
7827
7923
  }
7828
7924
  });
7829
7925
  scanner.on("fix", (suggestion) => {
7830
- if (!session.suggestions.some(
7926
+ const index = session.suggestions.findIndex(
7831
7927
  (s) => s.componentName === suggestion.componentName && s.fix === suggestion.fix
7832
- )) {
7928
+ );
7929
+ if (index === -1) {
7833
7930
  session.suggestions.push(suggestion);
7834
- if (session.tui) {
7835
- session.tui.update({ suggestions: session.suggestions });
7836
- }
7931
+ } else {
7932
+ session.suggestions[index] = suggestion;
7933
+ }
7934
+ if (session.tui) {
7935
+ session.tui.update({ suggestions: session.suggestions });
7837
7936
  }
7838
7937
  });
7839
7938
  scanner.on("fps-drop", (fps) => {
@@ -7866,12 +7965,8 @@ function setupTUIEvents(session) {
7866
7965
  });
7867
7966
  });
7868
7967
  tui.on("selectComponent", (component) => {
7869
- const suggestions = scanner.analyzeComponent(component.name);
7870
- session.suggestions.push(...suggestions.filter(
7871
- (s) => !session.suggestions.some(
7872
- (ex) => ex.componentName === s.componentName && ex.fix === s.fix
7873
- )
7874
- ));
7968
+ scanner.analyzeComponent(component.name);
7969
+ session.suggestions = scanner.getSuggestions();
7875
7970
  tui.update({ suggestions: session.suggestions });
7876
7971
  });
7877
7972
  tui.on("toggleOverlay", () => {
@@ -7910,8 +8005,10 @@ async function waitForSignal() {
7910
8005
  });
7911
8006
  }
7912
8007
  function generateReport(session) {
7913
- const { scanner, options, chains, suggestions } = session;
8008
+ const { scanner, options, chains } = session;
7914
8009
  const exported = scanner.export();
8010
+ const suggestions = exported.suggestions;
8011
+ session.suggestions = suggestions;
7915
8012
  const sessionInfo = {
7916
8013
  url: options.target,
7917
8014
  duration: scanner.getSessionDuration(),
@@ -7933,7 +8030,7 @@ function generateReport(session) {
7933
8030
  };
7934
8031
  }
7935
8032
  async function saveReport(report, options) {
7936
- const { ensureDir: ensureDir2, writeTextFile: writeTextFile2, joinPath: joinPath2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
8033
+ const { ensureDir: ensureDir2, writeTextFile: writeTextFile2, joinPath: joinPath3 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
7937
8034
  const { generateHTMLReport: generateHTMLReport2 } = await Promise.resolve().then(() => (init_html(), html_exports));
7938
8035
  const { generateJSONReport: generateJSONReport2 } = await Promise.resolve().then(() => (init_json(), json_exports));
7939
8036
  const { generateMarkdownReport: generateMarkdownReport2 } = await Promise.resolve().then(() => (init_markdown(), markdown_exports));
@@ -7960,7 +8057,7 @@ async function saveReport(report, options) {
7960
8057
  continue;
7961
8058
  }
7962
8059
  const filename = `reactcheck-report-${timestamp}.${extension}`;
7963
- const filepath = joinPath2(options.output, filename);
8060
+ const filepath = joinPath3(options.output, filename);
7964
8061
  await writeTextFile2(filepath, content);
7965
8062
  logger5.info(`Report saved: ${filepath}`);
7966
8063
  }
@@ -8117,6 +8214,29 @@ async function runInitCommand(args) {
8117
8214
 
8118
8215
  // src/detect/framework.ts
8119
8216
  init_fs();
8217
+ var VITE_CONFIG_FILES = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs", "vite.config.cts", "vite.config.cjs"];
8218
+ var VITE_SSR_ENTRIES = ["entry-server.tsx", "entry-server.ts", "entry-server.jsx", "entry-server.js"];
8219
+ async function detectViteSSR(pkg, dir) {
8220
+ if (Object.values(pkg.scripts ?? {}).some((script) => /(^|\s)--ssr(\s|=|$)/.test(script))) {
8221
+ return true;
8222
+ }
8223
+ for (const file of VITE_CONFIG_FILES) {
8224
+ const path = joinPath(dir, file);
8225
+ if (await exists(path)) {
8226
+ try {
8227
+ const source = (await readTextFile(path)).replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "");
8228
+ if (/\bssr\s*:/.test(source)) return true;
8229
+ } catch {
8230
+ }
8231
+ }
8232
+ }
8233
+ for (const entry of VITE_SSR_ENTRIES) {
8234
+ if (await exists(joinPath(dir, "src", entry)) || await exists(joinPath(dir, entry))) {
8235
+ return true;
8236
+ }
8237
+ }
8238
+ return false;
8239
+ }
8120
8240
  var FRAMEWORK_DETECTORS = [
8121
8241
  // Next.js
8122
8242
  {
@@ -8183,7 +8303,8 @@ var FRAMEWORK_DETECTORS = [
8183
8303
  },
8184
8304
  {
8185
8305
  name: "ssr",
8186
- detect: async (_, dir) => await exists(joinPath(dir, "vite.config.ts")) || await exists(joinPath(dir, "vite.config.js"))
8306
+ deps: ["vike", "vite-plugin-ssr"],
8307
+ detect: detectViteSSR
8187
8308
  }
8188
8309
  ],
8189
8310
  tips: [
@@ -8819,15 +8940,23 @@ function printVersion() {
8819
8940
  function printHelp() {
8820
8941
  console.log(getHelpText());
8821
8942
  }
8943
+ function getBannerText() {
8944
+ const title = "ReactCheck";
8945
+ const tagline = " - Scan, diagnose, and fix React performance issues";
8946
+ const inner = 3 + title.length + tagline.length + 3;
8947
+ const blank = `\u2551${" ".repeat(inner)}\u2551`;
8948
+ return [
8949
+ "",
8950
+ `${colors.cyan}\u2554${"\u2550".repeat(inner)}\u2557`,
8951
+ blank,
8952
+ `\u2551 ${colors.bold}${title}${colors.reset}${colors.cyan}${tagline} \u2551`,
8953
+ blank,
8954
+ `\u255A${"\u2550".repeat(inner)}\u255D${colors.reset}`,
8955
+ ""
8956
+ ].join("\n");
8957
+ }
8822
8958
  function printBanner() {
8823
- const banner = `
8824
- ${colors.cyan}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
8825
- \u2551 \u2551
8826
- \u2551 ${colors.bold}ReactCheck${colors.reset}${colors.cyan} - Scan, diagnose, and fix React performance \u2551
8827
- \u2551 \u2551
8828
- \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${colors.reset}
8829
- `;
8830
- console.log(banner);
8959
+ console.log(getBannerText());
8831
8960
  }
8832
8961
  var CLI = class {
8833
8962
  /** Raw arguments */
@@ -8846,9 +8975,7 @@ var CLI = class {
8846
8975
  */
8847
8976
  wizardConfigToArgs(config) {
8848
8977
  const flags = /* @__PURE__ */ new Map();
8849
- if (config.mode === "tui") {
8850
- flags.set("tui", true);
8851
- } else if (config.mode === "webui") {
8978
+ if (config.mode === "webui") {
8852
8979
  flags.set("webui", true);
8853
8980
  flags.set("webui-port", String(config.webuiPort));
8854
8981
  } else if (config.mode === "headless") {
@@ -8959,6 +9086,6 @@ if (!process.env.VITEST) {
8959
9086
  });
8960
9087
  }
8961
9088
 
8962
- export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
9089
+ export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getBannerText, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
8963
9090
  //# sourceMappingURL=cli.js.map
8964
9091
  //# sourceMappingURL=cli.js.map