eaa-kit 0.9.0 → 0.11.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 (106) hide show
  1. package/README.md +174 -149
  2. package/dist/astro/index.d.ts +1 -3
  3. package/dist/astro/index.js +2 -3
  4. package/dist/audit/runners/worker.js +2 -3
  5. package/dist/{audit-J2jeLo-y.js → audit-DbqNIrt6.js} +61 -35
  6. package/dist/audit-rUhqnm3o.js +1 -0
  7. package/dist/{baseline-DrFh7joZ.js → baseline-CKElWbx4.js} +4 -5
  8. package/dist/baseline-DU0EPiTq.js +1 -0
  9. package/dist/baseline-DYOejLFO.js +1 -0
  10. package/dist/{baseline-wyJsSIFQ.js → baseline-DvdsFTQy.js} +5 -6
  11. package/dist/{cache-D4dOIuOi.js → cache-DIV4G0TI.js} +24 -5
  12. package/dist/{checklist-Gx2g3LFC.js → checklist-CA0Ri71Z.js} +7 -8
  13. package/dist/cli/index.js +52 -35
  14. package/dist/{collect-BJYk7_pJ.js → collect-CjucwTEF.js} +16 -8
  15. package/dist/{command-BGGMf4vn.js → command-C8ZFvcc1.js} +6 -9
  16. package/dist/completeness-Cg-XIKWN.js +1 -0
  17. package/dist/completeness-Dzyvgr4Z.js +72 -0
  18. package/dist/component-CgbeRgJa.js +1 -0
  19. package/dist/{component-ChisoFyY.js → component-ZLd8DA_a.js} +3 -4
  20. package/dist/{countries-Dg0BdytB.js → countries-B_PE6r5R.js} +42 -18
  21. package/dist/{countries-DRTBubeE.js → countries-CCqog6dy.js} +10 -7
  22. package/dist/coverage-B9_6yv_8.js +2 -0
  23. package/dist/{coverage-zdzgSKjz.js → coverage-C1Z6t9Ct.js} +5 -7
  24. package/dist/{crawl-DwdqiljK.js → crawl-CkHJJV4w.js} +131 -23
  25. package/dist/{criteria-CnPJKGeb.js → criteria-CacF0HP1.js} +1 -2
  26. package/dist/{define-Ctf2uOEh.js → define-BdTPIfqE.js} +5 -5
  27. package/dist/detect-DnFHXpWh.js +49 -0
  28. package/dist/detect-oLDadgee.js +160 -0
  29. package/dist/doctor-q8IebwAb.js +248 -0
  30. package/dist/eleventy/index.d.ts +1 -3
  31. package/dist/eleventy/index.js +2 -3
  32. package/dist/{entry-CjqjrUBY.js → entry-kf94P140.js} +1 -2
  33. package/dist/{fingerprint-BjYV_0F7.js → fingerprint-CcoQ1WxQ.js} +1 -2
  34. package/dist/{frameworks-B4ClIJgE.js → frameworks-BboC8eNk.js} +234 -28
  35. package/dist/frameworks-Y-n3NUuG.js +1 -0
  36. package/dist/{fs-BmPtmFke.js → fs-tPD5r0wY.js} +1 -2
  37. package/dist/hosts-B48qR6Vt.js +19 -0
  38. package/dist/{html-whingnfj.js → html-Bjq3Iw3g.js} +54 -14
  39. package/dist/{impact-luGCnN8F.js → impact-BGlJ6j0Y.js} +1 -2
  40. package/dist/{impact-EEB9ZXmC.d.ts → impact-CZjUloYC.d.ts} +0 -2
  41. package/dist/index.d.ts +10 -23
  42. package/dist/index.js +3 -3
  43. package/dist/{init-CPbFVMuk.js → init-3Ti3ao5Z.js} +65 -126
  44. package/dist/issues-WLlepU95.js +120 -0
  45. package/dist/{jsdom-CsW_xVcA.js → jsdom-C4pLIMyP.js} +2 -3
  46. package/dist/jsdom-Zle--VQ1.js +2 -0
  47. package/dist/{json-SGCgxSPT.js → json-B_k4CDmR.js} +5 -6
  48. package/dist/json-IL1JxlTL.js +1 -0
  49. package/dist/{load-CH-ltdlq.js → load-C3eFEdoH.js} +3 -4
  50. package/dist/load-oQQJPNlV.js +1 -0
  51. package/dist/markdown-D-QpPYsz.js +138 -0
  52. package/dist/next-8zDgH0nP.js +119 -0
  53. package/dist/nuxt/index.d.ts +1 -3
  54. package/dist/nuxt/index.js +2 -3
  55. package/dist/{pages-DxY5Z0gl.js → pages-CCP1WfYe.js} +80 -17
  56. package/dist/{playwright-ukCr_5o3.js → playwright-ky4b_HME.js} +98 -16
  57. package/dist/{pool-B4tEUa2S.js → pool-B3XKdk57.js} +4 -5
  58. package/dist/project-B21NT_aX.js +502 -0
  59. package/dist/project-Dht13sb1.js +1 -0
  60. package/dist/{remediation-Bbs4KcX1.js → remediation-BkE7q7dT.js} +2 -193
  61. package/dist/{render-C6zYfaba.js → render-ky8cm4QF.js} +22 -20
  62. package/dist/result-DhoT4g0P.js +1 -0
  63. package/dist/{result-B7_zVxAX.js → result-g8dGsrcv.js} +1 -2
  64. package/dist/{review-Bz0fO9_I.js → review-BGjTBFvd.js} +2 -3
  65. package/dist/review-iheEjp7_.js +1 -0
  66. package/dist/{routes-CSctpS1P.js → routes-BpQeBDmM.js} +4 -5
  67. package/dist/{run-DzVEOkiF.js → run-D7tc7IU2.js} +2 -3
  68. package/dist/{run-BK2blxMI.d.ts → run-VXnP4uLp.d.ts} +2 -6
  69. package/dist/{sarif-9BAgNiOa.js → sarif-v66-PjdE.js} +7 -8
  70. package/dist/{schema-DJSF4K05.js → schema-DfC-Ww1w.js} +1 -2
  71. package/dist/setup-BYlqHlo0.js +2 -0
  72. package/dist/setup-Cf82ONw0.js +353 -0
  73. package/dist/shell-BdQYTaBQ.js +89 -0
  74. package/dist/{site-BHMtf3q2.js → site-CxVyh8IO.js} +1 -2
  75. package/dist/{start-DzOM0p6I.js → start-bdanSxZr.js} +9 -10
  76. package/dist/statement/templates/cz.cs.md +2 -1
  77. package/dist/statement/templates/cz.en.md +2 -1
  78. package/dist/statement/templates/dk.da.md +3 -2
  79. package/dist/statement/templates/dk.en.md +4 -3
  80. package/dist/statement/templates/pt.en.md +3 -2
  81. package/dist/statement/templates/pt.pt.md +3 -3
  82. package/dist/statement/templates/se.en.md +9 -0
  83. package/dist/statement/templates/se.sv.md +8 -0
  84. package/dist/{text-BF1LHMiV.js → text-CISDPU49.js} +11 -3
  85. package/dist/{version-B3v4rNoG.js → version-C8aJm8YJ.js} +1 -2
  86. package/dist/vite/index.d.ts +1 -3
  87. package/dist/vite/index.js +2 -3
  88. package/dist/{watch-B2RoUbo0.js → watch-CefxwMsZ.js} +3 -4
  89. package/dist/webpack/index.d.ts +1 -3
  90. package/dist/webpack/index.js +2 -3
  91. package/dist/{worksheet-B_kQ1pxq.js → worksheet-CcBo9G7s.js} +4 -5
  92. package/dist/workspaces-BBFXOyeV.js +85 -0
  93. package/package.json +15 -13
  94. package/dist/audit-CJDCQaFY.js +0 -2
  95. package/dist/baseline-477B1CZ_.js +0 -2
  96. package/dist/baseline-D9ihb-wk.js +0 -2
  97. package/dist/component-DcCn3BJS.js +0 -2
  98. package/dist/coverage-GvaMpV64.js +0 -3
  99. package/dist/frameworks-etFg_O8K.js +0 -2
  100. package/dist/jsdom-BUYuVJJm.js +0 -3
  101. package/dist/json-CyLmvF5P.js +0 -2
  102. package/dist/load-D7lBeOsq.js +0 -2
  103. package/dist/project-BLFdCbOq.js +0 -2
  104. package/dist/project-v2PoRw70.js +0 -291
  105. package/dist/result-CRmjjoAA.js +0 -2
  106. package/dist/review-a-2ghjQ5.js +0 -2
@@ -1,14 +1,15 @@
1
- import { n as IMPACT_LEVELS, o as impactRank } from "./impact-luGCnN8F.js";
2
- import { c as nullable, h as string, l as number, m as safeParse, p as record, s as isoDateTime, t as array, u as object, y as withDefault } from "./schema-DJSF4K05.js";
3
- import { s as STATEMENT_LOCALES } from "./define-Ctf2uOEh.js";
4
- import { n as isDirectory } from "./fs-BmPtmFke.js";
5
- import { a as isoDate, i as escapeText, n as count, r as escapeAttribute, s as standardsReference } from "./text-BF1LHMiV.js";
6
- import { t as TOOL_VERSION } from "./version-B3v4rNoG.js";
7
- import { t as WCAG22_AA_CRITERIA } from "./criteria-CnPJKGeb.js";
1
+ import { n as IMPACT_LEVELS, o as impactRank } from "./impact-BGlJ6j0Y.js";
2
+ import { c as nullable, h as string, l as number, m as safeParse, p as record, s as isoDateTime, t as array, u as object, y as withDefault } from "./schema-DfC-Ww1w.js";
3
+ import { s as STATEMENT_LOCALES } from "./define-BdTPIfqE.js";
4
+ import { n as isDirectory } from "./fs-tPD5r0wY.js";
5
+ import { a as isCalendarDate, c as standardsReference, i as escapeText, n as count, o as isoDate, r as escapeAttribute } from "./text-CISDPU49.js";
6
+ import { t as TOOL_VERSION } from "./version-C8aJm8YJ.js";
7
+ import { t as WCAG22_AA_CRITERIA } from "./criteria-CacF0HP1.js";
8
+ import { n as authorityChanged, o as localToday } from "./countries-B_PE6r5R.js";
8
9
  import { readFile, readdir } from "node:fs/promises";
9
10
  import path from "node:path";
10
11
  import { fileURLToPath } from "node:url";
11
- //#region src/statement/error.ts
12
+ // src/statement/error.ts
12
13
  /**
13
14
  * Lives in its own module so that both the renderer and the audit-report reader
14
15
  * can throw it without importing each other.
@@ -26,8 +27,7 @@ var StatementError = class extends Error {
26
27
  this.next = next;
27
28
  }
28
29
  };
29
- //#endregion
30
- //#region src/statement/evidence.ts
30
+ // src/statement/evidence.ts
31
31
  /**
32
32
  * How old a claim or a report may be before the document says so.
33
33
  *
@@ -230,8 +230,7 @@ function toImpact(value) {
230
230
  function bySeverityThenRule(a, b) {
231
231
  return impactRank(a.impact) - impactRank(b.impact) || a.ruleId.localeCompare(b.ruleId);
232
232
  }
233
- //#endregion
234
- //#region src/statement/html.ts
233
+ // src/statement/html.ts
235
234
  /**
236
235
  * A standalone, self-contained HTML page.
237
236
  *
@@ -403,8 +402,7 @@ function trailingPunctuation(candidate) {
403
402
  }
404
403
  return candidate.slice(end);
405
404
  }
406
- //#endregion
407
- //#region src/statement/template.ts
405
+ // src/statement/template.ts
408
406
  var TemplateError = class extends Error {
409
407
  name = "TemplateError";
410
408
  };
@@ -510,8 +508,7 @@ function stringify(value) {
510
508
  if (Array.isArray(value)) return value.map(stringify).join(", ");
511
509
  return String(value);
512
510
  }
513
- //#endregion
514
- //#region src/statement/render.ts
511
+ // src/statement/render.ts
515
512
  /** How many affected pages a barrier lists before it starts counting instead. */
516
513
  const MAX_LISTED_PAGES = 5;
517
514
  /**
@@ -525,7 +522,7 @@ async function renderStatement(config, options = {}) {
525
522
  const country = options.country ?? config.enforcement.country;
526
523
  const locale = options.locale ?? defaultLocale(config);
527
524
  const template = `${country.toLowerCase()}.${locale}`;
528
- const markdown = tidy(renderTemplate(await loadTemplate(country, locale), buildScope(config, locale, options)));
525
+ const markdown = tidy(renderTemplate(await loadTemplate(country, locale), buildScope(config, country, locale, options)));
529
526
  return {
530
527
  markdown,
531
528
  html: toHtmlDocument(markdown, {
@@ -555,8 +552,10 @@ function defaultLocale(config) {
555
552
  * template, which keeps the template language trivial and puts the mapping
556
553
  * somewhere that can be typechecked.
557
554
  */
558
- function buildScope(config, locale, options) {
555
+ function buildScope(config, country, locale, options) {
559
556
  const audit = options.audit;
557
+ if (options.today !== void 0 && !isCalendarDate(options.today)) throw new StatementError(`today must be an ISO date (YYYY-MM-DD), got "${options.today}"`);
558
+ const changed = authorityChanged(country, options.today ?? localToday());
560
559
  const review = options.review ? toReviewScope(options.review, locale) : void 0;
561
560
  const issues = [...config.compliance.knownIssues.map((issue) => toIssueScope(issue, locale)), ...(audit?.findings ?? []).map((finding) => toFindingScope(finding, config.compliance.auditReason))];
562
561
  return {
@@ -577,7 +576,11 @@ function buildScope(config, locale, options) {
577
576
  review,
578
577
  hasReview: review !== void 0,
579
578
  hasKnownIssues: issues.length > 0,
580
- hasNoKnownIssues: issues.length === 0
579
+ hasNoKnownIssues: issues.length === 0,
580
+ supervision: {
581
+ changed,
582
+ unchanged: !changed
583
+ }
581
584
  };
582
585
  }
583
586
  /**
@@ -776,5 +779,4 @@ async function findTemplateDirectory() {
776
779
  for (const candidate of candidates) if (await isDirectory(candidate)) return candidate;
777
780
  throw new StatementError(`Could not locate the statement templates. Looked in: ${candidates.join(", ")}`);
778
781
  }
779
- //#endregion
780
782
  export { summariseAuditReport as a, StatementError as c, readAuditReport as i, toHtmlBody as n, checkStatementEvidence as o, toHtmlDocument as r, refuses as s, renderStatement as t };
@@ -0,0 +1 @@
1
+ export { c as pageUrl } from "./result-g8dGsrcv.js";
@@ -1,6 +1,6 @@
1
1
  import { pathToFileURL } from "node:url";
2
2
  import axe from "axe-core";
3
- //#region src/audit/result.ts
3
+ // src/audit/result.ts
4
4
  /**
5
5
  * Per-page ceiling for an audit, in milliseconds.
6
6
  *
@@ -335,5 +335,4 @@ function enClauses(tags) {
335
335
  }
336
336
  return [...clauses].sort();
337
337
  }
338
- //#endregion
339
338
  export { enClauses as a, pageUrl as c, runOptions as d, shapeResults as f, blindRulesInScope as i, ruleOutcomes as l, uniqueRuleOutcomes as m, DEFAULT_TAGS as n, failedPage as o, successCriteria as p, ENGINE_BLIND_RULES as r, findingElements as s, DEFAULT_PAGE_TIMEOUT_MS as t, runEngine as u };
@@ -1,5 +1,5 @@
1
- import { d as optional, h as string, i as enumeration, l as number, m as safeParse, o as isoDate, p as record, u as object, y as withDefault } from "./schema-DJSF4K05.js";
2
- import { a as isoDate$1 } from "./text-BF1LHMiV.js";
1
+ import { d as optional, h as string, i as enumeration, l as number, m as safeParse, o as isoDate, p as record, u as object, y as withDefault } from "./schema-DfC-Ww1w.js";
2
+ import { o as isoDate$1 } from "./text-CISDPU49.js";
3
3
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  /** Default filename, used by the CLI when no path is given. */
@@ -165,5 +165,4 @@ async function writeReview(file, record, cwd = process.cwd()) {
165
165
  await writeFile(target, serialiseReview(record), "utf8");
166
166
  return target;
167
167
  }
168
- //#endregion
169
168
  export { blankReview as a, readReview as c, writeReview as d, answeredCount as i, reviewSentence as l, REVIEW_RESULTS as n, compareCriteria as o, ReviewError as r, criterionReview as s, DEFAULT_REVIEW_FILE as t, serialiseReview as u };
@@ -0,0 +1 @@
1
+ export { r as ReviewError, i as answeredCount, a as blankReview, c as readReview, d as writeReview } from "./review-BGjTBFvd.js";
@@ -1,9 +1,9 @@
1
- import { i as toPosix, n as isDirectory } from "./fs-BmPtmFke.js";
2
- import { i as detectFramework } from "./frameworks-B4ClIJgE.js";
3
- import { i as readPackageJson } from "./project-v2PoRw70.js";
1
+ import { i as toPosix, n as isDirectory } from "./fs-tPD5r0wY.js";
2
+ import { i as detectFramework } from "./frameworks-BboC8eNk.js";
3
+ import { o as readPackageJson } from "./project-B21NT_aX.js";
4
4
  import path from "node:path";
5
5
  import { glob } from "tinyglobby";
6
- //#region src/audit/routes.ts
6
+ // src/audit/routes.ts
7
7
  /**
8
8
  * A path segment that serves more than one page, or none.
9
9
  *
@@ -261,5 +261,4 @@ function sourceFor(map, pagePath) {
261
261
  if (map === void 0) return void 0;
262
262
  return map.sources.get(pagePath) ?? map.sources.get(pagePath.replace(/^\//, ""));
263
263
  }
264
- //#endregion
265
264
  export { buildRouteMap, sourceFor };
@@ -1,4 +1,4 @@
1
- //#region src/integration/run.ts
1
+ // src/integration/run.ts
2
2
  /**
3
3
  * Where an integration writes when its host offers no logger of its own.
4
4
  *
@@ -39,7 +39,7 @@ async function auditBuild(directory, options, logger) {
39
39
  logger.info("skipped (enabled: false)");
40
40
  return;
41
41
  }
42
- const { runAuditCommand } = await import("./audit-CJDCQaFY.js");
42
+ const { runAuditCommand } = await import("./audit-rUhqnm3o.js");
43
43
  const { exitCode } = await runAuditCommand(directory, auditOptions);
44
44
  if (exitCode === 0) {
45
45
  logger.info("no violations at or above the threshold");
@@ -53,5 +53,4 @@ async function auditBuild(directory, options, logger) {
53
53
  logger.error(message);
54
54
  throw new BuildAuditError(`eaa-kit: ${message}`);
55
55
  }
56
- //#endregion
57
56
  export { auditBuild as n, stderrLogger as r, BuildAuditError as t };
@@ -1,9 +1,6 @@
1
- import { t as ImpactLevel } from "./impact-EEB9ZXmC.js";
2
- //#region src/cli/audit.d.ts
3
- declare const OUTPUT_FORMATS: readonly ['console', 'json', 'sarif', 'html'];
1
+ import { t as ImpactLevel } from "./impact-CZjUloYC.js";
2
+ declare const OUTPUT_FORMATS: readonly ['console', 'json', 'sarif', 'html', 'markdown'];
4
3
  type OutputFormat = (typeof OUTPUT_FORMATS)[number];
5
- //#endregion
6
- //#region src/integration/run.d.ts
7
4
  /**
8
5
  * What a build-time integration does once the build has written its files.
9
6
  *
@@ -66,5 +63,4 @@ interface IntegrationOptions {
66
63
  declare class BuildAuditError extends Error {
67
64
  readonly name = "BuildAuditError";
68
65
  }
69
- //#endregion
70
66
  export { IntegrationOptions as n, BuildAuditError as t };
@@ -1,11 +1,11 @@
1
- import { s as isImpactLevel } from "./impact-luGCnN8F.js";
2
- import { s as standardsReference } from "./text-BF1LHMiV.js";
3
- import { t as TOOL_VERSION } from "./version-B3v4rNoG.js";
4
- import { t as elementFingerprint } from "./fingerprint-BjYV_0F7.js";
5
- import { m as uniqueRuleOutcomes, s as findingElements, u as runEngine } from "./result-B7_zVxAX.js";
6
- import { t as buildCoverage } from "./coverage-zdzgSKjz.js";
1
+ import { c as standardsReference } from "./text-CISDPU49.js";
2
+ import { t as TOOL_VERSION } from "./version-C8aJm8YJ.js";
3
+ import { t as buildCoverage } from "./coverage-C1Z6t9Ct.js";
4
+ import { t as elementFingerprint } from "./fingerprint-CcoQ1WxQ.js";
5
+ import { s as isImpactLevel } from "./impact-BGlJ6j0Y.js";
6
+ import { m as uniqueRuleOutcomes, s as findingElements, u as runEngine } from "./result-g8dGsrcv.js";
7
7
  import path from "node:path";
8
- //#region src/audit/report/sarif.ts
8
+ // src/audit/report/sarif.ts
9
9
  const SARIF_VERSION = "2.1.0";
10
10
  const SARIF_SCHEMA = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json";
11
11
  /**
@@ -187,5 +187,4 @@ function artifactUri(directory, relativePath, cwd) {
187
187
  if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return relativePath;
188
188
  return relative.split(path.sep).join("/");
189
189
  }
190
- //#endregion
191
190
  export { buildSarifReport, serialiseSarifReport };
@@ -1,4 +1,4 @@
1
- //#region src/schema.ts
1
+ // src/schema.ts
2
2
  function safeParse(schema, value) {
3
3
  const issues = [];
4
4
  const data = schema.read(value, [], issues);
@@ -205,5 +205,4 @@ function email() {
205
205
  return value;
206
206
  } };
207
207
  }
208
- //#endregion
209
208
  export { union as _, integer as a, nullable as c, optional as d, pipe as f, transform as g, string as h, enumeration as i, number as l, safeParse as m, boolean as n, isoDate as o, record as p, email as r, isoDateTime as s, array as t, object as u, url as v, withDefault as y };
@@ -0,0 +1,2 @@
1
+ import "./hosts-B48qR6Vt.js";
2
+ export { s as findGitRoot } from "./setup-Cf82ONw0.js";
@@ -0,0 +1,353 @@
1
+ import { a as readDenoConfig, n as detectPackageManager, o as readPackageJson } from "./project-B21NT_aX.js";
2
+ import { t as exists } from "./fs-tPD5r0wY.js";
3
+ import { t as TOOL_VERSION } from "./version-C8aJm8YJ.js";
4
+ import { readFile, stat } from "node:fs/promises";
5
+ import path from "node:path";
6
+ // src/cli/setup.ts
7
+ /**
8
+ * The CI half of `eaa-kit init`: a pipeline written for this project rather
9
+ * than copied from the docs and edited until it works. GitHub Actions, GitLab
10
+ * CI or Bitbucket Pipelines, whichever the repository is hosted on, since many
11
+ * of the agencies this tool is for are not on GitHub.
12
+ *
13
+ * Everything in it is read from the project. The package manager comes from
14
+ * the lockfile, the build from the `build` script, the directory from what
15
+ * `init` found, and the baseline from whether one was just recorded. Anything
16
+ * it cannot read is left to the action's own detection rather than guessed,
17
+ * because a workflow that fails on its first push teaches somebody to switch
18
+ * it off.
19
+ */
20
+ /** Where the workflow goes, relative to the repository root. */
21
+ const WORKFLOW_FILE = path.join(".github", "workflows", "accessibility.yml");
22
+ /** GitLab reads one file; a project that already has one gets the job in a file it includes. */
23
+ const GITLAB_FILE = ".gitlab-ci.yml";
24
+ const GITLAB_INCLUDED_FILE = path.join(".gitlab", "eaa-kit.gitlab-ci.yml");
25
+ const BITBUCKET_FILE = "bitbucket-pipelines.yml";
26
+ /**
27
+ * Which CI the repository is on, from where it is pushed to.
28
+ *
29
+ * The remote decides first, because it is where the pipeline will run: a
30
+ * GitHub mirror of a GitLab project still runs GitLab's pipeline. Then a
31
+ * pipeline file already in the repository. GitHub is the answer when nothing
32
+ * says otherwise, which is what `init` did before it knew any other host.
33
+ * Self-hosted GitLab is recognised by a host name with "gitlab" in it, which is
34
+ * the convention; anything else can be named with `--ci`.
35
+ */
36
+ async function detectCiHost(root) {
37
+ const remotes = await remoteUrls(root);
38
+ for (const url of remotes) {
39
+ const host = hostOf(url);
40
+ if (host === void 0) continue;
41
+ if (host === "github.com" || host.endsWith(".github.com")) return "github";
42
+ if (host === "bitbucket.org" || host.includes("bitbucket")) return "bitbucket";
43
+ if (host.includes("gitlab")) return "gitlab";
44
+ }
45
+ if (await exists(path.join(root, ".gitlab-ci.yml"))) return "gitlab";
46
+ if (await exists(path.join(root, "bitbucket-pipelines.yml"))) return "bitbucket";
47
+ return "github";
48
+ }
49
+ /** Remote URLs from .git/config, origin first. */
50
+ async function remoteUrls(root) {
51
+ let config;
52
+ try {
53
+ config = await readFile(path.join(root, ".git", "config"), "utf8");
54
+ } catch {
55
+ return [];
56
+ }
57
+ const urls = [];
58
+ let remote;
59
+ for (const line of config.split(/\r?\n/)) {
60
+ const section = /^\s*\[remote\s+"([^"]+)"\]/.exec(line);
61
+ if (section) {
62
+ remote = section[1];
63
+ continue;
64
+ }
65
+ if (/^\s*\[/.test(line)) {
66
+ remote = void 0;
67
+ continue;
68
+ }
69
+ const url = /^\s*url\s*=\s*(\S+)/.exec(line)?.[1];
70
+ if (remote !== void 0 && url !== void 0) urls.push({
71
+ name: remote,
72
+ url
73
+ });
74
+ }
75
+ urls.sort((a, b) => Number(b.name === "origin") - Number(a.name === "origin"));
76
+ return urls.map((entry) => entry.url);
77
+ }
78
+ /** The host of `https://host/…`, `ssh://git@host/…` or scp-style `git@host:…`. */
79
+ function hostOf(url) {
80
+ const scp = /^[^@/]+@([^:/]+):/.exec(url);
81
+ if (scp?.[1]) return scp[1].toLowerCase();
82
+ try {
83
+ return new URL(url).hostname.toLowerCase() || void 0;
84
+ } catch {
85
+ return;
86
+ }
87
+ }
88
+ /**
89
+ * Where a pipeline for `host` would be written, or why none can be.
90
+ *
91
+ * Nothing is ever overwritten. GitHub has a directory of workflows, so a file
92
+ * of its own is always possible unless one of that name exists. GitLab has one
93
+ * file: without it, it is written; with it, the job goes in a file of its own
94
+ * and the reader is told the two lines that include it. Bitbucket has one file
95
+ * and no include, so a project that has one is pointed at the docs instead.
96
+ */
97
+ async function pipelinePlan(root, host) {
98
+ const at = (file) => path.join(root, file);
99
+ switch (host) {
100
+ case "github": return await exists(at(WORKFLOW_FILE)) ? { refused: `${toPosix(WORKFLOW_FILE)} already exists` } : { file: WORKFLOW_FILE };
101
+ case "gitlab":
102
+ if (!await exists(at(".gitlab-ci.yml"))) return { file: GITLAB_FILE };
103
+ if (await exists(at(GITLAB_INCLUDED_FILE))) return { refused: `${toPosix(GITLAB_INCLUDED_FILE)} already exists` };
104
+ return {
105
+ file: GITLAB_INCLUDED_FILE,
106
+ include: toPosix(GITLAB_INCLUDED_FILE)
107
+ };
108
+ case "bitbucket": return await exists(at("bitbucket-pipelines.yml")) ? { refused: `${BITBUCKET_FILE} already exists, and Bitbucket has no way to include another file. Add the step from docs/integrations.md#bitbucket-pipelines` } : { file: BITBUCKET_FILE };
109
+ }
110
+ }
111
+ /** The repository this project is in, found the way git finds it: upwards. */
112
+ async function findGitRoot(cwd) {
113
+ let current = path.resolve(cwd);
114
+ for (;;) try {
115
+ await stat(path.join(current, ".git"));
116
+ return current;
117
+ } catch {
118
+ const parent = path.dirname(current);
119
+ if (parent === current) return void 0;
120
+ current = parent;
121
+ }
122
+ }
123
+ /** The branch HEAD points at, which is the one worth auditing on push. */
124
+ async function currentBranch(root) {
125
+ try {
126
+ const head = await readFile(path.join(root, ".git", "HEAD"), "utf8");
127
+ return /^ref: refs\/heads\/(.+)$/m.exec(head)?.[1]?.trim();
128
+ } catch {
129
+ return;
130
+ }
131
+ }
132
+ async function projectFacts(inputs) {
133
+ const pkg = await readPackageJson(inputs.cwd);
134
+ const deno = await readDenoConfig(inputs.cwd);
135
+ const manager = pkg !== void 0 ? await detectPackageManager(inputs.cwd) : deno !== void 0 ? "deno" : void 0;
136
+ const install = manager === void 0 ? void 0 : {
137
+ npm: "npm ci",
138
+ pnpm: "pnpm install --frozen-lockfile",
139
+ yarn: "yarn install --frozen-lockfile",
140
+ bun: "bun install --frozen-lockfile",
141
+ deno: void 0
142
+ }[manager];
143
+ const hasBuild = pkg?.scripts?.["build"] !== void 0 || manager === "deno" && deno?.tasks?.["build"] !== void 0;
144
+ return {
145
+ manager,
146
+ pinsPackageManager: typeof pkg?.packageManager === "string",
147
+ install,
148
+ build: manager !== void 0 && hasBuild ? `${manager} ${manager === "deno" ? "task" : "run"} build` : void 0,
149
+ branch: await currentBranch(inputs.root) ?? "main",
150
+ workingDirectory: toPosix(path.relative(inputs.root, inputs.cwd)),
151
+ directory: inputs.site === void 0 ? "" : toPosix(path.relative(inputs.cwd, inputs.site)) || "."
152
+ };
153
+ }
154
+ /** The pipeline for `host`, as text. */
155
+ async function pipelineFor(host, inputs) {
156
+ const facts = await projectFacts(inputs);
157
+ switch (host) {
158
+ case "github": return githubWorkflow(facts, inputs);
159
+ case "gitlab": return gitlabJob(facts, inputs, await gitlabStage(inputs.root));
160
+ case "bitbucket": return bitbucketPipeline(facts, inputs);
161
+ }
162
+ }
163
+ function githubWorkflow(facts, inputs) {
164
+ const { manager, install, build, branch, workingDirectory, directory } = facts;
165
+ const setup = [];
166
+ if (manager === "pnpm") setup.push(" - uses: pnpm/action-setup@v4", ...facts.pinsPackageManager ? [] : [" with:", " version: 10"]);
167
+ if (manager === "bun") setup.push(" - uses: oven-sh/setup-bun@v2");
168
+ if (manager === "deno") setup.push(" - uses: denoland/setup-deno@v2");
169
+ const withLines = [
170
+ ...workingDirectory === "" ? [] : [`working-directory: ${workingDirectory}`],
171
+ ...install === void 0 ? [] : [`install-command: ${install}`],
172
+ ...build === void 0 ? [] : [`build-command: ${build}`],
173
+ `directory: ${directory === "" ? "''" : directory}`,
174
+ `fail-on: ${inputs.failOn}`,
175
+ ...inputs.baseline === void 0 ? [] : [`baseline: ${toPosix(inputs.baseline)}`]
176
+ ].map((line) => ` ${line}`);
177
+ return [
178
+ "# Written by eaa-kit init. Audits the built site against WCAG 2.2 AA on every",
179
+ "# push and pull request, uploads what it finds to GitHub code scanning, and",
180
+ "# fails the job on barriers at or above fail-on.",
181
+ "#",
182
+ "# The inputs are documented at",
183
+ "# https://github.com/likeBloodMoon/eaa-kit/blob/master/docs/integrations.md#github-actions",
184
+ "name: Accessibility",
185
+ "",
186
+ "on:",
187
+ " push:",
188
+ ` branches: [${branch}]`,
189
+ " pull_request:",
190
+ "",
191
+ "permissions:",
192
+ " contents: read",
193
+ " # Required by the SARIF upload to code scanning.",
194
+ " security-events: write",
195
+ "",
196
+ "jobs:",
197
+ " audit:",
198
+ " runs-on: ubuntu-latest",
199
+ " steps:",
200
+ " - uses: actions/checkout@v6",
201
+ ...setup,
202
+ " - uses: actions/setup-node@v6",
203
+ " with:",
204
+ " node-version: 22",
205
+ ` - uses: likeBloodMoon/eaa-kit@v${TOOL_VERSION}`,
206
+ " with:",
207
+ ...withLines,
208
+ ""
209
+ ].join("\n");
210
+ }
211
+ /**
212
+ * The commands a job runs, for the hosts that have no eaa-kit action: set up
213
+ * the package manager in a plain Node image, install, build, audit.
214
+ *
215
+ * The console report goes to the job log, which is where somebody reading a
216
+ * failed job looks, and the Markdown summary is kept as an artifact. The
217
+ * release is pinned for the reason the GitHub workflow pins it.
218
+ */
219
+ function auditScript(facts, inputs) {
220
+ const script = [];
221
+ if (facts.workingDirectory !== "") script.push(`cd ${quote(facts.workingDirectory)}`);
222
+ if (facts.manager === "pnpm" || facts.manager === "yarn") script.push("corepack enable");
223
+ if (facts.manager === "bun") script.push("npm install --global bun");
224
+ if (facts.manager === "deno") script.push("curl -fsSL https://deno.land/install.sh | sh", "export PATH=\"$HOME/.deno/bin:$PATH\"");
225
+ if (facts.install !== void 0) script.push(facts.install);
226
+ if (facts.build !== void 0) script.push(facts.build);
227
+ const args = [
228
+ ...facts.directory === "" ? [] : [quote(facts.directory)],
229
+ "--fail-on",
230
+ inputs.failOn,
231
+ ...inputs.baseline === void 0 ? [] : ["--baseline", quote(toPosix(inputs.baseline))],
232
+ ...facts.directory === "" ? [] : ["--no-build"],
233
+ "--summary",
234
+ "eaa-kit-summary.md"
235
+ ];
236
+ script.push(`npx --yes eaa-kit@${TOOL_VERSION} audit ${args.join(" ")}`);
237
+ return script;
238
+ }
239
+ function artifactPath(facts) {
240
+ return facts.workingDirectory === "" ? "eaa-kit-summary.md" : `${facts.workingDirectory}/eaa-kit-summary.md`;
241
+ }
242
+ /**
243
+ * The stage the job can run in, given the project's own `.gitlab-ci.yml`.
244
+ *
245
+ * `test`, which GitLab's default stages include, unless the project declares
246
+ * stages of its own without it: GitLab refuses a pipeline whose job names a
247
+ * stage nobody declared, and the job lands in a file included into that
248
+ * pipeline. Then `.post`, which GitLab adds to every pipeline whatever it
249
+ * declares, so the audit runs after the project's own stages.
250
+ */
251
+ async function gitlabStage(root) {
252
+ let config;
253
+ try {
254
+ config = await readFile(path.join(root, GITLAB_FILE), "utf8");
255
+ } catch {
256
+ return "test";
257
+ }
258
+ const stages = declaredStages(config);
259
+ return stages === void 0 || stages.includes("test") ? "test" : ".post";
260
+ }
261
+ /**
262
+ * The top-level `stages:` of a GitLab config, in block or flow style, or
263
+ * undefined when it declares none. Not a YAML parser: one key, read the two
264
+ * ways GitLab's own docs write it, so that init needs no YAML dependency.
265
+ */
266
+ function declaredStages(config) {
267
+ const lines = config.split(/\r?\n/);
268
+ const at = lines.findIndex((line) => /^stages\s*:/.test(line));
269
+ if (at === -1) return void 0;
270
+ const clean = (value) => value.replace(/\s+#.*$/, "").trim().replace(/^(['"])(.*)\1$/, "$2");
271
+ const rest = lines[at].replace(/^stages\s*:/, "").trim();
272
+ if (rest.startsWith("[")) {
273
+ let flow = rest;
274
+ for (let next = at + 1; !flow.includes("]") && next < lines.length; next += 1) flow += ` ${lines[next]}`;
275
+ return flow.slice(1, flow.includes("]") ? flow.indexOf("]") : void 0).split(",").map(clean).filter(Boolean);
276
+ }
277
+ const stages = [];
278
+ for (const line of lines.slice(at + 1)) {
279
+ if (/^\s*(#.*)?$/.test(line)) continue;
280
+ const item = /^\s+-\s*(.+)$/.exec(line);
281
+ if (item === null) break;
282
+ stages.push(clean(item[1]));
283
+ }
284
+ return stages;
285
+ }
286
+ function gitlabJob(facts, inputs, stage) {
287
+ return [
288
+ "# Written by eaa-kit init. Audits the built site against WCAG 2.2 AA in every",
289
+ "# pipeline and fails the job on barriers at or above --fail-on. The report is",
290
+ "# in the job log, and a Markdown summary is kept as an artifact.",
291
+ "#",
292
+ "# The options are documented at",
293
+ "# https://github.com/likeBloodMoon/eaa-kit/blob/master/docs/integrations.md#gitlab-ci",
294
+ "accessibility:",
295
+ " image: node:22",
296
+ ...stage === "test" ? [] : [" # .gitlab-ci.yml declares its own stages without \"test\"; .post always exists."],
297
+ ` stage: ${stage}`,
298
+ " script:",
299
+ ...auditScript(facts, inputs).map((line) => ` - ${yamlItem(line)}`),
300
+ " artifacts:",
301
+ " when: always",
302
+ " expose_as: accessibility summary",
303
+ " paths:",
304
+ ` - ${artifactPath(facts)}`,
305
+ ""
306
+ ].join("\n");
307
+ }
308
+ function bitbucketPipeline(facts, inputs) {
309
+ const step = [
310
+ " - step:",
311
+ " name: Accessibility",
312
+ " caches:",
313
+ " - node",
314
+ " script:",
315
+ ...auditScript(facts, inputs).map((line) => ` - ${yamlItem(line)}`),
316
+ " artifacts:",
317
+ ` - ${artifactPath(facts)}`
318
+ ];
319
+ return [
320
+ "# Written by eaa-kit init. Audits the built site against WCAG 2.2 AA on every",
321
+ "# push and pull request, and fails the step on barriers at or above --fail-on.",
322
+ "# The report is in the step log, and a Markdown summary is kept as an artifact.",
323
+ "#",
324
+ "# The options are documented at",
325
+ "# https://github.com/likeBloodMoon/eaa-kit/blob/master/docs/integrations.md#bitbucket-pipelines",
326
+ "image: node:22",
327
+ "",
328
+ "pipelines:",
329
+ " default:",
330
+ ...step,
331
+ " pull-requests:",
332
+ " '**':",
333
+ ...step.map((line) => ` ${line}`),
334
+ ""
335
+ ].join("\n");
336
+ }
337
+ /**
338
+ * A command as a YAML list item. Plain where YAML reads it back unchanged; in
339
+ * double quotes where it would not, such as a `: ` that turns it into a map or
340
+ * a ` #` that turns the rest into a comment.
341
+ */
342
+ function yamlItem(command) {
343
+ if (!/: |\s#|^[\s'"&*!|>%@`{[]/.test(command)) return command;
344
+ return `"${command.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
345
+ }
346
+ /** A word for a YAML list item and a shell command at once, quoted only when it has to be. */
347
+ function quote(value) {
348
+ return /^[\w./@:+-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
349
+ }
350
+ function toPosix(value) {
351
+ return value.split(path.sep).join("/");
352
+ }
353
+ export { declaredStages as a, gitlabStage as c, WORKFLOW_FILE as i, pipelineFor as l, GITLAB_FILE as n, detectCiHost as o, GITLAB_INCLUDED_FILE as r, findGitRoot as s, BITBUCKET_FILE as t, pipelinePlan as u };