@oxog/react-check 1.2.0 → 1.3.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +142 -50
  3. package/dist/browser-inject.global.js +13 -13
  4. package/dist/chain.cjs +8 -531
  5. package/dist/chain.cjs.map +1 -1
  6. package/dist/chain.d.cts +2 -2
  7. package/dist/chain.d.ts +2 -2
  8. package/dist/chain.js +2 -533
  9. package/dist/chain.js.map +1 -1
  10. package/dist/chunk-27R56V2S.js +473 -0
  11. package/dist/chunk-27R56V2S.js.map +1 -0
  12. package/dist/chunk-3K2AER5M.cjs +356 -0
  13. package/dist/chunk-3K2AER5M.cjs.map +1 -0
  14. package/dist/chunk-7R4KKJTW.cjs +255 -0
  15. package/dist/chunk-7R4KKJTW.cjs.map +1 -0
  16. package/dist/chunk-7YYMP3PP.js +723 -0
  17. package/dist/chunk-7YYMP3PP.js.map +1 -0
  18. package/dist/chunk-DWM55ACO.cjs +294 -0
  19. package/dist/chunk-DWM55ACO.cjs.map +1 -0
  20. package/dist/chunk-G7YVIPS7.cjs +475 -0
  21. package/dist/chunk-G7YVIPS7.cjs.map +1 -0
  22. package/dist/chunk-GE2ZX7I7.cjs +727 -0
  23. package/dist/chunk-GE2ZX7I7.cjs.map +1 -0
  24. package/dist/chunk-GS7T56RP.cjs +9 -0
  25. package/dist/chunk-GS7T56RP.cjs.map +1 -0
  26. package/dist/chunk-IM6OG2IC.js +338 -0
  27. package/dist/chunk-IM6OG2IC.js.map +1 -0
  28. package/dist/chunk-RQYHXWUC.js +292 -0
  29. package/dist/chunk-RQYHXWUC.js.map +1 -0
  30. package/dist/chunk-WLN7ZVO4.js +253 -0
  31. package/dist/chunk-WLN7ZVO4.js.map +1 -0
  32. package/dist/cli.js +975 -204
  33. package/dist/cli.js.map +1 -1
  34. package/dist/detect.cjs +22 -324
  35. package/dist/detect.cjs.map +1 -1
  36. package/dist/detect.d.cts +8 -2
  37. package/dist/detect.d.ts +8 -2
  38. package/dist/detect.js +1 -324
  39. package/dist/detect.js.map +1 -1
  40. package/dist/{event-emitter-CxKUDo9q.d.cts → event-emitter-BVYUPYLd.d.cts} +3 -2
  41. package/dist/{event-emitter-CxKUDo9q.d.ts → event-emitter-BVYUPYLd.d.ts} +3 -2
  42. package/dist/fix.cjs +6 -715
  43. package/dist/fix.cjs.map +1 -1
  44. package/dist/fix.d.cts +2 -2
  45. package/dist/fix.d.ts +2 -2
  46. package/dist/fix.js +2 -719
  47. package/dist/fix.js.map +1 -1
  48. package/dist/index.cjs +1238 -2987
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +166 -50
  51. package/dist/index.d.ts +166 -50
  52. package/dist/index.js +1137 -2959
  53. package/dist/index.js.map +1 -1
  54. package/dist/{scanner-Cc2187fH.d.ts → scanner-D0mBQGTx.d.ts} +23 -3
  55. package/dist/{scanner-S7BtVIpW.d.cts → scanner-DUBgwztZ.d.cts} +23 -3
  56. package/dist/scanner.cjs +8 -1652
  57. package/dist/scanner.cjs.map +1 -1
  58. package/dist/scanner.d.cts +3 -3
  59. package/dist/scanner.d.ts +3 -3
  60. package/dist/scanner.js +4 -1656
  61. package/dist/scanner.js.map +1 -1
  62. package/dist/{types-DuZyBVVV.d.cts → types-BZ3OeZ-5.d.cts} +28 -10
  63. package/dist/{types-DuZyBVVV.d.ts → types-BZ3OeZ-5.d.ts} +28 -10
  64. package/package.json +16 -9
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { F as FiberNode, R as RenderInfo, a as ReactDevToolsHook, S as SessionReport, b as ReportOptions, C as CLIMessage, B as BrowserMessage, c as RenderChainInfo, d as ScannerConfig, W as WindowWithReactDevTools } from './types-DuZyBVVV.cjs';
2
- export { q as ComponentNode, h as ComponentStats, E as ErrorCode, t as FiberType, g as FixSuggestion, e as FixType, k as FrameworkInfo, m as FrameworkOptions, O as OverlayOptions, p as ReactCheckConfig, r as ReactCheckError, s as ReactCheckEvents, o as ReactCheckOptions, n as RuleOptions, i as SessionInfo, j as SessionSummary, f as Severity, l as ThresholdOptions, T as TimelineEvent } from './types-DuZyBVVV.cjs';
3
- import { S as Scanner } from './scanner-S7BtVIpW.cjs';
4
- export { b as ScannerEvents, a as StatsCollector, c as StatsEvents } from './scanner-S7BtVIpW.cjs';
1
+ import { F as FiberNode, R as RenderInfo, a as ReactDevToolsHook, S as SessionReport, b as ReportOptions, C as CLIMessage, B as BrowserMessage, c as RenderChainInfo, d as ScannerConfig, W as WindowWithReactDevTools } from './types-BZ3OeZ-5.cjs';
2
+ export { r as ComponentNode, h as ComponentStats, E as ErrorCode, u as FiberType, g as FixSuggestion, e as FixType, k as FrameworkInfo, m as FrameworkOptions, O as OverlayOptions, q as ReactCheckConfig, s as ReactCheckError, t as ReactCheckEvents, p as ReactCheckOptions, n as RuleLevel, o as RuleOptions, i as SessionInfo, j as SessionSummary, f as Severity, l as ThresholdOptions, T as TimelineEvent } from './types-BZ3OeZ-5.cjs';
3
+ import { S as Scanner } from './scanner-DUBgwztZ.cjs';
4
+ export { b as ScannerEvents, a as StatsCollector, c as StatsEvents } from './scanner-DUBgwztZ.cjs';
5
5
  export { ChainAnalyzer, ChainEvents } from './chain.cjs';
6
6
  export { FixEvents, FixSuggester } from './fix.cjs';
7
7
  export { detectFramework, detectFrameworkFromWindow, frameworkDetectors, getFrameworkTips } from './detect.cjs';
8
- import { E as EventEmitter } from './event-emitter-CxKUDo9q.cjs';
8
+ import { E as EventEmitter } from './event-emitter-BVYUPYLd.cjs';
9
9
  import * as node_net from 'node:net';
10
10
  import * as puppeteer from 'puppeteer';
11
11
 
@@ -626,6 +626,19 @@ declare class Logger {
626
626
  group(label: string, fn: () => void): void;
627
627
  }
628
628
 
629
+ /**
630
+ * Component name pattern matching
631
+ * @packageDocumentation
632
+ */
633
+ /**
634
+ * Match a component name against a simple glob pattern (`*` = any characters,
635
+ * `?` = one character). All other characters match literally.
636
+ * @param name - Component name
637
+ * @param pattern - Glob pattern
638
+ * @returns true if the name matches
639
+ */
640
+ declare function matchComponentPattern(name: string, pattern: string): boolean;
641
+
629
642
  /**
630
643
  * WebSocket client connection
631
644
  */
@@ -759,6 +772,12 @@ declare class WebSocketServer extends EventEmitter<WebSocketServerEvents> {
759
772
  * Stop the server
760
773
  */
761
774
  stop(): Promise<void>;
775
+ /**
776
+ * Get the port the server listens on (the real port after start() when
777
+ * constructed with port 0)
778
+ * @returns Port number
779
+ */
780
+ getPort(): number;
762
781
  /**
763
782
  * Broadcast message to all clients
764
783
  * @param message - Message to broadcast
@@ -839,18 +858,13 @@ declare class ProxyServer extends EventEmitter<ProxyServerEvents> {
839
858
  private options;
840
859
  /** Target URL parsed */
841
860
  private targetUrl;
842
- /** Injection script */
861
+ /** Injection script (loaded from the bundled browser script on start() when not provided) */
843
862
  private injectionScript;
844
863
  /**
845
864
  * Create a new proxy server
846
865
  * @param options - Proxy options
847
866
  */
848
867
  constructor(options: ProxyOptions);
849
- /**
850
- * Build the injection script
851
- * @returns Injection script string
852
- */
853
- private buildInjectionScript;
854
868
  /**
855
869
  * Handle incoming request
856
870
  * @param req - Client request
@@ -1033,6 +1047,14 @@ declare class BrowserLauncher extends EventEmitter<BrowserEvents> {
1033
1047
  */
1034
1048
  declare function isPuppeteerAvailable(): Promise<boolean>;
1035
1049
 
1050
+ /**
1051
+ * Load the browser injection script and prepend the WebSocket port setting
1052
+ * @param wsPort - Port of the CLI WebSocket server the page should connect to
1053
+ * @returns Script source ready for `evaluateOnNewDocument` or a `<script>` tag
1054
+ * @throws Error when the bundle cannot be found (broken installation)
1055
+ */
1056
+ declare function loadInjectionScript(wsPort: number): Promise<string>;
1057
+
1036
1058
  /**
1037
1059
  * Browser overlay for render visualization
1038
1060
  * @packageDocumentation
@@ -1092,6 +1114,10 @@ declare class Overlay {
1092
1114
  constructor(config?: Partial<OverlayConfig>);
1093
1115
  /** Retry count for init */
1094
1116
  private initRetryCount;
1117
+ /** Pending init retry timer (document.body not ready yet) */
1118
+ private initRetryTimer;
1119
+ /** Aborts document-level listeners (drag handling) on destroy */
1120
+ private documentListeners;
1095
1121
  /**
1096
1122
  * Initialize the overlay
1097
1123
  */
@@ -1265,8 +1291,6 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1265
1291
  private running;
1266
1292
  /** React version detected */
1267
1293
  private reactVersion;
1268
- /** Previous fiber states for comparison */
1269
- private prevFiberStates;
1270
1294
  /** Component render counts */
1271
1295
  private renderCounts;
1272
1296
  /** Original DevTools hook methods */
@@ -1333,16 +1357,14 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1333
1357
  */
1334
1358
  private detectReactVersion;
1335
1359
  /**
1336
- * Process a fiber commit (public for IIFE hook integration)
1337
- * @param rootFiber - Root fiber of the committed tree
1360
+ * Process a fiber commit (public for IIFE hook integration).
1361
+ *
1362
+ * Only components that actually rendered in this commit are reported: React
1363
+ * reuses untouched subtrees (their `child` pointer is shared with the
1364
+ * alternate) and bailed-out components do not get the `PerformedWork` flag.
1365
+ * @param rootFiber - Root fiber of the committed tree (`root.current`)
1338
1366
  */
1339
1367
  processCommit(rootFiber: FiberNode): void;
1340
- /**
1341
- * Walk the fiber tree
1342
- * @param fiber - Current fiber
1343
- * @param parent - Parent component name
1344
- */
1345
- private walkFiber;
1346
1368
  /**
1347
1369
  * Process a single fiber
1348
1370
  * @param fiber - Fiber to process
@@ -1396,8 +1418,13 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1396
1418
  }
1397
1419
 
1398
1420
  /**
1399
- * Browser injection script - main entry point for browser-side code
1400
- * This file is bundled as an IIFE for injection into target pages
1421
+ * Browser-side injector: coordinates the BrowserScanner, the Overlay and the
1422
+ * WebSocket connection to the CLI.
1423
+ *
1424
+ * This module has NO side effects when imported, so it is safe to import from
1425
+ * Node.js, SSR bundles and tests. The self-installing IIFE lives in
1426
+ * `inject.ts`, which is only built into `dist/browser-inject.global.js`.
1427
+ *
1401
1428
  * @packageDocumentation
1402
1429
  */
1403
1430
 
@@ -1417,10 +1444,33 @@ declare class ReactCheckInjector {
1417
1444
  private reconnectTimeout;
1418
1445
  /** Whether initialized */
1419
1446
  private initialized;
1447
+ /** Whether destroyed (no more reconnects, commits are ignored) */
1448
+ private destroyed;
1449
+ /** Whether commit processing is paused (CLI sent `stop`) */
1450
+ private paused;
1451
+ /** Commits received before `init()` */
1452
+ private pendingCommits;
1453
+ /** Message queue for messages sent before connection */
1454
+ private messageQueue;
1455
+ /** requestAnimationFrame handle for FPS measurement */
1456
+ private rafHandle;
1457
+ /** Restores the React DevTools hook to its state before installation */
1458
+ private restoreHook;
1459
+ /** Window reference */
1460
+ private win;
1420
1461
  /**
1421
1462
  * Create the injector
1463
+ * @param win - Window object (defaults to the global window)
1464
+ */
1465
+ constructor(win?: WindowWithReactDevTools);
1466
+ /**
1467
+ * Feed a committed fiber root to the scanner. Called from the React DevTools
1468
+ * hook installed by {@link installReactCheck}.
1469
+ * @param root - Fiber root passed to `onCommitFiberRoot`
1422
1470
  */
1423
- constructor();
1471
+ handleCommit(root: {
1472
+ current: FiberNode;
1473
+ } | null | undefined): void;
1424
1474
  /**
1425
1475
  * Initialize the injector
1426
1476
  */
@@ -1429,10 +1479,20 @@ declare class ReactCheckInjector {
1429
1479
  * Set up scanner event handlers
1430
1480
  */
1431
1481
  private setupScannerEvents;
1482
+ /**
1483
+ * Measure frames per second with requestAnimationFrame and report it
1484
+ */
1485
+ private startFpsMeasurement;
1432
1486
  /**
1433
1487
  * Connect to CLI WebSocket server
1434
1488
  */
1435
1489
  private connect;
1490
+ /**
1491
+ * Remove event handlers from a socket so that closing it does not trigger
1492
+ * reconnects
1493
+ * @param ws - Socket
1494
+ */
1495
+ private detachSocket;
1436
1496
  /**
1437
1497
  * Schedule a reconnection attempt
1438
1498
  */
@@ -1461,8 +1521,6 @@ declare class ReactCheckInjector {
1461
1521
  * @param config - New configuration
1462
1522
  */
1463
1523
  private handleConfig;
1464
- /** Message queue for messages sent before connection */
1465
- private messageQueue;
1466
1524
  /**
1467
1525
  * Send message to CLI
1468
1526
  * @param message - Browser message
@@ -1473,10 +1531,85 @@ declare class ReactCheckInjector {
1473
1531
  */
1474
1532
  private flushMessageQueue;
1475
1533
  /**
1476
- * Destroy the injector
1534
+ * Register a function that restores the DevTools hook on destroy
1535
+ * @param restore - Restore callback
1536
+ */
1537
+ setHookRestorer(restore: () => void): void;
1538
+ /**
1539
+ * Destroy the injector: stops reconnecting, closes the socket, restores the
1540
+ * React DevTools hook, removes the overlay and cancels all timers.
1477
1541
  */
1478
1542
  destroy(): void;
1479
1543
  }
1544
+ /**
1545
+ * Install ReactCheck into a page: hooks the React DevTools global hook (creating
1546
+ * it when React has not loaded yet), creates the injector and initialises it
1547
+ * once the DOM is ready. Returns `null` on internal pages or when ReactCheck is
1548
+ * already installed.
1549
+ *
1550
+ * @param win - Window object
1551
+ * @returns The injector instance, or null when nothing was installed
1552
+ */
1553
+ declare function installReactCheck(win: WindowWithReactDevTools): ReactCheckInjector | null;
1554
+
1555
+ /**
1556
+ * Package version (kept in sync with package.json; checked by tests)
1557
+ * @packageDocumentation
1558
+ */
1559
+ declare const VERSION = "1.3.0";
1560
+
1561
+ /**
1562
+ * One-call programmatic scan of a URL
1563
+ * @packageDocumentation
1564
+ */
1565
+
1566
+ /**
1567
+ * Options for {@link quickScan}
1568
+ */
1569
+ interface QuickScanOptions {
1570
+ /** How long to observe the page, in milliseconds (default: 30000) */
1571
+ duration?: number;
1572
+ /** Run the browser headless (default: true) */
1573
+ headless?: boolean;
1574
+ /** Directory to write reports to (no files are written when omitted) */
1575
+ output?: string;
1576
+ /** Report formats to write when `output` is set (default: html, json) */
1577
+ formats?: Array<'html' | 'json' | 'md'>;
1578
+ /** Render-count thresholds */
1579
+ thresholds?: {
1580
+ critical?: number;
1581
+ warning?: number;
1582
+ fps?: number;
1583
+ };
1584
+ /** Only track components matching these glob patterns */
1585
+ include?: string[];
1586
+ /** Ignore components matching these glob patterns */
1587
+ exclude?: string[];
1588
+ /** Port for the internal WebSocket server (default: a free ephemeral port) */
1589
+ port?: number;
1590
+ /** Extra Chrome arguments passed to Puppeteer */
1591
+ browserArgs?: string[];
1592
+ }
1593
+ /**
1594
+ * Quick scan a URL and generate a report. Launches Chrome through Puppeteer
1595
+ * (an optional peer dependency), injects the ReactCheck browser script, records
1596
+ * renders for `duration` milliseconds and returns the session report.
1597
+ *
1598
+ * @example
1599
+ * ```typescript
1600
+ * import { quickScan } from '@oxog/react-check';
1601
+ *
1602
+ * const report = await quickScan('http://localhost:3000', {
1603
+ * duration: 30000,
1604
+ * headless: true,
1605
+ * });
1606
+ *
1607
+ * console.log(`Found ${report.summary.criticalIssues} critical issues`);
1608
+ * ```
1609
+ * @throws ReactCheckError BROWSER_LAUNCH_FAILED when Puppeteer is missing or the
1610
+ * browser cannot start, REACT_NOT_FOUND when no React render was observed
1611
+ */
1612
+ declare function quickScan(url: string, options?: QuickScanOptions): Promise<SessionReport>;
1480
1613
 
1481
1614
  /**
1482
1615
  * ReactCheck - Zero-dependency React Performance Scanner
@@ -1486,7 +1619,6 @@ declare class ReactCheckInjector {
1486
1619
  * @packageDocumentation
1487
1620
  */
1488
1621
 
1489
- declare const VERSION = "1.0.0";
1490
1622
  /**
1491
1623
  * Create a new ReactCheck scanner instance with default options
1492
1624
  *
@@ -1509,7 +1641,12 @@ declare function createScanner(options?: {
1509
1641
  thresholds?: {
1510
1642
  critical?: number;
1511
1643
  warning?: number;
1644
+ fps?: number;
1512
1645
  };
1646
+ /** Only track components matching one of these glob patterns */
1647
+ include?: string[];
1648
+ /** Ignore components matching one of these glob patterns */
1649
+ exclude?: string[];
1513
1650
  }): Scanner;
1514
1651
  /**
1515
1652
  * Create a new report generator
@@ -1531,26 +1668,5 @@ declare function createReportGenerator(options?: {
1531
1668
  output?: string;
1532
1669
  includeSourceCode?: boolean;
1533
1670
  }): ReportGenerator;
1534
- /**
1535
- * Quick scan a URL and generate a report
1536
- *
1537
- * @example
1538
- * ```typescript
1539
- * import { quickScan } from '@oxog/react-check';
1540
- *
1541
- * const report = await quickScan('http://localhost:3000', {
1542
- * duration: 30000,
1543
- * headless: true,
1544
- * });
1545
- *
1546
- * console.log(`Found ${report.summary.criticalIssues} critical issues`);
1547
- * ```
1548
- */
1549
- declare function quickScan(url: string, options?: {
1550
- duration?: number;
1551
- headless?: boolean;
1552
- output?: string;
1553
- formats?: Array<'html' | 'json' | 'md'>;
1554
- }): Promise<SessionReport>;
1555
1671
 
1556
- export { type BrowserEvents, type BrowserLaunchOptions, BrowserLauncher, BrowserMessage, BrowserScanner, type BrowserScannerEvents, CLIMessage, EventEmitter, FiberNode, FiberTag, LogLevel, Logger, Overlay, type OverlayConfig, type ProxyOptions, ProxyServer, type ProxyServerEvents, ReactCheckInjector, ReactDevToolsHook, RenderChainInfo, RenderInfo, type ReportFormat, ReportGenerator, ReportOptions, Scanner, ScannerConfig, SessionReport, VERSION, WebSocketClient, WebSocketServer, type WebSocketServerEvents, WindowWithReactDevTools, colors, createRenderInfo, createReportGenerator, createScanner, ensureDir, escapeHtml, exists, findFiberByName, findUp, formatBytes, formatDuration, formatNumber, formatPercent, formatRenderTime, generateHTMLReport, generateJSONReport, generateMarkdownReport, generateReport, getBaseName, getChangedProps, getComponentName, getComponentPath, getDirName, getExtension, getFiberDOMNode, getOwner, getParentFiber, getReactVersion, handleBrowserMessages, isHostComponent, isMemoized, isPuppeteerAvailable, isUserComponent, joinPath, pad, parseJSONReport, quickScan, readJsonFile, readTextFile, resolvePath, saveReport, saveReports, shallowEqual, stripAnsi, supportsColor, truncate, validateJSONReport, walkFiberTree, writeJsonFile, writeTextFile };
1672
+ export { type BrowserEvents, type BrowserLaunchOptions, BrowserLauncher, BrowserMessage, BrowserScanner, type BrowserScannerEvents, CLIMessage, EventEmitter, FiberNode, FiberTag, LogLevel, Logger, Overlay, type OverlayConfig, type ProxyOptions, ProxyServer, type ProxyServerEvents, type QuickScanOptions, ReactCheckInjector, ReactDevToolsHook, RenderChainInfo, RenderInfo, type ReportFormat, ReportGenerator, ReportOptions, Scanner, ScannerConfig, SessionReport, VERSION, WebSocketClient, WebSocketServer, type WebSocketServerEvents, WindowWithReactDevTools, colors, createRenderInfo, createReportGenerator, createScanner, ensureDir, escapeHtml, exists, findFiberByName, findUp, formatBytes, formatDuration, formatNumber, formatPercent, formatRenderTime, generateHTMLReport, generateJSONReport, generateMarkdownReport, generateReport, getBaseName, getChangedProps, getComponentName, getComponentPath, getDirName, getExtension, getFiberDOMNode, getOwner, getParentFiber, getReactVersion, handleBrowserMessages, installReactCheck, isHostComponent, isMemoized, isPuppeteerAvailable, isUserComponent, joinPath, loadInjectionScript, matchComponentPattern, pad, parseJSONReport, quickScan, readJsonFile, readTextFile, resolvePath, saveReport, saveReports, shallowEqual, stripAnsi, supportsColor, truncate, validateJSONReport, walkFiberTree, writeJsonFile, writeTextFile };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { F as FiberNode, R as RenderInfo, a as ReactDevToolsHook, S as SessionReport, b as ReportOptions, C as CLIMessage, B as BrowserMessage, c as RenderChainInfo, d as ScannerConfig, W as WindowWithReactDevTools } from './types-DuZyBVVV.js';
2
- export { q as ComponentNode, h as ComponentStats, E as ErrorCode, t as FiberType, g as FixSuggestion, e as FixType, k as FrameworkInfo, m as FrameworkOptions, O as OverlayOptions, p as ReactCheckConfig, r as ReactCheckError, s as ReactCheckEvents, o as ReactCheckOptions, n as RuleOptions, i as SessionInfo, j as SessionSummary, f as Severity, l as ThresholdOptions, T as TimelineEvent } from './types-DuZyBVVV.js';
3
- import { S as Scanner } from './scanner-Cc2187fH.js';
4
- export { b as ScannerEvents, a as StatsCollector, c as StatsEvents } from './scanner-Cc2187fH.js';
1
+ import { F as FiberNode, R as RenderInfo, a as ReactDevToolsHook, S as SessionReport, b as ReportOptions, C as CLIMessage, B as BrowserMessage, c as RenderChainInfo, d as ScannerConfig, W as WindowWithReactDevTools } from './types-BZ3OeZ-5.js';
2
+ export { r as ComponentNode, h as ComponentStats, E as ErrorCode, u as FiberType, g as FixSuggestion, e as FixType, k as FrameworkInfo, m as FrameworkOptions, O as OverlayOptions, q as ReactCheckConfig, s as ReactCheckError, t as ReactCheckEvents, p as ReactCheckOptions, n as RuleLevel, o as RuleOptions, i as SessionInfo, j as SessionSummary, f as Severity, l as ThresholdOptions, T as TimelineEvent } from './types-BZ3OeZ-5.js';
3
+ import { S as Scanner } from './scanner-D0mBQGTx.js';
4
+ export { b as ScannerEvents, a as StatsCollector, c as StatsEvents } from './scanner-D0mBQGTx.js';
5
5
  export { ChainAnalyzer, ChainEvents } from './chain.js';
6
6
  export { FixEvents, FixSuggester } from './fix.js';
7
7
  export { detectFramework, detectFrameworkFromWindow, frameworkDetectors, getFrameworkTips } from './detect.js';
8
- import { E as EventEmitter } from './event-emitter-CxKUDo9q.js';
8
+ import { E as EventEmitter } from './event-emitter-BVYUPYLd.js';
9
9
  import * as node_net from 'node:net';
10
10
  import * as puppeteer from 'puppeteer';
11
11
 
@@ -626,6 +626,19 @@ declare class Logger {
626
626
  group(label: string, fn: () => void): void;
627
627
  }
628
628
 
629
+ /**
630
+ * Component name pattern matching
631
+ * @packageDocumentation
632
+ */
633
+ /**
634
+ * Match a component name against a simple glob pattern (`*` = any characters,
635
+ * `?` = one character). All other characters match literally.
636
+ * @param name - Component name
637
+ * @param pattern - Glob pattern
638
+ * @returns true if the name matches
639
+ */
640
+ declare function matchComponentPattern(name: string, pattern: string): boolean;
641
+
629
642
  /**
630
643
  * WebSocket client connection
631
644
  */
@@ -759,6 +772,12 @@ declare class WebSocketServer extends EventEmitter<WebSocketServerEvents> {
759
772
  * Stop the server
760
773
  */
761
774
  stop(): Promise<void>;
775
+ /**
776
+ * Get the port the server listens on (the real port after start() when
777
+ * constructed with port 0)
778
+ * @returns Port number
779
+ */
780
+ getPort(): number;
762
781
  /**
763
782
  * Broadcast message to all clients
764
783
  * @param message - Message to broadcast
@@ -839,18 +858,13 @@ declare class ProxyServer extends EventEmitter<ProxyServerEvents> {
839
858
  private options;
840
859
  /** Target URL parsed */
841
860
  private targetUrl;
842
- /** Injection script */
861
+ /** Injection script (loaded from the bundled browser script on start() when not provided) */
843
862
  private injectionScript;
844
863
  /**
845
864
  * Create a new proxy server
846
865
  * @param options - Proxy options
847
866
  */
848
867
  constructor(options: ProxyOptions);
849
- /**
850
- * Build the injection script
851
- * @returns Injection script string
852
- */
853
- private buildInjectionScript;
854
868
  /**
855
869
  * Handle incoming request
856
870
  * @param req - Client request
@@ -1033,6 +1047,14 @@ declare class BrowserLauncher extends EventEmitter<BrowserEvents> {
1033
1047
  */
1034
1048
  declare function isPuppeteerAvailable(): Promise<boolean>;
1035
1049
 
1050
+ /**
1051
+ * Load the browser injection script and prepend the WebSocket port setting
1052
+ * @param wsPort - Port of the CLI WebSocket server the page should connect to
1053
+ * @returns Script source ready for `evaluateOnNewDocument` or a `<script>` tag
1054
+ * @throws Error when the bundle cannot be found (broken installation)
1055
+ */
1056
+ declare function loadInjectionScript(wsPort: number): Promise<string>;
1057
+
1036
1058
  /**
1037
1059
  * Browser overlay for render visualization
1038
1060
  * @packageDocumentation
@@ -1092,6 +1114,10 @@ declare class Overlay {
1092
1114
  constructor(config?: Partial<OverlayConfig>);
1093
1115
  /** Retry count for init */
1094
1116
  private initRetryCount;
1117
+ /** Pending init retry timer (document.body not ready yet) */
1118
+ private initRetryTimer;
1119
+ /** Aborts document-level listeners (drag handling) on destroy */
1120
+ private documentListeners;
1095
1121
  /**
1096
1122
  * Initialize the overlay
1097
1123
  */
@@ -1265,8 +1291,6 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1265
1291
  private running;
1266
1292
  /** React version detected */
1267
1293
  private reactVersion;
1268
- /** Previous fiber states for comparison */
1269
- private prevFiberStates;
1270
1294
  /** Component render counts */
1271
1295
  private renderCounts;
1272
1296
  /** Original DevTools hook methods */
@@ -1333,16 +1357,14 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1333
1357
  */
1334
1358
  private detectReactVersion;
1335
1359
  /**
1336
- * Process a fiber commit (public for IIFE hook integration)
1337
- * @param rootFiber - Root fiber of the committed tree
1360
+ * Process a fiber commit (public for IIFE hook integration).
1361
+ *
1362
+ * Only components that actually rendered in this commit are reported: React
1363
+ * reuses untouched subtrees (their `child` pointer is shared with the
1364
+ * alternate) and bailed-out components do not get the `PerformedWork` flag.
1365
+ * @param rootFiber - Root fiber of the committed tree (`root.current`)
1338
1366
  */
1339
1367
  processCommit(rootFiber: FiberNode): void;
1340
- /**
1341
- * Walk the fiber tree
1342
- * @param fiber - Current fiber
1343
- * @param parent - Parent component name
1344
- */
1345
- private walkFiber;
1346
1368
  /**
1347
1369
  * Process a single fiber
1348
1370
  * @param fiber - Fiber to process
@@ -1396,8 +1418,13 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
1396
1418
  }
1397
1419
 
1398
1420
  /**
1399
- * Browser injection script - main entry point for browser-side code
1400
- * This file is bundled as an IIFE for injection into target pages
1421
+ * Browser-side injector: coordinates the BrowserScanner, the Overlay and the
1422
+ * WebSocket connection to the CLI.
1423
+ *
1424
+ * This module has NO side effects when imported, so it is safe to import from
1425
+ * Node.js, SSR bundles and tests. The self-installing IIFE lives in
1426
+ * `inject.ts`, which is only built into `dist/browser-inject.global.js`.
1427
+ *
1401
1428
  * @packageDocumentation
1402
1429
  */
1403
1430
 
@@ -1417,10 +1444,33 @@ declare class ReactCheckInjector {
1417
1444
  private reconnectTimeout;
1418
1445
  /** Whether initialized */
1419
1446
  private initialized;
1447
+ /** Whether destroyed (no more reconnects, commits are ignored) */
1448
+ private destroyed;
1449
+ /** Whether commit processing is paused (CLI sent `stop`) */
1450
+ private paused;
1451
+ /** Commits received before `init()` */
1452
+ private pendingCommits;
1453
+ /** Message queue for messages sent before connection */
1454
+ private messageQueue;
1455
+ /** requestAnimationFrame handle for FPS measurement */
1456
+ private rafHandle;
1457
+ /** Restores the React DevTools hook to its state before installation */
1458
+ private restoreHook;
1459
+ /** Window reference */
1460
+ private win;
1420
1461
  /**
1421
1462
  * Create the injector
1463
+ * @param win - Window object (defaults to the global window)
1464
+ */
1465
+ constructor(win?: WindowWithReactDevTools);
1466
+ /**
1467
+ * Feed a committed fiber root to the scanner. Called from the React DevTools
1468
+ * hook installed by {@link installReactCheck}.
1469
+ * @param root - Fiber root passed to `onCommitFiberRoot`
1422
1470
  */
1423
- constructor();
1471
+ handleCommit(root: {
1472
+ current: FiberNode;
1473
+ } | null | undefined): void;
1424
1474
  /**
1425
1475
  * Initialize the injector
1426
1476
  */
@@ -1429,10 +1479,20 @@ declare class ReactCheckInjector {
1429
1479
  * Set up scanner event handlers
1430
1480
  */
1431
1481
  private setupScannerEvents;
1482
+ /**
1483
+ * Measure frames per second with requestAnimationFrame and report it
1484
+ */
1485
+ private startFpsMeasurement;
1432
1486
  /**
1433
1487
  * Connect to CLI WebSocket server
1434
1488
  */
1435
1489
  private connect;
1490
+ /**
1491
+ * Remove event handlers from a socket so that closing it does not trigger
1492
+ * reconnects
1493
+ * @param ws - Socket
1494
+ */
1495
+ private detachSocket;
1436
1496
  /**
1437
1497
  * Schedule a reconnection attempt
1438
1498
  */
@@ -1461,8 +1521,6 @@ declare class ReactCheckInjector {
1461
1521
  * @param config - New configuration
1462
1522
  */
1463
1523
  private handleConfig;
1464
- /** Message queue for messages sent before connection */
1465
- private messageQueue;
1466
1524
  /**
1467
1525
  * Send message to CLI
1468
1526
  * @param message - Browser message
@@ -1473,10 +1531,85 @@ declare class ReactCheckInjector {
1473
1531
  */
1474
1532
  private flushMessageQueue;
1475
1533
  /**
1476
- * Destroy the injector
1534
+ * Register a function that restores the DevTools hook on destroy
1535
+ * @param restore - Restore callback
1536
+ */
1537
+ setHookRestorer(restore: () => void): void;
1538
+ /**
1539
+ * Destroy the injector: stops reconnecting, closes the socket, restores the
1540
+ * React DevTools hook, removes the overlay and cancels all timers.
1477
1541
  */
1478
1542
  destroy(): void;
1479
1543
  }
1544
+ /**
1545
+ * Install ReactCheck into a page: hooks the React DevTools global hook (creating
1546
+ * it when React has not loaded yet), creates the injector and initialises it
1547
+ * once the DOM is ready. Returns `null` on internal pages or when ReactCheck is
1548
+ * already installed.
1549
+ *
1550
+ * @param win - Window object
1551
+ * @returns The injector instance, or null when nothing was installed
1552
+ */
1553
+ declare function installReactCheck(win: WindowWithReactDevTools): ReactCheckInjector | null;
1554
+
1555
+ /**
1556
+ * Package version (kept in sync with package.json; checked by tests)
1557
+ * @packageDocumentation
1558
+ */
1559
+ declare const VERSION = "1.3.0";
1560
+
1561
+ /**
1562
+ * One-call programmatic scan of a URL
1563
+ * @packageDocumentation
1564
+ */
1565
+
1566
+ /**
1567
+ * Options for {@link quickScan}
1568
+ */
1569
+ interface QuickScanOptions {
1570
+ /** How long to observe the page, in milliseconds (default: 30000) */
1571
+ duration?: number;
1572
+ /** Run the browser headless (default: true) */
1573
+ headless?: boolean;
1574
+ /** Directory to write reports to (no files are written when omitted) */
1575
+ output?: string;
1576
+ /** Report formats to write when `output` is set (default: html, json) */
1577
+ formats?: Array<'html' | 'json' | 'md'>;
1578
+ /** Render-count thresholds */
1579
+ thresholds?: {
1580
+ critical?: number;
1581
+ warning?: number;
1582
+ fps?: number;
1583
+ };
1584
+ /** Only track components matching these glob patterns */
1585
+ include?: string[];
1586
+ /** Ignore components matching these glob patterns */
1587
+ exclude?: string[];
1588
+ /** Port for the internal WebSocket server (default: a free ephemeral port) */
1589
+ port?: number;
1590
+ /** Extra Chrome arguments passed to Puppeteer */
1591
+ browserArgs?: string[];
1592
+ }
1593
+ /**
1594
+ * Quick scan a URL and generate a report. Launches Chrome through Puppeteer
1595
+ * (an optional peer dependency), injects the ReactCheck browser script, records
1596
+ * renders for `duration` milliseconds and returns the session report.
1597
+ *
1598
+ * @example
1599
+ * ```typescript
1600
+ * import { quickScan } from '@oxog/react-check';
1601
+ *
1602
+ * const report = await quickScan('http://localhost:3000', {
1603
+ * duration: 30000,
1604
+ * headless: true,
1605
+ * });
1606
+ *
1607
+ * console.log(`Found ${report.summary.criticalIssues} critical issues`);
1608
+ * ```
1609
+ * @throws ReactCheckError BROWSER_LAUNCH_FAILED when Puppeteer is missing or the
1610
+ * browser cannot start, REACT_NOT_FOUND when no React render was observed
1611
+ */
1612
+ declare function quickScan(url: string, options?: QuickScanOptions): Promise<SessionReport>;
1480
1613
 
1481
1614
  /**
1482
1615
  * ReactCheck - Zero-dependency React Performance Scanner
@@ -1486,7 +1619,6 @@ declare class ReactCheckInjector {
1486
1619
  * @packageDocumentation
1487
1620
  */
1488
1621
 
1489
- declare const VERSION = "1.0.0";
1490
1622
  /**
1491
1623
  * Create a new ReactCheck scanner instance with default options
1492
1624
  *
@@ -1509,7 +1641,12 @@ declare function createScanner(options?: {
1509
1641
  thresholds?: {
1510
1642
  critical?: number;
1511
1643
  warning?: number;
1644
+ fps?: number;
1512
1645
  };
1646
+ /** Only track components matching one of these glob patterns */
1647
+ include?: string[];
1648
+ /** Ignore components matching one of these glob patterns */
1649
+ exclude?: string[];
1513
1650
  }): Scanner;
1514
1651
  /**
1515
1652
  * Create a new report generator
@@ -1531,26 +1668,5 @@ declare function createReportGenerator(options?: {
1531
1668
  output?: string;
1532
1669
  includeSourceCode?: boolean;
1533
1670
  }): ReportGenerator;
1534
- /**
1535
- * Quick scan a URL and generate a report
1536
- *
1537
- * @example
1538
- * ```typescript
1539
- * import { quickScan } from '@oxog/react-check';
1540
- *
1541
- * const report = await quickScan('http://localhost:3000', {
1542
- * duration: 30000,
1543
- * headless: true,
1544
- * });
1545
- *
1546
- * console.log(`Found ${report.summary.criticalIssues} critical issues`);
1547
- * ```
1548
- */
1549
- declare function quickScan(url: string, options?: {
1550
- duration?: number;
1551
- headless?: boolean;
1552
- output?: string;
1553
- formats?: Array<'html' | 'json' | 'md'>;
1554
- }): Promise<SessionReport>;
1555
1671
 
1556
- export { type BrowserEvents, type BrowserLaunchOptions, BrowserLauncher, BrowserMessage, BrowserScanner, type BrowserScannerEvents, CLIMessage, EventEmitter, FiberNode, FiberTag, LogLevel, Logger, Overlay, type OverlayConfig, type ProxyOptions, ProxyServer, type ProxyServerEvents, ReactCheckInjector, ReactDevToolsHook, RenderChainInfo, RenderInfo, type ReportFormat, ReportGenerator, ReportOptions, Scanner, ScannerConfig, SessionReport, VERSION, WebSocketClient, WebSocketServer, type WebSocketServerEvents, WindowWithReactDevTools, colors, createRenderInfo, createReportGenerator, createScanner, ensureDir, escapeHtml, exists, findFiberByName, findUp, formatBytes, formatDuration, formatNumber, formatPercent, formatRenderTime, generateHTMLReport, generateJSONReport, generateMarkdownReport, generateReport, getBaseName, getChangedProps, getComponentName, getComponentPath, getDirName, getExtension, getFiberDOMNode, getOwner, getParentFiber, getReactVersion, handleBrowserMessages, isHostComponent, isMemoized, isPuppeteerAvailable, isUserComponent, joinPath, pad, parseJSONReport, quickScan, readJsonFile, readTextFile, resolvePath, saveReport, saveReports, shallowEqual, stripAnsi, supportsColor, truncate, validateJSONReport, walkFiberTree, writeJsonFile, writeTextFile };
1672
+ export { type BrowserEvents, type BrowserLaunchOptions, BrowserLauncher, BrowserMessage, BrowserScanner, type BrowserScannerEvents, CLIMessage, EventEmitter, FiberNode, FiberTag, LogLevel, Logger, Overlay, type OverlayConfig, type ProxyOptions, ProxyServer, type ProxyServerEvents, type QuickScanOptions, ReactCheckInjector, ReactDevToolsHook, RenderChainInfo, RenderInfo, type ReportFormat, ReportGenerator, ReportOptions, Scanner, ScannerConfig, SessionReport, VERSION, WebSocketClient, WebSocketServer, type WebSocketServerEvents, WindowWithReactDevTools, colors, createRenderInfo, createReportGenerator, createScanner, ensureDir, escapeHtml, exists, findFiberByName, findUp, formatBytes, formatDuration, formatNumber, formatPercent, formatRenderTime, generateHTMLReport, generateJSONReport, generateMarkdownReport, generateReport, getBaseName, getChangedProps, getComponentName, getComponentPath, getDirName, getExtension, getFiberDOMNode, getOwner, getParentFiber, getReactVersion, handleBrowserMessages, installReactCheck, isHostComponent, isMemoized, isPuppeteerAvailable, isUserComponent, joinPath, loadInjectionScript, matchComponentPattern, pad, parseJSONReport, quickScan, readJsonFile, readTextFile, resolvePath, saveReport, saveReports, shallowEqual, stripAnsi, supportsColor, truncate, validateJSONReport, walkFiberTree, writeJsonFile, writeTextFile };