@oxog/react-check 1.2.0 → 1.3.1
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 +129 -0
- package/README.md +177 -62
- 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-35I3PLS3.js +751 -0
- package/dist/chunk-35I3PLS3.js.map +1 -0
- package/dist/chunk-7R4KKJTW.cjs +255 -0
- package/dist/chunk-7R4KKJTW.cjs.map +1 -0
- package/dist/chunk-DSXOHC6R.cjs +755 -0
- package/dist/chunk-DSXOHC6R.cjs.map +1 -0
- package/dist/chunk-DWM55ACO.cjs +294 -0
- package/dist/chunk-DWM55ACO.cjs.map +1 -0
- package/dist/chunk-GS7T56RP.cjs +9 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -0
- package/dist/chunk-LFY7MUHJ.cjs +483 -0
- package/dist/chunk-LFY7MUHJ.cjs.map +1 -0
- package/dist/chunk-NLWGB4IE.cjs +380 -0
- package/dist/chunk-NLWGB4IE.cjs.map +1 -0
- package/dist/chunk-PIXJPQO7.js +481 -0
- package/dist/chunk-PIXJPQO7.js.map +1 -0
- package/dist/chunk-REEPUD73.js +362 -0
- package/dist/chunk-REEPUD73.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 +1195 -297
- 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 +8 -2
- package/dist/fix.d.ts +8 -2
- package/dist/fix.js +2 -719
- package/dist/fix.js.map +1 -1
- package/dist/index.cjs +1400 -3075
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +237 -57
- package/dist/index.d.ts +237 -57
- package/dist/index.js +1222 -2970
- package/dist/index.js.map +1 -1
- package/dist/{scanner-Cc2187fH.d.ts → scanner-BJFA0354.d.ts} +33 -4
- package/dist/{scanner-S7BtVIpW.d.cts → scanner-DZL2rIFv.d.cts} +33 -4
- 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-BMDemwIs.d.cts} +35 -10
- package/dist/{types-DuZyBVVV.d.ts → types-BMDemwIs.d.ts} +35 -10
- package/package.json +16 -9
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { constants } from 'fs';
|
|
4
|
-
import {
|
|
5
|
-
import { createServer } from 'http';
|
|
2
|
+
import { readFile, stat, access, writeFile, mkdir, rm, readdir } from 'fs/promises';
|
|
3
|
+
import { mkdirSync, existsSync, writeFileSync, constants } from 'fs';
|
|
4
|
+
import { join, resolve, extname, basename, dirname } from 'path';
|
|
5
|
+
import { createServer, request as request$1 } from 'http';
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { createRequire } from 'module';
|
|
8
|
+
import { homedir } from 'os';
|
|
9
|
+
import { URL as URL$1, fileURLToPath } from 'url';
|
|
10
|
+
import { request } from 'https';
|
|
11
|
+
import { execSync, exec } from 'child_process';
|
|
9
12
|
import * as readline from 'readline';
|
|
10
13
|
|
|
11
14
|
var __defProp = Object.defineProperty;
|
|
@@ -132,23 +135,17 @@ function getDirName(path) {
|
|
|
132
135
|
}
|
|
133
136
|
async function findUp(filename, startDir = process.cwd()) {
|
|
134
137
|
let currentDir = resolve(startDir);
|
|
135
|
-
|
|
136
|
-
while (currentDir !== root) {
|
|
138
|
+
for (; ; ) {
|
|
137
139
|
const filePath = join(currentDir, filename);
|
|
138
140
|
if (await exists(filePath)) {
|
|
139
141
|
return filePath;
|
|
140
142
|
}
|
|
141
143
|
const parentDir = dirname(currentDir);
|
|
142
144
|
if (parentDir === currentDir) {
|
|
143
|
-
|
|
145
|
+
return null;
|
|
144
146
|
}
|
|
145
147
|
currentDir = parentDir;
|
|
146
148
|
}
|
|
147
|
-
const rootFilePath = join(currentDir, filename);
|
|
148
|
-
if (await exists(rootFilePath)) {
|
|
149
|
-
return rootFilePath;
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
149
|
}
|
|
153
150
|
async function copyFile(src, dest) {
|
|
154
151
|
const content = await readFile(src);
|
|
@@ -1129,8 +1126,9 @@ var FLAG_DEFINITIONS = {
|
|
|
1129
1126
|
},
|
|
1130
1127
|
tui: {
|
|
1131
1128
|
short: "t",
|
|
1132
|
-
description: "
|
|
1133
|
-
default: false
|
|
1129
|
+
description: "Not supported",
|
|
1130
|
+
default: false,
|
|
1131
|
+
unsupported: "Option --tui (-t) is not supported. The terminal UI starts automatically when the scan runs in an interactive terminal; to scan without launching Chrome use --proxy and open the proxied URL in your own browser."
|
|
1134
1132
|
},
|
|
1135
1133
|
silent: {
|
|
1136
1134
|
short: "s",
|
|
@@ -1200,8 +1198,9 @@ var FLAG_DEFINITIONS = {
|
|
|
1200
1198
|
},
|
|
1201
1199
|
watch: {
|
|
1202
1200
|
short: "w",
|
|
1203
|
-
description: "
|
|
1204
|
-
default: false
|
|
1201
|
+
description: "Not supported",
|
|
1202
|
+
default: false,
|
|
1203
|
+
unsupported: "Option --watch (-w) is not supported. Without --duration a scan already keeps running until you quit (q or Ctrl+C)."
|
|
1205
1204
|
},
|
|
1206
1205
|
webui: {
|
|
1207
1206
|
short: "W",
|
|
@@ -1212,8 +1211,18 @@ var FLAG_DEFINITIONS = {
|
|
|
1212
1211
|
description: "WebUI dashboard port",
|
|
1213
1212
|
takesValue: true,
|
|
1214
1213
|
default: "3199"
|
|
1214
|
+
},
|
|
1215
|
+
json: {
|
|
1216
|
+
description: "Print machine-readable JSON (detect command)",
|
|
1217
|
+
default: false
|
|
1215
1218
|
}
|
|
1216
1219
|
};
|
|
1220
|
+
var REPORT_FORMATS = ["html", "json", "md", "all"];
|
|
1221
|
+
function parseFormatList(value) {
|
|
1222
|
+
const parts = value.split(",").map((p) => p.trim().toLowerCase()).filter((p) => p.length > 0);
|
|
1223
|
+
if (parts.includes("all")) return ["html", "json", "md"];
|
|
1224
|
+
return [...new Set(parts)];
|
|
1225
|
+
}
|
|
1217
1226
|
function buildShortFlagMap() {
|
|
1218
1227
|
const map = /* @__PURE__ */ new Map();
|
|
1219
1228
|
for (const [long, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
@@ -1225,11 +1234,23 @@ function buildShortFlagMap() {
|
|
|
1225
1234
|
}
|
|
1226
1235
|
var SHORT_FLAGS = buildShortFlagMap();
|
|
1227
1236
|
function parseArgs(argv) {
|
|
1237
|
+
const provided = /* @__PURE__ */ new Set();
|
|
1238
|
+
const unknown = [];
|
|
1228
1239
|
const result = {
|
|
1229
1240
|
command: "scan",
|
|
1230
1241
|
flags: /* @__PURE__ */ new Map(),
|
|
1231
1242
|
positional: [],
|
|
1232
|
-
raw: argv
|
|
1243
|
+
raw: argv,
|
|
1244
|
+
provided,
|
|
1245
|
+
unknown
|
|
1246
|
+
};
|
|
1247
|
+
const setFlag = (name, value, original) => {
|
|
1248
|
+
if (!(name in FLAG_DEFINITIONS)) {
|
|
1249
|
+
unknown.push(original);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
result.flags.set(name, value);
|
|
1253
|
+
provided.add(name);
|
|
1233
1254
|
};
|
|
1234
1255
|
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1235
1256
|
if (def.default !== void 0) {
|
|
@@ -1249,8 +1270,8 @@ function parseArgs(argv) {
|
|
|
1249
1270
|
i++;
|
|
1250
1271
|
continue;
|
|
1251
1272
|
}
|
|
1252
|
-
if (arg === "init") {
|
|
1253
|
-
result.command =
|
|
1273
|
+
if (arg === "init" || arg === "detect" || arg === "report") {
|
|
1274
|
+
result.command = arg;
|
|
1254
1275
|
i++;
|
|
1255
1276
|
continue;
|
|
1256
1277
|
}
|
|
@@ -1269,7 +1290,7 @@ function parseArgs(argv) {
|
|
|
1269
1290
|
const eqIndex = arg.indexOf("=");
|
|
1270
1291
|
const flagName = arg.slice(2, eqIndex);
|
|
1271
1292
|
const value = arg.slice(eqIndex + 1);
|
|
1272
|
-
|
|
1293
|
+
setFlag(flagName, value, arg);
|
|
1273
1294
|
i++;
|
|
1274
1295
|
continue;
|
|
1275
1296
|
}
|
|
@@ -1279,12 +1300,12 @@ function parseArgs(argv) {
|
|
|
1279
1300
|
if (def?.takesValue) {
|
|
1280
1301
|
const nextArg = argv[i + 1];
|
|
1281
1302
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1282
|
-
|
|
1303
|
+
setFlag(flagName, nextArg, arg);
|
|
1283
1304
|
i += 2;
|
|
1284
1305
|
continue;
|
|
1285
1306
|
}
|
|
1286
1307
|
}
|
|
1287
|
-
|
|
1308
|
+
setFlag(flagName, true, arg);
|
|
1288
1309
|
i++;
|
|
1289
1310
|
continue;
|
|
1290
1311
|
}
|
|
@@ -1294,7 +1315,7 @@ function parseArgs(argv) {
|
|
|
1294
1315
|
if (longFlag) {
|
|
1295
1316
|
const def = FLAG_DEFINITIONS[longFlag];
|
|
1296
1317
|
if (arg.length > 2 && def?.takesValue) {
|
|
1297
|
-
|
|
1318
|
+
setFlag(longFlag, arg.slice(2), arg);
|
|
1298
1319
|
i++;
|
|
1299
1320
|
continue;
|
|
1300
1321
|
}
|
|
@@ -1304,7 +1325,9 @@ function parseArgs(argv) {
|
|
|
1304
1325
|
if (sf) {
|
|
1305
1326
|
const lf = SHORT_FLAGS.get(sf);
|
|
1306
1327
|
if (lf) {
|
|
1307
|
-
|
|
1328
|
+
setFlag(lf, true, `-${sf}`);
|
|
1329
|
+
} else {
|
|
1330
|
+
unknown.push(`-${sf}`);
|
|
1308
1331
|
}
|
|
1309
1332
|
}
|
|
1310
1333
|
}
|
|
@@ -1314,12 +1337,12 @@ function parseArgs(argv) {
|
|
|
1314
1337
|
if (def?.takesValue) {
|
|
1315
1338
|
const nextArg = argv[i + 1];
|
|
1316
1339
|
if (nextArg && !nextArg.startsWith("-")) {
|
|
1317
|
-
|
|
1340
|
+
setFlag(longFlag, nextArg, arg);
|
|
1318
1341
|
i += 2;
|
|
1319
1342
|
continue;
|
|
1320
1343
|
}
|
|
1321
1344
|
}
|
|
1322
|
-
|
|
1345
|
+
setFlag(longFlag, true, arg);
|
|
1323
1346
|
i++;
|
|
1324
1347
|
continue;
|
|
1325
1348
|
}
|
|
@@ -1329,7 +1352,9 @@ function parseArgs(argv) {
|
|
|
1329
1352
|
if (sf) {
|
|
1330
1353
|
const lf = SHORT_FLAGS.get(sf);
|
|
1331
1354
|
if (lf) {
|
|
1332
|
-
|
|
1355
|
+
setFlag(lf, true, `-${sf}`);
|
|
1356
|
+
} else {
|
|
1357
|
+
unknown.push(`-${sf}`);
|
|
1333
1358
|
}
|
|
1334
1359
|
}
|
|
1335
1360
|
}
|
|
@@ -1346,6 +1371,7 @@ function parseArgs(argv) {
|
|
|
1346
1371
|
i++;
|
|
1347
1372
|
continue;
|
|
1348
1373
|
}
|
|
1374
|
+
unknown.push(arg);
|
|
1349
1375
|
i++;
|
|
1350
1376
|
}
|
|
1351
1377
|
if (result.flags.get("help") === true) {
|
|
@@ -1377,32 +1403,83 @@ function getNumberFlag(args, name) {
|
|
|
1377
1403
|
}
|
|
1378
1404
|
function validateArgs(args) {
|
|
1379
1405
|
const errors = [];
|
|
1406
|
+
for (const flag of args.unknown ?? []) {
|
|
1407
|
+
errors.push(`Unknown option: ${flag}`);
|
|
1408
|
+
}
|
|
1409
|
+
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1410
|
+
if (def.unsupported !== void 0 && (args.provided?.has(name) ?? args.flags.get(name) === true)) {
|
|
1411
|
+
errors.push(def.unsupported);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
for (const [name, def] of Object.entries(FLAG_DEFINITIONS)) {
|
|
1415
|
+
if (def.takesValue && args.flags.get(name) === true) {
|
|
1416
|
+
errors.push(`Option --${name} requires a value`);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1380
1419
|
if (args.command === "scan" && !args.target) {
|
|
1381
1420
|
errors.push("Target URL is required for scan command");
|
|
1382
1421
|
}
|
|
1383
|
-
|
|
1422
|
+
let targetIsCommandTypo = false;
|
|
1423
|
+
if (args.command === "scan" && args.target !== void 0 && looksLikeCommandWord(args.target)) {
|
|
1424
|
+
targetIsCommandTypo = true;
|
|
1425
|
+
errors.push(
|
|
1426
|
+
`Unknown command: ${args.target} (commands: scan, detect, report, init, help, version). To scan a host named "${args.target}", write http://${args.target}`
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
if (args.command === "scan" && !targetIsCommandTypo && args.positional.length > 0) {
|
|
1430
|
+
errors.push(`Unexpected argument: ${args.positional.join(" ")} (scan takes a single URL)`);
|
|
1431
|
+
}
|
|
1432
|
+
if (args.command === "report" && args.positional.length === 0) {
|
|
1433
|
+
errors.push("Input JSON report path is required for report command");
|
|
1434
|
+
}
|
|
1435
|
+
if (args.target && !targetIsCommandTypo) {
|
|
1384
1436
|
try {
|
|
1385
|
-
const url = args.target
|
|
1386
|
-
|
|
1437
|
+
const url = new URL(normalizeTarget(args.target));
|
|
1438
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1439
|
+
errors.push(`Invalid URL: ${args.target} (only http and https are supported)`);
|
|
1440
|
+
}
|
|
1387
1441
|
} catch {
|
|
1388
1442
|
errors.push(`Invalid URL: ${args.target}`);
|
|
1389
1443
|
}
|
|
1390
1444
|
}
|
|
1391
1445
|
const format = getStringFlag(args, "format");
|
|
1392
|
-
if (format
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1446
|
+
if (format !== void 0) {
|
|
1447
|
+
const formats = parseFormatList(format);
|
|
1448
|
+
const invalid = formats.filter((f) => !REPORT_FORMATS.includes(f));
|
|
1449
|
+
if (formats.length === 0 || invalid.length > 0) {
|
|
1450
|
+
errors.push(`Invalid format: ${format}. Must be one or more of: html, json, md, all (comma-separated)`);
|
|
1451
|
+
}
|
|
1398
1452
|
}
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1453
|
+
const integerFlag = (name, min, max) => {
|
|
1454
|
+
const raw = getStringFlag(args, name);
|
|
1455
|
+
if (raw === void 0) return void 0;
|
|
1456
|
+
const value = Number(raw);
|
|
1457
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
1458
|
+
errors.push(`Invalid value for --${name}: ${raw}. Must be an integer between ${min} and ${max}`);
|
|
1459
|
+
return void 0;
|
|
1460
|
+
}
|
|
1461
|
+
return value;
|
|
1462
|
+
};
|
|
1463
|
+
integerFlag("port", 1, 65535);
|
|
1464
|
+
integerFlag("webui-port", 1, 65535);
|
|
1465
|
+
integerFlag("fps-threshold", 1, 240);
|
|
1466
|
+
const critical = integerFlag("threshold-critical", 1, Number.MAX_SAFE_INTEGER);
|
|
1467
|
+
const warning = integerFlag("threshold-warning", 1, Number.MAX_SAFE_INTEGER);
|
|
1401
1468
|
if (critical !== void 0 && warning !== void 0 && critical <= warning) {
|
|
1402
1469
|
errors.push("Critical threshold must be greater than warning threshold");
|
|
1403
1470
|
}
|
|
1471
|
+
const duration = getStringFlag(args, "duration");
|
|
1472
|
+
if (duration !== void 0) {
|
|
1473
|
+
const value = Number(duration);
|
|
1474
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
1475
|
+
errors.push(`Invalid value for --duration: ${duration}. Must be a positive number of seconds`);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1404
1478
|
return errors;
|
|
1405
1479
|
}
|
|
1480
|
+
function looksLikeCommandWord(target) {
|
|
1481
|
+
return /^[a-z][a-z0-9_-]*$/i.test(target) && target.toLowerCase() !== "localhost";
|
|
1482
|
+
}
|
|
1406
1483
|
function getHelpText() {
|
|
1407
1484
|
const lines = [
|
|
1408
1485
|
"",
|
|
@@ -1410,6 +1487,9 @@ function getHelpText() {
|
|
|
1410
1487
|
"",
|
|
1411
1488
|
"Usage:",
|
|
1412
1489
|
" react-check <url> [options] Scan a React application",
|
|
1490
|
+
" react-check scan <url> Same as above",
|
|
1491
|
+
" react-check detect [path] Detect the React framework of a project",
|
|
1492
|
+
" react-check report <file.json> Re-generate reports from a JSON report",
|
|
1413
1493
|
" react-check init Create default config file",
|
|
1414
1494
|
" react-check help Show this help message",
|
|
1415
1495
|
" react-check version Show version number",
|
|
@@ -1417,8 +1497,8 @@ function getHelpText() {
|
|
|
1417
1497
|
"Options:"
|
|
1418
1498
|
];
|
|
1419
1499
|
const groups = {
|
|
1420
|
-
"General": ["help", "version", "verbose", "config"],
|
|
1421
|
-
"Mode": ["proxy", "
|
|
1500
|
+
"General": ["help", "version", "verbose", "config", "json"],
|
|
1501
|
+
"Mode": ["proxy", "silent", "headless", "webui", "webui-port"],
|
|
1422
1502
|
"Report": ["report", "format", "output", "fix"],
|
|
1423
1503
|
"Thresholds": ["threshold-critical", "threshold-warning", "fps-threshold"],
|
|
1424
1504
|
"Network": ["port", "duration"]
|
|
@@ -1452,9 +1532,16 @@ function getHelpText() {
|
|
|
1452
1532
|
lines.push(" react-check localhost:3000");
|
|
1453
1533
|
lines.push(" react-check https://myapp.dev --report --format=html");
|
|
1454
1534
|
lines.push(" react-check localhost:3000 --proxy --fix --verbose");
|
|
1455
|
-
lines.push(" react-check localhost:3000 --silent --
|
|
1535
|
+
lines.push(" react-check localhost:3000 --silent --headless --duration 30 --format json --output ./ci-reports");
|
|
1536
|
+
lines.push(" react-check detect ./my-app");
|
|
1537
|
+
lines.push(" react-check report ./ci-reports/reactcheck-report-123.json --format html,md");
|
|
1538
|
+
lines.push("");
|
|
1539
|
+
lines.push("Exit codes:");
|
|
1540
|
+
lines.push(" 0 scan finished without critical issues");
|
|
1541
|
+
lines.push(" 1 scan finished and found critical issues");
|
|
1542
|
+
lines.push(" 2 invalid usage or the scan could not run");
|
|
1456
1543
|
lines.push("");
|
|
1457
|
-
lines.push("Documentation: https://
|
|
1544
|
+
lines.push("Documentation: https://reactcheck.oxog.dev");
|
|
1458
1545
|
lines.push("");
|
|
1459
1546
|
return lines.join("\n");
|
|
1460
1547
|
}
|
|
@@ -1817,7 +1904,7 @@ var Logger = class _Logger {
|
|
|
1817
1904
|
for (const col of cols) {
|
|
1818
1905
|
widths[col] = col.length;
|
|
1819
1906
|
for (const row of data) {
|
|
1820
|
-
const value =
|
|
1907
|
+
const value = formatCell(row[col]);
|
|
1821
1908
|
widths[col] = Math.max(widths[col] ?? 0, value.length);
|
|
1822
1909
|
}
|
|
1823
1910
|
}
|
|
@@ -1826,7 +1913,7 @@ var Logger = class _Logger {
|
|
|
1826
1913
|
this.output.log(colors.bold + header + colors.reset);
|
|
1827
1914
|
this.output.log(separator);
|
|
1828
1915
|
for (const row of data) {
|
|
1829
|
-
const line = cols.map((col) =>
|
|
1916
|
+
const line = cols.map((col) => formatCell(row[col]).padEnd(widths[col] ?? 0)).join(" \u2502 ");
|
|
1830
1917
|
this.output.log(line);
|
|
1831
1918
|
}
|
|
1832
1919
|
}
|
|
@@ -1877,6 +1964,27 @@ var Logger = class _Logger {
|
|
|
1877
1964
|
}
|
|
1878
1965
|
};
|
|
1879
1966
|
new Logger({ prefix: "ReactCheck" });
|
|
1967
|
+
function formatCell(value) {
|
|
1968
|
+
if (value === null || value === void 0) return "";
|
|
1969
|
+
if (typeof value === "object") {
|
|
1970
|
+
try {
|
|
1971
|
+
return JSON.stringify(value);
|
|
1972
|
+
} catch {
|
|
1973
|
+
return Object.prototype.toString.call(value);
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
switch (typeof value) {
|
|
1977
|
+
case "string":
|
|
1978
|
+
return value;
|
|
1979
|
+
case "number":
|
|
1980
|
+
case "boolean":
|
|
1981
|
+
case "bigint":
|
|
1982
|
+
case "symbol":
|
|
1983
|
+
return value.toString();
|
|
1984
|
+
default:
|
|
1985
|
+
return "[function]";
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1880
1988
|
|
|
1881
1989
|
// src/cli/config.ts
|
|
1882
1990
|
var logger2 = new Logger({ prefix: "config", level: 2 /* WARN */ });
|
|
@@ -2019,12 +2127,9 @@ function validateConfig(config) {
|
|
|
2019
2127
|
if (config.rules) {
|
|
2020
2128
|
const validLevels = ["off", "warn", "error"];
|
|
2021
2129
|
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}`);
|
|
2130
|
+
const value = Array.isArray(level) ? level[0] : level;
|
|
2131
|
+
if (typeof value !== "string" || !validLevels.includes(value)) {
|
|
2132
|
+
errors.push(`Invalid rule level for ${rule}: ${String(value)}`);
|
|
2028
2133
|
}
|
|
2029
2134
|
}
|
|
2030
2135
|
}
|
|
@@ -2088,22 +2193,35 @@ export default {
|
|
|
2088
2193
|
output: '${DEFAULT_CONFIG.report.output}',
|
|
2089
2194
|
},
|
|
2090
2195
|
|
|
2091
|
-
//
|
|
2196
|
+
// Fix-suggestion rules ('off' disables a rule's suggestions)
|
|
2092
2197
|
rules: {
|
|
2093
|
-
// '
|
|
2094
|
-
// '
|
|
2095
|
-
// '
|
|
2198
|
+
// 'unnecessary-rerenders-memo': 'warn',
|
|
2199
|
+
// 'function-prop-stability': 'warn',
|
|
2200
|
+
// 'expensive-computation-memo': 'warn',
|
|
2201
|
+
// 'context-over-subscription': 'warn',
|
|
2202
|
+
// 'state-too-high': 'off',
|
|
2203
|
+
// 'extract-heavy-child': 'off',
|
|
2096
2204
|
},
|
|
2097
2205
|
};
|
|
2098
2206
|
`;
|
|
2099
2207
|
}
|
|
2100
2208
|
function configToOptions(config) {
|
|
2209
|
+
const thresholds = {
|
|
2210
|
+
critical: config.thresholds.critical ?? DEFAULT_CONFIG.thresholds.critical ?? 50,
|
|
2211
|
+
warning: config.thresholds.warning ?? DEFAULT_CONFIG.thresholds.warning ?? 20,
|
|
2212
|
+
fps: config.thresholds.fps ?? DEFAULT_CONFIG.thresholds.fps ?? 30
|
|
2213
|
+
};
|
|
2214
|
+
const report = {
|
|
2215
|
+
enabled: true,
|
|
2216
|
+
formats: config.report.formats ?? DEFAULT_CONFIG.report.formats ?? ["html", "json"],
|
|
2217
|
+
output: config.report.output ?? DEFAULT_CONFIG.report.output ?? "./reactcheck-reports"
|
|
2218
|
+
};
|
|
2219
|
+
if (config.report.includeSourceCode !== void 0) {
|
|
2220
|
+
report.includeSourceCode = config.report.includeSourceCode;
|
|
2221
|
+
}
|
|
2101
2222
|
return {
|
|
2102
|
-
thresholds
|
|
2103
|
-
report
|
|
2104
|
-
enabled: true,
|
|
2105
|
-
...config.report
|
|
2106
|
-
},
|
|
2223
|
+
thresholds,
|
|
2224
|
+
report,
|
|
2107
2225
|
rules: config.rules,
|
|
2108
2226
|
include: config.include,
|
|
2109
2227
|
exclude: config.exclude
|
|
@@ -2734,7 +2852,12 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2734
2852
|
* @returns Window key
|
|
2735
2853
|
*/
|
|
2736
2854
|
getWindowKey(timestamp) {
|
|
2737
|
-
|
|
2855
|
+
for (const [key, window2] of this.windows) {
|
|
2856
|
+
if (timestamp >= window2.startTime && timestamp < window2.startTime + this.windowSize) {
|
|
2857
|
+
return key;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
return timestamp;
|
|
2738
2861
|
}
|
|
2739
2862
|
/**
|
|
2740
2863
|
* Check if a render was likely triggered by context
|
|
@@ -3351,6 +3474,14 @@ var FixSuggester = class extends EventEmitter {
|
|
|
3351
3474
|
getSuggestions(componentName) {
|
|
3352
3475
|
return this.suggestions.get(componentName) ?? [];
|
|
3353
3476
|
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Whether suggestions have been generated (and cached) for a component
|
|
3479
|
+
* @param componentName - Component name
|
|
3480
|
+
* @returns true when {@link analyze} ran for the component
|
|
3481
|
+
*/
|
|
3482
|
+
hasSuggestions(componentName) {
|
|
3483
|
+
return this.suggestions.has(componentName);
|
|
3484
|
+
}
|
|
3354
3485
|
/**
|
|
3355
3486
|
* Get all cached suggestions
|
|
3356
3487
|
* @returns All suggestions
|
|
@@ -3417,7 +3548,31 @@ var FixSuggester = class extends EventEmitter {
|
|
|
3417
3548
|
}
|
|
3418
3549
|
};
|
|
3419
3550
|
|
|
3551
|
+
// src/utils/pattern.ts
|
|
3552
|
+
function matchComponentPattern(name, pattern) {
|
|
3553
|
+
let source = "";
|
|
3554
|
+
let prev = "";
|
|
3555
|
+
for (const ch of pattern) {
|
|
3556
|
+
if (ch === "*" && prev === "*") continue;
|
|
3557
|
+
prev = ch;
|
|
3558
|
+
if (ch === "*") source += ".*";
|
|
3559
|
+
else if (ch === "?") source += ".";
|
|
3560
|
+
else source += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
3561
|
+
}
|
|
3562
|
+
return new RegExp(`^${source}$`).test(name);
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3420
3565
|
// src/core/scanner.ts
|
|
3566
|
+
function toRuleLevels(rules) {
|
|
3567
|
+
const levels = {};
|
|
3568
|
+
for (const [id, setting] of Object.entries(rules)) {
|
|
3569
|
+
const level = Array.isArray(setting) ? setting[0] : setting;
|
|
3570
|
+
if (level === "off" || level === "warn" || level === "error") {
|
|
3571
|
+
levels[id] = level;
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
return levels;
|
|
3575
|
+
}
|
|
3421
3576
|
var DEFAULT_CONFIG2 = {
|
|
3422
3577
|
trackUnnecessary: true,
|
|
3423
3578
|
fpsThreshold: 30,
|
|
@@ -3436,6 +3591,8 @@ var Scanner = class extends EventEmitter {
|
|
|
3436
3591
|
chainAnalyzer;
|
|
3437
3592
|
/** Fix suggester */
|
|
3438
3593
|
fixSuggester;
|
|
3594
|
+
/** Components whose stats changed since their suggestions were last generated */
|
|
3595
|
+
staleSuggestions = /* @__PURE__ */ new Set();
|
|
3439
3596
|
/** Scanner configuration */
|
|
3440
3597
|
config;
|
|
3441
3598
|
/** Whether scanner is currently running */
|
|
@@ -3461,7 +3618,7 @@ var Scanner = class extends EventEmitter {
|
|
|
3461
3618
|
const thresholds = { ...DEFAULT_THRESHOLDS2, ...options.thresholds };
|
|
3462
3619
|
this.stats = new StatsCollector(thresholds);
|
|
3463
3620
|
this.chainAnalyzer = new ChainAnalyzer();
|
|
3464
|
-
this.fixSuggester = new FixSuggester();
|
|
3621
|
+
this.fixSuggester = new FixSuggester(options.rules ? { rules: toRuleLevels(options.rules) } : {});
|
|
3465
3622
|
this.setupEventForwarding();
|
|
3466
3623
|
}
|
|
3467
3624
|
/**
|
|
@@ -3469,6 +3626,7 @@ var Scanner = class extends EventEmitter {
|
|
|
3469
3626
|
*/
|
|
3470
3627
|
setupEventForwarding() {
|
|
3471
3628
|
this.stats.on("update", (stats) => {
|
|
3629
|
+
this.staleSuggestions.add(stats.name);
|
|
3472
3630
|
this.emit("stats", stats);
|
|
3473
3631
|
});
|
|
3474
3632
|
this.stats.on("severityChange", (change) => {
|
|
@@ -3517,29 +3675,71 @@ var Scanner = class extends EventEmitter {
|
|
|
3517
3675
|
this.stats.reset();
|
|
3518
3676
|
this.chainAnalyzer.reset();
|
|
3519
3677
|
this.fixSuggester.clearSuggestions();
|
|
3678
|
+
this.staleSuggestions.clear();
|
|
3520
3679
|
this.renderBatch = [];
|
|
3521
3680
|
this.emit("reset", void 0);
|
|
3522
3681
|
}
|
|
3523
3682
|
/**
|
|
3524
3683
|
* Process a render event
|
|
3525
3684
|
* @param render - Render information
|
|
3526
|
-
* @param parent - Optional parent component name
|
|
3685
|
+
* @param parent - Optional parent component name (defaults to `render.parent`,
|
|
3686
|
+
* which the injected browser script fills in from the fiber tree)
|
|
3527
3687
|
*/
|
|
3528
3688
|
addRender(render, parent) {
|
|
3529
3689
|
if (!this.running) return;
|
|
3690
|
+
if (!this.isComponentIncluded(render.componentName)) return;
|
|
3691
|
+
const parentName = parent ?? (typeof render.parent === "string" && render.parent !== "" ? render.parent : void 0);
|
|
3530
3692
|
this.renderBatch.push(render);
|
|
3531
3693
|
this.stats.addRender(render);
|
|
3532
|
-
|
|
3694
|
+
if (parentName !== void 0) {
|
|
3695
|
+
this.stats.setComponentParent(render.componentName, parentName);
|
|
3696
|
+
}
|
|
3697
|
+
this.chainAnalyzer.addRender(render, parentName);
|
|
3533
3698
|
this.emit("render", render);
|
|
3534
|
-
this.frameCount++;
|
|
3535
3699
|
this.scheduleBatchProcessing();
|
|
3536
3700
|
}
|
|
3537
3701
|
/**
|
|
3538
|
-
*
|
|
3702
|
+
* Check a component name against the configured include/exclude patterns
|
|
3703
|
+
* @param name - Component name
|
|
3704
|
+
* @returns true if renders of this component should be tracked
|
|
3705
|
+
*/
|
|
3706
|
+
isComponentIncluded(name) {
|
|
3707
|
+
const { include, exclude } = this.config;
|
|
3708
|
+
if (include && include.length > 0 && !include.some((p) => matchComponentPattern(name, p))) {
|
|
3709
|
+
return false;
|
|
3710
|
+
}
|
|
3711
|
+
if (exclude && exclude.length > 0 && exclude.some((p) => matchComponentPattern(name, p))) {
|
|
3712
|
+
return false;
|
|
3713
|
+
}
|
|
3714
|
+
return true;
|
|
3715
|
+
}
|
|
3716
|
+
/**
|
|
3717
|
+
* Record a painted frame for FPS calculation (the scanner derives FPS from
|
|
3718
|
+
* frames recorded during each one-second window)
|
|
3539
3719
|
*/
|
|
3540
3720
|
recordFrame() {
|
|
3541
3721
|
this.frameCount++;
|
|
3542
3722
|
}
|
|
3723
|
+
/**
|
|
3724
|
+
* Record an FPS sample measured elsewhere (e.g. by requestAnimationFrame in
|
|
3725
|
+
* the browser)
|
|
3726
|
+
* @param fps - Frames per second
|
|
3727
|
+
*/
|
|
3728
|
+
recordFps(fps) {
|
|
3729
|
+
if (!this.running || !Number.isFinite(fps) || fps < 0) return;
|
|
3730
|
+
this.lastFps = Math.round(fps);
|
|
3731
|
+
this.stats.addFpsSample(this.lastFps);
|
|
3732
|
+
if (this.lastFps < this.getFpsThreshold()) {
|
|
3733
|
+
this.emit("fps-drop", this.lastFps);
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
/**
|
|
3737
|
+
* FPS threshold below which `fps-drop` is emitted
|
|
3738
|
+
* @returns Threshold
|
|
3739
|
+
*/
|
|
3740
|
+
getFpsThreshold() {
|
|
3741
|
+
return this.stats.getThresholds().fps ?? this.config.fpsThreshold;
|
|
3742
|
+
}
|
|
3543
3743
|
/**
|
|
3544
3744
|
* Schedule batch processing
|
|
3545
3745
|
*/
|
|
@@ -3551,6 +3751,8 @@ var Scanner = class extends EventEmitter {
|
|
|
3551
3751
|
this.batchTimeout = setTimeout(() => {
|
|
3552
3752
|
this.flushBatch();
|
|
3553
3753
|
}, this.batchDelay);
|
|
3754
|
+
const timer = this.batchTimeout;
|
|
3755
|
+
timer.unref?.();
|
|
3554
3756
|
}
|
|
3555
3757
|
}
|
|
3556
3758
|
/**
|
|
@@ -3595,16 +3797,15 @@ var Scanner = class extends EventEmitter {
|
|
|
3595
3797
|
this.fpsInterval = setInterval(() => {
|
|
3596
3798
|
const now = Date.now();
|
|
3597
3799
|
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
|
-
}
|
|
3800
|
+
const frames = this.frameCount;
|
|
3605
3801
|
this.frameCount = 0;
|
|
3606
3802
|
this.lastFpsUpdate = now;
|
|
3803
|
+
if (elapsed > 0 && frames > 0) {
|
|
3804
|
+
this.recordFps(frames * 1e3 / elapsed);
|
|
3805
|
+
}
|
|
3607
3806
|
}, 1e3);
|
|
3807
|
+
const interval = this.fpsInterval;
|
|
3808
|
+
interval.unref?.();
|
|
3608
3809
|
}
|
|
3609
3810
|
/**
|
|
3610
3811
|
* Stop FPS monitoring
|
|
@@ -3695,14 +3896,33 @@ var Scanner = class extends EventEmitter {
|
|
|
3695
3896
|
* @returns All suggestions
|
|
3696
3897
|
*/
|
|
3697
3898
|
getSuggestions() {
|
|
3899
|
+
this.refreshSuggestions();
|
|
3698
3900
|
return this.fixSuggester.getAllSuggestions();
|
|
3699
3901
|
}
|
|
3902
|
+
/**
|
|
3903
|
+
* Re-generate cached suggestions whose component received renders since they
|
|
3904
|
+
* were created, so their text, numbers and severity match the current stats
|
|
3905
|
+
* @param componentName - Only refresh this component (all when omitted)
|
|
3906
|
+
*/
|
|
3907
|
+
refreshSuggestions(componentName) {
|
|
3908
|
+
const names = componentName !== void 0 ? [componentName] : [...this.staleSuggestions];
|
|
3909
|
+
for (const name of names) {
|
|
3910
|
+
if (!this.staleSuggestions.has(name)) continue;
|
|
3911
|
+
this.staleSuggestions.delete(name);
|
|
3912
|
+
if (!this.fixSuggester.hasSuggestions(name)) continue;
|
|
3913
|
+
const stats = this.stats.getComponentStats(name);
|
|
3914
|
+
if (stats) {
|
|
3915
|
+
this.fixSuggester.analyze(stats);
|
|
3916
|
+
}
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3700
3919
|
/**
|
|
3701
3920
|
* Get suggestions for a specific component
|
|
3702
3921
|
* @param componentName - Component name
|
|
3703
3922
|
* @returns Component suggestions
|
|
3704
3923
|
*/
|
|
3705
3924
|
getComponentSuggestions(componentName) {
|
|
3925
|
+
this.refreshSuggestions(componentName);
|
|
3706
3926
|
return this.fixSuggester.getSuggestions(componentName);
|
|
3707
3927
|
}
|
|
3708
3928
|
/**
|
|
@@ -4921,14 +5141,26 @@ var TUI = class extends EventEmitter {
|
|
|
4921
5141
|
this.keys.bind("end", () => this.componentList.moveToEnd());
|
|
4922
5142
|
this.keys.bind("enter", () => this.handleSelect());
|
|
4923
5143
|
this.keys.bind("escape", () => this.handleBack());
|
|
4924
|
-
this.keys.bind("q", () =>
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
this.keys.bind("
|
|
4928
|
-
|
|
5144
|
+
this.keys.bind("q", () => {
|
|
5145
|
+
this.emit("quit", void 0);
|
|
5146
|
+
});
|
|
5147
|
+
this.keys.bind("ctrl+c", () => {
|
|
5148
|
+
this.emit("quit", void 0);
|
|
5149
|
+
});
|
|
5150
|
+
this.keys.bind("p", () => {
|
|
5151
|
+
this.emit("togglePause", void 0);
|
|
5152
|
+
});
|
|
5153
|
+
this.keys.bind("r", () => {
|
|
5154
|
+
this.emit("generateReport", void 0);
|
|
5155
|
+
});
|
|
5156
|
+
this.keys.bind("s", () => {
|
|
5157
|
+
this.emit("openSettings", void 0);
|
|
5158
|
+
});
|
|
4929
5159
|
this.keys.bind("f", () => this.showFixSuggestions());
|
|
4930
5160
|
this.keys.bind("c", () => this.showRenderChain());
|
|
4931
|
-
this.keys.bind("o", () =>
|
|
5161
|
+
this.keys.bind("o", () => {
|
|
5162
|
+
this.emit("toggleOverlay", void 0);
|
|
5163
|
+
});
|
|
4932
5164
|
}
|
|
4933
5165
|
/**
|
|
4934
5166
|
* Start the TUI
|
|
@@ -5223,6 +5455,7 @@ var OPCODE = {
|
|
|
5223
5455
|
PONG: 10
|
|
5224
5456
|
};
|
|
5225
5457
|
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
5458
|
+
var MAX_FRAME_PAYLOAD = 16 * 1024 * 1024;
|
|
5226
5459
|
var WebSocketClient = class extends EventEmitter {
|
|
5227
5460
|
/** Socket connection */
|
|
5228
5461
|
socket;
|
|
@@ -5259,7 +5492,7 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5259
5492
|
* Process received frames
|
|
5260
5493
|
*/
|
|
5261
5494
|
processFrames() {
|
|
5262
|
-
while (this.frameBuffer.length >= 2) {
|
|
5495
|
+
while (this.isOpen && this.frameBuffer.length >= 2) {
|
|
5263
5496
|
const frame = this.parseFrame();
|
|
5264
5497
|
if (!frame) break;
|
|
5265
5498
|
switch (frame.opcode) {
|
|
@@ -5299,8 +5532,18 @@ var WebSocketClient = class extends EventEmitter {
|
|
|
5299
5532
|
offset = 4;
|
|
5300
5533
|
} else if (payloadLength === 127) {
|
|
5301
5534
|
if (this.frameBuffer.length < 10) return null;
|
|
5535
|
+
const high = this.frameBuffer.readUInt32BE(2);
|
|
5302
5536
|
payloadLength = this.frameBuffer.readUInt32BE(6);
|
|
5303
5537
|
offset = 10;
|
|
5538
|
+
if (high !== 0) {
|
|
5539
|
+
payloadLength = Number.POSITIVE_INFINITY;
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
if (payloadLength > MAX_FRAME_PAYLOAD) {
|
|
5543
|
+
this.frameBuffer = Buffer.alloc(0);
|
|
5544
|
+
this.close(1009, "Message too big");
|
|
5545
|
+
this.socket.destroy();
|
|
5546
|
+
return null;
|
|
5304
5547
|
}
|
|
5305
5548
|
let maskingKey = null;
|
|
5306
5549
|
if (masked) {
|
|
@@ -5498,6 +5741,10 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5498
5741
|
this.server.once("error", reject);
|
|
5499
5742
|
this.server.listen(this.port, () => {
|
|
5500
5743
|
this.server.removeListener("error", reject);
|
|
5744
|
+
const address = this.server.address();
|
|
5745
|
+
if (address && typeof address === "object") {
|
|
5746
|
+
this.port = address.port;
|
|
5747
|
+
}
|
|
5501
5748
|
this.emit("listening", { port: this.port });
|
|
5502
5749
|
resolve3();
|
|
5503
5750
|
});
|
|
@@ -5517,6 +5764,14 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5517
5764
|
});
|
|
5518
5765
|
});
|
|
5519
5766
|
}
|
|
5767
|
+
/**
|
|
5768
|
+
* Get the port the server listens on (the real port after start() when
|
|
5769
|
+
* constructed with port 0)
|
|
5770
|
+
* @returns Port number
|
|
5771
|
+
*/
|
|
5772
|
+
getPort() {
|
|
5773
|
+
return this.port;
|
|
5774
|
+
}
|
|
5520
5775
|
/**
|
|
5521
5776
|
* Broadcast message to all clients
|
|
5522
5777
|
* @param message - Message to broadcast
|
|
@@ -5552,16 +5807,53 @@ var WebSocketServer = class extends EventEmitter {
|
|
|
5552
5807
|
};
|
|
5553
5808
|
function handleBrowserMessages(client, handler) {
|
|
5554
5809
|
client.on("message", (data) => {
|
|
5810
|
+
let message;
|
|
5555
5811
|
try {
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5812
|
+
message = JSON.parse(data);
|
|
5813
|
+
} catch {
|
|
5814
|
+
return;
|
|
5815
|
+
}
|
|
5816
|
+
if (message === null || typeof message !== "object" || typeof message.type !== "string") {
|
|
5817
|
+
return;
|
|
5559
5818
|
}
|
|
5819
|
+
handler(message);
|
|
5560
5820
|
});
|
|
5561
5821
|
}
|
|
5822
|
+
function getPuppeteerInstallDir(env = process.env, platform = process.platform, home = homedir()) {
|
|
5823
|
+
const explicit = env["REACTCHECK_PUPPETEER_DIR"];
|
|
5824
|
+
if (explicit !== void 0 && explicit !== "") return explicit;
|
|
5825
|
+
const cacheRoot = platform === "win32" ? env["LOCALAPPDATA"] !== void 0 && env["LOCALAPPDATA"] !== "" ? env["LOCALAPPDATA"] : join(home, "AppData", "Local") : env["XDG_CACHE_HOME"] !== void 0 && env["XDG_CACHE_HOME"] !== "" ? env["XDG_CACHE_HOME"] : join(home, ".cache");
|
|
5826
|
+
return join(cacheRoot, "react-check", "puppeteer");
|
|
5827
|
+
}
|
|
5828
|
+
function toPuppeteer(loaded) {
|
|
5829
|
+
const candidates = [
|
|
5830
|
+
loaded?.default,
|
|
5831
|
+
loaded,
|
|
5832
|
+
loaded?.default?.default
|
|
5833
|
+
];
|
|
5834
|
+
for (const candidate of candidates) {
|
|
5835
|
+
if (candidate !== null && typeof candidate === "object" && typeof candidate.launch === "function") {
|
|
5836
|
+
return candidate;
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
return null;
|
|
5840
|
+
}
|
|
5841
|
+
async function loadPuppeteer(installDir = getPuppeteerInstallDir()) {
|
|
5842
|
+
try {
|
|
5843
|
+
const found = toPuppeteer(await import('puppeteer'));
|
|
5844
|
+
if (found) return found;
|
|
5845
|
+
} catch {
|
|
5846
|
+
}
|
|
5847
|
+
try {
|
|
5848
|
+
const requireFromDir = createRequire(join(installDir, "package.json"));
|
|
5849
|
+
return toPuppeteer(requireFromDir("puppeteer"));
|
|
5850
|
+
} catch {
|
|
5851
|
+
return null;
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5562
5854
|
|
|
5563
5855
|
// src/server/browser.ts
|
|
5564
|
-
var logger3 = new Logger({ prefix: "browser", level:
|
|
5856
|
+
var logger3 = new Logger({ prefix: "browser", level: 1 /* INFO */ });
|
|
5565
5857
|
var BrowserLauncher = class extends EventEmitter {
|
|
5566
5858
|
/** Puppeteer browser instance */
|
|
5567
5859
|
browser = null;
|
|
@@ -5600,7 +5892,10 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5600
5892
|
*/
|
|
5601
5893
|
async launch() {
|
|
5602
5894
|
try {
|
|
5603
|
-
const puppeteer = await
|
|
5895
|
+
const puppeteer = await loadPuppeteer();
|
|
5896
|
+
if (!puppeteer) {
|
|
5897
|
+
throw new Error("Puppeteer is not installed. Install it with: npm install puppeteer");
|
|
5898
|
+
}
|
|
5604
5899
|
const args = [
|
|
5605
5900
|
"--no-sandbox",
|
|
5606
5901
|
"--disable-setuid-sandbox",
|
|
@@ -5611,7 +5906,7 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5611
5906
|
`--window-size=${this.options.width},${this.options.height}`,
|
|
5612
5907
|
...this.options.args
|
|
5613
5908
|
];
|
|
5614
|
-
this.browser = await puppeteer.
|
|
5909
|
+
this.browser = await puppeteer.launch({
|
|
5615
5910
|
headless: this.options.headless,
|
|
5616
5911
|
args,
|
|
5617
5912
|
slowMo: this.options.slowMo,
|
|
@@ -5764,14 +6059,16 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5764
6059
|
return this.browser !== null && this.browser.connected;
|
|
5765
6060
|
}
|
|
5766
6061
|
/**
|
|
5767
|
-
* Get the page instance (for advanced usage)
|
|
6062
|
+
* Get the page instance (for advanced usage). The return type is a
|
|
6063
|
+
* structural subset of Puppeteer's `Page`; pass the real type for the full
|
|
6064
|
+
* API: `getPage<import('puppeteer').Page>()`.
|
|
5768
6065
|
* @returns Puppeteer page or null
|
|
5769
6066
|
*/
|
|
5770
6067
|
getPage() {
|
|
5771
6068
|
return this.page;
|
|
5772
6069
|
}
|
|
5773
6070
|
/**
|
|
5774
|
-
* Get the browser instance (for advanced usage)
|
|
6071
|
+
* Get the browser instance (for advanced usage); see {@link getPage}
|
|
5775
6072
|
* @returns Puppeteer browser or null
|
|
5776
6073
|
*/
|
|
5777
6074
|
getBrowser() {
|
|
@@ -5779,16 +6076,237 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5779
6076
|
}
|
|
5780
6077
|
};
|
|
5781
6078
|
async function isPuppeteerAvailable() {
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
6079
|
+
return await loadPuppeteer() !== null;
|
|
6080
|
+
}
|
|
6081
|
+
var INJECTION_SCRIPT_FILE = "browser-inject.global.js";
|
|
6082
|
+
function getInjectionScriptCandidates() {
|
|
6083
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
6084
|
+
return [
|
|
6085
|
+
resolve(here, INJECTION_SCRIPT_FILE),
|
|
6086
|
+
resolve(here, "..", INJECTION_SCRIPT_FILE),
|
|
6087
|
+
resolve(here, "..", "..", "dist", INJECTION_SCRIPT_FILE)
|
|
6088
|
+
];
|
|
6089
|
+
}
|
|
6090
|
+
async function loadInjectionScript(wsPort) {
|
|
6091
|
+
const port = Math.trunc(Number(wsPort));
|
|
6092
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
6093
|
+
throw new RangeError(`Invalid WebSocket port: ${String(wsPort)}`);
|
|
5787
6094
|
}
|
|
6095
|
+
for (const candidate of getInjectionScriptCandidates()) {
|
|
6096
|
+
try {
|
|
6097
|
+
const script = await readFile(candidate, "utf8");
|
|
6098
|
+
return `window.__REACTCHECK_PORT__ = ${port};
|
|
6099
|
+
${script}`;
|
|
6100
|
+
} catch {
|
|
6101
|
+
}
|
|
6102
|
+
}
|
|
6103
|
+
throw new Error(
|
|
6104
|
+
`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.`
|
|
6105
|
+
);
|
|
5788
6106
|
}
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
6107
|
+
var logger4 = new Logger({ prefix: "proxy", level: 1 /* INFO */ });
|
|
6108
|
+
var SCANNER_SCRIPT_PATH = "/__reactcheck__/scanner.js";
|
|
6109
|
+
function injectScriptTag(html) {
|
|
6110
|
+
const tag = `<script src="${SCANNER_SCRIPT_PATH}"></script>`;
|
|
6111
|
+
if (html.includes(tag)) return html;
|
|
6112
|
+
const head = /<head(?:\s[^>]*)?>/i.exec(html);
|
|
6113
|
+
if (head) {
|
|
6114
|
+
const at = head.index + head[0].length;
|
|
6115
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
6116
|
+
}
|
|
6117
|
+
const htmlTag = /<html(?:\s[^>]*)?>/i.exec(html);
|
|
6118
|
+
if (htmlTag) {
|
|
6119
|
+
const at = htmlTag.index + htmlTag[0].length;
|
|
6120
|
+
return html.slice(0, at) + tag + html.slice(at);
|
|
6121
|
+
}
|
|
6122
|
+
const doctype = /^\s*<!doctype[^>]*>/i.exec(html);
|
|
6123
|
+
if (doctype) {
|
|
6124
|
+
return doctype[0] + tag + html.slice(doctype[0].length);
|
|
6125
|
+
}
|
|
6126
|
+
return tag + html;
|
|
6127
|
+
}
|
|
6128
|
+
var ProxyServer = class extends EventEmitter {
|
|
6129
|
+
/** HTTP server instance */
|
|
6130
|
+
server;
|
|
6131
|
+
/** Proxy options */
|
|
6132
|
+
options;
|
|
6133
|
+
/** Target URL parsed */
|
|
6134
|
+
targetUrl;
|
|
6135
|
+
/** Injection script (loaded from the bundled browser script on start() when not provided) */
|
|
6136
|
+
injectionScript;
|
|
6137
|
+
/**
|
|
6138
|
+
* Create a new proxy server
|
|
6139
|
+
* @param options - Proxy options
|
|
6140
|
+
*/
|
|
6141
|
+
constructor(options) {
|
|
6142
|
+
super();
|
|
6143
|
+
this.options = options;
|
|
6144
|
+
this.targetUrl = new URL$1(options.target);
|
|
6145
|
+
this.injectionScript = options.injectionScript ?? null;
|
|
6146
|
+
this.server = createServer((req, res) => {
|
|
6147
|
+
this.handleRequest(req, res).catch((error) => {
|
|
6148
|
+
logger4.error("Request handling error:", error);
|
|
6149
|
+
this.emit("error", error);
|
|
6150
|
+
res.statusCode = 500;
|
|
6151
|
+
res.end("Internal Server Error");
|
|
6152
|
+
});
|
|
6153
|
+
});
|
|
6154
|
+
this.server.on("error", (error) => {
|
|
6155
|
+
this.emit("error", error);
|
|
6156
|
+
});
|
|
6157
|
+
}
|
|
6158
|
+
/**
|
|
6159
|
+
* Handle incoming request
|
|
6160
|
+
* @param req - Client request
|
|
6161
|
+
* @param res - Server response
|
|
6162
|
+
*/
|
|
6163
|
+
async handleRequest(req, res) {
|
|
6164
|
+
const requestUrl = req.url ?? "/";
|
|
6165
|
+
if (requestUrl.startsWith("/__reactcheck__/")) {
|
|
6166
|
+
this.handleReactCheckRoute(requestUrl, res);
|
|
6167
|
+
return;
|
|
6168
|
+
}
|
|
6169
|
+
this.emit("request", { url: requestUrl, method: req.method ?? "GET" });
|
|
6170
|
+
const targetUrl = new URL$1(requestUrl, this.targetUrl);
|
|
6171
|
+
await this.proxyRequest(req, res, targetUrl);
|
|
6172
|
+
}
|
|
6173
|
+
/**
|
|
6174
|
+
* Handle ReactCheck special routes
|
|
6175
|
+
* @param url - Request URL
|
|
6176
|
+
* @param res - Server response
|
|
6177
|
+
*/
|
|
6178
|
+
handleReactCheckRoute(url, res) {
|
|
6179
|
+
if (url === SCANNER_SCRIPT_PATH || url.startsWith(`${SCANNER_SCRIPT_PATH}?`)) {
|
|
6180
|
+
res.writeHead(200, {
|
|
6181
|
+
"Content-Type": "application/javascript; charset=utf-8",
|
|
6182
|
+
"Cache-Control": "no-cache",
|
|
6183
|
+
"Access-Control-Allow-Origin": "*"
|
|
6184
|
+
});
|
|
6185
|
+
res.end(this.injectionScript ?? "");
|
|
6186
|
+
return;
|
|
6187
|
+
}
|
|
6188
|
+
res.writeHead(404);
|
|
6189
|
+
res.end("Not Found");
|
|
6190
|
+
}
|
|
6191
|
+
/**
|
|
6192
|
+
* Proxy a request to the target
|
|
6193
|
+
* @param req - Client request
|
|
6194
|
+
* @param res - Server response
|
|
6195
|
+
* @param targetUrl - Target URL
|
|
6196
|
+
*/
|
|
6197
|
+
proxyRequest(req, res, targetUrl) {
|
|
6198
|
+
return new Promise((resolve3, reject) => {
|
|
6199
|
+
const isHttps = targetUrl.protocol === "https:";
|
|
6200
|
+
const requestFn = isHttps ? request : request$1;
|
|
6201
|
+
const headers = { ...req.headers };
|
|
6202
|
+
delete headers["accept-encoding"];
|
|
6203
|
+
headers["host"] = targetUrl.host;
|
|
6204
|
+
const options = {
|
|
6205
|
+
hostname: targetUrl.hostname,
|
|
6206
|
+
port: targetUrl.port || (isHttps ? 443 : 80),
|
|
6207
|
+
path: targetUrl.pathname + targetUrl.search,
|
|
6208
|
+
method: req.method,
|
|
6209
|
+
headers
|
|
6210
|
+
};
|
|
6211
|
+
const proxyReq = requestFn(options, (proxyRes) => {
|
|
6212
|
+
const contentType = proxyRes.headers["content-type"] ?? "";
|
|
6213
|
+
const contentEncoding = String(proxyRes.headers["content-encoding"] ?? "identity").toLowerCase();
|
|
6214
|
+
if (contentType.includes("text/html") && (contentEncoding === "identity" || contentEncoding === "")) {
|
|
6215
|
+
this.injectAndRespond(proxyRes, res, targetUrl.href);
|
|
6216
|
+
resolve3();
|
|
6217
|
+
return;
|
|
6218
|
+
}
|
|
6219
|
+
res.writeHead(proxyRes.statusCode ?? 200, proxyRes.headers);
|
|
6220
|
+
proxyRes.pipe(res);
|
|
6221
|
+
proxyRes.on("end", resolve3);
|
|
6222
|
+
});
|
|
6223
|
+
proxyReq.on("error", (error) => {
|
|
6224
|
+
logger4.error("Proxy request error:", error);
|
|
6225
|
+
reject(error);
|
|
6226
|
+
});
|
|
6227
|
+
req.pipe(proxyReq);
|
|
6228
|
+
});
|
|
6229
|
+
}
|
|
6230
|
+
/**
|
|
6231
|
+
* Inject script and respond with modified HTML
|
|
6232
|
+
* @param proxyRes - Proxy response
|
|
6233
|
+
* @param res - Client response
|
|
6234
|
+
* @param url - Request URL
|
|
6235
|
+
*/
|
|
6236
|
+
injectAndRespond(proxyRes, res, url) {
|
|
6237
|
+
const chunks = [];
|
|
6238
|
+
proxyRes.on("data", (chunk) => {
|
|
6239
|
+
chunks.push(chunk);
|
|
6240
|
+
});
|
|
6241
|
+
proxyRes.on("end", () => {
|
|
6242
|
+
const body = Buffer.concat(chunks).toString("utf-8");
|
|
6243
|
+
const injected = injectScriptTag(body);
|
|
6244
|
+
this.emit("inject", { url });
|
|
6245
|
+
const headers = {};
|
|
6246
|
+
for (const [key, value] of Object.entries(proxyRes.headers)) {
|
|
6247
|
+
const lower = key.toLowerCase();
|
|
6248
|
+
if (lower !== "content-length" && lower !== "transfer-encoding" && value !== void 0) {
|
|
6249
|
+
headers[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
headers["content-length"] = Buffer.byteLength(injected);
|
|
6253
|
+
res.writeHead(proxyRes.statusCode ?? 200, headers);
|
|
6254
|
+
res.end(injected);
|
|
6255
|
+
});
|
|
6256
|
+
proxyRes.on("error", (error) => {
|
|
6257
|
+
logger4.error("Proxy response error:", error);
|
|
6258
|
+
res.writeHead(502);
|
|
6259
|
+
res.end("Bad Gateway");
|
|
6260
|
+
});
|
|
6261
|
+
}
|
|
6262
|
+
/**
|
|
6263
|
+
* Start the proxy server
|
|
6264
|
+
*/
|
|
6265
|
+
async start() {
|
|
6266
|
+
if (this.injectionScript === null) {
|
|
6267
|
+
this.injectionScript = await loadInjectionScript(this.options.wsPort);
|
|
6268
|
+
}
|
|
6269
|
+
return new Promise((resolve3, reject) => {
|
|
6270
|
+
this.server.once("error", reject);
|
|
6271
|
+
this.server.listen(this.options.port, () => {
|
|
6272
|
+
this.server.removeListener("error", reject);
|
|
6273
|
+
const address = this.server.address();
|
|
6274
|
+
if (address && typeof address === "object") {
|
|
6275
|
+
this.options.port = address.port;
|
|
6276
|
+
}
|
|
6277
|
+
this.emit("listening", { port: this.options.port });
|
|
6278
|
+
logger4.info(`Proxy server listening on http://localhost:${this.options.port}`);
|
|
6279
|
+
logger4.info(`Proxying to ${this.options.target}`);
|
|
6280
|
+
resolve3();
|
|
6281
|
+
});
|
|
6282
|
+
});
|
|
6283
|
+
}
|
|
6284
|
+
/**
|
|
6285
|
+
* Stop the proxy server
|
|
6286
|
+
*/
|
|
6287
|
+
stop() {
|
|
6288
|
+
return new Promise((resolve3) => {
|
|
6289
|
+
this.server.close(() => {
|
|
6290
|
+
this.emit("close", void 0);
|
|
6291
|
+
resolve3();
|
|
6292
|
+
});
|
|
6293
|
+
});
|
|
6294
|
+
}
|
|
6295
|
+
/**
|
|
6296
|
+
* Get the proxy URL
|
|
6297
|
+
* @returns Local proxy URL
|
|
6298
|
+
*/
|
|
6299
|
+
getProxyUrl() {
|
|
6300
|
+
return `http://localhost:${this.options.port}`;
|
|
6301
|
+
}
|
|
6302
|
+
/**
|
|
6303
|
+
* Update injection script
|
|
6304
|
+
* @param script - New injection script
|
|
6305
|
+
*/
|
|
6306
|
+
setInjectionScript(script) {
|
|
6307
|
+
this.injectionScript = script;
|
|
6308
|
+
}
|
|
6309
|
+
};
|
|
5792
6310
|
|
|
5793
6311
|
// src/webui/dashboard.ts
|
|
5794
6312
|
function generateDashboardHTML(wsPort, target) {
|
|
@@ -6835,7 +7353,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6835
7353
|
this.server = createServer((req, res) => {
|
|
6836
7354
|
this.handleHttpRequest(req, res);
|
|
6837
7355
|
});
|
|
6838
|
-
this.server.on("upgrade", (req, socket
|
|
7356
|
+
this.server.on("upgrade", (req, socket) => {
|
|
6839
7357
|
this.handleUpgrade(req, socket);
|
|
6840
7358
|
});
|
|
6841
7359
|
this.server.on("error", (error) => {
|
|
@@ -6924,7 +7442,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6924
7442
|
*/
|
|
6925
7443
|
handleClientData(client, socket, data) {
|
|
6926
7444
|
if (data.length < 2) return;
|
|
6927
|
-
const opcode = data[0] & 15;
|
|
7445
|
+
const opcode = (data[0] ?? 0) & 15;
|
|
6928
7446
|
if (opcode === OPCODE2.PING) {
|
|
6929
7447
|
const pong = Buffer.alloc(2);
|
|
6930
7448
|
pong[0] = 138;
|
|
@@ -7052,62 +7570,86 @@ var WebUIServer = class extends EventEmitter {
|
|
|
7052
7570
|
return `http://localhost:${this.port}`;
|
|
7053
7571
|
}
|
|
7054
7572
|
};
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7573
|
+
|
|
7574
|
+
// src/version.ts
|
|
7575
|
+
var VERSION = "1.3.1";
|
|
7576
|
+
|
|
7577
|
+
// src/cli/commands/scan.ts
|
|
7578
|
+
var logger5 = new Logger({ prefix: "scan", level: 1 /* INFO */ });
|
|
7579
|
+
function canAutoInstall(env = process.env, isTTY = process.stdin.isTTY === true && process.stdout.isTTY === true) {
|
|
7580
|
+
if (!isTTY) return false;
|
|
7581
|
+
if (env["CI"] !== void 0 && env["CI"] !== "" && env["CI"] !== "false" && env["CI"] !== "0") return false;
|
|
7582
|
+
if (env["REACTCHECK_NO_INSTALL"] !== void 0 && env["REACTCHECK_NO_INSTALL"] !== "") return false;
|
|
7583
|
+
return true;
|
|
7584
|
+
}
|
|
7585
|
+
function defaultInstallDeps() {
|
|
7586
|
+
return {
|
|
7587
|
+
installDir: getPuppeteerInstallDir(),
|
|
7588
|
+
run: (command, cwd) => {
|
|
7589
|
+
execSync(command, { cwd, stdio: "inherit", timeout: 3e5 });
|
|
7590
|
+
},
|
|
7591
|
+
isAvailable: isPuppeteerAvailable,
|
|
7592
|
+
// eslint-disable-next-line no-console
|
|
7593
|
+
print: (line) => console.log(line)
|
|
7594
|
+
};
|
|
7595
|
+
}
|
|
7596
|
+
async function installPuppeteer(deps = defaultInstallDeps()) {
|
|
7597
|
+
const { installDir, print } = deps;
|
|
7598
|
+
print("");
|
|
7599
|
+
print(colors.cyan + "\u{1F4E6} Puppeteer is required for browser automation." + colors.reset);
|
|
7600
|
+
print(colors.gray + ` Installing puppeteer into ${installDir} (this may take a minute)` + colors.reset);
|
|
7601
|
+
print("");
|
|
7061
7602
|
try {
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
}
|
|
7067
|
-
|
|
7068
|
-
console.log(colors.green + "\u2713 Puppeteer installed successfully!" + colors.reset);
|
|
7069
|
-
console.log("");
|
|
7070
|
-
console.log(colors.cyan + "\u{1F504} Restarting scan..." + colors.reset);
|
|
7071
|
-
console.log("");
|
|
7072
|
-
if (wsServer) {
|
|
7073
|
-
await wsServer.stop();
|
|
7074
|
-
}
|
|
7075
|
-
const args = process.argv.slice(1);
|
|
7076
|
-
const { spawn } = await import('child_process');
|
|
7077
|
-
const isWindows = process.platform === "win32";
|
|
7078
|
-
const child = spawn(process.execPath, args, {
|
|
7079
|
-
stdio: "inherit",
|
|
7080
|
-
env: process.env,
|
|
7081
|
-
shell: isWindows,
|
|
7082
|
-
detached: false
|
|
7083
|
-
});
|
|
7084
|
-
await new Promise((resolve3) => {
|
|
7085
|
-
child.on("exit", (code) => {
|
|
7086
|
-
process.exit(code ?? 0);
|
|
7087
|
-
});
|
|
7088
|
-
child.on("error", (err) => {
|
|
7089
|
-
console.error("Spawn error:", err);
|
|
7090
|
-
resolve3();
|
|
7091
|
-
});
|
|
7092
|
-
});
|
|
7093
|
-
return false;
|
|
7603
|
+
mkdirSync(installDir, { recursive: true });
|
|
7604
|
+
const manifest = join(installDir, "package.json");
|
|
7605
|
+
if (!existsSync(manifest)) {
|
|
7606
|
+
writeFileSync(manifest, JSON.stringify({ name: "react-check-puppeteer", private: true }, null, 2) + "\n");
|
|
7607
|
+
}
|
|
7608
|
+
deps.run("npm install puppeteer --no-audit --no-fund", installDir);
|
|
7094
7609
|
} catch (error) {
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7610
|
+
print("");
|
|
7611
|
+
logger5.error(`Failed to install puppeteer automatically: ${error instanceof Error ? error.message : String(error)}`);
|
|
7612
|
+
printManualInstallHelp();
|
|
7613
|
+
return false;
|
|
7614
|
+
}
|
|
7615
|
+
if (!await deps.isAvailable()) {
|
|
7616
|
+
print("");
|
|
7617
|
+
logger5.error(`Puppeteer was installed into ${installDir} but still cannot be loaded.`);
|
|
7618
|
+
printManualInstallHelp();
|
|
7100
7619
|
return false;
|
|
7101
7620
|
}
|
|
7621
|
+
print("");
|
|
7622
|
+
print(colors.green + "\u2713 Puppeteer installed successfully!" + colors.reset);
|
|
7623
|
+
print("");
|
|
7624
|
+
return true;
|
|
7625
|
+
}
|
|
7626
|
+
function printManualInstallHelp() {
|
|
7627
|
+
logger5.info("Install it in your project and run react-check from there: npm install --save-dev puppeteer @oxog/react-check");
|
|
7628
|
+
logger5.info("Or install both globally: npm install -g @oxog/react-check puppeteer");
|
|
7629
|
+
logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
|
|
7630
|
+
logger5.info("Set REACTCHECK_NO_INSTALL=1 to skip the automatic install.");
|
|
7631
|
+
}
|
|
7632
|
+
function toFormats(value) {
|
|
7633
|
+
return parseFormatList(value).filter(
|
|
7634
|
+
(f) => f === "html" || f === "json" || f === "md"
|
|
7635
|
+
);
|
|
7636
|
+
}
|
|
7637
|
+
function toSeconds(value) {
|
|
7638
|
+
if (value === void 0) return void 0;
|
|
7639
|
+
const n = Number(value);
|
|
7640
|
+
return Number.isFinite(n) && n > 0 ? n : void 0;
|
|
7102
7641
|
}
|
|
7103
7642
|
function parseScanOptions(args) {
|
|
7643
|
+
const format = getStringFlag(args, "format") ?? "all";
|
|
7644
|
+
const provided = args.provided;
|
|
7645
|
+
const reportRequested = getBooleanFlag(args, "report") || (provided?.has("format") ?? false) || (provided?.has("output") ?? false);
|
|
7104
7646
|
return {
|
|
7105
7647
|
target: normalizeTarget(args.target ?? "localhost:3000"),
|
|
7106
7648
|
proxy: getBooleanFlag(args, "proxy"),
|
|
7107
|
-
tui: getBooleanFlag(args, "tui"),
|
|
7108
7649
|
silent: getBooleanFlag(args, "silent"),
|
|
7109
|
-
report:
|
|
7110
|
-
format
|
|
7650
|
+
report: reportRequested,
|
|
7651
|
+
format,
|
|
7652
|
+
formats: toFormats(format),
|
|
7111
7653
|
output: getStringFlag(args, "output") ?? "./reactcheck-reports",
|
|
7112
7654
|
fix: getBooleanFlag(args, "fix"),
|
|
7113
7655
|
verbose: getBooleanFlag(args, "verbose"),
|
|
@@ -7116,64 +7658,34 @@ function parseScanOptions(args) {
|
|
|
7116
7658
|
thresholdWarning: getNumberFlag(args, "threshold-warning") ?? 20,
|
|
7117
7659
|
fpsThreshold: getNumberFlag(args, "fps-threshold") ?? 30,
|
|
7118
7660
|
headless: getBooleanFlag(args, "headless"),
|
|
7119
|
-
duration:
|
|
7120
|
-
watch: getBooleanFlag(args, "watch"),
|
|
7661
|
+
duration: toSeconds(getStringFlag(args, "duration")),
|
|
7121
7662
|
configPath: getStringFlag(args, "config"),
|
|
7122
7663
|
webui: getBooleanFlag(args, "webui"),
|
|
7123
7664
|
webuiPort: getNumberFlag(args, "webui-port") ?? 3199
|
|
7124
7665
|
};
|
|
7125
7666
|
}
|
|
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
|
-
}
|
|
7667
|
+
function mergeScanOptions(options, config, provided) {
|
|
7668
|
+
const configOptions = configToOptions(config);
|
|
7669
|
+
const given = (flag) => provided?.has(flag) ?? true;
|
|
7670
|
+
return {
|
|
7671
|
+
...options,
|
|
7672
|
+
thresholdCritical: given("threshold-critical") ? options.thresholdCritical : configOptions.thresholds.critical,
|
|
7673
|
+
thresholdWarning: given("threshold-warning") ? options.thresholdWarning : configOptions.thresholds.warning,
|
|
7674
|
+
fpsThreshold: given("fps-threshold") ? options.fpsThreshold : configOptions.thresholds.fps,
|
|
7675
|
+
output: given("output") ? options.output : configOptions.report.output,
|
|
7676
|
+
formats: given("format") ? options.formats : configOptions.report.formats,
|
|
7677
|
+
include: configOptions.include,
|
|
7678
|
+
exclude: configOptions.exclude
|
|
7679
|
+
};
|
|
7162
7680
|
}
|
|
7163
7681
|
async function runScanCommand(args) {
|
|
7164
7682
|
const options = parseScanOptions(args);
|
|
7165
7683
|
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
7166
7684
|
if (fromFile) {
|
|
7167
|
-
|
|
7685
|
+
logger5.info(`Using config: ${configPath}`);
|
|
7168
7686
|
}
|
|
7169
7687
|
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
|
-
};
|
|
7688
|
+
const mergedOptions = mergeScanOptions(options, config, args.provided);
|
|
7177
7689
|
const session = {
|
|
7178
7690
|
id: generateId("scan"),
|
|
7179
7691
|
startTime: Date.now(),
|
|
@@ -7182,6 +7694,12 @@ async function runScanCommand(args) {
|
|
|
7182
7694
|
critical: mergedOptions.thresholdCritical,
|
|
7183
7695
|
warning: mergedOptions.thresholdWarning,
|
|
7184
7696
|
fps: mergedOptions.fpsThreshold
|
|
7697
|
+
},
|
|
7698
|
+
rules: configOptions.rules,
|
|
7699
|
+
config: {
|
|
7700
|
+
fpsThreshold: mergedOptions.fpsThreshold,
|
|
7701
|
+
...mergedOptions.include ? { include: mergedOptions.include } : {},
|
|
7702
|
+
...mergedOptions.exclude ? { exclude: mergedOptions.exclude } : {}
|
|
7185
7703
|
}
|
|
7186
7704
|
}),
|
|
7187
7705
|
tui: null,
|
|
@@ -7193,8 +7711,20 @@ async function runScanCommand(args) {
|
|
|
7193
7711
|
chains: [],
|
|
7194
7712
|
suggestions: [],
|
|
7195
7713
|
overlayEnabled: true,
|
|
7196
|
-
browserClients: /* @__PURE__ */ new Set()
|
|
7714
|
+
browserClients: /* @__PURE__ */ new Set(),
|
|
7715
|
+
proxy: null
|
|
7197
7716
|
};
|
|
7717
|
+
if (!mergedOptions.proxy && !await isPuppeteerAvailable()) {
|
|
7718
|
+
if (!canAutoInstall()) {
|
|
7719
|
+
logger5.error("Puppeteer is required to launch a browser but is not installed.");
|
|
7720
|
+
logger5.info("Install it with: npm install --save-dev puppeteer");
|
|
7721
|
+
logger5.info("Or use --proxy mode and open the proxied URL in your own browser.");
|
|
7722
|
+
return 2;
|
|
7723
|
+
}
|
|
7724
|
+
if (!await installPuppeteer()) {
|
|
7725
|
+
return 2;
|
|
7726
|
+
}
|
|
7727
|
+
}
|
|
7198
7728
|
setupScannerEvents(session);
|
|
7199
7729
|
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && !mergedOptions.webui && process.stdin.isTTY;
|
|
7200
7730
|
if (useTUI) {
|
|
@@ -7207,78 +7737,92 @@ async function runScanCommand(args) {
|
|
|
7207
7737
|
}));
|
|
7208
7738
|
session.tui.start();
|
|
7209
7739
|
} else if (!mergedOptions.silent && !mergedOptions.proxy && !process.stdin.isTTY) {
|
|
7210
|
-
|
|
7740
|
+
logger5.warn("TTY not available, TUI disabled. Use --silent for non-interactive mode.");
|
|
7211
7741
|
}
|
|
7212
7742
|
if (mergedOptions.webui) {
|
|
7213
7743
|
session.webui = new WebUIServer(mergedOptions.webuiPort, mergedOptions.target);
|
|
7214
7744
|
setupWebUIEvents(session);
|
|
7215
7745
|
}
|
|
7216
7746
|
if (!useTUI) {
|
|
7217
|
-
|
|
7747
|
+
logger5.info(`Starting scan of ${mergedOptions.target}`);
|
|
7218
7748
|
}
|
|
7219
7749
|
if (useTUI) {
|
|
7220
|
-
|
|
7750
|
+
logger5.setLevel(4 /* SILENT */);
|
|
7221
7751
|
}
|
|
7222
7752
|
try {
|
|
7223
7753
|
session.wsServer = new WebSocketServer(mergedOptions.port);
|
|
7224
7754
|
await session.wsServer.start();
|
|
7225
|
-
|
|
7755
|
+
logger5.info(`WebSocket server listening on port ${mergedOptions.port}`);
|
|
7226
7756
|
session.wsServer.on("connection", (client) => {
|
|
7227
|
-
|
|
7757
|
+
logger5.info("Browser connected");
|
|
7228
7758
|
session.browserClients.add(client);
|
|
7229
7759
|
handleBrowserMessages(client, (message) => {
|
|
7230
7760
|
switch (message.type) {
|
|
7231
7761
|
case "render":
|
|
7232
7762
|
session.scanner.addRender(message.payload);
|
|
7233
7763
|
break;
|
|
7764
|
+
case "fps":
|
|
7765
|
+
session.scanner.recordFps(message.payload);
|
|
7766
|
+
break;
|
|
7234
7767
|
case "ready":
|
|
7235
|
-
|
|
7768
|
+
if (message.payload.reactVersion.startsWith("unknown")) {
|
|
7769
|
+
logger5.info("Browser script ready, waiting for React to load");
|
|
7770
|
+
} else {
|
|
7771
|
+
logger5.info(`React detected: ${message.payload.reactVersion}`);
|
|
7772
|
+
}
|
|
7236
7773
|
client.send(JSON.stringify({ type: "start" }));
|
|
7774
|
+
client.send(JSON.stringify({
|
|
7775
|
+
type: "config",
|
|
7776
|
+
payload: { thresholds: { warning: mergedOptions.thresholdWarning, critical: mergedOptions.thresholdCritical } }
|
|
7777
|
+
}));
|
|
7237
7778
|
client.send(JSON.stringify({ type: "toggle-overlay", payload: { enabled: session.overlayEnabled } }));
|
|
7238
7779
|
break;
|
|
7239
7780
|
case "error":
|
|
7240
|
-
|
|
7781
|
+
logger5.error("Browser error:", message.payload.message);
|
|
7241
7782
|
break;
|
|
7242
7783
|
}
|
|
7243
7784
|
});
|
|
7244
7785
|
client.on("close", () => {
|
|
7245
|
-
|
|
7786
|
+
logger5.info("Browser disconnected");
|
|
7246
7787
|
session.browserClients.delete(client);
|
|
7247
7788
|
});
|
|
7248
7789
|
});
|
|
7249
7790
|
session.scanner.start();
|
|
7250
7791
|
if (session.webui) {
|
|
7251
|
-
|
|
7792
|
+
await session.webui.start();
|
|
7252
7793
|
session.webui.setScanning(true);
|
|
7253
7794
|
const webuiUrl = session.webui.getUrl();
|
|
7254
|
-
|
|
7795
|
+
logger5.info(`WebUI dashboard: ${webuiUrl}`);
|
|
7255
7796
|
openBrowser(webuiUrl);
|
|
7256
|
-
|
|
7797
|
+
logger5.info("WebUI dashboard opened, Puppeteer will open target URL next...");
|
|
7257
7798
|
}
|
|
7258
7799
|
if (mergedOptions.proxy) {
|
|
7800
|
+
const proxyPort = mergedOptions.port + 1;
|
|
7801
|
+
session.proxy = new ProxyServer({
|
|
7802
|
+
target: mergedOptions.target,
|
|
7803
|
+
port: proxyPort,
|
|
7804
|
+
wsPort: mergedOptions.port,
|
|
7805
|
+
injectionScript: await loadInjectionScript(mergedOptions.port)
|
|
7806
|
+
});
|
|
7807
|
+
await session.proxy.start();
|
|
7808
|
+
const targetUrl = new URL(mergedOptions.target);
|
|
7809
|
+
const proxyUrl = session.proxy.getProxyUrl();
|
|
7810
|
+
const proxiedPage = `${proxyUrl}${targetUrl.pathname}${targetUrl.search}`;
|
|
7259
7811
|
console.log("");
|
|
7260
7812
|
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
7813
|
console.log(colors.cyan + colors.bold + "\u2551 PROXY MODE ACTIVE \u2551" + colors.reset);
|
|
7262
7814
|
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
7815
|
console.log("");
|
|
7264
|
-
console.log(`
|
|
7816
|
+
console.log(` Open ${colors.cyan}${proxiedPage}${colors.reset} (proxies ${mergedOptions.target}) in any browser.`);
|
|
7265
7817
|
console.log("");
|
|
7266
|
-
console.log(
|
|
7267
|
-
console.log(colors.yellow + ` <script src="http://localhost:${mergedOptions.port + 1}/reactcheck.js"></script>` + colors.reset);
|
|
7818
|
+
console.log(" Or add this script to your HTML before React loads:");
|
|
7268
7819
|
console.log("");
|
|
7269
|
-
console.log(`
|
|
7820
|
+
console.log(colors.yellow + ` <script src="${proxyUrl}/__reactcheck__/scanner.js"></script>` + colors.reset);
|
|
7270
7821
|
console.log("");
|
|
7271
7822
|
console.log(` Press ${colors.bold}Ctrl+C${colors.reset} to stop scanning`);
|
|
7272
7823
|
console.log("");
|
|
7273
7824
|
} else {
|
|
7274
|
-
const
|
|
7275
|
-
if (!hasPuppeteer) {
|
|
7276
|
-
const installed = await installPuppeteer(session.wsServer ?? void 0);
|
|
7277
|
-
if (!installed) {
|
|
7278
|
-
return 2;
|
|
7279
|
-
}
|
|
7280
|
-
}
|
|
7281
|
-
const injectionScript = await getInjectionScript(mergedOptions.port);
|
|
7825
|
+
const injectionScript = await loadInjectionScript(mergedOptions.port);
|
|
7282
7826
|
session.browser = new BrowserLauncher({
|
|
7283
7827
|
url: mergedOptions.target,
|
|
7284
7828
|
headless: mergedOptions.headless,
|
|
@@ -7287,38 +7831,19 @@ async function runScanCommand(args) {
|
|
|
7287
7831
|
session.browser.setInjectionScript(injectionScript);
|
|
7288
7832
|
session.browser.on("console", ({ type, text }) => {
|
|
7289
7833
|
if (text.includes("[ReactCheck]") || text.includes("ReactCheck") || type === "error") {
|
|
7290
|
-
|
|
7834
|
+
logger5.info(`Browser [${type}]: ${text}`);
|
|
7291
7835
|
}
|
|
7292
7836
|
});
|
|
7293
7837
|
session.browser.on("error", (error) => {
|
|
7294
|
-
|
|
7838
|
+
logger5.error("Browser error:", error.message);
|
|
7295
7839
|
});
|
|
7296
|
-
|
|
7840
|
+
logger5.info("Launching Puppeteer browser for target URL...");
|
|
7297
7841
|
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);
|
|
7842
|
+
logger5.info("Puppeteer browser launched successfully, now scanning target...");
|
|
7319
7843
|
}
|
|
7320
7844
|
if (mergedOptions.duration) {
|
|
7321
|
-
|
|
7845
|
+
const durationMs = mergedOptions.duration * 1e3;
|
|
7846
|
+
await new Promise((resolve3) => setTimeout(resolve3, durationMs));
|
|
7322
7847
|
session.active = false;
|
|
7323
7848
|
} else if (session.tui) {
|
|
7324
7849
|
await waitForQuit(session);
|
|
@@ -7333,25 +7858,28 @@ async function runScanCommand(args) {
|
|
|
7333
7858
|
}
|
|
7334
7859
|
printSummary(session);
|
|
7335
7860
|
if (mergedOptions.fix && !mergedOptions.silent) {
|
|
7336
|
-
printFixSuggestions(session.
|
|
7861
|
+
printFixSuggestions(session.scanner.getSuggestions());
|
|
7337
7862
|
}
|
|
7338
7863
|
const summary = session.scanner.getSummary();
|
|
7339
7864
|
return summary.criticalIssues > 0 ? 1 : 0;
|
|
7340
7865
|
} catch (error) {
|
|
7341
7866
|
await cleanupSession(session);
|
|
7867
|
+
if (useTUI) {
|
|
7868
|
+
logger5.setLevel(1 /* INFO */);
|
|
7869
|
+
}
|
|
7342
7870
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7343
7871
|
if (errorMessage.includes("ERR_CONNECTION_REFUSED")) {
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7872
|
+
logger5.error(`Could not connect to ${mergedOptions.target}`);
|
|
7873
|
+
logger5.info("Make sure your React application is running at that address.");
|
|
7874
|
+
logger5.info("Example: npm start or npm run dev");
|
|
7347
7875
|
} else if (errorMessage.includes("EADDRINUSE")) {
|
|
7348
|
-
|
|
7349
|
-
|
|
7876
|
+
logger5.error(`Port ${mergedOptions.port} is already in use`);
|
|
7877
|
+
logger5.info("Try using a different port with --port <number>");
|
|
7350
7878
|
} else if (errorMessage.includes("ERR_CERT")) {
|
|
7351
|
-
|
|
7352
|
-
|
|
7879
|
+
logger5.error("SSL certificate error");
|
|
7880
|
+
logger5.info("ReactCheck now supports self-signed certificates by default.");
|
|
7353
7881
|
} else {
|
|
7354
|
-
|
|
7882
|
+
logger5.error("Scan failed:", errorMessage);
|
|
7355
7883
|
}
|
|
7356
7884
|
return 2;
|
|
7357
7885
|
}
|
|
@@ -7367,6 +7895,10 @@ async function cleanupSession(session) {
|
|
|
7367
7895
|
if (session.browser) {
|
|
7368
7896
|
await session.browser.close();
|
|
7369
7897
|
}
|
|
7898
|
+
if (session.proxy) {
|
|
7899
|
+
await session.proxy.stop();
|
|
7900
|
+
session.proxy = null;
|
|
7901
|
+
}
|
|
7370
7902
|
if (session.wsServer) {
|
|
7371
7903
|
await session.wsServer.stop();
|
|
7372
7904
|
}
|
|
@@ -7391,23 +7923,26 @@ function setupScannerEvents(session) {
|
|
|
7391
7923
|
}
|
|
7392
7924
|
});
|
|
7393
7925
|
scanner.on("fix", (suggestion) => {
|
|
7394
|
-
|
|
7926
|
+
const index = session.suggestions.findIndex(
|
|
7395
7927
|
(s) => s.componentName === suggestion.componentName && s.fix === suggestion.fix
|
|
7396
|
-
)
|
|
7928
|
+
);
|
|
7929
|
+
if (index === -1) {
|
|
7397
7930
|
session.suggestions.push(suggestion);
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7931
|
+
} else {
|
|
7932
|
+
session.suggestions[index] = suggestion;
|
|
7933
|
+
}
|
|
7934
|
+
if (session.tui) {
|
|
7935
|
+
session.tui.update({ suggestions: session.suggestions });
|
|
7401
7936
|
}
|
|
7402
7937
|
});
|
|
7403
7938
|
scanner.on("fps-drop", (fps) => {
|
|
7404
7939
|
if (session.options.verbose) {
|
|
7405
|
-
|
|
7940
|
+
logger5.warn(`FPS dropped to ${fps}`);
|
|
7406
7941
|
}
|
|
7407
7942
|
});
|
|
7408
7943
|
scanner.on("severityChange", ({ component, to }) => {
|
|
7409
7944
|
if (session.options.verbose && to === "critical") {
|
|
7410
|
-
|
|
7945
|
+
logger5.warn(`Component ${component} reached critical severity`);
|
|
7411
7946
|
}
|
|
7412
7947
|
});
|
|
7413
7948
|
}
|
|
@@ -7423,17 +7958,15 @@ function setupTUIEvents(session) {
|
|
|
7423
7958
|
tui.update({ paused: false });
|
|
7424
7959
|
}
|
|
7425
7960
|
});
|
|
7426
|
-
tui.on("generateReport",
|
|
7961
|
+
tui.on("generateReport", () => {
|
|
7427
7962
|
const report = generateReport(session);
|
|
7428
|
-
|
|
7963
|
+
saveReport(report, session.options).catch((error) => {
|
|
7964
|
+
logger5.error("Failed to save report:", error instanceof Error ? error.message : String(error));
|
|
7965
|
+
});
|
|
7429
7966
|
});
|
|
7430
7967
|
tui.on("selectComponent", (component) => {
|
|
7431
|
-
|
|
7432
|
-
session.suggestions.
|
|
7433
|
-
(s) => !session.suggestions.some(
|
|
7434
|
-
(ex) => ex.componentName === s.componentName && ex.fix === s.fix
|
|
7435
|
-
)
|
|
7436
|
-
));
|
|
7968
|
+
scanner.analyzeComponent(component.name);
|
|
7969
|
+
session.suggestions = scanner.getSuggestions();
|
|
7437
7970
|
tui.update({ suggestions: session.suggestions });
|
|
7438
7971
|
});
|
|
7439
7972
|
tui.on("toggleOverlay", () => {
|
|
@@ -7472,8 +8005,10 @@ async function waitForSignal() {
|
|
|
7472
8005
|
});
|
|
7473
8006
|
}
|
|
7474
8007
|
function generateReport(session) {
|
|
7475
|
-
const { scanner, options, chains
|
|
8008
|
+
const { scanner, options, chains } = session;
|
|
7476
8009
|
const exported = scanner.export();
|
|
8010
|
+
const suggestions = exported.suggestions;
|
|
8011
|
+
session.suggestions = suggestions;
|
|
7477
8012
|
const sessionInfo = {
|
|
7478
8013
|
url: options.target,
|
|
7479
8014
|
duration: scanner.getSessionDuration(),
|
|
@@ -7481,7 +8016,7 @@ function generateReport(session) {
|
|
|
7481
8016
|
id: session.id
|
|
7482
8017
|
};
|
|
7483
8018
|
return {
|
|
7484
|
-
version:
|
|
8019
|
+
version: VERSION,
|
|
7485
8020
|
generated: formatDate(),
|
|
7486
8021
|
session: sessionInfo,
|
|
7487
8022
|
summary: exported.stats.summary,
|
|
@@ -7495,13 +8030,13 @@ function generateReport(session) {
|
|
|
7495
8030
|
};
|
|
7496
8031
|
}
|
|
7497
8032
|
async function saveReport(report, options) {
|
|
7498
|
-
const { ensureDir: ensureDir2, writeTextFile: writeTextFile2, joinPath:
|
|
8033
|
+
const { ensureDir: ensureDir2, writeTextFile: writeTextFile2, joinPath: joinPath3 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
7499
8034
|
const { generateHTMLReport: generateHTMLReport2 } = await Promise.resolve().then(() => (init_html(), html_exports));
|
|
7500
8035
|
const { generateJSONReport: generateJSONReport2 } = await Promise.resolve().then(() => (init_json(), json_exports));
|
|
7501
8036
|
const { generateMarkdownReport: generateMarkdownReport2 } = await Promise.resolve().then(() => (init_markdown(), markdown_exports));
|
|
7502
8037
|
await ensureDir2(options.output);
|
|
7503
8038
|
const timestamp = Date.now();
|
|
7504
|
-
const formats = options.
|
|
8039
|
+
const formats = options.formats;
|
|
7505
8040
|
for (const format of formats) {
|
|
7506
8041
|
let content;
|
|
7507
8042
|
let extension;
|
|
@@ -7522,9 +8057,9 @@ async function saveReport(report, options) {
|
|
|
7522
8057
|
continue;
|
|
7523
8058
|
}
|
|
7524
8059
|
const filename = `reactcheck-report-${timestamp}.${extension}`;
|
|
7525
|
-
const filepath =
|
|
8060
|
+
const filepath = joinPath3(options.output, filename);
|
|
7526
8061
|
await writeTextFile2(filepath, content);
|
|
7527
|
-
|
|
8062
|
+
logger5.info(`Report saved: ${filepath}`);
|
|
7528
8063
|
}
|
|
7529
8064
|
}
|
|
7530
8065
|
function printSummary(session) {
|
|
@@ -7614,39 +8149,39 @@ function openBrowser(url) {
|
|
|
7614
8149
|
}
|
|
7615
8150
|
exec(command, (error) => {
|
|
7616
8151
|
if (error) {
|
|
7617
|
-
|
|
8152
|
+
logger5.debug(`Failed to open browser: ${error.message}`);
|
|
7618
8153
|
}
|
|
7619
8154
|
});
|
|
7620
8155
|
}
|
|
7621
8156
|
|
|
7622
8157
|
// src/cli/commands/init.ts
|
|
7623
8158
|
init_fs();
|
|
7624
|
-
var
|
|
8159
|
+
var logger6 = new Logger({ prefix: "init", level: 1 /* INFO */ });
|
|
7625
8160
|
var DEFAULT_CONFIG_NAME = "reactcheck.config.js";
|
|
7626
8161
|
async function runInitCommand(args) {
|
|
7627
8162
|
const configPath = args.positional[0] ?? DEFAULT_CONFIG_NAME;
|
|
7628
8163
|
if (await exists(configPath)) {
|
|
7629
|
-
|
|
8164
|
+
logger6.warn(`Config file already exists: ${configPath}`);
|
|
7630
8165
|
try {
|
|
7631
8166
|
const content2 = await readTextFile(configPath);
|
|
7632
8167
|
if (configPath.endsWith(".json")) {
|
|
7633
8168
|
const config = JSON.parse(content2);
|
|
7634
8169
|
const errors = validateConfig(config);
|
|
7635
8170
|
if (errors.length > 0) {
|
|
7636
|
-
|
|
8171
|
+
logger6.warn("Existing config has validation errors:");
|
|
7637
8172
|
for (const error of errors) {
|
|
7638
|
-
|
|
8173
|
+
logger6.warn(` - ${error}`);
|
|
7639
8174
|
}
|
|
7640
8175
|
} else {
|
|
7641
|
-
|
|
8176
|
+
logger6.info("Existing config is valid.");
|
|
7642
8177
|
}
|
|
7643
8178
|
}
|
|
7644
8179
|
} catch (error) {
|
|
7645
|
-
|
|
8180
|
+
logger6.warn("Could not validate existing config:", error);
|
|
7646
8181
|
}
|
|
7647
8182
|
console.log("");
|
|
7648
8183
|
console.log(colors.yellow + "? Overwrite existing config? (y/N) " + colors.reset);
|
|
7649
|
-
|
|
8184
|
+
logger6.info("To overwrite, delete the existing file and run init again.");
|
|
7650
8185
|
return 0;
|
|
7651
8186
|
}
|
|
7652
8187
|
const format = configPath.endsWith(".json") ? "json" : "js";
|
|
@@ -7672,10 +8207,355 @@ async function runInitCommand(args) {
|
|
|
7672
8207
|
console.log("");
|
|
7673
8208
|
return 0;
|
|
7674
8209
|
} catch (error) {
|
|
7675
|
-
|
|
8210
|
+
logger6.error(`Failed to create config file:`, error);
|
|
7676
8211
|
return 1;
|
|
7677
8212
|
}
|
|
7678
8213
|
}
|
|
8214
|
+
|
|
8215
|
+
// src/detect/framework.ts
|
|
8216
|
+
init_fs();
|
|
8217
|
+
var VITE_CONFIG_FILES = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs", "vite.config.cts", "vite.config.cjs"];
|
|
8218
|
+
var VITE_SSR_ENTRIES = ["entry-server.tsx", "entry-server.ts", "entry-server.jsx", "entry-server.js"];
|
|
8219
|
+
async function detectViteSSR(pkg, dir) {
|
|
8220
|
+
if (Object.values(pkg.scripts ?? {}).some((script) => /(^|\s)--ssr(\s|=|$)/.test(script))) {
|
|
8221
|
+
return true;
|
|
8222
|
+
}
|
|
8223
|
+
for (const file of VITE_CONFIG_FILES) {
|
|
8224
|
+
const path = joinPath(dir, file);
|
|
8225
|
+
if (await exists(path)) {
|
|
8226
|
+
try {
|
|
8227
|
+
const source = (await readTextFile(path)).replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "");
|
|
8228
|
+
if (/\bssr\s*:/.test(source)) return true;
|
|
8229
|
+
} catch {
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
}
|
|
8233
|
+
for (const entry of VITE_SSR_ENTRIES) {
|
|
8234
|
+
if (await exists(joinPath(dir, "src", entry)) || await exists(joinPath(dir, entry))) {
|
|
8235
|
+
return true;
|
|
8236
|
+
}
|
|
8237
|
+
}
|
|
8238
|
+
return false;
|
|
8239
|
+
}
|
|
8240
|
+
var FRAMEWORK_DETECTORS = [
|
|
8241
|
+
// Next.js
|
|
8242
|
+
{
|
|
8243
|
+
name: "next",
|
|
8244
|
+
dependencies: ["next"],
|
|
8245
|
+
features: [
|
|
8246
|
+
{
|
|
8247
|
+
name: "app-router",
|
|
8248
|
+
detect: async (_, dir) => exists(joinPath(dir, "app"))
|
|
8249
|
+
},
|
|
8250
|
+
{
|
|
8251
|
+
name: "pages-router",
|
|
8252
|
+
detect: async (_, dir) => exists(joinPath(dir, "pages"))
|
|
8253
|
+
},
|
|
8254
|
+
{
|
|
8255
|
+
name: "rsc",
|
|
8256
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["next"]) >= 13)
|
|
8257
|
+
},
|
|
8258
|
+
{
|
|
8259
|
+
name: "middleware",
|
|
8260
|
+
detect: async (_, dir) => await exists(joinPath(dir, "middleware.ts")) || await exists(joinPath(dir, "middleware.js"))
|
|
8261
|
+
}
|
|
8262
|
+
],
|
|
8263
|
+
tips: [
|
|
8264
|
+
'Use "use client" directive only for interactive components',
|
|
8265
|
+
"Keep server components as the default for better performance",
|
|
8266
|
+
"Consider using Server Actions for mutations",
|
|
8267
|
+
"Use next/dynamic for code splitting heavy components",
|
|
8268
|
+
"Avoid passing serializable props through server/client boundary"
|
|
8269
|
+
]
|
|
8270
|
+
},
|
|
8271
|
+
// Remix
|
|
8272
|
+
{
|
|
8273
|
+
name: "remix",
|
|
8274
|
+
dependencies: ["@remix-run/react", "@remix-run/node", "@remix-run/cloudflare"],
|
|
8275
|
+
features: [
|
|
8276
|
+
{
|
|
8277
|
+
name: "v2-routes",
|
|
8278
|
+
detect: async (_, dir) => exists(joinPath(dir, "app", "routes"))
|
|
8279
|
+
},
|
|
8280
|
+
{
|
|
8281
|
+
name: "defer",
|
|
8282
|
+
deps: ["@remix-run/react"],
|
|
8283
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["@remix-run/react"]) >= 1)
|
|
8284
|
+
}
|
|
8285
|
+
],
|
|
8286
|
+
tips: [
|
|
8287
|
+
"Use loader data efficiently to minimize client state",
|
|
8288
|
+
"Prefer fetcher over useNavigate for non-navigation mutations",
|
|
8289
|
+
"Use defer for streaming slow data",
|
|
8290
|
+
"Consider using useFetcher.load for background data fetching",
|
|
8291
|
+
"Avoid useEffect for data fetching, use loaders instead"
|
|
8292
|
+
]
|
|
8293
|
+
},
|
|
8294
|
+
// Vite
|
|
8295
|
+
{
|
|
8296
|
+
name: "vite",
|
|
8297
|
+
dependencies: [],
|
|
8298
|
+
devDependencies: ["vite"],
|
|
8299
|
+
features: [
|
|
8300
|
+
{
|
|
8301
|
+
name: "react-plugin",
|
|
8302
|
+
deps: ["@vitejs/plugin-react", "@vitejs/plugin-react-swc"]
|
|
8303
|
+
},
|
|
8304
|
+
{
|
|
8305
|
+
name: "ssr",
|
|
8306
|
+
deps: ["vike", "vite-plugin-ssr"],
|
|
8307
|
+
detect: detectViteSSR
|
|
8308
|
+
}
|
|
8309
|
+
],
|
|
8310
|
+
tips: [
|
|
8311
|
+
"Use React.lazy with Suspense for code splitting",
|
|
8312
|
+
"Configure build.rollupOptions.output.manualChunks for optimal chunking",
|
|
8313
|
+
"Enable build.sourcemap only in development",
|
|
8314
|
+
"Use @vitejs/plugin-react-swc for faster builds",
|
|
8315
|
+
"Consider using vite-plugin-pwa for PWA support"
|
|
8316
|
+
]
|
|
8317
|
+
},
|
|
8318
|
+
// Create React App
|
|
8319
|
+
{
|
|
8320
|
+
name: "cra",
|
|
8321
|
+
dependencies: ["react-scripts"],
|
|
8322
|
+
features: [
|
|
8323
|
+
{
|
|
8324
|
+
name: "typescript",
|
|
8325
|
+
deps: ["typescript"]
|
|
8326
|
+
},
|
|
8327
|
+
{
|
|
8328
|
+
name: "testing-library",
|
|
8329
|
+
deps: ["@testing-library/react"]
|
|
8330
|
+
}
|
|
8331
|
+
],
|
|
8332
|
+
tips: [
|
|
8333
|
+
"Consider migrating to Vite for faster development builds",
|
|
8334
|
+
"Use React.lazy for code splitting",
|
|
8335
|
+
'Run "npm run build -- --stats" to analyze bundle size',
|
|
8336
|
+
"Use REACT_APP_ prefix for environment variables",
|
|
8337
|
+
"Consider ejecting only if absolutely necessary"
|
|
8338
|
+
]
|
|
8339
|
+
},
|
|
8340
|
+
// Gatsby
|
|
8341
|
+
{
|
|
8342
|
+
name: "gatsby",
|
|
8343
|
+
dependencies: ["gatsby"],
|
|
8344
|
+
features: [
|
|
8345
|
+
{
|
|
8346
|
+
name: "v5",
|
|
8347
|
+
detect: (pkg) => Promise.resolve(getMajorVersion(pkg.dependencies?.["gatsby"]) >= 5)
|
|
8348
|
+
},
|
|
8349
|
+
{
|
|
8350
|
+
name: "image",
|
|
8351
|
+
deps: ["gatsby-plugin-image"]
|
|
8352
|
+
},
|
|
8353
|
+
{
|
|
8354
|
+
name: "graphql",
|
|
8355
|
+
deps: ["gatsby"]
|
|
8356
|
+
}
|
|
8357
|
+
],
|
|
8358
|
+
tips: [
|
|
8359
|
+
"Use gatsby-plugin-image for optimized images",
|
|
8360
|
+
"Prefer StaticQuery over page queries for reusable components",
|
|
8361
|
+
"Use incremental builds for faster development",
|
|
8362
|
+
"Configure proper caching headers for static assets",
|
|
8363
|
+
"Consider using DSG (Deferred Static Generation) for large sites"
|
|
8364
|
+
]
|
|
8365
|
+
}
|
|
8366
|
+
];
|
|
8367
|
+
function getMajorVersion(range) {
|
|
8368
|
+
if (typeof range !== "string") return Number.NaN;
|
|
8369
|
+
const match = /(\d+)(?:\.\d+)*/.exec(range);
|
|
8370
|
+
return match?.[1] !== void 0 ? parseInt(match[1], 10) : Number.NaN;
|
|
8371
|
+
}
|
|
8372
|
+
async function detectFramework(packageJsonPath) {
|
|
8373
|
+
let pkgPath = packageJsonPath;
|
|
8374
|
+
if (!pkgPath) {
|
|
8375
|
+
pkgPath = await findUp("package.json") ?? void 0;
|
|
8376
|
+
}
|
|
8377
|
+
if (!pkgPath || !await exists(pkgPath)) {
|
|
8378
|
+
return null;
|
|
8379
|
+
}
|
|
8380
|
+
let packageJson;
|
|
8381
|
+
try {
|
|
8382
|
+
packageJson = await readJsonFile(pkgPath);
|
|
8383
|
+
} catch {
|
|
8384
|
+
return null;
|
|
8385
|
+
}
|
|
8386
|
+
const projectDir = getDirName(pkgPath);
|
|
8387
|
+
for (const detector of FRAMEWORK_DETECTORS) {
|
|
8388
|
+
const match = await matchFramework(detector, packageJson, projectDir);
|
|
8389
|
+
if (match) {
|
|
8390
|
+
return match;
|
|
8391
|
+
}
|
|
8392
|
+
}
|
|
8393
|
+
return {
|
|
8394
|
+
name: "unknown",
|
|
8395
|
+
version: "",
|
|
8396
|
+
features: [],
|
|
8397
|
+
tips: [
|
|
8398
|
+
"Consider using React.memo for frequently re-rendering components",
|
|
8399
|
+
"Use useCallback for event handlers passed to child components",
|
|
8400
|
+
"Use useMemo for expensive computations",
|
|
8401
|
+
"Avoid inline object/array creation in render"
|
|
8402
|
+
]
|
|
8403
|
+
};
|
|
8404
|
+
}
|
|
8405
|
+
async function matchFramework(detector, packageJson, projectDir) {
|
|
8406
|
+
const allDeps = {
|
|
8407
|
+
...packageJson.dependencies,
|
|
8408
|
+
...packageJson.devDependencies
|
|
8409
|
+
};
|
|
8410
|
+
const mainDep = detector.dependencies.find((dep) => dep in allDeps) ?? detector.devDependencies?.find((dep) => dep in (packageJson.devDependencies ?? {}));
|
|
8411
|
+
if (!mainDep) {
|
|
8412
|
+
return null;
|
|
8413
|
+
}
|
|
8414
|
+
const rawVersion = allDeps[mainDep];
|
|
8415
|
+
const version = typeof rawVersion === "string" ? rawVersion.replace(/[\^~]/g, "") : "unknown";
|
|
8416
|
+
const features = [];
|
|
8417
|
+
for (const feature of detector.features) {
|
|
8418
|
+
let detected = false;
|
|
8419
|
+
if (feature.deps) {
|
|
8420
|
+
detected = feature.deps.some((dep) => dep in allDeps);
|
|
8421
|
+
}
|
|
8422
|
+
if (feature.files && !detected) {
|
|
8423
|
+
for (const file of feature.files) {
|
|
8424
|
+
if (await exists(joinPath(projectDir, file))) {
|
|
8425
|
+
detected = true;
|
|
8426
|
+
break;
|
|
8427
|
+
}
|
|
8428
|
+
}
|
|
8429
|
+
}
|
|
8430
|
+
if (feature.detect && !detected) {
|
|
8431
|
+
try {
|
|
8432
|
+
detected = await feature.detect(packageJson, projectDir);
|
|
8433
|
+
} catch {
|
|
8434
|
+
}
|
|
8435
|
+
}
|
|
8436
|
+
if (detected) {
|
|
8437
|
+
features.push(feature.name);
|
|
8438
|
+
}
|
|
8439
|
+
}
|
|
8440
|
+
return {
|
|
8441
|
+
name: detector.name,
|
|
8442
|
+
version,
|
|
8443
|
+
features,
|
|
8444
|
+
tips: detector.tips
|
|
8445
|
+
};
|
|
8446
|
+
}
|
|
8447
|
+
|
|
8448
|
+
// src/cli/commands/detect.ts
|
|
8449
|
+
init_fs();
|
|
8450
|
+
var logger7 = new Logger({ prefix: "detect", level: 1 /* INFO */ });
|
|
8451
|
+
async function runDetectCommand(args) {
|
|
8452
|
+
const target = resolvePath(process.cwd(), args.positional[0] ?? ".");
|
|
8453
|
+
const pkgPath = await isDirectory(target) ? joinPath(target, "package.json") : target;
|
|
8454
|
+
if (!await exists(pkgPath)) {
|
|
8455
|
+
logger7.error(`No package.json found at ${pkgPath}`);
|
|
8456
|
+
return 2;
|
|
8457
|
+
}
|
|
8458
|
+
const framework = await detectFramework(pkgPath);
|
|
8459
|
+
if (!framework) {
|
|
8460
|
+
logger7.error(`Could not read ${pkgPath}`);
|
|
8461
|
+
return 2;
|
|
8462
|
+
}
|
|
8463
|
+
if (getBooleanFlag(args, "json")) {
|
|
8464
|
+
console.log(JSON.stringify(framework, null, 2));
|
|
8465
|
+
return 0;
|
|
8466
|
+
}
|
|
8467
|
+
const name = framework.name === "unknown" ? "No known React framework" : framework.name;
|
|
8468
|
+
const version = framework.version ? ` ${framework.version}` : "";
|
|
8469
|
+
console.log(`${colors.bold}Framework:${colors.reset} ${name}${version}`);
|
|
8470
|
+
if (framework.features.length > 0) {
|
|
8471
|
+
console.log(`${colors.bold}Features:${colors.reset} ${framework.features.join(", ")}`);
|
|
8472
|
+
}
|
|
8473
|
+
if (framework.tips.length > 0) {
|
|
8474
|
+
console.log(`${colors.bold}Tips:${colors.reset}`);
|
|
8475
|
+
for (const tip of framework.tips) {
|
|
8476
|
+
console.log(` - ${tip}`);
|
|
8477
|
+
}
|
|
8478
|
+
}
|
|
8479
|
+
return 0;
|
|
8480
|
+
}
|
|
8481
|
+
|
|
8482
|
+
// src/cli/commands/report.ts
|
|
8483
|
+
init_json();
|
|
8484
|
+
|
|
8485
|
+
// src/report/index.ts
|
|
8486
|
+
init_json();
|
|
8487
|
+
init_markdown();
|
|
8488
|
+
init_html();
|
|
8489
|
+
init_json();
|
|
8490
|
+
init_markdown();
|
|
8491
|
+
init_html();
|
|
8492
|
+
init_fs();
|
|
8493
|
+
function generateReport2(report, format) {
|
|
8494
|
+
switch (format) {
|
|
8495
|
+
case "html":
|
|
8496
|
+
return generateHTMLReport(report);
|
|
8497
|
+
case "json":
|
|
8498
|
+
return generateJSONReport(report);
|
|
8499
|
+
case "md":
|
|
8500
|
+
return generateMarkdownReport(report);
|
|
8501
|
+
default:
|
|
8502
|
+
throw new Error(`Unknown report format: ${String(format)}`);
|
|
8503
|
+
}
|
|
8504
|
+
}
|
|
8505
|
+
async function saveReport2(report, format, outputDir, filename) {
|
|
8506
|
+
await ensureDir(outputDir);
|
|
8507
|
+
const baseName = filename ?? `reactcheck-report-${Date.now()}`;
|
|
8508
|
+
const extension = format === "md" ? "md" : format;
|
|
8509
|
+
const filePath = joinPath(outputDir, `${baseName}.${extension}`);
|
|
8510
|
+
const content = generateReport2(report, format);
|
|
8511
|
+
await writeTextFile(filePath, content);
|
|
8512
|
+
return filePath;
|
|
8513
|
+
}
|
|
8514
|
+
|
|
8515
|
+
// src/cli/commands/report.ts
|
|
8516
|
+
init_fs();
|
|
8517
|
+
var logger8 = new Logger({ prefix: "report", level: 1 /* INFO */ });
|
|
8518
|
+
async function runReportCommand(args) {
|
|
8519
|
+
const input = args.positional[0];
|
|
8520
|
+
if (!input) {
|
|
8521
|
+
logger8.error("Input JSON report path is required: react-check report <file.json>");
|
|
8522
|
+
return 2;
|
|
8523
|
+
}
|
|
8524
|
+
let content;
|
|
8525
|
+
try {
|
|
8526
|
+
content = await readTextFile(input);
|
|
8527
|
+
} catch (error) {
|
|
8528
|
+
logger8.error(`Cannot read ${input}: ${error instanceof Error ? error.message : String(error)}`);
|
|
8529
|
+
return 2;
|
|
8530
|
+
}
|
|
8531
|
+
let report;
|
|
8532
|
+
try {
|
|
8533
|
+
report = parseJSONReport(content);
|
|
8534
|
+
} catch (error) {
|
|
8535
|
+
logger8.error(`${input} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
8536
|
+
return 2;
|
|
8537
|
+
}
|
|
8538
|
+
const errors = validateJSONReport(report);
|
|
8539
|
+
if (errors.length > 0) {
|
|
8540
|
+
logger8.error(`${input} is not a ReactCheck JSON report:`);
|
|
8541
|
+
for (const error of errors) {
|
|
8542
|
+
logger8.error(` - ${error}`);
|
|
8543
|
+
}
|
|
8544
|
+
return 2;
|
|
8545
|
+
}
|
|
8546
|
+
report.chains = Array.isArray(report.chains) ? report.chains : [];
|
|
8547
|
+
report.suggestions = Array.isArray(report.suggestions) ? report.suggestions : [];
|
|
8548
|
+
report.timeline = Array.isArray(report.timeline) ? report.timeline : [];
|
|
8549
|
+
report.framework = report.framework ?? null;
|
|
8550
|
+
const formats = parseFormatList(getStringFlag(args, "format") ?? "all");
|
|
8551
|
+
const output = getStringFlag(args, "output") ?? "./reactcheck-reports";
|
|
8552
|
+
const baseName = getBaseName(input);
|
|
8553
|
+
for (const format of formats) {
|
|
8554
|
+
const path = await saveReport2(report, format, output, baseName);
|
|
8555
|
+
logger8.info(`Report saved: ${path}`);
|
|
8556
|
+
}
|
|
8557
|
+
return 0;
|
|
8558
|
+
}
|
|
7679
8559
|
var InteractiveWizard = class {
|
|
7680
8560
|
rl;
|
|
7681
8561
|
constructor() {
|
|
@@ -8053,23 +8933,30 @@ async function runInteractiveWizard() {
|
|
|
8053
8933
|
}
|
|
8054
8934
|
|
|
8055
8935
|
// src/cli/index.ts
|
|
8056
|
-
var
|
|
8057
|
-
var VERSION = "1.1.6";
|
|
8936
|
+
var logger9 = new Logger({ prefix: "ReactCheck", level: 1 /* INFO */ });
|
|
8058
8937
|
function printVersion() {
|
|
8059
8938
|
console.log(`@oxog/react-check v${VERSION}`);
|
|
8060
8939
|
}
|
|
8061
8940
|
function printHelp() {
|
|
8062
8941
|
console.log(getHelpText());
|
|
8063
8942
|
}
|
|
8943
|
+
function getBannerText() {
|
|
8944
|
+
const title = "ReactCheck";
|
|
8945
|
+
const tagline = " - Scan, diagnose, and fix React performance issues";
|
|
8946
|
+
const inner = 3 + title.length + tagline.length + 3;
|
|
8947
|
+
const blank = `\u2551${" ".repeat(inner)}\u2551`;
|
|
8948
|
+
return [
|
|
8949
|
+
"",
|
|
8950
|
+
`${colors.cyan}\u2554${"\u2550".repeat(inner)}\u2557`,
|
|
8951
|
+
blank,
|
|
8952
|
+
`\u2551 ${colors.bold}${title}${colors.reset}${colors.cyan}${tagline} \u2551`,
|
|
8953
|
+
blank,
|
|
8954
|
+
`\u255A${"\u2550".repeat(inner)}\u255D${colors.reset}`,
|
|
8955
|
+
""
|
|
8956
|
+
].join("\n");
|
|
8957
|
+
}
|
|
8064
8958
|
function printBanner() {
|
|
8065
|
-
|
|
8066
|
-
${colors.cyan}\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
|
|
8067
|
-
\u2551 \u2551
|
|
8068
|
-
\u2551 ${colors.bold}ReactCheck${colors.reset}${colors.cyan} - Scan, diagnose, and fix React performance \u2551
|
|
8069
|
-
\u2551 \u2551
|
|
8070
|
-
\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\u2550\u2550\u2550\u2550\u255D${colors.reset}
|
|
8071
|
-
`;
|
|
8072
|
-
console.log(banner);
|
|
8959
|
+
console.log(getBannerText());
|
|
8073
8960
|
}
|
|
8074
8961
|
var CLI = class {
|
|
8075
8962
|
/** Raw arguments */
|
|
@@ -8088,9 +8975,7 @@ var CLI = class {
|
|
|
8088
8975
|
*/
|
|
8089
8976
|
wizardConfigToArgs(config) {
|
|
8090
8977
|
const flags = /* @__PURE__ */ new Map();
|
|
8091
|
-
if (config.mode === "
|
|
8092
|
-
flags.set("tui", true);
|
|
8093
|
-
} else if (config.mode === "webui") {
|
|
8978
|
+
if (config.mode === "webui") {
|
|
8094
8979
|
flags.set("webui", true);
|
|
8095
8980
|
flags.set("webui-port", String(config.webuiPort));
|
|
8096
8981
|
} else if (config.mode === "headless") {
|
|
@@ -8119,7 +9004,8 @@ var CLI = class {
|
|
|
8119
9004
|
target: config.url,
|
|
8120
9005
|
flags,
|
|
8121
9006
|
positional: [],
|
|
8122
|
-
raw: []
|
|
9007
|
+
raw: [],
|
|
9008
|
+
provided: new Set(flags.keys())
|
|
8123
9009
|
};
|
|
8124
9010
|
}
|
|
8125
9011
|
/**
|
|
@@ -8140,8 +9026,19 @@ var CLI = class {
|
|
|
8140
9026
|
case "init":
|
|
8141
9027
|
printBanner();
|
|
8142
9028
|
return await runInitCommand(args);
|
|
9029
|
+
case "detect":
|
|
9030
|
+
case "report": {
|
|
9031
|
+
const errors = validateArgs(args);
|
|
9032
|
+
if (errors.length > 0) {
|
|
9033
|
+
for (const error of errors) {
|
|
9034
|
+
logger9.error(error);
|
|
9035
|
+
}
|
|
9036
|
+
return 2;
|
|
9037
|
+
}
|
|
9038
|
+
return args.command === "detect" ? await runDetectCommand(args) : await runReportCommand(args);
|
|
9039
|
+
}
|
|
8143
9040
|
case "scan":
|
|
8144
|
-
default:
|
|
9041
|
+
default: {
|
|
8145
9042
|
if (!args.target && args.raw.length === 0 && process.stdin.isTTY) {
|
|
8146
9043
|
printBanner();
|
|
8147
9044
|
const wizardConfig = await runInteractiveWizard();
|
|
@@ -8154,16 +9051,17 @@ var CLI = class {
|
|
|
8154
9051
|
const errors = validateArgs(args);
|
|
8155
9052
|
if (errors.length > 0) {
|
|
8156
9053
|
for (const error of errors) {
|
|
8157
|
-
|
|
9054
|
+
logger9.error(error);
|
|
8158
9055
|
}
|
|
8159
9056
|
console.log("");
|
|
8160
9057
|
console.log("Run " + colors.cyan + "react-check --help" + colors.reset + " for usage information.");
|
|
8161
9058
|
return 2;
|
|
8162
9059
|
}
|
|
8163
9060
|
return await runScanCommand(args);
|
|
9061
|
+
}
|
|
8164
9062
|
}
|
|
8165
9063
|
} catch (error) {
|
|
8166
|
-
|
|
9064
|
+
logger9.error("Unexpected error:", error);
|
|
8167
9065
|
return 1;
|
|
8168
9066
|
}
|
|
8169
9067
|
}
|
|
@@ -8188,6 +9086,6 @@ if (!process.env.VITEST) {
|
|
|
8188
9086
|
});
|
|
8189
9087
|
}
|
|
8190
9088
|
|
|
8191
|
-
export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
|
|
9089
|
+
export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getBannerText, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
|
|
8192
9090
|
//# sourceMappingURL=cli.js.map
|
|
8193
9091
|
//# sourceMappingURL=cli.js.map
|