@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.
- package/CHANGELOG.md +86 -0
- package/README.md +142 -50
- package/dist/browser-inject.global.js +13 -13
- package/dist/chain.cjs +8 -531
- package/dist/chain.cjs.map +1 -1
- package/dist/chain.d.cts +2 -2
- package/dist/chain.d.ts +2 -2
- package/dist/chain.js +2 -533
- package/dist/chain.js.map +1 -1
- package/dist/chunk-27R56V2S.js +473 -0
- package/dist/chunk-27R56V2S.js.map +1 -0
- package/dist/chunk-3K2AER5M.cjs +356 -0
- package/dist/chunk-3K2AER5M.cjs.map +1 -0
- package/dist/chunk-7R4KKJTW.cjs +255 -0
- package/dist/chunk-7R4KKJTW.cjs.map +1 -0
- package/dist/chunk-7YYMP3PP.js +723 -0
- package/dist/chunk-7YYMP3PP.js.map +1 -0
- package/dist/chunk-DWM55ACO.cjs +294 -0
- package/dist/chunk-DWM55ACO.cjs.map +1 -0
- package/dist/chunk-G7YVIPS7.cjs +475 -0
- package/dist/chunk-G7YVIPS7.cjs.map +1 -0
- package/dist/chunk-GE2ZX7I7.cjs +727 -0
- package/dist/chunk-GE2ZX7I7.cjs.map +1 -0
- package/dist/chunk-GS7T56RP.cjs +9 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -0
- package/dist/chunk-IM6OG2IC.js +338 -0
- package/dist/chunk-IM6OG2IC.js.map +1 -0
- package/dist/chunk-RQYHXWUC.js +292 -0
- package/dist/chunk-RQYHXWUC.js.map +1 -0
- package/dist/chunk-WLN7ZVO4.js +253 -0
- package/dist/chunk-WLN7ZVO4.js.map +1 -0
- package/dist/cli.js +975 -204
- package/dist/cli.js.map +1 -1
- package/dist/detect.cjs +22 -324
- package/dist/detect.cjs.map +1 -1
- package/dist/detect.d.cts +8 -2
- package/dist/detect.d.ts +8 -2
- package/dist/detect.js +1 -324
- package/dist/detect.js.map +1 -1
- package/dist/{event-emitter-CxKUDo9q.d.cts → event-emitter-BVYUPYLd.d.cts} +3 -2
- package/dist/{event-emitter-CxKUDo9q.d.ts → event-emitter-BVYUPYLd.d.ts} +3 -2
- package/dist/fix.cjs +6 -715
- package/dist/fix.cjs.map +1 -1
- package/dist/fix.d.cts +2 -2
- package/dist/fix.d.ts +2 -2
- package/dist/fix.js +2 -719
- package/dist/fix.js.map +1 -1
- package/dist/index.cjs +1238 -2987
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +166 -50
- package/dist/index.d.ts +166 -50
- package/dist/index.js +1137 -2959
- package/dist/index.js.map +1 -1
- package/dist/{scanner-Cc2187fH.d.ts → scanner-D0mBQGTx.d.ts} +23 -3
- package/dist/{scanner-S7BtVIpW.d.cts → scanner-DUBgwztZ.d.cts} +23 -3
- package/dist/scanner.cjs +8 -1652
- package/dist/scanner.cjs.map +1 -1
- package/dist/scanner.d.cts +3 -3
- package/dist/scanner.d.ts +3 -3
- package/dist/scanner.js +4 -1656
- package/dist/scanner.js.map +1 -1
- package/dist/{types-DuZyBVVV.d.cts → types-BZ3OeZ-5.d.cts} +28 -10
- package/dist/{types-DuZyBVVV.d.ts → types-BZ3OeZ-5.d.ts} +28 -10
- package/package.json +16 -9
package/dist/index.cjs
CHANGED
|
@@ -1,2354 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkGE2ZX7I7_cjs = require('./chunk-GE2ZX7I7.cjs');
|
|
4
|
+
var chunkDWM55ACO_cjs = require('./chunk-DWM55ACO.cjs');
|
|
5
|
+
var chunkG7YVIPS7_cjs = require('./chunk-G7YVIPS7.cjs');
|
|
6
|
+
var chunk7R4KKJTW_cjs = require('./chunk-7R4KKJTW.cjs');
|
|
7
|
+
var chunk3K2AER5M_cjs = require('./chunk-3K2AER5M.cjs');
|
|
8
|
+
var chunkGS7T56RP_cjs = require('./chunk-GS7T56RP.cjs');
|
|
6
9
|
var http = require('http');
|
|
7
10
|
var crypto = require('crypto');
|
|
8
11
|
var https = require('https');
|
|
9
12
|
var url = require('url');
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __esm = (fn, res) => function __init() {
|
|
14
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
-
};
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// src/utils/event-emitter.ts
|
|
22
|
-
exports.EventEmitter = void 0;
|
|
23
|
-
var init_event_emitter = __esm({
|
|
24
|
-
"src/utils/event-emitter.ts"() {
|
|
25
|
-
exports.EventEmitter = class {
|
|
26
|
-
/** Map of event names to their listeners */
|
|
27
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
28
|
-
/** Map of event names to their one-time listeners */
|
|
29
|
-
_onceListeners = /* @__PURE__ */ new Map();
|
|
30
|
-
/** Maximum number of listeners per event (0 = unlimited) */
|
|
31
|
-
maxListeners = 0;
|
|
32
|
-
/**
|
|
33
|
-
* Add an event listener
|
|
34
|
-
* @param event - Event name
|
|
35
|
-
* @param listener - Callback function
|
|
36
|
-
* @returns this for chaining
|
|
37
|
-
*/
|
|
38
|
-
on(event, listener) {
|
|
39
|
-
let eventListeners = this._listeners.get(event);
|
|
40
|
-
if (!eventListeners) {
|
|
41
|
-
eventListeners = /* @__PURE__ */ new Set();
|
|
42
|
-
this._listeners.set(event, eventListeners);
|
|
43
|
-
}
|
|
44
|
-
if (this.maxListeners > 0 && eventListeners.size >= this.maxListeners) {
|
|
45
|
-
console.warn(
|
|
46
|
-
`Warning: Possible EventEmitter memory leak detected. ${eventListeners.size + 1} listeners added for event "${String(event)}". Use setMaxListeners() to increase limit.`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
eventListeners.add(listener);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Alias for on()
|
|
54
|
-
*/
|
|
55
|
-
addListener(event, listener) {
|
|
56
|
-
return this.on(event, listener);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Add a one-time event listener
|
|
60
|
-
* @param event - Event name
|
|
61
|
-
* @param listener - Callback function
|
|
62
|
-
* @returns this for chaining
|
|
63
|
-
*/
|
|
64
|
-
once(event, listener) {
|
|
65
|
-
let eventListeners = this._onceListeners.get(event);
|
|
66
|
-
if (!eventListeners) {
|
|
67
|
-
eventListeners = /* @__PURE__ */ new Set();
|
|
68
|
-
this._onceListeners.set(event, eventListeners);
|
|
69
|
-
}
|
|
70
|
-
eventListeners.add(listener);
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Remove an event listener
|
|
75
|
-
* @param event - Event name
|
|
76
|
-
* @param listener - Callback function to remove
|
|
77
|
-
* @returns this for chaining
|
|
78
|
-
*/
|
|
79
|
-
off(event, listener) {
|
|
80
|
-
const eventListeners = this._listeners.get(event);
|
|
81
|
-
if (eventListeners) {
|
|
82
|
-
eventListeners.delete(listener);
|
|
83
|
-
if (eventListeners.size === 0) {
|
|
84
|
-
this._listeners.delete(event);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const onceEventListeners = this._onceListeners.get(event);
|
|
88
|
-
if (onceEventListeners) {
|
|
89
|
-
onceEventListeners.delete(listener);
|
|
90
|
-
if (onceEventListeners.size === 0) {
|
|
91
|
-
this._onceListeners.delete(event);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Alias for off()
|
|
98
|
-
*/
|
|
99
|
-
removeListener(event, listener) {
|
|
100
|
-
return this.off(event, listener);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Remove all listeners for an event, or all events if no event specified
|
|
104
|
-
* @param event - Optional event name
|
|
105
|
-
* @returns this for chaining
|
|
106
|
-
*/
|
|
107
|
-
removeAllListeners(event) {
|
|
108
|
-
if (event !== void 0) {
|
|
109
|
-
this._listeners.delete(event);
|
|
110
|
-
this._onceListeners.delete(event);
|
|
111
|
-
} else {
|
|
112
|
-
this._listeners.clear();
|
|
113
|
-
this._onceListeners.clear();
|
|
114
|
-
}
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Emit an event
|
|
119
|
-
* @param event - Event name
|
|
120
|
-
* @param data - Event data
|
|
121
|
-
* @returns true if any listeners were called
|
|
122
|
-
*/
|
|
123
|
-
emit(event, data) {
|
|
124
|
-
let called = false;
|
|
125
|
-
const eventListeners = this._listeners.get(event);
|
|
126
|
-
if (eventListeners) {
|
|
127
|
-
for (const listener of eventListeners) {
|
|
128
|
-
try {
|
|
129
|
-
listener(data);
|
|
130
|
-
called = true;
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (event !== "error") {
|
|
133
|
-
this.emit("error", error);
|
|
134
|
-
} else {
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const onceEventListeners = this._onceListeners.get(event);
|
|
141
|
-
if (onceEventListeners) {
|
|
142
|
-
const listenersToCall = Array.from(onceEventListeners);
|
|
143
|
-
this._onceListeners.delete(event);
|
|
144
|
-
for (const listener of listenersToCall) {
|
|
145
|
-
try {
|
|
146
|
-
listener(data);
|
|
147
|
-
called = true;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (event !== "error") {
|
|
150
|
-
this.emit("error", error);
|
|
151
|
-
} else {
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return called;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get all listener functions for an event
|
|
161
|
-
* @param event - Event name
|
|
162
|
-
* @returns Array of listener functions
|
|
163
|
-
*/
|
|
164
|
-
getListeners(event) {
|
|
165
|
-
const regular = this._listeners.get(event);
|
|
166
|
-
const once = this._onceListeners.get(event);
|
|
167
|
-
const result = [];
|
|
168
|
-
if (regular) {
|
|
169
|
-
result.push(...Array.from(regular));
|
|
170
|
-
}
|
|
171
|
-
if (once) {
|
|
172
|
-
result.push(...Array.from(once));
|
|
173
|
-
}
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Get the number of listeners for an event
|
|
178
|
-
* @param event - Event name
|
|
179
|
-
* @returns Number of listeners
|
|
180
|
-
*/
|
|
181
|
-
listenerCount(event) {
|
|
182
|
-
const regular = this._listeners.get(event)?.size ?? 0;
|
|
183
|
-
const once = this._onceListeners.get(event)?.size ?? 0;
|
|
184
|
-
return regular + once;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Get all event names that have listeners
|
|
188
|
-
* @returns Array of event names
|
|
189
|
-
*/
|
|
190
|
-
eventNames() {
|
|
191
|
-
const names = /* @__PURE__ */ new Set();
|
|
192
|
-
for (const name of this._listeners.keys()) {
|
|
193
|
-
names.add(name);
|
|
194
|
-
}
|
|
195
|
-
for (const name of this._onceListeners.keys()) {
|
|
196
|
-
names.add(name);
|
|
197
|
-
}
|
|
198
|
-
return Array.from(names);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Set the maximum number of listeners per event
|
|
202
|
-
* @param n - Maximum listeners (0 for unlimited)
|
|
203
|
-
* @returns this for chaining
|
|
204
|
-
*/
|
|
205
|
-
setMaxListeners(n) {
|
|
206
|
-
this.maxListeners = n;
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get the maximum number of listeners per event
|
|
211
|
-
* @returns Maximum listeners
|
|
212
|
-
*/
|
|
213
|
-
getMaxListeners() {
|
|
214
|
-
return this.maxListeners;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Prepend a listener to the beginning of the listeners array
|
|
218
|
-
* @param event - Event name
|
|
219
|
-
* @param listener - Callback function
|
|
220
|
-
* @returns this for chaining
|
|
221
|
-
*/
|
|
222
|
-
prependListener(event, listener) {
|
|
223
|
-
const eventListeners = this._listeners.get(event);
|
|
224
|
-
if (!eventListeners) {
|
|
225
|
-
return this.on(event, listener);
|
|
226
|
-
}
|
|
227
|
-
const arr = Array.from(eventListeners);
|
|
228
|
-
arr.unshift(listener);
|
|
229
|
-
this._listeners.set(event, new Set(arr));
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Prepend a one-time listener to the beginning
|
|
234
|
-
* @param event - Event name
|
|
235
|
-
* @param listener - Callback function
|
|
236
|
-
* @returns this for chaining
|
|
237
|
-
*/
|
|
238
|
-
prependOnceListener(event, listener) {
|
|
239
|
-
const eventListeners = this._onceListeners.get(event);
|
|
240
|
-
if (!eventListeners) {
|
|
241
|
-
return this.once(event, listener);
|
|
242
|
-
}
|
|
243
|
-
const arr = Array.from(eventListeners);
|
|
244
|
-
arr.unshift(listener);
|
|
245
|
-
this._onceListeners.set(event, new Set(arr));
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Wait for an event to be emitted
|
|
250
|
-
* @param event - Event name
|
|
251
|
-
* @param timeout - Optional timeout in milliseconds
|
|
252
|
-
* @returns Promise that resolves with the event data
|
|
253
|
-
*/
|
|
254
|
-
waitFor(event, timeout) {
|
|
255
|
-
return new Promise((resolve2, reject) => {
|
|
256
|
-
let timeoutId;
|
|
257
|
-
const listener = (data) => {
|
|
258
|
-
if (timeoutId) {
|
|
259
|
-
clearTimeout(timeoutId);
|
|
260
|
-
}
|
|
261
|
-
resolve2(data);
|
|
262
|
-
};
|
|
263
|
-
this.once(event, listener);
|
|
264
|
-
if (timeout !== void 0 && timeout > 0) {
|
|
265
|
-
timeoutId = setTimeout(() => {
|
|
266
|
-
this.off(event, listener);
|
|
267
|
-
reject(new Error(`Timeout waiting for event "${String(event)}"`));
|
|
268
|
-
}, timeout);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// src/utils/colors.ts
|
|
277
|
-
function checkColorSupport() {
|
|
278
|
-
if (process.env["FORCE_COLOR"] !== void 0) {
|
|
279
|
-
return process.env["FORCE_COLOR"] !== "0";
|
|
280
|
-
}
|
|
281
|
-
if (process.env["NO_COLOR"] !== void 0) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
if (!process.stdout.isTTY) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
if (process.env["TERM"] === "dumb") {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
if (process.env["CI"] !== void 0) {
|
|
291
|
-
const ciEnvs = ["TRAVIS", "CIRCLECI", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE"];
|
|
292
|
-
return ciEnvs.some((env) => process.env[env] !== void 0);
|
|
293
|
-
}
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
function colorize(text, ...codes) {
|
|
297
|
-
if (!exports.supportsColor || codes.length === 0) {
|
|
298
|
-
return text;
|
|
299
|
-
}
|
|
300
|
-
return codes.join("") + text + exports.colors.reset;
|
|
301
|
-
}
|
|
302
|
-
function createColorizer(code) {
|
|
303
|
-
return (text) => colorize(text, code);
|
|
304
|
-
}
|
|
305
|
-
function stripAnsi(text) {
|
|
306
|
-
return text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
307
|
-
}
|
|
308
|
-
exports.supportsColor = void 0; exports.colors = void 0; var semantic;
|
|
309
|
-
var init_colors = __esm({
|
|
310
|
-
"src/utils/colors.ts"() {
|
|
311
|
-
exports.supportsColor = checkColorSupport();
|
|
312
|
-
exports.colors = {
|
|
313
|
-
// Reset
|
|
314
|
-
reset: exports.supportsColor ? "\x1B[0m" : "",
|
|
315
|
-
// Text styles
|
|
316
|
-
bold: exports.supportsColor ? "\x1B[1m" : "",
|
|
317
|
-
dim: exports.supportsColor ? "\x1B[2m" : "",
|
|
318
|
-
italic: exports.supportsColor ? "\x1B[3m" : "",
|
|
319
|
-
underline: exports.supportsColor ? "\x1B[4m" : "",
|
|
320
|
-
blink: exports.supportsColor ? "\x1B[5m" : "",
|
|
321
|
-
inverse: exports.supportsColor ? "\x1B[7m" : "",
|
|
322
|
-
hidden: exports.supportsColor ? "\x1B[8m" : "",
|
|
323
|
-
strikethrough: exports.supportsColor ? "\x1B[9m" : "",
|
|
324
|
-
// Foreground colors
|
|
325
|
-
black: exports.supportsColor ? "\x1B[30m" : "",
|
|
326
|
-
red: exports.supportsColor ? "\x1B[31m" : "",
|
|
327
|
-
green: exports.supportsColor ? "\x1B[32m" : "",
|
|
328
|
-
yellow: exports.supportsColor ? "\x1B[33m" : "",
|
|
329
|
-
blue: exports.supportsColor ? "\x1B[34m" : "",
|
|
330
|
-
magenta: exports.supportsColor ? "\x1B[35m" : "",
|
|
331
|
-
cyan: exports.supportsColor ? "\x1B[36m" : "",
|
|
332
|
-
white: exports.supportsColor ? "\x1B[37m" : "",
|
|
333
|
-
gray: exports.supportsColor ? "\x1B[90m" : "",
|
|
334
|
-
grey: exports.supportsColor ? "\x1B[90m" : "",
|
|
335
|
-
// Bright foreground colors
|
|
336
|
-
brightRed: exports.supportsColor ? "\x1B[91m" : "",
|
|
337
|
-
brightGreen: exports.supportsColor ? "\x1B[92m" : "",
|
|
338
|
-
brightYellow: exports.supportsColor ? "\x1B[93m" : "",
|
|
339
|
-
brightBlue: exports.supportsColor ? "\x1B[94m" : "",
|
|
340
|
-
brightMagenta: exports.supportsColor ? "\x1B[95m" : "",
|
|
341
|
-
brightCyan: exports.supportsColor ? "\x1B[96m" : "",
|
|
342
|
-
brightWhite: exports.supportsColor ? "\x1B[97m" : "",
|
|
343
|
-
// Background colors
|
|
344
|
-
bgBlack: exports.supportsColor ? "\x1B[40m" : "",
|
|
345
|
-
bgRed: exports.supportsColor ? "\x1B[41m" : "",
|
|
346
|
-
bgGreen: exports.supportsColor ? "\x1B[42m" : "",
|
|
347
|
-
bgYellow: exports.supportsColor ? "\x1B[43m" : "",
|
|
348
|
-
bgBlue: exports.supportsColor ? "\x1B[44m" : "",
|
|
349
|
-
bgMagenta: exports.supportsColor ? "\x1B[45m" : "",
|
|
350
|
-
bgCyan: exports.supportsColor ? "\x1B[46m" : "",
|
|
351
|
-
bgWhite: exports.supportsColor ? "\x1B[47m" : "",
|
|
352
|
-
bgGray: exports.supportsColor ? "\x1B[100m" : "",
|
|
353
|
-
// Bright background colors
|
|
354
|
-
bgBrightRed: exports.supportsColor ? "\x1B[101m" : "",
|
|
355
|
-
bgBrightGreen: exports.supportsColor ? "\x1B[102m" : "",
|
|
356
|
-
bgBrightYellow: exports.supportsColor ? "\x1B[103m" : "",
|
|
357
|
-
bgBrightBlue: exports.supportsColor ? "\x1B[104m" : "",
|
|
358
|
-
bgBrightMagenta: exports.supportsColor ? "\x1B[105m" : "",
|
|
359
|
-
bgBrightCyan: exports.supportsColor ? "\x1B[106m" : "",
|
|
360
|
-
bgBrightWhite: exports.supportsColor ? "\x1B[107m" : ""
|
|
361
|
-
};
|
|
362
|
-
semantic = {
|
|
363
|
-
/** Critical issues (red) */
|
|
364
|
-
critical: createColorizer(exports.colors.red),
|
|
365
|
-
/** Warnings (yellow) */
|
|
366
|
-
warning: createColorizer(exports.colors.yellow),
|
|
367
|
-
/** Healthy/success (green) */
|
|
368
|
-
healthy: createColorizer(exports.colors.green),
|
|
369
|
-
/** Info/links (blue) */
|
|
370
|
-
info: createColorizer(exports.colors.blue),
|
|
371
|
-
/** Secondary text (gray) */
|
|
372
|
-
secondary: createColorizer(exports.colors.gray),
|
|
373
|
-
/** Highlighted text (cyan) */
|
|
374
|
-
highlight: createColorizer(exports.colors.cyan),
|
|
375
|
-
/** Error text (bright red, bold) */
|
|
376
|
-
error: (text) => colorize(text, exports.colors.brightRed, exports.colors.bold),
|
|
377
|
-
/** Success text (bright green, bold) */
|
|
378
|
-
success: (text) => colorize(text, exports.colors.brightGreen, exports.colors.bold),
|
|
379
|
-
/** Title text (bold) */
|
|
380
|
-
title: createColorizer(exports.colors.bold),
|
|
381
|
-
/** Dimmed text */
|
|
382
|
-
dimmed: createColorizer(exports.colors.dim)
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// src/utils/logger.ts
|
|
388
|
-
exports.LogLevel = void 0; var LOG_LEVEL_NAMES; exports.Logger = void 0;
|
|
389
|
-
var init_logger = __esm({
|
|
390
|
-
"src/utils/logger.ts"() {
|
|
391
|
-
init_colors();
|
|
392
|
-
exports.LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
393
|
-
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
394
|
-
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
395
|
-
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
396
|
-
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
397
|
-
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
398
|
-
return LogLevel2;
|
|
399
|
-
})(exports.LogLevel || {});
|
|
400
|
-
LOG_LEVEL_NAMES = {
|
|
401
|
-
[0 /* DEBUG */]: "DEBUG",
|
|
402
|
-
[1 /* INFO */]: "INFO",
|
|
403
|
-
[2 /* WARN */]: "WARN",
|
|
404
|
-
[3 /* ERROR */]: "ERROR",
|
|
405
|
-
[4 /* SILENT */]: "SILENT"
|
|
406
|
-
};
|
|
407
|
-
exports.Logger = class _Logger {
|
|
408
|
-
prefix;
|
|
409
|
-
level;
|
|
410
|
-
showTimestamp;
|
|
411
|
-
showLevel;
|
|
412
|
-
output;
|
|
413
|
-
/**
|
|
414
|
-
* Create a new Logger instance
|
|
415
|
-
* @param options - Logger configuration
|
|
416
|
-
*/
|
|
417
|
-
constructor(options = {}) {
|
|
418
|
-
this.prefix = options.prefix ?? "";
|
|
419
|
-
this.level = options.level ?? 1 /* INFO */;
|
|
420
|
-
this.showTimestamp = options.showTimestamp ?? false;
|
|
421
|
-
this.showLevel = options.showLevel ?? true;
|
|
422
|
-
this.output = options.output ?? {
|
|
423
|
-
/* eslint-disable no-console */
|
|
424
|
-
log: (msg) => console.log(msg),
|
|
425
|
-
warn: (msg) => console.warn(msg),
|
|
426
|
-
error: (msg) => console.error(msg)
|
|
427
|
-
/* eslint-enable no-console */
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Format a log message
|
|
432
|
-
* @param level - Log level
|
|
433
|
-
* @param message - Message to format
|
|
434
|
-
* @returns Formatted message
|
|
435
|
-
*/
|
|
436
|
-
format(level, message) {
|
|
437
|
-
const parts = [];
|
|
438
|
-
if (this.showTimestamp) {
|
|
439
|
-
const now = /* @__PURE__ */ new Date();
|
|
440
|
-
const time = now.toISOString().slice(11, 23);
|
|
441
|
-
parts.push(semantic.secondary(`[${time}]`));
|
|
442
|
-
}
|
|
443
|
-
if (this.showLevel) {
|
|
444
|
-
const levelName = LOG_LEVEL_NAMES[level] ?? "UNKNOWN";
|
|
445
|
-
let levelStr;
|
|
446
|
-
switch (level) {
|
|
447
|
-
case 0 /* DEBUG */:
|
|
448
|
-
levelStr = semantic.secondary(levelName);
|
|
449
|
-
break;
|
|
450
|
-
case 1 /* INFO */:
|
|
451
|
-
levelStr = semantic.info(levelName);
|
|
452
|
-
break;
|
|
453
|
-
case 2 /* WARN */:
|
|
454
|
-
levelStr = semantic.warning(levelName);
|
|
455
|
-
break;
|
|
456
|
-
case 3 /* ERROR */:
|
|
457
|
-
levelStr = semantic.error(levelName);
|
|
458
|
-
break;
|
|
459
|
-
default:
|
|
460
|
-
levelStr = levelName;
|
|
461
|
-
}
|
|
462
|
-
parts.push(`[${levelStr}]`);
|
|
463
|
-
}
|
|
464
|
-
if (this.prefix) {
|
|
465
|
-
parts.push(semantic.highlight(`[${this.prefix}]`));
|
|
466
|
-
}
|
|
467
|
-
parts.push(message);
|
|
468
|
-
return parts.join(" ");
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Log a debug message
|
|
472
|
-
* @param message - Message to log
|
|
473
|
-
* @param args - Additional arguments to log
|
|
474
|
-
*/
|
|
475
|
-
debug(message, ...args) {
|
|
476
|
-
if (this.level > 0 /* DEBUG */) return;
|
|
477
|
-
const formatted = this.format(0 /* DEBUG */, message);
|
|
478
|
-
if (args.length > 0) {
|
|
479
|
-
this.output.log(formatted + " " + args.map(String).join(" "));
|
|
480
|
-
} else {
|
|
481
|
-
this.output.log(formatted);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Log an info message
|
|
486
|
-
* @param message - Message to log
|
|
487
|
-
* @param args - Additional arguments to log
|
|
488
|
-
*/
|
|
489
|
-
info(message, ...args) {
|
|
490
|
-
if (this.level > 1 /* INFO */) return;
|
|
491
|
-
const formatted = this.format(1 /* INFO */, message);
|
|
492
|
-
if (args.length > 0) {
|
|
493
|
-
this.output.log(formatted + " " + args.map(String).join(" "));
|
|
494
|
-
} else {
|
|
495
|
-
this.output.log(formatted);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Log a warning message
|
|
500
|
-
* @param message - Message to log
|
|
501
|
-
* @param args - Additional arguments to log
|
|
502
|
-
*/
|
|
503
|
-
warn(message, ...args) {
|
|
504
|
-
if (this.level > 2 /* WARN */) return;
|
|
505
|
-
const formatted = this.format(2 /* WARN */, message);
|
|
506
|
-
if (args.length > 0) {
|
|
507
|
-
this.output.warn(formatted + " " + args.map(String).join(" "));
|
|
508
|
-
} else {
|
|
509
|
-
this.output.warn(formatted);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Log an error message
|
|
514
|
-
* @param message - Message to log
|
|
515
|
-
* @param args - Additional arguments to log
|
|
516
|
-
*/
|
|
517
|
-
error(message, ...args) {
|
|
518
|
-
if (this.level > 3 /* ERROR */) return;
|
|
519
|
-
const formatted = this.format(3 /* ERROR */, message);
|
|
520
|
-
if (args.length > 0) {
|
|
521
|
-
this.output.error(formatted + " " + args.map(String).join(" "));
|
|
522
|
-
} else {
|
|
523
|
-
this.output.error(formatted);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Log a success message (always shown unless silent)
|
|
528
|
-
* @param message - Message to log
|
|
529
|
-
*/
|
|
530
|
-
success(message) {
|
|
531
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
532
|
-
const prefix = this.prefix ? `[${semantic.highlight(this.prefix)}] ` : "";
|
|
533
|
-
this.output.log(prefix + semantic.success("\u2713 ") + message);
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Log a failure message (always shown unless silent)
|
|
537
|
-
* @param message - Message to log
|
|
538
|
-
*/
|
|
539
|
-
fail(message) {
|
|
540
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
541
|
-
const prefix = this.prefix ? `[${semantic.highlight(this.prefix)}] ` : "";
|
|
542
|
-
this.output.error(prefix + semantic.error("\u2717 ") + message);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Create a child logger with a sub-prefix
|
|
546
|
-
* @param prefix - Sub-prefix for the child logger
|
|
547
|
-
* @returns New Logger instance
|
|
548
|
-
*/
|
|
549
|
-
child(prefix) {
|
|
550
|
-
const childPrefix = this.prefix ? `${this.prefix}:${prefix}` : prefix;
|
|
551
|
-
return new _Logger({
|
|
552
|
-
prefix: childPrefix,
|
|
553
|
-
level: this.level,
|
|
554
|
-
showTimestamp: this.showTimestamp,
|
|
555
|
-
showLevel: this.showLevel,
|
|
556
|
-
output: this.output
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Set the log level
|
|
561
|
-
* @param level - New log level
|
|
562
|
-
*/
|
|
563
|
-
setLevel(level) {
|
|
564
|
-
this.level = level;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Get the current log level
|
|
568
|
-
* @returns Current log level
|
|
569
|
-
*/
|
|
570
|
-
getLevel() {
|
|
571
|
-
return this.level;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Check if a log level is enabled
|
|
575
|
-
* @param level - Level to check
|
|
576
|
-
* @returns true if the level would be logged
|
|
577
|
-
*/
|
|
578
|
-
isLevelEnabled(level) {
|
|
579
|
-
return this.level <= level;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Create a timer for performance logging
|
|
583
|
-
* @param label - Timer label
|
|
584
|
-
* @returns Object with end() method to log duration
|
|
585
|
-
*/
|
|
586
|
-
time(label) {
|
|
587
|
-
const start = performance.now();
|
|
588
|
-
return {
|
|
589
|
-
end: () => {
|
|
590
|
-
const duration = performance.now() - start;
|
|
591
|
-
this.debug(`${label}: ${duration.toFixed(2)}ms`);
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Log a table of data
|
|
597
|
-
* @param data - Array of objects to display
|
|
598
|
-
* @param columns - Optional column names to show
|
|
599
|
-
*/
|
|
600
|
-
table(data, columns) {
|
|
601
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
602
|
-
if (data.length === 0) {
|
|
603
|
-
this.info("(empty table)");
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
const cols = columns ?? Object.keys(data[0] ?? {});
|
|
607
|
-
if (cols.length === 0) {
|
|
608
|
-
this.info("(no columns)");
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
const widths = {};
|
|
612
|
-
for (const col of cols) {
|
|
613
|
-
widths[col] = col.length;
|
|
614
|
-
for (const row of data) {
|
|
615
|
-
const value = String(row[col] ?? "");
|
|
616
|
-
widths[col] = Math.max(widths[col] ?? 0, value.length);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
const header = cols.map((col) => col.padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
620
|
-
const separator = cols.map((col) => "\u2500".repeat(widths[col] ?? 0)).join("\u2500\u253C\u2500");
|
|
621
|
-
this.output.log(exports.colors.bold + header + exports.colors.reset);
|
|
622
|
-
this.output.log(separator);
|
|
623
|
-
for (const row of data) {
|
|
624
|
-
const line = cols.map((col) => String(row[col] ?? "").padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
625
|
-
this.output.log(line);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Log a progress message (overwrites previous line)
|
|
630
|
-
* @param message - Progress message
|
|
631
|
-
*/
|
|
632
|
-
progress(message) {
|
|
633
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
634
|
-
if (process.stdout.isTTY) {
|
|
635
|
-
process.stdout.write(`\r\x1B[K${message}`);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Clear the progress line
|
|
640
|
-
*/
|
|
641
|
-
clearProgress() {
|
|
642
|
-
if (process.stdout.isTTY) {
|
|
643
|
-
process.stdout.write("\r\x1B[K");
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Log a newline
|
|
648
|
-
*/
|
|
649
|
-
newline() {
|
|
650
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
651
|
-
this.output.log("");
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Log a horizontal rule
|
|
655
|
-
* @param char - Character to use for the rule
|
|
656
|
-
* @param width - Width of the rule
|
|
657
|
-
*/
|
|
658
|
-
hr(char = "\u2500", width = 60) {
|
|
659
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
660
|
-
this.output.log(exports.colors.gray + char.repeat(width) + exports.colors.reset);
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Group related log messages
|
|
664
|
-
* @param label - Group label
|
|
665
|
-
* @param fn - Function containing log calls
|
|
666
|
-
*/
|
|
667
|
-
group(label, fn) {
|
|
668
|
-
if (this.level >= 4 /* SILENT */) return;
|
|
669
|
-
this.output.log(exports.colors.bold + "\u250C " + label + exports.colors.reset);
|
|
670
|
-
fn();
|
|
671
|
-
this.output.log(exports.colors.bold + "\u2514" + "\u2500".repeat(label.length + 1) + exports.colors.reset);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
new exports.Logger({ prefix: "ReactCheck" });
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
// src/server/browser.ts
|
|
679
|
-
var browser_exports = {};
|
|
680
|
-
__export(browser_exports, {
|
|
681
|
-
BrowserLauncher: () => exports.BrowserLauncher,
|
|
682
|
-
isPuppeteerAvailable: () => isPuppeteerAvailable
|
|
683
|
-
});
|
|
684
|
-
async function isPuppeteerAvailable() {
|
|
685
|
-
try {
|
|
686
|
-
await import('puppeteer');
|
|
687
|
-
return true;
|
|
688
|
-
} catch {
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
var logger3; exports.BrowserLauncher = void 0;
|
|
693
|
-
var init_browser = __esm({
|
|
694
|
-
"src/server/browser.ts"() {
|
|
695
|
-
init_event_emitter();
|
|
696
|
-
init_logger();
|
|
697
|
-
logger3 = new exports.Logger({ prefix: "browser", level: 0 /* DEBUG */ });
|
|
698
|
-
exports.BrowserLauncher = class extends exports.EventEmitter {
|
|
699
|
-
/** Puppeteer browser instance */
|
|
700
|
-
browser = null;
|
|
701
|
-
/** Active page */
|
|
702
|
-
page = null;
|
|
703
|
-
/** Launch options */
|
|
704
|
-
options;
|
|
705
|
-
/** Injection script */
|
|
706
|
-
injectionScript = null;
|
|
707
|
-
/**
|
|
708
|
-
* Create a new browser launcher
|
|
709
|
-
* @param options - Launch options
|
|
710
|
-
*/
|
|
711
|
-
constructor(options) {
|
|
712
|
-
super();
|
|
713
|
-
this.options = {
|
|
714
|
-
url: options.url,
|
|
715
|
-
headless: options.headless ?? false,
|
|
716
|
-
width: options.width ?? 1280,
|
|
717
|
-
height: options.height ?? 800,
|
|
718
|
-
wsPort: options.wsPort ?? 3099,
|
|
719
|
-
args: options.args ?? [],
|
|
720
|
-
slowMo: options.slowMo ?? 0,
|
|
721
|
-
timeout: options.timeout ?? 3e4
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* Set the injection script
|
|
726
|
-
* @param script - Script to inject before page loads
|
|
727
|
-
*/
|
|
728
|
-
setInjectionScript(script) {
|
|
729
|
-
this.injectionScript = script;
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* Launch the browser
|
|
733
|
-
*/
|
|
734
|
-
async launch() {
|
|
735
|
-
try {
|
|
736
|
-
const puppeteer = await import('puppeteer');
|
|
737
|
-
const args = [
|
|
738
|
-
"--no-sandbox",
|
|
739
|
-
"--disable-setuid-sandbox",
|
|
740
|
-
"--disable-dev-shm-usage",
|
|
741
|
-
"--disable-gpu",
|
|
742
|
-
"--ignore-certificate-errors",
|
|
743
|
-
"--ignore-certificate-errors-spki-list",
|
|
744
|
-
`--window-size=${this.options.width},${this.options.height}`,
|
|
745
|
-
...this.options.args
|
|
746
|
-
];
|
|
747
|
-
this.browser = await puppeteer.default.launch({
|
|
748
|
-
headless: this.options.headless,
|
|
749
|
-
args,
|
|
750
|
-
slowMo: this.options.slowMo,
|
|
751
|
-
defaultViewport: {
|
|
752
|
-
width: this.options.width,
|
|
753
|
-
height: this.options.height
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
const pages = await this.browser.pages();
|
|
757
|
-
this.page = pages[0] ?? await this.browser.newPage();
|
|
758
|
-
this.setupPageHandlers();
|
|
759
|
-
if (this.injectionScript) {
|
|
760
|
-
logger3.debug("Injecting ReactCheck script into page...");
|
|
761
|
-
await this.page.evaluateOnNewDocument(this.injectionScript);
|
|
762
|
-
logger3.debug("Injection script registered");
|
|
763
|
-
}
|
|
764
|
-
this.emit("launched", void 0);
|
|
765
|
-
logger3.info("Browser launched");
|
|
766
|
-
await this.navigate(this.options.url);
|
|
767
|
-
} catch (error) {
|
|
768
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
769
|
-
this.emit("error", err);
|
|
770
|
-
throw err;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Set up page event handlers
|
|
775
|
-
*/
|
|
776
|
-
setupPageHandlers() {
|
|
777
|
-
if (!this.page) return;
|
|
778
|
-
this.page.on("console", (msg) => {
|
|
779
|
-
this.emit("console", {
|
|
780
|
-
type: msg.type(),
|
|
781
|
-
text: msg.text()
|
|
782
|
-
});
|
|
783
|
-
});
|
|
784
|
-
this.page.on("pageerror", (error) => {
|
|
785
|
-
this.emit("error", error);
|
|
786
|
-
});
|
|
787
|
-
this.page.on("framenavigated", (frame) => {
|
|
788
|
-
if (frame === this.page?.mainFrame()) {
|
|
789
|
-
this.emit("navigated", { url: frame.url() });
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
this.page.on("load", () => {
|
|
793
|
-
this.emit("loaded", void 0);
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Navigate to a URL with retry support
|
|
798
|
-
* @param url - URL to navigate to
|
|
799
|
-
* @param retries - Number of retries (default: 3)
|
|
800
|
-
* @param retryDelay - Delay between retries in ms (default: 2000)
|
|
801
|
-
*/
|
|
802
|
-
async navigate(url, retries = 3, retryDelay = 2e3) {
|
|
803
|
-
if (!this.page) {
|
|
804
|
-
throw new Error("Browser not launched");
|
|
805
|
-
}
|
|
806
|
-
let lastError = null;
|
|
807
|
-
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
808
|
-
try {
|
|
809
|
-
await this.page.goto(url, {
|
|
810
|
-
waitUntil: "networkidle2",
|
|
811
|
-
timeout: this.options.timeout
|
|
812
|
-
});
|
|
813
|
-
this.emit("navigated", { url });
|
|
814
|
-
logger3.info(`Navigated to ${url}`);
|
|
815
|
-
return;
|
|
816
|
-
} catch (error) {
|
|
817
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
818
|
-
this.emit("error", lastError);
|
|
819
|
-
if (lastError.message.includes("ERR_CONNECTION_REFUSED") && attempt < retries) {
|
|
820
|
-
logger3.warn(`Connection refused, retrying in ${retryDelay}ms... (${attempt}/${retries})`);
|
|
821
|
-
await new Promise((resolve2) => setTimeout(resolve2, retryDelay));
|
|
822
|
-
continue;
|
|
823
|
-
}
|
|
824
|
-
throw lastError;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
throw lastError ?? new Error("Navigation failed");
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Execute script in page context
|
|
831
|
-
* @param script - Script to execute
|
|
832
|
-
* @returns Script result
|
|
833
|
-
*/
|
|
834
|
-
async evaluate(script) {
|
|
835
|
-
if (!this.page) {
|
|
836
|
-
throw new Error("Browser not launched");
|
|
837
|
-
}
|
|
838
|
-
return this.page.evaluate(script);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Wait for selector
|
|
842
|
-
* @param selector - CSS selector
|
|
843
|
-
* @param timeout - Timeout in ms
|
|
844
|
-
*/
|
|
845
|
-
async waitForSelector(selector, timeout) {
|
|
846
|
-
if (!this.page) {
|
|
847
|
-
throw new Error("Browser not launched");
|
|
848
|
-
}
|
|
849
|
-
await this.page.waitForSelector(selector, {
|
|
850
|
-
timeout: timeout ?? this.options.timeout
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Take a screenshot
|
|
855
|
-
* @param path - File path to save screenshot
|
|
856
|
-
*/
|
|
857
|
-
async screenshot(path) {
|
|
858
|
-
if (!this.page) {
|
|
859
|
-
throw new Error("Browser not launched");
|
|
860
|
-
}
|
|
861
|
-
await this.page.screenshot({ path, fullPage: true });
|
|
862
|
-
logger3.info(`Screenshot saved to ${path}`);
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* Reload the page
|
|
866
|
-
*/
|
|
867
|
-
async reload() {
|
|
868
|
-
if (!this.page) {
|
|
869
|
-
throw new Error("Browser not launched");
|
|
870
|
-
}
|
|
871
|
-
await this.page.reload({ waitUntil: "networkidle2" });
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Get current URL
|
|
875
|
-
* @returns Current page URL
|
|
876
|
-
*/
|
|
877
|
-
getUrl() {
|
|
878
|
-
return this.page?.url() ?? null;
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* Close the browser
|
|
882
|
-
*/
|
|
883
|
-
async close() {
|
|
884
|
-
if (this.browser) {
|
|
885
|
-
await this.browser.close();
|
|
886
|
-
this.browser = null;
|
|
887
|
-
this.page = null;
|
|
888
|
-
this.emit("closed", void 0);
|
|
889
|
-
logger3.info("Browser closed");
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Check if browser is open
|
|
894
|
-
* @returns true if browser is open
|
|
895
|
-
*/
|
|
896
|
-
isOpen() {
|
|
897
|
-
return this.browser !== null && this.browser.connected;
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
* Get the page instance (for advanced usage)
|
|
901
|
-
* @returns Puppeteer page or null
|
|
902
|
-
*/
|
|
903
|
-
getPage() {
|
|
904
|
-
return this.page;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Get the browser instance (for advanced usage)
|
|
908
|
-
* @returns Puppeteer browser or null
|
|
909
|
-
*/
|
|
910
|
-
getBrowser() {
|
|
911
|
-
return this.browser;
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
});
|
|
13
|
+
var promises = require('fs/promises');
|
|
14
|
+
var path = require('path');
|
|
916
15
|
|
|
917
16
|
// src/types.ts
|
|
918
|
-
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
919
|
-
ErrorCode2["CONFIG_INVALID"] = "CONFIG_INVALID";
|
|
920
|
-
ErrorCode2["CONFIG_NOT_FOUND"] = "CONFIG_NOT_FOUND";
|
|
921
|
-
ErrorCode2["CONNECTION_FAILED"] = "CONNECTION_FAILED";
|
|
922
|
-
ErrorCode2["REACT_NOT_FOUND"] = "REACT_NOT_FOUND";
|
|
923
|
-
ErrorCode2["BROWSER_LAUNCH_FAILED"] = "BROWSER_LAUNCH_FAILED";
|
|
924
|
-
ErrorCode2["WEBSOCKET_ERROR"] = "WEBSOCKET_ERROR";
|
|
925
|
-
ErrorCode2["REPORT_WRITE_FAILED"] = "REPORT_WRITE_FAILED";
|
|
926
|
-
ErrorCode2["INVALID_URL"] = "INVALID_URL";
|
|
927
|
-
ErrorCode2["TIMEOUT"] = "TIMEOUT";
|
|
928
|
-
ErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
929
|
-
return ErrorCode2;
|
|
930
|
-
})(ErrorCode || {});
|
|
931
|
-
var ReactCheckError = class extends Error {
|
|
932
|
-
/** Error code */
|
|
933
|
-
code;
|
|
934
|
-
/** Additional error details */
|
|
935
|
-
details;
|
|
936
|
-
constructor(code, message, details) {
|
|
937
|
-
super(message);
|
|
938
|
-
this.name = "ReactCheckError";
|
|
939
|
-
this.code = code;
|
|
940
|
-
this.details = details;
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
// src/core/scanner.ts
|
|
945
|
-
init_event_emitter();
|
|
946
|
-
|
|
947
|
-
// src/core/stats.ts
|
|
948
|
-
init_event_emitter();
|
|
949
|
-
var DEFAULT_THRESHOLDS = {
|
|
950
|
-
critical: 50,
|
|
951
|
-
warning: 20,
|
|
952
|
-
fps: 30
|
|
953
|
-
};
|
|
954
|
-
var StatsCollector = class extends exports.EventEmitter {
|
|
955
|
-
/** Map of component names to their statistics */
|
|
956
|
-
components = /* @__PURE__ */ new Map();
|
|
957
|
-
/** Threshold configuration */
|
|
958
|
-
thresholds;
|
|
959
|
-
/** Session start time */
|
|
960
|
-
sessionStart;
|
|
961
|
-
/** Total render count across all components */
|
|
962
|
-
totalRenders = 0;
|
|
963
|
-
/** FPS samples for averaging */
|
|
964
|
-
fpsSamples = [];
|
|
965
|
-
/** Maximum FPS samples to keep */
|
|
966
|
-
maxFpsSamples = 100;
|
|
967
|
-
/**
|
|
968
|
-
* Create a new StatsCollector
|
|
969
|
-
* @param thresholds - Threshold configuration
|
|
970
|
-
*/
|
|
971
|
-
constructor(thresholds = {}) {
|
|
972
|
-
super();
|
|
973
|
-
this.thresholds = { ...DEFAULT_THRESHOLDS, ...thresholds };
|
|
974
|
-
this.sessionStart = Date.now();
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Add a render event to the statistics
|
|
978
|
-
* @param render - Render information
|
|
979
|
-
*/
|
|
980
|
-
addRender(render) {
|
|
981
|
-
const stats = this.getOrCreateStats(render.componentName);
|
|
982
|
-
const previousSeverity = stats.severity;
|
|
983
|
-
stats.renders++;
|
|
984
|
-
this.totalRenders++;
|
|
985
|
-
stats.totalRenderTime += render.renderTime;
|
|
986
|
-
stats.avgRenderTime = stats.totalRenderTime / stats.renders;
|
|
987
|
-
stats.maxRenderTime = Math.max(stats.maxRenderTime, render.renderTime);
|
|
988
|
-
stats.minRenderTime = Math.min(stats.minRenderTime, render.renderTime);
|
|
989
|
-
if (!render.necessary) {
|
|
990
|
-
stats.unnecessary++;
|
|
991
|
-
}
|
|
992
|
-
if (stats.firstRender === 0) {
|
|
993
|
-
stats.firstRender = render.timestamp;
|
|
994
|
-
}
|
|
995
|
-
stats.lastRender = render.timestamp;
|
|
996
|
-
if (render.changedProps && render.changedProps.length > 0) {
|
|
997
|
-
stats.propsChanged = true;
|
|
998
|
-
}
|
|
999
|
-
if (render.changedState && render.changedState.length > 0) {
|
|
1000
|
-
stats.stateChanged = true;
|
|
1001
|
-
}
|
|
1002
|
-
const sessionDuration = Date.now() - this.sessionStart;
|
|
1003
|
-
const sessionMinutes = sessionDuration / 6e4;
|
|
1004
|
-
stats.expectedRenders = Math.max(1, Math.ceil(sessionMinutes * 5));
|
|
1005
|
-
this.updateSeverity(stats);
|
|
1006
|
-
this.emit("update", stats);
|
|
1007
|
-
if (stats.severity !== previousSeverity) {
|
|
1008
|
-
this.emit("severityChange", {
|
|
1009
|
-
component: stats.name,
|
|
1010
|
-
from: previousSeverity,
|
|
1011
|
-
to: stats.severity
|
|
1012
|
-
});
|
|
1013
|
-
if (stats.severity === "critical" && previousSeverity !== "critical") {
|
|
1014
|
-
this.emit("critical", stats);
|
|
1015
|
-
} else if (stats.severity === "warning" && previousSeverity === "healthy") {
|
|
1016
|
-
this.emit("warning", stats);
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Record an FPS sample
|
|
1022
|
-
* @param fps - FPS value
|
|
1023
|
-
*/
|
|
1024
|
-
addFpsSample(fps) {
|
|
1025
|
-
this.fpsSamples.push(fps);
|
|
1026
|
-
if (this.fpsSamples.length > this.maxFpsSamples) {
|
|
1027
|
-
this.fpsSamples.shift();
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Get or create stats for a component
|
|
1032
|
-
* @param name - Component name
|
|
1033
|
-
* @returns Component stats
|
|
1034
|
-
*/
|
|
1035
|
-
getOrCreateStats(name) {
|
|
1036
|
-
let stats = this.components.get(name);
|
|
1037
|
-
if (!stats) {
|
|
1038
|
-
stats = this.createEmptyStats(name);
|
|
1039
|
-
this.components.set(name, stats);
|
|
1040
|
-
}
|
|
1041
|
-
return stats;
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Create empty stats for a component
|
|
1045
|
-
* @param name - Component name
|
|
1046
|
-
* @returns Empty component stats
|
|
1047
|
-
*/
|
|
1048
|
-
createEmptyStats(name) {
|
|
1049
|
-
return {
|
|
1050
|
-
name,
|
|
1051
|
-
renders: 0,
|
|
1052
|
-
expectedRenders: 1,
|
|
1053
|
-
avgRenderTime: 0,
|
|
1054
|
-
maxRenderTime: 0,
|
|
1055
|
-
minRenderTime: Infinity,
|
|
1056
|
-
totalRenderTime: 0,
|
|
1057
|
-
unnecessary: 0,
|
|
1058
|
-
severity: "healthy",
|
|
1059
|
-
chain: [],
|
|
1060
|
-
fixes: [],
|
|
1061
|
-
firstRender: 0,
|
|
1062
|
-
lastRender: 0,
|
|
1063
|
-
propsChanged: false,
|
|
1064
|
-
stateChanged: false
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Update severity for a component based on thresholds
|
|
1069
|
-
* @param stats - Component stats to update
|
|
1070
|
-
*/
|
|
1071
|
-
updateSeverity(stats) {
|
|
1072
|
-
if (stats.renders >= this.thresholds.critical) {
|
|
1073
|
-
stats.severity = "critical";
|
|
1074
|
-
} else if (stats.renders >= this.thresholds.warning) {
|
|
1075
|
-
stats.severity = "warning";
|
|
1076
|
-
} else {
|
|
1077
|
-
stats.severity = "healthy";
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
/**
|
|
1081
|
-
* Get stats for a specific component
|
|
1082
|
-
* @param name - Component name
|
|
1083
|
-
* @returns Component stats or undefined
|
|
1084
|
-
*/
|
|
1085
|
-
getComponentStats(name) {
|
|
1086
|
-
return this.components.get(name);
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Get all component stats
|
|
1090
|
-
* @returns Array of component stats
|
|
1091
|
-
*/
|
|
1092
|
-
getAllStats() {
|
|
1093
|
-
return Array.from(this.components.values());
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Get a snapshot of all stats sorted by severity/render count
|
|
1097
|
-
* @returns Sorted array of component stats
|
|
1098
|
-
*/
|
|
1099
|
-
getSnapshot() {
|
|
1100
|
-
return this.getAllStats().sort((a, b) => {
|
|
1101
|
-
const severityOrder = {
|
|
1102
|
-
critical: 0,
|
|
1103
|
-
warning: 1,
|
|
1104
|
-
info: 2,
|
|
1105
|
-
healthy: 3
|
|
1106
|
-
};
|
|
1107
|
-
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
1108
|
-
if (severityDiff !== 0) return severityDiff;
|
|
1109
|
-
return b.renders - a.renders;
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Get components by severity
|
|
1114
|
-
* @param severity - Severity level to filter
|
|
1115
|
-
* @returns Array of matching component stats
|
|
1116
|
-
*/
|
|
1117
|
-
getComponentsBySeverity(severity) {
|
|
1118
|
-
return this.getAllStats().filter((s) => s.severity === severity);
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Get session summary
|
|
1122
|
-
* @returns Session summary statistics
|
|
1123
|
-
*/
|
|
1124
|
-
getSummary() {
|
|
1125
|
-
const stats = this.getAllStats();
|
|
1126
|
-
const criticalCount = stats.filter((s) => s.severity === "critical").length;
|
|
1127
|
-
const warningCount = stats.filter((s) => s.severity === "warning").length;
|
|
1128
|
-
const healthyCount = stats.filter((s) => s.severity === "healthy").length;
|
|
1129
|
-
const unnecessaryCount = stats.reduce((sum, s) => sum + s.unnecessary, 0);
|
|
1130
|
-
let avgFps = 60;
|
|
1131
|
-
let minFps = 60;
|
|
1132
|
-
if (this.fpsSamples.length > 0) {
|
|
1133
|
-
avgFps = this.fpsSamples.reduce((a, b) => a + b, 0) / this.fpsSamples.length;
|
|
1134
|
-
minFps = Math.min(...this.fpsSamples);
|
|
1135
|
-
}
|
|
1136
|
-
return {
|
|
1137
|
-
totalComponents: stats.length,
|
|
1138
|
-
totalRenders: this.totalRenders,
|
|
1139
|
-
criticalIssues: criticalCount,
|
|
1140
|
-
warnings: warningCount,
|
|
1141
|
-
healthy: healthyCount,
|
|
1142
|
-
avgFps: Math.round(avgFps),
|
|
1143
|
-
minFps: Math.round(minFps),
|
|
1144
|
-
unnecessaryRenders: unnecessaryCount
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Get the most problematic components
|
|
1149
|
-
* @param limit - Maximum number to return
|
|
1150
|
-
* @returns Top problematic components
|
|
1151
|
-
*/
|
|
1152
|
-
getTopProblems(limit = 10) {
|
|
1153
|
-
return this.getSnapshot().filter((s) => s.severity !== "healthy").slice(0, limit);
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* Update chain information for a component
|
|
1157
|
-
* @param componentName - Component name
|
|
1158
|
-
* @param chain - Render chain
|
|
1159
|
-
*/
|
|
1160
|
-
setComponentChain(componentName, chain) {
|
|
1161
|
-
const stats = this.components.get(componentName);
|
|
1162
|
-
if (stats) {
|
|
1163
|
-
stats.chain = chain;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Update parent information for a component
|
|
1168
|
-
* @param componentName - Component name
|
|
1169
|
-
* @param parentName - Parent component name
|
|
1170
|
-
*/
|
|
1171
|
-
setComponentParent(componentName, parentName) {
|
|
1172
|
-
const stats = this.components.get(componentName);
|
|
1173
|
-
if (stats) {
|
|
1174
|
-
stats.parent = parentName;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Reset all statistics
|
|
1179
|
-
*/
|
|
1180
|
-
reset() {
|
|
1181
|
-
this.components.clear();
|
|
1182
|
-
this.totalRenders = 0;
|
|
1183
|
-
this.fpsSamples = [];
|
|
1184
|
-
this.sessionStart = Date.now();
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Update threshold configuration
|
|
1188
|
-
* @param thresholds - New thresholds
|
|
1189
|
-
*/
|
|
1190
|
-
setThresholds(thresholds) {
|
|
1191
|
-
this.thresholds = { ...this.thresholds, ...thresholds };
|
|
1192
|
-
for (const stats of this.components.values()) {
|
|
1193
|
-
const previousSeverity = stats.severity;
|
|
1194
|
-
this.updateSeverity(stats);
|
|
1195
|
-
if (stats.severity !== previousSeverity) {
|
|
1196
|
-
this.emit("severityChange", {
|
|
1197
|
-
component: stats.name,
|
|
1198
|
-
from: previousSeverity,
|
|
1199
|
-
to: stats.severity
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Get current thresholds
|
|
1206
|
-
* @returns Current threshold configuration
|
|
1207
|
-
*/
|
|
1208
|
-
getThresholds() {
|
|
1209
|
-
return { ...this.thresholds };
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Get session duration in milliseconds
|
|
1213
|
-
* @returns Session duration
|
|
1214
|
-
*/
|
|
1215
|
-
getSessionDuration() {
|
|
1216
|
-
return Date.now() - this.sessionStart;
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Get total render count
|
|
1220
|
-
* @returns Total renders across all components
|
|
1221
|
-
*/
|
|
1222
|
-
getTotalRenders() {
|
|
1223
|
-
return this.totalRenders;
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* Get component count
|
|
1227
|
-
* @returns Number of tracked components
|
|
1228
|
-
*/
|
|
1229
|
-
getComponentCount() {
|
|
1230
|
-
return this.components.size;
|
|
1231
|
-
}
|
|
1232
|
-
/**
|
|
1233
|
-
* Check if FPS is below threshold
|
|
1234
|
-
* @returns true if average FPS is below threshold
|
|
1235
|
-
*/
|
|
1236
|
-
isFpsBelowThreshold() {
|
|
1237
|
-
if (this.fpsSamples.length === 0) return false;
|
|
1238
|
-
const avgFps = this.fpsSamples.reduce((a, b) => a + b, 0) / this.fpsSamples.length;
|
|
1239
|
-
return avgFps < this.thresholds.fps;
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Export stats for serialization
|
|
1243
|
-
* @returns Serializable stats object
|
|
1244
|
-
*/
|
|
1245
|
-
export() {
|
|
1246
|
-
return {
|
|
1247
|
-
components: this.getSnapshot(),
|
|
1248
|
-
summary: this.getSummary(),
|
|
1249
|
-
thresholds: this.getThresholds(),
|
|
1250
|
-
sessionDuration: this.getSessionDuration()
|
|
1251
|
-
};
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
// src/core/chain.ts
|
|
1256
|
-
init_event_emitter();
|
|
1257
|
-
var ChainAnalyzer = class extends exports.EventEmitter {
|
|
1258
|
-
/** Time window size in ms (one frame at 60fps) */
|
|
1259
|
-
windowSize;
|
|
1260
|
-
/** Current render windows being tracked */
|
|
1261
|
-
windows = /* @__PURE__ */ new Map();
|
|
1262
|
-
/** Component parent relationships */
|
|
1263
|
-
parentMap = /* @__PURE__ */ new Map();
|
|
1264
|
-
/** Recently detected chains to avoid duplicates */
|
|
1265
|
-
recentChains = /* @__PURE__ */ new Set();
|
|
1266
|
-
/** Minimum chain depth to report */
|
|
1267
|
-
minChainDepth;
|
|
1268
|
-
/** Maximum time to keep recent chains */
|
|
1269
|
-
recentChainTtl;
|
|
1270
|
-
/**
|
|
1271
|
-
* Create a new ChainAnalyzer
|
|
1272
|
-
* @param options - Configuration options
|
|
1273
|
-
*/
|
|
1274
|
-
constructor(options = {}) {
|
|
1275
|
-
super();
|
|
1276
|
-
this.windowSize = options.windowSize ?? 16;
|
|
1277
|
-
this.minChainDepth = options.minChainDepth ?? 2;
|
|
1278
|
-
this.recentChainTtl = options.recentChainTtl ?? 1e3;
|
|
1279
|
-
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Add a render event for analysis
|
|
1282
|
-
* @param render - Render information
|
|
1283
|
-
* @param parent - Optional parent component name
|
|
1284
|
-
*/
|
|
1285
|
-
addRender(render, parent) {
|
|
1286
|
-
const trackedRender = {
|
|
1287
|
-
...render,
|
|
1288
|
-
...parent !== void 0 ? { parent } : {},
|
|
1289
|
-
contextTriggered: this.isContextTriggered(render)
|
|
1290
|
-
};
|
|
1291
|
-
if (parent) {
|
|
1292
|
-
this.parentMap.set(render.componentName, parent);
|
|
1293
|
-
}
|
|
1294
|
-
const windowKey = this.getWindowKey(render.timestamp);
|
|
1295
|
-
let window2 = this.windows.get(windowKey);
|
|
1296
|
-
if (!window2) {
|
|
1297
|
-
window2 = {
|
|
1298
|
-
renders: [],
|
|
1299
|
-
startTime: render.timestamp
|
|
1300
|
-
};
|
|
1301
|
-
this.windows.set(windowKey, window2);
|
|
1302
|
-
}
|
|
1303
|
-
window2.renders.push(trackedRender);
|
|
1304
|
-
if (window2.renders.length >= this.minChainDepth) {
|
|
1305
|
-
this.analyzeWindow(windowKey);
|
|
1306
|
-
}
|
|
1307
|
-
this.cleanupWindows(render.timestamp);
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Set parent relationship for a component
|
|
1311
|
-
* @param child - Child component name
|
|
1312
|
-
* @param parent - Parent component name
|
|
1313
|
-
*/
|
|
1314
|
-
setParent(child, parent) {
|
|
1315
|
-
this.parentMap.set(child, parent);
|
|
1316
|
-
}
|
|
1317
|
-
/**
|
|
1318
|
-
* Get window key for a timestamp
|
|
1319
|
-
* @param timestamp - Timestamp in ms
|
|
1320
|
-
* @returns Window key
|
|
1321
|
-
*/
|
|
1322
|
-
getWindowKey(timestamp) {
|
|
1323
|
-
return Math.floor(timestamp / this.windowSize);
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Check if a render was likely triggered by context
|
|
1327
|
-
* @param render - Render information
|
|
1328
|
-
* @returns true if context-triggered
|
|
1329
|
-
*/
|
|
1330
|
-
isContextTriggered(render) {
|
|
1331
|
-
return !render.changedProps?.length && !render.changedState?.length && render.phase === "update";
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* Analyze a render window for chains
|
|
1335
|
-
* @param windowKey - Window key to analyze
|
|
1336
|
-
*/
|
|
1337
|
-
analyzeWindow(windowKey) {
|
|
1338
|
-
const window2 = this.windows.get(windowKey);
|
|
1339
|
-
if (!window2 || window2.renders.length < this.minChainDepth) {
|
|
1340
|
-
return;
|
|
1341
|
-
}
|
|
1342
|
-
const sortedRenders = [...window2.renders].sort((a, b) => a.timestamp - b.timestamp);
|
|
1343
|
-
const chains = this.buildChains(sortedRenders);
|
|
1344
|
-
for (const chain of chains) {
|
|
1345
|
-
const chainKey = this.getChainKey(chain);
|
|
1346
|
-
if (this.recentChains.has(chainKey)) {
|
|
1347
|
-
continue;
|
|
1348
|
-
}
|
|
1349
|
-
this.recentChains.add(chainKey);
|
|
1350
|
-
setTimeout(() => {
|
|
1351
|
-
this.recentChains.delete(chainKey);
|
|
1352
|
-
}, this.recentChainTtl);
|
|
1353
|
-
this.emit("chain", chain);
|
|
1354
|
-
if (chain.isContextTriggered) {
|
|
1355
|
-
this.emit("contextChain", chain);
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* Build chains from a sorted render sequence
|
|
1361
|
-
* @param renders - Sorted render events
|
|
1362
|
-
* @returns Detected chains
|
|
1363
|
-
*/
|
|
1364
|
-
buildChains(renders) {
|
|
1365
|
-
const chains = [];
|
|
1366
|
-
const visited = /* @__PURE__ */ new Set();
|
|
1367
|
-
const chainComponents = [];
|
|
1368
|
-
for (const render of renders) {
|
|
1369
|
-
if (visited.has(render.componentName)) {
|
|
1370
|
-
continue;
|
|
1371
|
-
}
|
|
1372
|
-
const chain = this.traceChain(render.componentName, renders, visited);
|
|
1373
|
-
if (chain.length >= this.minChainDepth) {
|
|
1374
|
-
chainComponents.push(chain);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
for (const chain of chainComponents) {
|
|
1378
|
-
const chainRenders = renders.filter((r) => chain.includes(r.componentName));
|
|
1379
|
-
const isContextTriggered = chainRenders.some((r) => r.contextTriggered);
|
|
1380
|
-
const rootCause = this.findRootCause(chain, renders);
|
|
1381
|
-
const trigger = this.determineTrigger(rootCause, renders);
|
|
1382
|
-
chains.push({
|
|
1383
|
-
trigger,
|
|
1384
|
-
chain,
|
|
1385
|
-
depth: chain.length,
|
|
1386
|
-
totalRenders: chainRenders.length,
|
|
1387
|
-
rootCause,
|
|
1388
|
-
timestamp: Date.now(),
|
|
1389
|
-
isContextTriggered
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
return chains;
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Trace a chain starting from a component
|
|
1396
|
-
* @param startComponent - Starting component
|
|
1397
|
-
* @param renders - All renders in window
|
|
1398
|
-
* @param visited - Already visited components
|
|
1399
|
-
* @returns Chain of component names
|
|
1400
|
-
*/
|
|
1401
|
-
traceChain(startComponent, renders, visited) {
|
|
1402
|
-
const chain = [];
|
|
1403
|
-
const queue = [startComponent];
|
|
1404
|
-
while (queue.length > 0) {
|
|
1405
|
-
const current = queue.shift();
|
|
1406
|
-
if (!current || visited.has(current)) {
|
|
1407
|
-
continue;
|
|
1408
|
-
}
|
|
1409
|
-
visited.add(current);
|
|
1410
|
-
chain.push(current);
|
|
1411
|
-
const parent = this.parentMap.get(current);
|
|
1412
|
-
if (parent && renders.some((r) => r.componentName === parent) && !visited.has(parent)) {
|
|
1413
|
-
queue.unshift(parent);
|
|
1414
|
-
}
|
|
1415
|
-
for (const [child, p] of this.parentMap) {
|
|
1416
|
-
if (p === current && renders.some((r) => r.componentName === child) && !visited.has(child)) {
|
|
1417
|
-
queue.push(child);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
return chain;
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Find the root cause component in a chain
|
|
1425
|
-
* @param chain - Component chain
|
|
1426
|
-
* @param renders - All renders
|
|
1427
|
-
* @returns Root cause component name
|
|
1428
|
-
*/
|
|
1429
|
-
findRootCause(chain, renders) {
|
|
1430
|
-
const chainRenders = renders.filter((r) => chain.includes(r.componentName)).sort((a, b) => a.timestamp - b.timestamp);
|
|
1431
|
-
for (const render of chainRenders) {
|
|
1432
|
-
if (render.changedState?.length ?? render.changedProps?.length) {
|
|
1433
|
-
return render.componentName;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
return chain[0] ?? "Unknown";
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Determine what triggered a chain
|
|
1440
|
-
* @param rootCause - Root cause component
|
|
1441
|
-
* @param renders - All renders
|
|
1442
|
-
* @returns Trigger description
|
|
1443
|
-
*/
|
|
1444
|
-
determineTrigger(rootCause, renders) {
|
|
1445
|
-
const render = renders.find((r) => r.componentName === rootCause);
|
|
1446
|
-
if (!render) {
|
|
1447
|
-
return `Unknown trigger in ${rootCause}`;
|
|
1448
|
-
}
|
|
1449
|
-
if (render.changedState?.length) {
|
|
1450
|
-
return `setState in ${rootCause}`;
|
|
1451
|
-
}
|
|
1452
|
-
if (render.changedProps?.length) {
|
|
1453
|
-
const props = render.changedProps.slice(0, 3).join(", ");
|
|
1454
|
-
const more = render.changedProps.length > 3 ? "..." : "";
|
|
1455
|
-
return `Props changed (${props}${more}) in ${rootCause}`;
|
|
1456
|
-
}
|
|
1457
|
-
if (render.contextTriggered) {
|
|
1458
|
-
return `Context update affecting ${rootCause}`;
|
|
1459
|
-
}
|
|
1460
|
-
if (render.phase === "mount") {
|
|
1461
|
-
return `Initial mount of ${rootCause}`;
|
|
1462
|
-
}
|
|
1463
|
-
return `Re-render of ${rootCause}`;
|
|
1464
|
-
}
|
|
1465
|
-
/**
|
|
1466
|
-
* Generate a unique key for a chain to detect duplicates
|
|
1467
|
-
* @param chain - Chain info
|
|
1468
|
-
* @returns Unique key
|
|
1469
|
-
*/
|
|
1470
|
-
getChainKey(chain) {
|
|
1471
|
-
return `${chain.rootCause}:${chain.chain.join("->")}`;
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Clean up old render windows
|
|
1475
|
-
* @param currentTime - Current timestamp
|
|
1476
|
-
*/
|
|
1477
|
-
cleanupWindows(currentTime) {
|
|
1478
|
-
const cutoff = currentTime - this.windowSize * 10;
|
|
1479
|
-
for (const [key, window2] of this.windows) {
|
|
1480
|
-
if (window2.startTime < cutoff) {
|
|
1481
|
-
this.windows.delete(key);
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
/**
|
|
1486
|
-
* Get the parent of a component
|
|
1487
|
-
* @param componentName - Component name
|
|
1488
|
-
* @returns Parent name or undefined
|
|
1489
|
-
*/
|
|
1490
|
-
getParent(componentName) {
|
|
1491
|
-
return this.parentMap.get(componentName);
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Get all known parent relationships
|
|
1495
|
-
* @returns Map of child to parent
|
|
1496
|
-
*/
|
|
1497
|
-
getParentMap() {
|
|
1498
|
-
return new Map(this.parentMap);
|
|
1499
|
-
}
|
|
1500
|
-
/**
|
|
1501
|
-
* Build a full chain for a component (tracing up to root)
|
|
1502
|
-
* @param componentName - Starting component
|
|
1503
|
-
* @returns Chain from root to component
|
|
1504
|
-
*/
|
|
1505
|
-
getComponentChain(componentName) {
|
|
1506
|
-
const chain = [];
|
|
1507
|
-
let current = componentName;
|
|
1508
|
-
while (current) {
|
|
1509
|
-
chain.unshift(current);
|
|
1510
|
-
current = this.parentMap.get(current);
|
|
1511
|
-
if (chain.length > 100) {
|
|
1512
|
-
break;
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
return chain;
|
|
1516
|
-
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Clear all tracked data
|
|
1519
|
-
*/
|
|
1520
|
-
reset() {
|
|
1521
|
-
this.windows.clear();
|
|
1522
|
-
this.parentMap.clear();
|
|
1523
|
-
this.recentChains.clear();
|
|
1524
|
-
}
|
|
1525
|
-
/**
|
|
1526
|
-
* Get statistics about current tracking
|
|
1527
|
-
* @returns Tracking statistics
|
|
1528
|
-
*/
|
|
1529
|
-
getStats() {
|
|
1530
|
-
return {
|
|
1531
|
-
windowCount: this.windows.size,
|
|
1532
|
-
parentRelationships: this.parentMap.size,
|
|
1533
|
-
recentChains: this.recentChains.size
|
|
1534
|
-
};
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
|
|
1538
|
-
// src/core/fix.ts
|
|
1539
|
-
init_event_emitter();
|
|
1540
|
-
var BUILTIN_RULES = [
|
|
1541
|
-
// React.memo rule
|
|
1542
|
-
{
|
|
1543
|
-
id: "unnecessary-rerenders-memo",
|
|
1544
|
-
name: "Unnecessary Re-renders (memo)",
|
|
1545
|
-
description: "Component re-renders frequently without prop changes",
|
|
1546
|
-
fixType: "React.memo",
|
|
1547
|
-
priority: 1,
|
|
1548
|
-
detect: (stats) => {
|
|
1549
|
-
const unnecessaryRatio = stats.renders > 0 ? stats.unnecessary / stats.renders : 0;
|
|
1550
|
-
return stats.renders >= 10 && unnecessaryRatio >= 0.5 && !stats.propsChanged;
|
|
1551
|
-
},
|
|
1552
|
-
suggest: (stats) => ({
|
|
1553
|
-
severity: stats.severity === "healthy" ? "info" : stats.severity,
|
|
1554
|
-
issue: `Component "${stats.name}" re-renders ${stats.unnecessary} times unnecessarily out of ${stats.renders} total renders`,
|
|
1555
|
-
cause: stats.parent ? `Parent component "${stats.parent}" re-renders and causes cascading updates` : "Parent component re-renders propagate to this component",
|
|
1556
|
-
codeBefore: generateComponentCode(stats.name),
|
|
1557
|
-
codeAfter: generateMemoCode(stats.name),
|
|
1558
|
-
explanation: "React.memo is a higher-order component that prevents re-renders when props are unchanged. It performs a shallow comparison of props and skips rendering if they match.",
|
|
1559
|
-
impact: `Could prevent ~${stats.unnecessary} unnecessary renders (${Math.round(stats.unnecessary / stats.renders * 100)}% reduction)`
|
|
1560
|
-
})
|
|
1561
|
-
},
|
|
1562
|
-
// useMemo rule for expensive computations
|
|
1563
|
-
{
|
|
1564
|
-
id: "expensive-computation-memo",
|
|
1565
|
-
name: "Expensive Computation",
|
|
1566
|
-
description: "Component has high render times suggesting expensive calculations",
|
|
1567
|
-
fixType: "useMemo",
|
|
1568
|
-
priority: 2,
|
|
1569
|
-
detect: (stats) => {
|
|
1570
|
-
return stats.avgRenderTime > 16 && stats.renders >= 5;
|
|
1571
|
-
},
|
|
1572
|
-
suggest: (stats) => ({
|
|
1573
|
-
severity: stats.avgRenderTime > 50 ? "critical" : "warning",
|
|
1574
|
-
issue: `Component "${stats.name}" has slow renders averaging ${stats.avgRenderTime.toFixed(1)}ms`,
|
|
1575
|
-
cause: "Expensive calculations or data transformations are being performed on every render",
|
|
1576
|
-
codeBefore: generateExpensiveCode(stats.name),
|
|
1577
|
-
codeAfter: generateUseMemoCode(stats.name),
|
|
1578
|
-
explanation: "useMemo caches the result of expensive computations between renders. It only recalculates when dependencies change, improving performance.",
|
|
1579
|
-
impact: `Could reduce render time from ${stats.avgRenderTime.toFixed(1)}ms to <1ms for cached renders`
|
|
1580
|
-
})
|
|
1581
|
-
},
|
|
1582
|
-
// useCallback rule for function props
|
|
1583
|
-
{
|
|
1584
|
-
id: "function-prop-stability",
|
|
1585
|
-
name: "Unstable Function Props",
|
|
1586
|
-
description: "Component passes inline functions as props causing child re-renders",
|
|
1587
|
-
fixType: "useCallback",
|
|
1588
|
-
priority: 3,
|
|
1589
|
-
detect: (stats) => {
|
|
1590
|
-
return stats.renders >= 15 && stats.propsChanged;
|
|
1591
|
-
},
|
|
1592
|
-
suggest: (stats) => ({
|
|
1593
|
-
severity: stats.severity === "healthy" ? "info" : stats.severity,
|
|
1594
|
-
issue: `Component "${stats.name}" may be passing unstable function references as props`,
|
|
1595
|
-
cause: "Inline arrow functions are recreated on every render, causing children with React.memo to re-render",
|
|
1596
|
-
codeBefore: generateInlineFunctionCode(stats.name),
|
|
1597
|
-
codeAfter: generateUseCallbackCode(stats.name),
|
|
1598
|
-
explanation: "useCallback returns a memoized callback that only changes when dependencies change. This stabilizes function references passed to child components.",
|
|
1599
|
-
impact: "Stabilized function props allow memoized children to skip re-renders"
|
|
1600
|
-
})
|
|
1601
|
-
},
|
|
1602
|
-
// Context split rule
|
|
1603
|
-
{
|
|
1604
|
-
id: "context-over-subscription",
|
|
1605
|
-
name: "Context Over-subscription",
|
|
1606
|
-
description: "Context updates trigger unnecessary re-renders in unrelated components",
|
|
1607
|
-
fixType: "context-split",
|
|
1608
|
-
priority: 4,
|
|
1609
|
-
detect: (stats) => {
|
|
1610
|
-
return stats.renders >= 20 && stats.unnecessary > stats.renders * 0.7 && !stats.propsChanged && !stats.stateChanged;
|
|
1611
|
-
},
|
|
1612
|
-
suggest: (stats) => ({
|
|
1613
|
-
severity: stats.severity === "healthy" ? "warning" : stats.severity,
|
|
1614
|
-
issue: `Component "${stats.name}" re-renders due to context updates it doesn't use`,
|
|
1615
|
-
cause: "A context this component subscribes to contains unrelated state that changes frequently",
|
|
1616
|
-
codeBefore: generateContextCode("AppContext"),
|
|
1617
|
-
codeAfter: generateSplitContextCode(),
|
|
1618
|
-
explanation: "Splitting large contexts into smaller, focused contexts prevents unrelated updates from triggering re-renders in components that only need part of the context.",
|
|
1619
|
-
impact: `Could eliminate ${stats.unnecessary} unnecessary renders caused by unrelated context updates`
|
|
1620
|
-
})
|
|
1621
|
-
},
|
|
1622
|
-
// State colocation rule
|
|
1623
|
-
{
|
|
1624
|
-
id: "state-too-high",
|
|
1625
|
-
name: "State Location",
|
|
1626
|
-
description: "State is managed too high in the component tree",
|
|
1627
|
-
fixType: "state-colocation",
|
|
1628
|
-
priority: 5,
|
|
1629
|
-
detect: (stats) => {
|
|
1630
|
-
const chainDepth = stats.chain.length;
|
|
1631
|
-
return stats.renders >= 30 && chainDepth >= 3 && stats.stateChanged;
|
|
1632
|
-
},
|
|
1633
|
-
suggest: (stats) => ({
|
|
1634
|
-
severity: stats.severity === "healthy" ? "warning" : stats.severity,
|
|
1635
|
-
issue: `State changes in "${stats.name}" trigger a cascade of ${stats.chain.length} component re-renders`,
|
|
1636
|
-
cause: `State that only affects a subtree is managed at the "${stats.name}" level, causing unnecessary updates`,
|
|
1637
|
-
codeBefore: generateStateHighCode(stats.name),
|
|
1638
|
-
codeAfter: generateStateColocationCode(stats.name),
|
|
1639
|
-
explanation: "Moving state closer to where it's used (colocation) reduces the re-render scope. Only components that actually need the state will update.",
|
|
1640
|
-
impact: `Could reduce cascade depth from ${stats.chain.length} to 1-2 components`
|
|
1641
|
-
})
|
|
1642
|
-
},
|
|
1643
|
-
// Component extraction rule
|
|
1644
|
-
{
|
|
1645
|
-
id: "extract-heavy-child",
|
|
1646
|
-
name: "Component Extraction",
|
|
1647
|
-
description: "Part of the component updates independently and should be extracted",
|
|
1648
|
-
fixType: "component-extraction",
|
|
1649
|
-
priority: 6,
|
|
1650
|
-
detect: (stats) => {
|
|
1651
|
-
return stats.renders >= 50 && stats.avgRenderTime > 5;
|
|
1652
|
-
},
|
|
1653
|
-
suggest: (stats) => ({
|
|
1654
|
-
severity: stats.severity === "healthy" ? "info" : stats.severity,
|
|
1655
|
-
issue: `Component "${stats.name}" renders frequently (${stats.renders} times) with mixed concerns`,
|
|
1656
|
-
cause: "The component contains parts that update at different rates, causing full re-renders",
|
|
1657
|
-
codeBefore: generateMonolithCode(stats.name),
|
|
1658
|
-
codeAfter: generateExtractedCode(stats.name),
|
|
1659
|
-
explanation: "Extracting frequently-updating parts into separate components allows React to optimize renders for each part independently.",
|
|
1660
|
-
impact: "Isolates render cycles so fast-updating parts don't affect slow-updating parts"
|
|
1661
|
-
})
|
|
1662
|
-
}
|
|
1663
|
-
];
|
|
1664
|
-
function generateComponentCode(name, type) {
|
|
1665
|
-
return `function ${name}({ prop1, prop2 }) {
|
|
1666
|
-
return (
|
|
1667
|
-
<div>
|
|
1668
|
-
{/* component content */}
|
|
1669
|
-
</div>
|
|
1670
|
-
);
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
export default ${name};`;
|
|
1674
|
-
}
|
|
1675
|
-
function generateMemoCode(name) {
|
|
1676
|
-
return `import { memo } from 'react';
|
|
1677
|
-
|
|
1678
|
-
const ${name} = memo(function ${name}({ prop1, prop2 }) {
|
|
1679
|
-
return (
|
|
1680
|
-
<div>
|
|
1681
|
-
{/* component content */}
|
|
1682
|
-
</div>
|
|
1683
|
-
);
|
|
1684
|
-
});
|
|
1685
|
-
|
|
1686
|
-
export default ${name};`;
|
|
1687
|
-
}
|
|
1688
|
-
function generateExpensiveCode(name) {
|
|
1689
|
-
return `function ${name}({ items }) {
|
|
1690
|
-
// Expensive computation on every render
|
|
1691
|
-
const processed = items
|
|
1692
|
-
.filter(item => item.active)
|
|
1693
|
-
.map(item => transform(item))
|
|
1694
|
-
.sort((a, b) => a.value - b.value);
|
|
1695
|
-
|
|
1696
|
-
return <List items={processed} />;
|
|
1697
|
-
}`;
|
|
1698
|
-
}
|
|
1699
|
-
function generateUseMemoCode(name) {
|
|
1700
|
-
return `import { useMemo } from 'react';
|
|
1701
|
-
|
|
1702
|
-
function ${name}({ items }) {
|
|
1703
|
-
// Computation cached until items change
|
|
1704
|
-
const processed = useMemo(() => {
|
|
1705
|
-
return items
|
|
1706
|
-
.filter(item => item.active)
|
|
1707
|
-
.map(item => transform(item))
|
|
1708
|
-
.sort((a, b) => a.value - b.value);
|
|
1709
|
-
}, [items]);
|
|
1710
|
-
|
|
1711
|
-
return <List items={processed} />;
|
|
1712
|
-
}`;
|
|
1713
|
-
}
|
|
1714
|
-
function generateInlineFunctionCode(name) {
|
|
1715
|
-
return `function ${name}({ data }) {
|
|
1716
|
-
return (
|
|
1717
|
-
<ChildComponent
|
|
1718
|
-
onAction={(id) => handleAction(id)} // New function every render!
|
|
1719
|
-
onClick={() => setOpen(true)} // New function every render!
|
|
1720
|
-
/>
|
|
1721
|
-
);
|
|
1722
|
-
}`;
|
|
1723
|
-
}
|
|
1724
|
-
function generateUseCallbackCode(name) {
|
|
1725
|
-
return `import { useCallback } from 'react';
|
|
1726
|
-
|
|
1727
|
-
function ${name}({ data }) {
|
|
1728
|
-
const handleAction = useCallback((id) => {
|
|
1729
|
-
// Handle action
|
|
1730
|
-
}, []); // Empty deps if no external dependencies
|
|
1731
|
-
|
|
1732
|
-
const handleClick = useCallback(() => {
|
|
1733
|
-
setOpen(true);
|
|
1734
|
-
}, []);
|
|
1735
|
-
|
|
1736
|
-
return (
|
|
1737
|
-
<ChildComponent
|
|
1738
|
-
onAction={handleAction} // Stable reference
|
|
1739
|
-
onClick={handleClick} // Stable reference
|
|
1740
|
-
/>
|
|
1741
|
-
);
|
|
1742
|
-
}`;
|
|
1743
|
-
}
|
|
1744
|
-
function generateContextCode(contextName) {
|
|
1745
|
-
return `// Single large context with mixed concerns
|
|
1746
|
-
const ${contextName} = createContext({
|
|
1747
|
-
user: null,
|
|
1748
|
-
theme: 'light',
|
|
1749
|
-
notifications: [],
|
|
1750
|
-
settings: {},
|
|
1751
|
-
cart: [],
|
|
1752
|
-
// ... many more values
|
|
1753
|
-
});
|
|
1754
|
-
|
|
1755
|
-
// Every consumer re-renders when ANY value changes
|
|
1756
|
-
function Component() {
|
|
1757
|
-
const { theme } = useContext(${contextName});
|
|
1758
|
-
// Re-renders when user, notifications, cart change too!
|
|
1759
|
-
return <div className={theme}>...</div>;
|
|
1760
|
-
}`;
|
|
1761
|
-
}
|
|
1762
|
-
function generateSplitContextCode() {
|
|
1763
|
-
return `// Split into focused contexts
|
|
1764
|
-
const UserContext = createContext(null);
|
|
1765
|
-
const ThemeContext = createContext('light');
|
|
1766
|
-
const NotificationContext = createContext([]);
|
|
1767
|
-
|
|
1768
|
-
// Only re-renders when theme changes
|
|
1769
|
-
function Component() {
|
|
1770
|
-
const theme = useContext(ThemeContext);
|
|
1771
|
-
return <div className={theme}>...</div>;
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
// Provider composition
|
|
1775
|
-
function App() {
|
|
1776
|
-
return (
|
|
1777
|
-
<UserContext.Provider value={user}>
|
|
1778
|
-
<ThemeContext.Provider value={theme}>
|
|
1779
|
-
<NotificationContext.Provider value={notifications}>
|
|
1780
|
-
<MainContent />
|
|
1781
|
-
</NotificationContext.Provider>
|
|
1782
|
-
</ThemeContext.Provider>
|
|
1783
|
-
</UserContext.Provider>
|
|
1784
|
-
);
|
|
1785
|
-
}`;
|
|
1786
|
-
}
|
|
1787
|
-
function generateStateHighCode(name) {
|
|
1788
|
-
return `function ${name}() {
|
|
1789
|
-
// State managed at top level
|
|
1790
|
-
const [search, setSearch] = useState('');
|
|
1791
|
-
const [filter, setFilter] = useState('all');
|
|
1792
|
-
|
|
1793
|
-
return (
|
|
1794
|
-
<div>
|
|
1795
|
-
<Header />
|
|
1796
|
-
<Sidebar />
|
|
1797
|
-
{/* Only SearchBox needs search state */}
|
|
1798
|
-
<SearchBox value={search} onChange={setSearch} />
|
|
1799
|
-
<MainContent filter={filter} />
|
|
1800
|
-
<Footer />
|
|
1801
|
-
</div>
|
|
1802
|
-
);
|
|
1803
|
-
}`;
|
|
1804
|
-
}
|
|
1805
|
-
function generateStateColocationCode(name) {
|
|
1806
|
-
return `function ${name}() {
|
|
1807
|
-
// Only filter needed at this level
|
|
1808
|
-
const [filter, setFilter] = useState('all');
|
|
1809
|
-
|
|
1810
|
-
return (
|
|
1811
|
-
<div>
|
|
1812
|
-
<Header />
|
|
1813
|
-
<Sidebar />
|
|
1814
|
-
{/* SearchBox manages its own state */}
|
|
1815
|
-
<SearchBox />
|
|
1816
|
-
<MainContent filter={filter} />
|
|
1817
|
-
<Footer />
|
|
1818
|
-
</div>
|
|
1819
|
-
);
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
// State colocated with component that uses it
|
|
1823
|
-
function SearchBox() {
|
|
1824
|
-
const [search, setSearch] = useState('');
|
|
1825
|
-
return <input value={search} onChange={e => setSearch(e.target.value)} />;
|
|
1826
|
-
}`;
|
|
1827
|
-
}
|
|
1828
|
-
function generateMonolithCode(name) {
|
|
1829
|
-
return `function ${name}() {
|
|
1830
|
-
const [counter, setCounter] = useState(0);
|
|
1831
|
-
const [data, setData] = useState(null);
|
|
1832
|
-
|
|
1833
|
-
// Counter updates 10x/second
|
|
1834
|
-
useEffect(() => {
|
|
1835
|
-
const id = setInterval(() => setCounter(c => c + 1), 100);
|
|
1836
|
-
return () => clearInterval(id);
|
|
1837
|
-
}, []);
|
|
1838
|
-
|
|
1839
|
-
return (
|
|
1840
|
-
<div>
|
|
1841
|
-
<span>Count: {counter}</span> {/* Updates frequently */}
|
|
1842
|
-
<ExpensiveChart data={data} /> {/* Re-renders unnecessarily! */}
|
|
1843
|
-
<DataTable data={data} /> {/* Re-renders unnecessarily! */}
|
|
1844
|
-
</div>
|
|
1845
|
-
);
|
|
1846
|
-
}`;
|
|
1847
|
-
}
|
|
1848
|
-
function generateExtractedCode(name) {
|
|
1849
|
-
return `function ${name}() {
|
|
1850
|
-
const [data, setData] = useState(null);
|
|
1851
|
-
|
|
1852
|
-
return (
|
|
1853
|
-
<div>
|
|
1854
|
-
<LiveCounter /> {/* Isolated updates */}
|
|
1855
|
-
<ExpensiveChart data={data} /> {/* Only updates when data changes */}
|
|
1856
|
-
<DataTable data={data} /> {/* Only updates when data changes */}
|
|
1857
|
-
</div>
|
|
1858
|
-
);
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
// Extracted component with isolated state
|
|
1862
|
-
function LiveCounter() {
|
|
1863
|
-
const [counter, setCounter] = useState(0);
|
|
1864
|
-
|
|
1865
|
-
useEffect(() => {
|
|
1866
|
-
const id = setInterval(() => setCounter(c => c + 1), 100);
|
|
1867
|
-
return () => clearInterval(id);
|
|
1868
|
-
}, []);
|
|
1869
|
-
|
|
1870
|
-
return <span>Count: {counter}</span>;
|
|
1871
|
-
}`;
|
|
1872
|
-
}
|
|
1873
|
-
var FixSuggester = class extends exports.EventEmitter {
|
|
1874
|
-
/** Active rules */
|
|
1875
|
-
rules;
|
|
1876
|
-
/** Generated suggestions cache */
|
|
1877
|
-
suggestions = /* @__PURE__ */ new Map();
|
|
1878
|
-
/** Rule configuration */
|
|
1879
|
-
ruleConfig = /* @__PURE__ */ new Map();
|
|
1880
|
-
/**
|
|
1881
|
-
* Create a new FixSuggester
|
|
1882
|
-
* @param options - Configuration options
|
|
1883
|
-
*/
|
|
1884
|
-
constructor(options = {}) {
|
|
1885
|
-
super();
|
|
1886
|
-
this.rules = [...BUILTIN_RULES];
|
|
1887
|
-
if (options.rules) {
|
|
1888
|
-
for (const [ruleId, setting] of Object.entries(options.rules)) {
|
|
1889
|
-
this.ruleConfig.set(ruleId, setting);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Analyze a component and generate fix suggestions
|
|
1895
|
-
* @param stats - Component statistics
|
|
1896
|
-
* @returns Array of fix suggestions
|
|
1897
|
-
*/
|
|
1898
|
-
analyze(stats) {
|
|
1899
|
-
const suggestions = [];
|
|
1900
|
-
for (const rule of this.rules) {
|
|
1901
|
-
const config = this.ruleConfig.get(rule.id);
|
|
1902
|
-
if (config === "off") {
|
|
1903
|
-
continue;
|
|
1904
|
-
}
|
|
1905
|
-
if (!rule.detect(stats)) {
|
|
1906
|
-
continue;
|
|
1907
|
-
}
|
|
1908
|
-
const partialSuggestion = rule.suggest(stats);
|
|
1909
|
-
const suggestion = {
|
|
1910
|
-
componentName: stats.name,
|
|
1911
|
-
fix: rule.fixType,
|
|
1912
|
-
...partialSuggestion
|
|
1913
|
-
};
|
|
1914
|
-
if (config === "warn") {
|
|
1915
|
-
suggestion.severity = "warning";
|
|
1916
|
-
} else if (config === "error") {
|
|
1917
|
-
suggestion.severity = "critical";
|
|
1918
|
-
}
|
|
1919
|
-
suggestions.push(suggestion);
|
|
1920
|
-
this.emit("suggestion", suggestion);
|
|
1921
|
-
}
|
|
1922
|
-
suggestions.sort((a, b) => {
|
|
1923
|
-
const severityOrder = { critical: 0, warning: 1, info: 2 };
|
|
1924
|
-
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
1925
|
-
if (severityDiff !== 0) return severityDiff;
|
|
1926
|
-
const ruleA = this.rules.find((r) => r.fixType === a.fix);
|
|
1927
|
-
const ruleB = this.rules.find((r) => r.fixType === b.fix);
|
|
1928
|
-
return (ruleA?.priority ?? 99) - (ruleB?.priority ?? 99);
|
|
1929
|
-
});
|
|
1930
|
-
this.suggestions.set(stats.name, suggestions);
|
|
1931
|
-
return suggestions;
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* Get cached suggestions for a component
|
|
1935
|
-
* @param componentName - Component name
|
|
1936
|
-
* @returns Cached suggestions or empty array
|
|
1937
|
-
*/
|
|
1938
|
-
getSuggestions(componentName) {
|
|
1939
|
-
return this.suggestions.get(componentName) ?? [];
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Get all cached suggestions
|
|
1943
|
-
* @returns All suggestions
|
|
1944
|
-
*/
|
|
1945
|
-
getAllSuggestions() {
|
|
1946
|
-
return Array.from(this.suggestions.values()).flat();
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Get suggestions by severity
|
|
1950
|
-
* @param severity - Severity level
|
|
1951
|
-
* @returns Matching suggestions
|
|
1952
|
-
*/
|
|
1953
|
-
getSuggestionsBySeverity(severity) {
|
|
1954
|
-
return this.getAllSuggestions().filter((s) => s.severity === severity);
|
|
1955
|
-
}
|
|
1956
|
-
/**
|
|
1957
|
-
* Get suggestions by fix type
|
|
1958
|
-
* @param fixType - Fix type
|
|
1959
|
-
* @returns Matching suggestions
|
|
1960
|
-
*/
|
|
1961
|
-
getSuggestionsByType(fixType) {
|
|
1962
|
-
return this.getAllSuggestions().filter((s) => s.fix === fixType);
|
|
1963
|
-
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Clear cached suggestions
|
|
1966
|
-
* @param componentName - Optional component to clear (clears all if not specified)
|
|
1967
|
-
*/
|
|
1968
|
-
clearSuggestions(componentName) {
|
|
1969
|
-
if (componentName) {
|
|
1970
|
-
this.suggestions.delete(componentName);
|
|
1971
|
-
} else {
|
|
1972
|
-
this.suggestions.clear();
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* Configure a rule
|
|
1977
|
-
* @param ruleId - Rule identifier
|
|
1978
|
-
* @param setting - Rule setting
|
|
1979
|
-
*/
|
|
1980
|
-
configureRule(ruleId, setting) {
|
|
1981
|
-
this.ruleConfig.set(ruleId, setting);
|
|
1982
|
-
}
|
|
1983
|
-
/**
|
|
1984
|
-
* Get available rule IDs
|
|
1985
|
-
* @returns Array of rule IDs
|
|
1986
|
-
*/
|
|
1987
|
-
getRuleIds() {
|
|
1988
|
-
return this.rules.map((r) => r.id);
|
|
1989
|
-
}
|
|
1990
|
-
/**
|
|
1991
|
-
* Get rule information
|
|
1992
|
-
* @param ruleId - Rule identifier
|
|
1993
|
-
* @returns Rule info or undefined
|
|
1994
|
-
*/
|
|
1995
|
-
getRule(ruleId) {
|
|
1996
|
-
const rule = this.rules.find((r) => r.id === ruleId);
|
|
1997
|
-
if (!rule) return void 0;
|
|
1998
|
-
return {
|
|
1999
|
-
id: rule.id,
|
|
2000
|
-
name: rule.name,
|
|
2001
|
-
description: rule.description,
|
|
2002
|
-
fixType: rule.fixType
|
|
2003
|
-
};
|
|
2004
|
-
}
|
|
2005
|
-
};
|
|
2006
|
-
|
|
2007
|
-
// src/core/scanner.ts
|
|
2008
|
-
var DEFAULT_CONFIG = {
|
|
2009
|
-
trackUnnecessary: true,
|
|
2010
|
-
fpsThreshold: 30,
|
|
2011
|
-
highlightRenders: true,
|
|
2012
|
-
animationSpeed: "fast"
|
|
2013
|
-
};
|
|
2014
|
-
var DEFAULT_THRESHOLDS2 = {
|
|
2015
|
-
critical: 50,
|
|
2016
|
-
warning: 20,
|
|
2017
|
-
fps: 30
|
|
2018
|
-
};
|
|
2019
|
-
var Scanner = class extends exports.EventEmitter {
|
|
2020
|
-
/** Statistics collector */
|
|
2021
|
-
stats;
|
|
2022
|
-
/** Chain analyzer */
|
|
2023
|
-
chainAnalyzer;
|
|
2024
|
-
/** Fix suggester */
|
|
2025
|
-
fixSuggester;
|
|
2026
|
-
/** Scanner configuration */
|
|
2027
|
-
config;
|
|
2028
|
-
/** Whether scanner is currently running */
|
|
2029
|
-
running = false;
|
|
2030
|
-
/** Last recorded FPS */
|
|
2031
|
-
lastFps = 60;
|
|
2032
|
-
/** FPS tracking */
|
|
2033
|
-
frameCount = 0;
|
|
2034
|
-
lastFpsUpdate = 0;
|
|
2035
|
-
fpsInterval = null;
|
|
2036
|
-
/** Batch processing */
|
|
2037
|
-
renderBatch = [];
|
|
2038
|
-
batchTimeout = null;
|
|
2039
|
-
batchSize = 10;
|
|
2040
|
-
batchDelay = 100;
|
|
2041
|
-
/**
|
|
2042
|
-
* Create a new Scanner instance
|
|
2043
|
-
* @param options - Configuration options
|
|
2044
|
-
*/
|
|
2045
|
-
constructor(options = {}) {
|
|
2046
|
-
super();
|
|
2047
|
-
this.config = { ...DEFAULT_CONFIG, ...options.config };
|
|
2048
|
-
const thresholds = { ...DEFAULT_THRESHOLDS2, ...options.thresholds };
|
|
2049
|
-
this.stats = new StatsCollector(thresholds);
|
|
2050
|
-
this.chainAnalyzer = new ChainAnalyzer();
|
|
2051
|
-
this.fixSuggester = new FixSuggester();
|
|
2052
|
-
this.setupEventForwarding();
|
|
2053
|
-
}
|
|
2054
|
-
/**
|
|
2055
|
-
* Set up event forwarding from sub-modules
|
|
2056
|
-
*/
|
|
2057
|
-
setupEventForwarding() {
|
|
2058
|
-
this.stats.on("update", (stats) => {
|
|
2059
|
-
this.emit("stats", stats);
|
|
2060
|
-
});
|
|
2061
|
-
this.stats.on("severityChange", (change) => {
|
|
2062
|
-
this.emit("severityChange", change);
|
|
2063
|
-
const stats = this.stats.getComponentStats(change.component);
|
|
2064
|
-
if (stats && (change.to === "critical" || change.to === "warning")) {
|
|
2065
|
-
const suggestions = this.fixSuggester.analyze(stats);
|
|
2066
|
-
for (const suggestion of suggestions) {
|
|
2067
|
-
this.emit("fix", suggestion);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
});
|
|
2071
|
-
this.chainAnalyzer.on("chain", (chain) => {
|
|
2072
|
-
this.emit("chain", chain);
|
|
2073
|
-
for (const componentName of chain.chain) {
|
|
2074
|
-
this.stats.setComponentChain(componentName, chain.chain);
|
|
2075
|
-
}
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
/**
|
|
2079
|
-
* Start the scanner
|
|
2080
|
-
*/
|
|
2081
|
-
start() {
|
|
2082
|
-
if (this.running) return;
|
|
2083
|
-
this.running = true;
|
|
2084
|
-
this.lastFpsUpdate = Date.now();
|
|
2085
|
-
this.frameCount = 0;
|
|
2086
|
-
this.startFpsMonitoring();
|
|
2087
|
-
this.emit("start", void 0);
|
|
2088
|
-
}
|
|
2089
|
-
/**
|
|
2090
|
-
* Stop the scanner
|
|
2091
|
-
*/
|
|
2092
|
-
stop() {
|
|
2093
|
-
if (!this.running) return;
|
|
2094
|
-
this.running = false;
|
|
2095
|
-
this.stopFpsMonitoring();
|
|
2096
|
-
this.flushBatch();
|
|
2097
|
-
this.emit("stop", void 0);
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* Reset the scanner, clearing all data
|
|
2101
|
-
*/
|
|
2102
|
-
reset() {
|
|
2103
|
-
this.stop();
|
|
2104
|
-
this.stats.reset();
|
|
2105
|
-
this.chainAnalyzer.reset();
|
|
2106
|
-
this.fixSuggester.clearSuggestions();
|
|
2107
|
-
this.renderBatch = [];
|
|
2108
|
-
this.emit("reset", void 0);
|
|
2109
|
-
}
|
|
2110
|
-
/**
|
|
2111
|
-
* Process a render event
|
|
2112
|
-
* @param render - Render information
|
|
2113
|
-
* @param parent - Optional parent component name
|
|
2114
|
-
*/
|
|
2115
|
-
addRender(render, parent) {
|
|
2116
|
-
if (!this.running) return;
|
|
2117
|
-
this.renderBatch.push(render);
|
|
2118
|
-
this.stats.addRender(render);
|
|
2119
|
-
this.chainAnalyzer.addRender(render, parent);
|
|
2120
|
-
this.emit("render", render);
|
|
2121
|
-
this.frameCount++;
|
|
2122
|
-
this.scheduleBatchProcessing();
|
|
2123
|
-
}
|
|
2124
|
-
/**
|
|
2125
|
-
* Record a frame for FPS calculation
|
|
2126
|
-
*/
|
|
2127
|
-
recordFrame() {
|
|
2128
|
-
this.frameCount++;
|
|
2129
|
-
}
|
|
2130
|
-
/**
|
|
2131
|
-
* Schedule batch processing
|
|
2132
|
-
*/
|
|
2133
|
-
scheduleBatchProcessing() {
|
|
2134
|
-
if (this.batchTimeout) return;
|
|
2135
|
-
if (this.renderBatch.length >= this.batchSize) {
|
|
2136
|
-
this.flushBatch();
|
|
2137
|
-
} else {
|
|
2138
|
-
this.batchTimeout = setTimeout(() => {
|
|
2139
|
-
this.flushBatch();
|
|
2140
|
-
}, this.batchDelay);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
/**
|
|
2144
|
-
* Flush the render batch
|
|
2145
|
-
*/
|
|
2146
|
-
flushBatch() {
|
|
2147
|
-
if (this.batchTimeout) {
|
|
2148
|
-
clearTimeout(this.batchTimeout);
|
|
2149
|
-
this.batchTimeout = null;
|
|
2150
|
-
}
|
|
2151
|
-
if (this.renderBatch.length === 0) return;
|
|
2152
|
-
this.processBatch(this.renderBatch);
|
|
2153
|
-
this.renderBatch = [];
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Process a batch of renders for patterns
|
|
2157
|
-
* @param batch - Render batch
|
|
2158
|
-
*/
|
|
2159
|
-
processBatch(batch) {
|
|
2160
|
-
const byComponent = /* @__PURE__ */ new Map();
|
|
2161
|
-
for (const render of batch) {
|
|
2162
|
-
const existing = byComponent.get(render.componentName) ?? [];
|
|
2163
|
-
existing.push(render);
|
|
2164
|
-
byComponent.set(render.componentName, existing);
|
|
2165
|
-
}
|
|
2166
|
-
for (const [componentName, renders] of byComponent) {
|
|
2167
|
-
if (renders.length >= 3) {
|
|
2168
|
-
const stats = this.stats.getComponentStats(componentName);
|
|
2169
|
-
if (stats) {
|
|
2170
|
-
const suggestions = this.fixSuggester.analyze(stats);
|
|
2171
|
-
for (const suggestion of suggestions) {
|
|
2172
|
-
this.emit("fix", suggestion);
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Start FPS monitoring
|
|
2180
|
-
*/
|
|
2181
|
-
startFpsMonitoring() {
|
|
2182
|
-
this.fpsInterval = setInterval(() => {
|
|
2183
|
-
const now = Date.now();
|
|
2184
|
-
const elapsed = now - this.lastFpsUpdate;
|
|
2185
|
-
if (elapsed > 0) {
|
|
2186
|
-
this.lastFps = Math.round(this.frameCount * 1e3 / elapsed);
|
|
2187
|
-
this.stats.addFpsSample(this.lastFps);
|
|
2188
|
-
if (this.lastFps < this.config.fpsThreshold) {
|
|
2189
|
-
this.emit("fps-drop", this.lastFps);
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
this.frameCount = 0;
|
|
2193
|
-
this.lastFpsUpdate = now;
|
|
2194
|
-
}, 1e3);
|
|
2195
|
-
}
|
|
2196
|
-
/**
|
|
2197
|
-
* Stop FPS monitoring
|
|
2198
|
-
*/
|
|
2199
|
-
stopFpsMonitoring() {
|
|
2200
|
-
if (this.fpsInterval) {
|
|
2201
|
-
clearInterval(this.fpsInterval);
|
|
2202
|
-
this.fpsInterval = null;
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
/**
|
|
2206
|
-
* Get current FPS
|
|
2207
|
-
* @returns Current FPS value
|
|
2208
|
-
*/
|
|
2209
|
-
getFps() {
|
|
2210
|
-
return this.lastFps;
|
|
2211
|
-
}
|
|
2212
|
-
/**
|
|
2213
|
-
* Check if scanner is running
|
|
2214
|
-
* @returns true if running
|
|
2215
|
-
*/
|
|
2216
|
-
isRunning() {
|
|
2217
|
-
return this.running;
|
|
2218
|
-
}
|
|
2219
|
-
/**
|
|
2220
|
-
* Get scanner configuration
|
|
2221
|
-
* @returns Current configuration
|
|
2222
|
-
*/
|
|
2223
|
-
getConfig() {
|
|
2224
|
-
return { ...this.config };
|
|
2225
|
-
}
|
|
2226
|
-
/**
|
|
2227
|
-
* Update scanner configuration
|
|
2228
|
-
* @param config - Partial configuration to update
|
|
2229
|
-
*/
|
|
2230
|
-
configure(config) {
|
|
2231
|
-
this.config = { ...this.config, ...config };
|
|
2232
|
-
}
|
|
2233
|
-
/**
|
|
2234
|
-
* Update threshold configuration
|
|
2235
|
-
* @param thresholds - New thresholds
|
|
2236
|
-
*/
|
|
2237
|
-
setThresholds(thresholds) {
|
|
2238
|
-
this.stats.setThresholds(thresholds);
|
|
2239
|
-
}
|
|
2240
|
-
/**
|
|
2241
|
-
* Get current thresholds
|
|
2242
|
-
* @returns Current threshold configuration
|
|
2243
|
-
*/
|
|
2244
|
-
getThresholds() {
|
|
2245
|
-
return this.stats.getThresholds();
|
|
2246
|
-
}
|
|
2247
|
-
/**
|
|
2248
|
-
* Get component statistics
|
|
2249
|
-
* @param name - Component name (optional, returns all if not specified)
|
|
2250
|
-
* @returns Component stats
|
|
2251
|
-
*/
|
|
2252
|
-
getStats(name) {
|
|
2253
|
-
if (name) {
|
|
2254
|
-
return this.stats.getComponentStats(name);
|
|
2255
|
-
}
|
|
2256
|
-
return this.stats.getAllStats();
|
|
2257
|
-
}
|
|
2258
|
-
/**
|
|
2259
|
-
* Get a snapshot of all stats sorted by severity
|
|
2260
|
-
* @returns Sorted stats array
|
|
2261
|
-
*/
|
|
2262
|
-
getSnapshot() {
|
|
2263
|
-
return this.stats.getSnapshot();
|
|
2264
|
-
}
|
|
2265
|
-
/**
|
|
2266
|
-
* Get session summary
|
|
2267
|
-
* @returns Session summary statistics
|
|
2268
|
-
*/
|
|
2269
|
-
getSummary() {
|
|
2270
|
-
return this.stats.getSummary();
|
|
2271
|
-
}
|
|
2272
|
-
/**
|
|
2273
|
-
* Get top problematic components
|
|
2274
|
-
* @param limit - Maximum number to return
|
|
2275
|
-
* @returns Top problems
|
|
2276
|
-
*/
|
|
2277
|
-
getTopProblems(limit = 10) {
|
|
2278
|
-
return this.stats.getTopProblems(limit);
|
|
2279
|
-
}
|
|
2280
|
-
/**
|
|
2281
|
-
* Get all fix suggestions
|
|
2282
|
-
* @returns All suggestions
|
|
2283
|
-
*/
|
|
2284
|
-
getSuggestions() {
|
|
2285
|
-
return this.fixSuggester.getAllSuggestions();
|
|
2286
|
-
}
|
|
2287
|
-
/**
|
|
2288
|
-
* Get suggestions for a specific component
|
|
2289
|
-
* @param componentName - Component name
|
|
2290
|
-
* @returns Component suggestions
|
|
2291
|
-
*/
|
|
2292
|
-
getComponentSuggestions(componentName) {
|
|
2293
|
-
return this.fixSuggester.getSuggestions(componentName);
|
|
2294
|
-
}
|
|
2295
|
-
/**
|
|
2296
|
-
* Set parent relationship for a component
|
|
2297
|
-
* @param child - Child component name
|
|
2298
|
-
* @param parent - Parent component name
|
|
2299
|
-
*/
|
|
2300
|
-
setParent(child, parent) {
|
|
2301
|
-
this.chainAnalyzer.setParent(child, parent);
|
|
2302
|
-
this.stats.setComponentParent(child, parent);
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Get the render chain for a component
|
|
2306
|
-
* @param componentName - Component name
|
|
2307
|
-
* @returns Render chain
|
|
2308
|
-
*/
|
|
2309
|
-
getComponentChain(componentName) {
|
|
2310
|
-
return this.chainAnalyzer.getComponentChain(componentName);
|
|
2311
|
-
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Get session duration
|
|
2314
|
-
* @returns Duration in milliseconds
|
|
2315
|
-
*/
|
|
2316
|
-
getSessionDuration() {
|
|
2317
|
-
return this.stats.getSessionDuration();
|
|
2318
|
-
}
|
|
2319
|
-
/**
|
|
2320
|
-
* Export scanner data for reporting
|
|
2321
|
-
* @returns Exportable data object
|
|
2322
|
-
*/
|
|
2323
|
-
export() {
|
|
2324
|
-
return {
|
|
2325
|
-
stats: this.stats.export(),
|
|
2326
|
-
suggestions: this.getSuggestions(),
|
|
2327
|
-
config: this.getConfig()
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
/**
|
|
2331
|
-
* Analyze a specific component and generate suggestions
|
|
2332
|
-
* @param componentName - Component name
|
|
2333
|
-
* @returns Fix suggestions for the component
|
|
2334
|
-
*/
|
|
2335
|
-
analyzeComponent(componentName) {
|
|
2336
|
-
const stats = this.stats.getComponentStats(componentName);
|
|
2337
|
-
if (!stats) return [];
|
|
2338
|
-
return this.fixSuggester.analyze(stats);
|
|
2339
|
-
}
|
|
2340
|
-
/**
|
|
2341
|
-
* Analyze all components and generate suggestions
|
|
2342
|
-
* @returns All fix suggestions
|
|
2343
|
-
*/
|
|
2344
|
-
analyzeAll() {
|
|
2345
|
-
const allStats = this.stats.getAllStats();
|
|
2346
|
-
const allSuggestions = [];
|
|
2347
|
-
for (const stats of allStats) {
|
|
2348
|
-
const suggestions = this.fixSuggester.analyze(stats);
|
|
2349
|
-
allSuggestions.push(...suggestions);
|
|
2350
|
-
}
|
|
2351
|
-
return allSuggestions;
|
|
17
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
18
|
+
ErrorCode2["CONFIG_INVALID"] = "CONFIG_INVALID";
|
|
19
|
+
ErrorCode2["CONFIG_NOT_FOUND"] = "CONFIG_NOT_FOUND";
|
|
20
|
+
ErrorCode2["CONNECTION_FAILED"] = "CONNECTION_FAILED";
|
|
21
|
+
ErrorCode2["REACT_NOT_FOUND"] = "REACT_NOT_FOUND";
|
|
22
|
+
ErrorCode2["BROWSER_LAUNCH_FAILED"] = "BROWSER_LAUNCH_FAILED";
|
|
23
|
+
ErrorCode2["WEBSOCKET_ERROR"] = "WEBSOCKET_ERROR";
|
|
24
|
+
ErrorCode2["REPORT_WRITE_FAILED"] = "REPORT_WRITE_FAILED";
|
|
25
|
+
ErrorCode2["INVALID_URL"] = "INVALID_URL";
|
|
26
|
+
ErrorCode2["TIMEOUT"] = "TIMEOUT";
|
|
27
|
+
ErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
28
|
+
return ErrorCode2;
|
|
29
|
+
})(ErrorCode || {});
|
|
30
|
+
var ReactCheckError = class extends Error {
|
|
31
|
+
/** Error code */
|
|
32
|
+
code;
|
|
33
|
+
/** Additional error details */
|
|
34
|
+
details;
|
|
35
|
+
constructor(code, message, details) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "ReactCheckError";
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.details = details;
|
|
2352
40
|
}
|
|
2353
41
|
};
|
|
2354
42
|
|
|
@@ -2452,6 +140,24 @@ function isUserComponent(fiber) {
|
|
|
2452
140
|
const { tag } = fiber;
|
|
2453
141
|
return tag === FiberTag.FunctionComponent || tag === FiberTag.ClassComponent || tag === FiberTag.MemoComponent || tag === FiberTag.SimpleMemoComponent || tag === FiberTag.ForwardRef || tag === FiberTag.LazyComponent;
|
|
2454
142
|
}
|
|
143
|
+
var PERFORMED_WORK_FLAG = 1;
|
|
144
|
+
function didFiberRender(fiber) {
|
|
145
|
+
const prev = fiber.alternate;
|
|
146
|
+
if (!prev) return true;
|
|
147
|
+
switch (fiber.tag) {
|
|
148
|
+
case FiberTag.FunctionComponent:
|
|
149
|
+
case FiberTag.ClassComponent:
|
|
150
|
+
case FiberTag.ContextConsumer:
|
|
151
|
+
case FiberTag.ForwardRef:
|
|
152
|
+
case FiberTag.MemoComponent:
|
|
153
|
+
case FiberTag.SimpleMemoComponent: {
|
|
154
|
+
const flags = fiber.flags ?? fiber.effectTag ?? 0;
|
|
155
|
+
return (flags & PERFORMED_WORK_FLAG) === PERFORMED_WORK_FLAG;
|
|
156
|
+
}
|
|
157
|
+
default:
|
|
158
|
+
return prev.memoizedProps !== fiber.memoizedProps || prev.memoizedState !== fiber.memoizedState;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
2455
161
|
function isHostComponent(fiber) {
|
|
2456
162
|
return fiber.tag === FiberTag.HostComponent;
|
|
2457
163
|
}
|
|
@@ -2768,6 +474,9 @@ function formatRenderTime(ms) {
|
|
|
2768
474
|
}
|
|
2769
475
|
return `${(ms / 1e3).toFixed(2)}s`;
|
|
2770
476
|
}
|
|
477
|
+
function formatDate(date = /* @__PURE__ */ new Date()) {
|
|
478
|
+
return date.toISOString();
|
|
479
|
+
}
|
|
2771
480
|
function pad(str, length, char = " ", position = "right") {
|
|
2772
481
|
if (str.length >= length) {
|
|
2773
482
|
return str;
|
|
@@ -2791,6 +500,11 @@ function escapeHtml(str) {
|
|
|
2791
500
|
};
|
|
2792
501
|
return str.replace(/[&<>"']/g, (char) => escapeMap[char] ?? char);
|
|
2793
502
|
}
|
|
503
|
+
function generateId(prefix = "") {
|
|
504
|
+
const timestamp = Date.now().toString(36);
|
|
505
|
+
const random = Math.random().toString(36).slice(2, 8);
|
|
506
|
+
return prefix ? `${prefix}_${timestamp}${random}` : `${timestamp}${random}`;
|
|
507
|
+
}
|
|
2794
508
|
|
|
2795
509
|
// src/report/markdown.ts
|
|
2796
510
|
function generateMarkdownReport(report) {
|
|
@@ -3502,71 +1216,6 @@ function renderFooter(report) {
|
|
|
3502
1216
|
</footer>
|
|
3503
1217
|
`;
|
|
3504
1218
|
}
|
|
3505
|
-
async function exists(path) {
|
|
3506
|
-
try {
|
|
3507
|
-
await promises.access(path, fs.constants.F_OK);
|
|
3508
|
-
return true;
|
|
3509
|
-
} catch {
|
|
3510
|
-
return false;
|
|
3511
|
-
}
|
|
3512
|
-
}
|
|
3513
|
-
async function readTextFile(path, encoding = "utf-8") {
|
|
3514
|
-
return promises.readFile(path, { encoding });
|
|
3515
|
-
}
|
|
3516
|
-
async function writeTextFile(path$1, content, encoding = "utf-8") {
|
|
3517
|
-
const dir = path.dirname(path$1);
|
|
3518
|
-
await ensureDir(dir);
|
|
3519
|
-
await promises.writeFile(path$1, content, { encoding });
|
|
3520
|
-
}
|
|
3521
|
-
async function readJsonFile(path) {
|
|
3522
|
-
const content = await readTextFile(path);
|
|
3523
|
-
return JSON.parse(content);
|
|
3524
|
-
}
|
|
3525
|
-
async function writeJsonFile(path, data, pretty = true) {
|
|
3526
|
-
const content = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
3527
|
-
await writeTextFile(path, content);
|
|
3528
|
-
}
|
|
3529
|
-
async function ensureDir(path) {
|
|
3530
|
-
if (!await exists(path)) {
|
|
3531
|
-
await promises.mkdir(path, { recursive: true });
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
function getExtension(path$1) {
|
|
3535
|
-
return path.extname(path$1).slice(1);
|
|
3536
|
-
}
|
|
3537
|
-
function getBaseName(path$1) {
|
|
3538
|
-
const ext = path.extname(path$1);
|
|
3539
|
-
return path.basename(path$1, ext);
|
|
3540
|
-
}
|
|
3541
|
-
function resolvePath(base, ...paths) {
|
|
3542
|
-
return path.resolve(base, ...paths);
|
|
3543
|
-
}
|
|
3544
|
-
function joinPath(...paths) {
|
|
3545
|
-
return path.join(...paths);
|
|
3546
|
-
}
|
|
3547
|
-
function getDirName(path$1) {
|
|
3548
|
-
return path.dirname(path$1);
|
|
3549
|
-
}
|
|
3550
|
-
async function findUp(filename, startDir = process.cwd()) {
|
|
3551
|
-
let currentDir = path.resolve(startDir);
|
|
3552
|
-
const root = path.dirname(currentDir);
|
|
3553
|
-
while (currentDir !== root) {
|
|
3554
|
-
const filePath = path.join(currentDir, filename);
|
|
3555
|
-
if (await exists(filePath)) {
|
|
3556
|
-
return filePath;
|
|
3557
|
-
}
|
|
3558
|
-
const parentDir = path.dirname(currentDir);
|
|
3559
|
-
if (parentDir === currentDir) {
|
|
3560
|
-
break;
|
|
3561
|
-
}
|
|
3562
|
-
currentDir = parentDir;
|
|
3563
|
-
}
|
|
3564
|
-
const rootFilePath = path.join(currentDir, filename);
|
|
3565
|
-
if (await exists(rootFilePath)) {
|
|
3566
|
-
return rootFilePath;
|
|
3567
|
-
}
|
|
3568
|
-
return null;
|
|
3569
|
-
}
|
|
3570
1219
|
|
|
3571
1220
|
// src/report/index.ts
|
|
3572
1221
|
function generateReport(report, format) {
|
|
@@ -3578,16 +1227,16 @@ function generateReport(report, format) {
|
|
|
3578
1227
|
case "md":
|
|
3579
1228
|
return generateMarkdownReport(report);
|
|
3580
1229
|
default:
|
|
3581
|
-
throw new Error(`Unknown report format: ${format}`);
|
|
1230
|
+
throw new Error(`Unknown report format: ${String(format)}`);
|
|
3582
1231
|
}
|
|
3583
1232
|
}
|
|
3584
1233
|
async function saveReport(report, format, outputDir, filename) {
|
|
3585
|
-
await ensureDir(outputDir);
|
|
1234
|
+
await chunk3K2AER5M_cjs.ensureDir(outputDir);
|
|
3586
1235
|
const baseName = filename ?? `reactcheck-report-${Date.now()}`;
|
|
3587
1236
|
const extension = format === "md" ? "md" : format;
|
|
3588
|
-
const filePath = joinPath(outputDir, `${baseName}.${extension}`);
|
|
1237
|
+
const filePath = chunk3K2AER5M_cjs.joinPath(outputDir, `${baseName}.${extension}`);
|
|
3589
1238
|
const content = generateReport(report, format);
|
|
3590
|
-
await writeTextFile(filePath, content);
|
|
1239
|
+
await chunk3K2AER5M_cjs.writeTextFile(filePath, content);
|
|
3591
1240
|
return filePath;
|
|
3592
1241
|
}
|
|
3593
1242
|
async function saveReports(report, options) {
|
|
@@ -3595,7 +1244,7 @@ async function saveReports(report, options) {
|
|
|
3595
1244
|
if (!options.enabled) {
|
|
3596
1245
|
return paths;
|
|
3597
1246
|
}
|
|
3598
|
-
await ensureDir(options.output);
|
|
1247
|
+
await chunk3K2AER5M_cjs.ensureDir(options.output);
|
|
3599
1248
|
const baseName = `reactcheck-report-${Date.now()}`;
|
|
3600
1249
|
for (const format of options.formats) {
|
|
3601
1250
|
const path = await saveReport(report, format, options.output, baseName);
|
|
@@ -3672,289 +1321,417 @@ var ReportGenerator = class {
|
|
|
3672
1321
|
}
|
|
3673
1322
|
};
|
|
3674
1323
|
|
|
3675
|
-
// src/
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
name: "next",
|
|
3680
|
-
dependencies: ["next"],
|
|
3681
|
-
features: [
|
|
3682
|
-
{
|
|
3683
|
-
name: "app-router",
|
|
3684
|
-
detect: async (_, dir) => exists(joinPath(dir, "app"))
|
|
3685
|
-
},
|
|
3686
|
-
{
|
|
3687
|
-
name: "pages-router",
|
|
3688
|
-
detect: async (_, dir) => exists(joinPath(dir, "pages"))
|
|
3689
|
-
},
|
|
3690
|
-
{
|
|
3691
|
-
name: "rsc",
|
|
3692
|
-
deps: ["next"],
|
|
3693
|
-
detect: async (pkg) => {
|
|
3694
|
-
const version = pkg.dependencies?.["next"] ?? "";
|
|
3695
|
-
const major = parseInt(version.replace(/[^0-9]/g, "").slice(0, 2), 10);
|
|
3696
|
-
return major >= 13;
|
|
3697
|
-
}
|
|
3698
|
-
},
|
|
3699
|
-
{
|
|
3700
|
-
name: "middleware",
|
|
3701
|
-
detect: async (_, dir) => exists(joinPath(dir, "middleware.ts")) || exists(joinPath(dir, "middleware.js"))
|
|
3702
|
-
}
|
|
3703
|
-
],
|
|
3704
|
-
tips: [
|
|
3705
|
-
'Use "use client" directive only for interactive components',
|
|
3706
|
-
"Keep server components as the default for better performance",
|
|
3707
|
-
"Consider using Server Actions for mutations",
|
|
3708
|
-
"Use next/dynamic for code splitting heavy components",
|
|
3709
|
-
"Avoid passing serializable props through server/client boundary"
|
|
3710
|
-
]
|
|
3711
|
-
},
|
|
3712
|
-
// Remix
|
|
3713
|
-
{
|
|
3714
|
-
name: "remix",
|
|
3715
|
-
dependencies: ["@remix-run/react", "@remix-run/node", "@remix-run/cloudflare"],
|
|
3716
|
-
features: [
|
|
3717
|
-
{
|
|
3718
|
-
name: "v2-routes",
|
|
3719
|
-
detect: async (_, dir) => exists(joinPath(dir, "app", "routes"))
|
|
3720
|
-
},
|
|
3721
|
-
{
|
|
3722
|
-
name: "defer",
|
|
3723
|
-
deps: ["@remix-run/react"],
|
|
3724
|
-
detect: async (pkg) => {
|
|
3725
|
-
const version = pkg.dependencies?.["@remix-run/react"] ?? "";
|
|
3726
|
-
return version.includes("1.") || version.includes("2.");
|
|
3727
|
-
}
|
|
3728
|
-
}
|
|
3729
|
-
],
|
|
3730
|
-
tips: [
|
|
3731
|
-
"Use loader data efficiently to minimize client state",
|
|
3732
|
-
"Prefer fetcher over useNavigate for non-navigation mutations",
|
|
3733
|
-
"Use defer for streaming slow data",
|
|
3734
|
-
"Consider using useFetcher.load for background data fetching",
|
|
3735
|
-
"Avoid useEffect for data fetching, use loaders instead"
|
|
3736
|
-
]
|
|
3737
|
-
},
|
|
3738
|
-
// Vite
|
|
3739
|
-
{
|
|
3740
|
-
name: "vite",
|
|
3741
|
-
dependencies: [],
|
|
3742
|
-
devDependencies: ["vite"],
|
|
3743
|
-
features: [
|
|
3744
|
-
{
|
|
3745
|
-
name: "react-plugin",
|
|
3746
|
-
deps: ["@vitejs/plugin-react", "@vitejs/plugin-react-swc"]
|
|
3747
|
-
},
|
|
3748
|
-
{
|
|
3749
|
-
name: "ssr",
|
|
3750
|
-
detect: async (_, dir) => exists(joinPath(dir, "vite.config.ts")) || exists(joinPath(dir, "vite.config.js"))
|
|
3751
|
-
}
|
|
3752
|
-
],
|
|
3753
|
-
tips: [
|
|
3754
|
-
"Use React.lazy with Suspense for code splitting",
|
|
3755
|
-
"Configure build.rollupOptions.output.manualChunks for optimal chunking",
|
|
3756
|
-
"Enable build.sourcemap only in development",
|
|
3757
|
-
"Use @vitejs/plugin-react-swc for faster builds",
|
|
3758
|
-
"Consider using vite-plugin-pwa for PWA support"
|
|
3759
|
-
]
|
|
3760
|
-
},
|
|
3761
|
-
// Create React App
|
|
3762
|
-
{
|
|
3763
|
-
name: "cra",
|
|
3764
|
-
dependencies: ["react-scripts"],
|
|
3765
|
-
features: [
|
|
3766
|
-
{
|
|
3767
|
-
name: "typescript",
|
|
3768
|
-
deps: ["typescript"]
|
|
3769
|
-
},
|
|
3770
|
-
{
|
|
3771
|
-
name: "testing-library",
|
|
3772
|
-
deps: ["@testing-library/react"]
|
|
3773
|
-
}
|
|
3774
|
-
],
|
|
3775
|
-
tips: [
|
|
3776
|
-
"Consider migrating to Vite for faster development builds",
|
|
3777
|
-
"Use React.lazy for code splitting",
|
|
3778
|
-
'Run "npm run build -- --stats" to analyze bundle size',
|
|
3779
|
-
"Use REACT_APP_ prefix for environment variables",
|
|
3780
|
-
"Consider ejecting only if absolutely necessary"
|
|
3781
|
-
]
|
|
3782
|
-
},
|
|
3783
|
-
// Gatsby
|
|
3784
|
-
{
|
|
3785
|
-
name: "gatsby",
|
|
3786
|
-
dependencies: ["gatsby"],
|
|
3787
|
-
features: [
|
|
3788
|
-
{
|
|
3789
|
-
name: "v5",
|
|
3790
|
-
deps: ["gatsby"],
|
|
3791
|
-
detect: async (pkg) => {
|
|
3792
|
-
const version = pkg.dependencies?.["gatsby"] ?? "";
|
|
3793
|
-
return version.includes("5.") || version.includes("^5");
|
|
3794
|
-
}
|
|
3795
|
-
},
|
|
3796
|
-
{
|
|
3797
|
-
name: "image",
|
|
3798
|
-
deps: ["gatsby-plugin-image"]
|
|
3799
|
-
},
|
|
3800
|
-
{
|
|
3801
|
-
name: "graphql",
|
|
3802
|
-
deps: ["gatsby"]
|
|
3803
|
-
}
|
|
3804
|
-
],
|
|
3805
|
-
tips: [
|
|
3806
|
-
"Use gatsby-plugin-image for optimized images",
|
|
3807
|
-
"Prefer StaticQuery over page queries for reusable components",
|
|
3808
|
-
"Use incremental builds for faster development",
|
|
3809
|
-
"Configure proper caching headers for static assets",
|
|
3810
|
-
"Consider using DSG (Deferred Static Generation) for large sites"
|
|
3811
|
-
]
|
|
3812
|
-
}
|
|
3813
|
-
];
|
|
3814
|
-
async function detectFramework(packageJsonPath) {
|
|
3815
|
-
let pkgPath = packageJsonPath;
|
|
3816
|
-
if (!pkgPath) {
|
|
3817
|
-
pkgPath = await findUp("package.json") ?? void 0;
|
|
3818
|
-
}
|
|
3819
|
-
if (!pkgPath || !await exists(pkgPath)) {
|
|
3820
|
-
return null;
|
|
1324
|
+
// src/utils/colors.ts
|
|
1325
|
+
function checkColorSupport() {
|
|
1326
|
+
if (process.env["FORCE_COLOR"] !== void 0) {
|
|
1327
|
+
return process.env["FORCE_COLOR"] !== "0";
|
|
3821
1328
|
}
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
packageJson = await readJsonFile(pkgPath);
|
|
3825
|
-
} catch {
|
|
3826
|
-
return null;
|
|
1329
|
+
if (process.env["NO_COLOR"] !== void 0) {
|
|
1330
|
+
return false;
|
|
3827
1331
|
}
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
tips: [
|
|
3840
|
-
"Consider using React.memo for frequently re-rendering components",
|
|
3841
|
-
"Use useCallback for event handlers passed to child components",
|
|
3842
|
-
"Use useMemo for expensive computations",
|
|
3843
|
-
"Avoid inline object/array creation in render"
|
|
3844
|
-
]
|
|
3845
|
-
};
|
|
1332
|
+
if (!process.stdout.isTTY) {
|
|
1333
|
+
return false;
|
|
1334
|
+
}
|
|
1335
|
+
if (process.env["TERM"] === "dumb") {
|
|
1336
|
+
return false;
|
|
1337
|
+
}
|
|
1338
|
+
if (process.env["CI"] !== void 0) {
|
|
1339
|
+
const ciEnvs = ["TRAVIS", "CIRCLECI", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE"];
|
|
1340
|
+
return ciEnvs.some((env) => process.env[env] !== void 0);
|
|
1341
|
+
}
|
|
1342
|
+
return true;
|
|
3846
1343
|
}
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
1344
|
+
var supportsColor = checkColorSupport();
|
|
1345
|
+
var colors = {
|
|
1346
|
+
// Reset
|
|
1347
|
+
reset: supportsColor ? "\x1B[0m" : "",
|
|
1348
|
+
// Text styles
|
|
1349
|
+
bold: supportsColor ? "\x1B[1m" : "",
|
|
1350
|
+
dim: supportsColor ? "\x1B[2m" : "",
|
|
1351
|
+
italic: supportsColor ? "\x1B[3m" : "",
|
|
1352
|
+
underline: supportsColor ? "\x1B[4m" : "",
|
|
1353
|
+
blink: supportsColor ? "\x1B[5m" : "",
|
|
1354
|
+
inverse: supportsColor ? "\x1B[7m" : "",
|
|
1355
|
+
hidden: supportsColor ? "\x1B[8m" : "",
|
|
1356
|
+
strikethrough: supportsColor ? "\x1B[9m" : "",
|
|
1357
|
+
// Foreground colors
|
|
1358
|
+
black: supportsColor ? "\x1B[30m" : "",
|
|
1359
|
+
red: supportsColor ? "\x1B[31m" : "",
|
|
1360
|
+
green: supportsColor ? "\x1B[32m" : "",
|
|
1361
|
+
yellow: supportsColor ? "\x1B[33m" : "",
|
|
1362
|
+
blue: supportsColor ? "\x1B[34m" : "",
|
|
1363
|
+
magenta: supportsColor ? "\x1B[35m" : "",
|
|
1364
|
+
cyan: supportsColor ? "\x1B[36m" : "",
|
|
1365
|
+
white: supportsColor ? "\x1B[37m" : "",
|
|
1366
|
+
gray: supportsColor ? "\x1B[90m" : "",
|
|
1367
|
+
grey: supportsColor ? "\x1B[90m" : "",
|
|
1368
|
+
// Bright foreground colors
|
|
1369
|
+
brightRed: supportsColor ? "\x1B[91m" : "",
|
|
1370
|
+
brightGreen: supportsColor ? "\x1B[92m" : "",
|
|
1371
|
+
brightYellow: supportsColor ? "\x1B[93m" : "",
|
|
1372
|
+
brightBlue: supportsColor ? "\x1B[94m" : "",
|
|
1373
|
+
brightMagenta: supportsColor ? "\x1B[95m" : "",
|
|
1374
|
+
brightCyan: supportsColor ? "\x1B[96m" : "",
|
|
1375
|
+
brightWhite: supportsColor ? "\x1B[97m" : "",
|
|
1376
|
+
// Background colors
|
|
1377
|
+
bgBlack: supportsColor ? "\x1B[40m" : "",
|
|
1378
|
+
bgRed: supportsColor ? "\x1B[41m" : "",
|
|
1379
|
+
bgGreen: supportsColor ? "\x1B[42m" : "",
|
|
1380
|
+
bgYellow: supportsColor ? "\x1B[43m" : "",
|
|
1381
|
+
bgBlue: supportsColor ? "\x1B[44m" : "",
|
|
1382
|
+
bgMagenta: supportsColor ? "\x1B[45m" : "",
|
|
1383
|
+
bgCyan: supportsColor ? "\x1B[46m" : "",
|
|
1384
|
+
bgWhite: supportsColor ? "\x1B[47m" : "",
|
|
1385
|
+
bgGray: supportsColor ? "\x1B[100m" : "",
|
|
1386
|
+
// Bright background colors
|
|
1387
|
+
bgBrightRed: supportsColor ? "\x1B[101m" : "",
|
|
1388
|
+
bgBrightGreen: supportsColor ? "\x1B[102m" : "",
|
|
1389
|
+
bgBrightYellow: supportsColor ? "\x1B[103m" : "",
|
|
1390
|
+
bgBrightBlue: supportsColor ? "\x1B[104m" : "",
|
|
1391
|
+
bgBrightMagenta: supportsColor ? "\x1B[105m" : "",
|
|
1392
|
+
bgBrightCyan: supportsColor ? "\x1B[106m" : "",
|
|
1393
|
+
bgBrightWhite: supportsColor ? "\x1B[107m" : ""
|
|
1394
|
+
};
|
|
1395
|
+
function colorize(text, ...codes) {
|
|
1396
|
+
if (!supportsColor || codes.length === 0) {
|
|
1397
|
+
return text;
|
|
3855
1398
|
}
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
1399
|
+
return codes.join("") + text + colors.reset;
|
|
1400
|
+
}
|
|
1401
|
+
function createColorizer(code) {
|
|
1402
|
+
return (text) => colorize(text, code);
|
|
1403
|
+
}
|
|
1404
|
+
var semantic = {
|
|
1405
|
+
/** Critical issues (red) */
|
|
1406
|
+
critical: createColorizer(colors.red),
|
|
1407
|
+
/** Warnings (yellow) */
|
|
1408
|
+
warning: createColorizer(colors.yellow),
|
|
1409
|
+
/** Healthy/success (green) */
|
|
1410
|
+
healthy: createColorizer(colors.green),
|
|
1411
|
+
/** Info/links (blue) */
|
|
1412
|
+
info: createColorizer(colors.blue),
|
|
1413
|
+
/** Secondary text (gray) */
|
|
1414
|
+
secondary: createColorizer(colors.gray),
|
|
1415
|
+
/** Highlighted text (cyan) */
|
|
1416
|
+
highlight: createColorizer(colors.cyan),
|
|
1417
|
+
/** Error text (bright red, bold) */
|
|
1418
|
+
error: (text) => colorize(text, colors.brightRed, colors.bold),
|
|
1419
|
+
/** Success text (bright green, bold) */
|
|
1420
|
+
success: (text) => colorize(text, colors.brightGreen, colors.bold),
|
|
1421
|
+
/** Title text (bold) */
|
|
1422
|
+
title: createColorizer(colors.bold),
|
|
1423
|
+
/** Dimmed text */
|
|
1424
|
+
dimmed: createColorizer(colors.dim)
|
|
1425
|
+
};
|
|
1426
|
+
function stripAnsi(text) {
|
|
1427
|
+
return text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/utils/logger.ts
|
|
1431
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
1432
|
+
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
1433
|
+
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
1434
|
+
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
1435
|
+
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
1436
|
+
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
1437
|
+
return LogLevel2;
|
|
1438
|
+
})(LogLevel || {});
|
|
1439
|
+
var LOG_LEVEL_NAMES = {
|
|
1440
|
+
[0 /* DEBUG */]: "DEBUG",
|
|
1441
|
+
[1 /* INFO */]: "INFO",
|
|
1442
|
+
[2 /* WARN */]: "WARN",
|
|
1443
|
+
[3 /* ERROR */]: "ERROR",
|
|
1444
|
+
[4 /* SILENT */]: "SILENT"
|
|
1445
|
+
};
|
|
1446
|
+
var Logger = class _Logger {
|
|
1447
|
+
prefix;
|
|
1448
|
+
level;
|
|
1449
|
+
showTimestamp;
|
|
1450
|
+
showLevel;
|
|
1451
|
+
output;
|
|
1452
|
+
/**
|
|
1453
|
+
* Create a new Logger instance
|
|
1454
|
+
* @param options - Logger configuration
|
|
1455
|
+
*/
|
|
1456
|
+
constructor(options = {}) {
|
|
1457
|
+
this.prefix = options.prefix ?? "";
|
|
1458
|
+
this.level = options.level ?? 1 /* INFO */;
|
|
1459
|
+
this.showTimestamp = options.showTimestamp ?? false;
|
|
1460
|
+
this.showLevel = options.showLevel ?? true;
|
|
1461
|
+
this.output = options.output ?? {
|
|
1462
|
+
/* eslint-disable no-console */
|
|
1463
|
+
log: (msg) => console.log(msg),
|
|
1464
|
+
warn: (msg) => console.warn(msg),
|
|
1465
|
+
error: (msg) => console.error(msg)
|
|
1466
|
+
/* eslint-enable no-console */
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Format a log message
|
|
1471
|
+
* @param level - Log level
|
|
1472
|
+
* @param message - Message to format
|
|
1473
|
+
* @returns Formatted message
|
|
1474
|
+
*/
|
|
1475
|
+
format(level, message) {
|
|
1476
|
+
const parts = [];
|
|
1477
|
+
if (this.showTimestamp) {
|
|
1478
|
+
const now = /* @__PURE__ */ new Date();
|
|
1479
|
+
const time = now.toISOString().slice(11, 23);
|
|
1480
|
+
parts.push(semantic.secondary(`[${time}]`));
|
|
1481
|
+
}
|
|
1482
|
+
if (this.showLevel) {
|
|
1483
|
+
const levelName = LOG_LEVEL_NAMES[level] ?? "UNKNOWN";
|
|
1484
|
+
let levelStr;
|
|
1485
|
+
switch (level) {
|
|
1486
|
+
case 0 /* DEBUG */:
|
|
1487
|
+
levelStr = semantic.secondary(levelName);
|
|
3867
1488
|
break;
|
|
3868
|
-
|
|
1489
|
+
case 1 /* INFO */:
|
|
1490
|
+
levelStr = semantic.info(levelName);
|
|
1491
|
+
break;
|
|
1492
|
+
case 2 /* WARN */:
|
|
1493
|
+
levelStr = semantic.warning(levelName);
|
|
1494
|
+
break;
|
|
1495
|
+
case 3 /* ERROR */:
|
|
1496
|
+
levelStr = semantic.error(levelName);
|
|
1497
|
+
break;
|
|
1498
|
+
default:
|
|
1499
|
+
levelStr = levelName;
|
|
3869
1500
|
}
|
|
1501
|
+
parts.push(`[${levelStr}]`);
|
|
3870
1502
|
}
|
|
3871
|
-
if (
|
|
3872
|
-
|
|
3873
|
-
detected = await feature.detect(packageJson, projectDir);
|
|
3874
|
-
} catch {
|
|
3875
|
-
}
|
|
1503
|
+
if (this.prefix) {
|
|
1504
|
+
parts.push(semantic.highlight(`[${this.prefix}]`));
|
|
3876
1505
|
}
|
|
3877
|
-
|
|
3878
|
-
|
|
1506
|
+
parts.push(message);
|
|
1507
|
+
return parts.join(" ");
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Log a debug message
|
|
1511
|
+
* @param message - Message to log
|
|
1512
|
+
* @param args - Additional arguments to log
|
|
1513
|
+
*/
|
|
1514
|
+
debug(message, ...args) {
|
|
1515
|
+
if (this.level > 0 /* DEBUG */) return;
|
|
1516
|
+
const formatted = this.format(0 /* DEBUG */, message);
|
|
1517
|
+
if (args.length > 0) {
|
|
1518
|
+
this.output.log(formatted + " " + args.map(String).join(" "));
|
|
1519
|
+
} else {
|
|
1520
|
+
this.output.log(formatted);
|
|
3879
1521
|
}
|
|
3880
1522
|
}
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
case "next":
|
|
3894
|
-
tips.push("Consider using server components to avoid client-side context re-renders");
|
|
3895
|
-
break;
|
|
3896
|
-
case "remix":
|
|
3897
|
-
tips.push("Use loader data instead of context for server data");
|
|
3898
|
-
break;
|
|
3899
|
-
default:
|
|
3900
|
-
tips.push("Split large contexts into smaller, focused contexts");
|
|
1523
|
+
/**
|
|
1524
|
+
* Log an info message
|
|
1525
|
+
* @param message - Message to log
|
|
1526
|
+
* @param args - Additional arguments to log
|
|
1527
|
+
*/
|
|
1528
|
+
info(message, ...args) {
|
|
1529
|
+
if (this.level > 1 /* INFO */) return;
|
|
1530
|
+
const formatted = this.format(1 /* INFO */, message);
|
|
1531
|
+
if (args.length > 0) {
|
|
1532
|
+
this.output.log(formatted + " " + args.map(String).join(" "));
|
|
1533
|
+
} else {
|
|
1534
|
+
this.output.log(formatted);
|
|
3901
1535
|
}
|
|
3902
1536
|
}
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
1537
|
+
/**
|
|
1538
|
+
* Log a warning message
|
|
1539
|
+
* @param message - Message to log
|
|
1540
|
+
* @param args - Additional arguments to log
|
|
1541
|
+
*/
|
|
1542
|
+
warn(message, ...args) {
|
|
1543
|
+
if (this.level > 2 /* WARN */) return;
|
|
1544
|
+
const formatted = this.format(2 /* WARN */, message);
|
|
1545
|
+
if (args.length > 0) {
|
|
1546
|
+
this.output.warn(formatted + " " + args.map(String).join(" "));
|
|
1547
|
+
} else {
|
|
1548
|
+
this.output.warn(formatted);
|
|
3913
1549
|
}
|
|
3914
1550
|
}
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
1551
|
+
/**
|
|
1552
|
+
* Log an error message
|
|
1553
|
+
* @param message - Message to log
|
|
1554
|
+
* @param args - Additional arguments to log
|
|
1555
|
+
*/
|
|
1556
|
+
error(message, ...args) {
|
|
1557
|
+
if (this.level > 3 /* ERROR */) return;
|
|
1558
|
+
const formatted = this.format(3 /* ERROR */, message);
|
|
1559
|
+
if (args.length > 0) {
|
|
1560
|
+
this.output.error(formatted + " " + args.map(String).join(" "));
|
|
1561
|
+
} else {
|
|
1562
|
+
this.output.error(formatted);
|
|
1563
|
+
}
|
|
3920
1564
|
}
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
tips: []
|
|
3930
|
-
};
|
|
1565
|
+
/**
|
|
1566
|
+
* Log a success message (always shown unless silent)
|
|
1567
|
+
* @param message - Message to log
|
|
1568
|
+
*/
|
|
1569
|
+
success(message) {
|
|
1570
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1571
|
+
const prefix = this.prefix ? `[${semantic.highlight(this.prefix)}] ` : "";
|
|
1572
|
+
this.output.log(prefix + semantic.success("\u2713 ") + message);
|
|
3931
1573
|
}
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
};
|
|
1574
|
+
/**
|
|
1575
|
+
* Log a failure message (always shown unless silent)
|
|
1576
|
+
* @param message - Message to log
|
|
1577
|
+
*/
|
|
1578
|
+
fail(message) {
|
|
1579
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1580
|
+
const prefix = this.prefix ? `[${semantic.highlight(this.prefix)}] ` : "";
|
|
1581
|
+
this.output.error(prefix + semantic.error("\u2717 ") + message);
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Create a child logger with a sub-prefix
|
|
1585
|
+
* @param prefix - Sub-prefix for the child logger
|
|
1586
|
+
* @returns New Logger instance
|
|
1587
|
+
*/
|
|
1588
|
+
child(prefix) {
|
|
1589
|
+
const childPrefix = this.prefix ? `${this.prefix}:${prefix}` : prefix;
|
|
1590
|
+
return new _Logger({
|
|
1591
|
+
prefix: childPrefix,
|
|
1592
|
+
level: this.level,
|
|
1593
|
+
showTimestamp: this.showTimestamp,
|
|
1594
|
+
showLevel: this.showLevel,
|
|
1595
|
+
output: this.output
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Set the log level
|
|
1600
|
+
* @param level - New log level
|
|
1601
|
+
*/
|
|
1602
|
+
setLevel(level) {
|
|
1603
|
+
this.level = level;
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Get the current log level
|
|
1607
|
+
* @returns Current log level
|
|
1608
|
+
*/
|
|
1609
|
+
getLevel() {
|
|
1610
|
+
return this.level;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Check if a log level is enabled
|
|
1614
|
+
* @param level - Level to check
|
|
1615
|
+
* @returns true if the level would be logged
|
|
1616
|
+
*/
|
|
1617
|
+
isLevelEnabled(level) {
|
|
1618
|
+
return this.level <= level;
|
|
3939
1619
|
}
|
|
3940
|
-
|
|
1620
|
+
/**
|
|
1621
|
+
* Create a timer for performance logging
|
|
1622
|
+
* @param label - Timer label
|
|
1623
|
+
* @returns Object with end() method to log duration
|
|
1624
|
+
*/
|
|
1625
|
+
time(label) {
|
|
1626
|
+
const start = performance.now();
|
|
3941
1627
|
return {
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
1628
|
+
end: () => {
|
|
1629
|
+
const duration = performance.now() - start;
|
|
1630
|
+
this.debug(`${label}: ${duration.toFixed(2)}ms`);
|
|
1631
|
+
}
|
|
3946
1632
|
};
|
|
3947
1633
|
}
|
|
3948
|
-
|
|
1634
|
+
/**
|
|
1635
|
+
* Log a table of data
|
|
1636
|
+
* @param data - Array of objects to display
|
|
1637
|
+
* @param columns - Optional column names to show
|
|
1638
|
+
*/
|
|
1639
|
+
table(data, columns) {
|
|
1640
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1641
|
+
if (data.length === 0) {
|
|
1642
|
+
this.info("(empty table)");
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const cols = columns ?? Object.keys(data[0] ?? {});
|
|
1646
|
+
if (cols.length === 0) {
|
|
1647
|
+
this.info("(no columns)");
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
const widths = {};
|
|
1651
|
+
for (const col of cols) {
|
|
1652
|
+
widths[col] = col.length;
|
|
1653
|
+
for (const row of data) {
|
|
1654
|
+
const value = formatCell(row[col]);
|
|
1655
|
+
widths[col] = Math.max(widths[col] ?? 0, value.length);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
const header = cols.map((col) => col.padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
1659
|
+
const separator = cols.map((col) => "\u2500".repeat(widths[col] ?? 0)).join("\u2500\u253C\u2500");
|
|
1660
|
+
this.output.log(colors.bold + header + colors.reset);
|
|
1661
|
+
this.output.log(separator);
|
|
1662
|
+
for (const row of data) {
|
|
1663
|
+
const line = cols.map((col) => formatCell(row[col]).padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
1664
|
+
this.output.log(line);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Log a progress message (overwrites previous line)
|
|
1669
|
+
* @param message - Progress message
|
|
1670
|
+
*/
|
|
1671
|
+
progress(message) {
|
|
1672
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1673
|
+
if (process.stdout.isTTY) {
|
|
1674
|
+
process.stdout.write(`\r\x1B[K${message}`);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Clear the progress line
|
|
1679
|
+
*/
|
|
1680
|
+
clearProgress() {
|
|
1681
|
+
if (process.stdout.isTTY) {
|
|
1682
|
+
process.stdout.write("\r\x1B[K");
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Log a newline
|
|
1687
|
+
*/
|
|
1688
|
+
newline() {
|
|
1689
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1690
|
+
this.output.log("");
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Log a horizontal rule
|
|
1694
|
+
* @param char - Character to use for the rule
|
|
1695
|
+
* @param width - Width of the rule
|
|
1696
|
+
*/
|
|
1697
|
+
hr(char = "\u2500", width = 60) {
|
|
1698
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1699
|
+
this.output.log(colors.gray + char.repeat(width) + colors.reset);
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Group related log messages
|
|
1703
|
+
* @param label - Group label
|
|
1704
|
+
* @param fn - Function containing log calls
|
|
1705
|
+
*/
|
|
1706
|
+
group(label, fn) {
|
|
1707
|
+
if (this.level >= 4 /* SILENT */) return;
|
|
1708
|
+
this.output.log(colors.bold + "\u250C " + label + colors.reset);
|
|
1709
|
+
fn();
|
|
1710
|
+
this.output.log(colors.bold + "\u2514" + "\u2500".repeat(label.length + 1) + colors.reset);
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
new Logger({ prefix: "ReactCheck" });
|
|
1714
|
+
function formatCell(value) {
|
|
1715
|
+
if (value === null || value === void 0) return "";
|
|
1716
|
+
if (typeof value === "object") {
|
|
1717
|
+
try {
|
|
1718
|
+
return JSON.stringify(value);
|
|
1719
|
+
} catch {
|
|
1720
|
+
return Object.prototype.toString.call(value);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
switch (typeof value) {
|
|
1724
|
+
case "string":
|
|
1725
|
+
return value;
|
|
1726
|
+
case "number":
|
|
1727
|
+
case "boolean":
|
|
1728
|
+
case "bigint":
|
|
1729
|
+
case "symbol":
|
|
1730
|
+
return value.toString();
|
|
1731
|
+
default:
|
|
1732
|
+
return "[function]";
|
|
1733
|
+
}
|
|
3949
1734
|
}
|
|
3950
|
-
|
|
3951
|
-
// src/utils/index.ts
|
|
3952
|
-
init_colors();
|
|
3953
|
-
init_event_emitter();
|
|
3954
|
-
init_logger();
|
|
3955
|
-
|
|
3956
|
-
// src/server/websocket.ts
|
|
3957
|
-
init_event_emitter();
|
|
3958
1735
|
var OPCODE = {
|
|
3959
1736
|
TEXT: 1,
|
|
3960
1737
|
BINARY: 2,
|
|
@@ -3963,7 +1740,8 @@ var OPCODE = {
|
|
|
3963
1740
|
PONG: 10
|
|
3964
1741
|
};
|
|
3965
1742
|
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
3966
|
-
var
|
|
1743
|
+
var MAX_FRAME_PAYLOAD = 16 * 1024 * 1024;
|
|
1744
|
+
var WebSocketClient = class extends chunk7R4KKJTW_cjs.EventEmitter {
|
|
3967
1745
|
/** Socket connection */
|
|
3968
1746
|
socket;
|
|
3969
1747
|
/** Whether connection is open */
|
|
@@ -3999,7 +1777,7 @@ var WebSocketClient = class extends exports.EventEmitter {
|
|
|
3999
1777
|
* Process received frames
|
|
4000
1778
|
*/
|
|
4001
1779
|
processFrames() {
|
|
4002
|
-
while (this.frameBuffer.length >= 2) {
|
|
1780
|
+
while (this.isOpen && this.frameBuffer.length >= 2) {
|
|
4003
1781
|
const frame = this.parseFrame();
|
|
4004
1782
|
if (!frame) break;
|
|
4005
1783
|
switch (frame.opcode) {
|
|
@@ -4039,8 +1817,18 @@ var WebSocketClient = class extends exports.EventEmitter {
|
|
|
4039
1817
|
offset = 4;
|
|
4040
1818
|
} else if (payloadLength === 127) {
|
|
4041
1819
|
if (this.frameBuffer.length < 10) return null;
|
|
1820
|
+
const high = this.frameBuffer.readUInt32BE(2);
|
|
4042
1821
|
payloadLength = this.frameBuffer.readUInt32BE(6);
|
|
4043
1822
|
offset = 10;
|
|
1823
|
+
if (high !== 0) {
|
|
1824
|
+
payloadLength = Number.POSITIVE_INFINITY;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
if (payloadLength > MAX_FRAME_PAYLOAD) {
|
|
1828
|
+
this.frameBuffer = Buffer.alloc(0);
|
|
1829
|
+
this.close(1009, "Message too big");
|
|
1830
|
+
this.socket.destroy();
|
|
1831
|
+
return null;
|
|
4044
1832
|
}
|
|
4045
1833
|
let maskingKey = null;
|
|
4046
1834
|
if (masked) {
|
|
@@ -4154,7 +1942,7 @@ var WebSocketClient = class extends exports.EventEmitter {
|
|
|
4154
1942
|
return this.isOpen;
|
|
4155
1943
|
}
|
|
4156
1944
|
};
|
|
4157
|
-
var WebSocketServer = class extends
|
|
1945
|
+
var WebSocketServer = class extends chunk7R4KKJTW_cjs.EventEmitter {
|
|
4158
1946
|
/** HTTP server */
|
|
4159
1947
|
server;
|
|
4160
1948
|
/** Connected clients */
|
|
@@ -4238,6 +2026,10 @@ var WebSocketServer = class extends exports.EventEmitter {
|
|
|
4238
2026
|
this.server.once("error", reject);
|
|
4239
2027
|
this.server.listen(this.port, () => {
|
|
4240
2028
|
this.server.removeListener("error", reject);
|
|
2029
|
+
const address = this.server.address();
|
|
2030
|
+
if (address && typeof address === "object") {
|
|
2031
|
+
this.port = address.port;
|
|
2032
|
+
}
|
|
4241
2033
|
this.emit("listening", { port: this.port });
|
|
4242
2034
|
resolve2();
|
|
4243
2035
|
});
|
|
@@ -4257,6 +2049,14 @@ var WebSocketServer = class extends exports.EventEmitter {
|
|
|
4257
2049
|
});
|
|
4258
2050
|
});
|
|
4259
2051
|
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Get the port the server listens on (the real port after start() when
|
|
2054
|
+
* constructed with port 0)
|
|
2055
|
+
* @returns Port number
|
|
2056
|
+
*/
|
|
2057
|
+
getPort() {
|
|
2058
|
+
return this.port;
|
|
2059
|
+
}
|
|
4260
2060
|
/**
|
|
4261
2061
|
* Broadcast message to all clients
|
|
4262
2062
|
* @param message - Message to broadcast
|
|
@@ -4292,26 +2092,75 @@ var WebSocketServer = class extends exports.EventEmitter {
|
|
|
4292
2092
|
};
|
|
4293
2093
|
function handleBrowserMessages(client, handler) {
|
|
4294
2094
|
client.on("message", (data) => {
|
|
2095
|
+
let message;
|
|
4295
2096
|
try {
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
2097
|
+
message = JSON.parse(data);
|
|
2098
|
+
} catch {
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
if (message === null || typeof message !== "object" || typeof message.type !== "string") {
|
|
2102
|
+
return;
|
|
4299
2103
|
}
|
|
2104
|
+
handler(message);
|
|
4300
2105
|
});
|
|
4301
2106
|
}
|
|
2107
|
+
var INJECTION_SCRIPT_FILE = "browser-inject.global.js";
|
|
2108
|
+
function getInjectionScriptCandidates() {
|
|
2109
|
+
const here = path.dirname(url.fileURLToPath(chunkGS7T56RP_cjs.importMetaUrl));
|
|
2110
|
+
return [
|
|
2111
|
+
path.resolve(here, INJECTION_SCRIPT_FILE),
|
|
2112
|
+
path.resolve(here, "..", INJECTION_SCRIPT_FILE),
|
|
2113
|
+
path.resolve(here, "..", "..", "dist", INJECTION_SCRIPT_FILE)
|
|
2114
|
+
];
|
|
2115
|
+
}
|
|
2116
|
+
async function loadInjectionScript(wsPort) {
|
|
2117
|
+
const port = Math.trunc(Number(wsPort));
|
|
2118
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
2119
|
+
throw new RangeError(`Invalid WebSocket port: ${String(wsPort)}`);
|
|
2120
|
+
}
|
|
2121
|
+
for (const candidate of getInjectionScriptCandidates()) {
|
|
2122
|
+
try {
|
|
2123
|
+
const script = await promises.readFile(candidate, "utf8");
|
|
2124
|
+
return `window.__REACTCHECK_PORT__ = ${port};
|
|
2125
|
+
${script}`;
|
|
2126
|
+
} catch {
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
throw new Error(
|
|
2130
|
+
`ReactCheck browser script (${INJECTION_SCRIPT_FILE}) not found next to the installed package. Reinstall @oxog/react-check or run "npm run build" when working from source.`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
4302
2133
|
|
|
4303
2134
|
// src/server/proxy.ts
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
2135
|
+
var logger2 = new Logger({ prefix: "proxy", level: 1 /* INFO */ });
|
|
2136
|
+
var SCANNER_SCRIPT_PATH = "/__reactcheck__/scanner.js";
|
|
2137
|
+
function injectScriptTag(html) {
|
|
2138
|
+
const tag = `<script src="${SCANNER_SCRIPT_PATH}"></script>`;
|
|
2139
|
+
if (html.includes(tag)) return html;
|
|
2140
|
+
const head = /<head(?:\s[^>]*)?>/i.exec(html);
|
|
2141
|
+
if (head) {
|
|
2142
|
+
const at = head.index + head[0].length;
|
|
2143
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
2144
|
+
}
|
|
2145
|
+
const htmlTag = /<html(?:\s[^>]*)?>/i.exec(html);
|
|
2146
|
+
if (htmlTag) {
|
|
2147
|
+
const at = htmlTag.index + htmlTag[0].length;
|
|
2148
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
2149
|
+
}
|
|
2150
|
+
const doctype = /^\s*<!doctype[^>]*>/i.exec(html);
|
|
2151
|
+
if (doctype) {
|
|
2152
|
+
return doctype[0] + tag + html.slice(doctype[0].length);
|
|
2153
|
+
}
|
|
2154
|
+
return tag + html;
|
|
2155
|
+
}
|
|
2156
|
+
var ProxyServer = class extends chunk7R4KKJTW_cjs.EventEmitter {
|
|
4308
2157
|
/** HTTP server instance */
|
|
4309
2158
|
server;
|
|
4310
2159
|
/** Proxy options */
|
|
4311
2160
|
options;
|
|
4312
2161
|
/** Target URL parsed */
|
|
4313
2162
|
targetUrl;
|
|
4314
|
-
/** Injection script */
|
|
2163
|
+
/** Injection script (loaded from the bundled browser script on start() when not provided) */
|
|
4315
2164
|
injectionScript;
|
|
4316
2165
|
/**
|
|
4317
2166
|
* Create a new proxy server
|
|
@@ -4321,101 +2170,18 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4321
2170
|
super();
|
|
4322
2171
|
this.options = options;
|
|
4323
2172
|
this.targetUrl = new url.URL(options.target);
|
|
4324
|
-
this.injectionScript = options.injectionScript ??
|
|
2173
|
+
this.injectionScript = options.injectionScript ?? null;
|
|
4325
2174
|
this.server = http.createServer((req, res) => {
|
|
4326
2175
|
this.handleRequest(req, res).catch((error) => {
|
|
4327
2176
|
logger2.error("Request handling error:", error);
|
|
4328
2177
|
this.emit("error", error);
|
|
4329
2178
|
res.statusCode = 500;
|
|
4330
2179
|
res.end("Internal Server Error");
|
|
4331
|
-
});
|
|
4332
|
-
});
|
|
4333
|
-
this.server.on("error", (error) => {
|
|
4334
|
-
this.emit("error", error);
|
|
4335
|
-
});
|
|
4336
|
-
}
|
|
4337
|
-
/**
|
|
4338
|
-
* Build the injection script
|
|
4339
|
-
* @returns Injection script string
|
|
4340
|
-
*/
|
|
4341
|
-
buildInjectionScript() {
|
|
4342
|
-
const { wsPort } = this.options;
|
|
4343
|
-
return `
|
|
4344
|
-
(function() {
|
|
4345
|
-
if (window.__REACTCHECK_INJECTED__) return;
|
|
4346
|
-
window.__REACTCHECK_INJECTED__ = true;
|
|
4347
|
-
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
4348
|
-
|
|
4349
|
-
// Load the main scanner script
|
|
4350
|
-
const script = document.createElement('script');
|
|
4351
|
-
script.src = '/__reactcheck__/scanner.js';
|
|
4352
|
-
script.async = true;
|
|
4353
|
-
document.head.appendChild(script);
|
|
4354
|
-
|
|
4355
|
-
// Fallback: Connect WebSocket directly if script fails to load
|
|
4356
|
-
script.onerror = function() {
|
|
4357
|
-
console.warn('[ReactCheck] Failed to load scanner script, using minimal mode');
|
|
4358
|
-
connectWebSocket();
|
|
4359
|
-
};
|
|
4360
|
-
|
|
4361
|
-
function connectWebSocket() {
|
|
4362
|
-
const ws = new WebSocket('ws://localhost:${wsPort}');
|
|
4363
|
-
|
|
4364
|
-
ws.onopen = function() {
|
|
4365
|
-
ws.send(JSON.stringify({
|
|
4366
|
-
type: 'ready',
|
|
4367
|
-
payload: { reactVersion: detectReactVersion() }
|
|
4368
|
-
}));
|
|
4369
|
-
};
|
|
4370
|
-
|
|
4371
|
-
ws.onmessage = function(event) {
|
|
4372
|
-
try {
|
|
4373
|
-
const msg = JSON.parse(event.data);
|
|
4374
|
-
handleMessage(msg);
|
|
4375
|
-
} catch (e) {}
|
|
4376
|
-
};
|
|
4377
|
-
|
|
4378
|
-
ws.onerror = function(error) {
|
|
4379
|
-
console.error('[ReactCheck] WebSocket error:', error);
|
|
4380
|
-
};
|
|
4381
|
-
|
|
4382
|
-
ws.onclose = function() {
|
|
4383
|
-
// Try to reconnect after 2 seconds
|
|
4384
|
-
setTimeout(connectWebSocket, 2000);
|
|
4385
|
-
};
|
|
4386
|
-
}
|
|
4387
|
-
|
|
4388
|
-
function detectReactVersion() {
|
|
4389
|
-
if (window.React && window.React.version) {
|
|
4390
|
-
return window.React.version;
|
|
4391
|
-
}
|
|
4392
|
-
if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
4393
|
-
const renderers = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers;
|
|
4394
|
-
if (renderers && renderers.size > 0) {
|
|
4395
|
-
const renderer = renderers.values().next().value;
|
|
4396
|
-
if (renderer && renderer.version) {
|
|
4397
|
-
return renderer.version;
|
|
4398
|
-
}
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
return 'unknown';
|
|
4402
|
-
}
|
|
4403
|
-
|
|
4404
|
-
function handleMessage(msg) {
|
|
4405
|
-
switch (msg.type) {
|
|
4406
|
-
case 'start':
|
|
4407
|
-
console.log('[ReactCheck] Scanning started');
|
|
4408
|
-
break;
|
|
4409
|
-
case 'stop':
|
|
4410
|
-
console.log('[ReactCheck] Scanning stopped');
|
|
4411
|
-
break;
|
|
4412
|
-
case 'config':
|
|
4413
|
-
console.log('[ReactCheck] Config updated:', msg.payload);
|
|
4414
|
-
break;
|
|
4415
|
-
}
|
|
4416
|
-
}
|
|
4417
|
-
})();
|
|
4418
|
-
`;
|
|
2180
|
+
});
|
|
2181
|
+
});
|
|
2182
|
+
this.server.on("error", (error) => {
|
|
2183
|
+
this.emit("error", error);
|
|
2184
|
+
});
|
|
4419
2185
|
}
|
|
4420
2186
|
/**
|
|
4421
2187
|
* Handle incoming request
|
|
@@ -4438,12 +2204,13 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4438
2204
|
* @param res - Server response
|
|
4439
2205
|
*/
|
|
4440
2206
|
handleReactCheckRoute(url, res) {
|
|
4441
|
-
if (url ===
|
|
2207
|
+
if (url === SCANNER_SCRIPT_PATH || url.startsWith(`${SCANNER_SCRIPT_PATH}?`)) {
|
|
4442
2208
|
res.writeHead(200, {
|
|
4443
|
-
"Content-Type": "application/javascript",
|
|
4444
|
-
"Cache-Control": "no-cache"
|
|
2209
|
+
"Content-Type": "application/javascript; charset=utf-8",
|
|
2210
|
+
"Cache-Control": "no-cache",
|
|
2211
|
+
"Access-Control-Allow-Origin": "*"
|
|
4445
2212
|
});
|
|
4446
|
-
res.end(
|
|
2213
|
+
res.end(this.injectionScript ?? "");
|
|
4447
2214
|
return;
|
|
4448
2215
|
}
|
|
4449
2216
|
res.writeHead(404);
|
|
@@ -4471,7 +2238,8 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4471
2238
|
};
|
|
4472
2239
|
const proxyReq = requestFn(options, (proxyRes) => {
|
|
4473
2240
|
const contentType = proxyRes.headers["content-type"] ?? "";
|
|
4474
|
-
|
|
2241
|
+
const contentEncoding = String(proxyRes.headers["content-encoding"] ?? "identity").toLowerCase();
|
|
2242
|
+
if (contentType.includes("text/html") && (contentEncoding === "identity" || contentEncoding === "")) {
|
|
4475
2243
|
this.injectAndRespond(proxyRes, res, targetUrl.href);
|
|
4476
2244
|
resolve2();
|
|
4477
2245
|
return;
|
|
@@ -4500,19 +2268,12 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4500
2268
|
});
|
|
4501
2269
|
proxyRes.on("end", () => {
|
|
4502
2270
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
4503
|
-
|
|
4504
|
-
const scriptTag = `<script>${this.injectionScript}</script>`;
|
|
4505
|
-
if (body.includes("</body>")) {
|
|
4506
|
-
injected = body.replace("</body>", `${scriptTag}</body>`);
|
|
4507
|
-
} else if (body.includes("</head>")) {
|
|
4508
|
-
injected = body.replace("</head>", `${scriptTag}</head>`);
|
|
4509
|
-
} else {
|
|
4510
|
-
injected = body + scriptTag;
|
|
4511
|
-
}
|
|
2271
|
+
const injected = injectScriptTag(body);
|
|
4512
2272
|
this.emit("inject", { url });
|
|
4513
2273
|
const headers = {};
|
|
4514
2274
|
for (const [key, value] of Object.entries(proxyRes.headers)) {
|
|
4515
|
-
|
|
2275
|
+
const lower = key.toLowerCase();
|
|
2276
|
+
if (lower !== "content-length" && lower !== "transfer-encoding" && value !== void 0) {
|
|
4516
2277
|
headers[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
4517
2278
|
}
|
|
4518
2279
|
}
|
|
@@ -4529,11 +2290,18 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4529
2290
|
/**
|
|
4530
2291
|
* Start the proxy server
|
|
4531
2292
|
*/
|
|
4532
|
-
start() {
|
|
2293
|
+
async start() {
|
|
2294
|
+
if (this.injectionScript === null) {
|
|
2295
|
+
this.injectionScript = await loadInjectionScript(this.options.wsPort);
|
|
2296
|
+
}
|
|
4533
2297
|
return new Promise((resolve2, reject) => {
|
|
4534
2298
|
this.server.once("error", reject);
|
|
4535
2299
|
this.server.listen(this.options.port, () => {
|
|
4536
2300
|
this.server.removeListener("error", reject);
|
|
2301
|
+
const address = this.server.address();
|
|
2302
|
+
if (address && typeof address === "object") {
|
|
2303
|
+
this.options.port = address.port;
|
|
2304
|
+
}
|
|
4537
2305
|
this.emit("listening", { port: this.options.port });
|
|
4538
2306
|
logger2.info(`Proxy server listening on http://localhost:${this.options.port}`);
|
|
4539
2307
|
logger2.info(`Proxying to ${this.options.target}`);
|
|
@@ -4568,14 +2336,238 @@ var ProxyServer = class extends exports.EventEmitter {
|
|
|
4568
2336
|
}
|
|
4569
2337
|
};
|
|
4570
2338
|
|
|
4571
|
-
// src/server/
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
2339
|
+
// src/server/browser.ts
|
|
2340
|
+
var logger3 = new Logger({ prefix: "browser", level: 1 /* INFO */ });
|
|
2341
|
+
var BrowserLauncher = class extends chunk7R4KKJTW_cjs.EventEmitter {
|
|
2342
|
+
/** Puppeteer browser instance */
|
|
2343
|
+
browser = null;
|
|
2344
|
+
/** Active page */
|
|
2345
|
+
page = null;
|
|
2346
|
+
/** Launch options */
|
|
2347
|
+
options;
|
|
2348
|
+
/** Injection script */
|
|
2349
|
+
injectionScript = null;
|
|
2350
|
+
/**
|
|
2351
|
+
* Create a new browser launcher
|
|
2352
|
+
* @param options - Launch options
|
|
2353
|
+
*/
|
|
2354
|
+
constructor(options) {
|
|
2355
|
+
super();
|
|
2356
|
+
this.options = {
|
|
2357
|
+
url: options.url,
|
|
2358
|
+
headless: options.headless ?? false,
|
|
2359
|
+
width: options.width ?? 1280,
|
|
2360
|
+
height: options.height ?? 800,
|
|
2361
|
+
wsPort: options.wsPort ?? 3099,
|
|
2362
|
+
args: options.args ?? [],
|
|
2363
|
+
slowMo: options.slowMo ?? 0,
|
|
2364
|
+
timeout: options.timeout ?? 3e4
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Set the injection script
|
|
2369
|
+
* @param script - Script to inject before page loads
|
|
2370
|
+
*/
|
|
2371
|
+
setInjectionScript(script) {
|
|
2372
|
+
this.injectionScript = script;
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Launch the browser
|
|
2376
|
+
*/
|
|
2377
|
+
async launch() {
|
|
2378
|
+
try {
|
|
2379
|
+
const puppeteer = await import('puppeteer');
|
|
2380
|
+
const args = [
|
|
2381
|
+
"--no-sandbox",
|
|
2382
|
+
"--disable-setuid-sandbox",
|
|
2383
|
+
"--disable-dev-shm-usage",
|
|
2384
|
+
"--disable-gpu",
|
|
2385
|
+
"--ignore-certificate-errors",
|
|
2386
|
+
"--ignore-certificate-errors-spki-list",
|
|
2387
|
+
`--window-size=${this.options.width},${this.options.height}`,
|
|
2388
|
+
...this.options.args
|
|
2389
|
+
];
|
|
2390
|
+
this.browser = await puppeteer.default.launch({
|
|
2391
|
+
headless: this.options.headless,
|
|
2392
|
+
args,
|
|
2393
|
+
slowMo: this.options.slowMo,
|
|
2394
|
+
defaultViewport: {
|
|
2395
|
+
width: this.options.width,
|
|
2396
|
+
height: this.options.height
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
const pages = await this.browser.pages();
|
|
2400
|
+
this.page = pages[0] ?? await this.browser.newPage();
|
|
2401
|
+
this.setupPageHandlers();
|
|
2402
|
+
if (this.injectionScript) {
|
|
2403
|
+
logger3.debug("Injecting ReactCheck script into page...");
|
|
2404
|
+
await this.page.evaluateOnNewDocument(this.injectionScript);
|
|
2405
|
+
logger3.debug("Injection script registered");
|
|
2406
|
+
}
|
|
2407
|
+
this.emit("launched", void 0);
|
|
2408
|
+
logger3.info("Browser launched");
|
|
2409
|
+
await this.navigate(this.options.url);
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2412
|
+
this.emit("error", err);
|
|
2413
|
+
throw err;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Set up page event handlers
|
|
2418
|
+
*/
|
|
2419
|
+
setupPageHandlers() {
|
|
2420
|
+
if (!this.page) return;
|
|
2421
|
+
this.page.on("console", (msg) => {
|
|
2422
|
+
this.emit("console", {
|
|
2423
|
+
type: msg.type(),
|
|
2424
|
+
text: msg.text()
|
|
2425
|
+
});
|
|
2426
|
+
});
|
|
2427
|
+
this.page.on("pageerror", (error) => {
|
|
2428
|
+
this.emit("error", error);
|
|
2429
|
+
});
|
|
2430
|
+
this.page.on("framenavigated", (frame) => {
|
|
2431
|
+
if (frame === this.page?.mainFrame()) {
|
|
2432
|
+
this.emit("navigated", { url: frame.url() });
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2435
|
+
this.page.on("load", () => {
|
|
2436
|
+
this.emit("loaded", void 0);
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Navigate to a URL with retry support
|
|
2441
|
+
* @param url - URL to navigate to
|
|
2442
|
+
* @param retries - Number of retries (default: 3)
|
|
2443
|
+
* @param retryDelay - Delay between retries in ms (default: 2000)
|
|
2444
|
+
*/
|
|
2445
|
+
async navigate(url, retries = 3, retryDelay = 2e3) {
|
|
2446
|
+
if (!this.page) {
|
|
2447
|
+
throw new Error("Browser not launched");
|
|
2448
|
+
}
|
|
2449
|
+
let lastError = null;
|
|
2450
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
2451
|
+
try {
|
|
2452
|
+
await this.page.goto(url, {
|
|
2453
|
+
waitUntil: "networkidle2",
|
|
2454
|
+
timeout: this.options.timeout
|
|
2455
|
+
});
|
|
2456
|
+
this.emit("navigated", { url });
|
|
2457
|
+
logger3.info(`Navigated to ${url}`);
|
|
2458
|
+
return;
|
|
2459
|
+
} catch (error) {
|
|
2460
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2461
|
+
this.emit("error", lastError);
|
|
2462
|
+
if (lastError.message.includes("ERR_CONNECTION_REFUSED") && attempt < retries) {
|
|
2463
|
+
logger3.warn(`Connection refused, retrying in ${retryDelay}ms... (${attempt}/${retries})`);
|
|
2464
|
+
await new Promise((resolve2) => setTimeout(resolve2, retryDelay));
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
throw lastError;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
throw lastError ?? new Error("Navigation failed");
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Execute script in page context
|
|
2474
|
+
* @param script - Script to execute
|
|
2475
|
+
* @returns Script result
|
|
2476
|
+
*/
|
|
2477
|
+
async evaluate(script) {
|
|
2478
|
+
if (!this.page) {
|
|
2479
|
+
throw new Error("Browser not launched");
|
|
2480
|
+
}
|
|
2481
|
+
return this.page.evaluate(script);
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* Wait for selector
|
|
2485
|
+
* @param selector - CSS selector
|
|
2486
|
+
* @param timeout - Timeout in ms
|
|
2487
|
+
*/
|
|
2488
|
+
async waitForSelector(selector, timeout) {
|
|
2489
|
+
if (!this.page) {
|
|
2490
|
+
throw new Error("Browser not launched");
|
|
2491
|
+
}
|
|
2492
|
+
await this.page.waitForSelector(selector, {
|
|
2493
|
+
timeout: timeout ?? this.options.timeout
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
/**
|
|
2497
|
+
* Take a screenshot
|
|
2498
|
+
* @param path - File path to save screenshot
|
|
2499
|
+
*/
|
|
2500
|
+
async screenshot(path) {
|
|
2501
|
+
if (!this.page) {
|
|
2502
|
+
throw new Error("Browser not launched");
|
|
2503
|
+
}
|
|
2504
|
+
await this.page.screenshot({ path, fullPage: true });
|
|
2505
|
+
logger3.info(`Screenshot saved to ${path}`);
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Reload the page
|
|
2509
|
+
*/
|
|
2510
|
+
async reload() {
|
|
2511
|
+
if (!this.page) {
|
|
2512
|
+
throw new Error("Browser not launched");
|
|
2513
|
+
}
|
|
2514
|
+
await this.page.reload({ waitUntil: "networkidle2" });
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Get current URL
|
|
2518
|
+
* @returns Current page URL
|
|
2519
|
+
*/
|
|
2520
|
+
getUrl() {
|
|
2521
|
+
return this.page?.url() ?? null;
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Close the browser
|
|
2525
|
+
*/
|
|
2526
|
+
async close() {
|
|
2527
|
+
if (this.browser) {
|
|
2528
|
+
await this.browser.close();
|
|
2529
|
+
this.browser = null;
|
|
2530
|
+
this.page = null;
|
|
2531
|
+
this.emit("closed", void 0);
|
|
2532
|
+
logger3.info("Browser closed");
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Check if browser is open
|
|
2537
|
+
* @returns true if browser is open
|
|
2538
|
+
*/
|
|
2539
|
+
isOpen() {
|
|
2540
|
+
return this.browser !== null && this.browser.connected;
|
|
2541
|
+
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Get the page instance (for advanced usage)
|
|
2544
|
+
* @returns Puppeteer page or null
|
|
2545
|
+
*/
|
|
2546
|
+
getPage() {
|
|
2547
|
+
return this.page;
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Get the browser instance (for advanced usage)
|
|
2551
|
+
* @returns Puppeteer browser or null
|
|
2552
|
+
*/
|
|
2553
|
+
getBrowser() {
|
|
2554
|
+
return this.browser;
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
async function isPuppeteerAvailable() {
|
|
2558
|
+
try {
|
|
2559
|
+
await import('puppeteer');
|
|
2560
|
+
return true;
|
|
2561
|
+
} catch {
|
|
2562
|
+
return false;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
4576
2565
|
|
|
4577
2566
|
// src/browser/overlay.ts
|
|
4578
|
-
|
|
2567
|
+
function escapeOverlayHtml(value) {
|
|
2568
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2569
|
+
}
|
|
2570
|
+
var DEFAULT_CONFIG = {
|
|
4579
2571
|
enabled: true,
|
|
4580
2572
|
highlightRenders: true,
|
|
4581
2573
|
showToolbar: true,
|
|
@@ -4624,10 +2616,14 @@ var Overlay = class _Overlay {
|
|
|
4624
2616
|
* @param config - Overlay configuration
|
|
4625
2617
|
*/
|
|
4626
2618
|
constructor(config = {}) {
|
|
4627
|
-
this.config = { ...
|
|
2619
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
4628
2620
|
}
|
|
4629
2621
|
/** Retry count for init */
|
|
4630
2622
|
initRetryCount = 0;
|
|
2623
|
+
/** Pending init retry timer (document.body not ready yet) */
|
|
2624
|
+
initRetryTimer = null;
|
|
2625
|
+
/** Aborts document-level listeners (drag handling) on destroy */
|
|
2626
|
+
documentListeners = null;
|
|
4631
2627
|
/**
|
|
4632
2628
|
* Initialize the overlay
|
|
4633
2629
|
*/
|
|
@@ -4636,9 +2632,12 @@ var Overlay = class _Overlay {
|
|
|
4636
2632
|
return;
|
|
4637
2633
|
}
|
|
4638
2634
|
if (!document.body) {
|
|
4639
|
-
if (this.initRetryCount < 10) {
|
|
2635
|
+
if (this.initRetryCount < 10 && this.initRetryTimer === null) {
|
|
4640
2636
|
this.initRetryCount++;
|
|
4641
|
-
setTimeout(() =>
|
|
2637
|
+
this.initRetryTimer = setTimeout(() => {
|
|
2638
|
+
this.initRetryTimer = null;
|
|
2639
|
+
this.init();
|
|
2640
|
+
}, 100);
|
|
4642
2641
|
}
|
|
4643
2642
|
return;
|
|
4644
2643
|
}
|
|
@@ -4669,6 +2668,14 @@ var Overlay = class _Overlay {
|
|
|
4669
2668
|
* Destroy the overlay
|
|
4670
2669
|
*/
|
|
4671
2670
|
destroy() {
|
|
2671
|
+
if (this.initRetryTimer !== null) {
|
|
2672
|
+
clearTimeout(this.initRetryTimer);
|
|
2673
|
+
this.initRetryTimer = null;
|
|
2674
|
+
}
|
|
2675
|
+
if (this.documentListeners) {
|
|
2676
|
+
this.documentListeners.abort();
|
|
2677
|
+
this.documentListeners = null;
|
|
2678
|
+
}
|
|
4672
2679
|
if (this.statsInterval) {
|
|
4673
2680
|
clearInterval(this.statsInterval);
|
|
4674
2681
|
this.statsInterval = null;
|
|
@@ -5603,6 +3610,8 @@ var Overlay = class _Overlay {
|
|
|
5603
3610
|
initialX = element.offsetLeft;
|
|
5604
3611
|
initialY = element.offsetTop;
|
|
5605
3612
|
});
|
|
3613
|
+
this.documentListeners ??= new AbortController();
|
|
3614
|
+
const { signal } = this.documentListeners;
|
|
5606
3615
|
document.addEventListener("mousemove", (e) => {
|
|
5607
3616
|
if (!isDragging) return;
|
|
5608
3617
|
const dx = e.clientX - startX;
|
|
@@ -5610,10 +3619,10 @@ var Overlay = class _Overlay {
|
|
|
5610
3619
|
element.style.left = `${initialX + dx}px`;
|
|
5611
3620
|
element.style.top = `${initialY + dy}px`;
|
|
5612
3621
|
element.style.right = "auto";
|
|
5613
|
-
});
|
|
3622
|
+
}, { signal });
|
|
5614
3623
|
document.addEventListener("mouseup", () => {
|
|
5615
3624
|
isDragging = false;
|
|
5616
|
-
});
|
|
3625
|
+
}, { signal });
|
|
5617
3626
|
}
|
|
5618
3627
|
/** Maximum number of highlights to show at once */
|
|
5619
3628
|
static MAX_HIGHLIGHTS = 50;
|
|
@@ -5888,7 +3897,7 @@ var Overlay = class _Overlay {
|
|
|
5888
3897
|
<div class="component-item">
|
|
5889
3898
|
<div class="component-severity" style="background: ${color}"></div>
|
|
5890
3899
|
<div class="component-info">
|
|
5891
|
-
<div class="component-name">${name}</div>
|
|
3900
|
+
<div class="component-name">${escapeOverlayHtml(name)}</div>
|
|
5892
3901
|
<div class="component-meta">${avgTime}ms avg \xB7 ${timeStr}</div>
|
|
5893
3902
|
</div>
|
|
5894
3903
|
<div class="component-count" style="color: ${color}">${tracked.count}</div>
|
|
@@ -5913,11 +3922,11 @@ var Overlay = class _Overlay {
|
|
|
5913
3922
|
return;
|
|
5914
3923
|
}
|
|
5915
3924
|
list.innerHTML = this.renderChains.slice(0, 10).map((chain) => {
|
|
5916
|
-
const flow = chain.chain.map((c) => `<span class="chain-node">${c}</span>`).join('<span class="chain-arrow">\u2192</span>');
|
|
3925
|
+
const flow = chain.chain.map((c) => `<span class="chain-node">${escapeOverlayHtml(c)}</span>`).join('<span class="chain-arrow">\u2192</span>');
|
|
5917
3926
|
return `
|
|
5918
3927
|
<div class="chain-item">
|
|
5919
3928
|
<div class="chain-header">
|
|
5920
|
-
<span class="chain-trigger">${chain.trigger}</span>
|
|
3929
|
+
<span class="chain-trigger">${escapeOverlayHtml(chain.trigger)}</span>
|
|
5921
3930
|
<span class="chain-count">${chain.chain.length} components</span>
|
|
5922
3931
|
</div>
|
|
5923
3932
|
<div class="chain-flow">${flow}</div>
|
|
@@ -5997,21 +4006,19 @@ var Overlay = class _Overlay {
|
|
|
5997
4006
|
};
|
|
5998
4007
|
|
|
5999
4008
|
// src/browser/scanner.ts
|
|
6000
|
-
var
|
|
4009
|
+
var DEFAULT_CONFIG2 = {
|
|
6001
4010
|
trackUnnecessary: true,
|
|
6002
4011
|
fpsThreshold: 30,
|
|
6003
4012
|
highlightRenders: true,
|
|
6004
4013
|
animationSpeed: "fast"
|
|
6005
4014
|
};
|
|
6006
|
-
var BrowserScanner = class extends
|
|
4015
|
+
var BrowserScanner = class extends chunk7R4KKJTW_cjs.EventEmitter {
|
|
6007
4016
|
/** Scanner configuration */
|
|
6008
4017
|
config;
|
|
6009
4018
|
/** Whether scanner is running */
|
|
6010
4019
|
running = false;
|
|
6011
4020
|
/** React version detected */
|
|
6012
4021
|
reactVersion = "unknown";
|
|
6013
|
-
/** Previous fiber states for comparison */
|
|
6014
|
-
prevFiberStates = /* @__PURE__ */ new WeakMap();
|
|
6015
4022
|
/** Component render counts */
|
|
6016
4023
|
renderCounts = /* @__PURE__ */ new Map();
|
|
6017
4024
|
/** Original DevTools hook methods */
|
|
@@ -6027,7 +4034,7 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6027
4034
|
*/
|
|
6028
4035
|
constructor(config = {}, win) {
|
|
6029
4036
|
super();
|
|
6030
|
-
this.config = { ...
|
|
4037
|
+
this.config = { ...DEFAULT_CONFIG2, ...config };
|
|
6031
4038
|
this.win = win ?? (typeof window !== "undefined" ? window : {});
|
|
6032
4039
|
}
|
|
6033
4040
|
/**
|
|
@@ -6038,6 +4045,9 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6038
4045
|
* @returns DOM Element or null
|
|
6039
4046
|
*/
|
|
6040
4047
|
getDOMElement(fiber) {
|
|
4048
|
+
if (typeof Element === "undefined") {
|
|
4049
|
+
return null;
|
|
4050
|
+
}
|
|
6041
4051
|
if (fiber.stateNode instanceof Element) {
|
|
6042
4052
|
return fiber.stateNode;
|
|
6043
4053
|
}
|
|
@@ -6114,7 +4124,6 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6114
4124
|
*/
|
|
6115
4125
|
reset() {
|
|
6116
4126
|
this.renderCounts.clear();
|
|
6117
|
-
this.prevFiberStates = /* @__PURE__ */ new WeakMap();
|
|
6118
4127
|
}
|
|
6119
4128
|
/**
|
|
6120
4129
|
* Hook into React DevTools global hook
|
|
@@ -6125,12 +4134,13 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6125
4134
|
this.installHook();
|
|
6126
4135
|
return;
|
|
6127
4136
|
}
|
|
6128
|
-
|
|
4137
|
+
const original = hook.onCommitFiberRoot;
|
|
4138
|
+
this.originalOnCommitFiberRoot = original;
|
|
6129
4139
|
hook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
|
|
6130
|
-
|
|
6131
|
-
|
|
4140
|
+
original.call(hook, rendererID, root, priorityLevel);
|
|
4141
|
+
if (this.running) {
|
|
4142
|
+
this.processCommit(root.current);
|
|
6132
4143
|
}
|
|
6133
|
-
this.processCommit(root.current);
|
|
6134
4144
|
};
|
|
6135
4145
|
this.reactVersion = this.detectReactVersion(hook);
|
|
6136
4146
|
this.emit("ready", { reactVersion: this.reactVersion });
|
|
@@ -6148,7 +4158,9 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6148
4158
|
return id;
|
|
6149
4159
|
},
|
|
6150
4160
|
onCommitFiberRoot: (_rendererID, root, _priorityLevel) => {
|
|
6151
|
-
this.
|
|
4161
|
+
if (this.running) {
|
|
4162
|
+
this.processCommit(root.current);
|
|
4163
|
+
}
|
|
6152
4164
|
},
|
|
6153
4165
|
onCommitFiberUnmount: () => {
|
|
6154
4166
|
}
|
|
@@ -6182,25 +4194,37 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6182
4194
|
return "unknown";
|
|
6183
4195
|
}
|
|
6184
4196
|
/**
|
|
6185
|
-
* Process a fiber commit (public for IIFE hook integration)
|
|
6186
|
-
*
|
|
4197
|
+
* Process a fiber commit (public for IIFE hook integration).
|
|
4198
|
+
*
|
|
4199
|
+
* Only components that actually rendered in this commit are reported: React
|
|
4200
|
+
* reuses untouched subtrees (their `child` pointer is shared with the
|
|
4201
|
+
* alternate) and bailed-out components do not get the `PerformedWork` flag.
|
|
4202
|
+
* @param rootFiber - Root fiber of the committed tree (`root.current`)
|
|
6187
4203
|
*/
|
|
6188
4204
|
processCommit(rootFiber) {
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
4205
|
+
const stack = [{ fiber: rootFiber, parent: null }];
|
|
4206
|
+
while (stack.length > 0) {
|
|
4207
|
+
const item = stack.pop();
|
|
4208
|
+
if (!item) continue;
|
|
4209
|
+
const { fiber } = item;
|
|
4210
|
+
let parent = item.parent;
|
|
4211
|
+
if (fiber.sibling) {
|
|
4212
|
+
stack.push({ fiber: fiber.sibling, parent: item.parent });
|
|
4213
|
+
}
|
|
4214
|
+
if (isUserComponent(fiber)) {
|
|
4215
|
+
if (fiber.tag !== FiberTag.MemoComponent && didFiberRender(fiber)) {
|
|
4216
|
+
this.processFiber(fiber, parent);
|
|
4217
|
+
}
|
|
4218
|
+
parent = getComponentName(fiber);
|
|
4219
|
+
}
|
|
4220
|
+
const alternate = fiber.alternate;
|
|
4221
|
+
if (alternate && fiber !== rootFiber && fiber.child === alternate.child) {
|
|
4222
|
+
continue;
|
|
4223
|
+
}
|
|
4224
|
+
if (fiber.child) {
|
|
4225
|
+
stack.push({ fiber: fiber.child, parent });
|
|
4226
|
+
}
|
|
6201
4227
|
}
|
|
6202
|
-
this.walkFiber(fiber.child, parent);
|
|
6203
|
-
this.walkFiber(fiber.sibling, parent);
|
|
6204
4228
|
}
|
|
6205
4229
|
/**
|
|
6206
4230
|
* Process a single fiber
|
|
@@ -6212,22 +4236,18 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6212
4236
|
if (this.shouldFilterComponent(componentName)) {
|
|
6213
4237
|
return;
|
|
6214
4238
|
}
|
|
6215
|
-
const
|
|
6216
|
-
const phase =
|
|
4239
|
+
const alternate = fiber.alternate ?? null;
|
|
4240
|
+
const phase = alternate ? "update" : "mount";
|
|
6217
4241
|
const renderInfo = createRenderInfo(
|
|
6218
4242
|
fiber,
|
|
6219
4243
|
phase,
|
|
6220
|
-
|
|
6221
|
-
|
|
4244
|
+
alternate ? alternate.memoizedProps ?? {} : null,
|
|
4245
|
+
alternate ? alternate.memoizedState : void 0
|
|
6222
4246
|
);
|
|
6223
4247
|
const currentCount = this.renderCounts.get(componentName) ?? 0;
|
|
6224
4248
|
const newCount = currentCount + 1;
|
|
6225
4249
|
this.renderCounts.set(componentName, newCount);
|
|
6226
4250
|
renderInfo.renderCount = newCount;
|
|
6227
|
-
this.prevFiberStates.set(fiber, {
|
|
6228
|
-
props: fiber.memoizedProps,
|
|
6229
|
-
state: fiber.memoizedState
|
|
6230
|
-
});
|
|
6231
4251
|
const domElement = this.getDOMElement(fiber);
|
|
6232
4252
|
if (this.overlay && this.config.highlightRenders) {
|
|
6233
4253
|
if (domElement) {
|
|
@@ -6266,13 +4286,7 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6266
4286
|
* @returns true if matches
|
|
6267
4287
|
*/
|
|
6268
4288
|
matchPattern(name, pattern) {
|
|
6269
|
-
|
|
6270
|
-
try {
|
|
6271
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
6272
|
-
return regex.test(name);
|
|
6273
|
-
} catch {
|
|
6274
|
-
return false;
|
|
6275
|
-
}
|
|
4289
|
+
return chunkGE2ZX7I7_cjs.matchComponentPattern(name, pattern);
|
|
6276
4290
|
}
|
|
6277
4291
|
/**
|
|
6278
4292
|
* Get current configuration
|
|
@@ -6319,7 +4333,10 @@ var BrowserScanner = class extends exports.EventEmitter {
|
|
|
6319
4333
|
}
|
|
6320
4334
|
};
|
|
6321
4335
|
|
|
6322
|
-
// src/browser/
|
|
4336
|
+
// src/browser/injector.ts
|
|
4337
|
+
var MAX_QUEUED_MESSAGES = 5e3;
|
|
4338
|
+
var MAX_PENDING_COMMITS = 500;
|
|
4339
|
+
var RECONNECT_DELAY_MS = 2e3;
|
|
6323
4340
|
var ReactCheckInjector = class {
|
|
6324
4341
|
/** Browser scanner instance */
|
|
6325
4342
|
scanner;
|
|
@@ -6333,36 +4350,69 @@ var ReactCheckInjector = class {
|
|
|
6333
4350
|
reconnectTimeout = null;
|
|
6334
4351
|
/** Whether initialized */
|
|
6335
4352
|
initialized = false;
|
|
4353
|
+
/** Whether destroyed (no more reconnects, commits are ignored) */
|
|
4354
|
+
destroyed = false;
|
|
4355
|
+
/** Whether commit processing is paused (CLI sent `stop`) */
|
|
4356
|
+
paused = false;
|
|
4357
|
+
/** Commits received before `init()` */
|
|
4358
|
+
pendingCommits = [];
|
|
4359
|
+
/** Message queue for messages sent before connection */
|
|
4360
|
+
messageQueue = [];
|
|
4361
|
+
/** requestAnimationFrame handle for FPS measurement */
|
|
4362
|
+
rafHandle = null;
|
|
4363
|
+
/** Restores the React DevTools hook to its state before installation */
|
|
4364
|
+
restoreHook = null;
|
|
4365
|
+
/** Window reference */
|
|
4366
|
+
win;
|
|
6336
4367
|
/**
|
|
6337
4368
|
* Create the injector
|
|
4369
|
+
* @param win - Window object (defaults to the global window)
|
|
6338
4370
|
*/
|
|
6339
|
-
constructor() {
|
|
6340
|
-
|
|
6341
|
-
this.wsPort = win.__REACTCHECK_PORT__ ?? 3099;
|
|
4371
|
+
constructor(win) {
|
|
4372
|
+
this.win = win ?? window;
|
|
4373
|
+
this.wsPort = this.win.__REACTCHECK_PORT__ ?? 3099;
|
|
6342
4374
|
this.scanner = new BrowserScanner({
|
|
6343
4375
|
trackUnnecessary: true,
|
|
6344
4376
|
highlightRenders: true,
|
|
6345
4377
|
animationSpeed: "fast"
|
|
6346
|
-
}, win);
|
|
4378
|
+
}, this.win);
|
|
6347
4379
|
this.overlay = new Overlay({
|
|
6348
4380
|
enabled: true,
|
|
6349
4381
|
highlightRenders: true,
|
|
6350
4382
|
showToolbar: true
|
|
6351
4383
|
});
|
|
6352
4384
|
}
|
|
4385
|
+
/**
|
|
4386
|
+
* Feed a committed fiber root to the scanner. Called from the React DevTools
|
|
4387
|
+
* hook installed by {@link installReactCheck}.
|
|
4388
|
+
* @param root - Fiber root passed to `onCommitFiberRoot`
|
|
4389
|
+
*/
|
|
4390
|
+
handleCommit(root) {
|
|
4391
|
+
if (this.destroyed || this.paused || !root?.current) return;
|
|
4392
|
+
if (!this.initialized) {
|
|
4393
|
+
if (this.pendingCommits.length >= MAX_PENDING_COMMITS) {
|
|
4394
|
+
this.pendingCommits.shift();
|
|
4395
|
+
}
|
|
4396
|
+
this.pendingCommits.push(root.current);
|
|
4397
|
+
return;
|
|
4398
|
+
}
|
|
4399
|
+
this.scanner.processCommit(root.current);
|
|
4400
|
+
}
|
|
6353
4401
|
/**
|
|
6354
4402
|
* Initialize the injector
|
|
6355
4403
|
*/
|
|
6356
4404
|
init() {
|
|
6357
|
-
if (this.initialized) return;
|
|
4405
|
+
if (this.initialized || this.destroyed) return;
|
|
6358
4406
|
this.initialized = true;
|
|
6359
4407
|
this.overlay.init();
|
|
6360
4408
|
this.setupScannerEvents();
|
|
6361
4409
|
this.connect();
|
|
6362
|
-
const
|
|
6363
|
-
|
|
6364
|
-
|
|
4410
|
+
const pending = this.pendingCommits;
|
|
4411
|
+
this.pendingCommits = [];
|
|
4412
|
+
for (const fiber of pending) {
|
|
4413
|
+
this.scanner.processCommit(fiber);
|
|
6365
4414
|
}
|
|
4415
|
+
this.startFpsMeasurement();
|
|
6366
4416
|
console.log("[ReactCheck] Initialized");
|
|
6367
4417
|
}
|
|
6368
4418
|
/**
|
|
@@ -6386,16 +4436,46 @@ var ReactCheckInjector = class {
|
|
|
6386
4436
|
});
|
|
6387
4437
|
});
|
|
6388
4438
|
}
|
|
4439
|
+
/**
|
|
4440
|
+
* Measure frames per second with requestAnimationFrame and report it
|
|
4441
|
+
*/
|
|
4442
|
+
startFpsMeasurement() {
|
|
4443
|
+
const raf = this.win.requestAnimationFrame;
|
|
4444
|
+
if (typeof raf !== "function") return;
|
|
4445
|
+
let frames = 0;
|
|
4446
|
+
let windowStart = Date.now();
|
|
4447
|
+
const tick = () => {
|
|
4448
|
+
if (this.destroyed) return;
|
|
4449
|
+
frames++;
|
|
4450
|
+
const now = Date.now();
|
|
4451
|
+
const elapsed = now - windowStart;
|
|
4452
|
+
if (elapsed >= 1e3) {
|
|
4453
|
+
const fps = Math.round(frames * 1e3 / elapsed);
|
|
4454
|
+
frames = 0;
|
|
4455
|
+
windowStart = now;
|
|
4456
|
+
this.overlay.updateFps(fps);
|
|
4457
|
+
if (!this.paused) {
|
|
4458
|
+
this.send({ type: "fps", payload: fps });
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
this.rafHandle = raf.call(this.win, tick);
|
|
4462
|
+
};
|
|
4463
|
+
this.rafHandle = raf.call(this.win, tick);
|
|
4464
|
+
}
|
|
6389
4465
|
/**
|
|
6390
4466
|
* Connect to CLI WebSocket server
|
|
6391
4467
|
*/
|
|
6392
4468
|
connect() {
|
|
4469
|
+
if (this.destroyed) return;
|
|
6393
4470
|
if (this.ws) {
|
|
4471
|
+
this.detachSocket(this.ws);
|
|
6394
4472
|
this.ws.close();
|
|
4473
|
+
this.ws = null;
|
|
6395
4474
|
}
|
|
6396
4475
|
try {
|
|
6397
|
-
|
|
6398
|
-
this.ws
|
|
4476
|
+
const ws = new WebSocket(`ws://localhost:${this.wsPort}`);
|
|
4477
|
+
this.ws = ws;
|
|
4478
|
+
ws.onopen = () => {
|
|
6399
4479
|
console.log("[ReactCheck] Connected to CLI");
|
|
6400
4480
|
if (this.reconnectTimeout) {
|
|
6401
4481
|
clearTimeout(this.reconnectTimeout);
|
|
@@ -6407,7 +4487,7 @@ var ReactCheckInjector = class {
|
|
|
6407
4487
|
});
|
|
6408
4488
|
this.flushMessageQueue();
|
|
6409
4489
|
};
|
|
6410
|
-
|
|
4490
|
+
ws.onmessage = (event) => {
|
|
6411
4491
|
try {
|
|
6412
4492
|
const message = JSON.parse(event.data);
|
|
6413
4493
|
this.handleMessage(message);
|
|
@@ -6415,10 +4495,10 @@ var ReactCheckInjector = class {
|
|
|
6415
4495
|
console.warn("[ReactCheck] Invalid message:", error);
|
|
6416
4496
|
}
|
|
6417
4497
|
};
|
|
6418
|
-
|
|
4498
|
+
ws.onerror = (error) => {
|
|
6419
4499
|
console.warn("[ReactCheck] WebSocket error:", error);
|
|
6420
4500
|
};
|
|
6421
|
-
|
|
4501
|
+
ws.onclose = () => {
|
|
6422
4502
|
console.log("[ReactCheck] Disconnected from CLI");
|
|
6423
4503
|
this.scheduleReconnect();
|
|
6424
4504
|
};
|
|
@@ -6427,16 +4507,28 @@ var ReactCheckInjector = class {
|
|
|
6427
4507
|
this.scheduleReconnect();
|
|
6428
4508
|
}
|
|
6429
4509
|
}
|
|
4510
|
+
/**
|
|
4511
|
+
* Remove event handlers from a socket so that closing it does not trigger
|
|
4512
|
+
* reconnects
|
|
4513
|
+
* @param ws - Socket
|
|
4514
|
+
*/
|
|
4515
|
+
detachSocket(ws) {
|
|
4516
|
+
ws.onopen = null;
|
|
4517
|
+
ws.onmessage = null;
|
|
4518
|
+
ws.onerror = null;
|
|
4519
|
+
ws.onclose = null;
|
|
4520
|
+
}
|
|
6430
4521
|
/**
|
|
6431
4522
|
* Schedule a reconnection attempt
|
|
6432
4523
|
*/
|
|
6433
4524
|
scheduleReconnect() {
|
|
6434
|
-
if (this.reconnectTimeout) return;
|
|
4525
|
+
if (this.reconnectTimeout || this.destroyed) return;
|
|
6435
4526
|
this.reconnectTimeout = setTimeout(() => {
|
|
6436
4527
|
this.reconnectTimeout = null;
|
|
4528
|
+
if (this.destroyed) return;
|
|
6437
4529
|
console.log("[ReactCheck] Attempting to reconnect...");
|
|
6438
4530
|
this.connect();
|
|
6439
|
-
},
|
|
4531
|
+
}, RECONNECT_DELAY_MS);
|
|
6440
4532
|
}
|
|
6441
4533
|
/**
|
|
6442
4534
|
* Handle message from CLI
|
|
@@ -6445,11 +4537,11 @@ var ReactCheckInjector = class {
|
|
|
6445
4537
|
handleMessage(message) {
|
|
6446
4538
|
switch (message.type) {
|
|
6447
4539
|
case "start":
|
|
6448
|
-
this.
|
|
4540
|
+
this.paused = false;
|
|
6449
4541
|
this.overlay.show();
|
|
6450
4542
|
break;
|
|
6451
4543
|
case "stop":
|
|
6452
|
-
this.
|
|
4544
|
+
this.paused = true;
|
|
6453
4545
|
break;
|
|
6454
4546
|
case "reset":
|
|
6455
4547
|
this.scanner.reset();
|
|
@@ -6504,16 +4596,18 @@ var ReactCheckInjector = class {
|
|
|
6504
4596
|
this.overlay.configure({ highlightRenders: config.highlightRenders });
|
|
6505
4597
|
}
|
|
6506
4598
|
}
|
|
6507
|
-
/** Message queue for messages sent before connection */
|
|
6508
|
-
messageQueue = [];
|
|
6509
4599
|
/**
|
|
6510
4600
|
* Send message to CLI
|
|
6511
4601
|
* @param message - Browser message
|
|
6512
4602
|
*/
|
|
6513
4603
|
send(message) {
|
|
4604
|
+
if (this.destroyed) return;
|
|
6514
4605
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
6515
4606
|
this.ws.send(JSON.stringify(message));
|
|
6516
4607
|
} else {
|
|
4608
|
+
if (this.messageQueue.length >= MAX_QUEUED_MESSAGES) {
|
|
4609
|
+
this.messageQueue.shift();
|
|
4610
|
+
}
|
|
6517
4611
|
this.messageQueue.push(message);
|
|
6518
4612
|
}
|
|
6519
4613
|
}
|
|
@@ -6529,226 +4623,383 @@ var ReactCheckInjector = class {
|
|
|
6529
4623
|
}
|
|
6530
4624
|
}
|
|
6531
4625
|
/**
|
|
6532
|
-
*
|
|
4626
|
+
* Register a function that restores the DevTools hook on destroy
|
|
4627
|
+
* @param restore - Restore callback
|
|
4628
|
+
*/
|
|
4629
|
+
setHookRestorer(restore) {
|
|
4630
|
+
this.restoreHook = restore;
|
|
4631
|
+
}
|
|
4632
|
+
/**
|
|
4633
|
+
* Destroy the injector: stops reconnecting, closes the socket, restores the
|
|
4634
|
+
* React DevTools hook, removes the overlay and cancels all timers.
|
|
6533
4635
|
*/
|
|
6534
4636
|
destroy() {
|
|
4637
|
+
if (this.destroyed) return;
|
|
4638
|
+
this.destroyed = true;
|
|
6535
4639
|
if (this.reconnectTimeout) {
|
|
6536
4640
|
clearTimeout(this.reconnectTimeout);
|
|
4641
|
+
this.reconnectTimeout = null;
|
|
4642
|
+
}
|
|
4643
|
+
if (this.rafHandle !== null) {
|
|
4644
|
+
const caf = this.win.cancelAnimationFrame;
|
|
4645
|
+
if (typeof caf === "function") {
|
|
4646
|
+
caf.call(this.win, this.rafHandle);
|
|
4647
|
+
}
|
|
4648
|
+
this.rafHandle = null;
|
|
6537
4649
|
}
|
|
6538
4650
|
if (this.ws) {
|
|
4651
|
+
this.detachSocket(this.ws);
|
|
6539
4652
|
this.ws.close();
|
|
4653
|
+
this.ws = null;
|
|
6540
4654
|
}
|
|
4655
|
+
if (this.restoreHook) {
|
|
4656
|
+
this.restoreHook();
|
|
4657
|
+
this.restoreHook = null;
|
|
4658
|
+
}
|
|
4659
|
+
this.pendingCommits = [];
|
|
4660
|
+
this.messageQueue = [];
|
|
6541
4661
|
this.scanner.stop();
|
|
4662
|
+
this.scanner.removeAllListeners();
|
|
6542
4663
|
this.overlay.destroy();
|
|
6543
4664
|
this.initialized = false;
|
|
6544
4665
|
}
|
|
6545
4666
|
};
|
|
6546
|
-
|
|
6547
|
-
const currentUrl =
|
|
4667
|
+
function installReactCheck(win) {
|
|
4668
|
+
const currentUrl = win.location.href;
|
|
6548
4669
|
if (currentUrl === "about:blank" || currentUrl.startsWith("chrome://") || currentUrl.startsWith("chrome-extension://") || currentUrl.startsWith("devtools://")) {
|
|
6549
|
-
return;
|
|
4670
|
+
return null;
|
|
6550
4671
|
}
|
|
6551
|
-
const win = window;
|
|
6552
4672
|
if (win.__REACTCHECK_INJECTED__) {
|
|
6553
|
-
return;
|
|
4673
|
+
return null;
|
|
6554
4674
|
}
|
|
6555
4675
|
win.__REACTCHECK_INJECTED__ = true;
|
|
6556
|
-
const injector = new ReactCheckInjector();
|
|
6557
|
-
const
|
|
6558
|
-
|
|
6559
|
-
const handleCommit = (root) => {
|
|
6560
|
-
if (injectorReady) {
|
|
6561
|
-
const scanner = injector.scanner;
|
|
6562
|
-
if (scanner) {
|
|
6563
|
-
const fiber = root.current;
|
|
6564
|
-
scanner.processCommit(fiber);
|
|
6565
|
-
}
|
|
6566
|
-
} else {
|
|
6567
|
-
pendingCommits.push({ rendererID: 0, root });
|
|
6568
|
-
}
|
|
6569
|
-
};
|
|
6570
|
-
const processPendingCommits = () => {
|
|
6571
|
-
injectorReady = true;
|
|
6572
|
-
const scanner = injector.scanner;
|
|
6573
|
-
if (scanner) {
|
|
6574
|
-
for (const { root } of pendingCommits) {
|
|
6575
|
-
scanner.processCommit(root.current);
|
|
6576
|
-
}
|
|
6577
|
-
pendingCommits.length = 0;
|
|
6578
|
-
}
|
|
6579
|
-
};
|
|
6580
|
-
if (!win.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
4676
|
+
const injector = new ReactCheckInjector(win);
|
|
4677
|
+
const existingHook = win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
4678
|
+
if (!existingHook) {
|
|
6581
4679
|
const hook = {
|
|
6582
4680
|
renderers: /* @__PURE__ */ new Map(),
|
|
6583
4681
|
supportsFiber: true,
|
|
6584
|
-
inject
|
|
6585
|
-
const id =
|
|
6586
|
-
|
|
4682
|
+
inject(renderer) {
|
|
4683
|
+
const id = hook.renderers.size + 1;
|
|
4684
|
+
hook.renderers.set(id, renderer);
|
|
6587
4685
|
return id;
|
|
6588
4686
|
},
|
|
6589
|
-
onCommitFiberRoot
|
|
6590
|
-
handleCommit(root);
|
|
4687
|
+
onCommitFiberRoot(_rendererID, root) {
|
|
4688
|
+
injector.handleCommit(root);
|
|
6591
4689
|
},
|
|
6592
|
-
onCommitFiberUnmount
|
|
4690
|
+
onCommitFiberUnmount() {
|
|
6593
4691
|
}
|
|
6594
4692
|
};
|
|
6595
4693
|
win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
4694
|
+
injector.setHookRestorer(() => {
|
|
4695
|
+
hook.onCommitFiberRoot = () => {
|
|
4696
|
+
};
|
|
4697
|
+
});
|
|
6596
4698
|
console.log("[ReactCheck] DevTools hook installed");
|
|
6597
4699
|
} else {
|
|
6598
|
-
const
|
|
6599
|
-
const originalOnCommit = existingHook.onCommitFiberRoot.bind(existingHook);
|
|
4700
|
+
const originalOnCommit = existingHook.onCommitFiberRoot;
|
|
6600
4701
|
existingHook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
|
|
6601
|
-
originalOnCommit(rendererID, root, priorityLevel);
|
|
6602
|
-
handleCommit(root);
|
|
4702
|
+
originalOnCommit.call(existingHook, rendererID, root, priorityLevel);
|
|
4703
|
+
injector.handleCommit(root);
|
|
6603
4704
|
};
|
|
4705
|
+
injector.setHookRestorer(() => {
|
|
4706
|
+
existingHook.onCommitFiberRoot = originalOnCommit;
|
|
4707
|
+
});
|
|
6604
4708
|
console.log("[ReactCheck] Wrapped existing DevTools hook");
|
|
6605
4709
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
if (document.readyState === "loading") {
|
|
6610
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
4710
|
+
const doc = win.document;
|
|
4711
|
+
if (doc.readyState === "loading") {
|
|
4712
|
+
doc.addEventListener("DOMContentLoaded", () => {
|
|
6611
4713
|
injector.init();
|
|
6612
|
-
});
|
|
4714
|
+
}, { once: true });
|
|
6613
4715
|
} else {
|
|
6614
4716
|
injector.init();
|
|
6615
4717
|
}
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
// src/index.ts
|
|
6620
|
-
var VERSION = "1.0.0";
|
|
6621
|
-
function createScanner(options = {}) {
|
|
6622
|
-
return new Scanner({
|
|
6623
|
-
thresholds: {
|
|
6624
|
-
critical: options.thresholds?.critical ?? 50,
|
|
6625
|
-
warning: options.thresholds?.warning ?? 20
|
|
6626
|
-
}
|
|
6627
|
-
});
|
|
6628
|
-
}
|
|
6629
|
-
function createReportGenerator(options = {}) {
|
|
6630
|
-
return new ReportGenerator({
|
|
6631
|
-
enabled: true,
|
|
6632
|
-
formats: options.formats ?? ["html", "json"],
|
|
6633
|
-
output: options.output ?? "./reactcheck-reports",
|
|
6634
|
-
includeSourceCode: options.includeSourceCode ?? false
|
|
6635
|
-
});
|
|
4718
|
+
win.__REACTCHECK__ = injector;
|
|
4719
|
+
return injector;
|
|
6636
4720
|
}
|
|
4721
|
+
|
|
4722
|
+
// src/version.ts
|
|
4723
|
+
var VERSION = "1.3.0";
|
|
4724
|
+
|
|
4725
|
+
// src/quick-scan.ts
|
|
6637
4726
|
async function quickScan(url, options = {}) {
|
|
6638
|
-
|
|
6639
|
-
const puppeteerAvailable = await isPuppeteerAvailable2();
|
|
6640
|
-
if (!puppeteerAvailable) {
|
|
4727
|
+
if (!await isPuppeteerAvailable()) {
|
|
6641
4728
|
throw new ReactCheckError(
|
|
6642
4729
|
"BROWSER_LAUNCH_FAILED" /* BROWSER_LAUNCH_FAILED */,
|
|
6643
4730
|
"Puppeteer is required for quickScan. Install it with: npm install puppeteer"
|
|
6644
4731
|
);
|
|
6645
4732
|
}
|
|
6646
|
-
const
|
|
6647
|
-
url,
|
|
6648
|
-
headless: options.headless ?? true
|
|
6649
|
-
});
|
|
4733
|
+
const target = url.includes("://") ? url : `http://${url}`;
|
|
6650
4734
|
const duration = options.duration ?? 3e4;
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
4735
|
+
const startTime = Date.now();
|
|
4736
|
+
const scanner = new chunkGE2ZX7I7_cjs.Scanner({
|
|
4737
|
+
thresholds: {
|
|
4738
|
+
critical: options.thresholds?.critical ?? 50,
|
|
4739
|
+
warning: options.thresholds?.warning ?? 20,
|
|
4740
|
+
...options.thresholds?.fps !== void 0 ? { fps: options.thresholds.fps } : {}
|
|
4741
|
+
},
|
|
4742
|
+
config: {
|
|
4743
|
+
...options.include ? { include: options.include } : {},
|
|
4744
|
+
...options.exclude ? { exclude: options.exclude } : {}
|
|
4745
|
+
}
|
|
4746
|
+
});
|
|
4747
|
+
const chains = [];
|
|
4748
|
+
const suggestions = [];
|
|
4749
|
+
scanner.on("chain", (chain) => {
|
|
4750
|
+
chains.push(chain);
|
|
4751
|
+
});
|
|
4752
|
+
scanner.on("fix", (suggestion) => {
|
|
4753
|
+
if (!suggestions.some((s) => s.componentName === suggestion.componentName && s.fix === suggestion.fix)) {
|
|
4754
|
+
suggestions.push(suggestion);
|
|
4755
|
+
}
|
|
6663
4756
|
});
|
|
6664
|
-
|
|
6665
|
-
|
|
4757
|
+
const wsServer = new WebSocketServer(options.port ?? 0);
|
|
4758
|
+
let launcher = null;
|
|
4759
|
+
try {
|
|
4760
|
+
await wsServer.start();
|
|
4761
|
+
wsServer.on("connection", (client) => {
|
|
4762
|
+
handleBrowserMessages(client, (message) => {
|
|
4763
|
+
switch (message.type) {
|
|
4764
|
+
case "render":
|
|
4765
|
+
scanner.addRender(message.payload);
|
|
4766
|
+
break;
|
|
4767
|
+
case "fps":
|
|
4768
|
+
scanner.recordFps(message.payload);
|
|
4769
|
+
break;
|
|
4770
|
+
case "ready":
|
|
4771
|
+
client.send(JSON.stringify({ type: "start" }));
|
|
4772
|
+
break;
|
|
4773
|
+
default:
|
|
4774
|
+
break;
|
|
4775
|
+
}
|
|
4776
|
+
});
|
|
4777
|
+
});
|
|
4778
|
+
scanner.start();
|
|
4779
|
+
launcher = new BrowserLauncher({
|
|
4780
|
+
url: target,
|
|
4781
|
+
headless: options.headless ?? true,
|
|
4782
|
+
wsPort: wsServer.getPort(),
|
|
4783
|
+
...options.browserArgs ? { args: options.browserArgs } : {}
|
|
4784
|
+
});
|
|
4785
|
+
launcher.on("error", () => {
|
|
4786
|
+
});
|
|
4787
|
+
launcher.setInjectionScript(await loadInjectionScript(wsServer.getPort()));
|
|
4788
|
+
try {
|
|
4789
|
+
await launcher.launch();
|
|
4790
|
+
} catch (error) {
|
|
4791
|
+
throw new ReactCheckError(
|
|
4792
|
+
"BROWSER_LAUNCH_FAILED" /* BROWSER_LAUNCH_FAILED */,
|
|
4793
|
+
`Could not open ${target}: ${error instanceof Error ? error.message : String(error)}`
|
|
4794
|
+
);
|
|
4795
|
+
}
|
|
4796
|
+
await new Promise((resolve2) => setTimeout(resolve2, duration));
|
|
4797
|
+
} finally {
|
|
4798
|
+
scanner.stop();
|
|
4799
|
+
if (launcher) {
|
|
4800
|
+
await launcher.close().catch(() => void 0);
|
|
4801
|
+
}
|
|
4802
|
+
await wsServer.stop();
|
|
4803
|
+
}
|
|
4804
|
+
const exported = scanner.export();
|
|
4805
|
+
if (exported.stats.summary.totalRenders === 0) {
|
|
6666
4806
|
throw new ReactCheckError(
|
|
6667
4807
|
"REACT_NOT_FOUND" /* REACT_NOT_FOUND */,
|
|
6668
|
-
"
|
|
4808
|
+
"No React renders were observed. Make sure the page uses React (development or production build) and is reachable."
|
|
6669
4809
|
);
|
|
6670
4810
|
}
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
4811
|
+
const report = {
|
|
4812
|
+
version: VERSION,
|
|
4813
|
+
generated: formatDate(),
|
|
4814
|
+
session: {
|
|
4815
|
+
url: target,
|
|
4816
|
+
duration: Date.now() - startTime,
|
|
4817
|
+
timestamp: formatDate(new Date(startTime)),
|
|
4818
|
+
id: generateId("scan")
|
|
4819
|
+
},
|
|
4820
|
+
summary: exported.stats.summary,
|
|
4821
|
+
components: exported.stats.components,
|
|
4822
|
+
chains,
|
|
4823
|
+
timeline: [],
|
|
4824
|
+
framework: null,
|
|
4825
|
+
suggestions
|
|
4826
|
+
};
|
|
4827
|
+
if (options.output) {
|
|
4828
|
+
const generator = new ReportGenerator({
|
|
4829
|
+
enabled: true,
|
|
4830
|
+
formats: options.formats ?? ["html", "json"],
|
|
4831
|
+
output: options.output,
|
|
4832
|
+
includeSourceCode: false
|
|
6680
4833
|
});
|
|
6681
|
-
await generator.saveAll(
|
|
4834
|
+
await generator.saveAll(report);
|
|
6682
4835
|
}
|
|
6683
|
-
return
|
|
4836
|
+
return report;
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4839
|
+
// src/index.ts
|
|
4840
|
+
function createScanner(options = {}) {
|
|
4841
|
+
const config = {};
|
|
4842
|
+
if (options.include) config.include = options.include;
|
|
4843
|
+
if (options.exclude) config.exclude = options.exclude;
|
|
4844
|
+
return new chunkGE2ZX7I7_cjs.Scanner({
|
|
4845
|
+
thresholds: {
|
|
4846
|
+
critical: options.thresholds?.critical ?? 50,
|
|
4847
|
+
warning: options.thresholds?.warning ?? 20,
|
|
4848
|
+
...options.thresholds?.fps !== void 0 ? { fps: options.thresholds.fps } : {}
|
|
4849
|
+
},
|
|
4850
|
+
config
|
|
4851
|
+
});
|
|
4852
|
+
}
|
|
4853
|
+
function createReportGenerator(options = {}) {
|
|
4854
|
+
return new ReportGenerator({
|
|
4855
|
+
enabled: true,
|
|
4856
|
+
formats: options.formats ?? ["html", "json"],
|
|
4857
|
+
output: options.output ?? "./reactcheck-reports",
|
|
4858
|
+
includeSourceCode: options.includeSourceCode ?? false
|
|
4859
|
+
});
|
|
6684
4860
|
}
|
|
6685
4861
|
|
|
4862
|
+
Object.defineProperty(exports, "Scanner", {
|
|
4863
|
+
enumerable: true,
|
|
4864
|
+
get: function () { return chunkGE2ZX7I7_cjs.Scanner; }
|
|
4865
|
+
});
|
|
4866
|
+
Object.defineProperty(exports, "StatsCollector", {
|
|
4867
|
+
enumerable: true,
|
|
4868
|
+
get: function () { return chunkGE2ZX7I7_cjs.StatsCollector; }
|
|
4869
|
+
});
|
|
4870
|
+
Object.defineProperty(exports, "matchComponentPattern", {
|
|
4871
|
+
enumerable: true,
|
|
4872
|
+
get: function () { return chunkGE2ZX7I7_cjs.matchComponentPattern; }
|
|
4873
|
+
});
|
|
4874
|
+
Object.defineProperty(exports, "ChainAnalyzer", {
|
|
4875
|
+
enumerable: true,
|
|
4876
|
+
get: function () { return chunkDWM55ACO_cjs.ChainAnalyzer; }
|
|
4877
|
+
});
|
|
4878
|
+
Object.defineProperty(exports, "FixSuggester", {
|
|
4879
|
+
enumerable: true,
|
|
4880
|
+
get: function () { return chunkG7YVIPS7_cjs.FixSuggester; }
|
|
4881
|
+
});
|
|
4882
|
+
Object.defineProperty(exports, "EventEmitter", {
|
|
4883
|
+
enumerable: true,
|
|
4884
|
+
get: function () { return chunk7R4KKJTW_cjs.EventEmitter; }
|
|
4885
|
+
});
|
|
4886
|
+
Object.defineProperty(exports, "detectFramework", {
|
|
4887
|
+
enumerable: true,
|
|
4888
|
+
get: function () { return chunk3K2AER5M_cjs.detectFramework; }
|
|
4889
|
+
});
|
|
4890
|
+
Object.defineProperty(exports, "detectFrameworkFromWindow", {
|
|
4891
|
+
enumerable: true,
|
|
4892
|
+
get: function () { return chunk3K2AER5M_cjs.detectFrameworkFromWindow; }
|
|
4893
|
+
});
|
|
4894
|
+
Object.defineProperty(exports, "ensureDir", {
|
|
4895
|
+
enumerable: true,
|
|
4896
|
+
get: function () { return chunk3K2AER5M_cjs.ensureDir; }
|
|
4897
|
+
});
|
|
4898
|
+
Object.defineProperty(exports, "exists", {
|
|
4899
|
+
enumerable: true,
|
|
4900
|
+
get: function () { return chunk3K2AER5M_cjs.exists; }
|
|
4901
|
+
});
|
|
4902
|
+
Object.defineProperty(exports, "findUp", {
|
|
4903
|
+
enumerable: true,
|
|
4904
|
+
get: function () { return chunk3K2AER5M_cjs.findUp; }
|
|
4905
|
+
});
|
|
4906
|
+
Object.defineProperty(exports, "frameworkDetectors", {
|
|
4907
|
+
enumerable: true,
|
|
4908
|
+
get: function () { return chunk3K2AER5M_cjs.FRAMEWORK_DETECTORS; }
|
|
4909
|
+
});
|
|
4910
|
+
Object.defineProperty(exports, "getBaseName", {
|
|
4911
|
+
enumerable: true,
|
|
4912
|
+
get: function () { return chunk3K2AER5M_cjs.getBaseName; }
|
|
4913
|
+
});
|
|
4914
|
+
Object.defineProperty(exports, "getDirName", {
|
|
4915
|
+
enumerable: true,
|
|
4916
|
+
get: function () { return chunk3K2AER5M_cjs.getDirName; }
|
|
4917
|
+
});
|
|
4918
|
+
Object.defineProperty(exports, "getExtension", {
|
|
4919
|
+
enumerable: true,
|
|
4920
|
+
get: function () { return chunk3K2AER5M_cjs.getExtension; }
|
|
4921
|
+
});
|
|
4922
|
+
Object.defineProperty(exports, "getFrameworkTips", {
|
|
4923
|
+
enumerable: true,
|
|
4924
|
+
get: function () { return chunk3K2AER5M_cjs.getFrameworkTips; }
|
|
4925
|
+
});
|
|
4926
|
+
Object.defineProperty(exports, "joinPath", {
|
|
4927
|
+
enumerable: true,
|
|
4928
|
+
get: function () { return chunk3K2AER5M_cjs.joinPath; }
|
|
4929
|
+
});
|
|
4930
|
+
Object.defineProperty(exports, "readJsonFile", {
|
|
4931
|
+
enumerable: true,
|
|
4932
|
+
get: function () { return chunk3K2AER5M_cjs.readJsonFile; }
|
|
4933
|
+
});
|
|
4934
|
+
Object.defineProperty(exports, "readTextFile", {
|
|
4935
|
+
enumerable: true,
|
|
4936
|
+
get: function () { return chunk3K2AER5M_cjs.readTextFile; }
|
|
4937
|
+
});
|
|
4938
|
+
Object.defineProperty(exports, "resolvePath", {
|
|
4939
|
+
enumerable: true,
|
|
4940
|
+
get: function () { return chunk3K2AER5M_cjs.resolvePath; }
|
|
4941
|
+
});
|
|
4942
|
+
Object.defineProperty(exports, "writeJsonFile", {
|
|
4943
|
+
enumerable: true,
|
|
4944
|
+
get: function () { return chunk3K2AER5M_cjs.writeJsonFile; }
|
|
4945
|
+
});
|
|
4946
|
+
Object.defineProperty(exports, "writeTextFile", {
|
|
4947
|
+
enumerable: true,
|
|
4948
|
+
get: function () { return chunk3K2AER5M_cjs.writeTextFile; }
|
|
4949
|
+
});
|
|
4950
|
+
exports.BrowserLauncher = BrowserLauncher;
|
|
6686
4951
|
exports.BrowserScanner = BrowserScanner;
|
|
6687
|
-
exports.ChainAnalyzer = ChainAnalyzer;
|
|
6688
4952
|
exports.ErrorCode = ErrorCode;
|
|
6689
4953
|
exports.FiberTag = FiberTag;
|
|
6690
|
-
exports.
|
|
4954
|
+
exports.LogLevel = LogLevel;
|
|
4955
|
+
exports.Logger = Logger;
|
|
6691
4956
|
exports.Overlay = Overlay;
|
|
6692
4957
|
exports.ProxyServer = ProxyServer;
|
|
6693
4958
|
exports.ReactCheckError = ReactCheckError;
|
|
6694
4959
|
exports.ReactCheckInjector = ReactCheckInjector;
|
|
6695
4960
|
exports.ReportGenerator = ReportGenerator;
|
|
6696
|
-
exports.Scanner = Scanner;
|
|
6697
|
-
exports.StatsCollector = StatsCollector;
|
|
6698
4961
|
exports.VERSION = VERSION;
|
|
6699
4962
|
exports.WebSocketClient = WebSocketClient;
|
|
6700
4963
|
exports.WebSocketServer = WebSocketServer;
|
|
4964
|
+
exports.colors = colors;
|
|
6701
4965
|
exports.createRenderInfo = createRenderInfo;
|
|
6702
4966
|
exports.createReportGenerator = createReportGenerator;
|
|
6703
4967
|
exports.createScanner = createScanner;
|
|
6704
|
-
exports.detectFramework = detectFramework;
|
|
6705
|
-
exports.detectFrameworkFromWindow = detectFrameworkFromWindow;
|
|
6706
|
-
exports.ensureDir = ensureDir;
|
|
6707
4968
|
exports.escapeHtml = escapeHtml;
|
|
6708
|
-
exports.exists = exists;
|
|
6709
4969
|
exports.findFiberByName = findFiberByName;
|
|
6710
|
-
exports.findUp = findUp;
|
|
6711
4970
|
exports.formatBytes = formatBytes;
|
|
6712
4971
|
exports.formatDuration = formatDuration;
|
|
6713
4972
|
exports.formatNumber = formatNumber;
|
|
6714
4973
|
exports.formatPercent = formatPercent;
|
|
6715
4974
|
exports.formatRenderTime = formatRenderTime;
|
|
6716
|
-
exports.frameworkDetectors = FRAMEWORK_DETECTORS;
|
|
6717
4975
|
exports.generateHTMLReport = generateHTMLReport;
|
|
6718
4976
|
exports.generateJSONReport = generateJSONReport;
|
|
6719
4977
|
exports.generateMarkdownReport = generateMarkdownReport;
|
|
6720
4978
|
exports.generateReport = generateReport;
|
|
6721
|
-
exports.getBaseName = getBaseName;
|
|
6722
4979
|
exports.getChangedProps = getChangedProps;
|
|
6723
4980
|
exports.getComponentName = getComponentName;
|
|
6724
4981
|
exports.getComponentPath = getComponentPath;
|
|
6725
|
-
exports.getDirName = getDirName;
|
|
6726
|
-
exports.getExtension = getExtension;
|
|
6727
4982
|
exports.getFiberDOMNode = getFiberDOMNode;
|
|
6728
|
-
exports.getFrameworkTips = getFrameworkTips;
|
|
6729
4983
|
exports.getOwner = getOwner;
|
|
6730
4984
|
exports.getParentFiber = getParentFiber;
|
|
6731
4985
|
exports.getReactVersion = getReactVersion;
|
|
6732
4986
|
exports.handleBrowserMessages = handleBrowserMessages;
|
|
4987
|
+
exports.installReactCheck = installReactCheck;
|
|
6733
4988
|
exports.isHostComponent = isHostComponent;
|
|
6734
4989
|
exports.isMemoized = isMemoized;
|
|
6735
4990
|
exports.isPuppeteerAvailable = isPuppeteerAvailable;
|
|
6736
4991
|
exports.isUserComponent = isUserComponent;
|
|
6737
|
-
exports.
|
|
4992
|
+
exports.loadInjectionScript = loadInjectionScript;
|
|
6738
4993
|
exports.pad = pad;
|
|
6739
4994
|
exports.parseJSONReport = parseJSONReport;
|
|
6740
4995
|
exports.quickScan = quickScan;
|
|
6741
|
-
exports.readJsonFile = readJsonFile;
|
|
6742
|
-
exports.readTextFile = readTextFile;
|
|
6743
|
-
exports.resolvePath = resolvePath;
|
|
6744
4996
|
exports.saveReport = saveReport;
|
|
6745
4997
|
exports.saveReports = saveReports;
|
|
6746
4998
|
exports.shallowEqual = shallowEqual;
|
|
6747
4999
|
exports.stripAnsi = stripAnsi;
|
|
5000
|
+
exports.supportsColor = supportsColor;
|
|
6748
5001
|
exports.truncate = truncate;
|
|
6749
5002
|
exports.validateJSONReport = validateJSONReport;
|
|
6750
5003
|
exports.walkFiberTree = walkFiberTree;
|
|
6751
|
-
exports.writeJsonFile = writeJsonFile;
|
|
6752
|
-
exports.writeTextFile = writeTextFile;
|
|
6753
5004
|
//# sourceMappingURL=index.cjs.map
|
|
6754
5005
|
//# sourceMappingURL=index.cjs.map
|