@arx-hq/collectors-browser 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/index.d.ts +120 -0
- package/dist/index.js +1769 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1769 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { ARX_SCHEMA_VERSION } from "@arx-hq/contracts";
|
|
3
|
+
|
|
4
|
+
// src/browser-probe.ts
|
|
5
|
+
async function dynamicImportOptional(moduleName) {
|
|
6
|
+
try {
|
|
7
|
+
return await import(moduleName);
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function createPlaywrightBrowserProbe() {
|
|
13
|
+
return {
|
|
14
|
+
async probeUrl(url, viewports) {
|
|
15
|
+
const pw = await dynamicImportOptional("playwright");
|
|
16
|
+
if (!pw?.chromium) {
|
|
17
|
+
return {
|
|
18
|
+
available: false,
|
|
19
|
+
reason: "Optional peer dependency 'playwright' is not installed; live T3 viewport probe skipped.",
|
|
20
|
+
url,
|
|
21
|
+
viewports: []
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const axeMod = await dynamicImportOptional(
|
|
25
|
+
"@axe-core/playwright"
|
|
26
|
+
);
|
|
27
|
+
const AxeCtor = axeMod?.AxeBuilder ?? axeMod?.default;
|
|
28
|
+
const browser = await pw.chromium.launch({ headless: true });
|
|
29
|
+
try {
|
|
30
|
+
const snapshots = [];
|
|
31
|
+
for (const viewport of viewports) {
|
|
32
|
+
const page = await browser.newPage();
|
|
33
|
+
const consoleErrors = [];
|
|
34
|
+
const pageErrors = [];
|
|
35
|
+
page.on("console", (msg) => {
|
|
36
|
+
if (typeof msg === "object" && msg !== null && "type" in msg && "text" in msg && typeof msg.type === "function" && msg.type() === "error") {
|
|
37
|
+
consoleErrors.push(
|
|
38
|
+
String(msg.text())
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
page.on("pageerror", (err) => {
|
|
43
|
+
pageErrors.push(err instanceof Error ? err.message : String(err));
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
await page.setViewportSize({
|
|
47
|
+
width: viewport.width,
|
|
48
|
+
height: viewport.height
|
|
49
|
+
});
|
|
50
|
+
await page.goto(url, { waitUntil: "networkidle", timeout: 25e3 });
|
|
51
|
+
const domMetrics = await page.evaluate(() => {
|
|
52
|
+
const doc = globalThis.document;
|
|
53
|
+
const scrollWidth = doc.documentElement.scrollWidth;
|
|
54
|
+
const clientWidth = doc.documentElement.clientWidth;
|
|
55
|
+
const hasFavicon = Boolean(
|
|
56
|
+
doc.querySelector('link[rel*="icon"]')
|
|
57
|
+
);
|
|
58
|
+
const brokenImages = [];
|
|
59
|
+
for (const img of doc.querySelectorAll("img")) {
|
|
60
|
+
if (img.complete && img.naturalWidth === 0) {
|
|
61
|
+
brokenImages.push({
|
|
62
|
+
src: img.getAttribute("src") ?? "<unknown>"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const interactives = Array.from(
|
|
67
|
+
doc.querySelectorAll("a, button, input, select, textarea")
|
|
68
|
+
);
|
|
69
|
+
const smallTapTargets = [];
|
|
70
|
+
const boxes = [];
|
|
71
|
+
for (const el of interactives.slice(0, 60)) {
|
|
72
|
+
const rect = el.getBoundingClientRect();
|
|
73
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const label = `${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""}`;
|
|
77
|
+
if (rect.width < 44 || rect.height < 44) {
|
|
78
|
+
smallTapTargets.push({
|
|
79
|
+
selector: label,
|
|
80
|
+
width: Math.round(rect.width),
|
|
81
|
+
height: Math.round(rect.height)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
boxes.push({
|
|
85
|
+
selector: label,
|
|
86
|
+
left: rect.left,
|
|
87
|
+
right: rect.right,
|
|
88
|
+
top: rect.top,
|
|
89
|
+
bottom: rect.bottom
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const overlaps = [];
|
|
93
|
+
for (let i = 0; i < boxes.length; i += 1) {
|
|
94
|
+
const a = boxes[i];
|
|
95
|
+
if (!a) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (let j = i + 1; j < boxes.length; j += 1) {
|
|
99
|
+
const b = boxes[j];
|
|
100
|
+
if (!b) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const overlapX = Math.min(a.right, b.right) - Math.max(a.left, b.left);
|
|
104
|
+
const overlapY = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
|
|
105
|
+
if (overlapX > 4 && overlapY > 4) {
|
|
106
|
+
overlaps.push({
|
|
107
|
+
selectorA: a.selector,
|
|
108
|
+
selectorB: b.selector
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const perf = globalThis.performance;
|
|
114
|
+
const nav = perf?.getEntriesByType("navigation")?.[0];
|
|
115
|
+
const lcpEntries = perf?.getEntriesByType("largest-contentful-paint") ?? [];
|
|
116
|
+
const lastLcp = lcpEntries[lcpEntries.length - 1];
|
|
117
|
+
const clsEntries = perf?.getEntriesByType("layout-shift") ?? [];
|
|
118
|
+
let cls = 0;
|
|
119
|
+
for (const entry of clsEntries) {
|
|
120
|
+
if (!entry.hadRecentInput && typeof entry.value === "number") {
|
|
121
|
+
cls += entry.value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
scrollWidth,
|
|
126
|
+
clientWidth,
|
|
127
|
+
hasFavicon,
|
|
128
|
+
brokenImages,
|
|
129
|
+
smallTapTargets,
|
|
130
|
+
overlaps: overlaps.slice(0, 10),
|
|
131
|
+
cwv: {
|
|
132
|
+
...typeof lastLcp?.startTime === "number" ? { lcpMs: Math.round(lastLcp.startTime) } : {},
|
|
133
|
+
...typeof nav?.responseStart === "number" ? { ttfbMs: Math.round(nav.responseStart) } : {},
|
|
134
|
+
cls: Math.round(cls * 1e3) / 1e3
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const axeViolations = [];
|
|
139
|
+
if (AxeCtor) {
|
|
140
|
+
const axeRes = await new AxeCtor({ page }).analyze();
|
|
141
|
+
for (const v of axeRes.violations ?? []) {
|
|
142
|
+
const impact = v.impact === "critical" || v.impact === "serious" || v.impact === "moderate" || v.impact === "minor" ? v.impact : "moderate";
|
|
143
|
+
axeViolations.push({
|
|
144
|
+
id: v.id,
|
|
145
|
+
impact,
|
|
146
|
+
help: v.help,
|
|
147
|
+
nodesCount: v.nodes?.length ?? 1
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
snapshots.push({
|
|
152
|
+
viewport,
|
|
153
|
+
scrollWidth: domMetrics.scrollWidth,
|
|
154
|
+
clientWidth: domMetrics.clientWidth,
|
|
155
|
+
overlaps: domMetrics.overlaps,
|
|
156
|
+
smallTapTargets: domMetrics.smallTapTargets,
|
|
157
|
+
brokenImages: domMetrics.brokenImages,
|
|
158
|
+
hasFavicon: domMetrics.hasFavicon,
|
|
159
|
+
consoleErrors,
|
|
160
|
+
pageErrors,
|
|
161
|
+
axeViolations,
|
|
162
|
+
cwv: domMetrics.cwv
|
|
163
|
+
});
|
|
164
|
+
} finally {
|
|
165
|
+
await page.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { available: true, url, viewports: snapshots };
|
|
169
|
+
} finally {
|
|
170
|
+
await browser.close();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/collectors/design-browser.ts
|
|
177
|
+
import {
|
|
178
|
+
createFindingFingerprint
|
|
179
|
+
} from "@arx-hq/contracts";
|
|
180
|
+
function evaluateDesignProbe(probeResult) {
|
|
181
|
+
if (!probeResult.available) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const findings = [];
|
|
185
|
+
let reportedMissingFavicon = false;
|
|
186
|
+
for (const snap of probeResult.viewports) {
|
|
187
|
+
const vpLabel = `${snap.viewport.width}x${snap.viewport.height}`;
|
|
188
|
+
if (snap.scrollWidth > snap.clientWidth) {
|
|
189
|
+
const overflowPx = snap.scrollWidth - snap.clientWidth;
|
|
190
|
+
const isMobile = snap.viewport.width <= 480;
|
|
191
|
+
findings.push({
|
|
192
|
+
id: "DES-02",
|
|
193
|
+
fingerprint: createFindingFingerprint({
|
|
194
|
+
id: "DES-02",
|
|
195
|
+
collector: "design-browser",
|
|
196
|
+
detail: `${probeResult.url}:${vpLabel}:overflow`
|
|
197
|
+
}),
|
|
198
|
+
pillar: "DESIGN",
|
|
199
|
+
tier: "T3",
|
|
200
|
+
severity: isMobile ? "critical" : "high",
|
|
201
|
+
title: `Horizontal overflow (+${overflowPx}px) at ${vpLabel}`,
|
|
202
|
+
plainSummary: `The page overflows horizontally by ${overflowPx}px on ${snap.viewport.name} (${vpLabel}), causing unwanted sideways scrolling.`,
|
|
203
|
+
evidence: {
|
|
204
|
+
url: probeResult.url,
|
|
205
|
+
viewport: vpLabel,
|
|
206
|
+
snippet: `scrollWidth=${snap.scrollWidth} > clientWidth=${snap.clientWidth}`
|
|
207
|
+
},
|
|
208
|
+
autoFixable: false,
|
|
209
|
+
repairHint: `Inspect wide elements at viewport ${vpLabel} and apply responsive width/overflow constraints.`,
|
|
210
|
+
collector: "design-browser"
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
for (const overlap of snap.overlaps.slice(0, 5)) {
|
|
214
|
+
findings.push({
|
|
215
|
+
id: "DES-03",
|
|
216
|
+
fingerprint: createFindingFingerprint({
|
|
217
|
+
id: "DES-03",
|
|
218
|
+
collector: "design-browser",
|
|
219
|
+
detail: `${vpLabel}:${overlap.selectorA}:${overlap.selectorB}`
|
|
220
|
+
}),
|
|
221
|
+
pillar: "DESIGN",
|
|
222
|
+
tier: "T3",
|
|
223
|
+
severity: "high",
|
|
224
|
+
title: `Overlapping interactive elements at ${vpLabel}`,
|
|
225
|
+
plainSummary: `Interactive controls (${overlap.selectorA} and ${overlap.selectorB}) overlap on ${snap.viewport.name}.`,
|
|
226
|
+
evidence: {
|
|
227
|
+
url: probeResult.url,
|
|
228
|
+
viewport: vpLabel,
|
|
229
|
+
snippet: `${overlap.selectorA} overlaps ${overlap.selectorB}`
|
|
230
|
+
},
|
|
231
|
+
autoFixable: false,
|
|
232
|
+
repairHint: `Adjust layout spacing/z-index so ${overlap.selectorA} and ${overlap.selectorB} do not collide at ${vpLabel}.`,
|
|
233
|
+
collector: "design-browser"
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
for (const brokenImg of snap.brokenImages) {
|
|
237
|
+
findings.push({
|
|
238
|
+
id: "DES-06",
|
|
239
|
+
fingerprint: createFindingFingerprint({
|
|
240
|
+
id: "DES-06",
|
|
241
|
+
collector: "design-browser",
|
|
242
|
+
detail: `broken-img:${brokenImg.src}`
|
|
243
|
+
}),
|
|
244
|
+
pillar: "DESIGN",
|
|
245
|
+
tier: "T3",
|
|
246
|
+
severity: "high",
|
|
247
|
+
title: `Broken image asset: ${brokenImg.src}`,
|
|
248
|
+
plainSummary: `Image "${brokenImg.src}" failed to load (naturalWidth === 0).`,
|
|
249
|
+
evidence: {
|
|
250
|
+
url: probeResult.url,
|
|
251
|
+
viewport: vpLabel,
|
|
252
|
+
snippet: brokenImg.src
|
|
253
|
+
},
|
|
254
|
+
autoFixable: false,
|
|
255
|
+
repairHint: `Verify image path/asset for "${brokenImg.src}" and ensure it loads with HTTP 200.`,
|
|
256
|
+
collector: "design-browser"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (!snap.hasFavicon && !reportedMissingFavicon) {
|
|
260
|
+
reportedMissingFavicon = true;
|
|
261
|
+
findings.push({
|
|
262
|
+
id: "DES-06",
|
|
263
|
+
fingerprint: createFindingFingerprint({
|
|
264
|
+
id: "DES-06",
|
|
265
|
+
collector: "design-browser",
|
|
266
|
+
detail: `missing-favicon:${probeResult.url}`
|
|
267
|
+
}),
|
|
268
|
+
pillar: "DESIGN",
|
|
269
|
+
tier: "T3",
|
|
270
|
+
severity: "low",
|
|
271
|
+
title: "Missing favicon link",
|
|
272
|
+
plainSummary: "No favicon icon is declared in the document <head>.",
|
|
273
|
+
evidence: { url: probeResult.url },
|
|
274
|
+
autoFixable: false,
|
|
275
|
+
repairHint: 'Add `<link rel="icon" href="/favicon.ico" />` to the HTML document head.',
|
|
276
|
+
collector: "design-browser"
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return findings;
|
|
281
|
+
}
|
|
282
|
+
function createDesignBrowserCollector(probe = createPlaywrightBrowserProbe()) {
|
|
283
|
+
return {
|
|
284
|
+
name: "design-browser",
|
|
285
|
+
pillar: "DESIGN",
|
|
286
|
+
tier: "T3",
|
|
287
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
288
|
+
async detect(ctx) {
|
|
289
|
+
return Boolean(ctx.config.appUrl);
|
|
290
|
+
},
|
|
291
|
+
async run(ctx) {
|
|
292
|
+
if (!ctx.config.appUrl) {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
const result = await probe.probeUrl(
|
|
296
|
+
ctx.config.appUrl,
|
|
297
|
+
ctx.config.viewports
|
|
298
|
+
);
|
|
299
|
+
return evaluateDesignProbe(result);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/collectors/design-tokens.ts
|
|
305
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
306
|
+
import path2 from "path";
|
|
307
|
+
import {
|
|
308
|
+
createFindingFingerprint as createFindingFingerprint2
|
|
309
|
+
} from "@arx-hq/contracts";
|
|
310
|
+
|
|
311
|
+
// src/utils/walk.ts
|
|
312
|
+
import { access, readdir, readFile } from "fs/promises";
|
|
313
|
+
import path from "path";
|
|
314
|
+
import { parseInlineIgnore } from "@arx-hq/contracts";
|
|
315
|
+
var ALWAYS_IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
316
|
+
".git",
|
|
317
|
+
"node_modules",
|
|
318
|
+
"dist",
|
|
319
|
+
".next",
|
|
320
|
+
"coverage",
|
|
321
|
+
".arx"
|
|
322
|
+
]);
|
|
323
|
+
function toPosix(filePath) {
|
|
324
|
+
return filePath.replace(/\\/g, "/");
|
|
325
|
+
}
|
|
326
|
+
function globToRegex(pattern) {
|
|
327
|
+
const normalized = toPosix(pattern).replace(/^\.\//, "");
|
|
328
|
+
let regex = "^";
|
|
329
|
+
for (let i = 0; i < normalized.length; i += 1) {
|
|
330
|
+
const ch = normalized[i];
|
|
331
|
+
const next = normalized[i + 1];
|
|
332
|
+
if (ch === "*" && next === "*") {
|
|
333
|
+
if (normalized[i + 2] === "/") {
|
|
334
|
+
regex += "(?:.*/)?";
|
|
335
|
+
i += 2;
|
|
336
|
+
} else {
|
|
337
|
+
regex += ".*";
|
|
338
|
+
i += 1;
|
|
339
|
+
}
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (ch === "*") {
|
|
343
|
+
regex += "[^/]*";
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (ch === "?") {
|
|
347
|
+
regex += "[^/]";
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (ch && /[.+^${}()|[\]\\]/.test(ch)) {
|
|
351
|
+
regex += `\\${ch}`;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
regex += ch ?? "";
|
|
355
|
+
}
|
|
356
|
+
regex += "$";
|
|
357
|
+
return new RegExp(regex);
|
|
358
|
+
}
|
|
359
|
+
function createIgnoreMatcher(ignorePaths) {
|
|
360
|
+
const regexes = ignorePaths.map((pattern) => globToRegex(pattern));
|
|
361
|
+
return (relPosixPath) => {
|
|
362
|
+
const clean = toPosix(relPosixPath).replace(/^\.\//, "");
|
|
363
|
+
return regexes.some((rx) => rx.test(clean));
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
async function walkProjectFiles(options) {
|
|
367
|
+
const isIgnored = createIgnoreMatcher(options.ignorePaths);
|
|
368
|
+
const results = [];
|
|
369
|
+
async function visit(currentDir) {
|
|
370
|
+
let entries;
|
|
371
|
+
try {
|
|
372
|
+
entries = await readdir(currentDir, { withFileTypes: true });
|
|
373
|
+
} catch {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
377
|
+
for (const entry of entries) {
|
|
378
|
+
const absPath = path.join(currentDir, entry.name);
|
|
379
|
+
const relPosix = toPosix(path.relative(options.rootDir, absPath));
|
|
380
|
+
if (entry.isDirectory()) {
|
|
381
|
+
if (entry.name === ".git" || entry.name === "node_modules") {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (!options.includeBuildDirs && (ALWAYS_IGNORED_DIRS.has(entry.name) || isIgnored(relPosix) || isIgnored(`${relPosix}/`))) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
await visit(absPath);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (!entry.isFile()) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (!options.includeBuildDirs && isIgnored(relPosix)) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (options.extensions) {
|
|
397
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
398
|
+
if (!options.extensions.has(ext)) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
results.push(relPosix);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
await visit(options.rootDir);
|
|
406
|
+
return results;
|
|
407
|
+
}
|
|
408
|
+
async function pathExists(absPath) {
|
|
409
|
+
try {
|
|
410
|
+
await access(absPath);
|
|
411
|
+
return true;
|
|
412
|
+
} catch {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async function readTextIfExists(absPath) {
|
|
417
|
+
try {
|
|
418
|
+
return await readFile(absPath, "utf8");
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function isSuppressedAtLine(lines, oneBasedLine, metricId) {
|
|
427
|
+
const current = lines[oneBasedLine - 1];
|
|
428
|
+
const previous = oneBasedLine > 1 ? lines[oneBasedLine - 2] : void 0;
|
|
429
|
+
for (const candidate of [current, previous]) {
|
|
430
|
+
if (!candidate) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const directive = parseInlineIgnore(candidate);
|
|
434
|
+
if (directive && directive.metricId === metricId) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/collectors/design-tokens.ts
|
|
442
|
+
var STYLE_UI_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".scss", ".tsx", ".jsx"]);
|
|
443
|
+
var TOKEN_FILE_REGEX = /(?:^|\/)(?:tokens|theme|variables|palette|tailwind\.config)\.[^/]+$/i;
|
|
444
|
+
var CSS_VAR_DEF_REGEX = /^\s*--[a-zA-Z0-9_-]+\s*:/;
|
|
445
|
+
var HEX_COLOR_REGEX = /#[0-9a-fA-F]{3,8}\b/g;
|
|
446
|
+
var RGB_COLOR_REGEX = /\brgba?\(\s*\d+/g;
|
|
447
|
+
var TW_ARBITRARY_REGEX = /\b(?:bg|text|border|p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|w|h|gap)-\[(?:#[0-9a-fA-F]{3,8}|\d+px)\]/g;
|
|
448
|
+
function scanDesignTokens(relFile, content) {
|
|
449
|
+
if (TOKEN_FILE_REGEX.test(relFile)) {
|
|
450
|
+
return { findings: [], totalStyleLines: 0 };
|
|
451
|
+
}
|
|
452
|
+
const findings = [];
|
|
453
|
+
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
454
|
+
let totalStyleLines = 0;
|
|
455
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
456
|
+
const lineNum = i + 1;
|
|
457
|
+
const line = lines[i] ?? "";
|
|
458
|
+
const trimmed = line.trim();
|
|
459
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*") || CSS_VAR_DEF_REGEX.test(trimmed)) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (trimmed.includes(":") || trimmed.includes("className") || trimmed.includes("style=")) {
|
|
463
|
+
totalStyleLines += 1;
|
|
464
|
+
}
|
|
465
|
+
if (isSuppressedAtLine(lines, lineNum, "DES-01")) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const hits = [];
|
|
469
|
+
for (const rx of [TW_ARBITRARY_REGEX, HEX_COLOR_REGEX, RGB_COLOR_REGEX]) {
|
|
470
|
+
rx.lastIndex = 0;
|
|
471
|
+
const match = rx.exec(line);
|
|
472
|
+
if (match?.[0]) {
|
|
473
|
+
hits.push(match[0]);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (hits.length > 0) {
|
|
477
|
+
const sample = hits[0] ?? "";
|
|
478
|
+
findings.push({
|
|
479
|
+
id: "DES-01",
|
|
480
|
+
fingerprint: createFindingFingerprint2({
|
|
481
|
+
id: "DES-01",
|
|
482
|
+
collector: "design-tokens",
|
|
483
|
+
file: relFile,
|
|
484
|
+
line: lineNum,
|
|
485
|
+
detail: sample
|
|
486
|
+
}),
|
|
487
|
+
pillar: "DESIGN",
|
|
488
|
+
tier: "T2",
|
|
489
|
+
severity: "medium",
|
|
490
|
+
title: `Hardcoded design value "${sample}" in ${relFile}:${lineNum}`,
|
|
491
|
+
plainSummary: `A hardcoded color or spacing value (${sample}) bypasses the design token system in ${relFile}.`,
|
|
492
|
+
evidence: {
|
|
493
|
+
file: relFile,
|
|
494
|
+
line: lineNum,
|
|
495
|
+
snippet: trimmed.slice(0, 140)
|
|
496
|
+
},
|
|
497
|
+
autoFixable: false,
|
|
498
|
+
repairHint: `Replace hardcoded "${sample}" at ${relFile}:${lineNum} with a CSS custom property or theme token.`,
|
|
499
|
+
collector: "design-tokens"
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return { findings, totalStyleLines };
|
|
504
|
+
}
|
|
505
|
+
function createDesignTokensCollector() {
|
|
506
|
+
return {
|
|
507
|
+
name: "design-tokens",
|
|
508
|
+
pillar: "DESIGN",
|
|
509
|
+
tier: "T2",
|
|
510
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
511
|
+
async detect(ctx) {
|
|
512
|
+
const files = await walkProjectFiles({
|
|
513
|
+
rootDir: ctx.rootDir,
|
|
514
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
515
|
+
extensions: STYLE_UI_EXTENSIONS
|
|
516
|
+
});
|
|
517
|
+
return files.length > 0;
|
|
518
|
+
},
|
|
519
|
+
async run(ctx) {
|
|
520
|
+
const files = await walkProjectFiles({
|
|
521
|
+
rootDir: ctx.rootDir,
|
|
522
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
523
|
+
extensions: STYLE_UI_EXTENSIONS
|
|
524
|
+
});
|
|
525
|
+
const allFindings = [];
|
|
526
|
+
let totalStyleLines = 0;
|
|
527
|
+
for (const relFile of files) {
|
|
528
|
+
if (relFile.includes("/test/") || relFile.includes("/tests/")) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const content = await readFile2(
|
|
532
|
+
path2.resolve(ctx.rootDir, relFile),
|
|
533
|
+
"utf8"
|
|
534
|
+
);
|
|
535
|
+
const scanned = scanDesignTokens(relFile, content);
|
|
536
|
+
allFindings.push(...scanned.findings);
|
|
537
|
+
totalStyleLines += scanned.totalStyleLines;
|
|
538
|
+
}
|
|
539
|
+
if (ctx.config.mode !== "strict" && totalStyleLines > 0) {
|
|
540
|
+
const leakRatio = allFindings.length / totalStyleLines;
|
|
541
|
+
if (leakRatio < 0.03) {
|
|
542
|
+
return [];
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return allFindings;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/collectors/perf-ast.ts
|
|
551
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
552
|
+
import path3 from "path";
|
|
553
|
+
import {
|
|
554
|
+
createFindingFingerprint as createFindingFingerprint3
|
|
555
|
+
} from "@arx-hq/contracts";
|
|
556
|
+
import ts from "typescript";
|
|
557
|
+
var CODE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs"]);
|
|
558
|
+
var IO_QUERY_METHODS = /* @__PURE__ */ new Set([
|
|
559
|
+
"fetch",
|
|
560
|
+
"query",
|
|
561
|
+
"findUnique",
|
|
562
|
+
"findFirst",
|
|
563
|
+
"findMany",
|
|
564
|
+
"execute"
|
|
565
|
+
]);
|
|
566
|
+
function isLoopNode(node) {
|
|
567
|
+
return ts.isForStatement(node) || ts.isForInStatement(node) || ts.isForOfStatement(node) || ts.isWhileStatement(node) || ts.isDoStatement(node);
|
|
568
|
+
}
|
|
569
|
+
function getCalleeMethodName(expr) {
|
|
570
|
+
if (ts.isIdentifier(expr)) {
|
|
571
|
+
return expr.text;
|
|
572
|
+
}
|
|
573
|
+
if (ts.isPropertyAccessExpression(expr)) {
|
|
574
|
+
return expr.name.text;
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
function scanPerfAstPatterns(relFile, content) {
|
|
579
|
+
const findings = [];
|
|
580
|
+
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
581
|
+
const sourceFile = ts.createSourceFile(
|
|
582
|
+
relFile,
|
|
583
|
+
content,
|
|
584
|
+
ts.ScriptTarget.Latest,
|
|
585
|
+
true,
|
|
586
|
+
relFile.endsWith(".tsx") || relFile.endsWith(".jsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS
|
|
587
|
+
);
|
|
588
|
+
let hasClearInterval = false;
|
|
589
|
+
let hasRemoveEventListener = false;
|
|
590
|
+
let hasAbortController = false;
|
|
591
|
+
const setIntervalLines = [];
|
|
592
|
+
const addEventListenerLines = [];
|
|
593
|
+
function visit(node, loopDepth) {
|
|
594
|
+
const nextDepth = isLoopNode(node) ? loopDepth + 1 : loopDepth;
|
|
595
|
+
if (loopDepth > 0 && ts.isAwaitExpression(node) && ts.isCallExpression(node.expression)) {
|
|
596
|
+
const method = getCalleeMethodName(node.expression.expression);
|
|
597
|
+
if (method && IO_QUERY_METHODS.has(method)) {
|
|
598
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(
|
|
599
|
+
node.getStart(sourceFile)
|
|
600
|
+
);
|
|
601
|
+
const line = pos.line + 1;
|
|
602
|
+
if (!isSuppressedAtLine(lines, line, "PERF-04")) {
|
|
603
|
+
findings.push({
|
|
604
|
+
id: "PERF-04",
|
|
605
|
+
fingerprint: createFindingFingerprint3({
|
|
606
|
+
id: "PERF-04",
|
|
607
|
+
collector: "perf-ast",
|
|
608
|
+
file: relFile,
|
|
609
|
+
line,
|
|
610
|
+
detail: `n-plus-one:${method}`
|
|
611
|
+
}),
|
|
612
|
+
pillar: "PERF",
|
|
613
|
+
tier: "T2",
|
|
614
|
+
severity: "high",
|
|
615
|
+
title: `Potential N+1 async ${method}() inside loop at ${relFile}:${line}`,
|
|
616
|
+
plainSummary: `Calling await ${method}() inside a loop can cause slow N+1 database or network bottlenecks.`,
|
|
617
|
+
evidence: {
|
|
618
|
+
file: relFile,
|
|
619
|
+
line,
|
|
620
|
+
snippet: lines[line - 1]?.trim().slice(0, 140)
|
|
621
|
+
},
|
|
622
|
+
autoFixable: false,
|
|
623
|
+
repairHint: `Batch queries or execute independent requests in parallel with Promise.all() at ${relFile}:${line}.`,
|
|
624
|
+
collector: "perf-ast"
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (ts.isCallExpression(node)) {
|
|
630
|
+
const method = getCalleeMethodName(node.expression);
|
|
631
|
+
if (method === "findMany") {
|
|
632
|
+
const arg = node.arguments[0];
|
|
633
|
+
let hasLimit = false;
|
|
634
|
+
if (arg && ts.isObjectLiteralExpression(arg)) {
|
|
635
|
+
hasLimit = arg.properties.some(
|
|
636
|
+
(prop) => ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && (prop.name.text === "take" || prop.name.text === "limit")
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
if (!hasLimit) {
|
|
640
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(
|
|
641
|
+
node.getStart(sourceFile)
|
|
642
|
+
);
|
|
643
|
+
const line = pos.line + 1;
|
|
644
|
+
if (!isSuppressedAtLine(lines, line, "PERF-04")) {
|
|
645
|
+
findings.push({
|
|
646
|
+
id: "PERF-04",
|
|
647
|
+
fingerprint: createFindingFingerprint3({
|
|
648
|
+
id: "PERF-04",
|
|
649
|
+
collector: "perf-ast",
|
|
650
|
+
file: relFile,
|
|
651
|
+
line,
|
|
652
|
+
detail: "unbounded-findMany"
|
|
653
|
+
}),
|
|
654
|
+
pillar: "PERF",
|
|
655
|
+
tier: "T2",
|
|
656
|
+
severity: "high",
|
|
657
|
+
title: `Unbounded findMany() query without take/limit at ${relFile}:${line}`,
|
|
658
|
+
plainSummary: `Fetching an unbounded list with findMany() risks memory exhaustion as tables grow.`,
|
|
659
|
+
evidence: {
|
|
660
|
+
file: relFile,
|
|
661
|
+
line,
|
|
662
|
+
snippet: lines[line - 1]?.trim().slice(0, 140)
|
|
663
|
+
},
|
|
664
|
+
autoFixable: false,
|
|
665
|
+
repairHint: `Pass an explicit \`take\` or \`limit\` pagination bound to findMany() at ${relFile}:${line}.`,
|
|
666
|
+
collector: "perf-ast"
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (method === "setInterval") {
|
|
672
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(
|
|
673
|
+
node.getStart(sourceFile)
|
|
674
|
+
);
|
|
675
|
+
setIntervalLines.push(pos.line + 1);
|
|
676
|
+
} else if (method === "clearInterval") {
|
|
677
|
+
hasClearInterval = true;
|
|
678
|
+
} else if (method === "addEventListener") {
|
|
679
|
+
const optionsArg = node.arguments[2];
|
|
680
|
+
const hasOnceOrSignal = optionsArg !== void 0 && ts.isObjectLiteralExpression(optionsArg) && optionsArg.properties.some(
|
|
681
|
+
(prop) => ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && (prop.name.text === "once" || prop.name.text === "signal")
|
|
682
|
+
);
|
|
683
|
+
if (!hasOnceOrSignal) {
|
|
684
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(
|
|
685
|
+
node.getStart(sourceFile)
|
|
686
|
+
);
|
|
687
|
+
addEventListenerLines.push(pos.line + 1);
|
|
688
|
+
}
|
|
689
|
+
} else if (method === "removeEventListener") {
|
|
690
|
+
hasRemoveEventListener = true;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (ts.isIdentifier(node) && node.text === "AbortController") {
|
|
694
|
+
hasAbortController = true;
|
|
695
|
+
}
|
|
696
|
+
ts.forEachChild(node, (child) => visit(child, nextDepth));
|
|
697
|
+
}
|
|
698
|
+
visit(sourceFile, 0);
|
|
699
|
+
if (!hasClearInterval) {
|
|
700
|
+
for (const line of setIntervalLines) {
|
|
701
|
+
if (isSuppressedAtLine(lines, line, "PERF-05")) {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
findings.push({
|
|
705
|
+
id: "PERF-05",
|
|
706
|
+
fingerprint: createFindingFingerprint3({
|
|
707
|
+
id: "PERF-05",
|
|
708
|
+
collector: "perf-ast",
|
|
709
|
+
file: relFile,
|
|
710
|
+
line,
|
|
711
|
+
detail: "uncleaned-setInterval"
|
|
712
|
+
}),
|
|
713
|
+
pillar: "PERF",
|
|
714
|
+
tier: "T2",
|
|
715
|
+
severity: "medium",
|
|
716
|
+
title: `setInterval() without clearInterval() cleanup at ${relFile}:${line}`,
|
|
717
|
+
plainSummary: `A repeating timer is started in ${relFile}:${line} with no clearInterval() cleanup, risking memory leaks.`,
|
|
718
|
+
evidence: { file: relFile, line, snippet: lines[line - 1]?.trim() },
|
|
719
|
+
autoFixable: false,
|
|
720
|
+
repairHint: `Store the interval ID and call clearInterval() during unmount/shutdown in ${relFile}.`,
|
|
721
|
+
collector: "perf-ast"
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (!hasRemoveEventListener && !hasAbortController) {
|
|
726
|
+
for (const line of addEventListenerLines) {
|
|
727
|
+
if (isSuppressedAtLine(lines, line, "PERF-05")) {
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
findings.push({
|
|
731
|
+
id: "PERF-05",
|
|
732
|
+
fingerprint: createFindingFingerprint3({
|
|
733
|
+
id: "PERF-05",
|
|
734
|
+
collector: "perf-ast",
|
|
735
|
+
file: relFile,
|
|
736
|
+
line,
|
|
737
|
+
detail: "uncleaned-addEventListener"
|
|
738
|
+
}),
|
|
739
|
+
pillar: "PERF",
|
|
740
|
+
tier: "T2",
|
|
741
|
+
severity: "medium",
|
|
742
|
+
title: `addEventListener() without cleanup at ${relFile}:${line}`,
|
|
743
|
+
plainSummary: `Event listener registered in ${relFile}:${line} is never removed, risking memory leaks.`,
|
|
744
|
+
evidence: { file: relFile, line, snippet: lines[line - 1]?.trim() },
|
|
745
|
+
autoFixable: false,
|
|
746
|
+
repairHint: `Pair addEventListener() with removeEventListener(), AbortController signal, or { once: true }.`,
|
|
747
|
+
collector: "perf-ast"
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return findings;
|
|
752
|
+
}
|
|
753
|
+
function createPerfAstCollector() {
|
|
754
|
+
return {
|
|
755
|
+
name: "perf-ast",
|
|
756
|
+
pillar: "PERF",
|
|
757
|
+
tier: "T2",
|
|
758
|
+
supportedStacks: ["ts-node", "nextjs", "vite", "react", "backend-api"],
|
|
759
|
+
async detect(ctx) {
|
|
760
|
+
const files = await walkProjectFiles({
|
|
761
|
+
rootDir: ctx.rootDir,
|
|
762
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
763
|
+
extensions: CODE_EXTENSIONS
|
|
764
|
+
});
|
|
765
|
+
return files.length > 0;
|
|
766
|
+
},
|
|
767
|
+
async run(ctx) {
|
|
768
|
+
const files = await walkProjectFiles({
|
|
769
|
+
rootDir: ctx.rootDir,
|
|
770
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
771
|
+
extensions: CODE_EXTENSIONS
|
|
772
|
+
});
|
|
773
|
+
const findings = [];
|
|
774
|
+
for (const relFile of files) {
|
|
775
|
+
if (relFile.endsWith(".d.ts") || relFile.includes("/test/") || relFile.includes("/tests/") || /\.test\.[a-z]+$/.test(relFile)) {
|
|
776
|
+
continue;
|
|
777
|
+
}
|
|
778
|
+
const content = await readFile3(
|
|
779
|
+
path3.resolve(ctx.rootDir, relFile),
|
|
780
|
+
"utf8"
|
|
781
|
+
);
|
|
782
|
+
findings.push(...scanPerfAstPatterns(relFile, content));
|
|
783
|
+
}
|
|
784
|
+
return findings;
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// src/collectors/perf-bundle.ts
|
|
790
|
+
import { readFile as readFile4, stat } from "fs/promises";
|
|
791
|
+
import path4 from "path";
|
|
792
|
+
import { gzipSync } from "zlib";
|
|
793
|
+
import {
|
|
794
|
+
createFindingFingerprint as createFindingFingerprint4
|
|
795
|
+
} from "@arx-hq/contracts";
|
|
796
|
+
var BUNDLE_DIRS = ["dist/assets", ".next/static/chunks", "build/assets"];
|
|
797
|
+
var MEDIA_DIRS = ["public", "assets", "src/assets"];
|
|
798
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
799
|
+
".png",
|
|
800
|
+
".jpg",
|
|
801
|
+
".jpeg",
|
|
802
|
+
".bmp",
|
|
803
|
+
".gif",
|
|
804
|
+
".tiff"
|
|
805
|
+
]);
|
|
806
|
+
var MAX_UNOPTIMIZED_IMAGE_BYTES = 500 * 1024;
|
|
807
|
+
function createPerfBundleCollector() {
|
|
808
|
+
return {
|
|
809
|
+
name: "perf-bundle-media",
|
|
810
|
+
pillar: "PERF",
|
|
811
|
+
tier: "T2",
|
|
812
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
813
|
+
async detect(ctx) {
|
|
814
|
+
for (const relDir of [...BUNDLE_DIRS, ...MEDIA_DIRS]) {
|
|
815
|
+
if (await pathExists(path4.resolve(ctx.rootDir, relDir))) {
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
},
|
|
821
|
+
async run(ctx) {
|
|
822
|
+
const findings = [];
|
|
823
|
+
let totalJsGzipBytes = 0;
|
|
824
|
+
for (const relDir of BUNDLE_DIRS) {
|
|
825
|
+
const absDir = path4.resolve(ctx.rootDir, relDir);
|
|
826
|
+
if (!await pathExists(absDir)) {
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
const jsFiles = await walkProjectFiles({
|
|
830
|
+
rootDir: absDir,
|
|
831
|
+
ignorePaths: [],
|
|
832
|
+
extensions: /* @__PURE__ */ new Set([".js", ".mjs"]),
|
|
833
|
+
includeBuildDirs: true
|
|
834
|
+
});
|
|
835
|
+
for (const relJs of jsFiles) {
|
|
836
|
+
const buf = await readFile4(path4.join(absDir, relJs));
|
|
837
|
+
totalJsGzipBytes += gzipSync(buf).byteLength;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
const gzipKb = Math.round(totalJsGzipBytes / 1024 * 10) / 10;
|
|
841
|
+
if (gzipKb > ctx.config.budgets.initialJsKb) {
|
|
842
|
+
findings.push({
|
|
843
|
+
id: "PERF-02",
|
|
844
|
+
fingerprint: createFindingFingerprint4({
|
|
845
|
+
id: "PERF-02",
|
|
846
|
+
collector: "perf-bundle-media",
|
|
847
|
+
detail: "initial-js-budget"
|
|
848
|
+
}),
|
|
849
|
+
pillar: "PERF",
|
|
850
|
+
tier: "T2",
|
|
851
|
+
severity: "high",
|
|
852
|
+
title: `JS bundle gzip size (${gzipKb}KB) exceeds ${ctx.config.budgets.initialJsKb}KB budget`,
|
|
853
|
+
plainSummary: `JavaScript bundle is ${gzipKb}KB gzipped, exceeding the ${ctx.config.budgets.initialJsKb}KB performance budget.`,
|
|
854
|
+
evidence: {
|
|
855
|
+
snippet: `gzip=${gzipKb}KB > budget=${ctx.config.budgets.initialJsKb}KB`
|
|
856
|
+
},
|
|
857
|
+
autoFixable: false,
|
|
858
|
+
repairHint: "Code-split heavy dependencies via dynamic import() and remove unused libraries.",
|
|
859
|
+
collector: "perf-bundle-media"
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
for (const relDir of MEDIA_DIRS) {
|
|
863
|
+
const absDir = path4.resolve(ctx.rootDir, relDir);
|
|
864
|
+
if (!await pathExists(absDir)) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const mediaFiles = await walkProjectFiles({
|
|
868
|
+
rootDir: absDir,
|
|
869
|
+
ignorePaths: [],
|
|
870
|
+
extensions: IMAGE_EXTENSIONS,
|
|
871
|
+
includeBuildDirs: true
|
|
872
|
+
});
|
|
873
|
+
for (const relMedia of mediaFiles) {
|
|
874
|
+
const absMedia = path4.join(absDir, relMedia);
|
|
875
|
+
const info = await stat(absMedia);
|
|
876
|
+
if (info.size > MAX_UNOPTIMIZED_IMAGE_BYTES) {
|
|
877
|
+
const kb = Math.round(info.size / 1024);
|
|
878
|
+
const displayRel = `${relDir}/${relMedia}`;
|
|
879
|
+
findings.push({
|
|
880
|
+
id: "PERF-03",
|
|
881
|
+
fingerprint: createFindingFingerprint4({
|
|
882
|
+
id: "PERF-03",
|
|
883
|
+
collector: "perf-bundle-media",
|
|
884
|
+
file: displayRel,
|
|
885
|
+
detail: "oversized-image"
|
|
886
|
+
}),
|
|
887
|
+
pillar: "PERF",
|
|
888
|
+
tier: "T2",
|
|
889
|
+
severity: "medium",
|
|
890
|
+
title: `Unoptimized image > 500KB (${kb}KB): ${displayRel}`,
|
|
891
|
+
plainSummary: `Image "${displayRel}" is ${kb}KB and will slow down page loads.`,
|
|
892
|
+
evidence: { file: displayRel, snippet: `${kb}KB` },
|
|
893
|
+
autoFixable: false,
|
|
894
|
+
repairHint: `Convert ${displayRel} to compressed WebP/AVIF under 500KB and enable lazy loading.`,
|
|
895
|
+
collector: "perf-bundle-media"
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return findings;
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// src/collectors/perf-cwv.ts
|
|
906
|
+
import {
|
|
907
|
+
createFindingFingerprint as createFindingFingerprint5
|
|
908
|
+
} from "@arx-hq/contracts";
|
|
909
|
+
function evaluateCwvProbe(probeResult, budgets) {
|
|
910
|
+
if (!probeResult.available) {
|
|
911
|
+
return [];
|
|
912
|
+
}
|
|
913
|
+
const findings = [];
|
|
914
|
+
for (const snap of probeResult.viewports) {
|
|
915
|
+
const vpLabel = `${snap.viewport.width}x${snap.viewport.height}`;
|
|
916
|
+
if (snap.cwv.lcpMs !== void 0 && snap.cwv.lcpMs > budgets.lcpMs) {
|
|
917
|
+
findings.push({
|
|
918
|
+
id: "PERF-01",
|
|
919
|
+
fingerprint: createFindingFingerprint5({
|
|
920
|
+
id: "PERF-01",
|
|
921
|
+
collector: "perf-cwv",
|
|
922
|
+
detail: `${vpLabel}:lcp`
|
|
923
|
+
}),
|
|
924
|
+
pillar: "PERF",
|
|
925
|
+
tier: "T3",
|
|
926
|
+
severity: "high",
|
|
927
|
+
title: `LCP (${snap.cwv.lcpMs}ms) exceeds ${budgets.lcpMs}ms budget at ${vpLabel}`,
|
|
928
|
+
plainSummary: `Main page content took ${snap.cwv.lcpMs}ms to paint on ${snap.viewport.name} (target <= ${budgets.lcpMs}ms).`,
|
|
929
|
+
evidence: {
|
|
930
|
+
url: probeResult.url,
|
|
931
|
+
viewport: vpLabel,
|
|
932
|
+
snippet: `LCP=${snap.cwv.lcpMs}ms`
|
|
933
|
+
},
|
|
934
|
+
autoFixable: false,
|
|
935
|
+
repairHint: "Preload hero image/font, minimize render-blocking scripts, and reduce server TTFB.",
|
|
936
|
+
collector: "perf-cwv"
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
if (snap.cwv.cls !== void 0 && snap.cwv.cls > budgets.cls) {
|
|
940
|
+
findings.push({
|
|
941
|
+
id: "PERF-01",
|
|
942
|
+
fingerprint: createFindingFingerprint5({
|
|
943
|
+
id: "PERF-01",
|
|
944
|
+
collector: "perf-cwv",
|
|
945
|
+
detail: `${vpLabel}:cls`
|
|
946
|
+
}),
|
|
947
|
+
pillar: "PERF",
|
|
948
|
+
tier: "T3",
|
|
949
|
+
severity: "high",
|
|
950
|
+
title: `CLS (${snap.cwv.cls}) exceeds ${budgets.cls} budget at ${vpLabel}`,
|
|
951
|
+
plainSummary: `Page layout shifted visibly during load (CLS=${snap.cwv.cls}, target <= ${budgets.cls}).`,
|
|
952
|
+
evidence: {
|
|
953
|
+
url: probeResult.url,
|
|
954
|
+
viewport: vpLabel,
|
|
955
|
+
snippet: `CLS=${snap.cwv.cls}`
|
|
956
|
+
},
|
|
957
|
+
autoFixable: false,
|
|
958
|
+
repairHint: "Reserve explicit width/height dimensions on images, embeds, and dynamic banners.",
|
|
959
|
+
collector: "perf-cwv"
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return findings;
|
|
964
|
+
}
|
|
965
|
+
function createPerfCwvCollector(probe = createPlaywrightBrowserProbe()) {
|
|
966
|
+
return {
|
|
967
|
+
name: "perf-cwv",
|
|
968
|
+
pillar: "PERF",
|
|
969
|
+
tier: "T3",
|
|
970
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
971
|
+
async detect(ctx) {
|
|
972
|
+
return Boolean(ctx.config.appUrl);
|
|
973
|
+
},
|
|
974
|
+
async run(ctx) {
|
|
975
|
+
if (!ctx.config.appUrl) {
|
|
976
|
+
return [];
|
|
977
|
+
}
|
|
978
|
+
const result = await probe.probeUrl(
|
|
979
|
+
ctx.config.appUrl,
|
|
980
|
+
ctx.config.viewports
|
|
981
|
+
);
|
|
982
|
+
return evaluateCwvProbe(result, ctx.config.budgets);
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/collectors/seo-audit.ts
|
|
988
|
+
import path5 from "path";
|
|
989
|
+
import {
|
|
990
|
+
createFindingFingerprint as createFindingFingerprint6
|
|
991
|
+
} from "@arx-hq/contracts";
|
|
992
|
+
|
|
993
|
+
// src/utils/html-parser.ts
|
|
994
|
+
function readAttr(tag, attrName) {
|
|
995
|
+
const regex = new RegExp(
|
|
996
|
+
`\\b${attrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
997
|
+
"i"
|
|
998
|
+
);
|
|
999
|
+
const match = regex.exec(tag);
|
|
1000
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
1001
|
+
}
|
|
1002
|
+
function parseHtmlDocument(html) {
|
|
1003
|
+
const htmlTagMatch = /<html\b[^>]*>/i.exec(html);
|
|
1004
|
+
const htmlLang = htmlTagMatch?.[0] ? readAttr(htmlTagMatch[0], "lang")?.trim() : void 0;
|
|
1005
|
+
const titleMatch = /<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(html);
|
|
1006
|
+
const title = titleMatch?.[1]?.replace(/\s+/g, " ").trim();
|
|
1007
|
+
let description;
|
|
1008
|
+
const ogTags = {};
|
|
1009
|
+
const twitterTags = {};
|
|
1010
|
+
const metaRegex = /<meta\b[^>]*>/gi;
|
|
1011
|
+
let metaMatch = metaRegex.exec(html);
|
|
1012
|
+
while (metaMatch !== null) {
|
|
1013
|
+
const tag = metaMatch[0];
|
|
1014
|
+
const name = readAttr(tag, "name")?.toLowerCase();
|
|
1015
|
+
const property = readAttr(tag, "property")?.toLowerCase();
|
|
1016
|
+
const content = readAttr(tag, "content")?.trim();
|
|
1017
|
+
if (name === "description" && content) {
|
|
1018
|
+
description = content;
|
|
1019
|
+
}
|
|
1020
|
+
if (property?.startsWith("og:") && content) {
|
|
1021
|
+
ogTags[property] = content;
|
|
1022
|
+
}
|
|
1023
|
+
if (name?.startsWith("twitter:") && content) {
|
|
1024
|
+
twitterTags[name] = content;
|
|
1025
|
+
}
|
|
1026
|
+
metaMatch = metaRegex.exec(html);
|
|
1027
|
+
}
|
|
1028
|
+
let canonical;
|
|
1029
|
+
let hasFavicon = false;
|
|
1030
|
+
const linkRegex = /<link\b[^>]*>/gi;
|
|
1031
|
+
let linkMatch = linkRegex.exec(html);
|
|
1032
|
+
while (linkMatch !== null) {
|
|
1033
|
+
const tag = linkMatch[0];
|
|
1034
|
+
const rel = readAttr(tag, "rel")?.toLowerCase() ?? "";
|
|
1035
|
+
const href = readAttr(tag, "href")?.trim();
|
|
1036
|
+
if (rel === "canonical" && href) {
|
|
1037
|
+
canonical = href;
|
|
1038
|
+
}
|
|
1039
|
+
if (rel.includes("icon") && href) {
|
|
1040
|
+
hasFavicon = true;
|
|
1041
|
+
}
|
|
1042
|
+
linkMatch = linkRegex.exec(html);
|
|
1043
|
+
}
|
|
1044
|
+
const headings = [];
|
|
1045
|
+
const headingRegex = /<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/gi;
|
|
1046
|
+
let hMatch = headingRegex.exec(html);
|
|
1047
|
+
while (hMatch !== null) {
|
|
1048
|
+
const level = Number(hMatch[1]);
|
|
1049
|
+
const text = (hMatch[2] ?? "").replace(/<[^>]+>/g, "").trim();
|
|
1050
|
+
headings.push({ level, text });
|
|
1051
|
+
hMatch = headingRegex.exec(html);
|
|
1052
|
+
}
|
|
1053
|
+
const hasMainLandmark = /<main\b/i.test(html) || /\brole\s*=\s*["']main["']/i.test(html);
|
|
1054
|
+
const imagesWithoutAlt = [];
|
|
1055
|
+
const imgRegex = /<img\b[^>]*>/gi;
|
|
1056
|
+
let imgMatch = imgRegex.exec(html);
|
|
1057
|
+
while (imgMatch !== null) {
|
|
1058
|
+
const tag = imgMatch[0];
|
|
1059
|
+
const alt = readAttr(tag, "alt");
|
|
1060
|
+
if (alt === void 0) {
|
|
1061
|
+
imagesWithoutAlt.push(readAttr(tag, "src") ?? "<img without src>");
|
|
1062
|
+
}
|
|
1063
|
+
imgMatch = imgRegex.exec(html);
|
|
1064
|
+
}
|
|
1065
|
+
const internalLinksSet = /* @__PURE__ */ new Set();
|
|
1066
|
+
const anchorRegex = /<a\b[^>]*>/gi;
|
|
1067
|
+
let anchorMatch = anchorRegex.exec(html);
|
|
1068
|
+
while (anchorMatch !== null) {
|
|
1069
|
+
const href = readAttr(anchorMatch[0], "href")?.trim();
|
|
1070
|
+
if (href?.startsWith("/") && !href.startsWith("//") && !href.startsWith("/#")) {
|
|
1071
|
+
const cleanPath = href.split("#")[0]?.split("?")[0] ?? "";
|
|
1072
|
+
if (cleanPath) {
|
|
1073
|
+
internalLinksSet.add(cleanPath);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
anchorMatch = anchorRegex.exec(html);
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
...htmlLang ? { htmlLang } : {},
|
|
1080
|
+
...title ? { title } : {},
|
|
1081
|
+
...description ? { description } : {},
|
|
1082
|
+
...canonical ? { canonical } : {},
|
|
1083
|
+
hasFavicon,
|
|
1084
|
+
ogTags,
|
|
1085
|
+
twitterTags,
|
|
1086
|
+
headings,
|
|
1087
|
+
hasMainLandmark,
|
|
1088
|
+
imagesWithoutAlt,
|
|
1089
|
+
internalLinks: Array.from(internalLinksSet)
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/collectors/seo-audit.ts
|
|
1094
|
+
var STATIC_HTML_CANDIDATES = [
|
|
1095
|
+
"index.html",
|
|
1096
|
+
"public/index.html",
|
|
1097
|
+
"dist/index.html"
|
|
1098
|
+
];
|
|
1099
|
+
function evaluateSeoHtml(html, sourceLabel, options) {
|
|
1100
|
+
const parsed = parseHtmlDocument(html);
|
|
1101
|
+
const findings = [];
|
|
1102
|
+
const baseEvidence = options.isUrl ? { url: sourceLabel } : { file: sourceLabel };
|
|
1103
|
+
if (!parsed.title || parsed.title.length < 10 || parsed.title.length > 65) {
|
|
1104
|
+
findings.push({
|
|
1105
|
+
id: "SEO-01",
|
|
1106
|
+
fingerprint: createFindingFingerprint6({
|
|
1107
|
+
id: "SEO-01",
|
|
1108
|
+
collector: "seo-audit",
|
|
1109
|
+
detail: `${sourceLabel}:title`
|
|
1110
|
+
}),
|
|
1111
|
+
pillar: "SEO",
|
|
1112
|
+
tier: "T2",
|
|
1113
|
+
severity: "high",
|
|
1114
|
+
title: parsed.title ? `Page <title> length (${parsed.title.length} chars) outside ideal 10-65 range` : "Missing <title> tag",
|
|
1115
|
+
plainSummary: "Search engines rely on a clear, well-sized <title> tag to index and display this page.",
|
|
1116
|
+
evidence: {
|
|
1117
|
+
...baseEvidence,
|
|
1118
|
+
...parsed.title ? { snippet: parsed.title } : {}
|
|
1119
|
+
},
|
|
1120
|
+
autoFixable: false,
|
|
1121
|
+
repairHint: "Add a unique <title> between 10 and 65 characters.",
|
|
1122
|
+
collector: "seo-audit"
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
if (!parsed.description) {
|
|
1126
|
+
findings.push({
|
|
1127
|
+
id: "SEO-01",
|
|
1128
|
+
fingerprint: createFindingFingerprint6({
|
|
1129
|
+
id: "SEO-01",
|
|
1130
|
+
collector: "seo-audit",
|
|
1131
|
+
detail: `${sourceLabel}:meta-description`
|
|
1132
|
+
}),
|
|
1133
|
+
pillar: "SEO",
|
|
1134
|
+
tier: "T2",
|
|
1135
|
+
severity: "medium",
|
|
1136
|
+
title: 'Missing <meta name="description"> tag',
|
|
1137
|
+
plainSummary: "Page lacks a meta description used in search engine result snippets.",
|
|
1138
|
+
evidence: baseEvidence,
|
|
1139
|
+
autoFixable: false,
|
|
1140
|
+
repairHint: 'Add `<meta name="description" content="..." />` (120-160 characters).',
|
|
1141
|
+
collector: "seo-audit"
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
const missingSocial = [];
|
|
1145
|
+
if (!parsed.ogTags["og:title"]) {
|
|
1146
|
+
missingSocial.push("og:title");
|
|
1147
|
+
}
|
|
1148
|
+
if (!parsed.ogTags["og:description"]) {
|
|
1149
|
+
missingSocial.push("og:description");
|
|
1150
|
+
}
|
|
1151
|
+
if (!parsed.ogTags["og:image"]) {
|
|
1152
|
+
missingSocial.push("og:image");
|
|
1153
|
+
}
|
|
1154
|
+
if (missingSocial.length > 0) {
|
|
1155
|
+
findings.push({
|
|
1156
|
+
id: "SEO-02",
|
|
1157
|
+
fingerprint: createFindingFingerprint6({
|
|
1158
|
+
id: "SEO-02",
|
|
1159
|
+
collector: "seo-audit",
|
|
1160
|
+
detail: `${sourceLabel}:social:${missingSocial.join(",")}`
|
|
1161
|
+
}),
|
|
1162
|
+
pillar: "SEO",
|
|
1163
|
+
tier: "T2",
|
|
1164
|
+
severity: "low",
|
|
1165
|
+
title: `Missing Open Graph tags: ${missingSocial.join(", ")}`,
|
|
1166
|
+
plainSummary: `Social share previews will look incomplete without ${missingSocial.join(", ")}.`,
|
|
1167
|
+
evidence: { ...baseEvidence, snippet: missingSocial.join(", ") },
|
|
1168
|
+
autoFixable: false,
|
|
1169
|
+
repairHint: `Add Open Graph meta tags (${missingSocial.join(", ")}) in document <head>.`,
|
|
1170
|
+
collector: "seo-audit"
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
const h1Count = parsed.headings.filter((h) => h.level === 1).length;
|
|
1174
|
+
if (h1Count !== 1) {
|
|
1175
|
+
findings.push({
|
|
1176
|
+
id: "SEO-03",
|
|
1177
|
+
fingerprint: createFindingFingerprint6({
|
|
1178
|
+
id: "SEO-03",
|
|
1179
|
+
collector: "seo-audit",
|
|
1180
|
+
detail: `${sourceLabel}:h1-count:${h1Count}`
|
|
1181
|
+
}),
|
|
1182
|
+
pillar: "SEO",
|
|
1183
|
+
tier: "T2",
|
|
1184
|
+
severity: "medium",
|
|
1185
|
+
title: h1Count === 0 ? "Missing <h1> heading" : `Multiple <h1> headings found (${h1Count})`,
|
|
1186
|
+
plainSummary: "Each page should have exactly one primary <h1> heading for semantic clarity.",
|
|
1187
|
+
evidence: baseEvidence,
|
|
1188
|
+
autoFixable: false,
|
|
1189
|
+
repairHint: "Use exactly one <h1> per page and nest subheadings cleanly (h2 -> h3).",
|
|
1190
|
+
collector: "seo-audit"
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
for (let i = 1; i < parsed.headings.length; i += 1) {
|
|
1194
|
+
const prev = parsed.headings[i - 1];
|
|
1195
|
+
const cur = parsed.headings[i];
|
|
1196
|
+
if (prev && cur && cur.level > prev.level + 1) {
|
|
1197
|
+
findings.push({
|
|
1198
|
+
id: "SEO-03",
|
|
1199
|
+
fingerprint: createFindingFingerprint6({
|
|
1200
|
+
id: "SEO-03",
|
|
1201
|
+
collector: "seo-audit",
|
|
1202
|
+
detail: `${sourceLabel}:heading-skip:h${prev.level}->h${cur.level}`
|
|
1203
|
+
}),
|
|
1204
|
+
pillar: "SEO",
|
|
1205
|
+
tier: "T2",
|
|
1206
|
+
severity: "low",
|
|
1207
|
+
title: `Skipped heading level (h${prev.level} -> h${cur.level})`,
|
|
1208
|
+
plainSummary: `Heading hierarchy jumps from <h${prev.level}> directly to <h${cur.level}>.`,
|
|
1209
|
+
evidence: { ...baseEvidence, snippet: cur.text },
|
|
1210
|
+
autoFixable: false,
|
|
1211
|
+
repairHint: `Avoid skipping heading levels between <h${prev.level}> and <h${cur.level}>.`,
|
|
1212
|
+
collector: "seo-audit"
|
|
1213
|
+
});
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
if (!parsed.hasMainLandmark) {
|
|
1218
|
+
findings.push({
|
|
1219
|
+
id: "SEO-03",
|
|
1220
|
+
fingerprint: createFindingFingerprint6({
|
|
1221
|
+
id: "SEO-03",
|
|
1222
|
+
collector: "seo-audit",
|
|
1223
|
+
detail: `${sourceLabel}:missing-main`
|
|
1224
|
+
}),
|
|
1225
|
+
pillar: "SEO",
|
|
1226
|
+
tier: "T2",
|
|
1227
|
+
severity: "low",
|
|
1228
|
+
title: "Missing semantic <main> landmark",
|
|
1229
|
+
plainSummary: "Wrapping primary page content in <main> improves both accessibility and search semantics.",
|
|
1230
|
+
evidence: baseEvidence,
|
|
1231
|
+
autoFixable: false,
|
|
1232
|
+
repairHint: "Wrap the primary page body content inside a <main> landmark.",
|
|
1233
|
+
collector: "seo-audit"
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
if (!options.hasRobotsTxt || !options.hasSitemapXml || !parsed.canonical) {
|
|
1237
|
+
const missingCrawl = [];
|
|
1238
|
+
if (!options.hasRobotsTxt) {
|
|
1239
|
+
missingCrawl.push("robots.txt");
|
|
1240
|
+
}
|
|
1241
|
+
if (!options.hasSitemapXml) {
|
|
1242
|
+
missingCrawl.push("sitemap.xml");
|
|
1243
|
+
}
|
|
1244
|
+
if (!parsed.canonical) {
|
|
1245
|
+
missingCrawl.push("canonical link");
|
|
1246
|
+
}
|
|
1247
|
+
findings.push({
|
|
1248
|
+
id: "SEO-04",
|
|
1249
|
+
fingerprint: createFindingFingerprint6({
|
|
1250
|
+
id: "SEO-04",
|
|
1251
|
+
collector: "seo-audit",
|
|
1252
|
+
detail: `${sourceLabel}:crawl:${missingCrawl.join(",")}`
|
|
1253
|
+
}),
|
|
1254
|
+
pillar: "SEO",
|
|
1255
|
+
tier: "T2",
|
|
1256
|
+
severity: "low",
|
|
1257
|
+
title: `Incomplete crawlability metadata: missing ${missingCrawl.join(", ")}`,
|
|
1258
|
+
plainSummary: `Search crawlers need ${missingCrawl.join(", ")} for optimal indexing.`,
|
|
1259
|
+
evidence: { ...baseEvidence, snippet: missingCrawl.join(", ") },
|
|
1260
|
+
autoFixable: false,
|
|
1261
|
+
repairHint: `Provide ${missingCrawl.join(", ")} for public web pages.`,
|
|
1262
|
+
collector: "seo-audit"
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
return findings;
|
|
1266
|
+
}
|
|
1267
|
+
async function fetchLiveSeoFindings(appUrl, fetchFn) {
|
|
1268
|
+
try {
|
|
1269
|
+
const base = new URL(appUrl);
|
|
1270
|
+
const [pageRes, robotsRes, sitemapRes] = await Promise.all([
|
|
1271
|
+
fetchFn(appUrl, { signal: AbortSignal.timeout(8e3) }),
|
|
1272
|
+
fetchFn(new URL("/robots.txt", base).toString(), {
|
|
1273
|
+
signal: AbortSignal.timeout(4e3)
|
|
1274
|
+
}).catch(() => null),
|
|
1275
|
+
fetchFn(new URL("/sitemap.xml", base).toString(), {
|
|
1276
|
+
signal: AbortSignal.timeout(4e3)
|
|
1277
|
+
}).catch(() => null)
|
|
1278
|
+
]);
|
|
1279
|
+
if (!pageRes.ok) {
|
|
1280
|
+
return null;
|
|
1281
|
+
}
|
|
1282
|
+
const html = await pageRes.text();
|
|
1283
|
+
return evaluateSeoHtml(html, appUrl, {
|
|
1284
|
+
hasRobotsTxt: Boolean(robotsRes?.ok),
|
|
1285
|
+
hasSitemapXml: Boolean(sitemapRes?.ok),
|
|
1286
|
+
isUrl: true
|
|
1287
|
+
});
|
|
1288
|
+
} catch (error) {
|
|
1289
|
+
return error instanceof Error ? null : null;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
function createSeoAuditCollector(fetchFn = fetch) {
|
|
1293
|
+
return {
|
|
1294
|
+
name: "seo-audit",
|
|
1295
|
+
pillar: "SEO",
|
|
1296
|
+
tier: "T2",
|
|
1297
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
1298
|
+
async detect(ctx) {
|
|
1299
|
+
if (ctx.config.appUrl) {
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
for (const candidate of STATIC_HTML_CANDIDATES) {
|
|
1303
|
+
if (await pathExists(path5.resolve(ctx.rootDir, candidate))) {
|
|
1304
|
+
return true;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
return false;
|
|
1308
|
+
},
|
|
1309
|
+
async run(ctx) {
|
|
1310
|
+
if (ctx.config.appUrl) {
|
|
1311
|
+
const liveFindings = await fetchLiveSeoFindings(
|
|
1312
|
+
ctx.config.appUrl,
|
|
1313
|
+
fetchFn
|
|
1314
|
+
);
|
|
1315
|
+
if (liveFindings !== null) {
|
|
1316
|
+
return liveFindings;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
for (const candidate of STATIC_HTML_CANDIDATES) {
|
|
1320
|
+
const content = await readTextIfExists(
|
|
1321
|
+
path5.resolve(ctx.rootDir, candidate)
|
|
1322
|
+
);
|
|
1323
|
+
if (content !== null) {
|
|
1324
|
+
const hasRobots = await pathExists(
|
|
1325
|
+
path5.resolve(ctx.rootDir, "public/robots.txt")
|
|
1326
|
+
) || await pathExists(path5.resolve(ctx.rootDir, "robots.txt"));
|
|
1327
|
+
const hasSitemap = await pathExists(
|
|
1328
|
+
path5.resolve(ctx.rootDir, "public/sitemap.xml")
|
|
1329
|
+
) || await pathExists(path5.resolve(ctx.rootDir, "sitemap.xml"));
|
|
1330
|
+
return evaluateSeoHtml(content, candidate, {
|
|
1331
|
+
hasRobotsTxt: hasRobots,
|
|
1332
|
+
hasSitemapXml: hasSitemap,
|
|
1333
|
+
isUrl: false
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
return [];
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// src/collectors/ux-browser.ts
|
|
1343
|
+
import {
|
|
1344
|
+
createFindingFingerprint as createFindingFingerprint7
|
|
1345
|
+
} from "@arx-hq/contracts";
|
|
1346
|
+
function evaluateUxProbe(probeResult) {
|
|
1347
|
+
if (!probeResult.available) {
|
|
1348
|
+
return [];
|
|
1349
|
+
}
|
|
1350
|
+
const findings = [];
|
|
1351
|
+
const seenErrors = /* @__PURE__ */ new Set();
|
|
1352
|
+
for (const snap of probeResult.viewports) {
|
|
1353
|
+
const vpLabel = `${snap.viewport.width}x${snap.viewport.height}`;
|
|
1354
|
+
for (const violation of snap.axeViolations) {
|
|
1355
|
+
if (violation.impact !== "critical" && violation.impact !== "serious") {
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
const key = `axe:${violation.id}`;
|
|
1359
|
+
if (seenErrors.has(key)) {
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
seenErrors.add(key);
|
|
1363
|
+
findings.push({
|
|
1364
|
+
id: "UX-01",
|
|
1365
|
+
fingerprint: createFindingFingerprint7({
|
|
1366
|
+
id: "UX-01",
|
|
1367
|
+
collector: "ux-browser",
|
|
1368
|
+
detail: key
|
|
1369
|
+
}),
|
|
1370
|
+
pillar: "UX_A11Y",
|
|
1371
|
+
tier: "T3",
|
|
1372
|
+
severity: violation.impact === "critical" ? "critical" : "high",
|
|
1373
|
+
title: `WCAG AA (${violation.impact}): ${violation.id}`,
|
|
1374
|
+
plainSummary: `Accessibility check failed: ${violation.help} (${violation.nodesCount} element(s)).`,
|
|
1375
|
+
evidence: {
|
|
1376
|
+
url: probeResult.url,
|
|
1377
|
+
viewport: vpLabel,
|
|
1378
|
+
snippet: violation.help
|
|
1379
|
+
},
|
|
1380
|
+
autoFixable: false,
|
|
1381
|
+
repairHint: `Resolve axe-core rule "${violation.id}": ${violation.help}`,
|
|
1382
|
+
collector: "ux-browser"
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
if (snap.viewport.width <= 480) {
|
|
1386
|
+
for (const small of snap.smallTapTargets.slice(0, 5)) {
|
|
1387
|
+
findings.push({
|
|
1388
|
+
id: "UX-03",
|
|
1389
|
+
fingerprint: createFindingFingerprint7({
|
|
1390
|
+
id: "UX-03",
|
|
1391
|
+
collector: "ux-browser",
|
|
1392
|
+
detail: `${vpLabel}:${small.selector}:${small.width}x${small.height}`
|
|
1393
|
+
}),
|
|
1394
|
+
pillar: "UX_A11Y",
|
|
1395
|
+
tier: "T3",
|
|
1396
|
+
severity: "medium",
|
|
1397
|
+
title: `Mobile tap target too small (${small.width}x${small.height}px): ${small.selector}`,
|
|
1398
|
+
plainSummary: `Button/link "${small.selector}" is ${small.width}x${small.height}px on mobile; touch targets should be at least 44x44px.`,
|
|
1399
|
+
evidence: {
|
|
1400
|
+
url: probeResult.url,
|
|
1401
|
+
viewport: vpLabel,
|
|
1402
|
+
snippet: `${small.selector} (${small.width}x${small.height}px)`
|
|
1403
|
+
},
|
|
1404
|
+
autoFixable: false,
|
|
1405
|
+
repairHint: `Increase hit area/padding of ${small.selector} to at least 44x44px on mobile viewports.`,
|
|
1406
|
+
collector: "ux-browser"
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
for (const errMsg of [...snap.consoleErrors, ...snap.pageErrors]) {
|
|
1411
|
+
const key = `runtime:${errMsg.slice(0, 120)}`;
|
|
1412
|
+
if (seenErrors.has(key)) {
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
seenErrors.add(key);
|
|
1416
|
+
findings.push({
|
|
1417
|
+
id: "UX-05",
|
|
1418
|
+
fingerprint: createFindingFingerprint7({
|
|
1419
|
+
id: "UX-05",
|
|
1420
|
+
collector: "ux-browser",
|
|
1421
|
+
detail: key
|
|
1422
|
+
}),
|
|
1423
|
+
pillar: "UX_A11Y",
|
|
1424
|
+
tier: "T3",
|
|
1425
|
+
severity: "critical",
|
|
1426
|
+
title: "Browser runtime or hydration error",
|
|
1427
|
+
plainSummary: `The page threw a runtime error in the browser: ${errMsg.slice(0, 120)}`,
|
|
1428
|
+
evidence: {
|
|
1429
|
+
url: probeResult.url,
|
|
1430
|
+
viewport: vpLabel,
|
|
1431
|
+
snippet: errMsg.slice(0, 240)
|
|
1432
|
+
},
|
|
1433
|
+
autoFixable: false,
|
|
1434
|
+
repairHint: `Fix the browser console/runtime error at ${probeResult.url}: ${errMsg.slice(0, 160)}`,
|
|
1435
|
+
collector: "ux-browser"
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return findings;
|
|
1440
|
+
}
|
|
1441
|
+
async function crawlInternalLinks(appUrl, fetchFn = fetch) {
|
|
1442
|
+
const findings = [];
|
|
1443
|
+
let html;
|
|
1444
|
+
try {
|
|
1445
|
+
const res = await fetchFn(appUrl, { signal: AbortSignal.timeout(8e3) });
|
|
1446
|
+
if (res.status >= 400) {
|
|
1447
|
+
return [
|
|
1448
|
+
{
|
|
1449
|
+
id: "UX-04",
|
|
1450
|
+
fingerprint: createFindingFingerprint7({
|
|
1451
|
+
id: "UX-04",
|
|
1452
|
+
collector: "ux-browser",
|
|
1453
|
+
detail: `root-status:${res.status}`
|
|
1454
|
+
}),
|
|
1455
|
+
pillar: "UX_A11Y",
|
|
1456
|
+
tier: "T3",
|
|
1457
|
+
severity: "critical",
|
|
1458
|
+
title: `App URL returned HTTP ${res.status}`,
|
|
1459
|
+
plainSummary: `Main page ${appUrl} responded with HTTP error ${res.status}.`,
|
|
1460
|
+
evidence: { url: appUrl },
|
|
1461
|
+
autoFixable: false,
|
|
1462
|
+
repairHint: `Fix server route error returning HTTP ${res.status} at ${appUrl}.`,
|
|
1463
|
+
collector: "ux-browser"
|
|
1464
|
+
}
|
|
1465
|
+
];
|
|
1466
|
+
}
|
|
1467
|
+
html = await res.text();
|
|
1468
|
+
} catch {
|
|
1469
|
+
return [];
|
|
1470
|
+
}
|
|
1471
|
+
const parsed = parseHtmlDocument(html);
|
|
1472
|
+
if (!parsed.htmlLang) {
|
|
1473
|
+
findings.push({
|
|
1474
|
+
id: "UX-01",
|
|
1475
|
+
fingerprint: createFindingFingerprint7({
|
|
1476
|
+
id: "UX-01",
|
|
1477
|
+
collector: "ux-browser",
|
|
1478
|
+
detail: `missing-html-lang:${appUrl}`
|
|
1479
|
+
}),
|
|
1480
|
+
pillar: "UX_A11Y",
|
|
1481
|
+
tier: "T3",
|
|
1482
|
+
severity: "high",
|
|
1483
|
+
title: "Missing lang attribute on <html>",
|
|
1484
|
+
plainSummary: "Screen readers cannot determine the document language because <html lang> is missing.",
|
|
1485
|
+
evidence: { url: appUrl },
|
|
1486
|
+
autoFixable: true,
|
|
1487
|
+
repairHint: 'Add a valid language attribute such as `<html lang="en">`.',
|
|
1488
|
+
collector: "ux-browser"
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
for (const imgSrc of parsed.imagesWithoutAlt) {
|
|
1492
|
+
findings.push({
|
|
1493
|
+
id: "UX-01",
|
|
1494
|
+
fingerprint: createFindingFingerprint7({
|
|
1495
|
+
id: "UX-01",
|
|
1496
|
+
collector: "ux-browser",
|
|
1497
|
+
detail: `missing-alt:${imgSrc}`
|
|
1498
|
+
}),
|
|
1499
|
+
pillar: "UX_A11Y",
|
|
1500
|
+
tier: "T3",
|
|
1501
|
+
severity: "critical",
|
|
1502
|
+
title: `Image missing alt attribute: ${imgSrc}`,
|
|
1503
|
+
plainSummary: `Image "${imgSrc}" has no alt text for screen reader accessibility.`,
|
|
1504
|
+
evidence: { url: appUrl, snippet: imgSrc },
|
|
1505
|
+
autoFixable: false,
|
|
1506
|
+
repairHint: `Add descriptive alt text (or alt="" for decorative images) to "${imgSrc}".`,
|
|
1507
|
+
collector: "ux-browser"
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
const base = new URL(appUrl);
|
|
1511
|
+
for (const relHref of parsed.internalLinks.slice(0, 25)) {
|
|
1512
|
+
const targetUrl = new URL(relHref, base).toString();
|
|
1513
|
+
try {
|
|
1514
|
+
const linkRes = await fetchFn(targetUrl, {
|
|
1515
|
+
signal: AbortSignal.timeout(5e3)
|
|
1516
|
+
});
|
|
1517
|
+
if (linkRes.status >= 400) {
|
|
1518
|
+
findings.push({
|
|
1519
|
+
id: "UX-04",
|
|
1520
|
+
fingerprint: createFindingFingerprint7({
|
|
1521
|
+
id: "UX-04",
|
|
1522
|
+
collector: "ux-browser",
|
|
1523
|
+
detail: `broken-link:${relHref}:${linkRes.status}`
|
|
1524
|
+
}),
|
|
1525
|
+
pillar: "UX_A11Y",
|
|
1526
|
+
tier: "T3",
|
|
1527
|
+
severity: "high",
|
|
1528
|
+
title: `Broken internal link ${relHref} (HTTP ${linkRes.status})`,
|
|
1529
|
+
plainSummary: `Internal link "${relHref}" returns HTTP ${linkRes.status}.`,
|
|
1530
|
+
evidence: { url: targetUrl, snippet: `HTTP ${linkRes.status}` },
|
|
1531
|
+
autoFixable: false,
|
|
1532
|
+
repairHint: `Fix or remove broken internal route "${relHref}" returning HTTP ${linkRes.status}.`,
|
|
1533
|
+
collector: "ux-browser"
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
} catch {
|
|
1537
|
+
findings.push({
|
|
1538
|
+
id: "UX-04",
|
|
1539
|
+
fingerprint: createFindingFingerprint7({
|
|
1540
|
+
id: "UX-04",
|
|
1541
|
+
collector: "ux-browser",
|
|
1542
|
+
detail: `unreachable-link:${relHref}`
|
|
1543
|
+
}),
|
|
1544
|
+
pillar: "UX_A11Y",
|
|
1545
|
+
tier: "T3",
|
|
1546
|
+
severity: "high",
|
|
1547
|
+
title: `Unreachable internal link ${relHref}`,
|
|
1548
|
+
plainSummary: `Internal route "${relHref}" failed to respond.`,
|
|
1549
|
+
evidence: { url: targetUrl },
|
|
1550
|
+
autoFixable: false,
|
|
1551
|
+
repairHint: `Verify route "${relHref}" responds cleanly without crashing.`,
|
|
1552
|
+
collector: "ux-browser"
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
return findings;
|
|
1557
|
+
}
|
|
1558
|
+
function createUxBrowserCollector(probe = createPlaywrightBrowserProbe(), fetchFn = fetch) {
|
|
1559
|
+
return {
|
|
1560
|
+
name: "ux-browser",
|
|
1561
|
+
pillar: "UX_A11Y",
|
|
1562
|
+
tier: "T3",
|
|
1563
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
1564
|
+
async detect(ctx) {
|
|
1565
|
+
return Boolean(ctx.config.appUrl);
|
|
1566
|
+
},
|
|
1567
|
+
async run(ctx) {
|
|
1568
|
+
if (!ctx.config.appUrl) {
|
|
1569
|
+
return [];
|
|
1570
|
+
}
|
|
1571
|
+
const [linkFindings, probeResult] = await Promise.all([
|
|
1572
|
+
crawlInternalLinks(ctx.config.appUrl, fetchFn),
|
|
1573
|
+
probe.probeUrl(ctx.config.appUrl, ctx.config.viewports)
|
|
1574
|
+
]);
|
|
1575
|
+
return [...linkFindings, ...evaluateUxProbe(probeResult)];
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/collectors/ux-states.ts
|
|
1581
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
1582
|
+
import path6 from "path";
|
|
1583
|
+
import {
|
|
1584
|
+
createFindingFingerprint as createFindingFingerprint8
|
|
1585
|
+
} from "@arx-hq/contracts";
|
|
1586
|
+
import ts2 from "typescript";
|
|
1587
|
+
var JSX_EXTENSIONS = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
1588
|
+
var NON_INTERACTIVE_TAGS = /* @__PURE__ */ new Set(["div", "span", "p", "li", "section"]);
|
|
1589
|
+
function scanUxStaticAst(relFile, content) {
|
|
1590
|
+
const findings = [];
|
|
1591
|
+
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
1592
|
+
const sourceFile = ts2.createSourceFile(
|
|
1593
|
+
relFile,
|
|
1594
|
+
content,
|
|
1595
|
+
ts2.ScriptTarget.Latest,
|
|
1596
|
+
true,
|
|
1597
|
+
ts2.ScriptKind.TSX
|
|
1598
|
+
);
|
|
1599
|
+
let fetchesData = false;
|
|
1600
|
+
let hasLoadingState = false;
|
|
1601
|
+
let hasErrorState = false;
|
|
1602
|
+
function visit(node) {
|
|
1603
|
+
if (ts2.isJsxOpeningLikeElement(node)) {
|
|
1604
|
+
const tagName = node.tagName.getText(sourceFile).toLowerCase();
|
|
1605
|
+
if (NON_INTERACTIVE_TAGS.has(tagName)) {
|
|
1606
|
+
const attrNames = /* @__PURE__ */ new Set();
|
|
1607
|
+
for (const prop of node.attributes.properties) {
|
|
1608
|
+
if (ts2.isJsxAttribute(prop) && ts2.isIdentifier(prop.name)) {
|
|
1609
|
+
attrNames.add(prop.name.text);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (attrNames.has("onClick") && !attrNames.has("role") && !attrNames.has("tabIndex")) {
|
|
1613
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(
|
|
1614
|
+
node.getStart(sourceFile)
|
|
1615
|
+
);
|
|
1616
|
+
const line = pos.line + 1;
|
|
1617
|
+
if (!isSuppressedAtLine(lines, line, "UX-02")) {
|
|
1618
|
+
findings.push({
|
|
1619
|
+
id: "UX-02",
|
|
1620
|
+
fingerprint: createFindingFingerprint8({
|
|
1621
|
+
id: "UX-02",
|
|
1622
|
+
collector: "ux-static",
|
|
1623
|
+
file: relFile,
|
|
1624
|
+
line,
|
|
1625
|
+
detail: `non-interactive-click:${tagName}`
|
|
1626
|
+
}),
|
|
1627
|
+
pillar: "UX_A11Y",
|
|
1628
|
+
tier: "T2",
|
|
1629
|
+
severity: "high",
|
|
1630
|
+
title: `Clickable non-interactive <${tagName}> without keyboard support`,
|
|
1631
|
+
plainSummary: `A <${tagName}> element handles clicks in ${relFile}:${line} without keyboard/ARIA accessibility.`,
|
|
1632
|
+
evidence: {
|
|
1633
|
+
file: relFile,
|
|
1634
|
+
line,
|
|
1635
|
+
snippet: lines[line - 1]?.trim().slice(0, 140)
|
|
1636
|
+
},
|
|
1637
|
+
autoFixable: false,
|
|
1638
|
+
repairHint: `Use a native <button type="button"> or add role="button", tabIndex={0}, and onKeyDown at ${relFile}:${line}.`,
|
|
1639
|
+
collector: "ux-static"
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
if (ts2.isCallExpression(node)) {
|
|
1646
|
+
const callee = node.expression.getText(sourceFile);
|
|
1647
|
+
if (callee === "fetch" || callee.endsWith(".fetch") || callee === "useQuery" || callee === "useSWR") {
|
|
1648
|
+
fetchesData = true;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (ts2.isIdentifier(node)) {
|
|
1652
|
+
const lower = node.text.toLowerCase();
|
|
1653
|
+
if (lower.includes("loading") || lower.includes("ispending") || lower.includes("skeleton") || lower.includes("suspense")) {
|
|
1654
|
+
hasLoadingState = true;
|
|
1655
|
+
}
|
|
1656
|
+
if (lower.includes("error") || lower.includes("iserror")) {
|
|
1657
|
+
hasErrorState = true;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
ts2.forEachChild(node, visit);
|
|
1661
|
+
}
|
|
1662
|
+
visit(sourceFile);
|
|
1663
|
+
if (fetchesData && (!hasLoadingState || !hasErrorState) && !isSuppressedAtLine(lines, 1, "UX-06")) {
|
|
1664
|
+
const missing = [
|
|
1665
|
+
...!hasLoadingState ? ["loading"] : [],
|
|
1666
|
+
...!hasErrorState ? ["error"] : []
|
|
1667
|
+
].join(" and ");
|
|
1668
|
+
findings.push({
|
|
1669
|
+
id: "UX-06",
|
|
1670
|
+
fingerprint: createFindingFingerprint8({
|
|
1671
|
+
id: "UX-06",
|
|
1672
|
+
collector: "ux-static",
|
|
1673
|
+
file: relFile,
|
|
1674
|
+
detail: `missing-ux-states:${missing}`
|
|
1675
|
+
}),
|
|
1676
|
+
pillar: "UX_A11Y",
|
|
1677
|
+
tier: "T2",
|
|
1678
|
+
severity: "medium",
|
|
1679
|
+
title: `Async view missing ${missing} state in ${relFile}`,
|
|
1680
|
+
plainSummary: `${relFile} fetches data without handling ${missing} UI state(s), leaving users with blank or broken screens.`,
|
|
1681
|
+
evidence: { file: relFile, line: 1 },
|
|
1682
|
+
autoFixable: false,
|
|
1683
|
+
repairHint: `Add explicit ${missing} UI state handling in ${relFile}.`,
|
|
1684
|
+
collector: "ux-static"
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
return findings;
|
|
1688
|
+
}
|
|
1689
|
+
function createUxStaticCollector() {
|
|
1690
|
+
return {
|
|
1691
|
+
name: "ux-static",
|
|
1692
|
+
pillar: "UX_A11Y",
|
|
1693
|
+
tier: "T2",
|
|
1694
|
+
supportedStacks: ["nextjs", "vite", "react", "web"],
|
|
1695
|
+
async detect(ctx) {
|
|
1696
|
+
const files = await walkProjectFiles({
|
|
1697
|
+
rootDir: ctx.rootDir,
|
|
1698
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
1699
|
+
extensions: JSX_EXTENSIONS
|
|
1700
|
+
});
|
|
1701
|
+
return files.length > 0;
|
|
1702
|
+
},
|
|
1703
|
+
async run(ctx) {
|
|
1704
|
+
const files = await walkProjectFiles({
|
|
1705
|
+
rootDir: ctx.rootDir,
|
|
1706
|
+
ignorePaths: ctx.config.ignorePaths,
|
|
1707
|
+
extensions: JSX_EXTENSIONS
|
|
1708
|
+
});
|
|
1709
|
+
const findings = [];
|
|
1710
|
+
for (const relFile of files) {
|
|
1711
|
+
if (relFile.includes("/test/") || relFile.includes("/tests/")) {
|
|
1712
|
+
continue;
|
|
1713
|
+
}
|
|
1714
|
+
const content = await readFile5(
|
|
1715
|
+
path6.resolve(ctx.rootDir, relFile),
|
|
1716
|
+
"utf8"
|
|
1717
|
+
);
|
|
1718
|
+
findings.push(...scanUxStaticAst(relFile, content));
|
|
1719
|
+
}
|
|
1720
|
+
return findings;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
// src/index.ts
|
|
1726
|
+
var COLLECTORS_BROWSER_SCHEMA_VERSION = ARX_SCHEMA_VERSION;
|
|
1727
|
+
function createBrowserCollectors(options = {}) {
|
|
1728
|
+
const probe = options.probe ?? createPlaywrightBrowserProbe();
|
|
1729
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
1730
|
+
return [
|
|
1731
|
+
createDesignTokensCollector(),
|
|
1732
|
+
createDesignBrowserCollector(probe),
|
|
1733
|
+
createUxStaticCollector(),
|
|
1734
|
+
createUxBrowserCollector(probe, fetchFn),
|
|
1735
|
+
createPerfBundleCollector(),
|
|
1736
|
+
createPerfAstCollector(),
|
|
1737
|
+
createPerfCwvCollector(probe),
|
|
1738
|
+
createSeoAuditCollector(fetchFn)
|
|
1739
|
+
];
|
|
1740
|
+
}
|
|
1741
|
+
export {
|
|
1742
|
+
COLLECTORS_BROWSER_SCHEMA_VERSION,
|
|
1743
|
+
crawlInternalLinks,
|
|
1744
|
+
createBrowserCollectors,
|
|
1745
|
+
createDesignBrowserCollector,
|
|
1746
|
+
createDesignTokensCollector,
|
|
1747
|
+
createIgnoreMatcher,
|
|
1748
|
+
createPerfAstCollector,
|
|
1749
|
+
createPerfBundleCollector,
|
|
1750
|
+
createPerfCwvCollector,
|
|
1751
|
+
createPlaywrightBrowserProbe,
|
|
1752
|
+
createSeoAuditCollector,
|
|
1753
|
+
createUxBrowserCollector,
|
|
1754
|
+
createUxStaticCollector,
|
|
1755
|
+
evaluateCwvProbe,
|
|
1756
|
+
evaluateDesignProbe,
|
|
1757
|
+
evaluateSeoHtml,
|
|
1758
|
+
evaluateUxProbe,
|
|
1759
|
+
isSuppressedAtLine,
|
|
1760
|
+
parseHtmlDocument,
|
|
1761
|
+
pathExists,
|
|
1762
|
+
readTextIfExists,
|
|
1763
|
+
scanDesignTokens,
|
|
1764
|
+
scanPerfAstPatterns,
|
|
1765
|
+
scanUxStaticAst,
|
|
1766
|
+
toPosix,
|
|
1767
|
+
walkProjectFiles
|
|
1768
|
+
};
|
|
1769
|
+
//# sourceMappingURL=index.js.map
|