@oxog/react-check 1.0.3 → 1.1.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 +84 -0
- package/README.md +90 -0
- package/dist/browser-inject.global.js +68 -6
- package/dist/chain.d.cts +1 -1
- package/dist/chain.d.ts +1 -1
- package/dist/cli.js +1472 -104
- 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 +572 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +183 -133
- package/dist/index.d.ts +183 -133
- package/dist/index.js +572 -357
- package/dist/index.js.map +1 -1
- package/dist/{scanner-BsBnFki5.d.cts → scanner-5j2LEM-q.d.cts} +1 -1
- package/dist/{scanner-bpT7eMcv.d.ts → scanner-CTBraprQ.d.ts} +1 -1
- package/dist/scanner.d.cts +2 -2
- package/dist/scanner.d.ts +2 -2
- package/dist/{types-CVcIoqzs.d.cts → types-xAXT9cir.d.cts} +5 -0
- package/dist/{types-CVcIoqzs.d.ts → types-xAXT9cir.d.ts} +5 -0
- package/package.json +8 -2
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, resolve, join, extname, basename } from 'path';
|
|
|
5
5
|
import { createServer } from 'http';
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
+
import { exec } from 'child_process';
|
|
8
9
|
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -277,7 +278,7 @@ function generateHTMLReport(report) {
|
|
|
277
278
|
<meta charset="UTF-8">
|
|
278
279
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
279
280
|
<title>ReactCheck Report - ${escapeHtml(report.session.url)}</title>
|
|
280
|
-
<style>${
|
|
281
|
+
<style>${getStyles2()}</style>
|
|
281
282
|
</head>
|
|
282
283
|
<body>
|
|
283
284
|
<div class="container">
|
|
@@ -289,11 +290,11 @@ function generateHTMLReport(report) {
|
|
|
289
290
|
${renderAllComponents(report)}
|
|
290
291
|
${renderFooter(report)}
|
|
291
292
|
</div>
|
|
292
|
-
<script>${
|
|
293
|
+
<script>${getScript2()}</script>
|
|
293
294
|
</body>
|
|
294
295
|
</html>`;
|
|
295
296
|
}
|
|
296
|
-
function
|
|
297
|
+
function getStyles2() {
|
|
297
298
|
return `
|
|
298
299
|
:root {
|
|
299
300
|
--bg-primary: #0a0a0a;
|
|
@@ -567,7 +568,7 @@ function getStyles() {
|
|
|
567
568
|
}
|
|
568
569
|
`;
|
|
569
570
|
}
|
|
570
|
-
function
|
|
571
|
+
function getScript2() {
|
|
571
572
|
return `
|
|
572
573
|
// Toggle collapsible sections
|
|
573
574
|
document.querySelectorAll('.collapsible').forEach(el => {
|
|
@@ -1200,6 +1201,16 @@ var FLAG_DEFINITIONS = {
|
|
|
1200
1201
|
short: "w",
|
|
1201
1202
|
description: "Watch mode - keep scanning until quit",
|
|
1202
1203
|
default: false
|
|
1204
|
+
},
|
|
1205
|
+
webui: {
|
|
1206
|
+
short: "W",
|
|
1207
|
+
description: "Enable WebUI dashboard",
|
|
1208
|
+
default: false
|
|
1209
|
+
},
|
|
1210
|
+
"webui-port": {
|
|
1211
|
+
description: "WebUI dashboard port",
|
|
1212
|
+
takesValue: true,
|
|
1213
|
+
default: "3100"
|
|
1203
1214
|
}
|
|
1204
1215
|
};
|
|
1205
1216
|
function buildShortFlagMap() {
|
|
@@ -1232,6 +1243,11 @@ function parseArgs(argv) {
|
|
|
1232
1243
|
continue;
|
|
1233
1244
|
}
|
|
1234
1245
|
if (i === 0 || result.positional.length === 0 && !result.target) {
|
|
1246
|
+
if (arg === "scan") {
|
|
1247
|
+
result.command = "scan";
|
|
1248
|
+
i++;
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1235
1251
|
if (arg === "init") {
|
|
1236
1252
|
result.command = "init";
|
|
1237
1253
|
i++;
|
|
@@ -4850,7 +4866,8 @@ function createDefaultState(target) {
|
|
|
4850
4866
|
suggestions: [],
|
|
4851
4867
|
chains: [],
|
|
4852
4868
|
paused: false,
|
|
4853
|
-
view: "list"
|
|
4869
|
+
view: "list",
|
|
4870
|
+
overlayEnabled: true
|
|
4854
4871
|
};
|
|
4855
4872
|
}
|
|
4856
4873
|
var TUI = class extends EventEmitter {
|
|
@@ -4870,6 +4887,8 @@ var TUI = class extends EventEmitter {
|
|
|
4870
4887
|
renderInterval = null;
|
|
4871
4888
|
/** Spinner frame */
|
|
4872
4889
|
spinnerFrame = 0;
|
|
4890
|
+
/** Data provider function for polling */
|
|
4891
|
+
dataProvider = null;
|
|
4873
4892
|
/**
|
|
4874
4893
|
* Create a new TUI
|
|
4875
4894
|
* @param target - Target URL
|
|
@@ -4908,6 +4927,7 @@ var TUI = class extends EventEmitter {
|
|
|
4908
4927
|
this.keys.bind("s", () => this.emit("openSettings", void 0));
|
|
4909
4928
|
this.keys.bind("f", () => this.showFixSuggestions());
|
|
4910
4929
|
this.keys.bind("c", () => this.showRenderChain());
|
|
4930
|
+
this.keys.bind("o", () => this.emit("toggleOverlay", void 0));
|
|
4911
4931
|
}
|
|
4912
4932
|
/**
|
|
4913
4933
|
* Start the TUI
|
|
@@ -4926,10 +4946,28 @@ var TUI = class extends EventEmitter {
|
|
|
4926
4946
|
});
|
|
4927
4947
|
this.renderInterval = setInterval(() => {
|
|
4928
4948
|
this.spinnerFrame++;
|
|
4949
|
+
if (this.dataProvider) {
|
|
4950
|
+
try {
|
|
4951
|
+
const data = this.dataProvider();
|
|
4952
|
+
this.state = { ...this.state, ...data };
|
|
4953
|
+
if (data.components && data.components.length > 0) {
|
|
4954
|
+
const items = createComponentListItems(data.components);
|
|
4955
|
+
this.componentList.setItems(items);
|
|
4956
|
+
}
|
|
4957
|
+
} catch {
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4929
4960
|
this.render();
|
|
4930
4961
|
}, 250);
|
|
4931
4962
|
this.render();
|
|
4932
4963
|
}
|
|
4964
|
+
/**
|
|
4965
|
+
* Set data provider for polling
|
|
4966
|
+
* @param provider - Function that returns current data
|
|
4967
|
+
*/
|
|
4968
|
+
setDataProvider(provider) {
|
|
4969
|
+
this.dataProvider = provider;
|
|
4970
|
+
}
|
|
4933
4971
|
/**
|
|
4934
4972
|
* Stop the TUI
|
|
4935
4973
|
*/
|
|
@@ -4989,7 +5027,7 @@ var TUI = class extends EventEmitter {
|
|
|
4989
5027
|
}
|
|
4990
5028
|
drawDivider(this.screen, 0, height - 3, width, "single", colors.gray);
|
|
4991
5029
|
this.renderFooter(1, height - 2, width - 2);
|
|
4992
|
-
this.screen.render();
|
|
5030
|
+
this.screen.render(true);
|
|
4993
5031
|
}
|
|
4994
5032
|
/**
|
|
4995
5033
|
* Render header
|
|
@@ -5115,7 +5153,8 @@ var TUI = class extends EventEmitter {
|
|
|
5115
5153
|
* Render footer with keybindings
|
|
5116
5154
|
*/
|
|
5117
5155
|
renderFooter(x, y, width) {
|
|
5118
|
-
const
|
|
5156
|
+
const overlayStatus = this.state.overlayEnabled ? "on" : "off";
|
|
5157
|
+
const bindings = this.state.view === "list" ? `[j/k] Navigate [Enter] Details [f] Fix [c] Chain [o] Overlay:${overlayStatus} [r] Report [p] Pause [q] Quit` : `[Esc] Back [f] Fix [c] Chain [o] Overlay:${overlayStatus} [r] Report [p] Pause [q] Quit`;
|
|
5119
5158
|
this.screen.writeText(x, y, colors.gray + bindings + colors.reset, width);
|
|
5120
5159
|
}
|
|
5121
5160
|
/**
|
|
@@ -5738,106 +5777,1369 @@ async function isPuppeteerAvailable() {
|
|
|
5738
5777
|
|
|
5739
5778
|
// src/cli/commands/scan.ts
|
|
5740
5779
|
init_fs();
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5780
|
+
|
|
5781
|
+
// src/webui/dashboard.ts
|
|
5782
|
+
function generateDashboardHTML(wsPort, target) {
|
|
5783
|
+
return `<!DOCTYPE html>
|
|
5784
|
+
<html lang="en">
|
|
5785
|
+
<head>
|
|
5786
|
+
<meta charset="UTF-8">
|
|
5787
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5788
|
+
<title>ReactCheck Dashboard</title>
|
|
5789
|
+
<style>${getStyles()}</style>
|
|
5790
|
+
</head>
|
|
5791
|
+
<body>
|
|
5792
|
+
<div class="container">
|
|
5793
|
+
<header class="header">
|
|
5794
|
+
<div class="header-left">
|
|
5795
|
+
<h1>
|
|
5796
|
+
<span class="logo">\u269B\uFE0F</span>
|
|
5797
|
+
ReactCheck
|
|
5798
|
+
<span class="status" id="status">
|
|
5799
|
+
<span class="status-dot"></span>
|
|
5800
|
+
<span class="status-text">Connecting...</span>
|
|
5801
|
+
</span>
|
|
5802
|
+
</h1>
|
|
5803
|
+
<div class="header-meta">
|
|
5804
|
+
<span id="target">Target: ${escapeHtml2(target)}</span>
|
|
5805
|
+
<span class="separator">\u2022</span>
|
|
5806
|
+
<span id="duration">Duration: 0s</span>
|
|
5807
|
+
</div>
|
|
5808
|
+
</div>
|
|
5809
|
+
<div class="header-right">
|
|
5810
|
+
<button id="export-btn" class="btn btn-secondary" disabled>Export Report</button>
|
|
5811
|
+
</div>
|
|
5812
|
+
</header>
|
|
5813
|
+
|
|
5814
|
+
<section class="summary">
|
|
5815
|
+
<div class="summary-grid">
|
|
5816
|
+
<div class="summary-card">
|
|
5817
|
+
<div class="summary-value info" id="components">0</div>
|
|
5818
|
+
<div class="summary-label">Components</div>
|
|
5819
|
+
</div>
|
|
5820
|
+
<div class="summary-card">
|
|
5821
|
+
<div class="summary-value" id="renders">0</div>
|
|
5822
|
+
<div class="summary-label">Total Renders</div>
|
|
5823
|
+
</div>
|
|
5824
|
+
<div class="summary-card">
|
|
5825
|
+
<div class="summary-value critical" id="critical">0</div>
|
|
5826
|
+
<div class="summary-label">Critical</div>
|
|
5827
|
+
</div>
|
|
5828
|
+
<div class="summary-card">
|
|
5829
|
+
<div class="summary-value warning" id="warnings">0</div>
|
|
5830
|
+
<div class="summary-label">Warnings</div>
|
|
5831
|
+
</div>
|
|
5832
|
+
<div class="summary-card">
|
|
5833
|
+
<div class="summary-value healthy" id="healthy">0</div>
|
|
5834
|
+
<div class="summary-label">Healthy</div>
|
|
5835
|
+
</div>
|
|
5836
|
+
<div class="summary-card">
|
|
5837
|
+
<div class="summary-value" id="fps">60</div>
|
|
5838
|
+
<div class="summary-label">Avg FPS</div>
|
|
5839
|
+
</div>
|
|
5840
|
+
</div>
|
|
5841
|
+
</section>
|
|
5842
|
+
|
|
5843
|
+
<section class="content">
|
|
5844
|
+
<div class="panel components-panel">
|
|
5845
|
+
<div class="panel-header">
|
|
5846
|
+
<h2>Components</h2>
|
|
5847
|
+
<input type="text" id="search" placeholder="Search components..." class="search-input">
|
|
5848
|
+
</div>
|
|
5849
|
+
<div class="table-container">
|
|
5850
|
+
<table class="component-table">
|
|
5851
|
+
<thead>
|
|
5852
|
+
<tr>
|
|
5853
|
+
<th class="sortable" data-sort="name">Component</th>
|
|
5854
|
+
<th class="sortable" data-sort="renders">Renders</th>
|
|
5855
|
+
<th class="sortable" data-sort="unnecessary">Unnecessary</th>
|
|
5856
|
+
<th class="sortable" data-sort="avgTime">Avg Time</th>
|
|
5857
|
+
<th class="sortable" data-sort="severity">Severity</th>
|
|
5858
|
+
</tr>
|
|
5859
|
+
</thead>
|
|
5860
|
+
<tbody id="component-list">
|
|
5861
|
+
<tr class="empty-row">
|
|
5862
|
+
<td colspan="5">Waiting for data...</td>
|
|
5863
|
+
</tr>
|
|
5864
|
+
</tbody>
|
|
5865
|
+
</table>
|
|
5866
|
+
</div>
|
|
5867
|
+
</div>
|
|
5868
|
+
|
|
5869
|
+
<div class="panel events-panel">
|
|
5870
|
+
<div class="panel-header">
|
|
5871
|
+
<h2>Live Events</h2>
|
|
5872
|
+
<span class="event-count" id="event-count">0 events</span>
|
|
5873
|
+
</div>
|
|
5874
|
+
<div class="events-container" id="events">
|
|
5875
|
+
<div class="empty-message">Waiting for render events...</div>
|
|
5876
|
+
</div>
|
|
5877
|
+
</div>
|
|
5878
|
+
</section>
|
|
5879
|
+
|
|
5880
|
+
<section class="chains-section">
|
|
5881
|
+
<div class="panel">
|
|
5882
|
+
<div class="panel-header">
|
|
5883
|
+
<h2>Render Chains</h2>
|
|
5884
|
+
</div>
|
|
5885
|
+
<div class="chains-container" id="chains">
|
|
5886
|
+
<div class="empty-message">No render chains detected yet...</div>
|
|
5887
|
+
</div>
|
|
5888
|
+
</div>
|
|
5889
|
+
</section>
|
|
5890
|
+
</div>
|
|
5891
|
+
<script>${getScript(wsPort)}</script>
|
|
5892
|
+
</body>
|
|
5893
|
+
</html>`;
|
|
5762
5894
|
}
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5895
|
+
function escapeHtml2(str) {
|
|
5896
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
5897
|
+
}
|
|
5898
|
+
function getStyles() {
|
|
5899
|
+
return `
|
|
5900
|
+
:root {
|
|
5901
|
+
--bg-primary: #0a0a0a;
|
|
5902
|
+
--bg-secondary: #141414;
|
|
5903
|
+
--bg-tertiary: #1f1f1f;
|
|
5904
|
+
--text-primary: #ffffff;
|
|
5905
|
+
--text-secondary: #a1a1aa;
|
|
5906
|
+
--accent-red: #ef4444;
|
|
5907
|
+
--accent-yellow: #eab308;
|
|
5908
|
+
--accent-green: #22c55e;
|
|
5909
|
+
--accent-blue: #3b82f6;
|
|
5910
|
+
--accent-purple: #a855f7;
|
|
5911
|
+
--border-color: #27272a;
|
|
5912
|
+
}
|
|
5778
5913
|
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5914
|
+
* {
|
|
5915
|
+
box-sizing: border-box;
|
|
5916
|
+
margin: 0;
|
|
5917
|
+
padding: 0;
|
|
5918
|
+
}
|
|
5919
|
+
|
|
5920
|
+
body {
|
|
5921
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
5922
|
+
background: var(--bg-primary);
|
|
5923
|
+
color: var(--text-primary);
|
|
5924
|
+
line-height: 1.6;
|
|
5925
|
+
min-height: 100vh;
|
|
5926
|
+
}
|
|
5927
|
+
|
|
5928
|
+
.container {
|
|
5929
|
+
max-width: 1400px;
|
|
5930
|
+
margin: 0 auto;
|
|
5931
|
+
padding: 1.5rem;
|
|
5932
|
+
}
|
|
5933
|
+
|
|
5934
|
+
/* Header */
|
|
5935
|
+
.header {
|
|
5936
|
+
display: flex;
|
|
5937
|
+
justify-content: space-between;
|
|
5938
|
+
align-items: flex-start;
|
|
5939
|
+
margin-bottom: 1.5rem;
|
|
5940
|
+
padding-bottom: 1rem;
|
|
5941
|
+
border-bottom: 1px solid var(--border-color);
|
|
5942
|
+
}
|
|
5943
|
+
|
|
5944
|
+
.header h1 {
|
|
5945
|
+
font-size: 1.75rem;
|
|
5946
|
+
color: var(--accent-green);
|
|
5947
|
+
display: flex;
|
|
5948
|
+
align-items: center;
|
|
5949
|
+
gap: 0.5rem;
|
|
5950
|
+
}
|
|
5951
|
+
|
|
5952
|
+
.logo {
|
|
5953
|
+
font-size: 1.5rem;
|
|
5954
|
+
}
|
|
5955
|
+
|
|
5956
|
+
.status {
|
|
5957
|
+
font-size: 0.875rem;
|
|
5958
|
+
font-weight: normal;
|
|
5959
|
+
display: inline-flex;
|
|
5960
|
+
align-items: center;
|
|
5961
|
+
gap: 0.375rem;
|
|
5962
|
+
padding: 0.25rem 0.75rem;
|
|
5963
|
+
background: var(--bg-tertiary);
|
|
5964
|
+
border-radius: 9999px;
|
|
5965
|
+
margin-left: 0.75rem;
|
|
5966
|
+
}
|
|
5967
|
+
|
|
5968
|
+
.status-dot {
|
|
5969
|
+
width: 8px;
|
|
5970
|
+
height: 8px;
|
|
5971
|
+
border-radius: 50%;
|
|
5972
|
+
background: var(--accent-yellow);
|
|
5973
|
+
animation: pulse 2s infinite;
|
|
5974
|
+
}
|
|
5975
|
+
|
|
5976
|
+
.status.connected .status-dot {
|
|
5977
|
+
background: var(--accent-green);
|
|
5978
|
+
animation: none;
|
|
5979
|
+
}
|
|
5980
|
+
|
|
5981
|
+
.status.scanning .status-dot {
|
|
5982
|
+
background: var(--accent-blue);
|
|
5983
|
+
animation: pulse 1s infinite;
|
|
5984
|
+
}
|
|
5985
|
+
|
|
5986
|
+
.status.paused .status-dot {
|
|
5987
|
+
background: var(--accent-yellow);
|
|
5988
|
+
animation: none;
|
|
5989
|
+
}
|
|
5990
|
+
|
|
5991
|
+
@keyframes pulse {
|
|
5992
|
+
0%, 100% { opacity: 1; }
|
|
5993
|
+
50% { opacity: 0.5; }
|
|
5994
|
+
}
|
|
5995
|
+
|
|
5996
|
+
.header-meta {
|
|
5997
|
+
color: var(--text-secondary);
|
|
5998
|
+
font-size: 0.875rem;
|
|
5999
|
+
margin-top: 0.5rem;
|
|
6000
|
+
}
|
|
6001
|
+
|
|
6002
|
+
.separator {
|
|
6003
|
+
margin: 0 0.5rem;
|
|
6004
|
+
}
|
|
6005
|
+
|
|
6006
|
+
.btn {
|
|
6007
|
+
padding: 0.5rem 1rem;
|
|
6008
|
+
border-radius: 6px;
|
|
6009
|
+
border: none;
|
|
6010
|
+
font-size: 0.875rem;
|
|
6011
|
+
font-weight: 500;
|
|
6012
|
+
cursor: pointer;
|
|
6013
|
+
transition: all 0.2s;
|
|
6014
|
+
}
|
|
6015
|
+
|
|
6016
|
+
.btn:disabled {
|
|
6017
|
+
opacity: 0.5;
|
|
6018
|
+
cursor: not-allowed;
|
|
6019
|
+
}
|
|
6020
|
+
|
|
6021
|
+
.btn-secondary {
|
|
6022
|
+
background: var(--bg-tertiary);
|
|
6023
|
+
color: var(--text-primary);
|
|
6024
|
+
}
|
|
6025
|
+
|
|
6026
|
+
.btn-secondary:hover:not(:disabled) {
|
|
6027
|
+
background: var(--border-color);
|
|
6028
|
+
}
|
|
6029
|
+
|
|
6030
|
+
/* Summary */
|
|
6031
|
+
.summary {
|
|
6032
|
+
margin-bottom: 1.5rem;
|
|
6033
|
+
}
|
|
6034
|
+
|
|
6035
|
+
.summary-grid {
|
|
6036
|
+
display: grid;
|
|
6037
|
+
grid-template-columns: repeat(6, 1fr);
|
|
6038
|
+
gap: 1rem;
|
|
6039
|
+
}
|
|
6040
|
+
|
|
6041
|
+
@media (max-width: 900px) {
|
|
6042
|
+
.summary-grid {
|
|
6043
|
+
grid-template-columns: repeat(3, 1fr);
|
|
5796
6044
|
}
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
5803
|
-
if (fromFile) {
|
|
5804
|
-
logger4.info(`Using config: ${configPath}`);
|
|
5805
|
-
}
|
|
5806
|
-
const configOptions = configToOptions(config);
|
|
5807
|
-
const mergedOptions = {
|
|
5808
|
-
...options,
|
|
5809
|
-
thresholdCritical: options.thresholdCritical ?? configOptions.thresholds.critical,
|
|
5810
|
-
thresholdWarning: options.thresholdWarning ?? configOptions.thresholds.warning,
|
|
5811
|
-
fpsThreshold: options.fpsThreshold ?? configOptions.thresholds.fps,
|
|
5812
|
-
output: options.output ?? configOptions.report.output
|
|
5813
|
-
};
|
|
5814
|
-
const session = {
|
|
5815
|
-
id: generateId("scan"),
|
|
5816
|
-
startTime: Date.now(),
|
|
5817
|
-
scanner: new Scanner({
|
|
5818
|
-
thresholds: {
|
|
5819
|
-
critical: mergedOptions.thresholdCritical,
|
|
5820
|
-
warning: mergedOptions.thresholdWarning,
|
|
5821
|
-
fps: mergedOptions.fpsThreshold
|
|
6045
|
+
}
|
|
6046
|
+
|
|
6047
|
+
@media (max-width: 500px) {
|
|
6048
|
+
.summary-grid {
|
|
6049
|
+
grid-template-columns: repeat(2, 1fr);
|
|
5822
6050
|
}
|
|
5823
|
-
}
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
6051
|
+
}
|
|
6052
|
+
|
|
6053
|
+
.summary-card {
|
|
6054
|
+
background: var(--bg-secondary);
|
|
6055
|
+
border-radius: 8px;
|
|
6056
|
+
padding: 1rem;
|
|
6057
|
+
text-align: center;
|
|
6058
|
+
transition: transform 0.2s;
|
|
6059
|
+
}
|
|
6060
|
+
|
|
6061
|
+
.summary-card:hover {
|
|
6062
|
+
transform: translateY(-2px);
|
|
6063
|
+
}
|
|
6064
|
+
|
|
6065
|
+
.summary-value {
|
|
6066
|
+
font-size: 2rem;
|
|
6067
|
+
font-weight: bold;
|
|
6068
|
+
transition: all 0.3s;
|
|
6069
|
+
}
|
|
6070
|
+
|
|
6071
|
+
.summary-value.updated {
|
|
6072
|
+
transform: scale(1.1);
|
|
6073
|
+
}
|
|
6074
|
+
|
|
6075
|
+
.summary-label {
|
|
6076
|
+
color: var(--text-secondary);
|
|
6077
|
+
font-size: 0.75rem;
|
|
6078
|
+
text-transform: uppercase;
|
|
6079
|
+
letter-spacing: 0.05em;
|
|
6080
|
+
}
|
|
6081
|
+
|
|
6082
|
+
.critical { color: var(--accent-red); }
|
|
6083
|
+
.warning { color: var(--accent-yellow); }
|
|
6084
|
+
.healthy { color: var(--accent-green); }
|
|
6085
|
+
.info { color: var(--accent-blue); }
|
|
6086
|
+
|
|
6087
|
+
/* Content */
|
|
6088
|
+
.content {
|
|
6089
|
+
display: grid;
|
|
6090
|
+
grid-template-columns: 2fr 1fr;
|
|
6091
|
+
gap: 1.5rem;
|
|
6092
|
+
margin-bottom: 1.5rem;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6095
|
+
@media (max-width: 900px) {
|
|
6096
|
+
.content {
|
|
6097
|
+
grid-template-columns: 1fr;
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
|
|
6101
|
+
.panel {
|
|
6102
|
+
background: var(--bg-secondary);
|
|
6103
|
+
border-radius: 8px;
|
|
6104
|
+
overflow: hidden;
|
|
6105
|
+
}
|
|
6106
|
+
|
|
6107
|
+
.panel-header {
|
|
6108
|
+
display: flex;
|
|
6109
|
+
justify-content: space-between;
|
|
6110
|
+
align-items: center;
|
|
6111
|
+
padding: 1rem;
|
|
6112
|
+
border-bottom: 1px solid var(--border-color);
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6115
|
+
.panel-header h2 {
|
|
6116
|
+
font-size: 1rem;
|
|
6117
|
+
font-weight: 600;
|
|
6118
|
+
}
|
|
6119
|
+
|
|
6120
|
+
.search-input {
|
|
6121
|
+
padding: 0.5rem 0.75rem;
|
|
6122
|
+
background: var(--bg-tertiary);
|
|
6123
|
+
border: 1px solid var(--border-color);
|
|
6124
|
+
border-radius: 6px;
|
|
6125
|
+
color: var(--text-primary);
|
|
6126
|
+
font-size: 0.875rem;
|
|
6127
|
+
width: 200px;
|
|
6128
|
+
}
|
|
6129
|
+
|
|
6130
|
+
.search-input:focus {
|
|
6131
|
+
outline: none;
|
|
6132
|
+
border-color: var(--accent-blue);
|
|
6133
|
+
}
|
|
6134
|
+
|
|
6135
|
+
.search-input::placeholder {
|
|
6136
|
+
color: var(--text-secondary);
|
|
6137
|
+
}
|
|
6138
|
+
|
|
6139
|
+
/* Table */
|
|
6140
|
+
.table-container {
|
|
6141
|
+
max-height: 400px;
|
|
6142
|
+
overflow-y: auto;
|
|
6143
|
+
}
|
|
6144
|
+
|
|
6145
|
+
.component-table {
|
|
6146
|
+
width: 100%;
|
|
6147
|
+
border-collapse: collapse;
|
|
6148
|
+
}
|
|
6149
|
+
|
|
6150
|
+
.component-table th,
|
|
6151
|
+
.component-table td {
|
|
6152
|
+
padding: 0.75rem 1rem;
|
|
6153
|
+
text-align: left;
|
|
6154
|
+
}
|
|
6155
|
+
|
|
6156
|
+
.component-table th {
|
|
6157
|
+
background: var(--bg-tertiary);
|
|
6158
|
+
font-size: 0.75rem;
|
|
6159
|
+
text-transform: uppercase;
|
|
6160
|
+
color: var(--text-secondary);
|
|
6161
|
+
position: sticky;
|
|
6162
|
+
top: 0;
|
|
6163
|
+
z-index: 1;
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
.component-table th.sortable {
|
|
6167
|
+
cursor: pointer;
|
|
6168
|
+
}
|
|
6169
|
+
|
|
6170
|
+
.component-table th.sortable:hover {
|
|
6171
|
+
color: var(--text-primary);
|
|
6172
|
+
}
|
|
6173
|
+
|
|
6174
|
+
.component-table th.sorted-asc::after {
|
|
6175
|
+
content: ' \u2191';
|
|
6176
|
+
}
|
|
6177
|
+
|
|
6178
|
+
.component-table th.sorted-desc::after {
|
|
6179
|
+
content: ' \u2193';
|
|
6180
|
+
}
|
|
6181
|
+
|
|
6182
|
+
.component-table tbody tr {
|
|
6183
|
+
border-bottom: 1px solid var(--border-color);
|
|
6184
|
+
transition: background 0.2s;
|
|
6185
|
+
}
|
|
6186
|
+
|
|
6187
|
+
.component-table tbody tr:hover {
|
|
6188
|
+
background: var(--bg-tertiary);
|
|
6189
|
+
}
|
|
6190
|
+
|
|
6191
|
+
.component-table tbody tr.new-row {
|
|
6192
|
+
animation: highlight 1s ease-out;
|
|
6193
|
+
}
|
|
6194
|
+
|
|
6195
|
+
@keyframes highlight {
|
|
6196
|
+
from { background: rgba(59, 130, 246, 0.2); }
|
|
6197
|
+
to { background: transparent; }
|
|
6198
|
+
}
|
|
6199
|
+
|
|
6200
|
+
.component-name {
|
|
6201
|
+
font-weight: 500;
|
|
6202
|
+
display: flex;
|
|
6203
|
+
align-items: center;
|
|
6204
|
+
gap: 0.5rem;
|
|
6205
|
+
}
|
|
6206
|
+
|
|
6207
|
+
.severity-badge {
|
|
6208
|
+
display: inline-block;
|
|
6209
|
+
padding: 0.125rem 0.5rem;
|
|
6210
|
+
border-radius: 9999px;
|
|
6211
|
+
font-size: 0.75rem;
|
|
6212
|
+
font-weight: 500;
|
|
6213
|
+
}
|
|
6214
|
+
|
|
6215
|
+
.severity-badge.critical {
|
|
6216
|
+
background: rgba(239, 68, 68, 0.2);
|
|
6217
|
+
}
|
|
6218
|
+
|
|
6219
|
+
.severity-badge.warning {
|
|
6220
|
+
background: rgba(234, 179, 8, 0.2);
|
|
6221
|
+
}
|
|
6222
|
+
|
|
6223
|
+
.severity-badge.healthy {
|
|
6224
|
+
background: rgba(34, 197, 94, 0.2);
|
|
6225
|
+
}
|
|
6226
|
+
|
|
6227
|
+
.empty-row td {
|
|
6228
|
+
text-align: center;
|
|
6229
|
+
color: var(--text-secondary);
|
|
6230
|
+
padding: 2rem;
|
|
6231
|
+
}
|
|
6232
|
+
|
|
6233
|
+
/* Events */
|
|
6234
|
+
.events-container {
|
|
6235
|
+
max-height: 400px;
|
|
6236
|
+
overflow-y: auto;
|
|
6237
|
+
padding: 0.5rem;
|
|
6238
|
+
}
|
|
6239
|
+
|
|
6240
|
+
.event-count {
|
|
6241
|
+
font-size: 0.75rem;
|
|
6242
|
+
color: var(--text-secondary);
|
|
6243
|
+
}
|
|
6244
|
+
|
|
6245
|
+
.event-item {
|
|
6246
|
+
display: flex;
|
|
6247
|
+
align-items: center;
|
|
6248
|
+
gap: 0.5rem;
|
|
6249
|
+
padding: 0.5rem;
|
|
6250
|
+
border-radius: 4px;
|
|
6251
|
+
font-size: 0.875rem;
|
|
6252
|
+
animation: slideIn 0.3s ease-out;
|
|
6253
|
+
}
|
|
6254
|
+
|
|
6255
|
+
@keyframes slideIn {
|
|
6256
|
+
from {
|
|
6257
|
+
opacity: 0;
|
|
6258
|
+
transform: translateX(-10px);
|
|
6259
|
+
}
|
|
6260
|
+
to {
|
|
6261
|
+
opacity: 1;
|
|
6262
|
+
transform: translateX(0);
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
|
|
6266
|
+
.event-item:nth-child(odd) {
|
|
6267
|
+
background: var(--bg-tertiary);
|
|
6268
|
+
}
|
|
6269
|
+
|
|
6270
|
+
.event-dot {
|
|
6271
|
+
width: 6px;
|
|
6272
|
+
height: 6px;
|
|
6273
|
+
border-radius: 50%;
|
|
6274
|
+
flex-shrink: 0;
|
|
6275
|
+
}
|
|
6276
|
+
|
|
6277
|
+
.event-name {
|
|
6278
|
+
flex: 1;
|
|
6279
|
+
overflow: hidden;
|
|
6280
|
+
text-overflow: ellipsis;
|
|
6281
|
+
white-space: nowrap;
|
|
6282
|
+
}
|
|
6283
|
+
|
|
6284
|
+
.event-time {
|
|
6285
|
+
font-size: 0.75rem;
|
|
6286
|
+
color: var(--text-secondary);
|
|
6287
|
+
}
|
|
6288
|
+
|
|
6289
|
+
.empty-message {
|
|
6290
|
+
color: var(--text-secondary);
|
|
6291
|
+
text-align: center;
|
|
6292
|
+
padding: 2rem;
|
|
6293
|
+
font-size: 0.875rem;
|
|
6294
|
+
}
|
|
6295
|
+
|
|
6296
|
+
/* Chains */
|
|
6297
|
+
.chains-section .panel {
|
|
6298
|
+
min-height: 150px;
|
|
6299
|
+
}
|
|
6300
|
+
|
|
6301
|
+
.chains-container {
|
|
6302
|
+
padding: 1rem;
|
|
6303
|
+
max-height: 300px;
|
|
6304
|
+
overflow-y: auto;
|
|
6305
|
+
}
|
|
6306
|
+
|
|
6307
|
+
.chain-item {
|
|
6308
|
+
background: var(--bg-tertiary);
|
|
6309
|
+
border-radius: 6px;
|
|
6310
|
+
padding: 1rem;
|
|
6311
|
+
margin-bottom: 0.75rem;
|
|
6312
|
+
animation: slideIn 0.3s ease-out;
|
|
6313
|
+
}
|
|
6314
|
+
|
|
6315
|
+
.chain-trigger {
|
|
6316
|
+
font-weight: 500;
|
|
6317
|
+
margin-bottom: 0.5rem;
|
|
6318
|
+
color: var(--accent-purple);
|
|
6319
|
+
}
|
|
6320
|
+
|
|
6321
|
+
.chain-flow {
|
|
6322
|
+
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
6323
|
+
font-size: 0.875rem;
|
|
6324
|
+
color: var(--text-secondary);
|
|
6325
|
+
overflow-x: auto;
|
|
6326
|
+
white-space: nowrap;
|
|
6327
|
+
padding: 0.5rem 0;
|
|
6328
|
+
}
|
|
6329
|
+
|
|
6330
|
+
.chain-flow span {
|
|
6331
|
+
color: var(--text-primary);
|
|
6332
|
+
}
|
|
6333
|
+
|
|
6334
|
+
.chain-flow .arrow {
|
|
6335
|
+
color: var(--accent-yellow);
|
|
6336
|
+
margin: 0 0.25rem;
|
|
6337
|
+
}
|
|
6338
|
+
|
|
6339
|
+
.chain-meta {
|
|
6340
|
+
font-size: 0.75rem;
|
|
6341
|
+
color: var(--text-secondary);
|
|
6342
|
+
margin-top: 0.5rem;
|
|
6343
|
+
}
|
|
6344
|
+
|
|
6345
|
+
/* Scrollbar */
|
|
6346
|
+
::-webkit-scrollbar {
|
|
6347
|
+
width: 8px;
|
|
6348
|
+
height: 8px;
|
|
6349
|
+
}
|
|
6350
|
+
|
|
6351
|
+
::-webkit-scrollbar-track {
|
|
6352
|
+
background: var(--bg-primary);
|
|
6353
|
+
}
|
|
6354
|
+
|
|
6355
|
+
::-webkit-scrollbar-thumb {
|
|
6356
|
+
background: var(--border-color);
|
|
6357
|
+
border-radius: 4px;
|
|
6358
|
+
}
|
|
6359
|
+
|
|
6360
|
+
::-webkit-scrollbar-thumb:hover {
|
|
6361
|
+
background: var(--text-secondary);
|
|
6362
|
+
}
|
|
6363
|
+
`;
|
|
6364
|
+
}
|
|
6365
|
+
function getScript(wsPort) {
|
|
6366
|
+
return `
|
|
6367
|
+
(function() {
|
|
6368
|
+
// State
|
|
6369
|
+
let ws = null;
|
|
6370
|
+
let state = null;
|
|
6371
|
+
let startTime = Date.now();
|
|
6372
|
+
let eventCount = 0;
|
|
6373
|
+
let sortColumn = 'renders';
|
|
6374
|
+
let sortDirection = 'desc';
|
|
6375
|
+
let searchQuery = '';
|
|
6376
|
+
|
|
6377
|
+
// Elements
|
|
6378
|
+
const statusEl = document.getElementById('status');
|
|
6379
|
+
const statusTextEl = statusEl.querySelector('.status-text');
|
|
6380
|
+
const durationEl = document.getElementById('duration');
|
|
6381
|
+
const componentsEl = document.getElementById('components');
|
|
6382
|
+
const rendersEl = document.getElementById('renders');
|
|
6383
|
+
const criticalEl = document.getElementById('critical');
|
|
6384
|
+
const warningsEl = document.getElementById('warnings');
|
|
6385
|
+
const healthyEl = document.getElementById('healthy');
|
|
6386
|
+
const fpsEl = document.getElementById('fps');
|
|
6387
|
+
const componentListEl = document.getElementById('component-list');
|
|
6388
|
+
const eventsEl = document.getElementById('events');
|
|
6389
|
+
const eventCountEl = document.getElementById('event-count');
|
|
6390
|
+
const chainsEl = document.getElementById('chains');
|
|
6391
|
+
const searchEl = document.getElementById('search');
|
|
6392
|
+
const exportBtn = document.getElementById('export-btn');
|
|
6393
|
+
|
|
6394
|
+
// Connect to WebSocket
|
|
6395
|
+
function connect() {
|
|
6396
|
+
ws = new WebSocket('ws://localhost:${wsPort}');
|
|
6397
|
+
|
|
6398
|
+
ws.onopen = () => {
|
|
6399
|
+
statusEl.className = 'status connected';
|
|
6400
|
+
statusTextEl.textContent = 'Connected';
|
|
6401
|
+
exportBtn.disabled = false;
|
|
6402
|
+
};
|
|
6403
|
+
|
|
6404
|
+
ws.onclose = () => {
|
|
6405
|
+
statusEl.className = 'status';
|
|
6406
|
+
statusTextEl.textContent = 'Disconnected';
|
|
6407
|
+
exportBtn.disabled = true;
|
|
6408
|
+
setTimeout(connect, 2000);
|
|
6409
|
+
};
|
|
6410
|
+
|
|
6411
|
+
ws.onerror = () => {
|
|
6412
|
+
ws.close();
|
|
6413
|
+
};
|
|
6414
|
+
|
|
6415
|
+
ws.onmessage = (event) => {
|
|
6416
|
+
try {
|
|
6417
|
+
const msg = JSON.parse(event.data);
|
|
6418
|
+
handleMessage(msg);
|
|
6419
|
+
} catch (e) {
|
|
6420
|
+
console.error('Failed to parse message:', e);
|
|
6421
|
+
}
|
|
6422
|
+
};
|
|
6423
|
+
}
|
|
6424
|
+
|
|
6425
|
+
// Handle incoming messages
|
|
6426
|
+
function handleMessage(msg) {
|
|
6427
|
+
switch (msg.type) {
|
|
6428
|
+
case 'state':
|
|
6429
|
+
state = msg.payload;
|
|
6430
|
+
startTime = msg.payload.startTime;
|
|
6431
|
+
updateStatus(msg.payload);
|
|
6432
|
+
updateSummary(msg.payload.summary);
|
|
6433
|
+
renderComponents(msg.payload.components);
|
|
6434
|
+
renderChains(msg.payload.chains);
|
|
6435
|
+
break;
|
|
6436
|
+
|
|
6437
|
+
case 'summary-update':
|
|
6438
|
+
updateSummary(msg.payload);
|
|
6439
|
+
break;
|
|
6440
|
+
|
|
6441
|
+
case 'component-update':
|
|
6442
|
+
updateComponent(msg.payload);
|
|
6443
|
+
break;
|
|
6444
|
+
|
|
6445
|
+
case 'render-event':
|
|
6446
|
+
addEvent(msg.payload);
|
|
6447
|
+
break;
|
|
6448
|
+
|
|
6449
|
+
case 'chain-detected':
|
|
6450
|
+
addChain(msg.payload);
|
|
6451
|
+
break;
|
|
6452
|
+
|
|
6453
|
+
case 'scanning-status':
|
|
6454
|
+
updateScanningStatus(msg.payload);
|
|
6455
|
+
break;
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
// Update status
|
|
6460
|
+
function updateStatus(data) {
|
|
6461
|
+
if (data.scanning && !data.paused) {
|
|
6462
|
+
statusEl.className = 'status scanning';
|
|
6463
|
+
statusTextEl.textContent = 'Scanning';
|
|
6464
|
+
} else if (data.paused) {
|
|
6465
|
+
statusEl.className = 'status paused';
|
|
6466
|
+
statusTextEl.textContent = 'Paused';
|
|
6467
|
+
} else {
|
|
6468
|
+
statusEl.className = 'status connected';
|
|
6469
|
+
statusTextEl.textContent = 'Connected';
|
|
6470
|
+
}
|
|
6471
|
+
}
|
|
6472
|
+
|
|
6473
|
+
function updateScanningStatus(data) {
|
|
6474
|
+
if (data.scanning && !data.paused) {
|
|
6475
|
+
statusEl.className = 'status scanning';
|
|
6476
|
+
statusTextEl.textContent = 'Scanning';
|
|
6477
|
+
} else if (data.paused) {
|
|
6478
|
+
statusEl.className = 'status paused';
|
|
6479
|
+
statusTextEl.textContent = 'Paused';
|
|
6480
|
+
} else {
|
|
6481
|
+
statusEl.className = 'status connected';
|
|
6482
|
+
statusTextEl.textContent = 'Connected';
|
|
6483
|
+
}
|
|
6484
|
+
}
|
|
6485
|
+
|
|
6486
|
+
// Update summary with animation
|
|
6487
|
+
function updateSummary(summary) {
|
|
6488
|
+
animateValue(componentsEl, summary.totalComponents);
|
|
6489
|
+
animateValue(rendersEl, summary.totalRenders);
|
|
6490
|
+
animateValue(criticalEl, summary.criticalIssues);
|
|
6491
|
+
animateValue(warningsEl, summary.warnings);
|
|
6492
|
+
animateValue(healthyEl, summary.healthy);
|
|
6493
|
+
animateValue(fpsEl, summary.avgFps);
|
|
6494
|
+
}
|
|
6495
|
+
|
|
6496
|
+
function animateValue(el, value) {
|
|
6497
|
+
const current = parseInt(el.textContent) || 0;
|
|
6498
|
+
if (current !== value) {
|
|
6499
|
+
el.textContent = value;
|
|
6500
|
+
el.classList.add('updated');
|
|
6501
|
+
setTimeout(() => el.classList.remove('updated'), 300);
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
6504
|
+
|
|
6505
|
+
// Update single component
|
|
6506
|
+
function updateComponent(component) {
|
|
6507
|
+
if (!state) state = { components: [] };
|
|
6508
|
+
const idx = state.components.findIndex(c => c.name === component.name);
|
|
6509
|
+
if (idx >= 0) {
|
|
6510
|
+
state.components[idx] = component;
|
|
6511
|
+
} else {
|
|
6512
|
+
state.components.push(component);
|
|
6513
|
+
}
|
|
6514
|
+
renderComponents(state.components);
|
|
6515
|
+
}
|
|
6516
|
+
|
|
6517
|
+
// Render components table
|
|
6518
|
+
function renderComponents(components) {
|
|
6519
|
+
if (!components || components.length === 0) {
|
|
6520
|
+
componentListEl.innerHTML = '<tr class="empty-row"><td colspan="5">No components detected yet...</td></tr>';
|
|
6521
|
+
return;
|
|
6522
|
+
}
|
|
6523
|
+
|
|
6524
|
+
// Filter
|
|
6525
|
+
let filtered = components;
|
|
6526
|
+
if (searchQuery) {
|
|
6527
|
+
filtered = components.filter(c =>
|
|
6528
|
+
c.name.toLowerCase().includes(searchQuery.toLowerCase())
|
|
6529
|
+
);
|
|
6530
|
+
}
|
|
6531
|
+
|
|
6532
|
+
// Sort
|
|
6533
|
+
filtered.sort((a, b) => {
|
|
6534
|
+
let aVal, bVal;
|
|
6535
|
+
switch (sortColumn) {
|
|
6536
|
+
case 'name': aVal = a.name; bVal = b.name; break;
|
|
6537
|
+
case 'renders': aVal = a.renders; bVal = b.renders; break;
|
|
6538
|
+
case 'unnecessary': aVal = a.unnecessary; bVal = b.unnecessary; break;
|
|
6539
|
+
case 'avgTime': aVal = a.avgRenderTime; bVal = b.avgRenderTime; break;
|
|
6540
|
+
case 'severity':
|
|
6541
|
+
const order = { critical: 0, warning: 1, info: 2, healthy: 3 };
|
|
6542
|
+
aVal = order[a.severity] ?? 4;
|
|
6543
|
+
bVal = order[b.severity] ?? 4;
|
|
6544
|
+
break;
|
|
6545
|
+
default: aVal = a.renders; bVal = b.renders;
|
|
6546
|
+
}
|
|
6547
|
+
if (typeof aVal === 'string') {
|
|
6548
|
+
return sortDirection === 'asc' ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal);
|
|
6549
|
+
}
|
|
6550
|
+
return sortDirection === 'asc' ? aVal - bVal : bVal - aVal;
|
|
6551
|
+
});
|
|
6552
|
+
|
|
6553
|
+
componentListEl.innerHTML = filtered.slice(0, 100).map(c => \`
|
|
6554
|
+
<tr data-name="\${escapeHtml(c.name)}">
|
|
6555
|
+
<td class="component-name">
|
|
6556
|
+
<span class="severity-indicator \${c.severity}"></span>
|
|
6557
|
+
\${escapeHtml(c.name)}
|
|
6558
|
+
</td>
|
|
6559
|
+
<td>\${c.renders}</td>
|
|
6560
|
+
<td>\${c.unnecessary}</td>
|
|
6561
|
+
<td>\${c.avgRenderTime.toFixed(2)}ms</td>
|
|
6562
|
+
<td><span class="severity-badge \${c.severity}">\${c.severity}</span></td>
|
|
6563
|
+
</tr>
|
|
6564
|
+
\`).join('');
|
|
6565
|
+
}
|
|
6566
|
+
|
|
6567
|
+
// Add event to timeline
|
|
6568
|
+
function addEvent(render) {
|
|
6569
|
+
eventCount++;
|
|
6570
|
+
eventCountEl.textContent = eventCount + ' events';
|
|
6571
|
+
|
|
6572
|
+
const isEmpty = eventsEl.querySelector('.empty-message');
|
|
6573
|
+
if (isEmpty) isEmpty.remove();
|
|
6574
|
+
|
|
6575
|
+
const severityColor = {
|
|
6576
|
+
critical: 'var(--accent-red)',
|
|
6577
|
+
warning: 'var(--accent-yellow)',
|
|
6578
|
+
info: 'var(--accent-blue)',
|
|
6579
|
+
healthy: 'var(--accent-green)'
|
|
6580
|
+
};
|
|
6581
|
+
|
|
6582
|
+
const color = render.renderCount > 50 ? severityColor.critical :
|
|
6583
|
+
render.renderCount > 20 ? severityColor.warning :
|
|
6584
|
+
severityColor.healthy;
|
|
6585
|
+
|
|
6586
|
+
const time = new Date(render.timestamp || Date.now()).toLocaleTimeString();
|
|
6587
|
+
|
|
6588
|
+
const eventHtml = \`
|
|
6589
|
+
<div class="event-item">
|
|
6590
|
+
<div class="event-dot" style="background: \${color}"></div>
|
|
6591
|
+
<span class="event-name">\${escapeHtml(render.componentName)}</span>
|
|
6592
|
+
<span class="event-time">\${time}</span>
|
|
6593
|
+
</div>
|
|
6594
|
+
\`;
|
|
6595
|
+
|
|
6596
|
+
eventsEl.insertAdjacentHTML('afterbegin', eventHtml);
|
|
6597
|
+
|
|
6598
|
+
// Keep only last 100 events
|
|
6599
|
+
while (eventsEl.children.length > 100) {
|
|
6600
|
+
eventsEl.lastChild.remove();
|
|
6601
|
+
}
|
|
6602
|
+
}
|
|
6603
|
+
|
|
6604
|
+
// Render chains
|
|
6605
|
+
function renderChains(chains) {
|
|
6606
|
+
if (!chains || chains.length === 0) {
|
|
6607
|
+
chainsEl.innerHTML = '<div class="empty-message">No render chains detected yet...</div>';
|
|
6608
|
+
return;
|
|
6609
|
+
}
|
|
6610
|
+
|
|
6611
|
+
chainsEl.innerHTML = chains.slice(0, 10).map(chain => \`
|
|
6612
|
+
<div class="chain-item">
|
|
6613
|
+
<div class="chain-trigger">Trigger: \${escapeHtml(chain.trigger)}</div>
|
|
6614
|
+
<div class="chain-flow">
|
|
6615
|
+
\${chain.chain.map((c, i) =>
|
|
6616
|
+
i === 0 ? \`<span style="color: var(--accent-red)">\${escapeHtml(c)}</span>\` :
|
|
6617
|
+
\`<span class="arrow">\u2192</span><span>\${escapeHtml(c)}</span>\`
|
|
6618
|
+
).join('')}
|
|
6619
|
+
</div>
|
|
6620
|
+
<div class="chain-meta">Depth: \${chain.depth} \u2022 Renders: \${chain.totalRenders}</div>
|
|
6621
|
+
</div>
|
|
6622
|
+
\`).join('');
|
|
6623
|
+
}
|
|
6624
|
+
|
|
6625
|
+
// Add chain
|
|
6626
|
+
function addChain(chain) {
|
|
6627
|
+
if (!state) state = { chains: [] };
|
|
6628
|
+
state.chains.unshift(chain);
|
|
6629
|
+
if (state.chains.length > 20) state.chains.pop();
|
|
6630
|
+
renderChains(state.chains);
|
|
6631
|
+
}
|
|
6632
|
+
|
|
6633
|
+
// Escape HTML
|
|
6634
|
+
function escapeHtml(str) {
|
|
6635
|
+
if (!str) return '';
|
|
6636
|
+
return str.replace(/&/g, '&')
|
|
6637
|
+
.replace(/</g, '<')
|
|
6638
|
+
.replace(/>/g, '>')
|
|
6639
|
+
.replace(/"/g, '"');
|
|
6640
|
+
}
|
|
6641
|
+
|
|
6642
|
+
// Update duration
|
|
6643
|
+
function updateDuration() {
|
|
6644
|
+
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
|
6645
|
+
const mins = Math.floor(elapsed / 60);
|
|
6646
|
+
const secs = elapsed % 60;
|
|
6647
|
+
durationEl.textContent = 'Duration: ' + (mins > 0 ? mins + 'm ' : '') + secs + 's';
|
|
6648
|
+
}
|
|
6649
|
+
|
|
6650
|
+
// Setup sorting
|
|
6651
|
+
document.querySelectorAll('.sortable').forEach(th => {
|
|
6652
|
+
th.addEventListener('click', () => {
|
|
6653
|
+
const column = th.dataset.sort;
|
|
6654
|
+
if (sortColumn === column) {
|
|
6655
|
+
sortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
|
|
6656
|
+
} else {
|
|
6657
|
+
sortColumn = column;
|
|
6658
|
+
sortDirection = 'desc';
|
|
6659
|
+
}
|
|
6660
|
+
|
|
6661
|
+
document.querySelectorAll('.sortable').forEach(el => {
|
|
6662
|
+
el.classList.remove('sorted-asc', 'sorted-desc');
|
|
6663
|
+
});
|
|
6664
|
+
th.classList.add(sortDirection === 'asc' ? 'sorted-asc' : 'sorted-desc');
|
|
6665
|
+
|
|
6666
|
+
if (state && state.components) {
|
|
6667
|
+
renderComponents(state.components);
|
|
6668
|
+
}
|
|
6669
|
+
});
|
|
6670
|
+
});
|
|
6671
|
+
|
|
6672
|
+
// Setup search
|
|
6673
|
+
searchEl.addEventListener('input', (e) => {
|
|
6674
|
+
searchQuery = e.target.value;
|
|
6675
|
+
if (state && state.components) {
|
|
6676
|
+
renderComponents(state.components);
|
|
6677
|
+
}
|
|
6678
|
+
});
|
|
6679
|
+
|
|
6680
|
+
// Setup export
|
|
6681
|
+
exportBtn.addEventListener('click', () => {
|
|
6682
|
+
if (!state) return;
|
|
6683
|
+
const data = JSON.stringify(state, null, 2);
|
|
6684
|
+
const blob = new Blob([data], { type: 'application/json' });
|
|
6685
|
+
const url = URL.createObjectURL(blob);
|
|
6686
|
+
const a = document.createElement('a');
|
|
6687
|
+
a.href = url;
|
|
6688
|
+
a.download = 'reactcheck-export-' + Date.now() + '.json';
|
|
6689
|
+
a.click();
|
|
6690
|
+
URL.revokeObjectURL(url);
|
|
6691
|
+
});
|
|
6692
|
+
|
|
6693
|
+
// Start
|
|
6694
|
+
connect();
|
|
6695
|
+
setInterval(updateDuration, 1000);
|
|
6696
|
+
|
|
6697
|
+
// Mark initial sort column
|
|
6698
|
+
document.querySelector('[data-sort="renders"]').classList.add('sorted-desc');
|
|
6699
|
+
})();
|
|
6700
|
+
`;
|
|
6701
|
+
}
|
|
6702
|
+
|
|
6703
|
+
// src/webui/server.ts
|
|
6704
|
+
var OPCODE2 = {
|
|
6705
|
+
CLOSE: 8,
|
|
6706
|
+
PING: 9};
|
|
6707
|
+
var WS_GUID2 = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
6708
|
+
var DashboardClient = class {
|
|
6709
|
+
socket;
|
|
6710
|
+
isOpen = true;
|
|
6711
|
+
constructor(socket) {
|
|
6712
|
+
this.socket = socket;
|
|
6713
|
+
this.socket.on("close", () => {
|
|
6714
|
+
this.isOpen = false;
|
|
6715
|
+
});
|
|
6716
|
+
this.socket.on("error", () => {
|
|
6717
|
+
this.isOpen = false;
|
|
6718
|
+
});
|
|
6719
|
+
}
|
|
6720
|
+
/**
|
|
6721
|
+
* Send a message to the client
|
|
6722
|
+
*/
|
|
6723
|
+
send(message) {
|
|
6724
|
+
if (!this.isOpen) return;
|
|
6725
|
+
try {
|
|
6726
|
+
const data = JSON.stringify(message);
|
|
6727
|
+
const frame = this.createFrame(data);
|
|
6728
|
+
this.socket.write(frame);
|
|
6729
|
+
} catch {
|
|
6730
|
+
}
|
|
6731
|
+
}
|
|
6732
|
+
/**
|
|
6733
|
+
* Create a WebSocket frame
|
|
6734
|
+
*/
|
|
6735
|
+
createFrame(data) {
|
|
6736
|
+
const payload = Buffer.from(data, "utf8");
|
|
6737
|
+
const length = payload.length;
|
|
6738
|
+
let frame;
|
|
6739
|
+
if (length < 126) {
|
|
6740
|
+
frame = Buffer.alloc(2 + length);
|
|
6741
|
+
frame[0] = 129;
|
|
6742
|
+
frame[1] = length;
|
|
6743
|
+
payload.copy(frame, 2);
|
|
6744
|
+
} else if (length < 65536) {
|
|
6745
|
+
frame = Buffer.alloc(4 + length);
|
|
6746
|
+
frame[0] = 129;
|
|
6747
|
+
frame[1] = 126;
|
|
6748
|
+
frame.writeUInt16BE(length, 2);
|
|
6749
|
+
payload.copy(frame, 4);
|
|
6750
|
+
} else {
|
|
6751
|
+
frame = Buffer.alloc(10 + length);
|
|
6752
|
+
frame[0] = 129;
|
|
6753
|
+
frame[1] = 127;
|
|
6754
|
+
frame.writeBigUInt64BE(BigInt(length), 2);
|
|
6755
|
+
payload.copy(frame, 10);
|
|
6756
|
+
}
|
|
6757
|
+
return frame;
|
|
6758
|
+
}
|
|
6759
|
+
/**
|
|
6760
|
+
* Close the connection
|
|
6761
|
+
*/
|
|
6762
|
+
close() {
|
|
6763
|
+
if (!this.isOpen) return;
|
|
6764
|
+
this.isOpen = false;
|
|
6765
|
+
try {
|
|
6766
|
+
const frame = Buffer.alloc(2);
|
|
6767
|
+
frame[0] = 136;
|
|
6768
|
+
frame[1] = 0;
|
|
6769
|
+
this.socket.write(frame);
|
|
6770
|
+
this.socket.end();
|
|
6771
|
+
} catch {
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6774
|
+
/**
|
|
6775
|
+
* Check if client is connected
|
|
6776
|
+
*/
|
|
6777
|
+
isConnected() {
|
|
6778
|
+
return this.isOpen;
|
|
6779
|
+
}
|
|
6780
|
+
};
|
|
6781
|
+
var WebUIServer = class extends EventEmitter {
|
|
6782
|
+
server = null;
|
|
6783
|
+
clients = /* @__PURE__ */ new Set();
|
|
6784
|
+
port;
|
|
6785
|
+
target;
|
|
6786
|
+
currentState;
|
|
6787
|
+
constructor(port = 3100, target = "") {
|
|
6788
|
+
super();
|
|
6789
|
+
this.port = port;
|
|
6790
|
+
this.target = target;
|
|
6791
|
+
this.currentState = this.createInitialState();
|
|
6792
|
+
}
|
|
6793
|
+
/**
|
|
6794
|
+
* Create initial dashboard state
|
|
6795
|
+
*/
|
|
6796
|
+
createInitialState() {
|
|
6797
|
+
return {
|
|
6798
|
+
target: this.target,
|
|
6799
|
+
startTime: Date.now(),
|
|
6800
|
+
scanning: false,
|
|
6801
|
+
paused: false,
|
|
6802
|
+
fps: 60,
|
|
6803
|
+
summary: {
|
|
6804
|
+
totalComponents: 0,
|
|
6805
|
+
totalRenders: 0,
|
|
6806
|
+
criticalIssues: 0,
|
|
6807
|
+
warnings: 0,
|
|
6808
|
+
healthy: 0,
|
|
6809
|
+
avgFps: 60,
|
|
6810
|
+
minFps: 60,
|
|
6811
|
+
unnecessaryRenders: 0
|
|
6812
|
+
},
|
|
6813
|
+
components: [],
|
|
6814
|
+
chains: [],
|
|
6815
|
+
recentRenders: []
|
|
6816
|
+
};
|
|
6817
|
+
}
|
|
6818
|
+
/**
|
|
6819
|
+
* Start the server
|
|
6820
|
+
*/
|
|
6821
|
+
async start() {
|
|
6822
|
+
return new Promise((resolve3, reject) => {
|
|
6823
|
+
this.server = createServer((req, res) => {
|
|
6824
|
+
this.handleHttpRequest(req, res);
|
|
6825
|
+
});
|
|
6826
|
+
this.server.on("upgrade", (req, socket, head) => {
|
|
6827
|
+
this.handleUpgrade(req, socket);
|
|
6828
|
+
});
|
|
6829
|
+
this.server.on("error", (error) => {
|
|
6830
|
+
if (error.code === "EADDRINUSE") {
|
|
6831
|
+
this.port++;
|
|
6832
|
+
this.server?.close();
|
|
6833
|
+
this.start().then(resolve3).catch(reject);
|
|
6834
|
+
} else {
|
|
6835
|
+
this.emit("error", error);
|
|
6836
|
+
reject(error);
|
|
6837
|
+
}
|
|
6838
|
+
});
|
|
6839
|
+
this.server.listen(this.port, () => {
|
|
6840
|
+
this.emit("listening", this.port);
|
|
6841
|
+
resolve3(this.port);
|
|
6842
|
+
});
|
|
6843
|
+
});
|
|
6844
|
+
}
|
|
6845
|
+
/**
|
|
6846
|
+
* Stop the server
|
|
6847
|
+
*/
|
|
6848
|
+
stop() {
|
|
6849
|
+
for (const client of this.clients) {
|
|
6850
|
+
client.close();
|
|
6851
|
+
}
|
|
6852
|
+
this.clients.clear();
|
|
6853
|
+
if (this.server) {
|
|
6854
|
+
this.server.close();
|
|
6855
|
+
this.server = null;
|
|
6856
|
+
}
|
|
6857
|
+
this.emit("close", void 0);
|
|
6858
|
+
}
|
|
6859
|
+
/**
|
|
6860
|
+
* Handle HTTP requests
|
|
6861
|
+
*/
|
|
6862
|
+
handleHttpRequest(req, res) {
|
|
6863
|
+
const url = req.url ?? "/";
|
|
6864
|
+
if (url === "/" || url === "/index.html") {
|
|
6865
|
+
const html = generateDashboardHTML(this.port, this.target);
|
|
6866
|
+
res.writeHead(200, {
|
|
6867
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
6868
|
+
"Cache-Control": "no-cache"
|
|
6869
|
+
});
|
|
6870
|
+
res.end(html);
|
|
6871
|
+
} else if (url === "/health") {
|
|
6872
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
6873
|
+
res.end(JSON.stringify({ status: "ok", clients: this.clients.size }));
|
|
6874
|
+
} else {
|
|
6875
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
6876
|
+
res.end("Not Found");
|
|
6877
|
+
}
|
|
6878
|
+
}
|
|
6879
|
+
/**
|
|
6880
|
+
* Handle WebSocket upgrade
|
|
6881
|
+
*/
|
|
6882
|
+
handleUpgrade(req, socket) {
|
|
6883
|
+
const key = req.headers["sec-websocket-key"];
|
|
6884
|
+
if (!key) {
|
|
6885
|
+
socket.destroy();
|
|
6886
|
+
return;
|
|
6887
|
+
}
|
|
6888
|
+
const acceptKey = createHash("sha1").update(key + WS_GUID2).digest("base64");
|
|
6889
|
+
const headers = [
|
|
6890
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
6891
|
+
"Upgrade: websocket",
|
|
6892
|
+
"Connection: Upgrade",
|
|
6893
|
+
`Sec-WebSocket-Accept: ${acceptKey}`,
|
|
6894
|
+
"",
|
|
6895
|
+
""
|
|
6896
|
+
].join("\r\n");
|
|
6897
|
+
socket.write(headers);
|
|
6898
|
+
const client = new DashboardClient(socket);
|
|
6899
|
+
this.clients.add(client);
|
|
6900
|
+
this.emit("client-connected", void 0);
|
|
6901
|
+
client.send({ type: "state", payload: this.currentState });
|
|
6902
|
+
socket.on("close", () => {
|
|
6903
|
+
this.clients.delete(client);
|
|
6904
|
+
this.emit("client-disconnected", void 0);
|
|
6905
|
+
});
|
|
6906
|
+
socket.on("data", (data) => {
|
|
6907
|
+
this.handleClientData(client, socket, data);
|
|
6908
|
+
});
|
|
6909
|
+
}
|
|
6910
|
+
/**
|
|
6911
|
+
* Handle data from client
|
|
6912
|
+
*/
|
|
6913
|
+
handleClientData(client, socket, data) {
|
|
6914
|
+
if (data.length < 2) return;
|
|
6915
|
+
const opcode = data[0] & 15;
|
|
6916
|
+
if (opcode === OPCODE2.PING) {
|
|
6917
|
+
const pong = Buffer.alloc(2);
|
|
6918
|
+
pong[0] = 138;
|
|
6919
|
+
pong[1] = 0;
|
|
6920
|
+
socket.write(pong);
|
|
6921
|
+
} else if (opcode === OPCODE2.CLOSE) {
|
|
6922
|
+
this.clients.delete(client);
|
|
6923
|
+
client.close();
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
/**
|
|
6927
|
+
* Update target URL
|
|
6928
|
+
*/
|
|
6929
|
+
setTarget(target) {
|
|
6930
|
+
this.target = target;
|
|
6931
|
+
this.currentState.target = target;
|
|
6932
|
+
}
|
|
6933
|
+
/**
|
|
6934
|
+
* Update scanning status
|
|
6935
|
+
*/
|
|
6936
|
+
setScanning(scanning, paused = false) {
|
|
6937
|
+
this.currentState.scanning = scanning;
|
|
6938
|
+
this.currentState.paused = paused;
|
|
6939
|
+
this.broadcast({ type: "scanning-status", payload: { scanning, paused } });
|
|
6940
|
+
}
|
|
6941
|
+
/**
|
|
6942
|
+
* Update summary
|
|
6943
|
+
*/
|
|
6944
|
+
updateSummary(summary) {
|
|
6945
|
+
this.currentState.summary = summary;
|
|
6946
|
+
this.broadcast({ type: "summary-update", payload: summary });
|
|
6947
|
+
}
|
|
6948
|
+
/**
|
|
6949
|
+
* Update components
|
|
6950
|
+
*/
|
|
6951
|
+
updateComponents(components) {
|
|
6952
|
+
this.currentState.components = components;
|
|
6953
|
+
}
|
|
6954
|
+
/**
|
|
6955
|
+
* Update FPS
|
|
6956
|
+
*/
|
|
6957
|
+
updateFps(fps) {
|
|
6958
|
+
this.currentState.fps = fps;
|
|
6959
|
+
}
|
|
6960
|
+
/**
|
|
6961
|
+
* Add render event
|
|
6962
|
+
*/
|
|
6963
|
+
addRenderEvent(render) {
|
|
6964
|
+
this.currentState.recentRenders.unshift(render);
|
|
6965
|
+
if (this.currentState.recentRenders.length > 50) {
|
|
6966
|
+
this.currentState.recentRenders.pop();
|
|
6967
|
+
}
|
|
6968
|
+
this.broadcast({ type: "render-event", payload: render });
|
|
6969
|
+
}
|
|
6970
|
+
/**
|
|
6971
|
+
* Add chain detected
|
|
6972
|
+
*/
|
|
6973
|
+
addChain(chain) {
|
|
6974
|
+
this.currentState.chains.unshift(chain);
|
|
6975
|
+
if (this.currentState.chains.length > 20) {
|
|
6976
|
+
this.currentState.chains.pop();
|
|
6977
|
+
}
|
|
6978
|
+
this.broadcast({ type: "chain-detected", payload: chain });
|
|
6979
|
+
}
|
|
6980
|
+
/**
|
|
6981
|
+
* Update component
|
|
6982
|
+
*/
|
|
6983
|
+
updateComponent(component) {
|
|
6984
|
+
const index = this.currentState.components.findIndex((c) => c.name === component.name);
|
|
6985
|
+
if (index >= 0) {
|
|
6986
|
+
this.currentState.components[index] = component;
|
|
6987
|
+
} else {
|
|
6988
|
+
this.currentState.components.push(component);
|
|
6989
|
+
}
|
|
6990
|
+
this.broadcast({ type: "component-update", payload: component });
|
|
6991
|
+
}
|
|
6992
|
+
/**
|
|
6993
|
+
* Broadcast full state to all clients
|
|
6994
|
+
*/
|
|
6995
|
+
broadcastState() {
|
|
6996
|
+
this.broadcast({ type: "state", payload: this.currentState });
|
|
6997
|
+
}
|
|
6998
|
+
/**
|
|
6999
|
+
* Broadcast message to all clients
|
|
7000
|
+
*/
|
|
7001
|
+
broadcast(message) {
|
|
7002
|
+
for (const client of this.clients) {
|
|
7003
|
+
if (client.isConnected()) {
|
|
7004
|
+
client.send(message);
|
|
7005
|
+
} else {
|
|
7006
|
+
this.clients.delete(client);
|
|
7007
|
+
}
|
|
7008
|
+
}
|
|
7009
|
+
}
|
|
7010
|
+
/**
|
|
7011
|
+
* Get current port
|
|
7012
|
+
*/
|
|
7013
|
+
getPort() {
|
|
7014
|
+
return this.port;
|
|
7015
|
+
}
|
|
7016
|
+
/**
|
|
7017
|
+
* Get client count
|
|
7018
|
+
*/
|
|
7019
|
+
getClientCount() {
|
|
7020
|
+
return this.clients.size;
|
|
7021
|
+
}
|
|
7022
|
+
/**
|
|
7023
|
+
* Get dashboard URL
|
|
7024
|
+
*/
|
|
7025
|
+
getUrl() {
|
|
7026
|
+
return `http://localhost:${this.port}`;
|
|
7027
|
+
}
|
|
7028
|
+
};
|
|
7029
|
+
var logger4 = new Logger({ prefix: "scan", level: 1 /* INFO */ });
|
|
7030
|
+
function parseScanOptions(args) {
|
|
7031
|
+
return {
|
|
7032
|
+
target: normalizeTarget(args.target ?? "localhost:3000"),
|
|
7033
|
+
proxy: getBooleanFlag(args, "proxy"),
|
|
7034
|
+
tui: getBooleanFlag(args, "tui"),
|
|
7035
|
+
silent: getBooleanFlag(args, "silent"),
|
|
7036
|
+
report: getBooleanFlag(args, "report"),
|
|
7037
|
+
format: getStringFlag(args, "format") ?? "all",
|
|
7038
|
+
output: getStringFlag(args, "output") ?? "./reactcheck-reports",
|
|
7039
|
+
fix: getBooleanFlag(args, "fix"),
|
|
7040
|
+
verbose: getBooleanFlag(args, "verbose"),
|
|
7041
|
+
port: getNumberFlag(args, "port") ?? 3099,
|
|
7042
|
+
thresholdCritical: getNumberFlag(args, "threshold-critical") ?? 50,
|
|
7043
|
+
thresholdWarning: getNumberFlag(args, "threshold-warning") ?? 20,
|
|
7044
|
+
fpsThreshold: getNumberFlag(args, "fps-threshold") ?? 30,
|
|
7045
|
+
headless: getBooleanFlag(args, "headless"),
|
|
7046
|
+
duration: getNumberFlag(args, "duration"),
|
|
7047
|
+
watch: getBooleanFlag(args, "watch"),
|
|
7048
|
+
configPath: getStringFlag(args, "config"),
|
|
7049
|
+
webui: getBooleanFlag(args, "webui"),
|
|
7050
|
+
webuiPort: getNumberFlag(args, "webui-port") ?? 3100
|
|
7051
|
+
};
|
|
7052
|
+
}
|
|
7053
|
+
async function getInjectionScript(wsPort) {
|
|
7054
|
+
try {
|
|
7055
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
7056
|
+
const currentDir = dirname(currentFile);
|
|
7057
|
+
const scriptPath = resolve(currentDir, "browser-inject.global.js");
|
|
7058
|
+
logger4.debug(`Loading injection script from: ${scriptPath}`);
|
|
7059
|
+
const script = await readTextFile(scriptPath);
|
|
7060
|
+
return `window.__REACTCHECK_PORT__ = ${wsPort};
|
|
7061
|
+
${script}`;
|
|
7062
|
+
} catch (error) {
|
|
7063
|
+
logger4.debug(`Failed to load injection script: ${error}`);
|
|
7064
|
+
logger4.warn("Could not load injection script, using minimal version");
|
|
7065
|
+
return `
|
|
7066
|
+
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
7067
|
+
window.__REACTCHECK_INJECTED__ = true;
|
|
7068
|
+
|
|
7069
|
+
// Install React DevTools hook
|
|
7070
|
+
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
7071
|
+
const hook = {
|
|
7072
|
+
renderers: new Map(),
|
|
7073
|
+
supportsFiber: true,
|
|
7074
|
+
inject: function(renderer) {
|
|
7075
|
+
const id = this.renderers.size + 1;
|
|
7076
|
+
this.renderers.set(id, renderer);
|
|
7077
|
+
return id;
|
|
7078
|
+
},
|
|
7079
|
+
onCommitFiberRoot: function(id, root) {
|
|
7080
|
+
// Will be overwritten by full script
|
|
7081
|
+
},
|
|
7082
|
+
onCommitFiberUnmount: function() {},
|
|
7083
|
+
};
|
|
7084
|
+
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
7085
|
+
console.log('[ReactCheck] DevTools hook installed (minimal)');
|
|
7086
|
+
}
|
|
7087
|
+
`;
|
|
7088
|
+
}
|
|
7089
|
+
}
|
|
7090
|
+
async function runScanCommand(args) {
|
|
7091
|
+
const options = parseScanOptions(args);
|
|
7092
|
+
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
7093
|
+
if (fromFile) {
|
|
7094
|
+
logger4.info(`Using config: ${configPath}`);
|
|
7095
|
+
}
|
|
7096
|
+
const configOptions = configToOptions(config);
|
|
7097
|
+
const mergedOptions = {
|
|
7098
|
+
...options,
|
|
7099
|
+
thresholdCritical: options.thresholdCritical ?? configOptions.thresholds.critical,
|
|
7100
|
+
thresholdWarning: options.thresholdWarning ?? configOptions.thresholds.warning,
|
|
7101
|
+
fpsThreshold: options.fpsThreshold ?? configOptions.thresholds.fps,
|
|
7102
|
+
output: options.output ?? configOptions.report.output
|
|
7103
|
+
};
|
|
7104
|
+
const session = {
|
|
7105
|
+
id: generateId("scan"),
|
|
7106
|
+
startTime: Date.now(),
|
|
7107
|
+
scanner: new Scanner({
|
|
7108
|
+
thresholds: {
|
|
7109
|
+
critical: mergedOptions.thresholdCritical,
|
|
7110
|
+
warning: mergedOptions.thresholdWarning,
|
|
7111
|
+
fps: mergedOptions.fpsThreshold
|
|
7112
|
+
}
|
|
7113
|
+
}),
|
|
7114
|
+
tui: null,
|
|
7115
|
+
wsServer: null,
|
|
7116
|
+
browser: null,
|
|
7117
|
+
webui: null,
|
|
7118
|
+
options: mergedOptions,
|
|
7119
|
+
active: true,
|
|
7120
|
+
chains: [],
|
|
7121
|
+
suggestions: [],
|
|
7122
|
+
overlayEnabled: true,
|
|
7123
|
+
browserClients: /* @__PURE__ */ new Set()
|
|
7124
|
+
};
|
|
7125
|
+
setupScannerEvents(session);
|
|
7126
|
+
const useTUI = !mergedOptions.silent && !mergedOptions.proxy;
|
|
7127
|
+
if (useTUI) {
|
|
7128
|
+
session.tui = new TUI(mergedOptions.target);
|
|
7129
|
+
setupTUIEvents(session);
|
|
7130
|
+
session.tui.setDataProvider(() => ({
|
|
7131
|
+
components: session.scanner.getSnapshot(),
|
|
7132
|
+
summary: session.scanner.getSummary(),
|
|
7133
|
+
fps: session.scanner.getFps()
|
|
7134
|
+
}));
|
|
7135
|
+
session.tui.start();
|
|
7136
|
+
}
|
|
7137
|
+
if (mergedOptions.webui) {
|
|
7138
|
+
session.webui = new WebUIServer(mergedOptions.webuiPort, mergedOptions.target);
|
|
7139
|
+
setupWebUIEvents(session);
|
|
7140
|
+
}
|
|
7141
|
+
if (!useTUI) {
|
|
7142
|
+
logger4.info(`Starting scan of ${mergedOptions.target}`);
|
|
5841
7143
|
}
|
|
5842
7144
|
if (useTUI) {
|
|
5843
7145
|
logger4.setLevel(4 /* SILENT */);
|
|
@@ -5848,6 +7150,7 @@ async function runScanCommand(args) {
|
|
|
5848
7150
|
logger4.info(`WebSocket server listening on port ${mergedOptions.port}`);
|
|
5849
7151
|
session.wsServer.on("connection", (client) => {
|
|
5850
7152
|
logger4.info("Browser connected");
|
|
7153
|
+
session.browserClients.add(client);
|
|
5851
7154
|
handleBrowserMessages(client, (message) => {
|
|
5852
7155
|
switch (message.type) {
|
|
5853
7156
|
case "render":
|
|
@@ -5856,6 +7159,7 @@ async function runScanCommand(args) {
|
|
|
5856
7159
|
case "ready":
|
|
5857
7160
|
logger4.info(`React detected: ${message.payload.reactVersion}`);
|
|
5858
7161
|
client.send(JSON.stringify({ type: "start" }));
|
|
7162
|
+
client.send(JSON.stringify({ type: "toggle-overlay", payload: { enabled: session.overlayEnabled } }));
|
|
5859
7163
|
break;
|
|
5860
7164
|
case "error":
|
|
5861
7165
|
logger4.error("Browser error:", message.payload.message);
|
|
@@ -5864,9 +7168,17 @@ async function runScanCommand(args) {
|
|
|
5864
7168
|
});
|
|
5865
7169
|
client.on("close", () => {
|
|
5866
7170
|
logger4.info("Browser disconnected");
|
|
7171
|
+
session.browserClients.delete(client);
|
|
5867
7172
|
});
|
|
5868
7173
|
});
|
|
5869
7174
|
session.scanner.start();
|
|
7175
|
+
if (session.webui) {
|
|
7176
|
+
const webuiPort = await session.webui.start();
|
|
7177
|
+
session.webui.setScanning(true);
|
|
7178
|
+
const webuiUrl = session.webui.getUrl();
|
|
7179
|
+
logger4.info(`WebUI dashboard: ${webuiUrl}`);
|
|
7180
|
+
openBrowser(webuiUrl);
|
|
7181
|
+
}
|
|
5870
7182
|
if (mergedOptions.proxy) {
|
|
5871
7183
|
console.log("");
|
|
5872
7184
|
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);
|
|
@@ -5940,6 +7252,9 @@ async function cleanupSession(session) {
|
|
|
5940
7252
|
if (session.tui) {
|
|
5941
7253
|
session.tui.stop();
|
|
5942
7254
|
}
|
|
7255
|
+
if (session.webui) {
|
|
7256
|
+
session.webui.stop();
|
|
7257
|
+
}
|
|
5943
7258
|
if (session.browser) {
|
|
5944
7259
|
await session.browser.close();
|
|
5945
7260
|
}
|
|
@@ -5949,7 +7264,7 @@ async function cleanupSession(session) {
|
|
|
5949
7264
|
}
|
|
5950
7265
|
function setupScannerEvents(session) {
|
|
5951
7266
|
const { scanner } = session;
|
|
5952
|
-
scanner.on("render", (
|
|
7267
|
+
scanner.on("render", () => {
|
|
5953
7268
|
if (session.tui) {
|
|
5954
7269
|
const snapshot = scanner.getSnapshot();
|
|
5955
7270
|
const summary = scanner.getSummary();
|
|
@@ -6012,6 +7327,20 @@ function setupTUIEvents(session) {
|
|
|
6012
7327
|
));
|
|
6013
7328
|
tui.update({ suggestions: session.suggestions });
|
|
6014
7329
|
});
|
|
7330
|
+
tui.on("toggleOverlay", () => {
|
|
7331
|
+
session.overlayEnabled = !session.overlayEnabled;
|
|
7332
|
+
tui.update({ overlayEnabled: session.overlayEnabled });
|
|
7333
|
+
const message = JSON.stringify({
|
|
7334
|
+
type: "toggle-overlay",
|
|
7335
|
+
payload: { enabled: session.overlayEnabled }
|
|
7336
|
+
});
|
|
7337
|
+
for (const client of session.browserClients) {
|
|
7338
|
+
try {
|
|
7339
|
+
client.send(message);
|
|
7340
|
+
} catch {
|
|
7341
|
+
}
|
|
7342
|
+
}
|
|
7343
|
+
});
|
|
6015
7344
|
}
|
|
6016
7345
|
async function waitForQuit(session) {
|
|
6017
7346
|
return new Promise((resolve3) => {
|
|
@@ -6131,6 +7460,45 @@ function printFixSuggestions(suggestions) {
|
|
|
6131
7460
|
console.log("");
|
|
6132
7461
|
}
|
|
6133
7462
|
}
|
|
7463
|
+
function setupWebUIEvents(session) {
|
|
7464
|
+
const { scanner, webui } = session;
|
|
7465
|
+
if (!webui) return;
|
|
7466
|
+
scanner.on("render", (render) => {
|
|
7467
|
+
webui.addRenderEvent(render);
|
|
7468
|
+
webui.updateSummary(scanner.getSummary());
|
|
7469
|
+
webui.updateComponents(scanner.getSnapshot());
|
|
7470
|
+
webui.updateFps(scanner.getFps());
|
|
7471
|
+
});
|
|
7472
|
+
scanner.on("chain", (chain) => {
|
|
7473
|
+
webui.addChain(chain);
|
|
7474
|
+
});
|
|
7475
|
+
scanner.on("severityChange", ({ component }) => {
|
|
7476
|
+
const stats = scanner.getSnapshot().find((c) => c.name === component);
|
|
7477
|
+
if (stats) {
|
|
7478
|
+
webui.updateComponent(stats);
|
|
7479
|
+
}
|
|
7480
|
+
});
|
|
7481
|
+
}
|
|
7482
|
+
function openBrowser(url) {
|
|
7483
|
+
const platform = process.platform;
|
|
7484
|
+
let command;
|
|
7485
|
+
switch (platform) {
|
|
7486
|
+
case "darwin":
|
|
7487
|
+
command = `open "${url}"`;
|
|
7488
|
+
break;
|
|
7489
|
+
case "win32":
|
|
7490
|
+
command = `start "" "${url}"`;
|
|
7491
|
+
break;
|
|
7492
|
+
default:
|
|
7493
|
+
command = `xdg-open "${url}"`;
|
|
7494
|
+
break;
|
|
7495
|
+
}
|
|
7496
|
+
exec(command, (error) => {
|
|
7497
|
+
if (error) {
|
|
7498
|
+
logger4.debug(`Failed to open browser: ${error.message}`);
|
|
7499
|
+
}
|
|
7500
|
+
});
|
|
7501
|
+
}
|
|
6134
7502
|
|
|
6135
7503
|
// src/cli/commands/init.ts
|
|
6136
7504
|
init_fs();
|