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
@@ -0,0 +1,502 @@
1
+ import { i as toPosix, n as isDirectory, t as exists } from "./fs-tPD5r0wY.js";
2
+ import { n as DEFAULT_EXCLUDE } from "./collect-CjucwTEF.js";
3
+ import { r as candidateOutputs } from "./frameworks-BboC8eNk.js";
4
+ import { readFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { glob } from "tinyglobby";
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import { createServer } from "node:net";
9
+ // src/audit/project.ts
10
+ /**
11
+ * Working out what to audit when nobody said.
12
+ *
13
+ * `eaa-kit audit ./dist` assumes the reader knows which directory their builder
14
+ * fills, that it has been built, and that it produces HTML at all — three
15
+ * assumptions that are wrong often enough to be the main thing standing between
16
+ * installing this tool and getting a report out of it. A Next.js project fails
17
+ * all three at once.
18
+ *
19
+ * So with no directory and no --url, the tool works it out: an existing build
20
+ * output if there is one, the project's own build if there is not, and the
21
+ * project's server if the build produces nothing browsable. Naming a directory
22
+ * or passing --url skips all of it.
23
+ */
24
+ /**
25
+ * Ports the common servers use, tried if nothing is announced: Next and Remix,
26
+ * Astro, Vite dev and preview, Angular, Gatsby, Hugo, Jekyll, and the usual
27
+ * fallbacks.
28
+ */
29
+ const KNOWN_PORTS = [
30
+ 3e3,
31
+ 4321,
32
+ 5173,
33
+ 4173,
34
+ 4200,
35
+ 8e3,
36
+ 1313,
37
+ 4e3,
38
+ 8080,
39
+ 3001
40
+ ];
41
+ /** How long to wait for a started server to answer. */
42
+ const SERVER_START_TIMEOUT_MS = 9e4;
43
+ async function readPackageJson(cwd) {
44
+ try {
45
+ return JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8"));
46
+ } catch {
47
+ return;
48
+ }
49
+ }
50
+ /**
51
+ * `deno.json` or `deno.jsonc`, the config of a Deno project, which may have no
52
+ * package.json at all. Undefined when there is neither, or it does not parse.
53
+ */
54
+ async function readDenoConfig(cwd) {
55
+ for (const name of ["deno.json", "deno.jsonc"]) {
56
+ let source;
57
+ try {
58
+ source = await readFile(path.join(cwd, name), "utf8");
59
+ } catch {
60
+ continue;
61
+ }
62
+ try {
63
+ return JSON.parse(withoutComments(source));
64
+ } catch {
65
+ return;
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * JSONC to JSON: comments out, strings untouched. A task is often a command
71
+ * with a URL in it, so `//` inside a string is not a comment.
72
+ */
73
+ function withoutComments(source) {
74
+ let out = "";
75
+ for (let i = 0; i < source.length; i++) {
76
+ const char = source[i];
77
+ if (char === "\"") {
78
+ const start = i;
79
+ for (i++; i < source.length && source[i] !== "\""; i++) if (source[i] === "\\") i++;
80
+ out += source.slice(start, i + 1);
81
+ } else if (char === "/" && source[i + 1] === "/") {
82
+ while (i < source.length && source[i] !== "\n") i++;
83
+ out += "\n";
84
+ } else if (char === "/" && source[i + 1] === "*") {
85
+ i = source.indexOf("*/", i + 2);
86
+ if (i === -1) break;
87
+ i++;
88
+ } else out += char;
89
+ }
90
+ return out.replace(/,(\s*[}\]])/g, "$1");
91
+ }
92
+ const MANAGERS = [
93
+ "pnpm",
94
+ "yarn",
95
+ "bun",
96
+ "deno",
97
+ "npm"
98
+ ];
99
+ /** Lockfiles, in the order they are believed when more than one is present. */
100
+ const LOCKFILES = [
101
+ ["pnpm-lock.yaml", "pnpm"],
102
+ ["yarn.lock", "yarn"],
103
+ ["bun.lock", "bun"],
104
+ ["bun.lockb", "bun"],
105
+ ["deno.lock", "deno"],
106
+ ["package-lock.json", "npm"],
107
+ ["npm-shrinkwrap.json", "npm"]
108
+ ];
109
+ /**
110
+ * The package manager this project uses, and how that was decided.
111
+ *
112
+ * Running the wrong one either fails or, worse, silently installs a second
113
+ * dependency tree, so this is read rather than guessed: corepack's
114
+ * `packageManager` field first, because it is the project saying so outright,
115
+ * then a lockfile. An app inside a monorepo has no lockfile of its own, so the
116
+ * search walks up to the repository root, and no further: a lockfile above the
117
+ * repository belongs to somebody else's project.
118
+ */
119
+ async function findPackageManager(cwd) {
120
+ let dir = path.resolve(cwd);
121
+ for (;;) {
122
+ const declared = (await readPackageJson(dir))?.packageManager;
123
+ const name = typeof declared === "string" ? declared.split("@")[0] : void 0;
124
+ const known = MANAGERS.find((manager) => manager === name);
125
+ if (known !== void 0) return {
126
+ manager: known,
127
+ evidence: `package.json declares packageManager ${declared}`
128
+ };
129
+ for (const [file, manager] of LOCKFILES) if (await exists(path.join(dir, file))) {
130
+ const where = path.relative(cwd, path.join(dir, file)) || file;
131
+ return {
132
+ manager,
133
+ evidence: `found ${toPosix(where)}`
134
+ };
135
+ }
136
+ for (const file of ["deno.json", "deno.jsonc"]) if (await exists(path.join(dir, file))) {
137
+ const where = path.relative(cwd, path.join(dir, file)) || file;
138
+ return {
139
+ manager: "deno",
140
+ evidence: `found ${toPosix(where)}`
141
+ };
142
+ }
143
+ const parent = path.dirname(dir);
144
+ if (parent === dir || await exists(path.join(dir, ".git"))) break;
145
+ dir = parent;
146
+ }
147
+ return {
148
+ manager: "npm",
149
+ evidence: "no lockfile, so npm"
150
+ };
151
+ }
152
+ async function detectPackageManager(cwd) {
153
+ return (await findPackageManager(cwd)).manager;
154
+ }
155
+ /**
156
+ * The first build directory that exists and actually holds HTML.
157
+ *
158
+ * Existence alone is not enough: `.next/` exists after any Next.js build and
159
+ * holds no browsable page, and `public/` exists in most projects and holds
160
+ * assets. What makes a directory the build output is that there is HTML in it.
161
+ */
162
+ async function findBuildOutput(cwd) {
163
+ const candidates = await candidateOutputs(cwd, await readPackageJson(cwd));
164
+ for (const candidate of candidates) {
165
+ const directory = path.join(cwd, candidate);
166
+ if (!await isDirectory(directory)) continue;
167
+ if ((await glob(["**/*.html", "**/*.htm"], {
168
+ cwd: directory,
169
+ ignore: [...DEFAULT_EXCLUDE],
170
+ onlyFiles: true,
171
+ dot: false
172
+ })).length > 0) return directory;
173
+ }
174
+ }
175
+ /** Whether a folder has an HTML file directly in it, not only somewhere below. */
176
+ async function holdsTopLevelHtml(cwd) {
177
+ return (await glob(["*.html", "*.htm"], {
178
+ cwd,
179
+ onlyFiles: true,
180
+ dot: false
181
+ })).length > 0;
182
+ }
183
+ /**
184
+ * How to invoke a package-manager script on this platform.
185
+ *
186
+ * Not `shell: true` with an argument array: Node deprecated that in DEP0190
187
+ * because the arguments are concatenated rather than escaped, and it prints a
188
+ * warning into the middle of somebody's build output. Windows still needs a
189
+ * shell — npm and pnpm are `.cmd` shims there, which cannot be spawned
190
+ * directly — so cmd.exe is invoked explicitly with one command string instead.
191
+ */
192
+ function scriptCommand(manager, script) {
193
+ const verb = manager === "deno" ? "task" : "run";
194
+ if (process.platform !== "win32") return {
195
+ command: manager,
196
+ args: [verb, script]
197
+ };
198
+ return {
199
+ command: process.env["ComSpec"] ?? "cmd.exe",
200
+ args: [
201
+ "/d",
202
+ "/s",
203
+ "/c",
204
+ `${manager} ${verb} ${script}`
205
+ ]
206
+ };
207
+ }
208
+ /**
209
+ * Run one of the project's own scripts and wait for it.
210
+ *
211
+ * stdio is inherited so the build's output goes where the user expects it. This
212
+ * runs project code, which is what a build-time tool does — the Astro
213
+ * integration already audits from inside one — but it is announced first and
214
+ * `--no-build` turns it off.
215
+ */
216
+ async function runScript(cwd, script) {
217
+ const manager = await detectPackageManager(cwd);
218
+ const command = `${manager} ${manager === "deno" ? "task" : "run"} ${script}`;
219
+ return new Promise((resolve) => {
220
+ const { command: bin, args } = scriptCommand(manager, script);
221
+ const child = spawn(bin, args, {
222
+ cwd,
223
+ stdio: [
224
+ "ignore",
225
+ "inherit",
226
+ "inherit"
227
+ ]
228
+ });
229
+ child.on("error", () => resolve({
230
+ ok: false,
231
+ command
232
+ }));
233
+ child.on("close", (code) => resolve({
234
+ ok: code === 0,
235
+ command
236
+ }));
237
+ });
238
+ }
239
+ /** Whether something is answering HTTP there yet. */
240
+ async function answers(origin) {
241
+ try {
242
+ const controller = new AbortController();
243
+ const timer = setTimeout(() => controller.abort(), 2e3);
244
+ try {
245
+ await fetch(origin, { signal: controller.signal });
246
+ return true;
247
+ } finally {
248
+ clearTimeout(timer);
249
+ }
250
+ } catch {
251
+ return false;
252
+ }
253
+ }
254
+ /** A port nothing is listening on right now, from the operating system. */
255
+ async function freePort() {
256
+ return new Promise((resolve) => {
257
+ const probe = createServer();
258
+ probe.once("error", () => resolve(void 0));
259
+ probe.listen(0, "127.0.0.1", () => {
260
+ const address = probe.address();
261
+ const port = typeof address === "object" && address !== null ? address.port : void 0;
262
+ probe.close(() => resolve(port));
263
+ });
264
+ });
265
+ }
266
+ async function startServer(cwd, script, options = {}) {
267
+ const manager = await detectPackageManager(cwd);
268
+ const { command: bin, args } = options.command === void 0 ? scriptCommand(manager, script) : {
269
+ command: options.command.bin,
270
+ args: options.command.args
271
+ };
272
+ const port = await freePort();
273
+ const child = spawn(bin, args, {
274
+ cwd: options.command?.cwd ?? cwd,
275
+ env: port === void 0 ? process.env : {
276
+ ...process.env,
277
+ PORT: String(port)
278
+ },
279
+ stdio: [
280
+ "ignore",
281
+ "pipe",
282
+ "pipe"
283
+ ],
284
+ detached: process.platform !== "win32"
285
+ });
286
+ let announced;
287
+ const watch = (chunk) => {
288
+ const text = String(chunk).replace(/\u001b\[[0-9;]*m/g, "");
289
+ const match = /https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\]):(\d{2,5})/.exec(text);
290
+ if (match && announced === void 0) announced = `http://localhost:${match[1]}`;
291
+ };
292
+ child.stdout?.on("data", watch);
293
+ child.stderr?.on("data", watch);
294
+ let stopped = false;
295
+ const stop = async () => {
296
+ if (stopped) return;
297
+ stopped = true;
298
+ const signal = (name) => {
299
+ try {
300
+ if (child.pid === void 0) return;
301
+ if (process.platform === "win32") spawnSync("taskkill", [
302
+ "/pid",
303
+ String(child.pid),
304
+ "/T",
305
+ "/F"
306
+ ], { stdio: "ignore" });
307
+ else process.kill(-child.pid, name);
308
+ } catch {}
309
+ };
310
+ if (child.exitCode === null && child.signalCode === null) {
311
+ signal("SIGTERM");
312
+ await new Promise((resolve) => {
313
+ const timer = setTimeout(() => {
314
+ signal("SIGKILL");
315
+ resolve();
316
+ }, 5e3);
317
+ child.once("close", () => {
318
+ clearTimeout(timer);
319
+ resolve();
320
+ });
321
+ });
322
+ }
323
+ child.stdout?.destroy();
324
+ child.stderr?.destroy();
325
+ child.unref();
326
+ };
327
+ const deadline = Date.now() + SERVER_START_TIMEOUT_MS;
328
+ while (Date.now() < deadline) {
329
+ if (child.exitCode !== null) return void 0;
330
+ const ports = port === void 0 ? KNOWN_PORTS : [port, ...KNOWN_PORTS];
331
+ for (const origin of announced === void 0 ? ports.map((candidate) => `http://localhost:${candidate}`) : [announced]) if (await answers(origin)) return {
332
+ origin,
333
+ stop
334
+ };
335
+ await new Promise((resolve) => setTimeout(resolve, 500));
336
+ }
337
+ await stop();
338
+ }
339
+ /**
340
+ * Work out what to audit in this project, building or serving it if need be.
341
+ *
342
+ * Returns undefined when there is nothing it can do, leaving the caller to
343
+ * explain — it has better context for the message than this does.
344
+ */
345
+ async function autoDetectSource(cwd, options = {}) {
346
+ const steps = [];
347
+ const step = (message) => {
348
+ steps.push(message);
349
+ options.onStep?.(message);
350
+ };
351
+ const existing = await findBuildOutput(cwd);
352
+ if (existing !== void 0) {
353
+ step(`Found a build in ${path.relative(cwd, existing) || "."}/`);
354
+ return {
355
+ directory: existing,
356
+ steps
357
+ };
358
+ }
359
+ const pkg = await readPackageJson(cwd);
360
+ const { detectFramework } = await import("./frameworks-Y-n3NUuG.js");
361
+ const detected = await detectFramework(cwd, pkg);
362
+ if (detected === void 0) {
363
+ const { findWorkspaceSites } = await import("./workspaces-BBFXOyeV.js");
364
+ const sites = (await findWorkspaceSites(cwd))?.sites ?? [];
365
+ const only = sites[0];
366
+ if (sites.length === 1 && only !== void 0) {
367
+ step(`This is a monorepo with one site, in ${only.dir}/`);
368
+ const inner = await autoDetectSource(path.join(cwd, only.dir), options);
369
+ return inner === void 0 ? { steps } : {
370
+ ...inner,
371
+ steps: [...steps, ...inner.steps]
372
+ };
373
+ }
374
+ if (sites.length > 1) {
375
+ step(`This is a monorepo with ${sites.length} sites: ${sites.map((site) => site.dir).join(", ")}`);
376
+ return {
377
+ steps,
378
+ sites: sites.map((site) => site.dir)
379
+ };
380
+ }
381
+ }
382
+ if (detected !== void 0 && detected.framework.outputs.length === 0) {
383
+ step(`${detected.framework.name} renders on a server and writes no HTML to disk`);
384
+ return { steps };
385
+ }
386
+ if (pkg === void 0) {
387
+ if (detected === void 0 && await holdsTopLevelHtml(cwd)) {
388
+ step("Found hand-written HTML in this folder");
389
+ return {
390
+ directory: cwd,
391
+ steps
392
+ };
393
+ }
394
+ return;
395
+ }
396
+ const scripts = pkg.scripts ?? {};
397
+ if (options.noBuild) return void 0;
398
+ if (scripts["build"] !== void 0) {
399
+ step("No build found; running the project build first");
400
+ const built = await runScript(cwd, "build");
401
+ if (!built.ok) {
402
+ step(`${built.command} failed`);
403
+ return { steps };
404
+ }
405
+ const produced = await findBuildOutput(cwd);
406
+ if (produced !== void 0) {
407
+ step(`Built ${path.relative(cwd, produced) || "."}/`);
408
+ return {
409
+ directory: produced,
410
+ steps
411
+ };
412
+ }
413
+ }
414
+ if (detected?.framework.id === "next") return serveNext(cwd, scripts, steps, step);
415
+ const serveScript = [
416
+ "start",
417
+ "preview",
418
+ "serve"
419
+ ].find((name) => scripts[name] !== void 0);
420
+ if (serveScript === void 0) return { steps };
421
+ const shown = await scriptLabel(cwd, serveScript);
422
+ step(`This site renders on a server; starting it with ${shown}`);
423
+ const server = await startServer(cwd, serveScript);
424
+ if (server === void 0) {
425
+ step(`Could not start the site with ${shown}`);
426
+ return { steps };
427
+ }
428
+ step(`Auditing ${server.origin}`);
429
+ return {
430
+ url: server.origin,
431
+ cleanup: server.stop,
432
+ steps
433
+ };
434
+ }
435
+ /**
436
+ * Serve a Next.js build and list its pages from the build's own manifests.
437
+ *
438
+ * Never `next dev`: the development overlay and unoptimised output are not the
439
+ * site anybody visits. A standalone build is served by the server.js it wrote,
440
+ * when the static files were copied beside it as Next's docs say; otherwise by
441
+ * `next start`, which serves any build.
442
+ */
443
+ async function serveNext(cwd, scripts, steps, step) {
444
+ const { nextPageUrl, nextRoutes, readNextConfig } = await import("./next-8zDgH0nP.js");
445
+ const config = await readNextConfig(cwd);
446
+ const dist = config.distDir ?? ".next";
447
+ const standalone = path.join(cwd, dist, "standalone");
448
+ let options;
449
+ let how;
450
+ if (config.output === "standalone" && await exists(path.join(standalone, "server.js")) && await exists(path.join(standalone, dist, "static"))) {
451
+ options = { command: {
452
+ bin: process.execPath,
453
+ args: ["server.js"],
454
+ cwd: standalone
455
+ } };
456
+ how = `node ${toPosix(path.join(dist, "standalone", "server.js"))}`;
457
+ } else if (scripts["start"] !== void 0) how = await scriptLabel(cwd, "start");
458
+ else {
459
+ const bin = path.join(cwd, "node_modules", "next", "dist", "bin", "next");
460
+ if (!await exists(bin)) return { steps };
461
+ options = { command: {
462
+ bin: process.execPath,
463
+ args: [bin, "start"]
464
+ } };
465
+ how = "next start";
466
+ }
467
+ step(`This site renders on a server; starting it with ${how}`);
468
+ const server = await startServer(cwd, "start", options);
469
+ if (server === void 0) {
470
+ step(`Could not start the site with ${how}`);
471
+ return { steps };
472
+ }
473
+ const routes = await nextRoutes(cwd);
474
+ if (routes === void 0) {
475
+ step(`Auditing ${server.origin}`);
476
+ return {
477
+ url: server.origin,
478
+ cleanup: server.stop,
479
+ steps
480
+ };
481
+ }
482
+ const url = nextPageUrl(server.origin, routes, "/");
483
+ const seeds = routes.pages.map((page) => nextPageUrl(server.origin, routes, page));
484
+ step(`Read ${seeds.length} ${seeds.length === 1 ? "page" : "pages"} from the Next.js build manifests`);
485
+ step(`Auditing ${url}`);
486
+ return {
487
+ url,
488
+ seeds,
489
+ ...routes.dynamic.length === 0 ? {} : { unreachable: routes.dynamic.map((route) => ({
490
+ location: `${routes.basePath}${route}`,
491
+ reason: "a dynamic route rendered on request, with no list of its pages: only pages that links reached were audited"
492
+ })) },
493
+ cleanup: server.stop,
494
+ steps
495
+ };
496
+ }
497
+ /** How a script is run here, for a message: `pnpm run start`. */
498
+ async function scriptLabel(cwd, script) {
499
+ const manager = await detectPackageManager(cwd);
500
+ return `${manager} ${manager === "deno" ? "task" : "run"} ${script}`;
501
+ }
502
+ export { readDenoConfig as a, startServer as c, findPackageManager as i, detectPackageManager as n, readPackageJson as o, findBuildOutput as r, runScript as s, autoDetectSource as t };
@@ -0,0 +1 @@
1
+ export { t as autoDetectSource, o as readPackageJson } from "./project-B21NT_aX.js";
@@ -1,194 +1,4 @@
1
- import { o as impactRank } from "./impact-luGCnN8F.js";
2
- import { t as elementFingerprint } from "./fingerprint-BjYV_0F7.js";
3
- import { s as findingElements } from "./result-B7_zVxAX.js";
4
- //#region src/audit/completeness.ts
5
- /**
6
- * Fold what the collector knew together with what the engine managed.
7
- *
8
- * The audits carry the second half: a page with an `error` was collected and
9
- * then not audited, and is as unmeasured as one that was never fetched.
10
- */
11
- function runCompleteness(audits, collection) {
12
- const errored = audits.filter((audit) => audit.error).length;
13
- const reused = audits.filter((audit) => audit.reused !== void 0).length;
14
- return {
15
- ...collection,
16
- audited: audits.length - errored - reused,
17
- reused,
18
- errored,
19
- complete: collection.unreachable.length === 0 && !collection.truncated && errored === 0
20
- };
21
- }
22
- /**
23
- * What a run reused, in one phrase, or nothing when it audited everything.
24
- *
25
- * Its own sentence rather than a clause in `missedParts`: nothing was missed
26
- * here. The pages have verdicts; they were reached on an earlier day, on markup
27
- * identical to today's, and a reader is entitled to know which.
28
- */
29
- function reusedPart(completeness) {
30
- if (completeness.reused === 0) return void 0;
31
- const pages = completeness.reused === 1 ? "page" : "pages";
32
- return `${completeness.reused} ${pages} unchanged since the last run, so the earlier result was reused`;
33
- }
34
- /**
35
- * Where a followed entry redirect took the run, in one sentence every format
36
- * prints. Undefined when the run went where it was sent.
37
- */
38
- function redirectPart(completeness) {
39
- const redirect = completeness.entryRedirect;
40
- if (redirect === void 0) return void 0;
41
- return `${redirect.requested} redirected to ${redirect.auditedFrom} (${redirect.statuses.join(" → ")}; ${redirectReason(redirect)}), so this report is about ${redirect.auditedFrom}`;
42
- }
43
- /** Why a redirect was followed, in words. */
44
- function redirectReason(redirect) {
45
- return {
46
- "same-site": "the same site at another address",
47
- flag: "followed because --redirects follow was set",
48
- prompt: "followed because it was approved when asked"
49
- }[redirect.followedBecause];
50
- }
51
- /**
52
- * What was missed, as phrases both reports print.
53
- *
54
- * Separate clauses rather than one total, for the same reason the coverage
55
- * parts are: a page that could not be fetched and a page that could not be
56
- * parsed are different problems with different fixes, and summing them would
57
- * name neither.
58
- */
59
- function missedParts(completeness) {
60
- const parts = [];
61
- if (completeness.unreachable.length > 0) parts.push(`${completeness.unreachable.length} could not be reached`);
62
- if (completeness.errored > 0) parts.push(`${completeness.errored} could not be audited`);
63
- if (completeness.truncated) parts.push("the run stopped at its page limit");
64
- return parts;
65
- }
66
- /** How the pages were found, in words, for the run details both reports show. */
67
- function discoveryLabel(discovery) {
68
- switch (discovery) {
69
- case "directory": return "files in the build directory";
70
- case "sitemap": return "sitemap.xml and links";
71
- case "links": return "links from the entry page";
72
- }
73
- }
74
- /** Whether this element looks like one component rendered on many pages. */
75
- function isShared(element) {
76
- return element.pages.length >= 3;
77
- }
78
- /**
79
- * Fold a run's violations into one entry per rule, and one per element within it.
80
- *
81
- * Accepted violations are not included: a baseline moves them out of what fails
82
- * the build, and this is a view of what fails.
83
- */
84
- function groupIssues(audits) {
85
- const byRule = /* @__PURE__ */ new Map();
86
- for (const audit of audits) for (const finding of audit.violations) {
87
- let issue = byRule.get(finding.ruleId);
88
- if (issue === void 0) {
89
- issue = {
90
- ruleId: finding.ruleId,
91
- help: finding.help,
92
- impact: finding.impact ?? null,
93
- successCriteria: finding.successCriteria,
94
- enClauses: finding.enClauses,
95
- helpUrl: finding.helpUrl,
96
- elements: [],
97
- pages: [],
98
- occurrences: 0
99
- };
100
- byRule.set(finding.ruleId, issue);
101
- }
102
- if (!issue.pages.includes(audit.relativePath)) issue.pages.push(audit.relativePath);
103
- for (const node of findingElements(finding)) {
104
- issue.occurrences += 1;
105
- const fingerprint = elementFingerprint(finding.ruleId, node.selector, node.html);
106
- const existing = issue.elements.find((element) => element.fingerprint === fingerprint);
107
- if (existing) {
108
- if (!existing.pages.includes(audit.relativePath)) existing.pages.push(audit.relativePath);
109
- continue;
110
- }
111
- issue.elements.push({
112
- fingerprint,
113
- selector: node.selector,
114
- html: node.html,
115
- pages: [audit.relativePath]
116
- });
117
- }
118
- }
119
- const issues = [...byRule.values()];
120
- for (const issue of issues) {
121
- issue.pages.sort();
122
- for (const element of issue.elements) element.pages.sort();
123
- issue.elements.sort(byReachThenSelector);
124
- }
125
- issues.sort(bySeverityThenReach);
126
- return issues;
127
- }
128
- /**
129
- * What the grouped issues add up to: distinct elements, and the violations they
130
- * account for. Both reports open their issues section with these two numbers,
131
- * and say something different when they are equal.
132
- */
133
- function issueTotals(issues) {
134
- let elements = 0;
135
- let occurrences = 0;
136
- for (const issue of issues) {
137
- elements += issue.elements.length;
138
- occurrences += issue.occurrences;
139
- }
140
- return {
141
- elements,
142
- occurrences
143
- };
144
- }
145
- /**
146
- * Unevaluated rules folded across the site, sorted by rule id.
147
- *
148
- * Both reports list these once at the end rather than under every page: on a
149
- * large site the same handful recurs on each one, and a wall of "not evaluated"
150
- * would bury the findings that are real.
151
- */
152
- function blindRules(audits) {
153
- const byRule = /* @__PURE__ */ new Map();
154
- for (const audit of audits) for (const finding of audit.incomplete) {
155
- if (finding.reason !== "engine-limitation") continue;
156
- const entry = byRule.get(finding.ruleId);
157
- if (entry) entry.pages += 1;
158
- else byRule.set(finding.ruleId, {
159
- ruleId: finding.ruleId,
160
- pages: 1,
161
- finding
162
- });
163
- }
164
- return [...byRule.values()].sort((a, b) => a.ruleId.localeCompare(b.ruleId));
165
- }
166
- /**
167
- * What one page's result actually rests on, as phrases both reports print.
168
- *
169
- * The counts stay separate on purpose. Only `passed` is evidence that a
170
- * criterion was met here; `not applicable` means the rule found nothing to
171
- * check, and adding the two together would turn an empty page into a
172
- * near-perfect score.
173
- */
174
- function coverageParts(audit) {
175
- const blind = audit.incomplete.filter((finding) => finding.reason === "engine-limitation").length;
176
- const review = audit.incomplete.length - blind;
177
- const parts = [`${audit.passes.length} passed`, `${audit.inapplicable.length} not applicable`];
178
- if (review > 0) parts.push(`${review} to review`);
179
- if (blind > 0) parts.push(`${blind} not evaluated`);
180
- return parts;
181
- }
182
- /** Widest reach first, then by selector so two runs agree. */
183
- function byReachThenSelector(a, b) {
184
- return b.pages.length - a.pages.length || a.selector.localeCompare(b.selector);
185
- }
186
- /** Worst first, then widest reach, then by rule id. */
187
- function bySeverityThenReach(a, b) {
188
- return impactRank(a.impact) - impactRank(b.impact) || b.pages.length - a.pages.length || a.ruleId.localeCompare(b.ruleId);
189
- }
190
- //#endregion
191
- //#region src/audit/remediation.ts
1
+ // src/audit/remediation.ts
192
2
  /**
193
3
  * Swap or add an attribute on the opening tag of the failing element.
194
4
  *
@@ -365,5 +175,4 @@ function remediationFor(ruleId, framework) {
365
175
  ...specific
366
176
  };
367
177
  }
368
- //#endregion
369
- export { isShared as a, missedParts as c, runCompleteness as d, groupIssues as i, redirectPart as l, blindRules as n, issueTotals as o, coverageParts as r, discoveryLabel as s, remediationFor as t, reusedPart as u };
178
+ export { remediationFor as t };