eaa-kit 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +2 -1
  2. package/dist/astro/index.d.ts +7 -34
  3. package/dist/astro/index.js +6 -26
  4. package/dist/audit/runners/worker.js +1 -1
  5. package/dist/audit-CuG2hYyo.js +2 -0
  6. package/dist/audit-DcL73mOC.js +635 -0
  7. package/dist/{baseline-CV_3lbER.js → baseline-CuKFq4IF.js} +1 -1
  8. package/dist/{baseline-CgBmzFTr.js → baseline-s9F3fXTN.js} +16 -26
  9. package/dist/cli/index.js +81 -143
  10. package/dist/collect-BkAQ0viT.js +123 -0
  11. package/dist/command-Dxpa00Ha.js +77 -0
  12. package/dist/component-7kEBjv_y.js +111 -0
  13. package/dist/{crawl-CtJbMNNb.js → crawl-Oxt2Gaqo.js} +13 -23
  14. package/dist/frameworks-BYa3tULg.js +243 -0
  15. package/dist/frameworks-DaDqrJOw.js +2 -0
  16. package/dist/fs-BmPtmFke.js +40 -0
  17. package/dist/{html-BLEuzep6.js → html-DKiI_3gs.js} +167 -86
  18. package/dist/{impact-DvgBjupx.js → impact-YdoOtFqm.js} +15 -1
  19. package/dist/index.js +2 -2
  20. package/dist/{init-DRKIdpK1.js → init-DiLiYvN1.js} +13 -10
  21. package/dist/{jsdom-BEu6Ra_2.js → jsdom-BjpF-2V-.js} +2 -7
  22. package/dist/jsdom-X4KYfTp8.js +3 -0
  23. package/dist/json-B0Y7rNjt.js +2 -0
  24. package/dist/{json-C9xS1PNC.js → json-Cnv9nd6U.js} +13 -21
  25. package/dist/{load-sCkKsvGQ.js → load-UYXLqGV9.js} +2 -8
  26. package/dist/manual-Vz-oX1I_.js +239 -0
  27. package/dist/{playwright-DWux49V3.js → playwright-DYFsGUNd.js} +79 -21
  28. package/dist/{pool-DixLeu8L.js → pool-BWkWZiJW.js} +4 -12
  29. package/dist/{project-CiyzKQud.js → project-DW08TseF.js} +37 -27
  30. package/dist/{render-BO0nVrrZ.js → render-DI_aCnAZ.js} +7 -15
  31. package/dist/{result-2aZPfM8w.js → result-DLxd2Eip.js} +38 -1
  32. package/dist/{routes-BxbSZKXC.js → routes-C2Cgf6Ko.js} +4 -8
  33. package/dist/run-BMASMmwO.d.ts +45 -0
  34. package/dist/run-BW6CVuND.js +36 -0
  35. package/dist/{sarif-eSCuI0eX.js → sarif-DB3WG7T9.js} +11 -33
  36. package/dist/text-BFmNtMsV.js +43 -0
  37. package/dist/vite/index.d.ts +39 -0
  38. package/dist/vite/index.js +40 -0
  39. package/package.json +8 -3
  40. package/dist/audit-CqrR9pIO.js +0 -2
  41. package/dist/audit-D4gju2BT.js +0 -949
  42. package/dist/escape-Dm1o_RAk.js +0 -21
  43. package/dist/jsdom-C6dIyaxN.js +0 -3
@@ -0,0 +1,635 @@
1
+ import { a as impactRank, i as impactLabel, r as countAtOrAbove } from "./impact-YdoOtFqm.js";
2
+ import { n as count, t as collapse } from "./text-BFmNtMsV.js";
3
+ import { a as groupIssues, i as coverageParts, n as understandingUrl, o as isShared, r as blindRules, t as manualCheckFor } from "./manual-Vz-oX1I_.js";
4
+ import { a as runEngine, i as note, n as emitDocument, o as warn, r as fail, t as advise } from "./command-Dxpa00Ha.js";
5
+ import { n as collectPages, r as emptyDirectoryHint, t as BuildDirectoryError } from "./collect-BkAQ0viT.js";
6
+ import path from "node:path";
7
+ import pc from "picocolors";
8
+ //#region src/audit/report/console.ts
9
+ const DEFAULT_MAX_NODES = 3;
10
+ const MIN_WIDTH = 40;
11
+ const MAX_WIDTH = 100;
12
+ /**
13
+ * Human-readable audit report.
14
+ *
15
+ * Deliberately not a columnar table: rule ids, help text and selectors are all
16
+ * variable-length, so a real table either wraps into soup or scrolls sideways
17
+ * on a narrow terminal. Everything is left-aligned and indented instead, and
18
+ * every line is assembled from segments trimmed as a group, so the width
19
+ * guarantee holds however long a selector or rule id turns out to be.
20
+ *
21
+ * Returns a string rather than printing, so the format is testable.
22
+ */
23
+ function formatConsoleReport(audits, options = {}) {
24
+ const ctx = context(options);
25
+ const lines = [
26
+ "",
27
+ ...headerLines(audits, ctx),
28
+ ""
29
+ ];
30
+ lines.push(...issuesSection(audits, ctx));
31
+ if (options.perPage) {
32
+ lines.push("", ...legendLines(ctx), "");
33
+ for (const audit of audits) lines.push(...pageSection(audit, ctx));
34
+ }
35
+ lines.push(...summary(audits, ctx));
36
+ return lines.join("\n");
37
+ }
38
+ function context(options) {
39
+ const detected = process.stdout.columns ?? 80;
40
+ const width = Math.min(Math.max(options.width ?? detected, MIN_WIDTH), MAX_WIDTH);
41
+ const c = pc.createColors(options.color ?? pc.isColorSupported);
42
+ const unicode = supportsUnicode();
43
+ return {
44
+ width,
45
+ maxNodes: options.maxNodes ?? DEFAULT_MAX_NODES,
46
+ failOn: options.failOn ?? "serious",
47
+ sourceFor: options.sourceFor ?? (() => void 0),
48
+ componentFor: options.componentFor ?? (() => void 0),
49
+ manual: options.manual ?? false,
50
+ c,
51
+ symbol: (kind) => {
52
+ switch (kind) {
53
+ case "violation": return unicode ? "✗" : "x";
54
+ case "review": return "?";
55
+ case "blind": return unicode ? "·" : "-";
56
+ case "clean": return unicode ? "✓" : "+";
57
+ case "error": return "!";
58
+ }
59
+ }
60
+ };
61
+ }
62
+ /** cmd.exe and older Windows consoles render these glyphs as mojibake. */
63
+ function supportsUnicode() {
64
+ if (process.platform !== "win32") return true;
65
+ return Boolean(process.env["WT_SESSION"] || process.env["TERM_PROGRAM"] || process.env["ConEmuTask"] || process.env["TERM"]);
66
+ }
67
+ /**
68
+ * Joins segments into one line, trimming the group to the terminal width.
69
+ * Colour codes are applied after trimming, so they never count towards it.
70
+ */
71
+ function render(ctx, segments) {
72
+ let remaining = ctx.width;
73
+ const parts = [];
74
+ for (const segment of segments) {
75
+ if (remaining <= 0) break;
76
+ const text = segment.text.length <= remaining ? segment.text : `${segment.text.slice(0, Math.max(remaining - 1, 0))}…`;
77
+ remaining -= text.length;
78
+ parts.push(segment.paint ? segment.paint(text) : text);
79
+ }
80
+ return parts.join("");
81
+ }
82
+ /** One line from a single segment, which is what most of this report is. */
83
+ function line(ctx, text, paint) {
84
+ return render(ctx, paint === void 0 ? [{ text }] : [{
85
+ text,
86
+ paint
87
+ }]);
88
+ }
89
+ function headerLines(audits, ctx) {
90
+ const engineLabel = (audits[0]?.engine ?? "jsdom") === "browser" ? "chromium" : "jsdom (browserless)";
91
+ return [render(ctx, [{
92
+ text: "eaa-kit audit",
93
+ paint: ctx.c.bold
94
+ }, {
95
+ text: ` ${count(audits.length, "page")} · ${engineLabel}`,
96
+ paint: ctx.c.dim
97
+ }])];
98
+ }
99
+ /**
100
+ * What the per-page counts mean.
101
+ *
102
+ * Only with the per-page listing, which is the only place those words appear:
103
+ * "not applicable" reads like good news unless it is spelled out, and printing
104
+ * the gloss for a section that is not there is noise.
105
+ */
106
+ function legendLines(ctx) {
107
+ return [line(ctx, "passed = checked and met · not applicable = nothing to check", ctx.c.dim)];
108
+ }
109
+ function pageSection(audit, ctx) {
110
+ const lines = [line(ctx, audit.relativePath, ctx.c.underline)];
111
+ if (audit.error) {
112
+ lines.push(render(ctx, [{
113
+ text: ` ${ctx.symbol("error")} not audited: `,
114
+ paint: ctx.c.red
115
+ }, { text: audit.error }]), "");
116
+ return lines;
117
+ }
118
+ for (const finding of sortByImpact(audit.violations)) lines.push(...violationLines(finding, ctx));
119
+ for (const finding of audit.incomplete.filter((item) => item.reason === "needs-review")) lines.push(render(ctx, [
120
+ {
121
+ text: ` ${ctx.symbol("review")} `,
122
+ paint: ctx.c.yellow
123
+ },
124
+ {
125
+ text: finding.ruleId,
126
+ paint: ctx.c.yellow
127
+ },
128
+ {
129
+ text: ` needs manual review${criteria(finding)}`,
130
+ paint: ctx.c.dim
131
+ }
132
+ ]));
133
+ if (audit.violations.length === 0) {
134
+ const clean = (audit.accepted ?? []).length === 0;
135
+ lines.push(render(ctx, [{
136
+ text: ` ${ctx.symbol("clean")} `,
137
+ paint: clean ? ctx.c.green : ctx.c.dim
138
+ }, {
139
+ text: clean ? "no violations" : "no new violations",
140
+ paint: clean ? ctx.c.green : ctx.c.dim
141
+ }]));
142
+ }
143
+ for (const finding of sortByImpact(audit.accepted ?? [])) {
144
+ const elements = count(finding.nodes.length, "element");
145
+ lines.push(line(ctx, ` · ${finding.ruleId} accepted by the baseline (${elements})`, ctx.c.dim));
146
+ }
147
+ lines.push(coverageLine(audit, ctx));
148
+ lines.push("");
149
+ return lines;
150
+ }
151
+ function coverageLine(audit, ctx) {
152
+ return line(ctx, ` ${coverageParts(audit).join(" · ")}`, ctx.c.dim);
153
+ }
154
+ function violationLines(finding, ctx) {
155
+ const impact = finding.impact ?? "unknown";
156
+ const lines = [render(ctx, [
157
+ {
158
+ text: ` ${ctx.symbol("violation")} `,
159
+ paint: ctx.c.red
160
+ },
161
+ {
162
+ text: finding.ruleId,
163
+ paint: ctx.c.bold
164
+ },
165
+ {
166
+ text: ` ${impact}${criteria(finding)}`,
167
+ paint: ctx.c.dim
168
+ }
169
+ ]), line(ctx, ` ${finding.help}`)];
170
+ for (const node of finding.nodes.slice(0, ctx.maxNodes)) {
171
+ lines.push(line(ctx, ` ${node.target.join(" ")}`, ctx.c.cyan));
172
+ lines.push(line(ctx, ` ${collapse(node.html)}`, ctx.c.dim));
173
+ }
174
+ const hidden = finding.nodes.length - ctx.maxNodes;
175
+ if (hidden > 0) lines.push(line(ctx, ` + ${count(hidden, "more element")}`, ctx.c.dim));
176
+ return lines;
177
+ }
178
+ function summary(audits, ctx) {
179
+ const withViolations = audits.filter((audit) => audit.violations.length > 0);
180
+ const errored = audits.filter((audit) => audit.error);
181
+ const ruleCount = audits.reduce((total, audit) => total + audit.violations.length, 0);
182
+ const elementCount = audits.reduce((total, audit) => total + audit.violations.reduce((sum, finding) => sum + finding.nodes.length, 0), 0);
183
+ const reviewCount = countRules(audits, "needs-review");
184
+ const pages = count(audits.length, "page");
185
+ const lines = [line(ctx, "Summary", ctx.c.bold)];
186
+ if (ruleCount === 0) lines.push(line(ctx, ` No violations across ${pages}.`, ctx.c.green));
187
+ else {
188
+ lines.push(render(ctx, [{
189
+ text: ` ${count(ruleCount, "violation")} on ${withViolations.length} of ${pages}`,
190
+ paint: ctx.c.red
191
+ }, {
192
+ text: ` (${count(elementCount, "element")})`,
193
+ paint: ctx.c.dim
194
+ }]));
195
+ lines.push(thresholdLine(audits, ctx));
196
+ }
197
+ if (reviewCount > 0) {
198
+ const verb = reviewCount === 1 ? "needs" : "need";
199
+ lines.push(line(ctx, ` ${count(reviewCount, "rule")} ${verb} manual review`, ctx.c.yellow));
200
+ }
201
+ if (errored.length > 0) lines.push(line(ctx, ` ${count(errored.length, "page")} could not be audited`, ctx.c.red));
202
+ const accepted = audits.reduce((total, audit) => total + (audit.accepted ?? []).reduce((sum, finding) => sum + finding.nodes.length, 0), 0);
203
+ if (accepted > 0) lines.push(line(ctx, ` ${count(accepted, "element")} accepted by the baseline, not counted above`, ctx.c.dim));
204
+ lines.push(...blindSection(audits, ctx));
205
+ return lines;
206
+ }
207
+ /**
208
+ * Why the run passed or failed. Without this, a build that exits 0 while the
209
+ * report lists violations looks like a bug rather than a threshold choice.
210
+ */
211
+ function thresholdLine(audits, ctx) {
212
+ const failOn = ctx.failOn;
213
+ const failing = countAtOrAbove(audits, failOn);
214
+ if (failing === 0) return line(ctx, ` none at or above ${failOn} (--fail-on ${failOn}), so this run passes`, ctx.c.green);
215
+ return line(ctx, ` ${failing} at or above ${failOn} (--fail-on ${failOn})`, ctx.c.red);
216
+ }
217
+ /**
218
+ * The unevaluated rules are listed once, at the end, rather than repeated under
219
+ * every page: on a large site the same handful recurs on each one, and a wall
220
+ * of "not evaluated" would bury the findings that are real.
221
+ */
222
+ function blindSection(audits, ctx) {
223
+ const blind = blindRules(audits).sort((a, b) => b.pages - a.pages);
224
+ if (blind.length === 0) return [];
225
+ const lines = [
226
+ "",
227
+ line(ctx, "Not evaluated", ctx.c.bold),
228
+ line(ctx, " This engine reached no verdict on these.", ctx.c.dim),
229
+ line(ctx, " They are never reported as passing.", ctx.c.dim)
230
+ ];
231
+ for (const { ruleId, pages, finding } of blind) {
232
+ lines.push(render(ctx, [
233
+ { text: ` ${ctx.symbol("blind")} ` },
234
+ { text: ruleId },
235
+ {
236
+ text: ` ${count(pages, "page")}${criteria(finding)}`,
237
+ paint: ctx.c.dim
238
+ }
239
+ ]), line(ctx, ` ${finding.reasonDetail}`, ctx.c.dim));
240
+ const manual = manualCheckFor(ruleId);
241
+ if (manual !== void 0 && ctx.manual) {
242
+ for (const wrapped of wrap(manual.check, ctx.width - 8)) lines.push(line(ctx, ` ${wrapped}`, ctx.c.dim));
243
+ if (manual.browserAnswers) lines.push(line(ctx, " or run again with --browser", ctx.c.dim));
244
+ }
245
+ for (const criterion of finding.successCriteria) {
246
+ const url = understandingUrl(criterion);
247
+ if (url !== void 0) lines.push(line(ctx, ` ${criterion}: ${url}`, ctx.c.dim));
248
+ }
249
+ }
250
+ if (!ctx.manual) lines.push(line(ctx, " Run with --manual for what to check by hand.", ctx.c.dim));
251
+ return lines;
252
+ }
253
+ function countRules(audits, reason) {
254
+ const ruleIds = /* @__PURE__ */ new Set();
255
+ for (const audit of audits) for (const finding of audit.incomplete) if (finding.reason === reason) ruleIds.add(finding.ruleId);
256
+ return ruleIds.size;
257
+ }
258
+ function sortByImpact(findings) {
259
+ return [...findings].sort((a, b) => impactRank(a.impact) - impactRank(b.impact) || a.ruleId.localeCompare(b.ruleId));
260
+ }
261
+ function criteria(finding) {
262
+ return finding.successCriteria.length > 0 ? `, WCAG ${finding.successCriteria.join(" ")}` : "";
263
+ }
264
+ /**
265
+ * What is actually broken, once per element rather than once per page.
266
+ *
267
+ * The page-by-page listing above is the truth, and on a site built from
268
+ * components it is not the work: one header with a missing `alt` reappears on
269
+ * every page that renders it, and nothing in a per-page report says those are
270
+ * one line in one file. This section says it, and orders the result by what
271
+ * fixing it would buy.
272
+ */
273
+ function issuesSection(audits, ctx) {
274
+ const issues = groupIssues(audits);
275
+ if (issues.length === 0) return [];
276
+ const elements = issues.reduce((total, issue) => total + issue.elements.length, 0);
277
+ const occurrences = issues.reduce((total, issue) => total + issue.occurrences, 0);
278
+ const lines = [line(ctx, "Issues", ctx.c.bold)];
279
+ const intro = occurrences === elements ? ` ${count(elements, "distinct element")} to fix.` : ` ${count(occurrences, "violation")} across the site come from ${count(elements, "distinct element")}.`;
280
+ lines.push(line(ctx, intro, ctx.c.dim));
281
+ for (const issue of issues) {
282
+ lines.push("");
283
+ lines.push(render(ctx, [
284
+ { text: ` ${ctx.symbol("violation")} ` },
285
+ {
286
+ text: issue.ruleId,
287
+ paint: ctx.c.bold
288
+ },
289
+ {
290
+ text: ` ${impactLabel(issue.impact)}`,
291
+ paint: ctx.c.dim
292
+ },
293
+ ...issue.successCriteria.length > 0 ? [{
294
+ text: `, WCAG ${issue.successCriteria.join(" ")}`,
295
+ paint: ctx.c.dim
296
+ }] : []
297
+ ]));
298
+ lines.push(line(ctx, ` ${issue.help}`, ctx.c.dim));
299
+ for (const element of issue.elements.slice(0, ctx.maxNodes)) {
300
+ lines.push(line(ctx, ` ${collapse(element.html)}`));
301
+ lines.push(...whereLines(element, ctx));
302
+ }
303
+ const hidden = issue.elements.length - ctx.maxNodes;
304
+ if (hidden > 0) lines.push(line(ctx, ` …and ${count(hidden, "more element")}`, ctx.c.dim));
305
+ }
306
+ return lines;
307
+ }
308
+ /** Where one element appears, and what that says about where the fix goes. */
309
+ function whereLines(element, ctx) {
310
+ const shown = element.pages.slice(0, ctx.maxNodes);
311
+ const rest = element.pages.length - shown.length;
312
+ const component = ctx.componentFor(element.html);
313
+ const lines = component === void 0 ? [] : [render(ctx, [{
314
+ text: " written in ",
315
+ paint: ctx.c.dim
316
+ }, { text: component }])];
317
+ lines.push(line(ctx, ` on ${count(element.pages.length, "page")}:`, ctx.c.dim));
318
+ for (const page of shown) {
319
+ const source = ctx.sourceFor(page);
320
+ lines.push(render(ctx, [{
321
+ text: ` ${page}`,
322
+ paint: ctx.c.dim
323
+ }, ...source === void 0 ? [] : [{
324
+ text: ` ${source}`,
325
+ paint: ctx.c.dim
326
+ }]]));
327
+ }
328
+ if (rest > 0) lines.push(line(ctx, ` …and ${count(rest, "more page")}`, ctx.c.dim));
329
+ if (isShared(element)) lines.push(line(ctx, " identical on each — likely one shared component", ctx.c.dim));
330
+ return lines;
331
+ }
332
+ /** Wraps a sentence to the terminal, so a paragraph of advice stays readable. */
333
+ function wrap(text, width) {
334
+ const words = text.split(" ");
335
+ const lines = [];
336
+ let line = "";
337
+ for (const word of words) if (line === "") line = word;
338
+ else if (`${line} ${word}`.length <= width) line = `${line} ${word}`;
339
+ else {
340
+ lines.push(line);
341
+ line = word;
342
+ }
343
+ if (line !== "") lines.push(line);
344
+ return lines;
345
+ }
346
+ //#endregion
347
+ //#region src/cli/pages.ts
348
+ /**
349
+ * Collect the pages to audit, reporting to stderr on the way.
350
+ *
351
+ * Returns undefined when there is nothing to audit, having already explained
352
+ * why. Every caller turns that into exit 2 — a run that reached no verdict,
353
+ * which is not the same as a clean one.
354
+ */
355
+ async function resolvePages(directory, options = {}) {
356
+ if (directory === void 0 && options.url === void 0) return resolveAutomatically(options);
357
+ if (options.url !== void 0) {
358
+ const crawled = await crawlPages(options.url, options);
359
+ if (!crawled) return void 0;
360
+ if (crawled.pages.length === 0) {
361
+ warn(`No pages could be fetched from ${options.url}`);
362
+ return;
363
+ }
364
+ return {
365
+ pages: crawled.pages,
366
+ origin: crawled.origin,
367
+ label: options.url
368
+ };
369
+ }
370
+ const cwd = options.cwd ?? process.cwd();
371
+ const shown = options.label ?? directory;
372
+ let pages;
373
+ try {
374
+ pages = await collectPages(directory, {
375
+ ...options.include ? { include: options.include } : {},
376
+ ...options.exclude ? { exclude: options.exclude } : {}
377
+ });
378
+ } catch (cause) {
379
+ if (!(cause instanceof BuildDirectoryError)) throw cause;
380
+ fail(cause.message);
381
+ note(await emptyDirectoryHint(shown, cwd));
382
+ return;
383
+ }
384
+ if (pages.length === 0) {
385
+ warn(await emptyDirectoryHint(shown, cwd));
386
+ return;
387
+ }
388
+ return {
389
+ pages,
390
+ label: shown
391
+ };
392
+ }
393
+ /**
394
+ * Fetch the pages of a running site, reporting what happened on the way.
395
+ *
396
+ * Returns undefined when the crawl could not start, which the caller turns into
397
+ * exit 2 — a run that reached no verdict, not a clean one.
398
+ */
399
+ async function crawlPages(url, options) {
400
+ const { crawlSite, CrawlError, parseEntryUrl } = await import("./crawl-Oxt2Gaqo.js");
401
+ let entry;
402
+ try {
403
+ entry = parseEntryUrl(url, options.allowRemote ?? false);
404
+ } catch (cause) {
405
+ if (cause instanceof CrawlError) {
406
+ fail(cause.message);
407
+ return;
408
+ }
409
+ throw cause;
410
+ }
411
+ note(`Crawling ${entry.origin}…`);
412
+ const result = await crawlSite(entry, {
413
+ ...options.allowRemote ? { allowRemote: true } : {},
414
+ ...options.ignoreRobots ? { ignoreRobots: true } : {},
415
+ ...options.maxPages === void 0 ? {} : { maxPages: options.maxPages },
416
+ ...options.maxDepth === void 0 ? {} : { maxDepth: options.maxDepth },
417
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
418
+ });
419
+ if (result.pages.length === 0 && result.failures.length > 0) {
420
+ fail(`Could not fetch ${entry.href} (${result.failures[0]?.reason})`);
421
+ note(" Is the site running at that address?");
422
+ return;
423
+ }
424
+ const found = result.discovery === "sitemap" ? "sitemap.xml and links" : "links";
425
+ note(`Found ${count(result.pages.length, "page")} from ${found}`);
426
+ if (result.failures.length > 0) {
427
+ const verb = result.failures.length === 1 ? "URL was" : "URLs were";
428
+ warn(`${result.failures.length} ${verb} not fetched, and so not audited:`);
429
+ for (const failure of result.failures.slice(0, 10)) note(` ${failure.url} — ${failure.reason}`);
430
+ if (result.failures.length > 10) note(` …and ${result.failures.length - 10} more`);
431
+ }
432
+ if (result.truncated) warn(`Stopped at ${count(result.pages.length, "page")}; the site has more. Raise --max-pages to go further.`);
433
+ return {
434
+ pages: result.pages,
435
+ origin: result.origin
436
+ };
437
+ }
438
+ /**
439
+ * No directory and no URL: work out what this project needs.
440
+ *
441
+ * The point is that `eaa-kit audit` on its own does something useful. Anything
442
+ * this starts is handed back as `cleanup` so the caller can stop it once the
443
+ * report is written.
444
+ */
445
+ async function resolveAutomatically(options) {
446
+ const cwd = options.cwd ?? process.cwd();
447
+ const { autoDetectSource } = await import("./project-DW08TseF.js");
448
+ const detected = await autoDetectSource(cwd, {
449
+ ...options.noBuild ? { noBuild: true } : {},
450
+ onStep: note
451
+ });
452
+ if (detected?.directory !== void 0) return resolvePages(detected.directory, {
453
+ ...options,
454
+ label: path.relative(cwd, detected.directory) || "."
455
+ });
456
+ if (detected?.url !== void 0) {
457
+ const resolved = await resolvePages(void 0, {
458
+ ...options,
459
+ url: detected.url
460
+ });
461
+ if (resolved === void 0) {
462
+ await detected.cleanup?.();
463
+ return;
464
+ }
465
+ return {
466
+ ...resolved,
467
+ ...detected.cleanup ? { cleanup: detected.cleanup } : {}
468
+ };
469
+ }
470
+ await detected?.cleanup?.();
471
+ warn(await emptyDirectoryHint("./dist", cwd));
472
+ }
473
+ //#endregion
474
+ //#region src/cli/audit.ts
475
+ const OUTPUT_FORMATS = [
476
+ "console",
477
+ "json",
478
+ "sarif",
479
+ "html"
480
+ ];
481
+ /**
482
+ * `eaa-kit audit [dir]`.
483
+ *
484
+ * Writes progress to stderr and the report to stdout, so the report can be
485
+ * piped somewhere without the chatter coming along.
486
+ */
487
+ async function runAuditCommand(dir, options = {}) {
488
+ const resolved = await resolvePages(dir, options);
489
+ if (!resolved) return {
490
+ audits: [],
491
+ exitCode: 2
492
+ };
493
+ const { pages, origin, label, cleanup } = resolved;
494
+ try {
495
+ note(`Auditing ${count(pages.length, "page")} in ${label}${await describeEngine(pages, options)}…`);
496
+ const baseUrl = options.baseUrl ?? origin;
497
+ let audits = await runEngine(pages, {
498
+ cwd: options.cwd ?? process.cwd(),
499
+ ...baseUrl === void 0 ? {} : { baseUrl },
500
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
501
+ ...options.browser ? { browser: true } : {},
502
+ ...options.concurrency === void 0 ? {} : { concurrency: options.concurrency },
503
+ ...options.url === void 0 && dir !== void 0 ? { directory: dir } : {}
504
+ });
505
+ if (!audits) return {
506
+ audits: [],
507
+ exitCode: 2
508
+ };
509
+ const failOn = options.failOn ?? "serious";
510
+ if (options.baseline) {
511
+ const applied = await acceptBaseline(audits, options);
512
+ if (!applied) return {
513
+ audits,
514
+ exitCode: 2
515
+ };
516
+ audits = applied;
517
+ }
518
+ await emit(audits, label, failOn, options);
519
+ const unaudited = audits.filter((audit) => audit.error);
520
+ if (unaudited.length > 0) {
521
+ fail(`${unaudited.length} of ${audits.length} pages could not be audited`);
522
+ return {
523
+ audits,
524
+ exitCode: 2
525
+ };
526
+ }
527
+ return {
528
+ audits,
529
+ exitCode: countAtOrAbove(audits, failOn) > 0 ? 1 : 0
530
+ };
531
+ } finally {
532
+ await cleanup?.();
533
+ }
534
+ }
535
+ /**
536
+ * Move the violations the baseline accounts for out of the failing set.
537
+ *
538
+ * Returns undefined when the baseline could not be read, which the caller
539
+ * turns into exit 2: a run asked to use a baseline it cannot find has not
540
+ * measured what it was told to measure, and silently failing on everything
541
+ * would be as wrong as silently passing.
542
+ */
543
+ async function acceptBaseline(audits, options) {
544
+ const { applyBaseline, BaselineError, readBaseline } = await import("./baseline-CuKFq4IF.js");
545
+ try {
546
+ const outcome = applyBaseline(audits, await readBaseline(options.baseline, options.cwd ?? process.cwd()));
547
+ if (outcome.accepted > 0) note(`Baseline accepted ${outcome.accepted} violating elements`);
548
+ if (outcome.stale.length > 0) {
549
+ const stale = outcome.stale.length;
550
+ note(`${stale} baseline ${stale === 1 ? "entry no longer matches" : "entries no longer match"} and can be removed`);
551
+ }
552
+ if (outcome.expired.length > 0) advise(`${outcome.expired.length} baseline entries have expired and no longer suppress anything`);
553
+ return outcome.audits;
554
+ } catch (cause) {
555
+ if (cause instanceof BaselineError) {
556
+ fail(cause.message);
557
+ return;
558
+ }
559
+ throw cause;
560
+ }
561
+ }
562
+ /**
563
+ * What the progress line says about the engine.
564
+ *
565
+ * The thread count is on it because it is the difference between a run that
566
+ * looks stalled and one that is working, and because a user comparing two
567
+ * timings deserves to know which one used the machine.
568
+ */
569
+ async function describeEngine(pages, options) {
570
+ if (options.browser) return " with Chromium";
571
+ const { plannedWorkers } = await import("./pool-BWkWZiJW.js");
572
+ const workers = options.concurrency ?? plannedWorkers(pages);
573
+ return workers > 1 ? ` across ${workers} threads` : "";
574
+ }
575
+ /**
576
+ * Emit the chosen format, to a file when --output is given and to stdout
577
+ * otherwise. Colour is dropped when writing to a file, since escape codes in a
578
+ * saved report are noise.
579
+ */
580
+ async function emit(audits, dir, failOn, options) {
581
+ const body = await renderReport(audits, dir, failOn, options.format ?? "console", typeof options.output === "string", options);
582
+ await emitDocument(body, options.output, options.cwd ?? process.cwd());
583
+ if (options.output !== void 0) note(`Report written to ${options.output}`);
584
+ }
585
+ async function renderReport(audits, dir, failOn, format, toFile, options) {
586
+ switch (format) {
587
+ case "json": {
588
+ const { buildJsonReport, serialiseJsonReport } = await import("./json-B0Y7rNjt.js");
589
+ return serialiseJsonReport(buildJsonReport(audits, {
590
+ directory: dir,
591
+ ...options.url === void 0 ? {} : { sourceKind: "url" },
592
+ failOn,
593
+ ...options.baseUrl ? { baseUrl: options.baseUrl } : {}
594
+ }));
595
+ }
596
+ case "sarif": {
597
+ const { buildSarifReport, serialiseSarifReport } = await import("./sarif-DB3WG7T9.js");
598
+ return serialiseSarifReport(buildSarifReport(audits, { directory: dir }));
599
+ }
600
+ case "html": {
601
+ const { buildHtmlReport } = await import("./html-DKiI_3gs.js");
602
+ return buildHtmlReport(audits, {
603
+ ...await sourceLookups(options.cwd ?? process.cwd()),
604
+ directory: dir,
605
+ failOn,
606
+ ...options.baseUrl ? { baseUrl: options.baseUrl } : {}
607
+ });
608
+ }
609
+ case "console": return `${formatConsoleReport(audits, {
610
+ ...await sourceLookups(options.cwd ?? process.cwd()),
611
+ dir,
612
+ failOn,
613
+ ...options.perPage ? { perPage: true } : {},
614
+ ...options.manual ? { manual: true } : {},
615
+ ...toFile ? { color: false } : {}
616
+ })}\n`;
617
+ }
618
+ }
619
+ /**
620
+ * Where a page and a failing element were written, for the two reports that say
621
+ * so. Best-effort: a project using no convention this recognises gets the
622
+ * report it always got, with no source named.
623
+ */
624
+ async function sourceLookups(cwd) {
625
+ const { buildRouteMap, sourceFor } = await import("./routes-C2Cgf6Ko.js");
626
+ const { buildComponentIndex, componentFor } = await import("./component-7kEBjv_y.js");
627
+ const routes = await buildRouteMap(cwd);
628
+ const components = await buildComponentIndex(cwd);
629
+ return {
630
+ sourceFor: (page) => sourceFor(routes, page),
631
+ componentFor: (html) => componentFor(components, html)
632
+ };
633
+ }
634
+ //#endregion
635
+ export { runAuditCommand as n, resolvePages as r, OUTPUT_FORMATS as t };
@@ -1,2 +1,2 @@
1
- import { a as readBaseline, r as applyBaseline, t as BaselineError } from "./baseline-CgBmzFTr.js";
1
+ import { a as readBaseline, r as applyBaseline, t as BaselineError } from "./baseline-s9F3fXTN.js";
2
2
  export { BaselineError, applyBaseline, readBaseline };