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.
- package/README.md +182 -135
- package/dist/astro/index.d.ts +1 -3
- package/dist/astro/index.js +2 -3
- package/dist/audit/runners/worker.js +2 -3
- package/dist/{audit-DRjAY2iY.js → audit-DbqNIrt6.js} +85 -219
- package/dist/audit-rUhqnm3o.js +1 -0
- package/dist/{baseline-BpE7DbDq.js → baseline-CKElWbx4.js} +18 -8
- package/dist/baseline-DU0EPiTq.js +1 -0
- package/dist/baseline-DYOejLFO.js +1 -0
- package/dist/baseline-DvdsFTQy.js +126 -0
- package/dist/{cache-D4dOIuOi.js → cache-DIV4G0TI.js} +24 -5
- package/dist/{checklist-DDd9jewi.js → checklist-CA0Ri71Z.js} +8 -9
- package/dist/cli/index.js +115 -158
- package/dist/{collect-Cu1q9NTB.js → collect-CjucwTEF.js} +16 -8
- package/dist/{command-3r4fht5f.js → command-C8ZFvcc1.js} +33 -10
- package/dist/completeness-Cg-XIKWN.js +1 -0
- package/dist/completeness-Dzyvgr4Z.js +72 -0
- package/dist/component-CgbeRgJa.js +1 -0
- package/dist/{component-ChisoFyY.js → component-ZLd8DA_a.js} +3 -4
- package/dist/countries-B_PE6r5R.js +180 -0
- package/dist/countries-CCqog6dy.js +28 -0
- package/dist/coverage-B9_6yv_8.js +2 -0
- package/dist/{coverage-cb5kPp48.js → coverage-C1Z6t9Ct.js} +5 -7
- package/dist/{crawl-BHkJmUkA.js → crawl-CkHJJV4w.js} +135 -25
- package/dist/{criteria-CnPJKGeb.js → criteria-CacF0HP1.js} +1 -2
- package/dist/{load-BaWMa-G_.js → define-BdTPIfqE.js} +46 -99
- package/dist/detect-DnFHXpWh.js +49 -0
- package/dist/detect-oLDadgee.js +160 -0
- package/dist/doctor-q8IebwAb.js +248 -0
- package/dist/eleventy/index.d.ts +1 -3
- package/dist/eleventy/index.js +2 -3
- package/dist/entry-kf94P140.js +173 -0
- package/dist/{fingerprint-BjYV_0F7.js → fingerprint-CcoQ1WxQ.js} +1 -2
- package/dist/{frameworks-B4ClIJgE.js → frameworks-BboC8eNk.js} +234 -28
- package/dist/frameworks-Y-n3NUuG.js +1 -0
- package/dist/{fs-BmPtmFke.js → fs-tPD5r0wY.js} +1 -2
- package/dist/hosts-B48qR6Vt.js +19 -0
- package/dist/{html-BIxxF3FC.js → html-Bjq3Iw3g.js} +56 -14
- package/dist/{impact-luGCnN8F.js → impact-BGlJ6j0Y.js} +1 -2
- package/dist/{impact-EEB9ZXmC.d.ts → impact-CZjUloYC.d.ts} +0 -2
- package/dist/index.d.ts +50 -26
- package/dist/index.js +3 -2
- package/dist/init-3Ti3ao5Z.js +232 -0
- package/dist/issues-WLlepU95.js +120 -0
- package/dist/{jsdom-CsW_xVcA.js → jsdom-C4pLIMyP.js} +2 -3
- package/dist/jsdom-Zle--VQ1.js +2 -0
- package/dist/{json-Bus6YhxB.js → json-B_k4CDmR.js} +5 -6
- package/dist/json-IL1JxlTL.js +1 -0
- package/dist/load-C3eFEdoH.js +98 -0
- package/dist/load-oQQJPNlV.js +1 -0
- package/dist/markdown-D-QpPYsz.js +138 -0
- package/dist/next-8zDgH0nP.js +119 -0
- package/dist/nuxt/index.d.ts +1 -3
- package/dist/nuxt/index.js +2 -3
- package/dist/pages-CCP1WfYe.js +363 -0
- package/dist/{playwright-ukCr_5o3.js → playwright-ky4b_HME.js} +98 -16
- package/dist/{pool-B4tEUa2S.js → pool-B3XKdk57.js} +4 -5
- package/dist/project-B21NT_aX.js +502 -0
- package/dist/project-Dht13sb1.js +1 -0
- package/dist/{remediation-C0klJblu.js → remediation-BkE7q7dT.js} +2 -176
- package/dist/{render-C1sUZZI_.js → render-ky8cm4QF.js} +50 -24
- package/dist/result-DhoT4g0P.js +1 -0
- package/dist/{result-B7_zVxAX.js → result-g8dGsrcv.js} +1 -2
- package/dist/{review-CdMK2GpQ.js → review-BGjTBFvd.js} +11 -4
- package/dist/review-iheEjp7_.js +1 -0
- package/dist/{routes-CmdRUuOs.js → routes-BpQeBDmM.js} +4 -5
- package/dist/{run-DrS0Komf.js → run-D7tc7IU2.js} +2 -3
- package/dist/{run-BK2blxMI.d.ts → run-VXnP4uLp.d.ts} +2 -6
- package/dist/{sarif-BNCE0PNT.js → sarif-v66-PjdE.js} +9 -9
- package/dist/{schema-DJSF4K05.js → schema-DfC-Ww1w.js} +1 -2
- package/dist/setup-BYlqHlo0.js +2 -0
- package/dist/setup-Cf82ONw0.js +353 -0
- package/dist/shell-BdQYTaBQ.js +89 -0
- package/dist/site-CxVyh8IO.js +71 -0
- package/dist/start-bdanSxZr.js +100 -0
- package/dist/statement/templates/be.de.md +148 -0
- package/dist/statement/templates/be.en.md +142 -0
- package/dist/statement/templates/be.fr.md +146 -0
- package/dist/statement/templates/be.nl.md +147 -0
- package/dist/statement/templates/cz.cs.md +138 -0
- package/dist/statement/templates/cz.en.md +140 -0
- package/dist/statement/templates/dk.da.md +142 -0
- package/dist/statement/templates/dk.en.md +142 -0
- package/dist/statement/templates/fi.en.md +139 -0
- package/dist/statement/templates/fi.fi.md +141 -0
- package/dist/statement/templates/ie.en.md +144 -0
- package/dist/statement/templates/pl.en.md +143 -0
- package/dist/statement/templates/pl.pl.md +144 -0
- package/dist/statement/templates/pt.en.md +143 -0
- package/dist/statement/templates/pt.pt.md +145 -0
- package/dist/statement/templates/se.en.md +148 -0
- package/dist/statement/templates/se.sv.md +150 -0
- package/dist/{text-BF1LHMiV.js → text-CISDPU49.js} +11 -3
- package/dist/{version-B3v4rNoG.js → version-C8aJm8YJ.js} +1 -2
- package/dist/vite/index.d.ts +1 -3
- package/dist/vite/index.js +2 -3
- package/dist/watch-CefxwMsZ.js +121 -0
- package/dist/webpack/index.d.ts +1 -3
- package/dist/webpack/index.js +2 -3
- package/dist/{worksheet-BIxMtbUd.js → worksheet-CcBo9G7s.js} +4 -5
- package/dist/workspaces-BBFXOyeV.js +85 -0
- package/package.json +16 -14
- package/dist/audit-Bwm1xBdJ.js +0 -2
- package/dist/baseline-rtnj3RHB.js +0 -2
- package/dist/component-DcCn3BJS.js +0 -2
- package/dist/coverage-n1X9CkiG.js +0 -3
- package/dist/frameworks-etFg_O8K.js +0 -2
- package/dist/init-DrFfzjvm.js +0 -119
- package/dist/jsdom-BUYuVJJm.js +0 -3
- package/dist/json-CrQmoTj6.js +0 -2
- package/dist/load-n62iXDq_.js +0 -2
- package/dist/project-CzOnkLH6.js +0 -274
- package/dist/project-MFrXcw1M.js +0 -2
- package/dist/result-CRmjjoAA.js +0 -2
- package/dist/review-DIbOTmOM.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,177 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
* What was missed, as phrases both reports print.
|
|
36
|
-
*
|
|
37
|
-
* Separate clauses rather than one total, for the same reason the coverage
|
|
38
|
-
* parts are: a page that could not be fetched and a page that could not be
|
|
39
|
-
* parsed are different problems with different fixes, and summing them would
|
|
40
|
-
* name neither.
|
|
41
|
-
*/
|
|
42
|
-
function missedParts(completeness) {
|
|
43
|
-
const parts = [];
|
|
44
|
-
if (completeness.unreachable.length > 0) parts.push(`${completeness.unreachable.length} could not be reached`);
|
|
45
|
-
if (completeness.errored > 0) parts.push(`${completeness.errored} could not be audited`);
|
|
46
|
-
if (completeness.truncated) parts.push("the run stopped at its page limit");
|
|
47
|
-
return parts;
|
|
48
|
-
}
|
|
49
|
-
/** How the pages were found, in words, for the run details both reports show. */
|
|
50
|
-
function discoveryLabel(discovery) {
|
|
51
|
-
switch (discovery) {
|
|
52
|
-
case "directory": return "files in the build directory";
|
|
53
|
-
case "sitemap": return "sitemap.xml and links";
|
|
54
|
-
case "links": return "links from the entry page";
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** Whether this element looks like one component rendered on many pages. */
|
|
58
|
-
function isShared(element) {
|
|
59
|
-
return element.pages.length >= 3;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Fold a run's violations into one entry per rule, and one per element within it.
|
|
63
|
-
*
|
|
64
|
-
* Accepted violations are not included: a baseline moves them out of what fails
|
|
65
|
-
* the build, and this is a view of what fails.
|
|
66
|
-
*/
|
|
67
|
-
function groupIssues(audits) {
|
|
68
|
-
const byRule = /* @__PURE__ */ new Map();
|
|
69
|
-
for (const audit of audits) for (const finding of audit.violations) {
|
|
70
|
-
let issue = byRule.get(finding.ruleId);
|
|
71
|
-
if (issue === void 0) {
|
|
72
|
-
issue = {
|
|
73
|
-
ruleId: finding.ruleId,
|
|
74
|
-
help: finding.help,
|
|
75
|
-
impact: finding.impact ?? null,
|
|
76
|
-
successCriteria: finding.successCriteria,
|
|
77
|
-
enClauses: finding.enClauses,
|
|
78
|
-
helpUrl: finding.helpUrl,
|
|
79
|
-
elements: [],
|
|
80
|
-
pages: [],
|
|
81
|
-
occurrences: 0
|
|
82
|
-
};
|
|
83
|
-
byRule.set(finding.ruleId, issue);
|
|
84
|
-
}
|
|
85
|
-
if (!issue.pages.includes(audit.relativePath)) issue.pages.push(audit.relativePath);
|
|
86
|
-
for (const node of findingElements(finding)) {
|
|
87
|
-
issue.occurrences += 1;
|
|
88
|
-
const fingerprint = elementFingerprint(finding.ruleId, node.selector, node.html);
|
|
89
|
-
const existing = issue.elements.find((element) => element.fingerprint === fingerprint);
|
|
90
|
-
if (existing) {
|
|
91
|
-
if (!existing.pages.includes(audit.relativePath)) existing.pages.push(audit.relativePath);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
issue.elements.push({
|
|
95
|
-
fingerprint,
|
|
96
|
-
selector: node.selector,
|
|
97
|
-
html: node.html,
|
|
98
|
-
pages: [audit.relativePath]
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const issues = [...byRule.values()];
|
|
103
|
-
for (const issue of issues) {
|
|
104
|
-
issue.pages.sort();
|
|
105
|
-
for (const element of issue.elements) element.pages.sort();
|
|
106
|
-
issue.elements.sort(byReachThenSelector);
|
|
107
|
-
}
|
|
108
|
-
issues.sort(bySeverityThenReach);
|
|
109
|
-
return issues;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* What the grouped issues add up to: distinct elements, and the violations they
|
|
113
|
-
* account for. Both reports open their issues section with these two numbers,
|
|
114
|
-
* and say something different when they are equal.
|
|
115
|
-
*/
|
|
116
|
-
function issueTotals(issues) {
|
|
117
|
-
let elements = 0;
|
|
118
|
-
let occurrences = 0;
|
|
119
|
-
for (const issue of issues) {
|
|
120
|
-
elements += issue.elements.length;
|
|
121
|
-
occurrences += issue.occurrences;
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
elements,
|
|
125
|
-
occurrences
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Unevaluated rules folded across the site, sorted by rule id.
|
|
130
|
-
*
|
|
131
|
-
* Both reports list these once at the end rather than under every page: on a
|
|
132
|
-
* large site the same handful recurs on each one, and a wall of "not evaluated"
|
|
133
|
-
* would bury the findings that are real.
|
|
134
|
-
*/
|
|
135
|
-
function blindRules(audits) {
|
|
136
|
-
const byRule = /* @__PURE__ */ new Map();
|
|
137
|
-
for (const audit of audits) for (const finding of audit.incomplete) {
|
|
138
|
-
if (finding.reason !== "engine-limitation") continue;
|
|
139
|
-
const entry = byRule.get(finding.ruleId);
|
|
140
|
-
if (entry) entry.pages += 1;
|
|
141
|
-
else byRule.set(finding.ruleId, {
|
|
142
|
-
ruleId: finding.ruleId,
|
|
143
|
-
pages: 1,
|
|
144
|
-
finding
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return [...byRule.values()].sort((a, b) => a.ruleId.localeCompare(b.ruleId));
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* What one page's result actually rests on, as phrases both reports print.
|
|
151
|
-
*
|
|
152
|
-
* The counts stay separate on purpose. Only `passed` is evidence that a
|
|
153
|
-
* criterion was met here; `not applicable` means the rule found nothing to
|
|
154
|
-
* check, and adding the two together would turn an empty page into a
|
|
155
|
-
* near-perfect score.
|
|
156
|
-
*/
|
|
157
|
-
function coverageParts(audit) {
|
|
158
|
-
const blind = audit.incomplete.filter((finding) => finding.reason === "engine-limitation").length;
|
|
159
|
-
const review = audit.incomplete.length - blind;
|
|
160
|
-
const parts = [`${audit.passes.length} passed`, `${audit.inapplicable.length} not applicable`];
|
|
161
|
-
if (review > 0) parts.push(`${review} to review`);
|
|
162
|
-
if (blind > 0) parts.push(`${blind} not evaluated`);
|
|
163
|
-
return parts;
|
|
164
|
-
}
|
|
165
|
-
/** Widest reach first, then by selector so two runs agree. */
|
|
166
|
-
function byReachThenSelector(a, b) {
|
|
167
|
-
return b.pages.length - a.pages.length || a.selector.localeCompare(b.selector);
|
|
168
|
-
}
|
|
169
|
-
/** Worst first, then widest reach, then by rule id. */
|
|
170
|
-
function bySeverityThenReach(a, b) {
|
|
171
|
-
return impactRank(a.impact) - impactRank(b.impact) || b.pages.length - a.pages.length || a.ruleId.localeCompare(b.ruleId);
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/audit/remediation.ts
|
|
1
|
+
// src/audit/remediation.ts
|
|
175
2
|
/**
|
|
176
3
|
* Swap or add an attribute on the opening tag of the failing element.
|
|
177
4
|
*
|
|
@@ -348,5 +175,4 @@ function remediationFor(ruleId, framework) {
|
|
|
348
175
|
...specific
|
|
349
176
|
};
|
|
350
177
|
}
|
|
351
|
-
|
|
352
|
-
export { isShared as a, missedParts as c, groupIssues as i, reusedPart as l, blindRules as n, issueTotals as o, coverageParts as r, discoveryLabel as s, remediationFor as t, runCompleteness as u };
|
|
178
|
+
export { remediationFor as t };
|