@oxog/react-check 1.1.6 → 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 +115 -1
- package/README.md +149 -51
- package/dist/browser-inject.global.js +705 -158
- 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 +1443 -207
- 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 +2380 -3308
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -88
- package/dist/index.d.ts +255 -88
- package/dist/index.js +2289 -3290
- package/dist/index.js.map +1 -1
- package/dist/{scanner-CTBraprQ.d.ts → scanner-D0mBQGTx.d.ts} +23 -3
- package/dist/{scanner-5j2LEM-q.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-xAXT9cir.d.cts → types-BZ3OeZ-5.d.cts} +28 -10
- package/dist/{types-xAXT9cir.d.ts → types-BZ3OeZ-5.d.ts} +28 -10
- package/package.json +20 -11
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, stat, access, writeFile, mkdir, rm, readdir } from 'fs/promises';
|
|
3
3
|
import { constants } from 'fs';
|
|
4
|
-
import {
|
|
5
|
-
import { createServer } from 'http';
|
|
4
|
+
import { resolve, join, extname, basename, dirname } from 'path';
|
|
5
|
+
import { createServer, request as request$1 } from 'http';
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
7
|
+
import { URL as URL$1, fileURLToPath } from 'url';
|
|
8
|
+
import { request } from 'https';
|
|
8
9
|
import { exec, execSync } from 'child_process';
|
|
10
|
+
import * as readline from 'readline';
|
|
9
11
|
|
|
10
12
|
var __defProp = Object.defineProperty;
|
|
11
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -131,23 +133,17 @@ function getDirName(path) {
|
|
|
131
133
|
}
|
|
132
134
|
async function findUp(filename, startDir = process.cwd()) {
|
|
133
135
|
let currentDir = resolve(startDir);
|
|
134
|
-
|
|
135
|
-
while (currentDir !== root) {
|
|
136
|
+
for (; ; ) {
|
|
136
137
|
const filePath = join(currentDir, filename);
|
|
137
138
|
if (await exists(filePath)) {
|
|
138
139
|
return filePath;
|
|
139
140
|
}
|
|
140
141
|
const parentDir = dirname(currentDir);
|
|
141
142
|
if (parentDir === currentDir) {
|
|
142
|
-
|
|
143
|
+
return null;
|
|
143
144
|
}
|
|
144
145
|
currentDir = parentDir;
|
|
145
146
|
}
|
|
146
|
-
const rootFilePath = join(currentDir, filename);
|
|
147
|
-
if (await exists(rootFilePath)) {
|
|
148
|
-
return rootFilePath;
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
147
|
}
|
|
152
148
|
async function copyFile(src, dest) {
|
|
153
149
|
const content = await readFile(src);
|
|
@@ -1210,9 +1206,19 @@ var FLAG_DEFINITIONS = {
|
|
|
1210
1206
|
"webui-port": {
|
|
1211
1207
|
description: "WebUI dashboard port",
|
|
1212
1208
|
takesValue: true,
|
|
1213
|
-
default: "
|
|
1209
|
+
default: "3199"
|
|
1210
|
+
},
|
|
1211
|
+
json: {
|
|
1212
|
+
description: "Print machine-readable JSON (detect command)",
|
|
1213
|
+
default: false
|
|
1214
1214
|
}
|
|
1215
1215
|
};
|
|
1216
|
+
var REPORT_FORMATS = ["html", "json", "md", "all"];
|
|
1217
|
+
function parseFormatList(value) {
|
|
1218
|
+
const parts = value.split(",").map((p) => p.trim().toLowerCase()).filter((p) => p.length > 0);
|
|
1219
|
+
if (parts.includes("all")) return ["html", "json", "md"];
|
|
1220
|
+
return [...new Set(parts)];
|
|
1221
|
+
}
|
|
1216
1222
|
function buildShortFlagMap() {
|
|
1217
1223
|
const map = /* @__PURE__ */ new Map();
|
|
1218
1224
|
for (const [long, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
@@ -1224,11 +1230,23 @@ function buildShortFlagMap() {
|
|
|
1224
1230
|
}
|
|
1225
1231
|
var SHORT_FLAGS = buildShortFlagMap();
|
|
1226
1232
|
function parseArgs(argv) {
|
|
1233
|
+
const provided = /* @__PURE__ */ new Set();
|
|
1234
|
+
const unknown = [];
|
|
1227
1235
|
const result = {
|
|
1228
1236
|
command: "scan",
|
|
1229
1237
|
flags: /* @__PURE__ */ new Map(),
|
|
1230
1238
|
positional: [],
|
|
1231
|
-
raw: argv
|
|
1239
|
+
raw: argv,
|
|
1240
|
+
provided,
|
|
1241
|
+
unknown
|
|
1242
|
+
};
|
|
1243
|
+
const setFlag = (name, value, original) => {
|
|
1244
|
+
if (!(name in FLAG_DEFINITIONS)) {
|
|
1245
|
+
unknown.push(original);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
result.flags.set(name, value);
|
|
1249
|
+
provided.add(name);
|
|
1232
1250
|
};
|
|
1233
1251
|
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1234
1252
|
if (def.default !== void 0) {
|
|
@@ -1248,8 +1266,8 @@ function parseArgs(argv) {
|
|
|
1248
1266
|
i++;
|
|
1249
1267
|
continue;
|
|
1250
1268
|
}
|
|
1251
|
-
if (arg === "init") {
|
|
1252
|
-
result.command =
|
|
1269
|
+
if (arg === "init" || arg === "detect" || arg === "report") {
|
|
1270
|
+
result.command = arg;
|
|
1253
1271
|
i++;
|
|
1254
1272
|
continue;
|
|
1255
1273
|
}
|
|
@@ -1268,7 +1286,7 @@ function parseArgs(argv) {
|
|
|
1268
1286
|
const eqIndex = arg.indexOf("=");
|
|
1269
1287
|
const flagName = arg.slice(2, eqIndex);
|
|
1270
1288
|
const value = arg.slice(eqIndex + 1);
|
|
1271
|
-
|
|
1289
|
+
setFlag(flagName, value, arg);
|
|
1272
1290
|
i++;
|
|
1273
1291
|
continue;
|
|
1274
1292
|
}
|
|
@@ -1278,12 +1296,12 @@ function parseArgs(argv) {
|
|
|
1278
1296
|
if (def?.takesValue) {
|
|
1279
1297
|
const nextArg = argv[i + 1];
|
|
1280
1298
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1281
|
-
|
|
1299
|
+
setFlag(flagName, nextArg, arg);
|
|
1282
1300
|
i += 2;
|
|
1283
1301
|
continue;
|
|
1284
1302
|
}
|
|
1285
1303
|
}
|
|
1286
|
-
|
|
1304
|
+
setFlag(flagName, true, arg);
|
|
1287
1305
|
i++;
|
|
1288
1306
|
continue;
|
|
1289
1307
|
}
|
|
@@ -1293,7 +1311,7 @@ function parseArgs(argv) {
|
|
|
1293
1311
|
if (longFlag) {
|
|
1294
1312
|
const def = FLAG_DEFINITIONS[longFlag];
|
|
1295
1313
|
if (arg.length > 2 && def?.takesValue) {
|
|
1296
|
-
|
|
1314
|
+
setFlag(longFlag, arg.slice(2), arg);
|
|
1297
1315
|
i++;
|
|
1298
1316
|
continue;
|
|
1299
1317
|
}
|
|
@@ -1303,7 +1321,9 @@ function parseArgs(argv) {
|
|
|
1303
1321
|
if (sf) {
|
|
1304
1322
|
const lf = SHORT_FLAGS.get(sf);
|
|
1305
1323
|
if (lf) {
|
|
1306
|
-
|
|
1324
|
+
setFlag(lf, true, `-${sf}`);
|
|
1325
|
+
} else {
|
|
1326
|
+
unknown.push(`-${sf}`);
|
|
1307
1327
|
}
|
|
1308
1328
|
}
|
|
1309
1329
|
}
|
|
@@ -1313,12 +1333,12 @@ function parseArgs(argv) {
|
|
|
1313
1333
|
if (def?.takesValue) {
|
|
1314
1334
|
const nextArg = argv[i + 1];
|
|
1315
1335
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1316
|
-
|
|
1336
|
+
setFlag(longFlag, nextArg, arg);
|
|
1317
1337
|
i += 2;
|
|
1318
1338
|
continue;
|
|
1319
1339
|
}
|
|
1320
1340
|
}
|
|
1321
|
-
|
|
1341
|
+
setFlag(longFlag, true, arg);
|
|
1322
1342
|
i++;
|
|
1323
1343
|
continue;
|
|
1324
1344
|
}
|
|
@@ -1328,7 +1348,9 @@ function parseArgs(argv) {
|
|
|
1328
1348
|
if (sf) {
|
|
1329
1349
|
const lf = SHORT_FLAGS.get(sf);
|
|
1330
1350
|
if (lf) {
|
|
1331
|
-
|
|
1351
|
+
setFlag(lf, true, `-${sf}`);
|
|
1352
|
+
} else {
|
|
1353
|
+
unknown.push(`-${sf}`);
|
|
1332
1354
|
}
|
|
1333
1355
|
}
|
|
1334
1356
|
}
|
|
@@ -1345,6 +1367,7 @@ function parseArgs(argv) {
|
|
|
1345
1367
|
i++;
|
|
1346
1368
|
continue;
|
|
1347
1369
|
}
|
|
1370
|
+
unknown.push(arg);
|
|
1348
1371
|
i++;
|
|
1349
1372
|
}
|
|
1350
1373
|
if (result.flags.get("help") === true) {
|
|
@@ -1376,30 +1399,63 @@ function getNumberFlag(args, name) {
|
|
|
1376
1399
|
}
|
|
1377
1400
|
function validateArgs(args) {
|
|
1378
1401
|
const errors = [];
|
|
1402
|
+
for (const flag of args.unknown ?? []) {
|
|
1403
|
+
errors.push(`Unknown option: ${flag}`);
|
|
1404
|
+
}
|
|
1405
|
+
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1406
|
+
if (def.takesValue && args.flags.get(name) === true) {
|
|
1407
|
+
errors.push(`Option --${name} requires a value`);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1379
1410
|
if (args.command === "scan" && !args.target) {
|
|
1380
1411
|
errors.push("Target URL is required for scan command");
|
|
1381
1412
|
}
|
|
1413
|
+
if (args.command === "report" && args.positional.length === 0) {
|
|
1414
|
+
errors.push("Input JSON report path is required for report command");
|
|
1415
|
+
}
|
|
1382
1416
|
if (args.target) {
|
|
1383
1417
|
try {
|
|
1384
|
-
const url = args.target
|
|
1385
|
-
|
|
1418
|
+
const url = new URL(normalizeTarget(args.target));
|
|
1419
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1420
|
+
errors.push(`Invalid URL: ${args.target} (only http and https are supported)`);
|
|
1421
|
+
}
|
|
1386
1422
|
} catch {
|
|
1387
1423
|
errors.push(`Invalid URL: ${args.target}`);
|
|
1388
1424
|
}
|
|
1389
1425
|
}
|
|
1390
1426
|
const format = getStringFlag(args, "format");
|
|
1391
|
-
if (format
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1427
|
+
if (format !== void 0) {
|
|
1428
|
+
const formats = parseFormatList(format);
|
|
1429
|
+
const invalid = formats.filter((f) => !REPORT_FORMATS.includes(f));
|
|
1430
|
+
if (formats.length === 0 || invalid.length > 0) {
|
|
1431
|
+
errors.push(`Invalid format: ${format}. Must be one or more of: html, json, md, all (comma-separated)`);
|
|
1432
|
+
}
|
|
1397
1433
|
}
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1434
|
+
const integerFlag = (name, min, max) => {
|
|
1435
|
+
const raw = getStringFlag(args, name);
|
|
1436
|
+
if (raw === void 0) return void 0;
|
|
1437
|
+
const value = Number(raw);
|
|
1438
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
1439
|
+
errors.push(`Invalid value for --${name}: ${raw}. Must be an integer between ${min} and ${max}`);
|
|
1440
|
+
return void 0;
|
|
1441
|
+
}
|
|
1442
|
+
return value;
|
|
1443
|
+
};
|
|
1444
|
+
integerFlag("port", 1, 65535);
|
|
1445
|
+
integerFlag("webui-port", 1, 65535);
|
|
1446
|
+
integerFlag("fps-threshold", 1, 240);
|
|
1447
|
+
const critical = integerFlag("threshold-critical", 1, Number.MAX_SAFE_INTEGER);
|
|
1448
|
+
const warning = integerFlag("threshold-warning", 1, Number.MAX_SAFE_INTEGER);
|
|
1400
1449
|
if (critical !== void 0 && warning !== void 0 && critical <= warning) {
|
|
1401
1450
|
errors.push("Critical threshold must be greater than warning threshold");
|
|
1402
1451
|
}
|
|
1452
|
+
const duration = getStringFlag(args, "duration");
|
|
1453
|
+
if (duration !== void 0) {
|
|
1454
|
+
const value = Number(duration);
|
|
1455
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
1456
|
+
errors.push(`Invalid value for --duration: ${duration}. Must be a positive number of seconds`);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1403
1459
|
return errors;
|
|
1404
1460
|
}
|
|
1405
1461
|
function getHelpText() {
|
|
@@ -1409,6 +1465,9 @@ function getHelpText() {
|
|
|
1409
1465
|
"",
|
|
1410
1466
|
"Usage:",
|
|
1411
1467
|
" react-check <url> [options] Scan a React application",
|
|
1468
|
+
" react-check scan <url> Same as above",
|
|
1469
|
+
" react-check detect [path] Detect the React framework of a project",
|
|
1470
|
+
" react-check report <file.json> Re-generate reports from a JSON report",
|
|
1412
1471
|
" react-check init Create default config file",
|
|
1413
1472
|
" react-check help Show this help message",
|
|
1414
1473
|
" react-check version Show version number",
|
|
@@ -1416,8 +1475,8 @@ function getHelpText() {
|
|
|
1416
1475
|
"Options:"
|
|
1417
1476
|
];
|
|
1418
1477
|
const groups = {
|
|
1419
|
-
"General": ["help", "version", "verbose", "config"],
|
|
1420
|
-
"Mode": ["proxy", "tui", "silent", "headless", "watch"],
|
|
1478
|
+
"General": ["help", "version", "verbose", "config", "json"],
|
|
1479
|
+
"Mode": ["proxy", "tui", "silent", "headless", "watch", "webui", "webui-port"],
|
|
1421
1480
|
"Report": ["report", "format", "output", "fix"],
|
|
1422
1481
|
"Thresholds": ["threshold-critical", "threshold-warning", "fps-threshold"],
|
|
1423
1482
|
"Network": ["port", "duration"]
|
|
@@ -1451,9 +1510,16 @@ function getHelpText() {
|
|
|
1451
1510
|
lines.push(" react-check localhost:3000");
|
|
1452
1511
|
lines.push(" react-check https://myapp.dev --report --format=html");
|
|
1453
1512
|
lines.push(" react-check localhost:3000 --proxy --fix --verbose");
|
|
1454
|
-
lines.push(" react-check localhost:3000 --silent --
|
|
1513
|
+
lines.push(" react-check localhost:3000 --silent --headless --duration 30 --format json --output ./ci-reports");
|
|
1514
|
+
lines.push(" react-check detect ./my-app");
|
|
1515
|
+
lines.push(" react-check report ./ci-reports/reactcheck-report-123.json --format html,md");
|
|
1516
|
+
lines.push("");
|
|
1517
|
+
lines.push("Exit codes:");
|
|
1518
|
+
lines.push(" 0 scan finished without critical issues");
|
|
1519
|
+
lines.push(" 1 scan finished and found critical issues");
|
|
1520
|
+
lines.push(" 2 invalid usage or the scan could not run");
|
|
1455
1521
|
lines.push("");
|
|
1456
|
-
lines.push("Documentation: https://
|
|
1522
|
+
lines.push("Documentation: https://reactcheck.oxog.dev");
|
|
1457
1523
|
lines.push("");
|
|
1458
1524
|
return lines.join("\n");
|
|
1459
1525
|
}
|
|
@@ -1816,7 +1882,7 @@ var Logger = class _Logger {
|
|
|
1816
1882
|
for (const col of cols) {
|
|
1817
1883
|
widths[col] = col.length;
|
|
1818
1884
|
for (const row of data) {
|
|
1819
|
-
const value =
|
|
1885
|
+
const value = formatCell(row[col]);
|
|
1820
1886
|
widths[col] = Math.max(widths[col] ?? 0, value.length);
|
|
1821
1887
|
}
|
|
1822
1888
|
}
|
|
@@ -1825,7 +1891,7 @@ var Logger = class _Logger {
|
|
|
1825
1891
|
this.output.log(colors.bold + header + colors.reset);
|
|
1826
1892
|
this.output.log(separator);
|
|
1827
1893
|
for (const row of data) {
|
|
1828
|
-
const line = cols.map((col) =>
|
|
1894
|
+
const line = cols.map((col) => formatCell(row[col]).padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
1829
1895
|
this.output.log(line);
|
|
1830
1896
|
}
|
|
1831
1897
|
}
|
|
@@ -1876,6 +1942,27 @@ var Logger = class _Logger {
|
|
|
1876
1942
|
}
|
|
1877
1943
|
};
|
|
1878
1944
|
new Logger({ prefix: "ReactCheck" });
|
|
1945
|
+
function formatCell(value) {
|
|
1946
|
+
if (value === null || value === void 0) return "";
|
|
1947
|
+
if (typeof value === "object") {
|
|
1948
|
+
try {
|
|
1949
|
+
return JSON.stringify(value);
|
|
1950
|
+
} catch {
|
|
1951
|
+
return Object.prototype.toString.call(value);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
switch (typeof value) {
|
|
1955
|
+
case "string":
|
|
1956
|
+
return value;
|
|
1957
|
+
case "number":
|
|
1958
|
+
case "boolean":
|
|
1959
|
+
case "bigint":
|
|
1960
|
+
case "symbol":
|
|
1961
|
+
return value.toString();
|
|
1962
|
+
default:
|
|
1963
|
+
return "[function]";
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1879
1966
|
|
|
1880
1967
|
// src/cli/config.ts
|
|
1881
1968
|
var logger2 = new Logger({ prefix: "config", level: 2 /* WARN */ });
|
|
@@ -2018,12 +2105,9 @@ function validateConfig(config) {
|
|
|
2018
2105
|
if (config.rules) {
|
|
2019
2106
|
const validLevels = ["off", "warn", "error"];
|
|
2020
2107
|
for (const [rule, level] of Object.entries(config.rules)) {
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
}
|
|
2025
|
-
} else if (!validLevels.includes(level)) {
|
|
2026
|
-
errors.push(`Invalid rule level for ${rule}: ${level}`);
|
|
2108
|
+
const value = Array.isArray(level) ? level[0] : level;
|
|
2109
|
+
if (typeof value !== "string" || !validLevels.includes(value)) {
|
|
2110
|
+
errors.push(`Invalid rule level for ${rule}: ${String(value)}`);
|
|
2027
2111
|
}
|
|
2028
2112
|
}
|
|
2029
2113
|
}
|
|
@@ -2087,22 +2171,35 @@ export default {
|
|
|
2087
2171
|
output: '${DEFAULT_CONFIG.report.output}',
|
|
2088
2172
|
},
|
|
2089
2173
|
|
|
2090
|
-
//
|
|
2174
|
+
// Fix-suggestion rules ('off' disables a rule's suggestions)
|
|
2091
2175
|
rules: {
|
|
2092
|
-
// '
|
|
2093
|
-
// '
|
|
2094
|
-
// '
|
|
2176
|
+
// 'unnecessary-rerenders-memo': 'warn',
|
|
2177
|
+
// 'function-prop-stability': 'warn',
|
|
2178
|
+
// 'expensive-computation-memo': 'warn',
|
|
2179
|
+
// 'context-over-subscription': 'warn',
|
|
2180
|
+
// 'state-too-high': 'off',
|
|
2181
|
+
// 'extract-heavy-child': 'off',
|
|
2095
2182
|
},
|
|
2096
2183
|
};
|
|
2097
2184
|
`;
|
|
2098
2185
|
}
|
|
2099
2186
|
function configToOptions(config) {
|
|
2187
|
+
const thresholds = {
|
|
2188
|
+
critical: config.thresholds.critical ?? DEFAULT_CONFIG.thresholds.critical ?? 50,
|
|
2189
|
+
warning: config.thresholds.warning ?? DEFAULT_CONFIG.thresholds.warning ?? 20,
|
|
2190
|
+
fps: config.thresholds.fps ?? DEFAULT_CONFIG.thresholds.fps ?? 30
|
|
2191
|
+
};
|
|
2192
|
+
const report = {
|
|
2193
|
+
enabled: true,
|
|
2194
|
+
formats: config.report.formats ?? DEFAULT_CONFIG.report.formats ?? ["html", "json"],
|
|
2195
|
+
output: config.report.output ?? DEFAULT_CONFIG.report.output ?? "./reactcheck-reports"
|
|
2196
|
+
};
|
|
2197
|
+
if (config.report.includeSourceCode !== void 0) {
|
|
2198
|
+
report.includeSourceCode = config.report.includeSourceCode;
|
|
2199
|
+
}
|
|
2100
2200
|
return {
|
|
2101
|
-
thresholds
|
|
2102
|
-
report
|
|
2103
|
-
enabled: true,
|
|
2104
|
-
...config.report
|
|
2105
|
-
},
|
|
2201
|
+
thresholds,
|
|
2202
|
+
report,
|
|
2106
2203
|
rules: config.rules,
|
|
2107
2204
|
include: config.include,
|
|
2108
2205
|
exclude: config.exclude
|
|
@@ -2705,16 +2802,16 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2705
2802
|
this.parentMap.set(render.componentName, parent);
|
|
2706
2803
|
}
|
|
2707
2804
|
const windowKey = this.getWindowKey(render.timestamp);
|
|
2708
|
-
let
|
|
2709
|
-
if (!
|
|
2710
|
-
|
|
2805
|
+
let window2 = this.windows.get(windowKey);
|
|
2806
|
+
if (!window2) {
|
|
2807
|
+
window2 = {
|
|
2711
2808
|
renders: [],
|
|
2712
2809
|
startTime: render.timestamp
|
|
2713
2810
|
};
|
|
2714
|
-
this.windows.set(windowKey,
|
|
2811
|
+
this.windows.set(windowKey, window2);
|
|
2715
2812
|
}
|
|
2716
|
-
|
|
2717
|
-
if (
|
|
2813
|
+
window2.renders.push(trackedRender);
|
|
2814
|
+
if (window2.renders.length >= this.minChainDepth) {
|
|
2718
2815
|
this.analyzeWindow(windowKey);
|
|
2719
2816
|
}
|
|
2720
2817
|
this.cleanupWindows(render.timestamp);
|
|
@@ -2733,7 +2830,12 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2733
2830
|
* @returns Window key
|
|
2734
2831
|
*/
|
|
2735
2832
|
getWindowKey(timestamp) {
|
|
2736
|
-
|
|
2833
|
+
for (const [key, window2] of this.windows) {
|
|
2834
|
+
if (timestamp >= window2.startTime && timestamp < window2.startTime + this.windowSize) {
|
|
2835
|
+
return key;
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
return timestamp;
|
|
2737
2839
|
}
|
|
2738
2840
|
/**
|
|
2739
2841
|
* Check if a render was likely triggered by context
|
|
@@ -2748,11 +2850,11 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2748
2850
|
* @param windowKey - Window key to analyze
|
|
2749
2851
|
*/
|
|
2750
2852
|
analyzeWindow(windowKey) {
|
|
2751
|
-
const
|
|
2752
|
-
if (!
|
|
2853
|
+
const window2 = this.windows.get(windowKey);
|
|
2854
|
+
if (!window2 || window2.renders.length < this.minChainDepth) {
|
|
2753
2855
|
return;
|
|
2754
2856
|
}
|
|
2755
|
-
const sortedRenders = [...
|
|
2857
|
+
const sortedRenders = [...window2.renders].sort((a, b) => a.timestamp - b.timestamp);
|
|
2756
2858
|
const chains = this.buildChains(sortedRenders);
|
|
2757
2859
|
for (const chain of chains) {
|
|
2758
2860
|
const chainKey = this.getChainKey(chain);
|
|
@@ -2889,8 +2991,8 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2889
2991
|
*/
|
|
2890
2992
|
cleanupWindows(currentTime) {
|
|
2891
2993
|
const cutoff = currentTime - this.windowSize * 10;
|
|
2892
|
-
for (const [key,
|
|
2893
|
-
if (
|
|
2994
|
+
for (const [key, window2] of this.windows) {
|
|
2995
|
+
if (window2.startTime < cutoff) {
|
|
2894
2996
|
this.windows.delete(key);
|
|
2895
2997
|
}
|
|
2896
2998
|
}
|
|
@@ -3416,7 +3518,31 @@ var FixSuggester = class extends EventEmitter {
|
|
|
3416
3518
|
}
|
|
3417
3519
|
};
|
|
3418
3520
|
|
|
3521
|
+
// src/utils/pattern.ts
|
|
3522
|
+
function matchComponentPattern(name, pattern) {
|
|
3523
|
+
let source = "";
|
|
3524
|
+
let prev = "";
|
|
3525
|
+
for (const ch of pattern) {
|
|
3526
|
+
if (ch === "*" && prev === "*") continue;
|
|
3527
|
+
prev = ch;
|
|
3528
|
+
if (ch === "*") source += ".*";
|
|
3529
|
+
else if (ch === "?") source += ".";
|
|
3530
|
+
else source += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
3531
|
+
}
|
|
3532
|
+
return new RegExp(`^${source}$`).test(name);
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3419
3535
|
// src/core/scanner.ts
|
|
3536
|
+
function toRuleLevels(rules) {
|
|
3537
|
+
const levels = {};
|
|
3538
|
+
for (const [id, setting] of Object.entries(rules)) {
|
|
3539
|
+
const level = Array.isArray(setting) ? setting[0] : setting;
|
|
3540
|
+
if (level === "off" || level === "warn" || level === "error") {
|
|
3541
|
+
levels[id] = level;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
return levels;
|
|
3545
|
+
}
|
|
3420
3546
|
var DEFAULT_CONFIG2 = {
|
|
3421
3547
|
trackUnnecessary: true,
|
|
3422
3548
|
fpsThreshold: 30,
|
|
@@ -3460,7 +3586,7 @@ var Scanner = class extends EventEmitter {
|
|
|
3460
3586
|
const thresholds = { ...DEFAULT_THRESHOLDS2, ...options.thresholds };
|
|
3461
3587
|
this.stats = new StatsCollector(thresholds);
|
|
3462
3588
|
this.chainAnalyzer = new ChainAnalyzer();
|
|
3463
|
-
this.fixSuggester = new FixSuggester();
|
|
3589
|
+
this.fixSuggester = new FixSuggester(options.rules ? { rules: toRuleLevels(options.rules) } : {});
|
|
3464
3590
|
this.setupEventForwarding();
|
|
3465
3591
|
}
|
|
3466
3592
|
/**
|
|
@@ -3526,19 +3652,55 @@ var Scanner = class extends EventEmitter {
|
|
|
3526
3652
|
*/
|
|
3527
3653
|
addRender(render, parent) {
|
|
3528
3654
|
if (!this.running) return;
|
|
3655
|
+
if (!this.isComponentIncluded(render.componentName)) return;
|
|
3529
3656
|
this.renderBatch.push(render);
|
|
3530
3657
|
this.stats.addRender(render);
|
|
3531
3658
|
this.chainAnalyzer.addRender(render, parent);
|
|
3532
3659
|
this.emit("render", render);
|
|
3533
|
-
this.frameCount++;
|
|
3534
3660
|
this.scheduleBatchProcessing();
|
|
3535
3661
|
}
|
|
3536
3662
|
/**
|
|
3537
|
-
*
|
|
3663
|
+
* Check a component name against the configured include/exclude patterns
|
|
3664
|
+
* @param name - Component name
|
|
3665
|
+
* @returns true if renders of this component should be tracked
|
|
3666
|
+
*/
|
|
3667
|
+
isComponentIncluded(name) {
|
|
3668
|
+
const { include, exclude } = this.config;
|
|
3669
|
+
if (include && include.length > 0 && !include.some((p) => matchComponentPattern(name, p))) {
|
|
3670
|
+
return false;
|
|
3671
|
+
}
|
|
3672
|
+
if (exclude && exclude.length > 0 && exclude.some((p) => matchComponentPattern(name, p))) {
|
|
3673
|
+
return false;
|
|
3674
|
+
}
|
|
3675
|
+
return true;
|
|
3676
|
+
}
|
|
3677
|
+
/**
|
|
3678
|
+
* Record a painted frame for FPS calculation (the scanner derives FPS from
|
|
3679
|
+
* frames recorded during each one-second window)
|
|
3538
3680
|
*/
|
|
3539
3681
|
recordFrame() {
|
|
3540
3682
|
this.frameCount++;
|
|
3541
3683
|
}
|
|
3684
|
+
/**
|
|
3685
|
+
* Record an FPS sample measured elsewhere (e.g. by requestAnimationFrame in
|
|
3686
|
+
* the browser)
|
|
3687
|
+
* @param fps - Frames per second
|
|
3688
|
+
*/
|
|
3689
|
+
recordFps(fps) {
|
|
3690
|
+
if (!this.running || !Number.isFinite(fps) || fps < 0) return;
|
|
3691
|
+
this.lastFps = Math.round(fps);
|
|
3692
|
+
this.stats.addFpsSample(this.lastFps);
|
|
3693
|
+
if (this.lastFps < this.getFpsThreshold()) {
|
|
3694
|
+
this.emit("fps-drop", this.lastFps);
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
/**
|
|
3698
|
+
* FPS threshold below which `fps-drop` is emitted
|
|
3699
|
+
* @returns Threshold
|
|
3700
|
+
*/
|
|
3701
|
+
getFpsThreshold() {
|
|
3702
|
+
return this.stats.getThresholds().fps ?? this.config.fpsThreshold;
|
|
3703
|
+
}
|
|
3542
3704
|
/**
|
|
3543
3705
|
* Schedule batch processing
|
|
3544
3706
|
*/
|
|
@@ -3550,6 +3712,8 @@ var Scanner = class extends EventEmitter {
|
|
|
3550
3712
|
this.batchTimeout = setTimeout(() => {
|
|
3551
3713
|
this.flushBatch();
|
|
3552
3714
|
}, this.batchDelay);
|
|
3715
|
+
const timer = this.batchTimeout;
|
|
3716
|
+
timer.unref?.();
|
|
3553
3717
|
}
|
|
3554
3718
|
}
|
|
3555
3719
|
/**
|
|
@@ -3594,16 +3758,15 @@ var Scanner = class extends EventEmitter {
|
|
|
3594
3758
|
this.fpsInterval = setInterval(() => {
|
|
3595
3759
|
const now = Date.now();
|
|
3596
3760
|
const elapsed = now - this.lastFpsUpdate;
|
|
3597
|
-
|
|
3598
|
-
this.lastFps = Math.round(this.frameCount * 1e3 / elapsed);
|
|
3599
|
-
this.stats.addFpsSample(this.lastFps);
|
|
3600
|
-
if (this.lastFps < this.config.fpsThreshold) {
|
|
3601
|
-
this.emit("fps-drop", this.lastFps);
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3761
|
+
const frames = this.frameCount;
|
|
3604
3762
|
this.frameCount = 0;
|
|
3605
3763
|
this.lastFpsUpdate = now;
|
|
3764
|
+
if (elapsed > 0 && frames > 0) {
|
|
3765
|
+
this.recordFps(frames * 1e3 / elapsed);
|
|
3766
|
+
}
|
|
3606
3767
|
}, 1e3);
|
|
3768
|
+
const interval = this.fpsInterval;
|
|
3769
|
+
interval.unref?.();
|
|
3607
3770
|
}
|
|
3608
3771
|
/**
|
|
3609
3772
|
* Stop FPS monitoring
|
|
@@ -4920,14 +5083,26 @@ var TUI = class extends EventEmitter {
|
|
|
4920
5083
|
this.keys.bind("end", () => this.componentList.moveToEnd());
|
|
4921
5084
|
this.keys.bind("enter", () => this.handleSelect());
|
|
4922
5085
|
this.keys.bind("escape", () => this.handleBack());
|
|
4923
|
-
this.keys.bind("q", () =>
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
this.keys.bind("
|
|
4927
|
-
|
|
5086
|
+
this.keys.bind("q", () => {
|
|
5087
|
+
this.emit("quit", void 0);
|
|
5088
|
+
});
|
|
5089
|
+
this.keys.bind("ctrl+c", () => {
|
|
5090
|
+
this.emit("quit", void 0);
|
|
5091
|
+
});
|
|
5092
|
+
this.keys.bind("p", () => {
|
|
5093
|
+
this.emit("togglePause", void 0);
|
|
5094
|
+
});
|
|
5095
|
+
this.keys.bind("r", () => {
|
|
5096
|
+
this.emit("generateReport", void 0);
|
|
5097
|
+
});
|
|
5098
|
+
this.keys.bind("s", () => {
|
|
5099
|
+
this.emit("openSettings", void 0);
|
|
5100
|
+
});
|
|
4928
5101
|
this.keys.bind("f", () => this.showFixSuggestions());
|
|
4929
5102
|
this.keys.bind("c", () => this.showRenderChain());
|
|
4930
|
-
this.keys.bind("o", () =>
|
|
5103
|
+
this.keys.bind("o", () => {
|
|
5104
|
+
this.emit("toggleOverlay", void 0);
|
|
5105
|
+
});
|
|
4931
5106
|
}
|
|
4932
5107
|
/**
|
|
4933
5108
|
* Start the TUI
|
|
@@ -5222,6 +5397,7 @@ var OPCODE = {
|
|
|
5222
5397
|
PONG: 10
|
|
5223
5398
|
};
|
|
5224
5399
|
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
5400
|
+
var MAX_FRAME_PAYLOAD = 16 * 1024 * 1024;
|
|
5225
5401
|
var WebSocketClient = class extends EventEmitter {
|
|
5226
5402
|
/** Socket connection */
|
|
5227
5403
|
socket;
|
|
@@ -5258,7 +5434,7 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5258
5434
|
* Process received frames
|
|
5259
5435
|
*/
|
|
5260
5436
|
processFrames() {
|
|
5261
|
-
while (this.frameBuffer.length >= 2) {
|
|
5437
|
+
while (this.isOpen && this.frameBuffer.length >= 2) {
|
|
5262
5438
|
const frame = this.parseFrame();
|
|
5263
5439
|
if (!frame) break;
|
|
5264
5440
|
switch (frame.opcode) {
|
|
@@ -5298,8 +5474,18 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5298
5474
|
offset = 4;
|
|
5299
5475
|
} else if (payloadLength === 127) {
|
|
5300
5476
|
if (this.frameBuffer.length < 10) return null;
|
|
5477
|
+
const high = this.frameBuffer.readUInt32BE(2);
|
|
5301
5478
|
payloadLength = this.frameBuffer.readUInt32BE(6);
|
|
5302
5479
|
offset = 10;
|
|
5480
|
+
if (high !== 0) {
|
|
5481
|
+
payloadLength = Number.POSITIVE_INFINITY;
|
|
5482
|
+
}
|
|
5483
|
+
}
|
|
5484
|
+
if (payloadLength > MAX_FRAME_PAYLOAD) {
|
|
5485
|
+
this.frameBuffer = Buffer.alloc(0);
|
|
5486
|
+
this.close(1009, "Message too big");
|
|
5487
|
+
this.socket.destroy();
|
|
5488
|
+
return null;
|
|
5303
5489
|
}
|
|
5304
5490
|
let maskingKey = null;
|
|
5305
5491
|
if (masked) {
|
|
@@ -5497,6 +5683,10 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5497
5683
|
this.server.once("error", reject);
|
|
5498
5684
|
this.server.listen(this.port, () => {
|
|
5499
5685
|
this.server.removeListener("error", reject);
|
|
5686
|
+
const address = this.server.address();
|
|
5687
|
+
if (address && typeof address === "object") {
|
|
5688
|
+
this.port = address.port;
|
|
5689
|
+
}
|
|
5500
5690
|
this.emit("listening", { port: this.port });
|
|
5501
5691
|
resolve3();
|
|
5502
5692
|
});
|
|
@@ -5516,6 +5706,14 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5516
5706
|
});
|
|
5517
5707
|
});
|
|
5518
5708
|
}
|
|
5709
|
+
/**
|
|
5710
|
+
* Get the port the server listens on (the real port after start() when
|
|
5711
|
+
* constructed with port 0)
|
|
5712
|
+
* @returns Port number
|
|
5713
|
+
*/
|
|
5714
|
+
getPort() {
|
|
5715
|
+
return this.port;
|
|
5716
|
+
}
|
|
5519
5717
|
/**
|
|
5520
5718
|
* Broadcast message to all clients
|
|
5521
5719
|
* @param message - Message to broadcast
|
|
@@ -5551,16 +5749,21 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5551
5749
|
};
|
|
5552
5750
|
function handleBrowserMessages(client, handler) {
|
|
5553
5751
|
client.on("message", (data) => {
|
|
5752
|
+
let message;
|
|
5554
5753
|
try {
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5754
|
+
message = JSON.parse(data);
|
|
5755
|
+
} catch {
|
|
5756
|
+
return;
|
|
5757
|
+
}
|
|
5758
|
+
if (message === null || typeof message !== "object" || typeof message.type !== "string") {
|
|
5759
|
+
return;
|
|
5558
5760
|
}
|
|
5761
|
+
handler(message);
|
|
5559
5762
|
});
|
|
5560
5763
|
}
|
|
5561
5764
|
|
|
5562
5765
|
// src/server/browser.ts
|
|
5563
|
-
var logger3 = new Logger({ prefix: "browser", level:
|
|
5766
|
+
var logger3 = new Logger({ prefix: "browser", level: 1 /* INFO */ });
|
|
5564
5767
|
var BrowserLauncher = class extends EventEmitter {
|
|
5565
5768
|
/** Puppeteer browser instance */
|
|
5566
5769
|
browser = null;
|
|
@@ -5623,12 +5826,10 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5623
5826
|
this.page = pages[0] ?? await this.browser.newPage();
|
|
5624
5827
|
this.setupPageHandlers();
|
|
5625
5828
|
if (this.injectionScript) {
|
|
5829
|
+
logger3.debug("Injecting ReactCheck script into page...");
|
|
5626
5830
|
await this.page.evaluateOnNewDocument(this.injectionScript);
|
|
5831
|
+
logger3.debug("Injection script registered");
|
|
5627
5832
|
}
|
|
5628
|
-
const wsPort = this.options.wsPort;
|
|
5629
|
-
await this.page.evaluateOnNewDocument(`
|
|
5630
|
-
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
5631
|
-
`);
|
|
5632
5833
|
this.emit("launched", void 0);
|
|
5633
5834
|
logger3.info("Browser launched");
|
|
5634
5835
|
await this.navigate(this.options.url);
|
|
@@ -5787,9 +5988,235 @@ async function isPuppeteerAvailable() {
|
|
|
5787
5988
|
return false;
|
|
5788
5989
|
}
|
|
5789
5990
|
}
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5991
|
+
var INJECTION_SCRIPT_FILE = "browser-inject.global.js";
|
|
5992
|
+
function getInjectionScriptCandidates() {
|
|
5993
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
5994
|
+
return [
|
|
5995
|
+
resolve(here, INJECTION_SCRIPT_FILE),
|
|
5996
|
+
resolve(here, "..", INJECTION_SCRIPT_FILE),
|
|
5997
|
+
resolve(here, "..", "..", "dist", INJECTION_SCRIPT_FILE)
|
|
5998
|
+
];
|
|
5999
|
+
}
|
|
6000
|
+
async function loadInjectionScript(wsPort) {
|
|
6001
|
+
const port = Math.trunc(Number(wsPort));
|
|
6002
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
6003
|
+
throw new RangeError(`Invalid WebSocket port: ${String(wsPort)}`);
|
|
6004
|
+
}
|
|
6005
|
+
for (const candidate of getInjectionScriptCandidates()) {
|
|
6006
|
+
try {
|
|
6007
|
+
const script = await readFile(candidate, "utf8");
|
|
6008
|
+
return `window.__REACTCHECK_PORT__ = ${port};
|
|
6009
|
+
${script}`;
|
|
6010
|
+
} catch {
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
throw new Error(
|
|
6014
|
+
`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.`
|
|
6015
|
+
);
|
|
6016
|
+
}
|
|
6017
|
+
var logger4 = new Logger({ prefix: "proxy", level: 1 /* INFO */ });
|
|
6018
|
+
var SCANNER_SCRIPT_PATH = "/__reactcheck__/scanner.js";
|
|
6019
|
+
function injectScriptTag(html) {
|
|
6020
|
+
const tag = `<script src="${SCANNER_SCRIPT_PATH}"></script>`;
|
|
6021
|
+
if (html.includes(tag)) return html;
|
|
6022
|
+
const head = /<head(?:\s[^>]*)?>/i.exec(html);
|
|
6023
|
+
if (head) {
|
|
6024
|
+
const at = head.index + head[0].length;
|
|
6025
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
6026
|
+
}
|
|
6027
|
+
const htmlTag = /<html(?:\s[^>]*)?>/i.exec(html);
|
|
6028
|
+
if (htmlTag) {
|
|
6029
|
+
const at = htmlTag.index + htmlTag[0].length;
|
|
6030
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
6031
|
+
}
|
|
6032
|
+
const doctype = /^\s*<!doctype[^>]*>/i.exec(html);
|
|
6033
|
+
if (doctype) {
|
|
6034
|
+
return doctype[0] + tag + html.slice(doctype[0].length);
|
|
6035
|
+
}
|
|
6036
|
+
return tag + html;
|
|
6037
|
+
}
|
|
6038
|
+
var ProxyServer = class extends EventEmitter {
|
|
6039
|
+
/** HTTP server instance */
|
|
6040
|
+
server;
|
|
6041
|
+
/** Proxy options */
|
|
6042
|
+
options;
|
|
6043
|
+
/** Target URL parsed */
|
|
6044
|
+
targetUrl;
|
|
6045
|
+
/** Injection script (loaded from the bundled browser script on start() when not provided) */
|
|
6046
|
+
injectionScript;
|
|
6047
|
+
/**
|
|
6048
|
+
* Create a new proxy server
|
|
6049
|
+
* @param options - Proxy options
|
|
6050
|
+
*/
|
|
6051
|
+
constructor(options) {
|
|
6052
|
+
super();
|
|
6053
|
+
this.options = options;
|
|
6054
|
+
this.targetUrl = new URL$1(options.target);
|
|
6055
|
+
this.injectionScript = options.injectionScript ?? null;
|
|
6056
|
+
this.server = createServer((req, res) => {
|
|
6057
|
+
this.handleRequest(req, res).catch((error) => {
|
|
6058
|
+
logger4.error("Request handling error:", error);
|
|
6059
|
+
this.emit("error", error);
|
|
6060
|
+
res.statusCode = 500;
|
|
6061
|
+
res.end("Internal Server Error");
|
|
6062
|
+
});
|
|
6063
|
+
});
|
|
6064
|
+
this.server.on("error", (error) => {
|
|
6065
|
+
this.emit("error", error);
|
|
6066
|
+
});
|
|
6067
|
+
}
|
|
6068
|
+
/**
|
|
6069
|
+
* Handle incoming request
|
|
6070
|
+
* @param req - Client request
|
|
6071
|
+
* @param res - Server response
|
|
6072
|
+
*/
|
|
6073
|
+
async handleRequest(req, res) {
|
|
6074
|
+
const requestUrl = req.url ?? "/";
|
|
6075
|
+
if (requestUrl.startsWith("/__reactcheck__/")) {
|
|
6076
|
+
this.handleReactCheckRoute(requestUrl, res);
|
|
6077
|
+
return;
|
|
6078
|
+
}
|
|
6079
|
+
this.emit("request", { url: requestUrl, method: req.method ?? "GET" });
|
|
6080
|
+
const targetUrl = new URL$1(requestUrl, this.targetUrl);
|
|
6081
|
+
await this.proxyRequest(req, res, targetUrl);
|
|
6082
|
+
}
|
|
6083
|
+
/**
|
|
6084
|
+
* Handle ReactCheck special routes
|
|
6085
|
+
* @param url - Request URL
|
|
6086
|
+
* @param res - Server response
|
|
6087
|
+
*/
|
|
6088
|
+
handleReactCheckRoute(url, res) {
|
|
6089
|
+
if (url === SCANNER_SCRIPT_PATH || url.startsWith(`${SCANNER_SCRIPT_PATH}?`)) {
|
|
6090
|
+
res.writeHead(200, {
|
|
6091
|
+
"Content-Type": "application/javascript; charset=utf-8",
|
|
6092
|
+
"Cache-Control": "no-cache",
|
|
6093
|
+
"Access-Control-Allow-Origin": "*"
|
|
6094
|
+
});
|
|
6095
|
+
res.end(this.injectionScript ?? "");
|
|
6096
|
+
return;
|
|
6097
|
+
}
|
|
6098
|
+
res.writeHead(404);
|
|
6099
|
+
res.end("Not Found");
|
|
6100
|
+
}
|
|
6101
|
+
/**
|
|
6102
|
+
* Proxy a request to the target
|
|
6103
|
+
* @param req - Client request
|
|
6104
|
+
* @param res - Server response
|
|
6105
|
+
* @param targetUrl - Target URL
|
|
6106
|
+
*/
|
|
6107
|
+
proxyRequest(req, res, targetUrl) {
|
|
6108
|
+
return new Promise((resolve3, reject) => {
|
|
6109
|
+
const isHttps = targetUrl.protocol === "https:";
|
|
6110
|
+
const requestFn = isHttps ? request : request$1;
|
|
6111
|
+
const headers = { ...req.headers };
|
|
6112
|
+
delete headers["accept-encoding"];
|
|
6113
|
+
headers["host"] = targetUrl.host;
|
|
6114
|
+
const options = {
|
|
6115
|
+
hostname: targetUrl.hostname,
|
|
6116
|
+
port: targetUrl.port || (isHttps ? 443 : 80),
|
|
6117
|
+
path: targetUrl.pathname + targetUrl.search,
|
|
6118
|
+
method: req.method,
|
|
6119
|
+
headers
|
|
6120
|
+
};
|
|
6121
|
+
const proxyReq = requestFn(options, (proxyRes) => {
|
|
6122
|
+
const contentType = proxyRes.headers["content-type"] ?? "";
|
|
6123
|
+
const contentEncoding = String(proxyRes.headers["content-encoding"] ?? "identity").toLowerCase();
|
|
6124
|
+
if (contentType.includes("text/html") && (contentEncoding === "identity" || contentEncoding === "")) {
|
|
6125
|
+
this.injectAndRespond(proxyRes, res, targetUrl.href);
|
|
6126
|
+
resolve3();
|
|
6127
|
+
return;
|
|
6128
|
+
}
|
|
6129
|
+
res.writeHead(proxyRes.statusCode ?? 200, proxyRes.headers);
|
|
6130
|
+
proxyRes.pipe(res);
|
|
6131
|
+
proxyRes.on("end", resolve3);
|
|
6132
|
+
});
|
|
6133
|
+
proxyReq.on("error", (error) => {
|
|
6134
|
+
logger4.error("Proxy request error:", error);
|
|
6135
|
+
reject(error);
|
|
6136
|
+
});
|
|
6137
|
+
req.pipe(proxyReq);
|
|
6138
|
+
});
|
|
6139
|
+
}
|
|
6140
|
+
/**
|
|
6141
|
+
* Inject script and respond with modified HTML
|
|
6142
|
+
* @param proxyRes - Proxy response
|
|
6143
|
+
* @param res - Client response
|
|
6144
|
+
* @param url - Request URL
|
|
6145
|
+
*/
|
|
6146
|
+
injectAndRespond(proxyRes, res, url) {
|
|
6147
|
+
const chunks = [];
|
|
6148
|
+
proxyRes.on("data", (chunk) => {
|
|
6149
|
+
chunks.push(chunk);
|
|
6150
|
+
});
|
|
6151
|
+
proxyRes.on("end", () => {
|
|
6152
|
+
const body = Buffer.concat(chunks).toString("utf-8");
|
|
6153
|
+
const injected = injectScriptTag(body);
|
|
6154
|
+
this.emit("inject", { url });
|
|
6155
|
+
const headers = {};
|
|
6156
|
+
for (const [key, value] of Object.entries(proxyRes.headers)) {
|
|
6157
|
+
const lower = key.toLowerCase();
|
|
6158
|
+
if (lower !== "content-length" && lower !== "transfer-encoding" && value !== void 0) {
|
|
6159
|
+
headers[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
headers["content-length"] = Buffer.byteLength(injected);
|
|
6163
|
+
res.writeHead(proxyRes.statusCode ?? 200, headers);
|
|
6164
|
+
res.end(injected);
|
|
6165
|
+
});
|
|
6166
|
+
proxyRes.on("error", (error) => {
|
|
6167
|
+
logger4.error("Proxy response error:", error);
|
|
6168
|
+
res.writeHead(502);
|
|
6169
|
+
res.end("Bad Gateway");
|
|
6170
|
+
});
|
|
6171
|
+
}
|
|
6172
|
+
/**
|
|
6173
|
+
* Start the proxy server
|
|
6174
|
+
*/
|
|
6175
|
+
async start() {
|
|
6176
|
+
if (this.injectionScript === null) {
|
|
6177
|
+
this.injectionScript = await loadInjectionScript(this.options.wsPort);
|
|
6178
|
+
}
|
|
6179
|
+
return new Promise((resolve3, reject) => {
|
|
6180
|
+
this.server.once("error", reject);
|
|
6181
|
+
this.server.listen(this.options.port, () => {
|
|
6182
|
+
this.server.removeListener("error", reject);
|
|
6183
|
+
const address = this.server.address();
|
|
6184
|
+
if (address && typeof address === "object") {
|
|
6185
|
+
this.options.port = address.port;
|
|
6186
|
+
}
|
|
6187
|
+
this.emit("listening", { port: this.options.port });
|
|
6188
|
+
logger4.info(`Proxy server listening on http://localhost:${this.options.port}`);
|
|
6189
|
+
logger4.info(`Proxying to ${this.options.target}`);
|
|
6190
|
+
resolve3();
|
|
6191
|
+
});
|
|
6192
|
+
});
|
|
6193
|
+
}
|
|
6194
|
+
/**
|
|
6195
|
+
* Stop the proxy server
|
|
6196
|
+
*/
|
|
6197
|
+
stop() {
|
|
6198
|
+
return new Promise((resolve3) => {
|
|
6199
|
+
this.server.close(() => {
|
|
6200
|
+
this.emit("close", void 0);
|
|
6201
|
+
resolve3();
|
|
6202
|
+
});
|
|
6203
|
+
});
|
|
6204
|
+
}
|
|
6205
|
+
/**
|
|
6206
|
+
* Get the proxy URL
|
|
6207
|
+
* @returns Local proxy URL
|
|
6208
|
+
*/
|
|
6209
|
+
getProxyUrl() {
|
|
6210
|
+
return `http://localhost:${this.options.port}`;
|
|
6211
|
+
}
|
|
6212
|
+
/**
|
|
6213
|
+
* Update injection script
|
|
6214
|
+
* @param script - New injection script
|
|
6215
|
+
*/
|
|
6216
|
+
setInjectionScript(script) {
|
|
6217
|
+
this.injectionScript = script;
|
|
6218
|
+
}
|
|
6219
|
+
};
|
|
5793
6220
|
|
|
5794
6221
|
// src/webui/dashboard.ts
|
|
5795
6222
|
function generateDashboardHTML(wsPort, target) {
|
|
@@ -6797,7 +7224,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6797
7224
|
port;
|
|
6798
7225
|
target;
|
|
6799
7226
|
currentState;
|
|
6800
|
-
constructor(port =
|
|
7227
|
+
constructor(port = 3199, target = "") {
|
|
6801
7228
|
super();
|
|
6802
7229
|
this.port = port;
|
|
6803
7230
|
this.target = target;
|
|
@@ -6836,7 +7263,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6836
7263
|
this.server = createServer((req, res) => {
|
|
6837
7264
|
this.handleHttpRequest(req, res);
|
|
6838
7265
|
});
|
|
6839
|
-
this.server.on("upgrade", (req, socket
|
|
7266
|
+
this.server.on("upgrade", (req, socket) => {
|
|
6840
7267
|
this.handleUpgrade(req, socket);
|
|
6841
7268
|
});
|
|
6842
7269
|
this.server.on("error", (error) => {
|
|
@@ -6925,7 +7352,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6925
7352
|
*/
|
|
6926
7353
|
handleClientData(client, socket, data) {
|
|
6927
7354
|
if (data.length < 2) return;
|
|
6928
|
-
const opcode = data[0] & 15;
|
|
7355
|
+
const opcode = (data[0] ?? 0) & 15;
|
|
6929
7356
|
if (opcode === OPCODE2.PING) {
|
|
6930
7357
|
const pong = Buffer.alloc(2);
|
|
6931
7358
|
pong[0] = 138;
|
|
@@ -6970,6 +7397,16 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6970
7397
|
updateFps(fps) {
|
|
6971
7398
|
this.currentState.fps = fps;
|
|
6972
7399
|
}
|
|
7400
|
+
/**
|
|
7401
|
+
* Broadcast components to all clients (for batch updates)
|
|
7402
|
+
*/
|
|
7403
|
+
broadcastComponents() {
|
|
7404
|
+
for (const component of this.currentState.components) {
|
|
7405
|
+
this.broadcast({ type: "component-update", payload: component });
|
|
7406
|
+
}
|
|
7407
|
+
}
|
|
7408
|
+
/** Last render broadcast time */
|
|
7409
|
+
lastRenderBroadcast = 0;
|
|
6973
7410
|
/**
|
|
6974
7411
|
* Add render event
|
|
6975
7412
|
*/
|
|
@@ -6978,7 +7415,11 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6978
7415
|
if (this.currentState.recentRenders.length > 50) {
|
|
6979
7416
|
this.currentState.recentRenders.pop();
|
|
6980
7417
|
}
|
|
6981
|
-
|
|
7418
|
+
const now = Date.now();
|
|
7419
|
+
if (now - this.lastRenderBroadcast >= 100) {
|
|
7420
|
+
this.lastRenderBroadcast = now;
|
|
7421
|
+
this.broadcast({ type: "render-event", payload: render });
|
|
7422
|
+
}
|
|
6982
7423
|
}
|
|
6983
7424
|
/**
|
|
6984
7425
|
* Add chain detected
|
|
@@ -7039,7 +7480,18 @@ var WebUIServer = class extends EventEmitter {
|
|
|
7039
7480
|
return `http://localhost:${this.port}`;
|
|
7040
7481
|
}
|
|
7041
7482
|
};
|
|
7042
|
-
|
|
7483
|
+
|
|
7484
|
+
// src/version.ts
|
|
7485
|
+
var VERSION = "1.3.0";
|
|
7486
|
+
|
|
7487
|
+
// src/cli/commands/scan.ts
|
|
7488
|
+
var logger5 = new Logger({ prefix: "scan", level: 1 /* INFO */ });
|
|
7489
|
+
function canAutoInstall(env = process.env, isTTY = process.stdin.isTTY === true && process.stdout.isTTY === true) {
|
|
7490
|
+
if (!isTTY) return false;
|
|
7491
|
+
if (env["CI"] !== void 0 && env["CI"] !== "" && env["CI"] !== "false" && env["CI"] !== "0") return false;
|
|
7492
|
+
if (env["REACTCHECK_NO_INSTALL"] !== void 0 && env["REACTCHECK_NO_INSTALL"] !== "") return false;
|
|
7493
|
+
return true;
|
|
7494
|
+
}
|
|
7043
7495
|
async function installPuppeteer(wsServer) {
|
|
7044
7496
|
console.log("");
|
|
7045
7497
|
console.log(colors.cyan + "\u{1F4E6} Puppeteer is required for browser automation." + colors.reset);
|
|
@@ -7081,20 +7533,34 @@ async function installPuppeteer(wsServer) {
|
|
|
7081
7533
|
} catch (error) {
|
|
7082
7534
|
console.log("");
|
|
7083
7535
|
console.error("Puppeteer installation error:", error);
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7536
|
+
logger5.error("Failed to install puppeteer automatically.");
|
|
7537
|
+
logger5.info("Please install it manually: npm install puppeteer");
|
|
7538
|
+
logger5.info("Or use --proxy mode: react-check scan --proxy <url>");
|
|
7087
7539
|
return false;
|
|
7088
7540
|
}
|
|
7089
7541
|
}
|
|
7542
|
+
function toFormats(value) {
|
|
7543
|
+
return parseFormatList(value).filter(
|
|
7544
|
+
(f) => f === "html" || f === "json" || f === "md"
|
|
7545
|
+
);
|
|
7546
|
+
}
|
|
7547
|
+
function toSeconds(value) {
|
|
7548
|
+
if (value === void 0) return void 0;
|
|
7549
|
+
const n = Number(value);
|
|
7550
|
+
return Number.isFinite(n) && n > 0 ? n : void 0;
|
|
7551
|
+
}
|
|
7090
7552
|
function parseScanOptions(args) {
|
|
7553
|
+
const format = getStringFlag(args, "format") ?? "all";
|
|
7554
|
+
const provided = args.provided;
|
|
7555
|
+
const reportRequested = getBooleanFlag(args, "report") || (provided?.has("format") ?? false) || (provided?.has("output") ?? false);
|
|
7091
7556
|
return {
|
|
7092
7557
|
target: normalizeTarget(args.target ?? "localhost:3000"),
|
|
7093
7558
|
proxy: getBooleanFlag(args, "proxy"),
|
|
7094
7559
|
tui: getBooleanFlag(args, "tui"),
|
|
7095
7560
|
silent: getBooleanFlag(args, "silent"),
|
|
7096
|
-
report:
|
|
7097
|
-
format
|
|
7561
|
+
report: reportRequested,
|
|
7562
|
+
format,
|
|
7563
|
+
formats: toFormats(format),
|
|
7098
7564
|
output: getStringFlag(args, "output") ?? "./reactcheck-reports",
|
|
7099
7565
|
fix: getBooleanFlag(args, "fix"),
|
|
7100
7566
|
verbose: getBooleanFlag(args, "verbose"),
|
|
@@ -7103,64 +7569,35 @@ function parseScanOptions(args) {
|
|
|
7103
7569
|
thresholdWarning: getNumberFlag(args, "threshold-warning") ?? 20,
|
|
7104
7570
|
fpsThreshold: getNumberFlag(args, "fps-threshold") ?? 30,
|
|
7105
7571
|
headless: getBooleanFlag(args, "headless"),
|
|
7106
|
-
duration:
|
|
7572
|
+
duration: toSeconds(getStringFlag(args, "duration")),
|
|
7107
7573
|
watch: getBooleanFlag(args, "watch"),
|
|
7108
7574
|
configPath: getStringFlag(args, "config"),
|
|
7109
7575
|
webui: getBooleanFlag(args, "webui"),
|
|
7110
|
-
webuiPort: getNumberFlag(args, "webui-port") ??
|
|
7576
|
+
webuiPort: getNumberFlag(args, "webui-port") ?? 3199
|
|
7111
7577
|
};
|
|
7112
7578
|
}
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
7127
|
-
window.__REACTCHECK_INJECTED__ = true;
|
|
7128
|
-
|
|
7129
|
-
// Install React DevTools hook
|
|
7130
|
-
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
7131
|
-
const hook = {
|
|
7132
|
-
renderers: new Map(),
|
|
7133
|
-
supportsFiber: true,
|
|
7134
|
-
inject: function(renderer) {
|
|
7135
|
-
const id = this.renderers.size + 1;
|
|
7136
|
-
this.renderers.set(id, renderer);
|
|
7137
|
-
return id;
|
|
7138
|
-
},
|
|
7139
|
-
onCommitFiberRoot: function(id, root) {
|
|
7140
|
-
// Will be overwritten by full script
|
|
7141
|
-
},
|
|
7142
|
-
onCommitFiberUnmount: function() {},
|
|
7143
|
-
};
|
|
7144
|
-
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
7145
|
-
console.log('[ReactCheck] DevTools hook installed (minimal)');
|
|
7146
|
-
}
|
|
7147
|
-
`;
|
|
7148
|
-
}
|
|
7579
|
+
function mergeScanOptions(options, config, provided) {
|
|
7580
|
+
const configOptions = configToOptions(config);
|
|
7581
|
+
const given = (flag) => provided?.has(flag) ?? true;
|
|
7582
|
+
return {
|
|
7583
|
+
...options,
|
|
7584
|
+
thresholdCritical: given("threshold-critical") ? options.thresholdCritical : configOptions.thresholds.critical,
|
|
7585
|
+
thresholdWarning: given("threshold-warning") ? options.thresholdWarning : configOptions.thresholds.warning,
|
|
7586
|
+
fpsThreshold: given("fps-threshold") ? options.fpsThreshold : configOptions.thresholds.fps,
|
|
7587
|
+
output: given("output") ? options.output : configOptions.report.output,
|
|
7588
|
+
formats: given("format") ? options.formats : configOptions.report.formats,
|
|
7589
|
+
include: configOptions.include,
|
|
7590
|
+
exclude: configOptions.exclude
|
|
7591
|
+
};
|
|
7149
7592
|
}
|
|
7150
7593
|
async function runScanCommand(args) {
|
|
7151
7594
|
const options = parseScanOptions(args);
|
|
7152
7595
|
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
7153
7596
|
if (fromFile) {
|
|
7154
|
-
|
|
7597
|
+
logger5.info(`Using config: ${configPath}`);
|
|
7155
7598
|
}
|
|
7156
7599
|
const configOptions = configToOptions(config);
|
|
7157
|
-
const mergedOptions =
|
|
7158
|
-
...options,
|
|
7159
|
-
thresholdCritical: options.thresholdCritical ?? configOptions.thresholds.critical,
|
|
7160
|
-
thresholdWarning: options.thresholdWarning ?? configOptions.thresholds.warning,
|
|
7161
|
-
fpsThreshold: options.fpsThreshold ?? configOptions.thresholds.fps,
|
|
7162
|
-
output: options.output ?? configOptions.report.output
|
|
7163
|
-
};
|
|
7600
|
+
const mergedOptions = mergeScanOptions(options, config, args.provided);
|
|
7164
7601
|
const session = {
|
|
7165
7602
|
id: generateId("scan"),
|
|
7166
7603
|
startTime: Date.now(),
|
|
@@ -7169,6 +7606,12 @@ async function runScanCommand(args) {
|
|
|
7169
7606
|
critical: mergedOptions.thresholdCritical,
|
|
7170
7607
|
warning: mergedOptions.thresholdWarning,
|
|
7171
7608
|
fps: mergedOptions.fpsThreshold
|
|
7609
|
+
},
|
|
7610
|
+
rules: configOptions.rules,
|
|
7611
|
+
config: {
|
|
7612
|
+
fpsThreshold: mergedOptions.fpsThreshold,
|
|
7613
|
+
...mergedOptions.include ? { include: mergedOptions.include } : {},
|
|
7614
|
+
...mergedOptions.exclude ? { exclude: mergedOptions.exclude } : {}
|
|
7172
7615
|
}
|
|
7173
7616
|
}),
|
|
7174
7617
|
tui: null,
|
|
@@ -7180,10 +7623,11 @@ async function runScanCommand(args) {
|
|
|
7180
7623
|
chains: [],
|
|
7181
7624
|
suggestions: [],
|
|
7182
7625
|
overlayEnabled: true,
|
|
7183
|
-
browserClients: /* @__PURE__ */ new Set()
|
|
7626
|
+
browserClients: /* @__PURE__ */ new Set(),
|
|
7627
|
+
proxy: null
|
|
7184
7628
|
};
|
|
7185
7629
|
setupScannerEvents(session);
|
|
7186
|
-
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && process.stdin.isTTY;
|
|
7630
|
+
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && !mergedOptions.webui && process.stdin.isTTY;
|
|
7187
7631
|
if (useTUI) {
|
|
7188
7632
|
session.tui = new TUI(mergedOptions.target);
|
|
7189
7633
|
setupTUIEvents(session);
|
|
@@ -7194,77 +7638,98 @@ async function runScanCommand(args) {
|
|
|
7194
7638
|
}));
|
|
7195
7639
|
session.tui.start();
|
|
7196
7640
|
} else if (!mergedOptions.silent && !mergedOptions.proxy && !process.stdin.isTTY) {
|
|
7197
|
-
|
|
7641
|
+
logger5.warn("TTY not available, TUI disabled. Use --silent for non-interactive mode.");
|
|
7198
7642
|
}
|
|
7199
7643
|
if (mergedOptions.webui) {
|
|
7200
7644
|
session.webui = new WebUIServer(mergedOptions.webuiPort, mergedOptions.target);
|
|
7201
7645
|
setupWebUIEvents(session);
|
|
7202
7646
|
}
|
|
7203
7647
|
if (!useTUI) {
|
|
7204
|
-
|
|
7648
|
+
logger5.info(`Starting scan of ${mergedOptions.target}`);
|
|
7205
7649
|
}
|
|
7206
7650
|
if (useTUI) {
|
|
7207
|
-
|
|
7651
|
+
logger5.setLevel(4 /* SILENT */);
|
|
7208
7652
|
}
|
|
7209
7653
|
try {
|
|
7210
7654
|
session.wsServer = new WebSocketServer(mergedOptions.port);
|
|
7211
7655
|
await session.wsServer.start();
|
|
7212
|
-
|
|
7656
|
+
logger5.info(`WebSocket server listening on port ${mergedOptions.port}`);
|
|
7213
7657
|
session.wsServer.on("connection", (client) => {
|
|
7214
|
-
|
|
7658
|
+
logger5.info("Browser connected");
|
|
7215
7659
|
session.browserClients.add(client);
|
|
7216
7660
|
handleBrowserMessages(client, (message) => {
|
|
7217
7661
|
switch (message.type) {
|
|
7218
7662
|
case "render":
|
|
7219
7663
|
session.scanner.addRender(message.payload);
|
|
7220
7664
|
break;
|
|
7665
|
+
case "fps":
|
|
7666
|
+
session.scanner.recordFps(message.payload);
|
|
7667
|
+
break;
|
|
7221
7668
|
case "ready":
|
|
7222
|
-
|
|
7669
|
+
logger5.info(`React detected: ${message.payload.reactVersion}`);
|
|
7223
7670
|
client.send(JSON.stringify({ type: "start" }));
|
|
7224
7671
|
client.send(JSON.stringify({ type: "toggle-overlay", payload: { enabled: session.overlayEnabled } }));
|
|
7225
7672
|
break;
|
|
7226
7673
|
case "error":
|
|
7227
|
-
|
|
7674
|
+
logger5.error("Browser error:", message.payload.message);
|
|
7228
7675
|
break;
|
|
7229
7676
|
}
|
|
7230
7677
|
});
|
|
7231
7678
|
client.on("close", () => {
|
|
7232
|
-
|
|
7679
|
+
logger5.info("Browser disconnected");
|
|
7233
7680
|
session.browserClients.delete(client);
|
|
7234
7681
|
});
|
|
7235
7682
|
});
|
|
7236
7683
|
session.scanner.start();
|
|
7237
7684
|
if (session.webui) {
|
|
7238
|
-
|
|
7685
|
+
await session.webui.start();
|
|
7239
7686
|
session.webui.setScanning(true);
|
|
7240
7687
|
const webuiUrl = session.webui.getUrl();
|
|
7241
|
-
|
|
7688
|
+
logger5.info(`WebUI dashboard: ${webuiUrl}`);
|
|
7242
7689
|
openBrowser(webuiUrl);
|
|
7690
|
+
logger5.info("WebUI dashboard opened, Puppeteer will open target URL next...");
|
|
7243
7691
|
}
|
|
7244
7692
|
if (mergedOptions.proxy) {
|
|
7693
|
+
const proxyPort = mergedOptions.port + 1;
|
|
7694
|
+
session.proxy = new ProxyServer({
|
|
7695
|
+
target: mergedOptions.target,
|
|
7696
|
+
port: proxyPort,
|
|
7697
|
+
wsPort: mergedOptions.port,
|
|
7698
|
+
injectionScript: await loadInjectionScript(mergedOptions.port)
|
|
7699
|
+
});
|
|
7700
|
+
await session.proxy.start();
|
|
7701
|
+
const targetUrl = new URL(mergedOptions.target);
|
|
7702
|
+
const proxyUrl = session.proxy.getProxyUrl();
|
|
7703
|
+
const proxiedPage = `${proxyUrl}${targetUrl.pathname}${targetUrl.search}`;
|
|
7245
7704
|
console.log("");
|
|
7246
7705
|
console.log(colors.cyan + colors.bold + "\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557" + colors.reset);
|
|
7247
7706
|
console.log(colors.cyan + colors.bold + "\u2551 PROXY MODE ACTIVE \u2551" + colors.reset);
|
|
7248
7707
|
console.log(colors.cyan + colors.bold + "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D" + colors.reset);
|
|
7249
7708
|
console.log("");
|
|
7250
|
-
console.log(`
|
|
7709
|
+
console.log(` Open ${colors.cyan}${proxiedPage}${colors.reset} (proxies ${mergedOptions.target}) in any browser.`);
|
|
7251
7710
|
console.log("");
|
|
7252
|
-
console.log(
|
|
7253
|
-
console.log(colors.yellow + ` <script src="http://localhost:${mergedOptions.port + 1}/reactcheck.js"></script>` + colors.reset);
|
|
7711
|
+
console.log(" Or add this script to your HTML before React loads:");
|
|
7254
7712
|
console.log("");
|
|
7255
|
-
console.log(`
|
|
7713
|
+
console.log(colors.yellow + ` <script src="${proxyUrl}/__reactcheck__/scanner.js"></script>` + colors.reset);
|
|
7256
7714
|
console.log("");
|
|
7257
7715
|
console.log(` Press ${colors.bold}Ctrl+C${colors.reset} to stop scanning`);
|
|
7258
7716
|
console.log("");
|
|
7259
7717
|
} else {
|
|
7260
7718
|
const hasPuppeteer = await isPuppeteerAvailable();
|
|
7719
|
+
if (!hasPuppeteer && !canAutoInstall()) {
|
|
7720
|
+
logger5.error("Puppeteer is required to launch a browser but is not installed.");
|
|
7721
|
+
logger5.info("Install it with: npm install --save-dev puppeteer");
|
|
7722
|
+
logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
|
|
7723
|
+
await cleanupSession(session);
|
|
7724
|
+
return 2;
|
|
7725
|
+
}
|
|
7261
7726
|
if (!hasPuppeteer) {
|
|
7262
7727
|
const installed = await installPuppeteer(session.wsServer ?? void 0);
|
|
7263
7728
|
if (!installed) {
|
|
7264
7729
|
return 2;
|
|
7265
7730
|
}
|
|
7266
7731
|
}
|
|
7267
|
-
const injectionScript = await
|
|
7732
|
+
const injectionScript = await loadInjectionScript(mergedOptions.port);
|
|
7268
7733
|
session.browser = new BrowserLauncher({
|
|
7269
7734
|
url: mergedOptions.target,
|
|
7270
7735
|
headless: mergedOptions.headless,
|
|
@@ -7272,19 +7737,20 @@ async function runScanCommand(args) {
|
|
|
7272
7737
|
});
|
|
7273
7738
|
session.browser.setInjectionScript(injectionScript);
|
|
7274
7739
|
session.browser.on("console", ({ type, text }) => {
|
|
7275
|
-
if (text.includes("[ReactCheck]")) {
|
|
7276
|
-
|
|
7740
|
+
if (text.includes("[ReactCheck]") || text.includes("ReactCheck") || type === "error") {
|
|
7741
|
+
logger5.info(`Browser [${type}]: ${text}`);
|
|
7277
7742
|
}
|
|
7278
7743
|
});
|
|
7279
7744
|
session.browser.on("error", (error) => {
|
|
7280
|
-
|
|
7745
|
+
logger5.error("Browser error:", error.message);
|
|
7281
7746
|
});
|
|
7282
|
-
|
|
7747
|
+
logger5.info("Launching Puppeteer browser for target URL...");
|
|
7283
7748
|
await session.browser.launch();
|
|
7284
|
-
|
|
7749
|
+
logger5.info("Puppeteer browser launched successfully, now scanning target...");
|
|
7285
7750
|
}
|
|
7286
7751
|
if (mergedOptions.duration) {
|
|
7287
|
-
|
|
7752
|
+
const durationMs = mergedOptions.duration * 1e3;
|
|
7753
|
+
await new Promise((resolve3) => setTimeout(resolve3, durationMs));
|
|
7288
7754
|
session.active = false;
|
|
7289
7755
|
} else if (session.tui) {
|
|
7290
7756
|
await waitForQuit(session);
|
|
@@ -7307,17 +7773,17 @@ async function runScanCommand(args) {
|
|
|
7307
7773
|
await cleanupSession(session);
|
|
7308
7774
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7309
7775
|
if (errorMessage.includes("ERR_CONNECTION_REFUSED")) {
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7776
|
+
logger5.error(`Could not connect to ${mergedOptions.target}`);
|
|
7777
|
+
logger5.info("Make sure your React application is running at that address.");
|
|
7778
|
+
logger5.info("Example: npm start or npm run dev");
|
|
7313
7779
|
} else if (errorMessage.includes("EADDRINUSE")) {
|
|
7314
|
-
|
|
7315
|
-
|
|
7780
|
+
logger5.error(`Port ${mergedOptions.port} is already in use`);
|
|
7781
|
+
logger5.info("Try using a different port with --port <number>");
|
|
7316
7782
|
} else if (errorMessage.includes("ERR_CERT")) {
|
|
7317
|
-
|
|
7318
|
-
|
|
7783
|
+
logger5.error("SSL certificate error");
|
|
7784
|
+
logger5.info("ReactCheck now supports self-signed certificates by default.");
|
|
7319
7785
|
} else {
|
|
7320
|
-
|
|
7786
|
+
logger5.error("Scan failed:", errorMessage);
|
|
7321
7787
|
}
|
|
7322
7788
|
return 2;
|
|
7323
7789
|
}
|
|
@@ -7333,6 +7799,10 @@ async function cleanupSession(session) {
|
|
|
7333
7799
|
if (session.browser) {
|
|
7334
7800
|
await session.browser.close();
|
|
7335
7801
|
}
|
|
7802
|
+
if (session.proxy) {
|
|
7803
|
+
await session.proxy.stop();
|
|
7804
|
+
session.proxy = null;
|
|
7805
|
+
}
|
|
7336
7806
|
if (session.wsServer) {
|
|
7337
7807
|
await session.wsServer.stop();
|
|
7338
7808
|
}
|
|
@@ -7368,12 +7838,12 @@ function setupScannerEvents(session) {
|
|
|
7368
7838
|
});
|
|
7369
7839
|
scanner.on("fps-drop", (fps) => {
|
|
7370
7840
|
if (session.options.verbose) {
|
|
7371
|
-
|
|
7841
|
+
logger5.warn(`FPS dropped to ${fps}`);
|
|
7372
7842
|
}
|
|
7373
7843
|
});
|
|
7374
7844
|
scanner.on("severityChange", ({ component, to }) => {
|
|
7375
7845
|
if (session.options.verbose && to === "critical") {
|
|
7376
|
-
|
|
7846
|
+
logger5.warn(`Component ${component} reached critical severity`);
|
|
7377
7847
|
}
|
|
7378
7848
|
});
|
|
7379
7849
|
}
|
|
@@ -7389,9 +7859,11 @@ function setupTUIEvents(session) {
|
|
|
7389
7859
|
tui.update({ paused: false });
|
|
7390
7860
|
}
|
|
7391
7861
|
});
|
|
7392
|
-
tui.on("generateReport",
|
|
7862
|
+
tui.on("generateReport", () => {
|
|
7393
7863
|
const report = generateReport(session);
|
|
7394
|
-
|
|
7864
|
+
saveReport(report, session.options).catch((error) => {
|
|
7865
|
+
logger5.error("Failed to save report:", error instanceof Error ? error.message : String(error));
|
|
7866
|
+
});
|
|
7395
7867
|
});
|
|
7396
7868
|
tui.on("selectComponent", (component) => {
|
|
7397
7869
|
const suggestions = scanner.analyzeComponent(component.name);
|
|
@@ -7447,7 +7919,7 @@ function generateReport(session) {
|
|
|
7447
7919
|
id: session.id
|
|
7448
7920
|
};
|
|
7449
7921
|
return {
|
|
7450
|
-
version:
|
|
7922
|
+
version: VERSION,
|
|
7451
7923
|
generated: formatDate(),
|
|
7452
7924
|
session: sessionInfo,
|
|
7453
7925
|
summary: exported.stats.summary,
|
|
@@ -7467,7 +7939,7 @@ async function saveReport(report, options) {
|
|
|
7467
7939
|
const { generateMarkdownReport: generateMarkdownReport2 } = await Promise.resolve().then(() => (init_markdown(), markdown_exports));
|
|
7468
7940
|
await ensureDir2(options.output);
|
|
7469
7941
|
const timestamp = Date.now();
|
|
7470
|
-
const formats = options.
|
|
7942
|
+
const formats = options.formats;
|
|
7471
7943
|
for (const format of formats) {
|
|
7472
7944
|
let content;
|
|
7473
7945
|
let extension;
|
|
@@ -7490,7 +7962,7 @@ async function saveReport(report, options) {
|
|
|
7490
7962
|
const filename = `reactcheck-report-${timestamp}.${extension}`;
|
|
7491
7963
|
const filepath = joinPath2(options.output, filename);
|
|
7492
7964
|
await writeTextFile2(filepath, content);
|
|
7493
|
-
|
|
7965
|
+
logger5.info(`Report saved: ${filepath}`);
|
|
7494
7966
|
}
|
|
7495
7967
|
}
|
|
7496
7968
|
function printSummary(session) {
|
|
@@ -7542,11 +8014,17 @@ function printFixSuggestions(suggestions) {
|
|
|
7542
8014
|
function setupWebUIEvents(session) {
|
|
7543
8015
|
const { scanner, webui } = session;
|
|
7544
8016
|
if (!webui) return;
|
|
8017
|
+
let lastBroadcast = 0;
|
|
8018
|
+
const BROADCAST_INTERVAL = 500;
|
|
7545
8019
|
scanner.on("render", (render) => {
|
|
7546
8020
|
webui.addRenderEvent(render);
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
8021
|
+
const now = Date.now();
|
|
8022
|
+
if (now - lastBroadcast >= BROADCAST_INTERVAL) {
|
|
8023
|
+
lastBroadcast = now;
|
|
8024
|
+
webui.updateSummary(scanner.getSummary());
|
|
8025
|
+
webui.updateComponents(scanner.getSnapshot());
|
|
8026
|
+
webui.updateFps(scanner.getFps());
|
|
8027
|
+
}
|
|
7550
8028
|
});
|
|
7551
8029
|
scanner.on("chain", (chain) => {
|
|
7552
8030
|
webui.addChain(chain);
|
|
@@ -7574,39 +8052,39 @@ function openBrowser(url) {
|
|
|
7574
8052
|
}
|
|
7575
8053
|
exec(command, (error) => {
|
|
7576
8054
|
if (error) {
|
|
7577
|
-
|
|
8055
|
+
logger5.debug(`Failed to open browser: ${error.message}`);
|
|
7578
8056
|
}
|
|
7579
8057
|
});
|
|
7580
8058
|
}
|
|
7581
8059
|
|
|
7582
8060
|
// src/cli/commands/init.ts
|
|
7583
8061
|
init_fs();
|
|
7584
|
-
var
|
|
8062
|
+
var logger6 = new Logger({ prefix: "init", level: 1 /* INFO */ });
|
|
7585
8063
|
var DEFAULT_CONFIG_NAME = "reactcheck.config.js";
|
|
7586
8064
|
async function runInitCommand(args) {
|
|
7587
8065
|
const configPath = args.positional[0] ?? DEFAULT_CONFIG_NAME;
|
|
7588
8066
|
if (await exists(configPath)) {
|
|
7589
|
-
|
|
8067
|
+
logger6.warn(`Config file already exists: ${configPath}`);
|
|
7590
8068
|
try {
|
|
7591
8069
|
const content2 = await readTextFile(configPath);
|
|
7592
8070
|
if (configPath.endsWith(".json")) {
|
|
7593
8071
|
const config = JSON.parse(content2);
|
|
7594
8072
|
const errors = validateConfig(config);
|
|
7595
8073
|
if (errors.length > 0) {
|
|
7596
|
-
|
|
8074
|
+
logger6.warn("Existing config has validation errors:");
|
|
7597
8075
|
for (const error of errors) {
|
|
7598
|
-
|
|
8076
|
+
logger6.warn(` - ${error}`);
|
|
7599
8077
|
}
|
|
7600
8078
|
} else {
|
|
7601
|
-
|
|
8079
|
+
logger6.info("Existing config is valid.");
|
|
7602
8080
|
}
|
|
7603
8081
|
}
|
|
7604
8082
|
} catch (error) {
|
|
7605
|
-
|
|
8083
|
+
logger6.warn("Could not validate existing config:", error);
|
|
7606
8084
|
}
|
|
7607
8085
|
console.log("");
|
|
7608
8086
|
console.log(colors.yellow + "? Overwrite existing config? (y/N) " + colors.reset);
|
|
7609
|
-
|
|
8087
|
+
logger6.info("To overwrite, delete the existing file and run init again.");
|
|
7610
8088
|
return 0;
|
|
7611
8089
|
}
|
|
7612
8090
|
const format = configPath.endsWith(".json") ? "json" : "js";
|
|
@@ -7632,14 +8110,709 @@ async function runInitCommand(args) {
|
|
|
7632
8110
|
console.log("");
|
|
7633
8111
|
return 0;
|
|
7634
8112
|
} catch (error) {
|
|
7635
|
-
|
|
8113
|
+
logger6.error(`Failed to create config file:`, error);
|
|
7636
8114
|
return 1;
|
|
7637
8115
|
}
|
|
7638
8116
|
}
|
|
7639
8117
|
|
|
8118
|
+
// src/detect/framework.ts
|
|
8119
|
+
init_fs();
|
|
8120
|
+
var FRAMEWORK_DETECTORS = [
|
|
8121
|
+
// Next.js
|
|
8122
|
+
{
|
|
8123
|
+
name: "next",
|
|
8124
|
+
dependencies: ["next"],
|
|
8125
|
+
features: [
|
|
8126
|
+
{
|
|
8127
|
+
name: "app-router",
|
|
8128
|
+
detect: async (_, dir) => exists(joinPath(dir, "app"))
|
|
8129
|
+
},
|
|
8130
|
+
{
|
|
8131
|
+
name: "pages-router",
|
|
8132
|
+
detect: async (_, dir) => exists(joinPath(dir, "pages"))
|
|
8133
|
+
},
|
|
8134
|
+
{
|
|
8135
|
+
name: "rsc",
|
|
8136
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["next"]) >= 13)
|
|
8137
|
+
},
|
|
8138
|
+
{
|
|
8139
|
+
name: "middleware",
|
|
8140
|
+
detect: async (_, dir) => await exists(joinPath(dir, "middleware.ts")) || await exists(joinPath(dir, "middleware.js"))
|
|
8141
|
+
}
|
|
8142
|
+
],
|
|
8143
|
+
tips: [
|
|
8144
|
+
'Use "use client" directive only for interactive components',
|
|
8145
|
+
"Keep server components as the default for better performance",
|
|
8146
|
+
"Consider using Server Actions for mutations",
|
|
8147
|
+
"Use next/dynamic for code splitting heavy components",
|
|
8148
|
+
"Avoid passing serializable props through server/client boundary"
|
|
8149
|
+
]
|
|
8150
|
+
},
|
|
8151
|
+
// Remix
|
|
8152
|
+
{
|
|
8153
|
+
name: "remix",
|
|
8154
|
+
dependencies: ["@remix-run/react", "@remix-run/node", "@remix-run/cloudflare"],
|
|
8155
|
+
features: [
|
|
8156
|
+
{
|
|
8157
|
+
name: "v2-routes",
|
|
8158
|
+
detect: async (_, dir) => exists(joinPath(dir, "app", "routes"))
|
|
8159
|
+
},
|
|
8160
|
+
{
|
|
8161
|
+
name: "defer",
|
|
8162
|
+
deps: ["@remix-run/react"],
|
|
8163
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["@remix-run/react"]) >= 1)
|
|
8164
|
+
}
|
|
8165
|
+
],
|
|
8166
|
+
tips: [
|
|
8167
|
+
"Use loader data efficiently to minimize client state",
|
|
8168
|
+
"Prefer fetcher over useNavigate for non-navigation mutations",
|
|
8169
|
+
"Use defer for streaming slow data",
|
|
8170
|
+
"Consider using useFetcher.load for background data fetching",
|
|
8171
|
+
"Avoid useEffect for data fetching, use loaders instead"
|
|
8172
|
+
]
|
|
8173
|
+
},
|
|
8174
|
+
// Vite
|
|
8175
|
+
{
|
|
8176
|
+
name: "vite",
|
|
8177
|
+
dependencies: [],
|
|
8178
|
+
devDependencies: ["vite"],
|
|
8179
|
+
features: [
|
|
8180
|
+
{
|
|
8181
|
+
name: "react-plugin",
|
|
8182
|
+
deps: ["@vitejs/plugin-react", "@vitejs/plugin-react-swc"]
|
|
8183
|
+
},
|
|
8184
|
+
{
|
|
8185
|
+
name: "ssr",
|
|
8186
|
+
detect: async (_, dir) => await exists(joinPath(dir, "vite.config.ts")) || await exists(joinPath(dir, "vite.config.js"))
|
|
8187
|
+
}
|
|
8188
|
+
],
|
|
8189
|
+
tips: [
|
|
8190
|
+
"Use React.lazy with Suspense for code splitting",
|
|
8191
|
+
"Configure build.rollupOptions.output.manualChunks for optimal chunking",
|
|
8192
|
+
"Enable build.sourcemap only in development",
|
|
8193
|
+
"Use @vitejs/plugin-react-swc for faster builds",
|
|
8194
|
+
"Consider using vite-plugin-pwa for PWA support"
|
|
8195
|
+
]
|
|
8196
|
+
},
|
|
8197
|
+
// Create React App
|
|
8198
|
+
{
|
|
8199
|
+
name: "cra",
|
|
8200
|
+
dependencies: ["react-scripts"],
|
|
8201
|
+
features: [
|
|
8202
|
+
{
|
|
8203
|
+
name: "typescript",
|
|
8204
|
+
deps: ["typescript"]
|
|
8205
|
+
},
|
|
8206
|
+
{
|
|
8207
|
+
name: "testing-library",
|
|
8208
|
+
deps: ["@testing-library/react"]
|
|
8209
|
+
}
|
|
8210
|
+
],
|
|
8211
|
+
tips: [
|
|
8212
|
+
"Consider migrating to Vite for faster development builds",
|
|
8213
|
+
"Use React.lazy for code splitting",
|
|
8214
|
+
'Run "npm run build -- --stats" to analyze bundle size',
|
|
8215
|
+
"Use REACT_APP_ prefix for environment variables",
|
|
8216
|
+
"Consider ejecting only if absolutely necessary"
|
|
8217
|
+
]
|
|
8218
|
+
},
|
|
8219
|
+
// Gatsby
|
|
8220
|
+
{
|
|
8221
|
+
name: "gatsby",
|
|
8222
|
+
dependencies: ["gatsby"],
|
|
8223
|
+
features: [
|
|
8224
|
+
{
|
|
8225
|
+
name: "v5",
|
|
8226
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["gatsby"]) >= 5)
|
|
8227
|
+
},
|
|
8228
|
+
{
|
|
8229
|
+
name: "image",
|
|
8230
|
+
deps: ["gatsby-plugin-image"]
|
|
8231
|
+
},
|
|
8232
|
+
{
|
|
8233
|
+
name: "graphql",
|
|
8234
|
+
deps: ["gatsby"]
|
|
8235
|
+
}
|
|
8236
|
+
],
|
|
8237
|
+
tips: [
|
|
8238
|
+
"Use gatsby-plugin-image for optimized images",
|
|
8239
|
+
"Prefer StaticQuery over page queries for reusable components",
|
|
8240
|
+
"Use incremental builds for faster development",
|
|
8241
|
+
"Configure proper caching headers for static assets",
|
|
8242
|
+
"Consider using DSG (Deferred Static Generation) for large sites"
|
|
8243
|
+
]
|
|
8244
|
+
}
|
|
8245
|
+
];
|
|
8246
|
+
function getMajorVersion(range) {
|
|
8247
|
+
if (typeof range !== "string") return Number.NaN;
|
|
8248
|
+
const match = /(\d+)(?:\.\d+)*/.exec(range);
|
|
8249
|
+
return match?.[1] !== void 0 ? parseInt(match[1], 10) : Number.NaN;
|
|
8250
|
+
}
|
|
8251
|
+
async function detectFramework(packageJsonPath) {
|
|
8252
|
+
let pkgPath = packageJsonPath;
|
|
8253
|
+
if (!pkgPath) {
|
|
8254
|
+
pkgPath = await findUp("package.json") ?? void 0;
|
|
8255
|
+
}
|
|
8256
|
+
if (!pkgPath || !await exists(pkgPath)) {
|
|
8257
|
+
return null;
|
|
8258
|
+
}
|
|
8259
|
+
let packageJson;
|
|
8260
|
+
try {
|
|
8261
|
+
packageJson = await readJsonFile(pkgPath);
|
|
8262
|
+
} catch {
|
|
8263
|
+
return null;
|
|
8264
|
+
}
|
|
8265
|
+
const projectDir = getDirName(pkgPath);
|
|
8266
|
+
for (const detector of FRAMEWORK_DETECTORS) {
|
|
8267
|
+
const match = await matchFramework(detector, packageJson, projectDir);
|
|
8268
|
+
if (match) {
|
|
8269
|
+
return match;
|
|
8270
|
+
}
|
|
8271
|
+
}
|
|
8272
|
+
return {
|
|
8273
|
+
name: "unknown",
|
|
8274
|
+
version: "",
|
|
8275
|
+
features: [],
|
|
8276
|
+
tips: [
|
|
8277
|
+
"Consider using React.memo for frequently re-rendering components",
|
|
8278
|
+
"Use useCallback for event handlers passed to child components",
|
|
8279
|
+
"Use useMemo for expensive computations",
|
|
8280
|
+
"Avoid inline object/array creation in render"
|
|
8281
|
+
]
|
|
8282
|
+
};
|
|
8283
|
+
}
|
|
8284
|
+
async function matchFramework(detector, packageJson, projectDir) {
|
|
8285
|
+
const allDeps = {
|
|
8286
|
+
...packageJson.dependencies,
|
|
8287
|
+
...packageJson.devDependencies
|
|
8288
|
+
};
|
|
8289
|
+
const mainDep = detector.dependencies.find((dep) => dep in allDeps) ?? detector.devDependencies?.find((dep) => dep in (packageJson.devDependencies ?? {}));
|
|
8290
|
+
if (!mainDep) {
|
|
8291
|
+
return null;
|
|
8292
|
+
}
|
|
8293
|
+
const rawVersion = allDeps[mainDep];
|
|
8294
|
+
const version = typeof rawVersion === "string" ? rawVersion.replace(/[\^~]/g, "") : "unknown";
|
|
8295
|
+
const features = [];
|
|
8296
|
+
for (const feature of detector.features) {
|
|
8297
|
+
let detected = false;
|
|
8298
|
+
if (feature.deps) {
|
|
8299
|
+
detected = feature.deps.some((dep) => dep in allDeps);
|
|
8300
|
+
}
|
|
8301
|
+
if (feature.files && !detected) {
|
|
8302
|
+
for (const file of feature.files) {
|
|
8303
|
+
if (await exists(joinPath(projectDir, file))) {
|
|
8304
|
+
detected = true;
|
|
8305
|
+
break;
|
|
8306
|
+
}
|
|
8307
|
+
}
|
|
8308
|
+
}
|
|
8309
|
+
if (feature.detect && !detected) {
|
|
8310
|
+
try {
|
|
8311
|
+
detected = await feature.detect(packageJson, projectDir);
|
|
8312
|
+
} catch {
|
|
8313
|
+
}
|
|
8314
|
+
}
|
|
8315
|
+
if (detected) {
|
|
8316
|
+
features.push(feature.name);
|
|
8317
|
+
}
|
|
8318
|
+
}
|
|
8319
|
+
return {
|
|
8320
|
+
name: detector.name,
|
|
8321
|
+
version,
|
|
8322
|
+
features,
|
|
8323
|
+
tips: detector.tips
|
|
8324
|
+
};
|
|
8325
|
+
}
|
|
8326
|
+
|
|
8327
|
+
// src/cli/commands/detect.ts
|
|
8328
|
+
init_fs();
|
|
8329
|
+
var logger7 = new Logger({ prefix: "detect", level: 1 /* INFO */ });
|
|
8330
|
+
async function runDetectCommand(args) {
|
|
8331
|
+
const target = resolvePath(process.cwd(), args.positional[0] ?? ".");
|
|
8332
|
+
const pkgPath = await isDirectory(target) ? joinPath(target, "package.json") : target;
|
|
8333
|
+
if (!await exists(pkgPath)) {
|
|
8334
|
+
logger7.error(`No package.json found at ${pkgPath}`);
|
|
8335
|
+
return 2;
|
|
8336
|
+
}
|
|
8337
|
+
const framework = await detectFramework(pkgPath);
|
|
8338
|
+
if (!framework) {
|
|
8339
|
+
logger7.error(`Could not read ${pkgPath}`);
|
|
8340
|
+
return 2;
|
|
8341
|
+
}
|
|
8342
|
+
if (getBooleanFlag(args, "json")) {
|
|
8343
|
+
console.log(JSON.stringify(framework, null, 2));
|
|
8344
|
+
return 0;
|
|
8345
|
+
}
|
|
8346
|
+
const name = framework.name === "unknown" ? "No known React framework" : framework.name;
|
|
8347
|
+
const version = framework.version ? ` ${framework.version}` : "";
|
|
8348
|
+
console.log(`${colors.bold}Framework:${colors.reset} ${name}${version}`);
|
|
8349
|
+
if (framework.features.length > 0) {
|
|
8350
|
+
console.log(`${colors.bold}Features:${colors.reset} ${framework.features.join(", ")}`);
|
|
8351
|
+
}
|
|
8352
|
+
if (framework.tips.length > 0) {
|
|
8353
|
+
console.log(`${colors.bold}Tips:${colors.reset}`);
|
|
8354
|
+
for (const tip of framework.tips) {
|
|
8355
|
+
console.log(` - ${tip}`);
|
|
8356
|
+
}
|
|
8357
|
+
}
|
|
8358
|
+
return 0;
|
|
8359
|
+
}
|
|
8360
|
+
|
|
8361
|
+
// src/cli/commands/report.ts
|
|
8362
|
+
init_json();
|
|
8363
|
+
|
|
8364
|
+
// src/report/index.ts
|
|
8365
|
+
init_json();
|
|
8366
|
+
init_markdown();
|
|
8367
|
+
init_html();
|
|
8368
|
+
init_json();
|
|
8369
|
+
init_markdown();
|
|
8370
|
+
init_html();
|
|
8371
|
+
init_fs();
|
|
8372
|
+
function generateReport2(report, format) {
|
|
8373
|
+
switch (format) {
|
|
8374
|
+
case "html":
|
|
8375
|
+
return generateHTMLReport(report);
|
|
8376
|
+
case "json":
|
|
8377
|
+
return generateJSONReport(report);
|
|
8378
|
+
case "md":
|
|
8379
|
+
return generateMarkdownReport(report);
|
|
8380
|
+
default:
|
|
8381
|
+
throw new Error(`Unknown report format: ${String(format)}`);
|
|
8382
|
+
}
|
|
8383
|
+
}
|
|
8384
|
+
async function saveReport2(report, format, outputDir, filename) {
|
|
8385
|
+
await ensureDir(outputDir);
|
|
8386
|
+
const baseName = filename ?? `reactcheck-report-${Date.now()}`;
|
|
8387
|
+
const extension = format === "md" ? "md" : format;
|
|
8388
|
+
const filePath = joinPath(outputDir, `${baseName}.${extension}`);
|
|
8389
|
+
const content = generateReport2(report, format);
|
|
8390
|
+
await writeTextFile(filePath, content);
|
|
8391
|
+
return filePath;
|
|
8392
|
+
}
|
|
8393
|
+
|
|
8394
|
+
// src/cli/commands/report.ts
|
|
8395
|
+
init_fs();
|
|
8396
|
+
var logger8 = new Logger({ prefix: "report", level: 1 /* INFO */ });
|
|
8397
|
+
async function runReportCommand(args) {
|
|
8398
|
+
const input = args.positional[0];
|
|
8399
|
+
if (!input) {
|
|
8400
|
+
logger8.error("Input JSON report path is required: react-check report <file.json>");
|
|
8401
|
+
return 2;
|
|
8402
|
+
}
|
|
8403
|
+
let content;
|
|
8404
|
+
try {
|
|
8405
|
+
content = await readTextFile(input);
|
|
8406
|
+
} catch (error) {
|
|
8407
|
+
logger8.error(`Cannot read ${input}: ${error instanceof Error ? error.message : String(error)}`);
|
|
8408
|
+
return 2;
|
|
8409
|
+
}
|
|
8410
|
+
let report;
|
|
8411
|
+
try {
|
|
8412
|
+
report = parseJSONReport(content);
|
|
8413
|
+
} catch (error) {
|
|
8414
|
+
logger8.error(`${input} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
8415
|
+
return 2;
|
|
8416
|
+
}
|
|
8417
|
+
const errors = validateJSONReport(report);
|
|
8418
|
+
if (errors.length > 0) {
|
|
8419
|
+
logger8.error(`${input} is not a ReactCheck JSON report:`);
|
|
8420
|
+
for (const error of errors) {
|
|
8421
|
+
logger8.error(` - ${error}`);
|
|
8422
|
+
}
|
|
8423
|
+
return 2;
|
|
8424
|
+
}
|
|
8425
|
+
report.chains = Array.isArray(report.chains) ? report.chains : [];
|
|
8426
|
+
report.suggestions = Array.isArray(report.suggestions) ? report.suggestions : [];
|
|
8427
|
+
report.timeline = Array.isArray(report.timeline) ? report.timeline : [];
|
|
8428
|
+
report.framework = report.framework ?? null;
|
|
8429
|
+
const formats = parseFormatList(getStringFlag(args, "format") ?? "all");
|
|
8430
|
+
const output = getStringFlag(args, "output") ?? "./reactcheck-reports";
|
|
8431
|
+
const baseName = getBaseName(input);
|
|
8432
|
+
for (const format of formats) {
|
|
8433
|
+
const path = await saveReport2(report, format, output, baseName);
|
|
8434
|
+
logger8.info(`Report saved: ${path}`);
|
|
8435
|
+
}
|
|
8436
|
+
return 0;
|
|
8437
|
+
}
|
|
8438
|
+
var InteractiveWizard = class {
|
|
8439
|
+
rl;
|
|
8440
|
+
constructor() {
|
|
8441
|
+
this.rl = readline.createInterface({
|
|
8442
|
+
input: process.stdin,
|
|
8443
|
+
output: process.stdout
|
|
8444
|
+
});
|
|
8445
|
+
}
|
|
8446
|
+
/**
|
|
8447
|
+
* Run the interactive wizard
|
|
8448
|
+
*/
|
|
8449
|
+
async run() {
|
|
8450
|
+
this.printHeader();
|
|
8451
|
+
try {
|
|
8452
|
+
const url = await this.askUrl();
|
|
8453
|
+
if (!url) {
|
|
8454
|
+
this.close();
|
|
8455
|
+
return null;
|
|
8456
|
+
}
|
|
8457
|
+
const mode = await this.askMode();
|
|
8458
|
+
let webuiPort = 3199;
|
|
8459
|
+
if (mode === "webui") {
|
|
8460
|
+
webuiPort = await this.askWebuiPort();
|
|
8461
|
+
}
|
|
8462
|
+
const duration = await this.askDuration();
|
|
8463
|
+
const { warning, critical } = await this.askThresholds();
|
|
8464
|
+
const reportFormats = await this.askReportFormats();
|
|
8465
|
+
const outputDir = await this.askOutputDir();
|
|
8466
|
+
const headless = mode === "webui" ? false : await this.askHeadless();
|
|
8467
|
+
this.printSummary({
|
|
8468
|
+
url,
|
|
8469
|
+
mode,
|
|
8470
|
+
duration,
|
|
8471
|
+
warningThreshold: warning,
|
|
8472
|
+
criticalThreshold: critical,
|
|
8473
|
+
reportFormats,
|
|
8474
|
+
outputDir,
|
|
8475
|
+
headless,
|
|
8476
|
+
webuiPort
|
|
8477
|
+
});
|
|
8478
|
+
const confirmed = await this.askConfirm();
|
|
8479
|
+
this.close();
|
|
8480
|
+
if (!confirmed) {
|
|
8481
|
+
return null;
|
|
8482
|
+
}
|
|
8483
|
+
return {
|
|
8484
|
+
url,
|
|
8485
|
+
mode,
|
|
8486
|
+
duration,
|
|
8487
|
+
warningThreshold: warning,
|
|
8488
|
+
criticalThreshold: critical,
|
|
8489
|
+
reportFormats,
|
|
8490
|
+
outputDir,
|
|
8491
|
+
headless,
|
|
8492
|
+
webuiPort
|
|
8493
|
+
};
|
|
8494
|
+
} catch {
|
|
8495
|
+
this.close();
|
|
8496
|
+
return null;
|
|
8497
|
+
}
|
|
8498
|
+
}
|
|
8499
|
+
/**
|
|
8500
|
+
* Print wizard header
|
|
8501
|
+
*/
|
|
8502
|
+
printHeader() {
|
|
8503
|
+
console.log("");
|
|
8504
|
+
console.log(
|
|
8505
|
+
colors.cyan + "\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510" + colors.reset
|
|
8506
|
+
);
|
|
8507
|
+
console.log(
|
|
8508
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.cyan + "\u2502" + colors.reset
|
|
8509
|
+
);
|
|
8510
|
+
console.log(
|
|
8511
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.bold + colors.green + "\u269B ReactCheck" + colors.reset + " - Interactive Setup Wizard " + colors.cyan + "\u2502" + colors.reset
|
|
8512
|
+
);
|
|
8513
|
+
console.log(
|
|
8514
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.cyan + "\u2502" + colors.reset
|
|
8515
|
+
);
|
|
8516
|
+
console.log(
|
|
8517
|
+
colors.cyan + "\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518" + colors.reset
|
|
8518
|
+
);
|
|
8519
|
+
console.log("");
|
|
8520
|
+
}
|
|
8521
|
+
/**
|
|
8522
|
+
* Ask for URL
|
|
8523
|
+
*/
|
|
8524
|
+
async askUrl() {
|
|
8525
|
+
console.log(colors.bold + "\u{1F4CD} Step 1/7: Target URL" + colors.reset);
|
|
8526
|
+
console.log(colors.dim + " Enter the URL of the React app to scan" + colors.reset);
|
|
8527
|
+
console.log("");
|
|
8528
|
+
const url = await this.prompt(" URL: ", "http://localhost:3000");
|
|
8529
|
+
if (!url) {
|
|
8530
|
+
console.log(colors.yellow + " \u26A0 URL is required" + colors.reset);
|
|
8531
|
+
return this.askUrl();
|
|
8532
|
+
}
|
|
8533
|
+
try {
|
|
8534
|
+
new URL(url);
|
|
8535
|
+
} catch {
|
|
8536
|
+
console.log(colors.red + " \u2717 Invalid URL format" + colors.reset);
|
|
8537
|
+
return this.askUrl();
|
|
8538
|
+
}
|
|
8539
|
+
console.log("");
|
|
8540
|
+
return url;
|
|
8541
|
+
}
|
|
8542
|
+
/**
|
|
8543
|
+
* Ask for display mode
|
|
8544
|
+
*/
|
|
8545
|
+
async askMode() {
|
|
8546
|
+
console.log(colors.bold + "\u{1F5A5}\uFE0F Step 2/7: Display Mode" + colors.reset);
|
|
8547
|
+
console.log(colors.dim + " How do you want to view the results?" + colors.reset);
|
|
8548
|
+
console.log("");
|
|
8549
|
+
const options = [
|
|
8550
|
+
{ label: "TUI", value: "tui", description: "Terminal UI with real-time updates" },
|
|
8551
|
+
{ label: "WebUI", value: "webui", description: "Browser dashboard at localhost:3199" },
|
|
8552
|
+
{ label: "Headless", value: "headless", description: "No UI, just generate reports" }
|
|
8553
|
+
];
|
|
8554
|
+
const mode = await this.selectMenu(options, "tui");
|
|
8555
|
+
console.log("");
|
|
8556
|
+
return mode;
|
|
8557
|
+
}
|
|
8558
|
+
/**
|
|
8559
|
+
* Ask for WebUI port
|
|
8560
|
+
*/
|
|
8561
|
+
async askWebuiPort() {
|
|
8562
|
+
console.log(colors.bold + "\u{1F310} WebUI Port" + colors.reset);
|
|
8563
|
+
console.log(colors.dim + " Which port should the WebUI dashboard use?" + colors.reset);
|
|
8564
|
+
console.log("");
|
|
8565
|
+
const portStr = await this.prompt(" Port: ", "3199");
|
|
8566
|
+
const port = parseInt(portStr, 10);
|
|
8567
|
+
if (isNaN(port) || port < 1 || port > 65535) {
|
|
8568
|
+
console.log(colors.yellow + " \u26A0 Invalid port, using default 3199" + colors.reset);
|
|
8569
|
+
console.log("");
|
|
8570
|
+
return 3199;
|
|
8571
|
+
}
|
|
8572
|
+
console.log("");
|
|
8573
|
+
return port;
|
|
8574
|
+
}
|
|
8575
|
+
/**
|
|
8576
|
+
* Ask for duration
|
|
8577
|
+
*/
|
|
8578
|
+
async askDuration() {
|
|
8579
|
+
console.log(colors.bold + "\u23F1\uFE0F Step 3/7: Scan Duration" + colors.reset);
|
|
8580
|
+
console.log(colors.dim + " How long should the scan run? (in seconds)" + colors.reset);
|
|
8581
|
+
console.log("");
|
|
8582
|
+
const options = [
|
|
8583
|
+
{ label: "15 seconds", value: 15, description: "Quick scan" },
|
|
8584
|
+
{ label: "30 seconds", value: 30, description: "Standard scan (recommended)" },
|
|
8585
|
+
{ label: "60 seconds", value: 60, description: "Thorough scan" },
|
|
8586
|
+
{ label: "120 seconds", value: 120, description: "Extended scan" },
|
|
8587
|
+
{ label: "Custom", value: -1, description: "Enter custom duration" }
|
|
8588
|
+
];
|
|
8589
|
+
const duration = await this.selectMenu(options, 30);
|
|
8590
|
+
if (duration === -1) {
|
|
8591
|
+
const custom = await this.prompt(" Duration (seconds): ", "30");
|
|
8592
|
+
const parsed = parseInt(custom, 10);
|
|
8593
|
+
if (isNaN(parsed) || parsed < 5) {
|
|
8594
|
+
console.log(colors.yellow + " \u26A0 Using default 30 seconds" + colors.reset);
|
|
8595
|
+
console.log("");
|
|
8596
|
+
return 30;
|
|
8597
|
+
}
|
|
8598
|
+
console.log("");
|
|
8599
|
+
return parsed;
|
|
8600
|
+
}
|
|
8601
|
+
console.log("");
|
|
8602
|
+
return duration;
|
|
8603
|
+
}
|
|
8604
|
+
/**
|
|
8605
|
+
* Ask for thresholds
|
|
8606
|
+
*/
|
|
8607
|
+
async askThresholds() {
|
|
8608
|
+
console.log(colors.bold + "\u{1F4CA} Step 4/7: Render Thresholds" + colors.reset);
|
|
8609
|
+
console.log(
|
|
8610
|
+
colors.dim + " Set thresholds for warning and critical render counts" + colors.reset
|
|
8611
|
+
);
|
|
8612
|
+
console.log("");
|
|
8613
|
+
const options = [
|
|
8614
|
+
{ label: "Relaxed", value: { warning: 30, critical: 75 }, description: "For complex apps" },
|
|
8615
|
+
{
|
|
8616
|
+
label: "Standard",
|
|
8617
|
+
value: { warning: 20, critical: 50 },
|
|
8618
|
+
description: "Recommended defaults"
|
|
8619
|
+
},
|
|
8620
|
+
{ label: "Strict", value: { warning: 10, critical: 25 }, description: "High performance" },
|
|
8621
|
+
{ label: "Custom", value: { warning: -1, critical: -1 }, description: "Set your own" }
|
|
8622
|
+
];
|
|
8623
|
+
const result = await this.selectMenu(options, { warning: 20, critical: 50 });
|
|
8624
|
+
if (result.warning === -1) {
|
|
8625
|
+
const warnStr = await this.prompt(" Warning threshold: ", "20");
|
|
8626
|
+
const critStr = await this.prompt(" Critical threshold: ", "50");
|
|
8627
|
+
console.log("");
|
|
8628
|
+
return {
|
|
8629
|
+
warning: parseInt(warnStr, 10) || 20,
|
|
8630
|
+
critical: parseInt(critStr, 10) || 50
|
|
8631
|
+
};
|
|
8632
|
+
}
|
|
8633
|
+
console.log("");
|
|
8634
|
+
return result;
|
|
8635
|
+
}
|
|
8636
|
+
/**
|
|
8637
|
+
* Ask for report formats
|
|
8638
|
+
*/
|
|
8639
|
+
async askReportFormats() {
|
|
8640
|
+
console.log(colors.bold + "\u{1F4C4} Step 5/7: Report Formats" + colors.reset);
|
|
8641
|
+
console.log(
|
|
8642
|
+
colors.dim + " Which report formats do you want to generate?" + colors.reset
|
|
8643
|
+
);
|
|
8644
|
+
console.log("");
|
|
8645
|
+
const formats = [];
|
|
8646
|
+
const htmlAnswer = await this.prompt(
|
|
8647
|
+
" Generate HTML report? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
8648
|
+
"y"
|
|
8649
|
+
);
|
|
8650
|
+
if (htmlAnswer.toLowerCase() !== "n") {
|
|
8651
|
+
formats.push("html");
|
|
8652
|
+
}
|
|
8653
|
+
const jsonAnswer = await this.prompt(
|
|
8654
|
+
" Generate JSON report? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
8655
|
+
"y"
|
|
8656
|
+
);
|
|
8657
|
+
if (jsonAnswer.toLowerCase() !== "n") {
|
|
8658
|
+
formats.push("json");
|
|
8659
|
+
}
|
|
8660
|
+
const mdAnswer = await this.prompt(
|
|
8661
|
+
" Generate Markdown report? " + colors.dim + "(y/N)" + colors.reset + ": ",
|
|
8662
|
+
"n"
|
|
8663
|
+
);
|
|
8664
|
+
if (mdAnswer.toLowerCase() === "y") {
|
|
8665
|
+
formats.push("md");
|
|
8666
|
+
}
|
|
8667
|
+
if (formats.length === 0) {
|
|
8668
|
+
formats.push("html", "json");
|
|
8669
|
+
console.log(colors.dim + " Using default: HTML, JSON" + colors.reset);
|
|
8670
|
+
}
|
|
8671
|
+
console.log("");
|
|
8672
|
+
return formats;
|
|
8673
|
+
}
|
|
8674
|
+
/**
|
|
8675
|
+
* Ask for output directory
|
|
8676
|
+
*/
|
|
8677
|
+
async askOutputDir() {
|
|
8678
|
+
console.log(colors.bold + "\u{1F4C1} Step 6/7: Output Directory" + colors.reset);
|
|
8679
|
+
console.log(colors.dim + " Where should reports be saved?" + colors.reset);
|
|
8680
|
+
console.log("");
|
|
8681
|
+
const dir = await this.prompt(" Directory: ", "./reactcheck-reports");
|
|
8682
|
+
console.log("");
|
|
8683
|
+
return dir || "./reactcheck-reports";
|
|
8684
|
+
}
|
|
8685
|
+
/**
|
|
8686
|
+
* Ask for headless mode
|
|
8687
|
+
*/
|
|
8688
|
+
async askHeadless() {
|
|
8689
|
+
console.log(colors.bold + "\u{1F47B} Step 7/7: Browser Mode" + colors.reset);
|
|
8690
|
+
console.log(colors.dim + " Run browser in headless mode (invisible)?" + colors.reset);
|
|
8691
|
+
console.log(colors.dim + " Note: If you want to interact with your site, choose No." + colors.reset);
|
|
8692
|
+
console.log("");
|
|
8693
|
+
const answer = await this.prompt(
|
|
8694
|
+
" Headless browser? " + colors.dim + "(y/N)" + colors.reset + ": ",
|
|
8695
|
+
"n"
|
|
8696
|
+
);
|
|
8697
|
+
console.log("");
|
|
8698
|
+
return answer.toLowerCase() === "y";
|
|
8699
|
+
}
|
|
8700
|
+
/**
|
|
8701
|
+
* Print configuration summary
|
|
8702
|
+
*/
|
|
8703
|
+
printSummary(config) {
|
|
8704
|
+
console.log(
|
|
8705
|
+
colors.cyan + "\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510" + colors.reset
|
|
8706
|
+
);
|
|
8707
|
+
console.log(
|
|
8708
|
+
colors.cyan + "\u2502" + colors.reset + colors.bold + " Configuration Summary " + colors.reset + colors.cyan + "\u2502" + colors.reset
|
|
8709
|
+
);
|
|
8710
|
+
console.log(
|
|
8711
|
+
colors.cyan + "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524" + colors.reset
|
|
8712
|
+
);
|
|
8713
|
+
console.log(
|
|
8714
|
+
colors.cyan + "\u2502" + colors.reset + ` URL: ${this.pad(config.url, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8715
|
+
);
|
|
8716
|
+
console.log(
|
|
8717
|
+
colors.cyan + "\u2502" + colors.reset + ` Mode: ${this.pad(config.mode.toUpperCase(), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8718
|
+
);
|
|
8719
|
+
console.log(
|
|
8720
|
+
colors.cyan + "\u2502" + colors.reset + ` Duration: ${this.pad(config.duration + " seconds", 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8721
|
+
);
|
|
8722
|
+
console.log(
|
|
8723
|
+
colors.cyan + "\u2502" + colors.reset + ` Thresholds: ${this.pad(`Warning: ${config.warningThreshold}, Critical: ${config.criticalThreshold}`, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8724
|
+
);
|
|
8725
|
+
console.log(
|
|
8726
|
+
colors.cyan + "\u2502" + colors.reset + ` Reports: ${this.pad(config.reportFormats.join(", ").toUpperCase(), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8727
|
+
);
|
|
8728
|
+
console.log(
|
|
8729
|
+
colors.cyan + "\u2502" + colors.reset + ` Output: ${this.pad(config.outputDir, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8730
|
+
);
|
|
8731
|
+
console.log(
|
|
8732
|
+
colors.cyan + "\u2502" + colors.reset + ` Headless: ${this.pad(config.headless ? "Yes" : "No", 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8733
|
+
);
|
|
8734
|
+
if (config.mode === "webui") {
|
|
8735
|
+
console.log(
|
|
8736
|
+
colors.cyan + "\u2502" + colors.reset + ` WebUI Port: ${this.pad(String(config.webuiPort), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
8737
|
+
);
|
|
8738
|
+
}
|
|
8739
|
+
console.log(
|
|
8740
|
+
colors.cyan + "\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518" + colors.reset
|
|
8741
|
+
);
|
|
8742
|
+
console.log("");
|
|
8743
|
+
}
|
|
8744
|
+
/**
|
|
8745
|
+
* Ask for confirmation
|
|
8746
|
+
*/
|
|
8747
|
+
async askConfirm() {
|
|
8748
|
+
const answer = await this.prompt(
|
|
8749
|
+
colors.green + " Start scan with these settings? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
8750
|
+
"y"
|
|
8751
|
+
);
|
|
8752
|
+
return answer.toLowerCase() !== "n";
|
|
8753
|
+
}
|
|
8754
|
+
/**
|
|
8755
|
+
* Prompt for input
|
|
8756
|
+
*/
|
|
8757
|
+
prompt(question, defaultValue = "") {
|
|
8758
|
+
return new Promise((resolve3) => {
|
|
8759
|
+
const defaultHint = defaultValue ? colors.dim + ` [${defaultValue}]` + colors.reset : "";
|
|
8760
|
+
this.rl.question(question + defaultHint + " ", (answer) => {
|
|
8761
|
+
resolve3(answer.trim() || defaultValue);
|
|
8762
|
+
});
|
|
8763
|
+
});
|
|
8764
|
+
}
|
|
8765
|
+
/**
|
|
8766
|
+
* Display a menu and get selection
|
|
8767
|
+
*/
|
|
8768
|
+
async selectMenu(options, defaultValue) {
|
|
8769
|
+
options.forEach((opt, i) => {
|
|
8770
|
+
const isDefault = JSON.stringify(opt.value) === JSON.stringify(defaultValue);
|
|
8771
|
+
const marker = isDefault ? colors.green + "\u25CF" + colors.reset : colors.dim + "\u25CB" + colors.reset;
|
|
8772
|
+
const label = isDefault ? colors.bold + opt.label + colors.reset : opt.label;
|
|
8773
|
+
const desc = opt.description ? colors.dim + " - " + opt.description + colors.reset : "";
|
|
8774
|
+
console.log(` ${marker} ${i + 1}. ${label}${desc}`);
|
|
8775
|
+
});
|
|
8776
|
+
console.log("");
|
|
8777
|
+
const answer = await this.prompt(" Select option: ", "");
|
|
8778
|
+
const num = parseInt(answer, 10);
|
|
8779
|
+
if (num >= 1 && num <= options.length) {
|
|
8780
|
+
const selected = options[num - 1];
|
|
8781
|
+
if (selected) {
|
|
8782
|
+
return selected.value;
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
const matched = options.find(
|
|
8786
|
+
(opt) => opt.label.toLowerCase() === answer.toLowerCase()
|
|
8787
|
+
);
|
|
8788
|
+
if (matched) {
|
|
8789
|
+
return matched.value;
|
|
8790
|
+
}
|
|
8791
|
+
return defaultValue;
|
|
8792
|
+
}
|
|
8793
|
+
/**
|
|
8794
|
+
* Pad string to fixed width
|
|
8795
|
+
*/
|
|
8796
|
+
pad(str, width) {
|
|
8797
|
+
if (str.length >= width) {
|
|
8798
|
+
return str.substring(0, width - 3) + "...";
|
|
8799
|
+
}
|
|
8800
|
+
return str + " ".repeat(width - str.length);
|
|
8801
|
+
}
|
|
8802
|
+
/**
|
|
8803
|
+
* Close readline interface
|
|
8804
|
+
*/
|
|
8805
|
+
close() {
|
|
8806
|
+
this.rl.close();
|
|
8807
|
+
}
|
|
8808
|
+
};
|
|
8809
|
+
async function runInteractiveWizard() {
|
|
8810
|
+
const wizard = new InteractiveWizard();
|
|
8811
|
+
return wizard.run();
|
|
8812
|
+
}
|
|
8813
|
+
|
|
7640
8814
|
// src/cli/index.ts
|
|
7641
|
-
var
|
|
7642
|
-
var VERSION = "1.1.6";
|
|
8815
|
+
var logger9 = new Logger({ prefix: "ReactCheck", level: 1 /* INFO */ });
|
|
7643
8816
|
function printVersion() {
|
|
7644
8817
|
console.log(`@oxog/react-check v${VERSION}`);
|
|
7645
8818
|
}
|
|
@@ -7666,6 +8839,48 @@ var CLI = class {
|
|
|
7666
8839
|
constructor(argv) {
|
|
7667
8840
|
this.argv = argv;
|
|
7668
8841
|
}
|
|
8842
|
+
/**
|
|
8843
|
+
* Convert wizard config to ParsedArgs
|
|
8844
|
+
* @param config - Wizard configuration
|
|
8845
|
+
* @returns Parsed arguments for scan command
|
|
8846
|
+
*/
|
|
8847
|
+
wizardConfigToArgs(config) {
|
|
8848
|
+
const flags = /* @__PURE__ */ new Map();
|
|
8849
|
+
if (config.mode === "tui") {
|
|
8850
|
+
flags.set("tui", true);
|
|
8851
|
+
} else if (config.mode === "webui") {
|
|
8852
|
+
flags.set("webui", true);
|
|
8853
|
+
flags.set("webui-port", String(config.webuiPort));
|
|
8854
|
+
} else if (config.mode === "headless") {
|
|
8855
|
+
flags.set("silent", true);
|
|
8856
|
+
}
|
|
8857
|
+
if (config.duration) {
|
|
8858
|
+
flags.set("duration", String(config.duration));
|
|
8859
|
+
}
|
|
8860
|
+
flags.set("threshold-warning", String(config.warningThreshold));
|
|
8861
|
+
flags.set("threshold-critical", String(config.criticalThreshold));
|
|
8862
|
+
if (config.reportFormats.length > 0) {
|
|
8863
|
+
flags.set("report", true);
|
|
8864
|
+
if (config.reportFormats.length === 3) {
|
|
8865
|
+
flags.set("format", "all");
|
|
8866
|
+
} else {
|
|
8867
|
+
const firstFormat = config.reportFormats[0];
|
|
8868
|
+
if (firstFormat) {
|
|
8869
|
+
flags.set("format", firstFormat);
|
|
8870
|
+
}
|
|
8871
|
+
}
|
|
8872
|
+
}
|
|
8873
|
+
flags.set("output", config.outputDir);
|
|
8874
|
+
flags.set("headless", config.headless);
|
|
8875
|
+
return {
|
|
8876
|
+
command: "scan",
|
|
8877
|
+
target: config.url,
|
|
8878
|
+
flags,
|
|
8879
|
+
positional: [],
|
|
8880
|
+
raw: [],
|
|
8881
|
+
provided: new Set(flags.keys())
|
|
8882
|
+
};
|
|
8883
|
+
}
|
|
7669
8884
|
/**
|
|
7670
8885
|
* Run the CLI
|
|
7671
8886
|
* @returns Exit code
|
|
@@ -7684,21 +8899,42 @@ var CLI = class {
|
|
|
7684
8899
|
case "init":
|
|
7685
8900
|
printBanner();
|
|
7686
8901
|
return await runInitCommand(args);
|
|
8902
|
+
case "detect":
|
|
8903
|
+
case "report": {
|
|
8904
|
+
const errors = validateArgs(args);
|
|
8905
|
+
if (errors.length > 0) {
|
|
8906
|
+
for (const error of errors) {
|
|
8907
|
+
logger9.error(error);
|
|
8908
|
+
}
|
|
8909
|
+
return 2;
|
|
8910
|
+
}
|
|
8911
|
+
return args.command === "detect" ? await runDetectCommand(args) : await runReportCommand(args);
|
|
8912
|
+
}
|
|
7687
8913
|
case "scan":
|
|
7688
|
-
default:
|
|
8914
|
+
default: {
|
|
8915
|
+
if (!args.target && args.raw.length === 0 && process.stdin.isTTY) {
|
|
8916
|
+
printBanner();
|
|
8917
|
+
const wizardConfig = await runInteractiveWizard();
|
|
8918
|
+
if (!wizardConfig) {
|
|
8919
|
+
return 0;
|
|
8920
|
+
}
|
|
8921
|
+
const wizardArgs = this.wizardConfigToArgs(wizardConfig);
|
|
8922
|
+
return await runScanCommand(wizardArgs);
|
|
8923
|
+
}
|
|
7689
8924
|
const errors = validateArgs(args);
|
|
7690
8925
|
if (errors.length > 0) {
|
|
7691
8926
|
for (const error of errors) {
|
|
7692
|
-
|
|
8927
|
+
logger9.error(error);
|
|
7693
8928
|
}
|
|
7694
8929
|
console.log("");
|
|
7695
8930
|
console.log("Run " + colors.cyan + "react-check --help" + colors.reset + " for usage information.");
|
|
7696
8931
|
return 2;
|
|
7697
8932
|
}
|
|
7698
8933
|
return await runScanCommand(args);
|
|
8934
|
+
}
|
|
7699
8935
|
}
|
|
7700
8936
|
} catch (error) {
|
|
7701
|
-
|
|
8937
|
+
logger9.error("Unexpected error:", error);
|
|
7702
8938
|
return 1;
|
|
7703
8939
|
}
|
|
7704
8940
|
}
|
|
@@ -7723,6 +8959,6 @@ if (!process.env.VITEST) {
|
|
|
7723
8959
|
});
|
|
7724
8960
|
}
|
|
7725
8961
|
|
|
7726
|
-
export { CLI, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, validateArgs, validateConfig };
|
|
8962
|
+
export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
|
|
7727
8963
|
//# sourceMappingURL=cli.js.map
|
|
7728
8964
|
//# sourceMappingURL=cli.js.map
|