eaa-kit 0.6.0 → 0.9.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 (97) hide show
  1. package/README.md +52 -15
  2. package/dist/astro/index.d.ts +1 -1
  3. package/dist/astro/index.js +1 -1
  4. package/dist/audit/runners/worker.js +1 -1
  5. package/dist/audit-CJDCQaFY.js +2 -0
  6. package/dist/{audit-e_uixhPG.js → audit-J2jeLo-y.js} +170 -241
  7. package/dist/{baseline-BscHfFSW.js → baseline-477B1CZ_.js} +1 -1
  8. package/dist/baseline-D9ihb-wk.js +2 -0
  9. package/dist/{baseline-D2qWmUC6.js → baseline-DrFh7joZ.js} +15 -4
  10. package/dist/baseline-wyJsSIFQ.js +127 -0
  11. package/dist/cache-D4dOIuOi.js +219 -0
  12. package/dist/{checklist-BtgkxMEa.js → checklist-Gx2g3LFC.js} +6 -6
  13. package/dist/cli/index.js +103 -147
  14. package/dist/{collect-Cu1q9NTB.js → collect-BJYk7_pJ.js} +1 -1
  15. package/dist/{command-CZKp9Wi_.js → command-BGGMf4vn.js} +35 -8
  16. package/dist/countries-DRTBubeE.js +25 -0
  17. package/dist/countries-Dg0BdytB.js +156 -0
  18. package/dist/coverage-GvaMpV64.js +3 -0
  19. package/dist/{coverage-BD2_CYns.js → coverage-zdzgSKjz.js} +4 -286
  20. package/dist/{crawl-BHkJmUkA.js → crawl-DwdqiljK.js} +5 -3
  21. package/dist/criteria-CnPJKGeb.js +286 -0
  22. package/dist/{load-vZdV_fD1.js → define-Ctf2uOEh.js} +47 -95
  23. package/dist/eleventy/index.d.ts +1 -1
  24. package/dist/eleventy/index.js +1 -1
  25. package/dist/entry-CjqjrUBY.js +174 -0
  26. package/dist/{html-Bmh7X_sM.js → html-whingnfj.js} +9 -5
  27. package/dist/index.d.ts +61 -5
  28. package/dist/index.js +3 -2
  29. package/dist/init-CPbFVMuk.js +293 -0
  30. package/dist/jsdom-BUYuVJJm.js +3 -0
  31. package/dist/{jsdom-CQar6OQS.js → jsdom-CsW_xVcA.js} +11 -12
  32. package/dist/{json-HJDgJp09.js → json-CyLmvF5P.js} +1 -1
  33. package/dist/{json-PNg6BeXp.js → json-SGCgxSPT.js} +4 -3
  34. package/dist/load-CH-ltdlq.js +99 -0
  35. package/dist/load-D7lBeOsq.js +2 -0
  36. package/dist/nuxt/index.d.ts +1 -1
  37. package/dist/nuxt/index.js +1 -1
  38. package/dist/pages-DxY5Z0gl.js +300 -0
  39. package/dist/{playwright-C-miJP2b.js → playwright-ukCr_5o3.js} +1 -1
  40. package/dist/{pool-dkexq5xo.js → pool-B4tEUa2S.js} +6 -2
  41. package/dist/{project-MFrXcw1M.js → project-BLFdCbOq.js} +1 -1
  42. package/dist/{project-CzOnkLH6.js → project-v2PoRw70.js} +18 -1
  43. package/dist/{completeness-Dwq3CPB3.js → remediation-Bbs4KcX1.js} +72 -42
  44. package/dist/{render-CtsqR0k-.js → render-C6zYfaba.js} +69 -7
  45. package/dist/{result-DfUru6y_.js → result-B7_zVxAX.js} +1 -1
  46. package/dist/result-CRmjjoAA.js +2 -0
  47. package/dist/{review-CdMK2GpQ.js → review-Bz0fO9_I.js} +9 -1
  48. package/dist/{review-DIbOTmOM.js → review-a-2ghjQ5.js} +1 -1
  49. package/dist/{routes-CmdRUuOs.js → routes-CSctpS1P.js} +1 -1
  50. package/dist/{run-YiqyQA2b.d.ts → run-BK2blxMI.d.ts} +8 -0
  51. package/dist/{run-D7hdVXLA.js → run-DzVEOkiF.js} +6 -2
  52. package/dist/{sarif-BKvq_AUm.js → sarif-9BAgNiOa.js} +5 -3
  53. package/dist/site-BHMtf3q2.js +72 -0
  54. package/dist/start-DzOM0p6I.js +101 -0
  55. package/dist/statement/templates/at.de.md +14 -0
  56. package/dist/statement/templates/at.en.md +14 -0
  57. package/dist/statement/templates/be.de.md +148 -0
  58. package/dist/statement/templates/be.en.md +142 -0
  59. package/dist/statement/templates/be.fr.md +146 -0
  60. package/dist/statement/templates/be.nl.md +147 -0
  61. package/dist/statement/templates/ch.de.md +14 -0
  62. package/dist/statement/templates/ch.en.md +14 -0
  63. package/dist/statement/templates/cz.cs.md +137 -0
  64. package/dist/statement/templates/cz.en.md +139 -0
  65. package/dist/statement/templates/de.de.md +14 -0
  66. package/dist/statement/templates/de.en.md +14 -0
  67. package/dist/statement/templates/dk.da.md +141 -0
  68. package/dist/statement/templates/dk.en.md +141 -0
  69. package/dist/statement/templates/es.en.md +14 -0
  70. package/dist/statement/templates/es.es.md +15 -0
  71. package/dist/statement/templates/fi.en.md +139 -0
  72. package/dist/statement/templates/fi.fi.md +141 -0
  73. package/dist/statement/templates/fr.en.md +14 -0
  74. package/dist/statement/templates/fr.fr.md +15 -0
  75. package/dist/statement/templates/ie.en.md +144 -0
  76. package/dist/statement/templates/it.en.md +14 -0
  77. package/dist/statement/templates/it.it.md +15 -0
  78. package/dist/statement/templates/nl.en.md +14 -0
  79. package/dist/statement/templates/nl.nl.md +15 -0
  80. package/dist/statement/templates/pl.en.md +143 -0
  81. package/dist/statement/templates/pl.pl.md +144 -0
  82. package/dist/statement/templates/pt.en.md +142 -0
  83. package/dist/statement/templates/pt.pt.md +145 -0
  84. package/dist/statement/templates/se.en.md +139 -0
  85. package/dist/statement/templates/se.sv.md +142 -0
  86. package/dist/vite/index.d.ts +1 -1
  87. package/dist/vite/index.js +1 -1
  88. package/dist/watch-B2RoUbo0.js +122 -0
  89. package/dist/webpack/index.d.ts +1 -1
  90. package/dist/webpack/index.js +1 -1
  91. package/dist/{worksheet-eUjwYLxC.js → worksheet-B_kQ1pxq.js} +3 -2
  92. package/package.json +4 -3
  93. package/dist/audit-DK2StT1_.js +0 -2
  94. package/dist/coverage-7bQqWNfN.js +0 -2
  95. package/dist/init-BjKYttxc.js +0 -119
  96. package/dist/jsdom-DMvU2h-f.js +0 -3
  97. package/dist/load-Bc_xDGAh.js +0 -2
@@ -1,14 +1,14 @@
1
1
  import { a as impactLabel, i as countAtOrAbove, r as byImpactThenRule } from "./impact-luGCnN8F.js";
2
2
  import { n as count, o as plural, t as collapse } from "./text-BF1LHMiV.js";
3
- import { c as runEngine } from "./result-DfUru6y_.js";
4
- import { a as emitDocument, c as runEngine$1, l as warn, o as fail, s as note, t as advise } from "./command-CZKp9Wi_.js";
5
- import { l as reviewSentence } from "./review-CdMK2GpQ.js";
3
+ import { t as TOOL_VERSION } from "./version-B3v4rNoG.js";
4
+ import { n as DEFAULT_TAGS, u as runEngine } from "./result-B7_zVxAX.js";
5
+ import { a as emitDocument, d as warn, l as note, o as fail, s as failWith, t as advise, u as runEngine$1 } from "./command-BGGMf4vn.js";
6
+ import { l as reviewSentence } from "./review-Bz0fO9_I.js";
7
+ import { a as isShared, d as runCompleteness, i as groupIssues, n as blindRules, o as issueTotals, r as coverageParts, t as remediationFor, u as reusedPart } from "./remediation-Bbs4KcX1.js";
6
8
  import { r as componentPath } from "./component-ChisoFyY.js";
7
- import { i as reviewSummary, n as buildCoverage, o as manualCheckFor, r as coverageSummary, s as understandingUrl } from "./coverage-BD2_CYns.js";
8
- import { a as blindRules, c as isShared, i as remediationFor, l as issueTotals, o as coverageParts, r as runCompleteness, s as groupIssues } from "./completeness-Dwq3CPB3.js";
9
- import { n as buildSummary } from "./json-PNg6BeXp.js";
10
- import { i as holdsHtml, n as collectPages, r as emptyDirectoryHint, t as BuildDirectoryError } from "./collect-Cu1q9NTB.js";
11
- import path from "node:path";
9
+ import { a as manualCheckFor, n as coverageSummary, o as understandingUrl, r as reviewSummary, t as buildCoverage } from "./coverage-zdzgSKjz.js";
10
+ import { n as buildSummary } from "./json-SGCgxSPT.js";
11
+ import { t as resolvePages } from "./pages-DxY5Z0gl.js";
12
12
  import pc from "picocolors";
13
13
  //#region src/audit/report/console.ts
14
14
  const DEFAULT_MAX_NODES = 3;
@@ -77,7 +77,7 @@ function supportsUnicode() {
77
77
  * Joins segments into one line, trimming the group to the terminal width.
78
78
  * Colour codes are applied after trimming, so they never count towards it.
79
79
  */
80
- function render(ctx, segments) {
80
+ function render$1(ctx, segments) {
81
81
  let remaining = ctx.width;
82
82
  const parts = [];
83
83
  for (const segment of segments) {
@@ -90,14 +90,14 @@ function render(ctx, segments) {
90
90
  }
91
91
  /** One line from a single segment, which is what most of this report is. */
92
92
  function line(ctx, text, paint) {
93
- return render(ctx, paint === void 0 ? [{ text }] : [{
93
+ return render$1(ctx, paint === void 0 ? [{ text }] : [{
94
94
  text,
95
95
  paint
96
96
  }]);
97
97
  }
98
98
  function headerLines(audits, ctx) {
99
99
  const engineLabel = runEngine(audits) === "browser" ? "chromium" : "jsdom (browserless)";
100
- return [render(ctx, [{
100
+ return [render$1(ctx, [{
101
101
  text: "eaa-kit audit",
102
102
  paint: ctx.c.bold
103
103
  }, {
@@ -118,14 +118,14 @@ function legendLines(ctx) {
118
118
  function pageSection(audit, ctx) {
119
119
  const lines = [line(ctx, audit.relativePath, ctx.c.underline)];
120
120
  if (audit.error) {
121
- lines.push(render(ctx, [{
121
+ lines.push(render$1(ctx, [{
122
122
  text: ` ${ctx.symbol("error")} not audited: `,
123
123
  paint: ctx.c.red
124
124
  }, { text: audit.error }]), "");
125
125
  return lines;
126
126
  }
127
127
  for (const finding of [...audit.violations].sort(byImpactThenRule)) lines.push(...violationLines(finding, ctx));
128
- for (const finding of audit.incomplete.filter((item) => item.reason === "needs-review")) lines.push(render(ctx, [
128
+ for (const finding of audit.incomplete.filter((item) => item.reason === "needs-review")) lines.push(render$1(ctx, [
129
129
  {
130
130
  text: ` ${ctx.symbol("review")} `,
131
131
  paint: ctx.c.yellow
@@ -141,7 +141,7 @@ function pageSection(audit, ctx) {
141
141
  ]));
142
142
  if (audit.violations.length === 0) {
143
143
  const clean = (audit.accepted ?? []).length === 0;
144
- lines.push(render(ctx, [{
144
+ lines.push(render$1(ctx, [{
145
145
  text: ` ${ctx.symbol("clean")} `,
146
146
  paint: clean ? ctx.c.green : ctx.c.dim
147
147
  }, {
@@ -162,7 +162,7 @@ function coverageLine(audit, ctx) {
162
162
  }
163
163
  function violationLines(finding, ctx) {
164
164
  const impact = impactLabel(finding.impact);
165
- const lines = [render(ctx, [
165
+ const lines = [render$1(ctx, [
166
166
  {
167
167
  text: ` ${ctx.symbol("violation")} `,
168
168
  paint: ctx.c.red
@@ -195,7 +195,7 @@ function summary(audits, ctx) {
195
195
  const clean = totals.pagesNotAudited > 0 || ctx.completeness && !ctx.completeness.complete ? ` No violations across the ${count(audited, "page")} that were audited.` : ` No violations across ${pages}.`;
196
196
  lines.push(line(ctx, clean, ctx.c.green));
197
197
  } else {
198
- lines.push(render(ctx, [{
198
+ lines.push(render$1(ctx, [{
199
199
  text: ` ${count(totals.violations, "violation")} on ${totals.pagesWithViolations} of ${count(audited, "page")}`,
200
200
  paint: ctx.c.red
201
201
  }, {
@@ -239,7 +239,7 @@ function coverageSection(audits, ctx) {
239
239
  for (const criterion of coverage.criteria) {
240
240
  const paint = criterion.status === "evaluated" ? ctx.c.green : ctx.c.dim;
241
241
  const note = criterion.browserWouldAnswer ? " (--browser would answer this)" : "";
242
- lines.push(render(ctx, [
242
+ lines.push(render$1(ctx, [
243
243
  {
244
244
  text: ` ${criterion.number} `,
245
245
  paint: ctx.c.bold
@@ -274,8 +274,19 @@ const STATUS_WORDS = {
274
274
  */
275
275
  function completenessLines(ctx) {
276
276
  const completeness = ctx.completeness;
277
- if (completeness === void 0 || completeness.complete) return [];
278
- const lines = [];
277
+ if (completeness === void 0) return [];
278
+ const reused = reusedPart(completeness);
279
+ const lines = reused === void 0 ? [] : [line(ctx, ` ${reused}`, ctx.c.dim)];
280
+ const redirect = completeness.entryRedirect;
281
+ if (redirect !== void 0) {
282
+ const why = {
283
+ "same-site": "same site",
284
+ flag: "--redirects follow",
285
+ prompt: "approved"
286
+ }[redirect.followedBecause];
287
+ lines.unshift(line(ctx, ` Redirected (${redirect.statuses.join(" → ")}, ${why}):`, ctx.c.yellow), line(ctx, ` from ${redirect.requested}`, ctx.c.yellow), line(ctx, ` to ${redirect.auditedFrom}`, ctx.c.yellow), line(ctx, " Everything below is about the second address.", ctx.c.dim));
288
+ }
289
+ if (completeness.complete) return lines;
279
290
  if (completeness.unreachable.length > 0) {
280
291
  const noun = plural(completeness.unreachable.length, "page");
281
292
  const verb = completeness.unreachable.length === 1 ? "was" : "were";
@@ -309,7 +320,7 @@ function blindSection(audits, ctx) {
309
320
  line(ctx, " They are never reported as passing.", ctx.c.dim)
310
321
  ];
311
322
  for (const { ruleId, pages, finding } of blind) {
312
- lines.push(render(ctx, [
323
+ lines.push(render$1(ctx, [
313
324
  { text: ` ${ctx.symbol("blind")} ` },
314
325
  { text: ruleId },
315
326
  {
@@ -356,7 +367,7 @@ function issuesSection(audits, ctx) {
356
367
  lines.push(line(ctx, intro, ctx.c.dim));
357
368
  for (const issue of issues) {
358
369
  lines.push("");
359
- lines.push(render(ctx, [
370
+ lines.push(render$1(ctx, [
360
371
  { text: ` ${ctx.symbol("violation")} ` },
361
372
  {
362
373
  text: issue.ruleId,
@@ -397,7 +408,7 @@ function remediationLines(ruleId, html, ctx) {
397
408
  const width = ctx.width - 6 - 2;
398
409
  const lines = [...wrap(remediation.why, width).map((text) => line(ctx, `${indent}${text}`, ctx.c.dim)), ...wrap(`Fix: ${remediation.fix}`, width).map((text) => line(ctx, `${indent}${text}`))];
399
410
  const example = html === void 0 ? void 0 : remediation.example?.(html);
400
- if (example !== void 0) lines.push(render(ctx, [{
411
+ if (example !== void 0) lines.push(render$1(ctx, [{
401
412
  text: `${indent}→ `,
402
413
  paint: ctx.c.green
403
414
  }, { text: collapse(example) }]));
@@ -408,14 +419,14 @@ function whereLines(element, ctx) {
408
419
  const shown = element.pages.slice(0, ctx.maxNodes);
409
420
  const rest = element.pages.length - shown.length;
410
421
  const component = ctx.componentFor(element.html);
411
- const lines = component === void 0 ? [] : [render(ctx, [{
422
+ const lines = component === void 0 ? [] : [render$1(ctx, [{
412
423
  text: " written in ",
413
424
  paint: ctx.c.dim
414
425
  }, { text: componentPath(component) }])];
415
426
  lines.push(line(ctx, ` on ${count(element.pages.length, "page")}:`, ctx.c.dim));
416
427
  for (const page of shown) {
417
428
  const source = ctx.sourceFor(page);
418
- lines.push(render(ctx, [{
429
+ lines.push(render$1(ctx, [{
419
430
  text: ` ${page}`,
420
431
  paint: ctx.c.dim
421
432
  }, ...source === void 0 ? [] : [{
@@ -442,180 +453,6 @@ function wrap(text, width) {
442
453
  return lines;
443
454
  }
444
455
  //#endregion
445
- //#region src/cli/pages.ts
446
- /**
447
- * Collect the pages to audit, reporting to stderr on the way.
448
- *
449
- * Returns undefined when there is nothing to audit, having already explained
450
- * why. Every caller turns that into exit 2 — a run that reached no verdict,
451
- * which is not the same as a clean one.
452
- */
453
- async function resolvePages(directory, options = {}) {
454
- if (directory === void 0 && options.url === void 0) return resolveAutomatically(options);
455
- if (options.url !== void 0) {
456
- const crawled = await crawlPages(options.url, options);
457
- if (!crawled) return void 0;
458
- if (crawled.pages.length === 0) {
459
- warn(`No pages could be fetched from ${options.url}`);
460
- return;
461
- }
462
- return {
463
- pages: crawled.pages,
464
- origin: crawled.origin,
465
- label: options.url,
466
- completeness: crawled.completeness
467
- };
468
- }
469
- const cwd = options.cwd ?? process.cwd();
470
- const shown = options.label ?? directory;
471
- const unreachable = [];
472
- let pages;
473
- try {
474
- pages = await collectPages(directory, {
475
- ...options.include ? { include: options.include } : {},
476
- ...options.exclude ? { exclude: options.exclude } : {},
477
- onUnreadable: (relativePath, reason) => unreachable.push({
478
- location: relativePath,
479
- reason
480
- })
481
- });
482
- } catch (cause) {
483
- if (!(cause instanceof BuildDirectoryError)) throw cause;
484
- fail(cause.message);
485
- note(await emptyDirectoryHint(shown, cwd));
486
- return;
487
- }
488
- if (pages.length === 0) {
489
- if ((options.include !== void 0 || options.exclude !== void 0) && await holdsHtml(directory)) {
490
- warn(`No page in ${shown} matched the filters, so nothing was audited.`);
491
- if (options.include !== void 0) note(` --include ${options.include.join(" ")}`);
492
- if (options.exclude !== void 0) note(` --exclude ${options.exclude.join(" ")}`);
493
- note(" Patterns are relative to the audited directory, with POSIX separators.");
494
- return;
495
- }
496
- warn(await emptyDirectoryHint(shown, cwd));
497
- return;
498
- }
499
- if (unreachable.length > 0) {
500
- const verb = unreachable.length === 1 ? "file was" : "files were";
501
- warn(`${unreachable.length} ${verb} not readable, and so not audited:`);
502
- for (const file of unreachable.slice(0, 10)) note(` ${file.location} — ${file.reason}`);
503
- if (unreachable.length > 10) note(` …and ${unreachable.length - 10} more`);
504
- }
505
- return {
506
- pages,
507
- directory,
508
- label: shown,
509
- completeness: {
510
- discovery: "directory",
511
- collected: pages.length,
512
- unreachable,
513
- truncated: false
514
- }
515
- };
516
- }
517
- /**
518
- * Fetch the pages of a running site, reporting what happened on the way.
519
- *
520
- * Returns undefined when the crawl could not start, which the caller turns into
521
- * exit 2 — a run that reached no verdict, not a clean one.
522
- */
523
- async function crawlPages(url, options) {
524
- const { collapsedOnto, crawlSite, CrawlError, parseEntryUrl } = await import("./crawl-BHkJmUkA.js");
525
- let entry;
526
- try {
527
- entry = parseEntryUrl(url, options.allowRemote ?? false);
528
- } catch (cause) {
529
- if (cause instanceof CrawlError) {
530
- fail(cause.message);
531
- return;
532
- }
533
- throw cause;
534
- }
535
- note(`Crawling ${entry.origin}…`);
536
- const result = await crawlSite(entry, {
537
- ...options.allowRemote ? { allowRemote: true } : {},
538
- ...options.ignoreRobots ? { ignoreRobots: true } : {},
539
- ...options.sitemap === void 0 ? {} : { sitemap: options.sitemap },
540
- ...options.maxPages === void 0 ? {} : { maxPages: options.maxPages },
541
- ...options.maxDepth === void 0 ? {} : { maxDepth: options.maxDepth },
542
- ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
543
- ...options.headers === void 0 ? {} : { headers: options.headers }
544
- });
545
- if (result.pages.length === 0 && result.failures.length > 0) {
546
- fail(`Could not fetch ${entry.href} (${result.failures[0]?.reason})`);
547
- note(" Is the site running at that address?");
548
- return;
549
- }
550
- const found = result.discovery === "sitemap" ? "sitemap.xml and links" : "links";
551
- note(`Found ${count(result.pages.length, "page")} from ${found}`);
552
- if (result.failures.length > 0) {
553
- const verb = result.failures.length === 1 ? "URL was" : "URLs were";
554
- warn(`${result.failures.length} ${verb} not fetched, and so not audited:`);
555
- for (const failure of result.failures.slice(0, 10)) note(` ${failure.url} — ${failure.reason}`);
556
- if (result.failures.length > 10) note(` …and ${result.failures.length - 10} more`);
557
- }
558
- if (result.truncated) warn(`Stopped at ${count(result.pages.length, "page")}; the site has more. Raise --max-pages to go further.`);
559
- const collapsed = collapsedOnto(result);
560
- if (collapsed.length > 0) {
561
- const landedOn = collapsed[0]?.landedOn ?? "";
562
- warn(`Every page requested answered at ${landedOn}, which is not where it was asked.`);
563
- note(" A sign-in page in front of the site looks like this.");
564
- note(" If it is behind one, pass --basic-auth user:password or --header \"Cookie: …\".");
565
- }
566
- return {
567
- pages: result.pages,
568
- origin: result.origin,
569
- completeness: {
570
- discovery: result.discovery,
571
- collected: result.pages.length,
572
- unreachable: [...result.failures.map((failure) => ({
573
- location: failure.url,
574
- reason: failure.reason
575
- })), ...collapsed.map((redirect) => ({
576
- location: redirect.requested,
577
- reason: `answered at ${redirect.landedOn} instead, so this page was not audited`
578
- }))],
579
- truncated: result.truncated
580
- }
581
- };
582
- }
583
- /**
584
- * No directory and no URL: work out what this project needs.
585
- *
586
- * The point is that `eaa-kit audit` on its own does something useful. Anything
587
- * this starts is handed back as `cleanup` so the caller can stop it once the
588
- * report is written.
589
- */
590
- async function resolveAutomatically(options) {
591
- const cwd = options.cwd ?? process.cwd();
592
- const { autoDetectSource } = await import("./project-MFrXcw1M.js");
593
- const detected = await autoDetectSource(cwd, {
594
- ...options.noBuild ? { noBuild: true } : {},
595
- onStep: note
596
- });
597
- if (detected?.directory !== void 0) return resolvePages(detected.directory, {
598
- ...options,
599
- label: path.relative(cwd, detected.directory) || "."
600
- });
601
- if (detected?.url !== void 0) {
602
- const resolved = await resolvePages(void 0, {
603
- ...options,
604
- url: detected.url
605
- });
606
- if (resolved === void 0) {
607
- await detected.cleanup?.();
608
- return;
609
- }
610
- return {
611
- ...resolved,
612
- ...detected.cleanup ? { cleanup: detected.cleanup } : {}
613
- };
614
- }
615
- await detected?.cleanup?.();
616
- warn(await emptyDirectoryHint("./dist", cwd));
617
- }
618
- //#endregion
619
456
  //#region src/cli/audit.ts
620
457
  const OUTPUT_FORMATS = [
621
458
  "console",
@@ -637,11 +474,14 @@ async function runAuditCommand(dir, options = {}) {
637
474
  exitCode: 2
638
475
  };
639
476
  const { pages, origin, label, cleanup, directory, completeness: collection } = resolved;
477
+ const found = directory === void 0 ? {} : { directory };
640
478
  if (options.headers !== void 0 && directory !== void 0 && !options.browser) warn("--header and --basic-auth apply to pages that are fetched; this run read files.");
641
479
  try {
642
- note(`Auditing ${count(pages.length, "page")} in ${label}${await describeEngine(pages, options)}…`);
643
480
  const baseUrl = options.baseUrl ?? origin;
644
- let audits = await runEngine$1(pages, {
481
+ const { hits, misses, cache } = await splitByCache(pages, baseUrl, options);
482
+ if (misses.length === 0) note(`Nothing changed in ${label}: reusing ${count(hits.length, "page")} from the cache.`);
483
+ else note(`Auditing ${count(misses.length, "page")} in ${label}${await describeEngine(misses, options)}${hits.length === 0 ? "" : `, reusing ${count(hits.length, "unchanged page")}`}…`);
484
+ const fresh = misses.length === 0 ? [] : await runEngine$1(misses, {
645
485
  cwd: options.cwd ?? process.cwd(),
646
486
  ...options.headers === void 0 ? {} : { headers: options.headers },
647
487
  ...baseUrl === void 0 ? {} : { baseUrl },
@@ -651,15 +491,23 @@ async function runAuditCommand(dir, options = {}) {
651
491
  ...options.concurrency === void 0 ? {} : { concurrency: options.concurrency },
652
492
  ...directory === void 0 ? {} : { directory }
653
493
  });
654
- if (!audits) return {
494
+ if (!fresh) return {
655
495
  audits: [],
496
+ ...found,
656
497
  exitCode: 2
657
498
  };
499
+ for (const [index, page] of misses.entries()) {
500
+ const audit = fresh[index];
501
+ if (audit) cache?.put(page, audit);
502
+ }
503
+ await cache?.flush();
504
+ let audits = inCollectedOrder(pages, [...hits, ...fresh]);
658
505
  const failOn = options.failOn ?? "serious";
659
506
  if (options.baseline) {
660
507
  const applied = await acceptBaseline(audits, options);
661
508
  if (!applied) return {
662
509
  audits,
510
+ ...found,
663
511
  exitCode: 2
664
512
  };
665
513
  audits = applied;
@@ -668,6 +516,7 @@ async function runAuditCommand(dir, options = {}) {
668
516
  const review = await loadReview(options);
669
517
  if (review === FAILED) return {
670
518
  audits,
519
+ ...found,
671
520
  exitCode: 2
672
521
  };
673
522
  await emit(audits, label, failOn, completeness, options, review);
@@ -676,11 +525,13 @@ async function runAuditCommand(dir, options = {}) {
676
525
  fail(`${unaudited.length} of ${audits.length} pages could not be audited`);
677
526
  return {
678
527
  audits,
528
+ ...found,
679
529
  exitCode: 2
680
530
  };
681
531
  }
682
532
  return {
683
533
  audits,
534
+ ...found,
684
535
  exitCode: countAtOrAbove(audits, failOn) > 0 ? 1 : 0
685
536
  };
686
537
  } finally {
@@ -688,6 +539,67 @@ async function runAuditCommand(dir, options = {}) {
688
539
  }
689
540
  }
690
541
  /**
542
+ * Which pages already have a result, and which have to be audited.
543
+ *
544
+ * Runs before the engine is imported, which is the point: a build where nothing
545
+ * changed produces no misses, and a run with no misses never loads jsdom. The
546
+ * cache itself is opened here rather than earlier so that a run given
547
+ * `--no-cache` does not read one at all.
548
+ */
549
+ async function splitByCache(pages, baseUrl, options) {
550
+ if (options.noCache) return {
551
+ hits: [],
552
+ misses: [...pages],
553
+ cache: void 0
554
+ };
555
+ const { fromEntry, openCache } = await import("./cache-D4dOIuOi.js");
556
+ const { pageUrl } = await import("./result-CRmjjoAA.js");
557
+ const axe = (await import("axe-core")).default;
558
+ const engine = options.browser ? "browser" : "jsdom";
559
+ const cache = await openCache({
560
+ toolVersion: TOOL_VERSION,
561
+ axeVersion: axe.version,
562
+ tags: DEFAULT_TAGS,
563
+ engine,
564
+ fast: options.fast === true && options.browser !== true,
565
+ ...baseUrl === void 0 ? {} : { baseUrl },
566
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
567
+ ...options.headers === void 0 ? {} : { headers: options.headers }
568
+ }, { ...options.cwd === void 0 ? {} : { cwd: options.cwd } });
569
+ const hits = [];
570
+ const misses = [];
571
+ for (const page of pages) {
572
+ const entry = cache.get(page);
573
+ if (entry === void 0) misses.push(page);
574
+ else hits.push(fromEntry(entry, page, {
575
+ url: pageUrl(page, baseUrl),
576
+ engine
577
+ }));
578
+ }
579
+ return {
580
+ hits,
581
+ misses,
582
+ cache
583
+ };
584
+ }
585
+ /**
586
+ * The audits back in the order their pages were collected in.
587
+ *
588
+ * Collection sorts by path so two runs of one build produce the same report,
589
+ * and splitting the pages into hits and misses would otherwise undo that: the
590
+ * same site would report its pages in a different order depending on which of
591
+ * them somebody had edited since yesterday.
592
+ */
593
+ function inCollectedOrder(pages, audits) {
594
+ const byPath = new Map(audits.map((audit) => [audit.relativePath, audit]));
595
+ const ordered = [];
596
+ for (const page of pages) {
597
+ const audit = byPath.get(page.relativePath);
598
+ if (audit) ordered.push(audit);
599
+ }
600
+ return ordered;
601
+ }
602
+ /**
691
603
  * Move the violations the baseline accounts for out of the failing set.
692
604
  *
693
605
  * Returns undefined when the baseline could not be read, which the caller
@@ -696,7 +608,7 @@ async function runAuditCommand(dir, options = {}) {
696
608
  * would be as wrong as silently passing.
697
609
  */
698
610
  async function acceptBaseline(audits, options) {
699
- const { applyBaseline, BaselineError, readBaseline } = await import("./baseline-BscHfFSW.js");
611
+ const { applyBaseline, BaselineError, readBaseline } = await import("./baseline-477B1CZ_.js");
700
612
  try {
701
613
  const outcome = applyBaseline(audits, await readBaseline(options.baseline, options.cwd ?? process.cwd()));
702
614
  if (outcome.accepted > 0) note(`Baseline accepted ${outcome.accepted} violating elements`);
@@ -708,7 +620,7 @@ async function acceptBaseline(audits, options) {
708
620
  return outcome.audits;
709
621
  } catch (cause) {
710
622
  if (cause instanceof BaselineError) {
711
- fail(cause.message);
623
+ failWith(cause);
712
624
  return;
713
625
  }
714
626
  throw cause;
@@ -724,7 +636,7 @@ const FAILED = Symbol("review-failed");
724
636
  */
725
637
  async function loadReview(options) {
726
638
  if (options.review === void 0) return void 0;
727
- const { answeredCount, readReview, ReviewError } = await import("./review-DIbOTmOM.js");
639
+ const { answeredCount, readReview, ReviewError } = await import("./review-a-2ghjQ5.js");
728
640
  try {
729
641
  const record = await readReview(options.review, options.cwd ?? process.cwd());
730
642
  note(`Review record: ${count(answeredCount(record), "criterion")} answered`);
@@ -734,7 +646,7 @@ async function loadReview(options) {
734
646
  };
735
647
  } catch (cause) {
736
648
  if (cause instanceof ReviewError) {
737
- fail(cause.message);
649
+ failWith(cause);
738
650
  return FAILED;
739
651
  }
740
652
  throw cause;
@@ -749,25 +661,36 @@ async function loadReview(options) {
749
661
  */
750
662
  async function describeEngine(pages, options) {
751
663
  if (options.browser) return " with Chromium";
752
- const { plannedWorkers } = await import("./pool-dkexq5xo.js");
664
+ const { plannedWorkers } = await import("./pool-B4tEUa2S.js");
753
665
  const workers = options.concurrency ?? plannedWorkers(pages);
754
666
  const threads = workers > 1 ? ` across ${workers} threads` : "";
755
667
  return options.fast ? `${threads}, skipping what this engine cannot decide` : threads;
756
668
  }
757
669
  /**
758
- * Emit the chosen format, to a file when --output is given and to stdout
759
- * otherwise. Colour is dropped when writing to a file, since escape codes in a
760
- * saved report are noise.
670
+ * Render the chosen format and put it where it was asked for: a file under
671
+ * --output, stdout otherwise. Colour is dropped when writing to a file, since
672
+ * escape codes in a saved report are noise.
673
+ *
674
+ * One function rather than a renderer and a writer, because the renderer needed
675
+ * to know where the document was going anyway — which is the whole of what the
676
+ * split was carrying between them.
761
677
  */
762
678
  async function emit(audits, dir, failOn, completeness, options, review) {
763
- const body = await renderReport(audits, dir, failOn, completeness, options.format ?? "console", typeof options.output === "string", options, review);
679
+ const body = await render(audits, dir, failOn, completeness, typeof options.output === "string", options, review);
764
680
  await emitDocument(body, options.output, options.cwd ?? process.cwd());
765
681
  if (options.output !== void 0) note(`Report written to ${options.output}`);
682
+ if (options.htmlReport !== void 0) {
683
+ const html = await render(audits, dir, failOn, completeness, true, {
684
+ ...options,
685
+ format: "html"
686
+ }, review);
687
+ await emitDocument(html, options.htmlReport, options.cwd ?? process.cwd());
688
+ }
766
689
  }
767
- async function renderReport(audits, dir, failOn, completeness, format, toFile, options, review) {
768
- switch (format) {
690
+ async function render(audits, dir, failOn, completeness, toFile, options, review) {
691
+ switch (options.format ?? "console") {
769
692
  case "json": {
770
- const { buildJsonReport, serialiseJsonReport } = await import("./json-HJDgJp09.js");
693
+ const { buildJsonReport, serialiseJsonReport } = await import("./json-CyLmvF5P.js");
771
694
  return serialiseJsonReport(buildJsonReport(audits, {
772
695
  directory: dir,
773
696
  ...options.url === void 0 ? {} : { sourceKind: "url" },
@@ -778,7 +701,7 @@ async function renderReport(audits, dir, failOn, completeness, format, toFile, o
778
701
  }));
779
702
  }
780
703
  case "sarif": {
781
- const { buildSarifReport, serialiseSarifReport } = await import("./sarif-BKvq_AUm.js");
704
+ const { buildSarifReport, serialiseSarifReport } = await import("./sarif-9BAgNiOa.js");
782
705
  return serialiseSarifReport(buildSarifReport(audits, {
783
706
  directory: dir,
784
707
  completeness,
@@ -786,48 +709,54 @@ async function renderReport(audits, dir, failOn, completeness, format, toFile, o
786
709
  }));
787
710
  }
788
711
  case "html": {
789
- const { buildHtmlReport } = await import("./html-Bmh7X_sM.js");
790
- const framework = await detectedFramework(options.cwd ?? process.cwd());
712
+ const { buildHtmlReport } = await import("./html-whingnfj.js");
791
713
  return buildHtmlReport(audits, {
792
- ...await sourceLookups(options.cwd ?? process.cwd(), audits),
714
+ ...await fromTheProject(audits, options),
793
715
  directory: dir,
794
716
  failOn,
795
717
  completeness,
796
718
  ...review === void 0 ? {} : { review },
797
- ...framework === void 0 ? {} : { framework },
798
719
  ...options.baseUrl ? { baseUrl: options.baseUrl } : {}
799
720
  });
800
721
  }
801
- case "console": {
802
- const framework = await detectedFramework(options.cwd ?? process.cwd());
803
- return `${formatConsoleReport(audits, {
804
- ...await sourceLookups(options.cwd ?? process.cwd(), audits),
805
- dir,
806
- failOn,
807
- completeness,
808
- ...review === void 0 ? {} : { review },
809
- ...options.perPage ? { perPage: true } : {},
810
- ...options.manual ? { manual: true } : {},
811
- ...options.coverage ? { coverage: true } : {},
812
- ...framework === void 0 ? {} : { framework },
813
- ...toFile ? { color: false } : {}
814
- })}\n`;
815
- }
722
+ case "console": return `${formatConsoleReport(audits, {
723
+ ...await fromTheProject(audits, options),
724
+ dir,
725
+ failOn,
726
+ completeness,
727
+ ...review === void 0 ? {} : { review },
728
+ ...options.perPage ? { perPage: true } : {},
729
+ ...options.manual ? { manual: true } : {},
730
+ ...options.coverage ? { coverage: true } : {},
731
+ ...toFile ? { color: false } : {}
732
+ })}\n`;
816
733
  }
817
734
  }
818
735
  /**
736
+ * What the two human-readable reports both take from the project on disk: where
737
+ * each page and each failing element was written, and what built the site.
738
+ *
739
+ * Only those two ask. JSON and SARIF are read by other programs, which have the
740
+ * project in front of them already, and building the component index for one of
741
+ * them would be several hundred milliseconds spent on nobody's behalf.
742
+ */
743
+ async function fromTheProject(audits, options) {
744
+ const cwd = options.cwd ?? process.cwd();
745
+ const { detectFramework } = await import("./frameworks-etFg_O8K.js");
746
+ const { readPackageJson } = await import("./project-BLFdCbOq.js");
747
+ const detected = await detectFramework(cwd, await readPackageJson(cwd));
748
+ return {
749
+ ...await sourceLookups(cwd, audits),
750
+ ...detected === void 0 ? {} : { framework: detected.framework.id }
751
+ };
752
+ }
753
+ /**
819
754
  * Where a page and a failing element were written, for the two reports that say
820
755
  * so. Best-effort: a project using no convention this recognises gets the
821
756
  * report it always got, with no source named.
822
757
  */
823
- /** The registry id of whatever built this project, for framework-shaped advice. */
824
- async function detectedFramework(cwd) {
825
- const { detectFramework } = await import("./frameworks-etFg_O8K.js");
826
- const { readPackageJson } = await import("./project-MFrXcw1M.js");
827
- return (await detectFramework(cwd, await readPackageJson(cwd)))?.framework.id;
828
- }
829
758
  async function sourceLookups(cwd, audits) {
830
- const { buildRouteMap, sourceFor } = await import("./routes-CmdRUuOs.js");
759
+ const { buildRouteMap, sourceFor } = await import("./routes-CSctpS1P.js");
831
760
  const routes = await buildRouteMap(cwd);
832
761
  if (!hasElementsToAttribute(audits)) return {
833
762
  sourceFor: (page) => sourceFor(routes, page),
@@ -845,4 +774,4 @@ function hasElementsToAttribute(audits) {
845
774
  return audits.some((audit) => audit.violations.length > 0 || (audit.accepted?.length ?? 0) > 0);
846
775
  }
847
776
  //#endregion
848
- export { runAuditCommand as n, resolvePages as r, OUTPUT_FORMATS as t };
777
+ export { runAuditCommand as n, OUTPUT_FORMATS as t };
@@ -1,2 +1,2 @@
1
- import { o as readBaseline, r as applyBaseline, t as BaselineError } from "./baseline-D2qWmUC6.js";
1
+ import { o as readBaseline, r as applyBaseline, t as BaselineError } from "./baseline-DrFh7joZ.js";
2
2
  export { BaselineError, applyBaseline, readBaseline };
@@ -0,0 +1,2 @@
1
+ import { t as runBaselineCommand } from "./baseline-wyJsSIFQ.js";
2
+ export { runBaselineCommand };