@oxog/react-check 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +9 -3
- package/dist/browser-inject.global.js +705 -158
- package/dist/chain.d.cts +1 -1
- package/dist/chain.d.ts +1 -1
- package/dist/cli.js +510 -32
- package/dist/cli.js.map +1 -1
- package/dist/detect.d.cts +1 -1
- package/dist/detect.d.ts +1 -1
- package/dist/fix.d.cts +1 -1
- package/dist/fix.d.ts +1 -1
- package/dist/index.cjs +1124 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -43
- package/dist/index.d.ts +94 -43
- package/dist/index.js +1124 -303
- package/dist/index.js.map +1 -1
- package/dist/{scanner-CTBraprQ.d.ts → scanner-Cc2187fH.d.ts} +1 -1
- package/dist/{scanner-5j2LEM-q.d.cts → scanner-S7BtVIpW.d.cts} +1 -1
- package/dist/scanner.d.cts +2 -2
- package/dist/scanner.d.ts +2 -2
- package/dist/{types-xAXT9cir.d.cts → types-DuZyBVVV.d.cts} +1 -1
- package/dist/{types-xAXT9cir.d.ts → types-DuZyBVVV.d.ts} +1 -1
- package/package.json +7 -5
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createServer } from 'http';
|
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { exec, execSync } from 'child_process';
|
|
9
|
+
import * as readline from 'readline';
|
|
9
10
|
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -1210,7 +1211,7 @@ var FLAG_DEFINITIONS = {
|
|
|
1210
1211
|
"webui-port": {
|
|
1211
1212
|
description: "WebUI dashboard port",
|
|
1212
1213
|
takesValue: true,
|
|
1213
|
-
default: "
|
|
1214
|
+
default: "3199"
|
|
1214
1215
|
}
|
|
1215
1216
|
};
|
|
1216
1217
|
function buildShortFlagMap() {
|
|
@@ -2705,16 +2706,16 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2705
2706
|
this.parentMap.set(render.componentName, parent);
|
|
2706
2707
|
}
|
|
2707
2708
|
const windowKey = this.getWindowKey(render.timestamp);
|
|
2708
|
-
let
|
|
2709
|
-
if (!
|
|
2710
|
-
|
|
2709
|
+
let window2 = this.windows.get(windowKey);
|
|
2710
|
+
if (!window2) {
|
|
2711
|
+
window2 = {
|
|
2711
2712
|
renders: [],
|
|
2712
2713
|
startTime: render.timestamp
|
|
2713
2714
|
};
|
|
2714
|
-
this.windows.set(windowKey,
|
|
2715
|
+
this.windows.set(windowKey, window2);
|
|
2715
2716
|
}
|
|
2716
|
-
|
|
2717
|
-
if (
|
|
2717
|
+
window2.renders.push(trackedRender);
|
|
2718
|
+
if (window2.renders.length >= this.minChainDepth) {
|
|
2718
2719
|
this.analyzeWindow(windowKey);
|
|
2719
2720
|
}
|
|
2720
2721
|
this.cleanupWindows(render.timestamp);
|
|
@@ -2748,11 +2749,11 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2748
2749
|
* @param windowKey - Window key to analyze
|
|
2749
2750
|
*/
|
|
2750
2751
|
analyzeWindow(windowKey) {
|
|
2751
|
-
const
|
|
2752
|
-
if (!
|
|
2752
|
+
const window2 = this.windows.get(windowKey);
|
|
2753
|
+
if (!window2 || window2.renders.length < this.minChainDepth) {
|
|
2753
2754
|
return;
|
|
2754
2755
|
}
|
|
2755
|
-
const sortedRenders = [...
|
|
2756
|
+
const sortedRenders = [...window2.renders].sort((a, b) => a.timestamp - b.timestamp);
|
|
2756
2757
|
const chains = this.buildChains(sortedRenders);
|
|
2757
2758
|
for (const chain of chains) {
|
|
2758
2759
|
const chainKey = this.getChainKey(chain);
|
|
@@ -2889,8 +2890,8 @@ var ChainAnalyzer = class extends EventEmitter {
|
|
|
2889
2890
|
*/
|
|
2890
2891
|
cleanupWindows(currentTime) {
|
|
2891
2892
|
const cutoff = currentTime - this.windowSize * 10;
|
|
2892
|
-
for (const [key,
|
|
2893
|
-
if (
|
|
2893
|
+
for (const [key, window2] of this.windows) {
|
|
2894
|
+
if (window2.startTime < cutoff) {
|
|
2894
2895
|
this.windows.delete(key);
|
|
2895
2896
|
}
|
|
2896
2897
|
}
|
|
@@ -5623,12 +5624,10 @@ var BrowserLauncher = class extends EventEmitter {
|
|
|
5623
5624
|
this.page = pages[0] ?? await this.browser.newPage();
|
|
5624
5625
|
this.setupPageHandlers();
|
|
5625
5626
|
if (this.injectionScript) {
|
|
5627
|
+
logger3.debug("Injecting ReactCheck script into page...");
|
|
5626
5628
|
await this.page.evaluateOnNewDocument(this.injectionScript);
|
|
5629
|
+
logger3.debug("Injection script registered");
|
|
5627
5630
|
}
|
|
5628
|
-
const wsPort = this.options.wsPort;
|
|
5629
|
-
await this.page.evaluateOnNewDocument(`
|
|
5630
|
-
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
5631
|
-
`);
|
|
5632
5631
|
this.emit("launched", void 0);
|
|
5633
5632
|
logger3.info("Browser launched");
|
|
5634
5633
|
await this.navigate(this.options.url);
|
|
@@ -6797,7 +6796,7 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6797
6796
|
port;
|
|
6798
6797
|
target;
|
|
6799
6798
|
currentState;
|
|
6800
|
-
constructor(port =
|
|
6799
|
+
constructor(port = 3199, target = "") {
|
|
6801
6800
|
super();
|
|
6802
6801
|
this.port = port;
|
|
6803
6802
|
this.target = target;
|
|
@@ -6970,6 +6969,16 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6970
6969
|
updateFps(fps) {
|
|
6971
6970
|
this.currentState.fps = fps;
|
|
6972
6971
|
}
|
|
6972
|
+
/**
|
|
6973
|
+
* Broadcast components to all clients (for batch updates)
|
|
6974
|
+
*/
|
|
6975
|
+
broadcastComponents() {
|
|
6976
|
+
for (const component of this.currentState.components) {
|
|
6977
|
+
this.broadcast({ type: "component-update", payload: component });
|
|
6978
|
+
}
|
|
6979
|
+
}
|
|
6980
|
+
/** Last render broadcast time */
|
|
6981
|
+
lastRenderBroadcast = 0;
|
|
6973
6982
|
/**
|
|
6974
6983
|
* Add render event
|
|
6975
6984
|
*/
|
|
@@ -6978,7 +6987,11 @@ var WebUIServer = class extends EventEmitter {
|
|
|
6978
6987
|
if (this.currentState.recentRenders.length > 50) {
|
|
6979
6988
|
this.currentState.recentRenders.pop();
|
|
6980
6989
|
}
|
|
6981
|
-
|
|
6990
|
+
const now = Date.now();
|
|
6991
|
+
if (now - this.lastRenderBroadcast >= 100) {
|
|
6992
|
+
this.lastRenderBroadcast = now;
|
|
6993
|
+
this.broadcast({ type: "render-event", payload: render });
|
|
6994
|
+
}
|
|
6982
6995
|
}
|
|
6983
6996
|
/**
|
|
6984
6997
|
* Add chain detected
|
|
@@ -7061,21 +7074,26 @@ async function installPuppeteer(wsServer) {
|
|
|
7061
7074
|
}
|
|
7062
7075
|
const args = process.argv.slice(1);
|
|
7063
7076
|
const { spawn } = await import('child_process');
|
|
7077
|
+
const isWindows = process.platform === "win32";
|
|
7064
7078
|
const child = spawn(process.execPath, args, {
|
|
7065
7079
|
stdio: "inherit",
|
|
7066
|
-
env: process.env
|
|
7080
|
+
env: process.env,
|
|
7081
|
+
shell: isWindows,
|
|
7082
|
+
detached: false
|
|
7067
7083
|
});
|
|
7068
7084
|
await new Promise((resolve3) => {
|
|
7069
7085
|
child.on("exit", (code) => {
|
|
7070
7086
|
process.exit(code ?? 0);
|
|
7071
7087
|
});
|
|
7072
|
-
child.on("error", () => {
|
|
7088
|
+
child.on("error", (err) => {
|
|
7089
|
+
console.error("Spawn error:", err);
|
|
7073
7090
|
resolve3();
|
|
7074
7091
|
});
|
|
7075
7092
|
});
|
|
7076
7093
|
return false;
|
|
7077
7094
|
} catch (error) {
|
|
7078
7095
|
console.log("");
|
|
7096
|
+
console.error("Puppeteer installation error:", error);
|
|
7079
7097
|
logger4.error("Failed to install puppeteer automatically.");
|
|
7080
7098
|
logger4.info("Please install it manually: npm install puppeteer");
|
|
7081
7099
|
logger4.info("Or use --proxy mode: react-check scan --proxy <url>");
|
|
@@ -7102,7 +7120,7 @@ function parseScanOptions(args) {
|
|
|
7102
7120
|
watch: getBooleanFlag(args, "watch"),
|
|
7103
7121
|
configPath: getStringFlag(args, "config"),
|
|
7104
7122
|
webui: getBooleanFlag(args, "webui"),
|
|
7105
|
-
webuiPort: getNumberFlag(args, "webui-port") ??
|
|
7123
|
+
webuiPort: getNumberFlag(args, "webui-port") ?? 3199
|
|
7106
7124
|
};
|
|
7107
7125
|
}
|
|
7108
7126
|
async function getInjectionScript(wsPort) {
|
|
@@ -7178,7 +7196,7 @@ async function runScanCommand(args) {
|
|
|
7178
7196
|
browserClients: /* @__PURE__ */ new Set()
|
|
7179
7197
|
};
|
|
7180
7198
|
setupScannerEvents(session);
|
|
7181
|
-
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && process.stdin.isTTY;
|
|
7199
|
+
const useTUI = !mergedOptions.silent && !mergedOptions.proxy && !mergedOptions.webui && process.stdin.isTTY;
|
|
7182
7200
|
if (useTUI) {
|
|
7183
7201
|
session.tui = new TUI(mergedOptions.target);
|
|
7184
7202
|
setupTUIEvents(session);
|
|
@@ -7235,6 +7253,7 @@ async function runScanCommand(args) {
|
|
|
7235
7253
|
const webuiUrl = session.webui.getUrl();
|
|
7236
7254
|
logger4.info(`WebUI dashboard: ${webuiUrl}`);
|
|
7237
7255
|
openBrowser(webuiUrl);
|
|
7256
|
+
logger4.info("WebUI dashboard opened, Puppeteer will open target URL next...");
|
|
7238
7257
|
}
|
|
7239
7258
|
if (mergedOptions.proxy) {
|
|
7240
7259
|
console.log("");
|
|
@@ -7267,16 +7286,36 @@ async function runScanCommand(args) {
|
|
|
7267
7286
|
});
|
|
7268
7287
|
session.browser.setInjectionScript(injectionScript);
|
|
7269
7288
|
session.browser.on("console", ({ type, text }) => {
|
|
7270
|
-
if (text.includes("[ReactCheck]")) {
|
|
7271
|
-
logger4.info(`Browser: ${text}`);
|
|
7289
|
+
if (text.includes("[ReactCheck]") || text.includes("ReactCheck") || type === "error") {
|
|
7290
|
+
logger4.info(`Browser [${type}]: ${text}`);
|
|
7272
7291
|
}
|
|
7273
7292
|
});
|
|
7274
7293
|
session.browser.on("error", (error) => {
|
|
7275
7294
|
logger4.error("Browser error:", error.message);
|
|
7276
7295
|
});
|
|
7277
|
-
logger4.info("Launching browser...");
|
|
7296
|
+
logger4.info("Launching Puppeteer browser for target URL...");
|
|
7278
7297
|
await session.browser.launch();
|
|
7279
|
-
logger4.info("
|
|
7298
|
+
logger4.info("Puppeteer browser launched successfully, now scanning target...");
|
|
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);
|
|
7280
7319
|
}
|
|
7281
7320
|
if (mergedOptions.duration) {
|
|
7282
7321
|
await new Promise((resolve3) => setTimeout(resolve3, mergedOptions.duration * 1e3));
|
|
@@ -7442,7 +7481,7 @@ function generateReport(session) {
|
|
|
7442
7481
|
id: session.id
|
|
7443
7482
|
};
|
|
7444
7483
|
return {
|
|
7445
|
-
version: "1.1.
|
|
7484
|
+
version: "1.1.6",
|
|
7446
7485
|
generated: formatDate(),
|
|
7447
7486
|
session: sessionInfo,
|
|
7448
7487
|
summary: exported.stats.summary,
|
|
@@ -7537,11 +7576,17 @@ function printFixSuggestions(suggestions) {
|
|
|
7537
7576
|
function setupWebUIEvents(session) {
|
|
7538
7577
|
const { scanner, webui } = session;
|
|
7539
7578
|
if (!webui) return;
|
|
7579
|
+
let lastBroadcast = 0;
|
|
7580
|
+
const BROADCAST_INTERVAL = 500;
|
|
7540
7581
|
scanner.on("render", (render) => {
|
|
7541
7582
|
webui.addRenderEvent(render);
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7583
|
+
const now = Date.now();
|
|
7584
|
+
if (now - lastBroadcast >= BROADCAST_INTERVAL) {
|
|
7585
|
+
lastBroadcast = now;
|
|
7586
|
+
webui.updateSummary(scanner.getSummary());
|
|
7587
|
+
webui.updateComponents(scanner.getSnapshot());
|
|
7588
|
+
webui.updateFps(scanner.getFps());
|
|
7589
|
+
}
|
|
7545
7590
|
});
|
|
7546
7591
|
scanner.on("chain", (chain) => {
|
|
7547
7592
|
webui.addChain(chain);
|
|
@@ -7631,10 +7676,385 @@ async function runInitCommand(args) {
|
|
|
7631
7676
|
return 1;
|
|
7632
7677
|
}
|
|
7633
7678
|
}
|
|
7679
|
+
var InteractiveWizard = class {
|
|
7680
|
+
rl;
|
|
7681
|
+
constructor() {
|
|
7682
|
+
this.rl = readline.createInterface({
|
|
7683
|
+
input: process.stdin,
|
|
7684
|
+
output: process.stdout
|
|
7685
|
+
});
|
|
7686
|
+
}
|
|
7687
|
+
/**
|
|
7688
|
+
* Run the interactive wizard
|
|
7689
|
+
*/
|
|
7690
|
+
async run() {
|
|
7691
|
+
this.printHeader();
|
|
7692
|
+
try {
|
|
7693
|
+
const url = await this.askUrl();
|
|
7694
|
+
if (!url) {
|
|
7695
|
+
this.close();
|
|
7696
|
+
return null;
|
|
7697
|
+
}
|
|
7698
|
+
const mode = await this.askMode();
|
|
7699
|
+
let webuiPort = 3199;
|
|
7700
|
+
if (mode === "webui") {
|
|
7701
|
+
webuiPort = await this.askWebuiPort();
|
|
7702
|
+
}
|
|
7703
|
+
const duration = await this.askDuration();
|
|
7704
|
+
const { warning, critical } = await this.askThresholds();
|
|
7705
|
+
const reportFormats = await this.askReportFormats();
|
|
7706
|
+
const outputDir = await this.askOutputDir();
|
|
7707
|
+
const headless = mode === "webui" ? false : await this.askHeadless();
|
|
7708
|
+
this.printSummary({
|
|
7709
|
+
url,
|
|
7710
|
+
mode,
|
|
7711
|
+
duration,
|
|
7712
|
+
warningThreshold: warning,
|
|
7713
|
+
criticalThreshold: critical,
|
|
7714
|
+
reportFormats,
|
|
7715
|
+
outputDir,
|
|
7716
|
+
headless,
|
|
7717
|
+
webuiPort
|
|
7718
|
+
});
|
|
7719
|
+
const confirmed = await this.askConfirm();
|
|
7720
|
+
this.close();
|
|
7721
|
+
if (!confirmed) {
|
|
7722
|
+
return null;
|
|
7723
|
+
}
|
|
7724
|
+
return {
|
|
7725
|
+
url,
|
|
7726
|
+
mode,
|
|
7727
|
+
duration,
|
|
7728
|
+
warningThreshold: warning,
|
|
7729
|
+
criticalThreshold: critical,
|
|
7730
|
+
reportFormats,
|
|
7731
|
+
outputDir,
|
|
7732
|
+
headless,
|
|
7733
|
+
webuiPort
|
|
7734
|
+
};
|
|
7735
|
+
} catch {
|
|
7736
|
+
this.close();
|
|
7737
|
+
return null;
|
|
7738
|
+
}
|
|
7739
|
+
}
|
|
7740
|
+
/**
|
|
7741
|
+
* Print wizard header
|
|
7742
|
+
*/
|
|
7743
|
+
printHeader() {
|
|
7744
|
+
console.log("");
|
|
7745
|
+
console.log(
|
|
7746
|
+
colors.cyan + "\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510" + colors.reset
|
|
7747
|
+
);
|
|
7748
|
+
console.log(
|
|
7749
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.cyan + "\u2502" + colors.reset
|
|
7750
|
+
);
|
|
7751
|
+
console.log(
|
|
7752
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.bold + colors.green + "\u269B ReactCheck" + colors.reset + " - Interactive Setup Wizard " + colors.cyan + "\u2502" + colors.reset
|
|
7753
|
+
);
|
|
7754
|
+
console.log(
|
|
7755
|
+
colors.cyan + "\u2502" + colors.reset + " " + colors.cyan + "\u2502" + colors.reset
|
|
7756
|
+
);
|
|
7757
|
+
console.log(
|
|
7758
|
+
colors.cyan + "\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518" + colors.reset
|
|
7759
|
+
);
|
|
7760
|
+
console.log("");
|
|
7761
|
+
}
|
|
7762
|
+
/**
|
|
7763
|
+
* Ask for URL
|
|
7764
|
+
*/
|
|
7765
|
+
async askUrl() {
|
|
7766
|
+
console.log(colors.bold + "\u{1F4CD} Step 1/7: Target URL" + colors.reset);
|
|
7767
|
+
console.log(colors.dim + " Enter the URL of the React app to scan" + colors.reset);
|
|
7768
|
+
console.log("");
|
|
7769
|
+
const url = await this.prompt(" URL: ", "http://localhost:3000");
|
|
7770
|
+
if (!url) {
|
|
7771
|
+
console.log(colors.yellow + " \u26A0 URL is required" + colors.reset);
|
|
7772
|
+
return this.askUrl();
|
|
7773
|
+
}
|
|
7774
|
+
try {
|
|
7775
|
+
new URL(url);
|
|
7776
|
+
} catch {
|
|
7777
|
+
console.log(colors.red + " \u2717 Invalid URL format" + colors.reset);
|
|
7778
|
+
return this.askUrl();
|
|
7779
|
+
}
|
|
7780
|
+
console.log("");
|
|
7781
|
+
return url;
|
|
7782
|
+
}
|
|
7783
|
+
/**
|
|
7784
|
+
* Ask for display mode
|
|
7785
|
+
*/
|
|
7786
|
+
async askMode() {
|
|
7787
|
+
console.log(colors.bold + "\u{1F5A5}\uFE0F Step 2/7: Display Mode" + colors.reset);
|
|
7788
|
+
console.log(colors.dim + " How do you want to view the results?" + colors.reset);
|
|
7789
|
+
console.log("");
|
|
7790
|
+
const options = [
|
|
7791
|
+
{ label: "TUI", value: "tui", description: "Terminal UI with real-time updates" },
|
|
7792
|
+
{ label: "WebUI", value: "webui", description: "Browser dashboard at localhost:3199" },
|
|
7793
|
+
{ label: "Headless", value: "headless", description: "No UI, just generate reports" }
|
|
7794
|
+
];
|
|
7795
|
+
const mode = await this.selectMenu(options, "tui");
|
|
7796
|
+
console.log("");
|
|
7797
|
+
return mode;
|
|
7798
|
+
}
|
|
7799
|
+
/**
|
|
7800
|
+
* Ask for WebUI port
|
|
7801
|
+
*/
|
|
7802
|
+
async askWebuiPort() {
|
|
7803
|
+
console.log(colors.bold + "\u{1F310} WebUI Port" + colors.reset);
|
|
7804
|
+
console.log(colors.dim + " Which port should the WebUI dashboard use?" + colors.reset);
|
|
7805
|
+
console.log("");
|
|
7806
|
+
const portStr = await this.prompt(" Port: ", "3199");
|
|
7807
|
+
const port = parseInt(portStr, 10);
|
|
7808
|
+
if (isNaN(port) || port < 1 || port > 65535) {
|
|
7809
|
+
console.log(colors.yellow + " \u26A0 Invalid port, using default 3199" + colors.reset);
|
|
7810
|
+
console.log("");
|
|
7811
|
+
return 3199;
|
|
7812
|
+
}
|
|
7813
|
+
console.log("");
|
|
7814
|
+
return port;
|
|
7815
|
+
}
|
|
7816
|
+
/**
|
|
7817
|
+
* Ask for duration
|
|
7818
|
+
*/
|
|
7819
|
+
async askDuration() {
|
|
7820
|
+
console.log(colors.bold + "\u23F1\uFE0F Step 3/7: Scan Duration" + colors.reset);
|
|
7821
|
+
console.log(colors.dim + " How long should the scan run? (in seconds)" + colors.reset);
|
|
7822
|
+
console.log("");
|
|
7823
|
+
const options = [
|
|
7824
|
+
{ label: "15 seconds", value: 15, description: "Quick scan" },
|
|
7825
|
+
{ label: "30 seconds", value: 30, description: "Standard scan (recommended)" },
|
|
7826
|
+
{ label: "60 seconds", value: 60, description: "Thorough scan" },
|
|
7827
|
+
{ label: "120 seconds", value: 120, description: "Extended scan" },
|
|
7828
|
+
{ label: "Custom", value: -1, description: "Enter custom duration" }
|
|
7829
|
+
];
|
|
7830
|
+
const duration = await this.selectMenu(options, 30);
|
|
7831
|
+
if (duration === -1) {
|
|
7832
|
+
const custom = await this.prompt(" Duration (seconds): ", "30");
|
|
7833
|
+
const parsed = parseInt(custom, 10);
|
|
7834
|
+
if (isNaN(parsed) || parsed < 5) {
|
|
7835
|
+
console.log(colors.yellow + " \u26A0 Using default 30 seconds" + colors.reset);
|
|
7836
|
+
console.log("");
|
|
7837
|
+
return 30;
|
|
7838
|
+
}
|
|
7839
|
+
console.log("");
|
|
7840
|
+
return parsed;
|
|
7841
|
+
}
|
|
7842
|
+
console.log("");
|
|
7843
|
+
return duration;
|
|
7844
|
+
}
|
|
7845
|
+
/**
|
|
7846
|
+
* Ask for thresholds
|
|
7847
|
+
*/
|
|
7848
|
+
async askThresholds() {
|
|
7849
|
+
console.log(colors.bold + "\u{1F4CA} Step 4/7: Render Thresholds" + colors.reset);
|
|
7850
|
+
console.log(
|
|
7851
|
+
colors.dim + " Set thresholds for warning and critical render counts" + colors.reset
|
|
7852
|
+
);
|
|
7853
|
+
console.log("");
|
|
7854
|
+
const options = [
|
|
7855
|
+
{ label: "Relaxed", value: { warning: 30, critical: 75 }, description: "For complex apps" },
|
|
7856
|
+
{
|
|
7857
|
+
label: "Standard",
|
|
7858
|
+
value: { warning: 20, critical: 50 },
|
|
7859
|
+
description: "Recommended defaults"
|
|
7860
|
+
},
|
|
7861
|
+
{ label: "Strict", value: { warning: 10, critical: 25 }, description: "High performance" },
|
|
7862
|
+
{ label: "Custom", value: { warning: -1, critical: -1 }, description: "Set your own" }
|
|
7863
|
+
];
|
|
7864
|
+
const result = await this.selectMenu(options, { warning: 20, critical: 50 });
|
|
7865
|
+
if (result.warning === -1) {
|
|
7866
|
+
const warnStr = await this.prompt(" Warning threshold: ", "20");
|
|
7867
|
+
const critStr = await this.prompt(" Critical threshold: ", "50");
|
|
7868
|
+
console.log("");
|
|
7869
|
+
return {
|
|
7870
|
+
warning: parseInt(warnStr, 10) || 20,
|
|
7871
|
+
critical: parseInt(critStr, 10) || 50
|
|
7872
|
+
};
|
|
7873
|
+
}
|
|
7874
|
+
console.log("");
|
|
7875
|
+
return result;
|
|
7876
|
+
}
|
|
7877
|
+
/**
|
|
7878
|
+
* Ask for report formats
|
|
7879
|
+
*/
|
|
7880
|
+
async askReportFormats() {
|
|
7881
|
+
console.log(colors.bold + "\u{1F4C4} Step 5/7: Report Formats" + colors.reset);
|
|
7882
|
+
console.log(
|
|
7883
|
+
colors.dim + " Which report formats do you want to generate?" + colors.reset
|
|
7884
|
+
);
|
|
7885
|
+
console.log("");
|
|
7886
|
+
const formats = [];
|
|
7887
|
+
const htmlAnswer = await this.prompt(
|
|
7888
|
+
" Generate HTML report? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
7889
|
+
"y"
|
|
7890
|
+
);
|
|
7891
|
+
if (htmlAnswer.toLowerCase() !== "n") {
|
|
7892
|
+
formats.push("html");
|
|
7893
|
+
}
|
|
7894
|
+
const jsonAnswer = await this.prompt(
|
|
7895
|
+
" Generate JSON report? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
7896
|
+
"y"
|
|
7897
|
+
);
|
|
7898
|
+
if (jsonAnswer.toLowerCase() !== "n") {
|
|
7899
|
+
formats.push("json");
|
|
7900
|
+
}
|
|
7901
|
+
const mdAnswer = await this.prompt(
|
|
7902
|
+
" Generate Markdown report? " + colors.dim + "(y/N)" + colors.reset + ": ",
|
|
7903
|
+
"n"
|
|
7904
|
+
);
|
|
7905
|
+
if (mdAnswer.toLowerCase() === "y") {
|
|
7906
|
+
formats.push("md");
|
|
7907
|
+
}
|
|
7908
|
+
if (formats.length === 0) {
|
|
7909
|
+
formats.push("html", "json");
|
|
7910
|
+
console.log(colors.dim + " Using default: HTML, JSON" + colors.reset);
|
|
7911
|
+
}
|
|
7912
|
+
console.log("");
|
|
7913
|
+
return formats;
|
|
7914
|
+
}
|
|
7915
|
+
/**
|
|
7916
|
+
* Ask for output directory
|
|
7917
|
+
*/
|
|
7918
|
+
async askOutputDir() {
|
|
7919
|
+
console.log(colors.bold + "\u{1F4C1} Step 6/7: Output Directory" + colors.reset);
|
|
7920
|
+
console.log(colors.dim + " Where should reports be saved?" + colors.reset);
|
|
7921
|
+
console.log("");
|
|
7922
|
+
const dir = await this.prompt(" Directory: ", "./reactcheck-reports");
|
|
7923
|
+
console.log("");
|
|
7924
|
+
return dir || "./reactcheck-reports";
|
|
7925
|
+
}
|
|
7926
|
+
/**
|
|
7927
|
+
* Ask for headless mode
|
|
7928
|
+
*/
|
|
7929
|
+
async askHeadless() {
|
|
7930
|
+
console.log(colors.bold + "\u{1F47B} Step 7/7: Browser Mode" + colors.reset);
|
|
7931
|
+
console.log(colors.dim + " Run browser in headless mode (invisible)?" + colors.reset);
|
|
7932
|
+
console.log(colors.dim + " Note: If you want to interact with your site, choose No." + colors.reset);
|
|
7933
|
+
console.log("");
|
|
7934
|
+
const answer = await this.prompt(
|
|
7935
|
+
" Headless browser? " + colors.dim + "(y/N)" + colors.reset + ": ",
|
|
7936
|
+
"n"
|
|
7937
|
+
);
|
|
7938
|
+
console.log("");
|
|
7939
|
+
return answer.toLowerCase() === "y";
|
|
7940
|
+
}
|
|
7941
|
+
/**
|
|
7942
|
+
* Print configuration summary
|
|
7943
|
+
*/
|
|
7944
|
+
printSummary(config) {
|
|
7945
|
+
console.log(
|
|
7946
|
+
colors.cyan + "\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510" + colors.reset
|
|
7947
|
+
);
|
|
7948
|
+
console.log(
|
|
7949
|
+
colors.cyan + "\u2502" + colors.reset + colors.bold + " Configuration Summary " + colors.reset + colors.cyan + "\u2502" + colors.reset
|
|
7950
|
+
);
|
|
7951
|
+
console.log(
|
|
7952
|
+
colors.cyan + "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524" + colors.reset
|
|
7953
|
+
);
|
|
7954
|
+
console.log(
|
|
7955
|
+
colors.cyan + "\u2502" + colors.reset + ` URL: ${this.pad(config.url, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7956
|
+
);
|
|
7957
|
+
console.log(
|
|
7958
|
+
colors.cyan + "\u2502" + colors.reset + ` Mode: ${this.pad(config.mode.toUpperCase(), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7959
|
+
);
|
|
7960
|
+
console.log(
|
|
7961
|
+
colors.cyan + "\u2502" + colors.reset + ` Duration: ${this.pad(config.duration + " seconds", 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7962
|
+
);
|
|
7963
|
+
console.log(
|
|
7964
|
+
colors.cyan + "\u2502" + colors.reset + ` Thresholds: ${this.pad(`Warning: ${config.warningThreshold}, Critical: ${config.criticalThreshold}`, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7965
|
+
);
|
|
7966
|
+
console.log(
|
|
7967
|
+
colors.cyan + "\u2502" + colors.reset + ` Reports: ${this.pad(config.reportFormats.join(", ").toUpperCase(), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7968
|
+
);
|
|
7969
|
+
console.log(
|
|
7970
|
+
colors.cyan + "\u2502" + colors.reset + ` Output: ${this.pad(config.outputDir, 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7971
|
+
);
|
|
7972
|
+
console.log(
|
|
7973
|
+
colors.cyan + "\u2502" + colors.reset + ` Headless: ${this.pad(config.headless ? "Yes" : "No", 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7974
|
+
);
|
|
7975
|
+
if (config.mode === "webui") {
|
|
7976
|
+
console.log(
|
|
7977
|
+
colors.cyan + "\u2502" + colors.reset + ` WebUI Port: ${this.pad(String(config.webuiPort), 45)}` + colors.cyan + "\u2502" + colors.reset
|
|
7978
|
+
);
|
|
7979
|
+
}
|
|
7980
|
+
console.log(
|
|
7981
|
+
colors.cyan + "\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518" + colors.reset
|
|
7982
|
+
);
|
|
7983
|
+
console.log("");
|
|
7984
|
+
}
|
|
7985
|
+
/**
|
|
7986
|
+
* Ask for confirmation
|
|
7987
|
+
*/
|
|
7988
|
+
async askConfirm() {
|
|
7989
|
+
const answer = await this.prompt(
|
|
7990
|
+
colors.green + " Start scan with these settings? " + colors.dim + "(Y/n)" + colors.reset + ": ",
|
|
7991
|
+
"y"
|
|
7992
|
+
);
|
|
7993
|
+
return answer.toLowerCase() !== "n";
|
|
7994
|
+
}
|
|
7995
|
+
/**
|
|
7996
|
+
* Prompt for input
|
|
7997
|
+
*/
|
|
7998
|
+
prompt(question, defaultValue = "") {
|
|
7999
|
+
return new Promise((resolve3) => {
|
|
8000
|
+
const defaultHint = defaultValue ? colors.dim + ` [${defaultValue}]` + colors.reset : "";
|
|
8001
|
+
this.rl.question(question + defaultHint + " ", (answer) => {
|
|
8002
|
+
resolve3(answer.trim() || defaultValue);
|
|
8003
|
+
});
|
|
8004
|
+
});
|
|
8005
|
+
}
|
|
8006
|
+
/**
|
|
8007
|
+
* Display a menu and get selection
|
|
8008
|
+
*/
|
|
8009
|
+
async selectMenu(options, defaultValue) {
|
|
8010
|
+
options.forEach((opt, i) => {
|
|
8011
|
+
const isDefault = JSON.stringify(opt.value) === JSON.stringify(defaultValue);
|
|
8012
|
+
const marker = isDefault ? colors.green + "\u25CF" + colors.reset : colors.dim + "\u25CB" + colors.reset;
|
|
8013
|
+
const label = isDefault ? colors.bold + opt.label + colors.reset : opt.label;
|
|
8014
|
+
const desc = opt.description ? colors.dim + " - " + opt.description + colors.reset : "";
|
|
8015
|
+
console.log(` ${marker} ${i + 1}. ${label}${desc}`);
|
|
8016
|
+
});
|
|
8017
|
+
console.log("");
|
|
8018
|
+
const answer = await this.prompt(" Select option: ", "");
|
|
8019
|
+
const num = parseInt(answer, 10);
|
|
8020
|
+
if (num >= 1 && num <= options.length) {
|
|
8021
|
+
const selected = options[num - 1];
|
|
8022
|
+
if (selected) {
|
|
8023
|
+
return selected.value;
|
|
8024
|
+
}
|
|
8025
|
+
}
|
|
8026
|
+
const matched = options.find(
|
|
8027
|
+
(opt) => opt.label.toLowerCase() === answer.toLowerCase()
|
|
8028
|
+
);
|
|
8029
|
+
if (matched) {
|
|
8030
|
+
return matched.value;
|
|
8031
|
+
}
|
|
8032
|
+
return defaultValue;
|
|
8033
|
+
}
|
|
8034
|
+
/**
|
|
8035
|
+
* Pad string to fixed width
|
|
8036
|
+
*/
|
|
8037
|
+
pad(str, width) {
|
|
8038
|
+
if (str.length >= width) {
|
|
8039
|
+
return str.substring(0, width - 3) + "...";
|
|
8040
|
+
}
|
|
8041
|
+
return str + " ".repeat(width - str.length);
|
|
8042
|
+
}
|
|
8043
|
+
/**
|
|
8044
|
+
* Close readline interface
|
|
8045
|
+
*/
|
|
8046
|
+
close() {
|
|
8047
|
+
this.rl.close();
|
|
8048
|
+
}
|
|
8049
|
+
};
|
|
8050
|
+
async function runInteractiveWizard() {
|
|
8051
|
+
const wizard = new InteractiveWizard();
|
|
8052
|
+
return wizard.run();
|
|
8053
|
+
}
|
|
7634
8054
|
|
|
7635
8055
|
// src/cli/index.ts
|
|
7636
8056
|
var logger6 = new Logger({ prefix: "ReactCheck", level: 1 /* INFO */ });
|
|
7637
|
-
var VERSION = "1.1.
|
|
8057
|
+
var VERSION = "1.1.6";
|
|
7638
8058
|
function printVersion() {
|
|
7639
8059
|
console.log(`@oxog/react-check v${VERSION}`);
|
|
7640
8060
|
}
|
|
@@ -7661,6 +8081,47 @@ var CLI = class {
|
|
|
7661
8081
|
constructor(argv) {
|
|
7662
8082
|
this.argv = argv;
|
|
7663
8083
|
}
|
|
8084
|
+
/**
|
|
8085
|
+
* Convert wizard config to ParsedArgs
|
|
8086
|
+
* @param config - Wizard configuration
|
|
8087
|
+
* @returns Parsed arguments for scan command
|
|
8088
|
+
*/
|
|
8089
|
+
wizardConfigToArgs(config) {
|
|
8090
|
+
const flags = /* @__PURE__ */ new Map();
|
|
8091
|
+
if (config.mode === "tui") {
|
|
8092
|
+
flags.set("tui", true);
|
|
8093
|
+
} else if (config.mode === "webui") {
|
|
8094
|
+
flags.set("webui", true);
|
|
8095
|
+
flags.set("webui-port", String(config.webuiPort));
|
|
8096
|
+
} else if (config.mode === "headless") {
|
|
8097
|
+
flags.set("silent", true);
|
|
8098
|
+
}
|
|
8099
|
+
if (config.duration) {
|
|
8100
|
+
flags.set("duration", String(config.duration));
|
|
8101
|
+
}
|
|
8102
|
+
flags.set("threshold-warning", String(config.warningThreshold));
|
|
8103
|
+
flags.set("threshold-critical", String(config.criticalThreshold));
|
|
8104
|
+
if (config.reportFormats.length > 0) {
|
|
8105
|
+
flags.set("report", true);
|
|
8106
|
+
if (config.reportFormats.length === 3) {
|
|
8107
|
+
flags.set("format", "all");
|
|
8108
|
+
} else {
|
|
8109
|
+
const firstFormat = config.reportFormats[0];
|
|
8110
|
+
if (firstFormat) {
|
|
8111
|
+
flags.set("format", firstFormat);
|
|
8112
|
+
}
|
|
8113
|
+
}
|
|
8114
|
+
}
|
|
8115
|
+
flags.set("output", config.outputDir);
|
|
8116
|
+
flags.set("headless", config.headless);
|
|
8117
|
+
return {
|
|
8118
|
+
command: "scan",
|
|
8119
|
+
target: config.url,
|
|
8120
|
+
flags,
|
|
8121
|
+
positional: [],
|
|
8122
|
+
raw: []
|
|
8123
|
+
};
|
|
8124
|
+
}
|
|
7664
8125
|
/**
|
|
7665
8126
|
* Run the CLI
|
|
7666
8127
|
* @returns Exit code
|
|
@@ -7681,6 +8142,15 @@ var CLI = class {
|
|
|
7681
8142
|
return await runInitCommand(args);
|
|
7682
8143
|
case "scan":
|
|
7683
8144
|
default:
|
|
8145
|
+
if (!args.target && args.raw.length === 0 && process.stdin.isTTY) {
|
|
8146
|
+
printBanner();
|
|
8147
|
+
const wizardConfig = await runInteractiveWizard();
|
|
8148
|
+
if (!wizardConfig) {
|
|
8149
|
+
return 0;
|
|
8150
|
+
}
|
|
8151
|
+
const wizardArgs = this.wizardConfigToArgs(wizardConfig);
|
|
8152
|
+
return await runScanCommand(wizardArgs);
|
|
8153
|
+
}
|
|
7684
8154
|
const errors = validateArgs(args);
|
|
7685
8155
|
if (errors.length > 0) {
|
|
7686
8156
|
for (const error of errors) {
|
|
@@ -7699,6 +8169,14 @@ var CLI = class {
|
|
|
7699
8169
|
}
|
|
7700
8170
|
};
|
|
7701
8171
|
async function main() {
|
|
8172
|
+
process.on("uncaughtException", (error) => {
|
|
8173
|
+
console.error(semantic.error("Uncaught exception:"), error);
|
|
8174
|
+
process.exit(1);
|
|
8175
|
+
});
|
|
8176
|
+
process.on("unhandledRejection", (reason) => {
|
|
8177
|
+
console.error(semantic.error("Unhandled rejection:"), reason);
|
|
8178
|
+
process.exit(1);
|
|
8179
|
+
});
|
|
7702
8180
|
const cli = new CLI(process.argv.slice(2));
|
|
7703
8181
|
const exitCode = await cli.run();
|
|
7704
8182
|
process.exit(exitCode);
|
|
@@ -7710,6 +8188,6 @@ if (!process.env.VITEST) {
|
|
|
7710
8188
|
});
|
|
7711
8189
|
}
|
|
7712
8190
|
|
|
7713
|
-
export { CLI, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, validateArgs, validateConfig };
|
|
8191
|
+
export { CLI, InteractiveWizard, TUI, generateDefaultConfigContent, getHelpText, loadConfig, parseArgs, runInteractiveWizard, validateArgs, validateConfig };
|
|
7714
8192
|
//# sourceMappingURL=cli.js.map
|
|
7715
8193
|
//# sourceMappingURL=cli.js.map
|