@oxog/react-check 1.0.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.
@@ -0,0 +1,474 @@
1
+ /**
2
+ * Core type definitions for ReactCheck
3
+ * @packageDocumentation
4
+ */
5
+ /**
6
+ * Information about a single component render
7
+ */
8
+ interface RenderInfo {
9
+ /** Name of the React component */
10
+ componentName: string;
11
+ /** Total number of renders for this component in the session */
12
+ renderCount: number;
13
+ /** Duration of this render in milliseconds */
14
+ renderTime: number;
15
+ /** Render phase: initial mount or update */
16
+ phase: 'mount' | 'update';
17
+ /** Whether this render was necessary (caused DOM changes) */
18
+ necessary: boolean;
19
+ /** Timestamp when render occurred */
20
+ timestamp: number;
21
+ /** Unique identifier for the component instance */
22
+ instanceId?: string;
23
+ /** Props that changed (if applicable) */
24
+ changedProps?: string[];
25
+ /** State keys that changed (if applicable) */
26
+ changedState?: string[];
27
+ }
28
+ /**
29
+ * Information about a cascade of renders (render chain)
30
+ */
31
+ interface RenderChainInfo {
32
+ /** What triggered the chain (e.g., 'UserContext.value', 'setState in App') */
33
+ trigger: string;
34
+ /** Component names in render order */
35
+ chain: string[];
36
+ /** Depth of the chain (number of components) */
37
+ depth: number;
38
+ /** Total number of renders caused by this chain */
39
+ totalRenders: number;
40
+ /** The root cause component that started the chain */
41
+ rootCause: string;
42
+ /** Timestamp when chain was detected */
43
+ timestamp: number;
44
+ /** Whether this chain was caused by a context update */
45
+ isContextTriggered: boolean;
46
+ }
47
+ /**
48
+ * Types of fixes that can be suggested
49
+ */
50
+ type FixType = 'React.memo' | 'useMemo' | 'useCallback' | 'context-split' | 'state-colocation' | 'component-extraction';
51
+ /**
52
+ * Severity levels for issues
53
+ */
54
+ type Severity = 'critical' | 'warning' | 'info';
55
+ /**
56
+ * A fix suggestion for a component
57
+ */
58
+ interface FixSuggestion {
59
+ /** Name of the component */
60
+ componentName: string;
61
+ /** Severity of the issue */
62
+ severity: Severity;
63
+ /** Description of the issue */
64
+ issue: string;
65
+ /** What caused the issue */
66
+ cause: string;
67
+ /** Type of fix recommended */
68
+ fix: FixType;
69
+ /** Code before the fix */
70
+ codeBefore: string;
71
+ /** Code after applying the fix */
72
+ codeAfter: string;
73
+ /** Explanation of why this fix works */
74
+ explanation: string;
75
+ /** Expected improvement after applying fix */
76
+ impact?: string;
77
+ }
78
+ /**
79
+ * Statistics for a single component
80
+ */
81
+ interface ComponentStats {
82
+ /** Component name */
83
+ name: string;
84
+ /** Total render count */
85
+ renders: number;
86
+ /** Expected number of renders (heuristic) */
87
+ expectedRenders: number;
88
+ /** Average render time in ms */
89
+ avgRenderTime: number;
90
+ /** Maximum render time in ms */
91
+ maxRenderTime: number;
92
+ /** Minimum render time in ms */
93
+ minRenderTime: number;
94
+ /** Total render time in ms */
95
+ totalRenderTime: number;
96
+ /** Number of unnecessary renders */
97
+ unnecessary: number;
98
+ /** Current severity level */
99
+ severity: Severity | 'healthy';
100
+ /** Render chain this component is part of */
101
+ chain: string[];
102
+ /** Suggested fixes */
103
+ fixes: FixSuggestion[];
104
+ /** First render timestamp */
105
+ firstRender: number;
106
+ /** Last render timestamp */
107
+ lastRender: number;
108
+ /** Whether props changed on last render */
109
+ propsChanged: boolean;
110
+ /** Whether state changed on last render */
111
+ stateChanged: boolean;
112
+ /** Parent component name */
113
+ parent?: string;
114
+ }
115
+ /**
116
+ * Session information
117
+ */
118
+ interface SessionInfo {
119
+ /** Target URL being scanned */
120
+ url: string;
121
+ /** Session duration in milliseconds */
122
+ duration: number;
123
+ /** Session start timestamp (ISO string) */
124
+ timestamp: string;
125
+ /** Session ID */
126
+ id: string;
127
+ }
128
+ /**
129
+ * Session summary statistics
130
+ */
131
+ interface SessionSummary {
132
+ /** Total number of unique components */
133
+ totalComponents: number;
134
+ /** Total number of renders */
135
+ totalRenders: number;
136
+ /** Number of critical issues */
137
+ criticalIssues: number;
138
+ /** Number of warnings */
139
+ warnings: number;
140
+ /** Number of healthy components */
141
+ healthy: number;
142
+ /** Average FPS during session */
143
+ avgFps: number;
144
+ /** Minimum FPS recorded */
145
+ minFps: number;
146
+ /** Total unnecessary renders */
147
+ unnecessaryRenders: number;
148
+ }
149
+ /**
150
+ * Timeline event for tracking activity
151
+ */
152
+ interface TimelineEvent {
153
+ /** Event type */
154
+ type: 'render' | 'chain' | 'fps-drop' | 'mount' | 'unmount';
155
+ /** Timestamp */
156
+ timestamp: number;
157
+ /** Event data */
158
+ data: RenderInfo | RenderChainInfo | number | string;
159
+ }
160
+ /**
161
+ * Framework detection result
162
+ */
163
+ interface FrameworkInfo {
164
+ /** Framework name */
165
+ name: 'next' | 'remix' | 'vite' | 'cra' | 'gatsby' | 'unknown';
166
+ /** Framework version */
167
+ version: string;
168
+ /** Detected features */
169
+ features: string[];
170
+ /** Framework-specific tips */
171
+ tips: string[];
172
+ }
173
+ /**
174
+ * Complete session report
175
+ */
176
+ interface SessionReport {
177
+ /** Report version */
178
+ version: string;
179
+ /** Generation timestamp (ISO string) */
180
+ generated: string;
181
+ /** Session information */
182
+ session: SessionInfo;
183
+ /** Summary statistics */
184
+ summary: SessionSummary;
185
+ /** Per-component statistics */
186
+ components: ComponentStats[];
187
+ /** Detected render chains */
188
+ chains: RenderChainInfo[];
189
+ /** Timeline of events */
190
+ timeline: TimelineEvent[];
191
+ /** Detected framework */
192
+ framework: FrameworkInfo | null;
193
+ /** All fix suggestions */
194
+ suggestions: FixSuggestion[];
195
+ }
196
+ /**
197
+ * Threshold configuration
198
+ */
199
+ interface ThresholdOptions {
200
+ /** Render count threshold for critical severity */
201
+ critical: number;
202
+ /** Render count threshold for warning severity */
203
+ warning: number;
204
+ /** FPS threshold for alerts */
205
+ fps: number;
206
+ }
207
+ /**
208
+ * Report generation options
209
+ */
210
+ interface ReportOptions {
211
+ /** Whether to generate reports */
212
+ enabled: boolean;
213
+ /** Report formats to generate */
214
+ formats: Array<'html' | 'json' | 'md'>;
215
+ /** Output directory for reports */
216
+ output: string;
217
+ /** Whether to include source code in reports */
218
+ includeSourceCode?: boolean;
219
+ }
220
+ /**
221
+ * Browser overlay options
222
+ */
223
+ interface OverlayOptions {
224
+ /** Whether overlay is enabled */
225
+ enabled: boolean;
226
+ /** Whether to highlight renders */
227
+ highlightRenders: boolean;
228
+ /** Animation speed for highlights */
229
+ animationSpeed: 'slow' | 'fast' | 'off';
230
+ /** Whether to show render count badges */
231
+ showBadges?: boolean;
232
+ /** Whether to show toolbar */
233
+ showToolbar?: boolean;
234
+ }
235
+ /**
236
+ * Framework-specific options
237
+ */
238
+ interface FrameworkOptions {
239
+ /** Auto-detect framework */
240
+ autoDetect: boolean;
241
+ /** Force specific framework */
242
+ force?: FrameworkInfo['name'];
243
+ }
244
+ /**
245
+ * Custom rule configuration
246
+ */
247
+ interface RuleOptions {
248
+ /** Rule for inline function props */
249
+ 'no-inline-functions'?: 'off' | 'warn' | 'error';
250
+ /** Rule for preferring React.memo */
251
+ 'prefer-memo'?: 'off' | 'warn' | 'error';
252
+ /** Rule for context size */
253
+ 'context-size'?: ['off' | 'warn' | 'error', {
254
+ maxConsumers: number;
255
+ }];
256
+ }
257
+ /**
258
+ * Main ReactCheck options
259
+ */
260
+ interface ReactCheckOptions {
261
+ /** Target URL to scan */
262
+ target: string;
263
+ /** Operation mode */
264
+ mode: 'browser' | 'proxy' | 'headless';
265
+ /** Enable fix suggestions */
266
+ fix: boolean;
267
+ /** Verbose output */
268
+ verbose: boolean;
269
+ /** Report options */
270
+ report: ReportOptions;
271
+ /** Enable TUI */
272
+ tui: boolean;
273
+ /** Overlay options */
274
+ overlay: OverlayOptions;
275
+ /** Threshold options */
276
+ thresholds: ThresholdOptions;
277
+ /** Framework options */
278
+ framework: FrameworkOptions;
279
+ /** WebSocket port */
280
+ port: number;
281
+ }
282
+ /**
283
+ * Configuration file format
284
+ */
285
+ interface ReactCheckConfig {
286
+ /** Extend another config file */
287
+ extends?: string;
288
+ /** Components to include (glob patterns) */
289
+ include?: string[];
290
+ /** Components to exclude */
291
+ exclude?: string[];
292
+ /** Threshold settings */
293
+ thresholds?: Partial<ThresholdOptions>;
294
+ /** Report settings */
295
+ report?: Partial<ReportOptions>;
296
+ /** Custom rules */
297
+ rules?: RuleOptions;
298
+ }
299
+ /**
300
+ * Messages sent from browser to CLI
301
+ */
302
+ type BrowserMessage = {
303
+ type: 'render';
304
+ payload: RenderInfo;
305
+ } | {
306
+ type: 'chain';
307
+ payload: RenderChainInfo;
308
+ } | {
309
+ type: 'fps';
310
+ payload: number;
311
+ } | {
312
+ type: 'component-tree';
313
+ payload: ComponentNode[];
314
+ } | {
315
+ type: 'ready';
316
+ payload: {
317
+ reactVersion: string;
318
+ };
319
+ } | {
320
+ type: 'error';
321
+ payload: {
322
+ message: string;
323
+ code: string;
324
+ };
325
+ };
326
+ /**
327
+ * Messages sent from CLI to browser
328
+ */
329
+ type CLIMessage = {
330
+ type: 'start';
331
+ } | {
332
+ type: 'stop';
333
+ } | {
334
+ type: 'reset';
335
+ } | {
336
+ type: 'config';
337
+ payload: Partial<ScannerConfig>;
338
+ } | {
339
+ type: 'highlight';
340
+ payload: {
341
+ component: string;
342
+ enabled: boolean;
343
+ };
344
+ };
345
+ /**
346
+ * Scanner configuration sent to browser
347
+ */
348
+ interface ScannerConfig {
349
+ /** Track unnecessary renders */
350
+ trackUnnecessary: boolean;
351
+ /** FPS threshold */
352
+ fpsThreshold: number;
353
+ /** Highlight renders in overlay */
354
+ highlightRenders: boolean;
355
+ /** Animation speed */
356
+ animationSpeed: 'slow' | 'fast' | 'off';
357
+ /** Components to include */
358
+ include?: string[];
359
+ /** Components to exclude */
360
+ exclude?: string[];
361
+ }
362
+ /**
363
+ * Component tree node
364
+ */
365
+ interface ComponentNode {
366
+ /** Component name */
367
+ name: string;
368
+ /** Unique ID */
369
+ id: string;
370
+ /** Children components */
371
+ children: ComponentNode[];
372
+ /** Render count */
373
+ renderCount: number;
374
+ /** Current severity */
375
+ severity: Severity | 'healthy';
376
+ }
377
+ /**
378
+ * Error codes
379
+ */
380
+ declare enum ErrorCode {
381
+ CONFIG_INVALID = "CONFIG_INVALID",
382
+ CONFIG_NOT_FOUND = "CONFIG_NOT_FOUND",
383
+ CONNECTION_FAILED = "CONNECTION_FAILED",
384
+ REACT_NOT_FOUND = "REACT_NOT_FOUND",
385
+ BROWSER_LAUNCH_FAILED = "BROWSER_LAUNCH_FAILED",
386
+ WEBSOCKET_ERROR = "WEBSOCKET_ERROR",
387
+ REPORT_WRITE_FAILED = "REPORT_WRITE_FAILED",
388
+ INVALID_URL = "INVALID_URL",
389
+ TIMEOUT = "TIMEOUT",
390
+ UNKNOWN = "UNKNOWN"
391
+ }
392
+ /**
393
+ * Custom error class for ReactCheck
394
+ */
395
+ declare class ReactCheckError extends Error {
396
+ /** Error code */
397
+ code: ErrorCode;
398
+ /** Additional error details */
399
+ details?: unknown;
400
+ constructor(code: ErrorCode, message: string, details?: unknown);
401
+ }
402
+ /**
403
+ * Event types emitted by ReactCheck
404
+ */
405
+ interface ReactCheckEvents {
406
+ /** Emitted on each render */
407
+ render: (info: RenderInfo) => void;
408
+ /** Emitted when a render chain is detected */
409
+ chain: (chain: RenderChainInfo) => void;
410
+ /** Emitted when a fix suggestion is generated */
411
+ fix: (suggestion: FixSuggestion) => void;
412
+ /** Emitted when FPS drops below threshold */
413
+ 'fps-drop': (fps: number) => void;
414
+ /** Emitted when scanner is ready */
415
+ ready: (info: {
416
+ reactVersion: string;
417
+ }) => void;
418
+ /** Emitted on error */
419
+ error: (error: ReactCheckError) => void;
420
+ /** Emitted when scanning starts */
421
+ start: () => void;
422
+ /** Emitted when scanning stops */
423
+ stop: () => void;
424
+ }
425
+ /**
426
+ * Simplified React Fiber node type
427
+ */
428
+ interface FiberNode {
429
+ tag: number;
430
+ type: FiberType;
431
+ key: string | null;
432
+ stateNode: unknown;
433
+ return: FiberNode | null;
434
+ child: FiberNode | null;
435
+ sibling: FiberNode | null;
436
+ memoizedProps: Record<string, unknown> | null;
437
+ memoizedState: unknown;
438
+ actualDuration?: number;
439
+ actualStartTime?: number;
440
+ selfBaseDuration?: number;
441
+ _debugOwner?: FiberNode | null;
442
+ }
443
+ /**
444
+ * Fiber type (function or class component)
445
+ */
446
+ type FiberType = string | (((...args: unknown[]) => unknown) & {
447
+ name?: string;
448
+ displayName?: string;
449
+ }) | {
450
+ name?: string;
451
+ displayName?: string;
452
+ } | null;
453
+ /**
454
+ * React DevTools global hook interface
455
+ */
456
+ interface ReactDevToolsHook {
457
+ renderers: Map<number, unknown>;
458
+ supportsFiber: boolean;
459
+ inject: (renderer: unknown) => number;
460
+ onCommitFiberRoot: (rendererID: number, root: {
461
+ current: FiberNode;
462
+ }, priorityLevel: unknown) => void;
463
+ onCommitFiberUnmount: (rendererID: number, fiber: FiberNode) => void;
464
+ }
465
+ /**
466
+ * Window with React DevTools hook
467
+ */
468
+ interface WindowWithReactDevTools extends Window {
469
+ __REACT_DEVTOOLS_GLOBAL_HOOK__?: ReactDevToolsHook;
470
+ __REACTCHECK_INJECTED__?: boolean;
471
+ __REACTCHECK_PORT__?: number;
472
+ }
473
+
474
+ export { type BrowserMessage as B, type CLIMessage as C, ErrorCode as E, type FiberNode as F, type OverlayOptions as O, type RenderInfo as R, type SessionReport as S, type TimelineEvent as T, type WindowWithReactDevTools as W, type ReactDevToolsHook as a, type ReportOptions as b, type ScannerConfig as c, type RenderChainInfo as d, type FixType as e, type Severity as f, type FixSuggestion as g, type ComponentStats as h, type SessionInfo as i, type SessionSummary as j, type FrameworkInfo as k, type ThresholdOptions as l, type FrameworkOptions as m, type RuleOptions as n, type ReactCheckOptions as o, type ReactCheckConfig as p, type ComponentNode as q, ReactCheckError as r, type ReactCheckEvents as s, type FiberType as t };