eaa-kit 0.7.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 (115) hide show
  1. package/README.md +182 -135
  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-DRjAY2iY.js → audit-DbqNIrt6.js} +85 -219
  6. package/dist/audit-rUhqnm3o.js +1 -0
  7. package/dist/{baseline-BpE7DbDq.js → baseline-CKElWbx4.js} +18 -8
  8. package/dist/baseline-DU0EPiTq.js +1 -0
  9. package/dist/baseline-DYOejLFO.js +1 -0
  10. package/dist/baseline-DvdsFTQy.js +126 -0
  11. package/dist/{cache-D4dOIuOi.js → cache-DIV4G0TI.js} +24 -5
  12. package/dist/{checklist-DDd9jewi.js → checklist-CA0Ri71Z.js} +8 -9
  13. package/dist/cli/index.js +115 -158
  14. package/dist/{collect-Cu1q9NTB.js → collect-CjucwTEF.js} +16 -8
  15. package/dist/{command-3r4fht5f.js → command-C8ZFvcc1.js} +33 -10
  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-B_PE6r5R.js +180 -0
  21. package/dist/countries-CCqog6dy.js +28 -0
  22. package/dist/coverage-B9_6yv_8.js +2 -0
  23. package/dist/{coverage-cb5kPp48.js → coverage-C1Z6t9Ct.js} +5 -7
  24. package/dist/{crawl-BHkJmUkA.js → crawl-CkHJJV4w.js} +135 -25
  25. package/dist/{criteria-CnPJKGeb.js → criteria-CacF0HP1.js} +1 -2
  26. package/dist/{load-BaWMa-G_.js → define-BdTPIfqE.js} +46 -99
  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-kf94P140.js +173 -0
  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-BIxxF3FC.js → html-Bjq3Iw3g.js} +56 -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 +50 -26
  42. package/dist/index.js +3 -2
  43. package/dist/init-3Ti3ao5Z.js +232 -0
  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-Bus6YhxB.js → json-B_k4CDmR.js} +5 -6
  48. package/dist/json-IL1JxlTL.js +1 -0
  49. package/dist/load-C3eFEdoH.js +98 -0
  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-CCP1WfYe.js +363 -0
  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-C0klJblu.js → remediation-BkE7q7dT.js} +2 -176
  61. package/dist/{render-C1sUZZI_.js → render-ky8cm4QF.js} +50 -24
  62. package/dist/result-DhoT4g0P.js +1 -0
  63. package/dist/{result-B7_zVxAX.js → result-g8dGsrcv.js} +1 -2
  64. package/dist/{review-CdMK2GpQ.js → review-BGjTBFvd.js} +11 -4
  65. package/dist/review-iheEjp7_.js +1 -0
  66. package/dist/{routes-CmdRUuOs.js → routes-BpQeBDmM.js} +4 -5
  67. package/dist/{run-DrS0Komf.js → run-D7tc7IU2.js} +2 -3
  68. package/dist/{run-BK2blxMI.d.ts → run-VXnP4uLp.d.ts} +2 -6
  69. package/dist/{sarif-BNCE0PNT.js → sarif-v66-PjdE.js} +9 -9
  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-CxVyh8IO.js +71 -0
  75. package/dist/start-bdanSxZr.js +100 -0
  76. package/dist/statement/templates/be.de.md +148 -0
  77. package/dist/statement/templates/be.en.md +142 -0
  78. package/dist/statement/templates/be.fr.md +146 -0
  79. package/dist/statement/templates/be.nl.md +147 -0
  80. package/dist/statement/templates/cz.cs.md +138 -0
  81. package/dist/statement/templates/cz.en.md +140 -0
  82. package/dist/statement/templates/dk.da.md +142 -0
  83. package/dist/statement/templates/dk.en.md +142 -0
  84. package/dist/statement/templates/fi.en.md +139 -0
  85. package/dist/statement/templates/fi.fi.md +141 -0
  86. package/dist/statement/templates/ie.en.md +144 -0
  87. package/dist/statement/templates/pl.en.md +143 -0
  88. package/dist/statement/templates/pl.pl.md +144 -0
  89. package/dist/statement/templates/pt.en.md +143 -0
  90. package/dist/statement/templates/pt.pt.md +145 -0
  91. package/dist/statement/templates/se.en.md +148 -0
  92. package/dist/statement/templates/se.sv.md +150 -0
  93. package/dist/{text-BF1LHMiV.js → text-CISDPU49.js} +11 -3
  94. package/dist/{version-B3v4rNoG.js → version-C8aJm8YJ.js} +1 -2
  95. package/dist/vite/index.d.ts +1 -3
  96. package/dist/vite/index.js +2 -3
  97. package/dist/watch-CefxwMsZ.js +121 -0
  98. package/dist/webpack/index.d.ts +1 -3
  99. package/dist/webpack/index.js +2 -3
  100. package/dist/{worksheet-BIxMtbUd.js → worksheet-CcBo9G7s.js} +4 -5
  101. package/dist/workspaces-BBFXOyeV.js +85 -0
  102. package/package.json +16 -14
  103. package/dist/audit-Bwm1xBdJ.js +0 -2
  104. package/dist/baseline-rtnj3RHB.js +0 -2
  105. package/dist/component-DcCn3BJS.js +0 -2
  106. package/dist/coverage-n1X9CkiG.js +0 -3
  107. package/dist/frameworks-etFg_O8K.js +0 -2
  108. package/dist/init-DrFfzjvm.js +0 -119
  109. package/dist/jsdom-BUYuVJJm.js +0 -3
  110. package/dist/json-CrQmoTj6.js +0 -2
  111. package/dist/load-n62iXDq_.js +0 -2
  112. package/dist/project-CzOnkLH6.js +0 -274
  113. package/dist/project-MFrXcw1M.js +0 -2
  114. package/dist/result-CRmjjoAA.js +0 -2
  115. package/dist/review-DIbOTmOM.js +0 -2
@@ -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 };
@@ -0,0 +1,89 @@
1
+ // src/audit/shell.ts
2
+ /**
3
+ * Whether a page is an empty shell that a script fills in.
4
+ *
5
+ * A single-page app's build writes one `index.html` holding an empty
6
+ * `<div id="root">` and a script tag. The browserless engine does not run
7
+ * scripts, so it audits the empty div, finds nothing wrong with it, and the
8
+ * run reports a clean site that was never looked at. That is the false
9
+ * assurance this tool exists to refuse, so such a page is set aside and named
10
+ * as not audited instead.
11
+ *
12
+ * The test is what a visitor could perceive before any script runs: text,
13
+ * images and media, embedded frames, and form controls. A page with none of
14
+ * those is a shell, whatever its root element is called.
15
+ */
16
+ function isAppShell(html) {
17
+ const lower = html.toLowerCase();
18
+ const bodyOpen = lower.indexOf("<body");
19
+ const bodyClose = lower.lastIndexOf("</body");
20
+ let body;
21
+ if (bodyOpen !== -1 && bodyClose > bodyOpen) {
22
+ const tagEnd = html.indexOf(">", bodyOpen);
23
+ body = tagEnd === -1 || tagEnd > bodyClose ? "" : html.slice(tagEnd + 1, bodyClose);
24
+ } else body = withoutElements(html, ["head"], true);
25
+ const visible = withoutComments(body);
26
+ if (/<(img|svg|video|audio|canvas|iframe|object|embed|input|select|textarea|button|picture)\b/i.test(visible)) return false;
27
+ return withoutTags(withoutElements(visible, [
28
+ "script",
29
+ "style",
30
+ "template",
31
+ "noscript"
32
+ ])).replace(/&nbsp;|&#160;/g, " ").trim() === "";
33
+ }
34
+ /** `<!-- … -->` taken out; an unclosed one runs to the end, as a browser reads it. */
35
+ function withoutComments(html) {
36
+ let output = "";
37
+ let cursor = 0;
38
+ for (;;) {
39
+ const open = html.indexOf("<!--", cursor);
40
+ if (open === -1) return output + html.slice(cursor);
41
+ output += html.slice(cursor, open);
42
+ const close = html.indexOf("-->", open + 4);
43
+ if (close === -1) return output;
44
+ cursor = close + 3;
45
+ }
46
+ }
47
+ /**
48
+ * Elements with these names taken out with their content. One left open is
49
+ * taken out to the end, which is what the old pattern's failure to match left
50
+ * in place instead; for a page that is never shown either way it is the same
51
+ * answer. `firstOnly` removes just the first, for the head.
52
+ */
53
+ function withoutElements(html, names, firstOnly = false) {
54
+ const lower = html.toLowerCase();
55
+ const opening = new RegExp(`<(${names.join("|")})\\b`, "g");
56
+ let output = "";
57
+ let cursor = 0;
58
+ for (;;) {
59
+ opening.lastIndex = cursor;
60
+ const match = opening.exec(lower);
61
+ if (match === null) return output + html.slice(cursor);
62
+ output += html.slice(cursor, match.index);
63
+ const close = closingTag(lower, match[1], match.index + match[0].length);
64
+ if (close === -1) return firstOnly ? output + html.slice(match.index) : output;
65
+ const end = lower.indexOf(">", close);
66
+ cursor = end === -1 ? html.length : end + 1;
67
+ if (firstOnly) return output + html.slice(cursor);
68
+ }
69
+ }
70
+ /** Where `</name` starts, as a whole name: `</head` is not `</header`. */
71
+ function closingTag(lower, name, from) {
72
+ let at = lower.indexOf(`</${name}`, from);
73
+ while (at !== -1 && /[a-z0-9-]/.test(lower[at + name.length + 2] ?? "")) at = lower.indexOf(`</${name}`, at + 1);
74
+ return at;
75
+ }
76
+ /** Markup taken out, text kept. A `<` with no `>` after it is text, as before. */
77
+ function withoutTags(html) {
78
+ let output = "";
79
+ let cursor = 0;
80
+ for (;;) {
81
+ const open = html.indexOf("<", cursor);
82
+ if (open === -1) return output + html.slice(cursor);
83
+ const close = html.indexOf(">", open + 1);
84
+ if (close === -1) return output + html.slice(cursor);
85
+ output += html.slice(cursor, open);
86
+ cursor = close + 1;
87
+ }
88
+ }
89
+ export { isAppShell };
@@ -0,0 +1,71 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { glob } from "tinyglobby";
4
+ // src/audit/site.ts
5
+ /** The home page, or failing that the first page in path order. */
6
+ async function homePage(directory) {
7
+ for (const name of ["index.html", "index.htm"]) {
8
+ const candidate = path.join(directory, name);
9
+ try {
10
+ return await readFile(candidate, "utf8");
11
+ } catch {}
12
+ }
13
+ const first = (await glob(["**/*.html", "**/*.htm"], {
14
+ cwd: directory,
15
+ ignore: ["**/node_modules/**"],
16
+ onlyFiles: true,
17
+ dot: false
18
+ })).sort()[0];
19
+ if (first === void 0) return void 0;
20
+ try {
21
+ return await readFile(path.join(directory, first), "utf8");
22
+ } catch {
23
+ return;
24
+ }
25
+ }
26
+ async function readSiteFacts(directory) {
27
+ const html = await homePage(directory);
28
+ if (html === void 0) return {};
29
+ return siteFactsFrom(html);
30
+ }
31
+ function siteFactsFrom(html) {
32
+ const facts = {};
33
+ const htmlTag = /<html\b[^>]*>/i.exec(html)?.[0];
34
+ const lang = htmlTag === void 0 ? void 0 : attribute(htmlTag, "lang");
35
+ if (lang !== void 0 && /^[a-z]{2,3}(-[a-z0-9]{2,8})*$/i.test(lang)) facts.lang = lang;
36
+ const url = canonicalUrl(html);
37
+ if (url !== void 0) facts.url = url;
38
+ const title = /<title\b[^>]*>([^<]*)<\/title>/i.exec(html)?.[1]?.trim();
39
+ if (title !== void 0 && title !== "") facts.title = decodeEntities(title);
40
+ return facts;
41
+ }
42
+ /**
43
+ * The address the site gives for itself. Only an absolute http(s) URL counts:
44
+ * a relative canonical tells you nothing about where the site lives.
45
+ */
46
+ function canonicalUrl(html) {
47
+ const candidates = [];
48
+ for (const tag of html.match(/<link\b[^>]*>/gi) ?? []) {
49
+ const rel = attribute(tag, "rel")?.toLowerCase().split(/\s+/);
50
+ const href = attribute(tag, "href");
51
+ if (rel?.includes("canonical") && href !== void 0) candidates.push(href);
52
+ }
53
+ for (const tag of html.match(/<meta\b[^>]*>/gi) ?? []) {
54
+ const content = attribute(tag, "content");
55
+ if (attribute(tag, "property") === "og:url" && content !== void 0) candidates.push(content);
56
+ }
57
+ for (const candidate of candidates) try {
58
+ const url = new URL(decodeEntities(candidate));
59
+ if (url.protocol === "http:" || url.protocol === "https:") return url.origin;
60
+ } catch {}
61
+ }
62
+ function attribute(tag, name) {
63
+ const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(tag);
64
+ const value = match?.[1] ?? match?.[2] ?? match?.[3];
65
+ return value === void 0 ? void 0 : value.trim();
66
+ }
67
+ /** The five entities a title or URL realistically carries. */
68
+ function decodeEntities(text) {
69
+ return text.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;|&apos;/g, "'");
70
+ }
71
+ export { readSiteFacts };
@@ -0,0 +1,100 @@
1
+ import "./baseline-CKElWbx4.js";
2
+ import { i as countryForLocale, t as COUNTRY_INFO } from "./countries-B_PE6r5R.js";
3
+ import { n as runAuditCommand } from "./audit-DbqNIrt6.js";
4
+ import { n as auditDefaults, o as fail, r as auditInvocation } from "./command-C8ZFvcc1.js";
5
+ import { access, mkdir, writeFile } from "node:fs/promises";
6
+ import path from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+ import pc from "picocolors";
9
+ // src/cli/start.ts
10
+ /**
11
+ * `eaa-kit`, with nothing after it.
12
+ *
13
+ * The first thing anybody types is the name of the tool, and until 0.8 that
14
+ * printed the help and exited 2. This makes that first command do the useful
15
+ * thing instead. It finds the site the way `audit` does: an existing build, the
16
+ * project's own build, its server, or a folder of hand-written HTML. It audits
17
+ * the site, writes the HTML report where it can be opened, and then says what it
18
+ * found about the project and which command to run next, based on what the
19
+ * project already has.
20
+ *
21
+ * Nothing is asked and nothing is written into the project except under
22
+ * `.eaa-kit/`, which the run's own cache already uses. A first look should be
23
+ * safe to take on somebody else's checkout.
24
+ */
25
+ /** Where the first run leaves the report, relative to the project. */
26
+ const FIRST_RUN_REPORT = path.join(".eaa-kit", "report.html");
27
+ async function runFirstRun(options = {}) {
28
+ const cwd = options.cwd ?? process.cwd();
29
+ process.stderr.write(`${pc.bold("eaa-kit")} ${pc.dim("· WCAG 2.2 AA · nothing to set up, finding your site…")}\n\n`);
30
+ const defaults = await auditDefaults({ cwd });
31
+ const invocation = auditInvocation(void 0, defaults, {});
32
+ const result = await runAuditCommand(invocation.dir, {
33
+ ...invocation.options,
34
+ cwd,
35
+ htmlReport: FIRST_RUN_REPORT
36
+ });
37
+ if (result.audits.length === 0) {
38
+ fail("No site found to audit, so no report was written.");
39
+ return { exitCode: result.exitCode };
40
+ }
41
+ await ensureToolDirectory(cwd);
42
+ process.stderr.write(await summary(cwd, result));
43
+ return { exitCode: result.exitCode };
44
+ }
45
+ /**
46
+ * `.eaa-kit/`, with a `.gitignore` that keeps everything in it out of version
47
+ * control.
48
+ *
49
+ * The docs have always said the directory belongs in `.gitignore`, which is
50
+ * advice nobody running the tool for the first time has read. The first run is
51
+ * about to put a report there as well as the cache. So it looks after that
52
+ * itself, without touching the project's own `.gitignore`.
53
+ */
54
+ async function ensureToolDirectory(cwd) {
55
+ const directory = path.join(cwd, ".eaa-kit");
56
+ const ignore = path.join(directory, ".gitignore");
57
+ try {
58
+ await mkdir(directory, { recursive: true });
59
+ if (!await exists(ignore)) await writeFile(ignore, "# Written by eaa-kit: the cache and reports are not source.\n*\n");
60
+ } catch {}
61
+ }
62
+ async function summary(cwd, result) {
63
+ const lines = ["", pc.bold("What eaa-kit found about this project")];
64
+ const where = result.directory === void 0 ? "a running server" : path.relative(cwd, result.directory) === "" ? "this folder" : `${path.relative(cwd, result.directory)}${path.sep}`;
65
+ const { detectFramework } = await import("./frameworks-Y-n3NUuG.js");
66
+ const { readPackageJson } = await import("./project-Dht13sb1.js");
67
+ const framework = (await detectFramework(cwd, await readPackageJson(cwd)))?.framework.name;
68
+ const pages = result.audits.length === 1 ? "1 page" : `${result.audits.length} pages`;
69
+ lines.push(` Site ${where}${framework === void 0 ? "" : ` (${framework})`}, ${pages}`);
70
+ const facts = result.directory === void 0 ? {} : await (await import("./site-CxVyh8IO.js")).readSiteFacts(result.directory);
71
+ const country = facts.lang === void 0 ? void 0 : countryForLocale(facts.lang);
72
+ if (facts.lang !== void 0) {
73
+ const law = country === void 0 ? "" : pc.dim(` → a statement under ${COUNTRY_INFO[country].name}'s law`);
74
+ lines.push(` Language ${facts.lang}${law}`);
75
+ } else lines.push(` Language ${pc.yellow("none declared")} ${pc.dim("(<html lang> is missing)")}`);
76
+ if (facts.url !== void 0) lines.push(` Address ${facts.url}`);
77
+ const report = path.resolve(cwd, FIRST_RUN_REPORT);
78
+ if (await exists(report)) lines.push(` Report ${pathToFileURL(report).href}`);
79
+ lines.push("", pc.bold("Next"));
80
+ const next = (command, why) => {
81
+ lines.push(` ${pc.cyan(command.padEnd(24))}${why}`);
82
+ };
83
+ const { existingConfig } = await import("./init-3Ti3ao5Z.js");
84
+ const config = await existingConfig(cwd);
85
+ if (config === void 0) next("eaa-kit init", country === void 0 ? "write the config your accessibility statement is made from" : `write the config for your statement, with ${COUNTRY_INFO[country].name} filled in`);
86
+ else next("eaa-kit statement", `write your accessibility statement from ${config}`);
87
+ if (result.audits.some((audit) => audit.violations.length > 0) && !await exists(path.join(cwd, "eaa-baseline.json"))) next("eaa-kit baseline", "accept today's findings; later runs fail only on new ones");
88
+ if (result.directory !== void 0) next("eaa-kit audit --watch", "check again on every build while you fix things");
89
+ next("eaa-kit checklist", "the 34 criteria no automated test can check");
90
+ return `${lines.join("\n")}\n`;
91
+ }
92
+ async function exists(target) {
93
+ try {
94
+ await access(target);
95
+ return true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ export { runFirstRun };