@oxog/react-check 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -0
- package/README.md +142 -50
- package/dist/browser-inject.global.js +13 -13
- package/dist/chain.cjs +8 -531
- package/dist/chain.cjs.map +1 -1
- package/dist/chain.d.cts +2 -2
- package/dist/chain.d.ts +2 -2
- package/dist/chain.js +2 -533
- package/dist/chain.js.map +1 -1
- package/dist/chunk-27R56V2S.js +473 -0
- package/dist/chunk-27R56V2S.js.map +1 -0
- package/dist/chunk-3K2AER5M.cjs +356 -0
- package/dist/chunk-3K2AER5M.cjs.map +1 -0
- package/dist/chunk-7R4KKJTW.cjs +255 -0
- package/dist/chunk-7R4KKJTW.cjs.map +1 -0
- package/dist/chunk-7YYMP3PP.js +723 -0
- package/dist/chunk-7YYMP3PP.js.map +1 -0
- package/dist/chunk-DWM55ACO.cjs +294 -0
- package/dist/chunk-DWM55ACO.cjs.map +1 -0
- package/dist/chunk-G7YVIPS7.cjs +475 -0
- package/dist/chunk-G7YVIPS7.cjs.map +1 -0
- package/dist/chunk-GE2ZX7I7.cjs +727 -0
- package/dist/chunk-GE2ZX7I7.cjs.map +1 -0
- package/dist/chunk-GS7T56RP.cjs +9 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -0
- package/dist/chunk-IM6OG2IC.js +338 -0
- package/dist/chunk-IM6OG2IC.js.map +1 -0
- package/dist/chunk-RQYHXWUC.js +292 -0
- package/dist/chunk-RQYHXWUC.js.map +1 -0
- package/dist/chunk-WLN7ZVO4.js +253 -0
- package/dist/chunk-WLN7ZVO4.js.map +1 -0
- package/dist/cli.js +975 -204
- package/dist/cli.js.map +1 -1
- package/dist/detect.cjs +22 -324
- package/dist/detect.cjs.map +1 -1
- package/dist/detect.d.cts +8 -2
- package/dist/detect.d.ts +8 -2
- package/dist/detect.js +1 -324
- package/dist/detect.js.map +1 -1
- package/dist/{event-emitter-CxKUDo9q.d.cts → event-emitter-BVYUPYLd.d.cts} +3 -2
- package/dist/{event-emitter-CxKUDo9q.d.ts → event-emitter-BVYUPYLd.d.ts} +3 -2
- package/dist/fix.cjs +6 -715
- package/dist/fix.cjs.map +1 -1
- package/dist/fix.d.cts +2 -2
- package/dist/fix.d.ts +2 -2
- package/dist/fix.js +2 -719
- package/dist/fix.js.map +1 -1
- package/dist/index.cjs +1238 -2987
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +166 -50
- package/dist/index.d.ts +166 -50
- package/dist/index.js +1137 -2959
- package/dist/index.js.map +1 -1
- package/dist/{scanner-Cc2187fH.d.ts → scanner-D0mBQGTx.d.ts} +23 -3
- package/dist/{scanner-S7BtVIpW.d.cts → scanner-DUBgwztZ.d.cts} +23 -3
- package/dist/scanner.cjs +8 -1652
- package/dist/scanner.cjs.map +1 -1
- package/dist/scanner.d.cts +3 -3
- package/dist/scanner.d.ts +3 -3
- package/dist/scanner.js +4 -1656
- package/dist/scanner.js.map +1 -1
- package/dist/{types-DuZyBVVV.d.cts → types-BZ3OeZ-5.d.cts} +28 -10
- package/dist/{types-DuZyBVVV.d.ts → types-BZ3OeZ-5.d.ts} +28 -10
- package/package.json +16 -9
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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';
|
|
9
10
|
import * as readline from 'readline';
|
|
10
11
|
|
|
@@ -132,23 +133,17 @@ function getDirName(path) {
|
|
|
132
133
|
}
|
|
133
134
|
async function findUp(filename, startDir = process.cwd()) {
|
|
134
135
|
let currentDir = resolve(startDir);
|
|
135
|
-
|
|
136
|
-
while (currentDir !== root) {
|
|
136
|
+
for (; ; ) {
|
|
137
137
|
const filePath = join(currentDir, filename);
|
|
138
138
|
if (await exists(filePath)) {
|
|
139
139
|
return filePath;
|
|
140
140
|
}
|
|
141
141
|
const parentDir = dirname(currentDir);
|
|
142
142
|
if (parentDir === currentDir) {
|
|
143
|
-
|
|
143
|
+
return null;
|
|
144
144
|
}
|
|
145
145
|
currentDir = parentDir;
|
|
146
146
|
}
|
|
147
|
-
const rootFilePath = join(currentDir, filename);
|
|
148
|
-
if (await exists(rootFilePath)) {
|
|
149
|
-
return rootFilePath;
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
147
|
}
|
|
153
148
|
async function copyFile(src, dest) {
|
|
154
149
|
const content = await readFile(src);
|
|
@@ -1212,8 +1207,18 @@ var FLAG_DEFINITIONS = {
|
|
|
1212
1207
|
description: "WebUI dashboard port",
|
|
1213
1208
|
takesValue: true,
|
|
1214
1209
|
default: "3199"
|
|
1210
|
+
},
|
|
1211
|
+
json: {
|
|
1212
|
+
description: "Print machine-readable JSON (detect command)",
|
|
1213
|
+
default: false
|
|
1215
1214
|
}
|
|
1216
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
|
+
}
|
|
1217
1222
|
function buildShortFlagMap() {
|
|
1218
1223
|
const map = /* @__PURE__ */ new Map();
|
|
1219
1224
|
for (const [long, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
@@ -1225,11 +1230,23 @@ function buildShortFlagMap() {
|
|
|
1225
1230
|
}
|
|
1226
1231
|
var SHORT_FLAGS = buildShortFlagMap();
|
|
1227
1232
|
function parseArgs(argv) {
|
|
1233
|
+
const provided = /* @__PURE__ */ new Set();
|
|
1234
|
+
const unknown = [];
|
|
1228
1235
|
const result = {
|
|
1229
1236
|
command: "scan",
|
|
1230
1237
|
flags: /* @__PURE__ */ new Map(),
|
|
1231
1238
|
positional: [],
|
|
1232
|
-
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);
|
|
1233
1250
|
};
|
|
1234
1251
|
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1235
1252
|
if (def.default !== void 0) {
|
|
@@ -1249,8 +1266,8 @@ function parseArgs(argv) {
|
|
|
1249
1266
|
i++;
|
|
1250
1267
|
continue;
|
|
1251
1268
|
}
|
|
1252
|
-
if (arg === "init") {
|
|
1253
|
-
result.command =
|
|
1269
|
+
if (arg === "init" || arg === "detect" || arg === "report") {
|
|
1270
|
+
result.command = arg;
|
|
1254
1271
|
i++;
|
|
1255
1272
|
continue;
|
|
1256
1273
|
}
|
|
@@ -1269,7 +1286,7 @@ function parseArgs(argv) {
|
|
|
1269
1286
|
const eqIndex = arg.indexOf("=");
|
|
1270
1287
|
const flagName = arg.slice(2, eqIndex);
|
|
1271
1288
|
const value = arg.slice(eqIndex + 1);
|
|
1272
|
-
|
|
1289
|
+
setFlag(flagName, value, arg);
|
|
1273
1290
|
i++;
|
|
1274
1291
|
continue;
|
|
1275
1292
|
}
|
|
@@ -1279,12 +1296,12 @@ function parseArgs(argv) {
|
|
|
1279
1296
|
if (def?.takesValue) {
|
|
1280
1297
|
const nextArg = argv[i + 1];
|
|
1281
1298
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1282
|
-
|
|
1299
|
+
setFlag(flagName, nextArg, arg);
|
|
1283
1300
|
i += 2;
|
|
1284
1301
|
continue;
|
|
1285
1302
|
}
|
|
1286
1303
|
}
|
|
1287
|
-
|
|
1304
|
+
setFlag(flagName, true, arg);
|
|
1288
1305
|
i++;
|
|
1289
1306
|
continue;
|
|
1290
1307
|
}
|
|
@@ -1294,7 +1311,7 @@ function parseArgs(argv) {
|
|
|
1294
1311
|
if (longFlag) {
|
|
1295
1312
|
const def = FLAG_DEFINITIONS[longFlag];
|
|
1296
1313
|
if (arg.length > 2 && def?.takesValue) {
|
|
1297
|
-
|
|
1314
|
+
setFlag(longFlag, arg.slice(2), arg);
|
|
1298
1315
|
i++;
|
|
1299
1316
|
continue;
|
|
1300
1317
|
}
|
|
@@ -1304,7 +1321,9 @@ function parseArgs(argv) {
|
|
|
1304
1321
|
if (sf) {
|
|
1305
1322
|
const lf = SHORT_FLAGS.get(sf);
|
|
1306
1323
|
if (lf) {
|
|
1307
|
-
|
|
1324
|
+
setFlag(lf, true, `-${sf}`);
|
|
1325
|
+
} else {
|
|
1326
|
+
unknown.push(`-${sf}`);
|
|
1308
1327
|
}
|
|
1309
1328
|
}
|
|
1310
1329
|
}
|
|
@@ -1314,12 +1333,12 @@ function parseArgs(argv) {
|
|
|
1314
1333
|
if (def?.takesValue) {
|
|
1315
1334
|
const nextArg = argv[i + 1];
|
|
1316
1335
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1317
|
-
|
|
1336
|
+
setFlag(longFlag, nextArg, arg);
|
|
1318
1337
|
i += 2;
|
|
1319
1338
|
continue;
|
|
1320
1339
|
}
|
|
1321
1340
|
}
|
|
1322
|
-
|
|
1341
|
+
setFlag(longFlag, true, arg);
|
|
1323
1342
|
i++;
|
|
1324
1343
|
continue;
|
|
1325
1344
|
}
|
|
@@ -1329,7 +1348,9 @@ function parseArgs(argv) {
|
|
|
1329
1348
|
if (sf) {
|
|
1330
1349
|
const lf = SHORT_FLAGS.get(sf);
|
|
1331
1350
|
if (lf) {
|
|
1332
|
-
|
|
1351
|
+
setFlag(lf, true, `-${sf}`);
|
|
1352
|
+
} else {
|
|
1353
|
+
unknown.push(`-${sf}`);
|
|
1333
1354
|
}
|
|
1334
1355
|
}
|
|
1335
1356
|
}
|
|
@@ -1346,6 +1367,7 @@ function parseArgs(argv) {
|
|
|
1346
1367
|
i++;
|
|
1347
1368
|
continue;
|
|
1348
1369
|
}
|
|
1370
|
+
unknown.push(arg);
|
|
1349
1371
|
i++;
|
|
1350
1372
|
}
|
|
1351
1373
|
if (result.flags.get("help") === true) {
|
|
@@ -1377,30 +1399,63 @@ function getNumberFlag(args, name) {
|
|
|
1377
1399
|
}
|
|
1378
1400
|
function validateArgs(args) {
|
|
1379
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
|
+
}
|
|
1380
1410
|
if (args.command === "scan" && !args.target) {
|
|
1381
1411
|
errors.push("Target URL is required for scan command");
|
|
1382
1412
|
}
|
|
1413
|
+
if (args.command === "report" && args.positional.length === 0) {
|
|
1414
|
+
errors.push("Input JSON report path is required for report command");
|
|
1415
|
+
}
|
|
1383
1416
|
if (args.target) {
|
|
1384
1417
|
try {
|
|
1385
|
-
const url = args.target
|
|
1386
|
-
|
|
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
|
+
}
|
|
1387
1422
|
} catch {
|
|
1388
1423
|
errors.push(`Invalid URL: ${args.target}`);
|
|
1389
1424
|
}
|
|
1390
1425
|
}
|
|
1391
1426
|
const format = getStringFlag(args, "format");
|
|
1392
|
-
if (format
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
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
|
+
}
|
|
1398
1433
|
}
|
|
1399
|
-
const
|
|
1400
|
-
|
|
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);
|
|
1401
1449
|
if (critical !== void 0 && warning !== void 0 && critical <= warning) {
|
|
1402
1450
|
errors.push("Critical threshold must be greater than warning threshold");
|
|
1403
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
|
+
}
|
|
1404
1459
|
return errors;
|
|
1405
1460
|
}
|
|
1406
1461
|
function getHelpText() {
|
|
@@ -1410,6 +1465,9 @@ function getHelpText() {
|
|
|
1410
1465
|
"",
|
|
1411
1466
|
"Usage:",
|
|
1412
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",
|
|
1413
1471
|
" react-check init Create default config file",
|
|
1414
1472
|
" react-check help Show this help message",
|
|
1415
1473
|
" react-check version Show version number",
|
|
@@ -1417,8 +1475,8 @@ function getHelpText() {
|
|
|
1417
1475
|
"Options:"
|
|
1418
1476
|
];
|
|
1419
1477
|
const groups = {
|
|
1420
|
-
"General": ["help", "version", "verbose", "config"],
|
|
1421
|
-
"Mode": ["proxy", "tui", "silent", "headless", "watch"],
|
|
1478
|
+
"General": ["help", "version", "verbose", "config", "json"],
|
|
1479
|
+
"Mode": ["proxy", "tui", "silent", "headless", "watch", "webui", "webui-port"],
|
|
1422
1480
|
"Report": ["report", "format", "output", "fix"],
|
|
1423
1481
|
"Thresholds": ["threshold-critical", "threshold-warning", "fps-threshold"],
|
|
1424
1482
|
"Network": ["port", "duration"]
|
|
@@ -1452,9 +1510,16 @@ function getHelpText() {
|
|
|
1452
1510
|
lines.push(" react-check localhost:3000");
|
|
1453
1511
|
lines.push(" react-check https://myapp.dev --report --format=html");
|
|
1454
1512
|
lines.push(" react-check localhost:3000 --proxy --fix --verbose");
|
|
1455
|
-
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");
|
|
1456
1521
|
lines.push("");
|
|
1457
|
-
lines.push("Documentation: https://
|
|
1522
|
+
lines.push("Documentation: https://reactcheck.oxog.dev");
|
|
1458
1523
|
lines.push("");
|
|
1459
1524
|
return lines.join("\n");
|
|
1460
1525
|
}
|
|
@@ -1817,7 +1882,7 @@ var Logger = class _Logger {
|
|
|
1817
1882
|
for (const col of cols) {
|
|
1818
1883
|
widths[col] = col.length;
|
|
1819
1884
|
for (const row of data) {
|
|
1820
|
-
const value =
|
|
1885
|
+
const value = formatCell(row[col]);
|
|
1821
1886
|
widths[col] = Math.max(widths[col] ?? 0, value.length);
|
|
1822
1887
|
}
|
|
1823
1888
|
}
|
|
@@ -1826,7 +1891,7 @@ var Logger = class _Logger {
|
|
|
1826
1891
|
this.output.log(colors.bold + header + colors.reset);
|
|
1827
1892
|
this.output.log(separator);
|
|
1828
1893
|
for (const row of data) {
|
|
1829
|
-
const line = cols.map((col) =>
|
|
1894
|
+
const line = cols.map((col) => formatCell(row[col]).padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
1830
1895
|
this.output.log(line);
|
|
1831
1896
|
}
|
|
1832
1897
|
}
|
|
@@ -1877,6 +1942,27 @@ var Logger = class _Logger {
|
|
|
1877
1942
|
}
|
|
1878
1943
|
};
|
|
1879
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
|
+
}
|
|
1880
1966
|
|
|
1881
1967
|
// src/cli/config.ts
|
|
1882
1968
|
var logger2 = new Logger({ prefix: "config", level: 2 /* WARN */ });
|
|
@@ -2019,12 +2105,9 @@ function validateConfig(config) {
|
|
|
2019
2105
|
if (config.rules) {
|
|
2020
2106
|
const validLevels = ["off", "warn", "error"];
|
|
2021
2107
|
for (const [rule, level] of Object.entries(config.rules)) {
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
}
|
|
2026
|
-
} else if (!validLevels.includes(level)) {
|
|
2027
|
-
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)}`);
|
|
2028
2111
|
}
|
|
2029
2112
|
}
|
|
2030
2113
|
}
|
|
@@ -2088,22 +2171,35 @@ export default {
|
|
|
2088
2171
|
output: '${DEFAULT_CONFIG.report.output}',
|
|
2089
2172
|
},
|
|
2090
2173
|
|
|
2091
|
-
//
|
|
2174
|
+
// Fix-suggestion rules ('off' disables a rule's suggestions)
|
|
2092
2175
|
rules: {
|
|
2093
|
-
// '
|
|
2094
|
-
// '
|
|
2095
|
-
// '
|
|
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',
|
|
2096
2182
|
},
|
|
2097
2183
|
};
|
|
2098
2184
|
`;
|
|
2099
2185
|
}
|
|
2100
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
|
+
}
|
|
2101
2200
|
return {
|
|
2102
|
-
thresholds
|
|
2103
|
-
report
|
|
2104
|
-
enabled: true,
|
|
2105
|
-
...config.report
|
|
2106
|
-
},
|
|
2201
|
+
thresholds,
|
|
2202
|
+
report,
|
|
2107
2203
|
rules: config.rules,
|
|
2108
2204
|
include: config.include,
|
|
2109
2205
|
exclude: config.exclude
|
|
@@ -2734,7 +2830,12 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2734
2830
|
* @returns Window key
|
|
2735
2831
|
*/
|
|
2736
2832
|
getWindowKey(timestamp) {
|
|
2737
|
-
|
|
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;
|
|
2738
2839
|
}
|
|
2739
2840
|
/**
|
|
2740
2841
|
* Check if a render was likely triggered by context
|
|
@@ -3417,7 +3518,31 @@ var FixSuggester = class extends EventEmitter {
|
|
|
3417
3518
|
}
|
|
3418
3519
|
};
|
|
3419
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
|
+
|
|
3420
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
|
+
}
|
|
3421
3546
|
var DEFAULT_CONFIG2 = {
|
|
3422
3547
|
trackUnnecessary: true,
|
|
3423
3548
|
fpsThreshold: 30,
|
|
@@ -3461,7 +3586,7 @@ var Scanner = class extends EventEmitter {
|
|
|
3461
3586
|
const thresholds = { ...DEFAULT_THRESHOLDS2, ...options.thresholds };
|
|
3462
3587
|
this.stats = new StatsCollector(thresholds);
|
|
3463
3588
|
this.chainAnalyzer = new ChainAnalyzer();
|
|
3464
|
-
this.fixSuggester = new FixSuggester();
|
|
3589
|
+
this.fixSuggester = new FixSuggester(options.rules ? { rules: toRuleLevels(options.rules) } : {});
|
|
3465
3590
|
this.setupEventForwarding();
|
|
3466
3591
|
}
|
|
3467
3592
|
/**
|
|
@@ -3527,19 +3652,55 @@ var Scanner = class extends EventEmitter {
|
|
|
3527
3652
|
*/
|
|
3528
3653
|
addRender(render, parent) {
|
|
3529
3654
|
if (!this.running) return;
|
|
3655
|
+
if (!this.isComponentIncluded(render.componentName)) return;
|
|
3530
3656
|
this.renderBatch.push(render);
|
|
3531
3657
|
this.stats.addRender(render);
|
|
3532
3658
|
this.chainAnalyzer.addRender(render, parent);
|
|
3533
3659
|
this.emit("render", render);
|
|
3534
|
-
this.frameCount++;
|
|
3535
3660
|
this.scheduleBatchProcessing();
|
|
3536
3661
|
}
|
|
3537
3662
|
/**
|
|
3538
|
-
*
|
|
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)
|
|
3539
3680
|
*/
|
|
3540
3681
|
recordFrame() {
|
|
3541
3682
|
this.frameCount++;
|
|
3542
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
|
+
}
|
|
3543
3704
|
/**
|
|
3544
3705
|
* Schedule batch processing
|
|
3545
3706
|
*/
|
|
@@ -3551,6 +3712,8 @@ var Scanner = class extends EventEmitter {
|
|
|
3551
3712
|
this.batchTimeout = setTimeout(() => {
|
|
3552
3713
|
this.flushBatch();
|
|
3553
3714
|
}, this.batchDelay);
|
|
3715
|
+
const timer = this.batchTimeout;
|
|
3716
|
+
timer.unref?.();
|
|
3554
3717
|
}
|
|
3555
3718
|
}
|
|
3556
3719
|
/**
|
|
@@ -3595,16 +3758,15 @@ var Scanner = class extends EventEmitter {
|
|
|
3595
3758
|
this.fpsInterval = setInterval(() => {
|
|
3596
3759
|
const now = Date.now();
|
|
3597
3760
|
const elapsed = now - this.lastFpsUpdate;
|
|
3598
|
-
|
|
3599
|
-
this.lastFps = Math.round(this.frameCount * 1e3 / elapsed);
|
|
3600
|
-
this.stats.addFpsSample(this.lastFps);
|
|
3601
|
-
if (this.lastFps < this.config.fpsThreshold) {
|
|
3602
|
-
this.emit("fps-drop", this.lastFps);
|
|
3603
|
-
}
|
|
3604
|
-
}
|
|
3761
|
+
const frames = this.frameCount;
|
|
3605
3762
|
this.frameCount = 0;
|
|
3606
3763
|
this.lastFpsUpdate = now;
|
|
3764
|
+
if (elapsed > 0 && frames > 0) {
|
|
3765
|
+
this.recordFps(frames * 1e3 / elapsed);
|
|
3766
|
+
}
|
|
3607
3767
|
}, 1e3);
|
|
3768
|
+
const interval = this.fpsInterval;
|
|
3769
|
+
interval.unref?.();
|
|
3608
3770
|
}
|
|
3609
3771
|
/**
|
|
3610
3772
|
* Stop FPS monitoring
|
|
@@ -4921,14 +5083,26 @@ var TUI = class extends EventEmitter {
|
|
|
4921
5083
|
this.keys.bind("end", () => this.componentList.moveToEnd());
|
|
4922
5084
|
this.keys.bind("enter", () => this.handleSelect());
|
|
4923
5085
|
this.keys.bind("escape", () => this.handleBack());
|
|
4924
|
-
this.keys.bind("q", () =>
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
this.keys.bind("
|
|
4928
|
-
|
|
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
|
+
});
|
|
4929
5101
|
this.keys.bind("f", () => this.showFixSuggestions());
|
|
4930
5102
|
this.keys.bind("c", () => this.showRenderChain());
|
|
4931
|
-
this.keys.bind("o", () =>
|
|
5103
|
+
this.keys.bind("o", () => {
|
|
5104
|
+
this.emit("toggleOverlay", void 0);
|
|
5105
|
+
});
|
|
4932
5106
|
}
|
|
4933
5107
|
/**
|
|
4934
5108
|
* Start the TUI
|
|
@@ -5223,6 +5397,7 @@ var OPCODE = {
|
|
|
5223
5397
|
PONG: 10
|
|
5224
5398
|
};
|
|
5225
5399
|
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
5400
|
+
var MAX_FRAME_PAYLOAD = 16 * 1024 * 1024;
|
|
5226
5401
|
var WebSocketClient = class extends EventEmitter {
|
|
5227
5402
|
/** Socket connection */
|
|
5228
5403
|
socket;
|
|
@@ -5259,7 +5434,7 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5259
5434
|
* Process received frames
|
|
5260
5435
|
*/
|
|
5261
5436
|
processFrames() {
|
|
5262
|
-
while (this.frameBuffer.length >= 2) {
|
|
5437
|
+
while (this.isOpen && this.frameBuffer.length >= 2) {
|
|
5263
5438
|
const frame = this.parseFrame();
|
|
5264
5439
|
if (!frame) break;
|
|
5265
5440
|
switch (frame.opcode) {
|
|
@@ -5299,8 +5474,18 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5299
5474
|
offset = 4;
|
|
5300
5475
|
} else if (payloadLength === 127) {
|
|
5301
5476
|
if (this.frameBuffer.length < 10) return null;
|
|
5477
|
+
const high = this.frameBuffer.readUInt32BE(2);
|
|
5302
5478
|
payloadLength = this.frameBuffer.readUInt32BE(6);
|
|
5303
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;
|
|
5304
5489
|
}
|
|
5305
5490
|
let maskingKey = null;
|
|
5306
5491
|
if (masked) {
|
|
@@ -5498,6 +5683,10 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5498
5683
|
this.server.once("error", reject);
|
|
5499
5684
|
this.server.listen(this.port, () => {
|
|
5500
5685
|
this.server.removeListener("error", reject);
|
|
5686
|
+
const address = this.server.address();
|
|
5687
|
+
if (address && typeof address === "object") {
|
|
5688
|
+
this.port = address.port;
|
|
5689
|
+
}
|
|
5501
5690
|
this.emit("listening", { port: this.port });
|
|
5502
5691
|
resolve3();
|
|
5503
5692
|
});
|
|
@@ -5517,6 +5706,14 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5517
5706
|
});
|
|
5518
5707
|
});
|
|
5519
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
|
+
}
|
|
5520
5717
|
/**
|
|
5521
5718
|
* Broadcast message to all clients
|
|
5522
5719
|
* @param message - Message to broadcast
|
|
@@ -5552,16 +5749,21 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5552
5749
|
};
|
|
5553
5750
|
function handleBrowserMessages(client, handler) {
|
|
5554
5751
|
client.on("message", (data) => {
|
|
5752
|
+
let message;
|
|
5555
5753
|
try {
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5754
|
+
message = JSON.parse(data);
|
|
5755
|
+
} catch {
|
|
5756
|
+
return;
|
|
5757
|
+
}
|
|
5758
|
+
if (message === null || typeof message !== "object" || typeof message.type !== "string") {
|
|
5759
|
+
return;
|
|
5559
5760
|
}
|
|
5761
|
+
handler(message);
|
|
5560
5762
|
});
|
|
5561
5763
|
}
|
|
5562
5764
|
|
|
5563
5765
|
// src/server/browser.ts
|
|
5564
|
-
var logger3 = new Logger({ prefix: "browser", level:
|
|
5766
|
+
var logger3 = new Logger({ prefix: "browser", level: 1 /* INFO */ });
|
|
5565
5767
|
var BrowserLauncher = class extends EventEmitter {
|
|
5566
5768
|
/** Puppeteer browser instance */
|
|
5567
5769
|
browser = null;
|
|
@@ -5786,9 +5988,235 @@ async function isPuppeteerAvailable() {
|
|
|
5786
5988
|
return false;
|
|
5787
5989
|
}
|
|
5788
5990
|
}
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
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
|
+
};
|
|
5792
6220
|
|
|
5793
6221
|
// src/webui/dashboard.ts
|
|
5794
6222
|
function generateDashboardHTML(wsPort, target) {
|
|
@@ -6835,7 +7263,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6835
7263
|
this.server = createServer((req, res) => {
|
|
6836
7264
|
this.handleHttpRequest(req, res);
|
|
6837
7265
|
});
|
|
6838
|
-
this.server.on("upgrade", (req, socket
|
|
7266
|
+
this.server.on("upgrade", (req, socket) => {
|
|
6839
7267
|
this.handleUpgrade(req, socket);
|
|
6840
7268
|
});
|
|
6841
7269
|
this.server.on("error", (error) => {
|
|
@@ -6924,7 +7352,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6924
7352
|
*/
|
|
6925
7353
|
handleClientData(client, socket, data) {
|
|
6926
7354
|
if (data.length < 2) return;
|
|
6927
|
-
const opcode = data[0] & 15;
|
|
7355
|
+
const opcode = (data[0] ?? 0) & 15;
|
|
6928
7356
|
if (opcode === OPCODE2.PING) {
|
|
6929
7357
|
const pong = Buffer.alloc(2);
|
|
6930
7358
|
pong[0] = 138;
|
|
@@ -7052,7 +7480,18 @@ var WebUIServer = class extends EventEmitter {
|
|
|
7052
7480
|
return `http://localhost:${this.port}`;
|
|
7053
7481
|
}
|
|
7054
7482
|
};
|
|
7055
|
-
|
|
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
|
+
}
|
|
7056
7495
|
async function installPuppeteer(wsServer) {
|
|
7057
7496
|
console.log("");
|
|
7058
7497
|
console.log(colors.cyan + "\u{1F4E6} Puppeteer is required for browser automation." + colors.reset);
|
|
@@ -7094,20 +7533,34 @@ async function installPuppeteer(wsServer) {
|
|
|
7094
7533
|
} catch (error) {
|
|
7095
7534
|
console.log("");
|
|
7096
7535
|
console.error("Puppeteer installation error:", error);
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
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>");
|
|
7100
7539
|
return false;
|
|
7101
7540
|
}
|
|
7102
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
|
+
}
|
|
7103
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);
|
|
7104
7556
|
return {
|
|
7105
7557
|
target: normalizeTarget(args.target ?? "localhost:3000"),
|
|
7106
7558
|
proxy: getBooleanFlag(args, "proxy"),
|
|
7107
7559
|
tui: getBooleanFlag(args, "tui"),
|
|
7108
7560
|
silent: getBooleanFlag(args, "silent"),
|
|
7109
|
-
report:
|
|
7110
|
-
format
|
|
7561
|
+
report: reportRequested,
|
|
7562
|
+
format,
|
|
7563
|
+
formats: toFormats(format),
|
|
7111
7564
|
output: getStringFlag(args, "output") ?? "./reactcheck-reports",
|
|
7112
7565
|
fix: getBooleanFlag(args, "fix"),
|
|
7113
7566
|
verbose: getBooleanFlag(args, "verbose"),
|
|
@@ -7116,64 +7569,35 @@ function parseScanOptions(args) {
|
|
|
7116
7569
|
thresholdWarning: getNumberFlag(args, "threshold-warning") ?? 20,
|
|
7117
7570
|
fpsThreshold: getNumberFlag(args, "fps-threshold") ?? 30,
|
|
7118
7571
|
headless: getBooleanFlag(args, "headless"),
|
|
7119
|
-
duration:
|
|
7572
|
+
duration: toSeconds(getStringFlag(args, "duration")),
|
|
7120
7573
|
watch: getBooleanFlag(args, "watch"),
|
|
7121
7574
|
configPath: getStringFlag(args, "config"),
|
|
7122
7575
|
webui: getBooleanFlag(args, "webui"),
|
|
7123
7576
|
webuiPort: getNumberFlag(args, "webui-port") ?? 3199
|
|
7124
7577
|
};
|
|
7125
7578
|
}
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
7140
|
-
window.__REACTCHECK_INJECTED__ = true;
|
|
7141
|
-
|
|
7142
|
-
// Install React DevTools hook
|
|
7143
|
-
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
7144
|
-
const hook = {
|
|
7145
|
-
renderers: new Map(),
|
|
7146
|
-
supportsFiber: true,
|
|
7147
|
-
inject: function(renderer) {
|
|
7148
|
-
const id = this.renderers.size + 1;
|
|
7149
|
-
this.renderers.set(id, renderer);
|
|
7150
|
-
return id;
|
|
7151
|
-
},
|
|
7152
|
-
onCommitFiberRoot: function(id, root) {
|
|
7153
|
-
// Will be overwritten by full script
|
|
7154
|
-
},
|
|
7155
|
-
onCommitFiberUnmount: function() {},
|
|
7156
|
-
};
|
|
7157
|
-
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
7158
|
-
console.log('[ReactCheck] DevTools hook installed (minimal)');
|
|
7159
|
-
}
|
|
7160
|
-
`;
|
|
7161
|
-
}
|
|
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
|
+
};
|
|
7162
7592
|
}
|
|
7163
7593
|
async function runScanCommand(args) {
|
|
7164
7594
|
const options = parseScanOptions(args);
|
|
7165
7595
|
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
7166
7596
|
if (fromFile) {
|
|
7167
|
-
|
|
7597
|
+
logger5.info(`Using config: ${configPath}`);
|
|
7168
7598
|
}
|
|
7169
7599
|
const configOptions = configToOptions(config);
|
|
7170
|
-
const mergedOptions =
|
|
7171
|
-
...options,
|
|
7172
|
-
thresholdCritical: options.thresholdCritical ?? configOptions.thresholds.critical,
|
|
7173
|
-
thresholdWarning: options.thresholdWarning ?? configOptions.thresholds.warning,
|
|
7174
|
-
fpsThreshold: options.fpsThreshold ?? configOptions.thresholds.fps,
|
|
7175
|
-
output: options.output ?? configOptions.report.output
|
|
7176
|
-
};
|
|
7600
|
+
const mergedOptions = mergeScanOptions(options, config, args.provided);
|
|
7177
7601
|
const session = {
|
|
7178
7602
|
id: generateId("scan"),
|
|
7179
7603
|
startTime: Date.now(),
|
|
@@ -7182,6 +7606,12 @@ async function runScanCommand(args) {
|
|
|
7182
7606
|
critical: mergedOptions.thresholdCritical,
|
|
7183
7607
|
warning: mergedOptions.thresholdWarning,
|
|
7184
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 } : {}
|
|
7185
7615
|
}
|
|
7186
7616
|
}),
|
|
7187
7617
|
tui: null,
|
|
@@ -7193,7 +7623,8 @@ async function runScanCommand(args) {
|
|
|
7193
7623
|
chains: [],
|
|
7194
7624
|
suggestions: [],
|
|
7195
7625
|
overlayEnabled: true,
|
|
7196
|
-
browserClients: /* @__PURE__ */ new Set()
|
|
7626
|
+
browserClients: /* @__PURE__ */ new Set(),
|
|
7627
|
+
proxy: null
|
|
7197
7628
|
};
|
|
7198
7629
|
setupScannerEvents(session);
|
|
7199
7630
|
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && !mergedOptions.webui && process.stdin.isTTY;
|
|
@@ -7207,78 +7638,98 @@ async function runScanCommand(args) {
|
|
|
7207
7638
|
}));
|
|
7208
7639
|
session.tui.start();
|
|
7209
7640
|
} else if (!mergedOptions.silent && !mergedOptions.proxy && !process.stdin.isTTY) {
|
|
7210
|
-
|
|
7641
|
+
logger5.warn("TTY not available, TUI disabled. Use --silent for non-interactive mode.");
|
|
7211
7642
|
}
|
|
7212
7643
|
if (mergedOptions.webui) {
|
|
7213
7644
|
session.webui = new WebUIServer(mergedOptions.webuiPort, mergedOptions.target);
|
|
7214
7645
|
setupWebUIEvents(session);
|
|
7215
7646
|
}
|
|
7216
7647
|
if (!useTUI) {
|
|
7217
|
-
|
|
7648
|
+
logger5.info(`Starting scan of ${mergedOptions.target}`);
|
|
7218
7649
|
}
|
|
7219
7650
|
if (useTUI) {
|
|
7220
|
-
|
|
7651
|
+
logger5.setLevel(4 /* SILENT */);
|
|
7221
7652
|
}
|
|
7222
7653
|
try {
|
|
7223
7654
|
session.wsServer = new WebSocketServer(mergedOptions.port);
|
|
7224
7655
|
await session.wsServer.start();
|
|
7225
|
-
|
|
7656
|
+
logger5.info(`WebSocket server listening on port ${mergedOptions.port}`);
|
|
7226
7657
|
session.wsServer.on("connection", (client) => {
|
|
7227
|
-
|
|
7658
|
+
logger5.info("Browser connected");
|
|
7228
7659
|
session.browserClients.add(client);
|
|
7229
7660
|
handleBrowserMessages(client, (message) => {
|
|
7230
7661
|
switch (message.type) {
|
|
7231
7662
|
case "render":
|
|
7232
7663
|
session.scanner.addRender(message.payload);
|
|
7233
7664
|
break;
|
|
7665
|
+
case "fps":
|
|
7666
|
+
session.scanner.recordFps(message.payload);
|
|
7667
|
+
break;
|
|
7234
7668
|
case "ready":
|
|
7235
|
-
|
|
7669
|
+
logger5.info(`React detected: ${message.payload.reactVersion}`);
|
|
7236
7670
|
client.send(JSON.stringify({ type: "start" }));
|
|
7237
7671
|
client.send(JSON.stringify({ type: "toggle-overlay", payload: { enabled: session.overlayEnabled } }));
|
|
7238
7672
|
break;
|
|
7239
7673
|
case "error":
|
|
7240
|
-
|
|
7674
|
+
logger5.error("Browser error:", message.payload.message);
|
|
7241
7675
|
break;
|
|
7242
7676
|
}
|
|
7243
7677
|
});
|
|
7244
7678
|
client.on("close", () => {
|
|
7245
|
-
|
|
7679
|
+
logger5.info("Browser disconnected");
|
|
7246
7680
|
session.browserClients.delete(client);
|
|
7247
7681
|
});
|
|
7248
7682
|
});
|
|
7249
7683
|
session.scanner.start();
|
|
7250
7684
|
if (session.webui) {
|
|
7251
|
-
|
|
7685
|
+
await session.webui.start();
|
|
7252
7686
|
session.webui.setScanning(true);
|
|
7253
7687
|
const webuiUrl = session.webui.getUrl();
|
|
7254
|
-
|
|
7688
|
+
logger5.info(`WebUI dashboard: ${webuiUrl}`);
|
|
7255
7689
|
openBrowser(webuiUrl);
|
|
7256
|
-
|
|
7690
|
+
logger5.info("WebUI dashboard opened, Puppeteer will open target URL next...");
|
|
7257
7691
|
}
|
|
7258
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}`;
|
|
7259
7704
|
console.log("");
|
|
7260
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);
|
|
7261
7706
|
console.log(colors.cyan + colors.bold + "\u2551 PROXY MODE ACTIVE \u2551" + colors.reset);
|
|
7262
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);
|
|
7263
7708
|
console.log("");
|
|
7264
|
-
console.log(`
|
|
7709
|
+
console.log(` Open ${colors.cyan}${proxiedPage}${colors.reset} (proxies ${mergedOptions.target}) in any browser.`);
|
|
7265
7710
|
console.log("");
|
|
7266
|
-
console.log(
|
|
7267
|
-
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:");
|
|
7268
7712
|
console.log("");
|
|
7269
|
-
console.log(`
|
|
7713
|
+
console.log(colors.yellow + ` <script src="${proxyUrl}/__reactcheck__/scanner.js"></script>` + colors.reset);
|
|
7270
7714
|
console.log("");
|
|
7271
7715
|
console.log(` Press ${colors.bold}Ctrl+C${colors.reset} to stop scanning`);
|
|
7272
7716
|
console.log("");
|
|
7273
7717
|
} else {
|
|
7274
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
|
+
}
|
|
7275
7726
|
if (!hasPuppeteer) {
|
|
7276
7727
|
const installed = await installPuppeteer(session.wsServer ?? void 0);
|
|
7277
7728
|
if (!installed) {
|
|
7278
7729
|
return 2;
|
|
7279
7730
|
}
|
|
7280
7731
|
}
|
|
7281
|
-
const injectionScript = await
|
|
7732
|
+
const injectionScript = await loadInjectionScript(mergedOptions.port);
|
|
7282
7733
|
session.browser = new BrowserLauncher({
|
|
7283
7734
|
url: mergedOptions.target,
|
|
7284
7735
|
headless: mergedOptions.headless,
|
|
@@ -7287,38 +7738,19 @@ async function runScanCommand(args) {
|
|
|
7287
7738
|
session.browser.setInjectionScript(injectionScript);
|
|
7288
7739
|
session.browser.on("console", ({ type, text }) => {
|
|
7289
7740
|
if (text.includes("[ReactCheck]") || text.includes("ReactCheck") || type === "error") {
|
|
7290
|
-
|
|
7741
|
+
logger5.info(`Browser [${type}]: ${text}`);
|
|
7291
7742
|
}
|
|
7292
7743
|
});
|
|
7293
7744
|
session.browser.on("error", (error) => {
|
|
7294
|
-
|
|
7745
|
+
logger5.error("Browser error:", error.message);
|
|
7295
7746
|
});
|
|
7296
|
-
|
|
7747
|
+
logger5.info("Launching Puppeteer browser for target URL...");
|
|
7297
7748
|
await session.browser.launch();
|
|
7298
|
-
|
|
7299
|
-
setTimeout(async () => {
|
|
7300
|
-
try {
|
|
7301
|
-
const page = session.browser?.getPage();
|
|
7302
|
-
if (page) {
|
|
7303
|
-
const overlayCheck = await page.evaluate(() => {
|
|
7304
|
-
const host = document.getElementById("reactcheck-overlay-host");
|
|
7305
|
-
const injected = window.__REACTCHECK_INJECTED__;
|
|
7306
|
-
const reactcheck = window.__REACTCHECK__;
|
|
7307
|
-
return {
|
|
7308
|
-
hostExists: !!host,
|
|
7309
|
-
injected: !!injected,
|
|
7310
|
-
reactcheckExists: !!reactcheck,
|
|
7311
|
-
url: window.location.href
|
|
7312
|
-
};
|
|
7313
|
-
});
|
|
7314
|
-
console.log("[ReactCheck DEBUG] Overlay check:", JSON.stringify(overlayCheck));
|
|
7315
|
-
}
|
|
7316
|
-
} catch (e) {
|
|
7317
|
-
}
|
|
7318
|
-
}, 3e3);
|
|
7749
|
+
logger5.info("Puppeteer browser launched successfully, now scanning target...");
|
|
7319
7750
|
}
|
|
7320
7751
|
if (mergedOptions.duration) {
|
|
7321
|
-
|
|
7752
|
+
const durationMs = mergedOptions.duration * 1e3;
|
|
7753
|
+
await new Promise((resolve3) => setTimeout(resolve3, durationMs));
|
|
7322
7754
|
session.active = false;
|
|
7323
7755
|
} else if (session.tui) {
|
|
7324
7756
|
await waitForQuit(session);
|
|
@@ -7341,17 +7773,17 @@ async function runScanCommand(args) {
|
|
|
7341
7773
|
await cleanupSession(session);
|
|
7342
7774
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7343
7775
|
if (errorMessage.includes("ERR_CONNECTION_REFUSED")) {
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
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");
|
|
7347
7779
|
} else if (errorMessage.includes("EADDRINUSE")) {
|
|
7348
|
-
|
|
7349
|
-
|
|
7780
|
+
logger5.error(`Port ${mergedOptions.port} is already in use`);
|
|
7781
|
+
logger5.info("Try using a different port with --port <number>");
|
|
7350
7782
|
} else if (errorMessage.includes("ERR_CERT")) {
|
|
7351
|
-
|
|
7352
|
-
|
|
7783
|
+
logger5.error("SSL certificate error");
|
|
7784
|
+
logger5.info("ReactCheck now supports self-signed certificates by default.");
|
|
7353
7785
|
} else {
|
|
7354
|
-
|
|
7786
|
+
logger5.error("Scan failed:", errorMessage);
|
|
7355
7787
|
}
|
|
7356
7788
|
return 2;
|
|
7357
7789
|
}
|
|
@@ -7367,6 +7799,10 @@ async function cleanupSession(session) {
|
|
|
7367
7799
|
if (session.browser) {
|
|
7368
7800
|
await session.browser.close();
|
|
7369
7801
|
}
|
|
7802
|
+
if (session.proxy) {
|
|
7803
|
+
await session.proxy.stop();
|
|
7804
|
+
session.proxy = null;
|
|
7805
|
+
}
|
|
7370
7806
|
if (session.wsServer) {
|
|
7371
7807
|
await session.wsServer.stop();
|
|
7372
7808
|
}
|
|
@@ -7402,12 +7838,12 @@ function setupScannerEvents(session) {
|
|
|
7402
7838
|
});
|
|
7403
7839
|
scanner.on("fps-drop", (fps) => {
|
|
7404
7840
|
if (session.options.verbose) {
|
|
7405
|
-
|
|
7841
|
+
logger5.warn(`FPS dropped to ${fps}`);
|
|
7406
7842
|
}
|
|
7407
7843
|
});
|
|
7408
7844
|
scanner.on("severityChange", ({ component, to }) => {
|
|
7409
7845
|
if (session.options.verbose && to === "critical") {
|
|
7410
|
-
|
|
7846
|
+
logger5.warn(`Component ${component} reached critical severity`);
|
|
7411
7847
|
}
|
|
7412
7848
|
});
|
|
7413
7849
|
}
|
|
@@ -7423,9 +7859,11 @@ function setupTUIEvents(session) {
|
|
|
7423
7859
|
tui.update({ paused: false });
|
|
7424
7860
|
}
|
|
7425
7861
|
});
|
|
7426
|
-
tui.on("generateReport",
|
|
7862
|
+
tui.on("generateReport", () => {
|
|
7427
7863
|
const report = generateReport(session);
|
|
7428
|
-
|
|
7864
|
+
saveReport(report, session.options).catch((error) => {
|
|
7865
|
+
logger5.error("Failed to save report:", error instanceof Error ? error.message : String(error));
|
|
7866
|
+
});
|
|
7429
7867
|
});
|
|
7430
7868
|
tui.on("selectComponent", (component) => {
|
|
7431
7869
|
const suggestions = scanner.analyzeComponent(component.name);
|
|
@@ -7481,7 +7919,7 @@ function generateReport(session) {
|
|
|
7481
7919
|
id: session.id
|
|
7482
7920
|
};
|
|
7483
7921
|
return {
|
|
7484
|
-
version:
|
|
7922
|
+
version: VERSION,
|
|
7485
7923
|
generated: formatDate(),
|
|
7486
7924
|
session: sessionInfo,
|
|
7487
7925
|
summary: exported.stats.summary,
|
|
@@ -7501,7 +7939,7 @@ async function saveReport(report, options) {
|
|
|
7501
7939
|
const { generateMarkdownReport: generateMarkdownReport2 } = await Promise.resolve().then(() => (init_markdown(), markdown_exports));
|
|
7502
7940
|
await ensureDir2(options.output);
|
|
7503
7941
|
const timestamp = Date.now();
|
|
7504
|
-
const formats = options.
|
|
7942
|
+
const formats = options.formats;
|
|
7505
7943
|
for (const format of formats) {
|
|
7506
7944
|
let content;
|
|
7507
7945
|
let extension;
|
|
@@ -7524,7 +7962,7 @@ async function saveReport(report, options) {
|
|
|
7524
7962
|
const filename = `reactcheck-report-${timestamp}.${extension}`;
|
|
7525
7963
|
const filepath = joinPath2(options.output, filename);
|
|
7526
7964
|
await writeTextFile2(filepath, content);
|
|
7527
|
-
|
|
7965
|
+
logger5.info(`Report saved: ${filepath}`);
|
|
7528
7966
|
}
|
|
7529
7967
|
}
|
|
7530
7968
|
function printSummary(session) {
|
|
@@ -7614,39 +8052,39 @@ function openBrowser(url) {
|
|
|
7614
8052
|
}
|
|
7615
8053
|
exec(command, (error) => {
|
|
7616
8054
|
if (error) {
|
|
7617
|
-
|
|
8055
|
+
logger5.debug(`Failed to open browser: ${error.message}`);
|
|
7618
8056
|
}
|
|
7619
8057
|
});
|
|
7620
8058
|
}
|
|
7621
8059
|
|
|
7622
8060
|
// src/cli/commands/init.ts
|
|
7623
8061
|
init_fs();
|
|
7624
|
-
var
|
|
8062
|
+
var logger6 = new Logger({ prefix: "init", level: 1 /* INFO */ });
|
|
7625
8063
|
var DEFAULT_CONFIG_NAME = "reactcheck.config.js";
|
|
7626
8064
|
async function runInitCommand(args) {
|
|
7627
8065
|
const configPath = args.positional[0] ?? DEFAULT_CONFIG_NAME;
|
|
7628
8066
|
if (await exists(configPath)) {
|
|
7629
|
-
|
|
8067
|
+
logger6.warn(`Config file already exists: ${configPath}`);
|
|
7630
8068
|
try {
|
|
7631
8069
|
const content2 = await readTextFile(configPath);
|
|
7632
8070
|
if (configPath.endsWith(".json")) {
|
|
7633
8071
|
const config = JSON.parse(content2);
|
|
7634
8072
|
const errors = validateConfig(config);
|
|
7635
8073
|
if (errors.length > 0) {
|
|
7636
|
-
|
|
8074
|
+
logger6.warn("Existing config has validation errors:");
|
|
7637
8075
|
for (const error of errors) {
|
|
7638
|
-
|
|
8076
|
+
logger6.warn(` - ${error}`);
|
|
7639
8077
|
}
|
|
7640
8078
|
} else {
|
|
7641
|
-
|
|
8079
|
+
logger6.info("Existing config is valid.");
|
|
7642
8080
|
}
|
|
7643
8081
|
}
|
|
7644
8082
|
} catch (error) {
|
|
7645
|
-
|
|
8083
|
+
logger6.warn("Could not validate existing config:", error);
|
|
7646
8084
|
}
|
|
7647
8085
|
console.log("");
|
|
7648
8086
|
console.log(colors.yellow + "? Overwrite existing config? (y/N) " + colors.reset);
|
|
7649
|
-
|
|
8087
|
+
logger6.info("To overwrite, delete the existing file and run init again.");
|
|
7650
8088
|
return 0;
|
|
7651
8089
|
}
|
|
7652
8090
|
const format = configPath.endsWith(".json") ? "json" : "js";
|
|
@@ -7672,10 +8110,331 @@ async function runInitCommand(args) {
|
|
|
7672
8110
|
console.log("");
|
|
7673
8111
|
return 0;
|
|
7674
8112
|
} catch (error) {
|
|
7675
|
-
|
|
8113
|
+
logger6.error(`Failed to create config file:`, error);
|
|
7676
8114
|
return 1;
|
|
7677
8115
|
}
|
|
7678
8116
|
}
|
|
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
|
+
}
|
|
7679
8438
|
var InteractiveWizard = class {
|
|
7680
8439
|
rl;
|
|
7681
8440
|
constructor() {
|
|
@@ -8053,8 +8812,7 @@ async function runInteractiveWizard() {
|
|
|
8053
8812
|
}
|
|
8054
8813
|
|
|
8055
8814
|
// src/cli/index.ts
|
|
8056
|
-
var
|
|
8057
|
-
var VERSION = "1.1.6";
|
|
8815
|
+
var logger9 = new Logger({ prefix: "ReactCheck", level: 1 /* INFO */ });
|
|
8058
8816
|
function printVersion() {
|
|
8059
8817
|
console.log(`@oxog/react-check v${VERSION}`);
|
|
8060
8818
|
}
|
|
@@ -8119,7 +8877,8 @@ var CLI = class {
|
|
|
8119
8877
|
target: config.url,
|
|
8120
8878
|
flags,
|
|
8121
8879
|
positional: [],
|
|
8122
|
-
raw: []
|
|
8880
|
+
raw: [],
|
|
8881
|
+
provided: new Set(flags.keys())
|
|
8123
8882
|
};
|
|
8124
8883
|
}
|
|
8125
8884
|
/**
|
|
@@ -8140,8 +8899,19 @@ var CLI = class {
|
|
|
8140
8899
|
case "init":
|
|
8141
8900
|
printBanner();
|
|
8142
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
|
+
}
|
|
8143
8913
|
case "scan":
|
|
8144
|
-
default:
|
|
8914
|
+
default: {
|
|
8145
8915
|
if (!args.target && args.raw.length === 0 && process.stdin.isTTY) {
|
|
8146
8916
|
printBanner();
|
|
8147
8917
|
const wizardConfig = await runInteractiveWizard();
|
|
@@ -8154,16 +8924,17 @@ var CLI = class {
|
|
|
8154
8924
|
const errors = validateArgs(args);
|
|
8155
8925
|
if (errors.length > 0) {
|
|
8156
8926
|
for (const error of errors) {
|
|
8157
|
-
|
|
8927
|
+
logger9.error(error);
|
|
8158
8928
|
}
|
|
8159
8929
|
console.log("");
|
|
8160
8930
|
console.log("Run " + colors.cyan + "react-check --help" + colors.reset + " for usage information.");
|
|
8161
8931
|
return 2;
|
|
8162
8932
|
}
|
|
8163
8933
|
return await runScanCommand(args);
|
|
8934
|
+
}
|
|
8164
8935
|
}
|
|
8165
8936
|
} catch (error) {
|
|
8166
|
-
|
|
8937
|
+
logger9.error("Unexpected error:", error);
|
|
8167
8938
|
return 1;
|
|
8168
8939
|
}
|
|
8169
8940
|
}
|