@v-office/site-checks 0.2.4 → 0.3.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 +76 -58
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +9 -0
- package/dist/{report-D8jkvHtK.mjs → cli-Cj1FkuvI.mjs} +972 -555
- package/dist/index.d.mts +324 -8
- package/dist/index.mjs +2 -2
- package/instructions/CHANGELOG.md +1 -0
- package/instructions/MIGRATION.md +1 -0
- package/instructions/versions/0.3.0/CHANGELOG.md +39 -0
- package/instructions/versions/0.3.0/MIGRATION.md +43 -0
- package/package.json +5 -5
- package/dist/astro.d.mts +0 -37
- package/dist/astro.mjs +0 -56
- package/dist/dist-checks.d.mts +0 -21
- package/dist/dist-checks.mjs +0 -410
- package/dist/options-CANJso9Q.d.mts +0 -95
- package/dist/runner-CK4iXk8Z.d.mts +0 -169
package/dist/dist-checks.mjs
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { _ as referencedUrls, c as MAX_PATH_CHARS, g as loadDistContext, h as isSameSiteReference, l as blockingResults, o as MAX_FINDINGS_PER_CHECK, r as summarizeBlocking, s as MAX_MESSAGE_CHARS, t as SITE_CHECKS_FILE, u as runChecks, v as resolveReference, y as xmlText } from "./report-D8jkvHtK.mjs";
|
|
2
|
-
//#region src/distChecks/insecureResources.ts
|
|
3
|
-
/** `<link>` relations the browser fetches as a subresource; canonical,
|
|
4
|
-
* alternate, preconnect and friends are hints or metadata, not loads. */
|
|
5
|
-
const RESOURCE_RELS = /* @__PURE__ */ new Set([
|
|
6
|
-
"stylesheet",
|
|
7
|
-
"preload",
|
|
8
|
-
"modulepreload",
|
|
9
|
-
"prefetch",
|
|
10
|
-
"icon",
|
|
11
|
-
"apple-touch-icon",
|
|
12
|
-
"manifest"
|
|
13
|
-
]);
|
|
14
|
-
const isResource = (el) => {
|
|
15
|
-
if (el.tagName === "A" || el.tagName === "AREA" || el.tagName === "BASE") return false;
|
|
16
|
-
if (el.tagName !== "LINK") return true;
|
|
17
|
-
return (el.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).some((rel) => RESOURCE_RELS.has(rel));
|
|
18
|
-
};
|
|
19
|
-
/** A resource loaded over plain http on an https site is blocked or downgraded
|
|
20
|
-
* by the browser (mixed content); the page renders without it. Links a
|
|
21
|
-
* visitor clicks (`<a href>`) are not resources and are left alone. */
|
|
22
|
-
const insecureResources = {
|
|
23
|
-
id: "insecure-resources",
|
|
24
|
-
title: "No script, style, image or media is loaded over http://",
|
|
25
|
-
severity: "warning",
|
|
26
|
-
begin() {
|
|
27
|
-
const findings = [];
|
|
28
|
-
const visit = (page) => {
|
|
29
|
-
const seen = /* @__PURE__ */ new Set();
|
|
30
|
-
for (const el of page.document.querySelectorAll("[href], [src], [srcset], [poster]")) {
|
|
31
|
-
if (!isResource(el)) continue;
|
|
32
|
-
for (const value of referencedUrls(el)) {
|
|
33
|
-
const v = value.trim();
|
|
34
|
-
if (!/^http:\/\//i.test(v) || seen.has(v)) continue;
|
|
35
|
-
seen.add(v);
|
|
36
|
-
findings.push({
|
|
37
|
-
message: `${el.tagName.toLowerCase()} loads ${v} over http://`,
|
|
38
|
-
path: page.path
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
visit,
|
|
45
|
-
finish: () => findings
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/distChecks/internalLinks.ts
|
|
51
|
-
/** A same-site reference (`href`, `src`, `srcset`, `poster`) that no file of
|
|
52
|
-
* the build serves — the 404 class, caught before a guest hits it. One finding
|
|
53
|
-
* per missing target, on the first page that references it and with the count
|
|
54
|
-
* of pages that do: a layout link to one missing file must not bury every other
|
|
55
|
-
* finding under a copy per page. On a single-page app only file-like paths
|
|
56
|
-
* (with an extension) are checked: its routes are handled by the app, not by
|
|
57
|
-
* files. */
|
|
58
|
-
const internalLinks = {
|
|
59
|
-
id: "internal-links",
|
|
60
|
-
title: "Every internal link and asset reference is served by the build",
|
|
61
|
-
severity: "warning",
|
|
62
|
-
begin(ctx) {
|
|
63
|
-
const missing = /* @__PURE__ */ new Map();
|
|
64
|
-
const visit = (page) => {
|
|
65
|
-
const seen = /* @__PURE__ */ new Set();
|
|
66
|
-
for (const el of page.document.querySelectorAll("[href], [src], [srcset], [poster]")) {
|
|
67
|
-
if (el.tagName === "BASE") continue;
|
|
68
|
-
for (const value of referencedUrls(el)) {
|
|
69
|
-
if (!isSameSiteReference(value, ctx.origin)) continue;
|
|
70
|
-
const target = resolveReference(page, value);
|
|
71
|
-
if (seen.has(target)) continue;
|
|
72
|
-
seen.add(target);
|
|
73
|
-
if (!ctx.isAstro && !/\.[a-z0-9]+$/i.test(target)) continue;
|
|
74
|
-
if (ctx.serves(target)) continue;
|
|
75
|
-
const known = missing.get(target);
|
|
76
|
-
if (known) known.pages++;
|
|
77
|
-
else missing.set(target, {
|
|
78
|
-
tag: el.tagName.toLowerCase(),
|
|
79
|
-
path: page.path,
|
|
80
|
-
pages: 1
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const finish = () => [...missing].map(([target, { tag, path, pages }]) => ({
|
|
86
|
-
message: `${tag} references ${target}, which no file in the build serves${pages > 1 ? ` (from ${pages} pages)` : ""}`,
|
|
87
|
-
path
|
|
88
|
-
}));
|
|
89
|
-
return {
|
|
90
|
-
visit,
|
|
91
|
-
finish
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/distChecks/keyPages.ts
|
|
97
|
-
/** The pages every build must emit: the home page, and on an Astro site the
|
|
98
|
-
* 404 page the hosting serves for unknown paths. */
|
|
99
|
-
const keyPages = {
|
|
100
|
-
id: "key-pages",
|
|
101
|
-
title: "The home page and the 404 page are in the build",
|
|
102
|
-
severity: "warning",
|
|
103
|
-
begin(ctx) {
|
|
104
|
-
const findings = [];
|
|
105
|
-
if (!ctx.has("index.html")) findings.push({
|
|
106
|
-
message: "No index.html: the site has no home page",
|
|
107
|
-
path: "index.html"
|
|
108
|
-
});
|
|
109
|
-
if (ctx.isAstro && !ctx.has("404.html")) findings.push({
|
|
110
|
-
message: "No 404.html: unknown paths get the hosting's default error page",
|
|
111
|
-
path: "404.html"
|
|
112
|
-
});
|
|
113
|
-
return { finish: () => findings };
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/distChecks/legalPages.ts
|
|
118
|
-
/** German sites owe an Impressum (§ 5 DDG) and a privacy notice (Art. 13
|
|
119
|
-
* DSGVO) reachable from every page; English wordings count too. Matched on
|
|
120
|
-
* the link's target and its text, so a footer link named either way passes.
|
|
121
|
-
* The 404 page and redirect stubs are skipped. */
|
|
122
|
-
const LEGAL = [{
|
|
123
|
-
name: "Impressum / legal notice",
|
|
124
|
-
pattern: /impressum|imprint|legal[-_ ]?notice|colophon/i
|
|
125
|
-
}, {
|
|
126
|
-
name: "Datenschutz / privacy notice",
|
|
127
|
-
pattern: /datenschutz|privacy/i
|
|
128
|
-
}];
|
|
129
|
-
const legalPages = {
|
|
130
|
-
id: "legal-pages",
|
|
131
|
-
title: "Every page links to an Impressum and a privacy notice",
|
|
132
|
-
severity: "warning",
|
|
133
|
-
begin(ctx) {
|
|
134
|
-
if (!ctx.isAstro) return null;
|
|
135
|
-
const findings = [];
|
|
136
|
-
const visit = (page) => {
|
|
137
|
-
if (page.path === "404.html" || page.redirect) return;
|
|
138
|
-
const links = [...page.document.querySelectorAll("a[href]")].map((a) => `${a.getAttribute("href") ?? ""} ${a.textContent ?? ""}`);
|
|
139
|
-
for (const { name, pattern } of LEGAL) {
|
|
140
|
-
if (pattern.test(page.path)) continue;
|
|
141
|
-
if (!links.some((link) => pattern.test(link))) findings.push({
|
|
142
|
-
message: `No link to a ${name} on this page`,
|
|
143
|
-
path: page.path
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
return {
|
|
148
|
-
visit,
|
|
149
|
-
finish: () => findings
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region src/distChecks/notFoundBeacon.ts
|
|
155
|
-
const BEACON = /\/api\/404-log\b/;
|
|
156
|
-
/** The hosting serves 404.html for every unknown path, and AI Studio learns of
|
|
157
|
-
* the miss only when that page posts the URL to /api/404-log
|
|
158
|
-
* (docs/internal/operations/404-logging.md). Without the beacon the site's 404 list stays
|
|
159
|
-
* empty and no redirect is ever suggested. Astro bundles page scripts into
|
|
160
|
-
* files under _astro/, so the page's same-site scripts count as well. */
|
|
161
|
-
const notFoundBeacon = {
|
|
162
|
-
id: "not-found-beacon",
|
|
163
|
-
title: "The 404 page reports missing URLs to AI Studio",
|
|
164
|
-
severity: "warning",
|
|
165
|
-
begin(ctx) {
|
|
166
|
-
if (!ctx.isAstro || !ctx.has("404.html")) return null;
|
|
167
|
-
let beacon = false;
|
|
168
|
-
const visit = (page) => {
|
|
169
|
-
if (page.path !== "404.html") return;
|
|
170
|
-
beacon = [...page.document.querySelectorAll("script")].map((script) => {
|
|
171
|
-
const src = script.getAttribute("src");
|
|
172
|
-
if (!src) return script.textContent ?? "";
|
|
173
|
-
if (!isSameSiteReference(src, ctx.origin)) return "";
|
|
174
|
-
const file = resolveReference(page, src).replace(/^\//, "");
|
|
175
|
-
return ctx.has(file) ? ctx.read(file) : "";
|
|
176
|
-
}).some((code) => BEACON.test(code));
|
|
177
|
-
};
|
|
178
|
-
const finish = () => beacon ? [] : [{
|
|
179
|
-
message: "404.html does not call /api/404-log: missing URLs are never logged",
|
|
180
|
-
path: "404.html"
|
|
181
|
-
}];
|
|
182
|
-
return {
|
|
183
|
-
visit,
|
|
184
|
-
finish
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/distChecks/pageMetadata.ts
|
|
190
|
-
/** What every page needs in its head: a title, a description, the document
|
|
191
|
-
* language. Missing ones are the classic leftovers of a generated layout. A
|
|
192
|
-
* redirect stub is no page anyone reads and is skipped. */
|
|
193
|
-
const pageMetadata = {
|
|
194
|
-
id: "page-metadata",
|
|
195
|
-
title: "Every page has a title, a description and a language",
|
|
196
|
-
severity: "warning",
|
|
197
|
-
begin() {
|
|
198
|
-
const findings = [];
|
|
199
|
-
const visit = (page) => {
|
|
200
|
-
if (page.redirect) return;
|
|
201
|
-
const { document } = page;
|
|
202
|
-
if (!document.querySelector("title")?.textContent?.trim()) findings.push({
|
|
203
|
-
message: "No <title>",
|
|
204
|
-
path: page.path
|
|
205
|
-
});
|
|
206
|
-
if (!document.querySelector("meta[name=\"description\"]")?.getAttribute("content")?.trim()) findings.push({
|
|
207
|
-
message: "No <meta name=\"description\">",
|
|
208
|
-
path: page.path
|
|
209
|
-
});
|
|
210
|
-
if (!document.documentElement?.getAttribute("lang")?.trim()) findings.push({
|
|
211
|
-
message: "No lang attribute on <html>",
|
|
212
|
-
path: page.path
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
return {
|
|
216
|
-
visit,
|
|
217
|
-
finish: () => findings
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/distChecks/placeholderContent.ts
|
|
223
|
-
/** Text that should never reach a visitor: template filler, a value that was
|
|
224
|
-
* rendered instead of formatted, a template expression the build did not
|
|
225
|
-
* evaluate. And references to development hosts or example domains. */
|
|
226
|
-
const TEXT_PATTERNS = [
|
|
227
|
-
{
|
|
228
|
-
name: "lorem ipsum",
|
|
229
|
-
pattern: /lorem ipsum/i
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: "[object Object]",
|
|
233
|
-
pattern: /\[object Object\]/
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
name: "a bare 'undefined'",
|
|
237
|
-
pattern: /(?<![\w-])undefined(?![\w-])/
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
name: "a bare 'NaN'",
|
|
241
|
-
pattern: /(?<![\w-])NaN(?![\w-])/
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
name: "an unrendered template expression",
|
|
245
|
-
pattern: /\{\{[^}]*\}\}/
|
|
246
|
-
}
|
|
247
|
-
];
|
|
248
|
-
/** Development hosts and the RFC 2606 example domains, including their
|
|
249
|
-
* subdomains — but not a real host that merely ends in "example.com", such as
|
|
250
|
-
* counterexample.com (fixed 2026-09-24). */
|
|
251
|
-
const DEV_HOSTS = /^(https?:)?\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0|(?:[^/:?#]+\.)?example\.(com|org|net))(?=[/:?#]|$)/i;
|
|
252
|
-
const CONTEXT = 40;
|
|
253
|
-
const placeholderContent = {
|
|
254
|
-
id: "placeholder-content",
|
|
255
|
-
title: "No placeholder text or development hosts reach the visitor",
|
|
256
|
-
severity: "warning",
|
|
257
|
-
begin() {
|
|
258
|
-
const findings = [];
|
|
259
|
-
const visit = (page) => {
|
|
260
|
-
const text = page.visibleText();
|
|
261
|
-
for (const { name, pattern } of TEXT_PATTERNS) {
|
|
262
|
-
const match = pattern.exec(text);
|
|
263
|
-
if (!match) continue;
|
|
264
|
-
const start = Math.max(0, match.index - CONTEXT);
|
|
265
|
-
const snippet = text.slice(start, match.index + match[0].length + CONTEXT).trim();
|
|
266
|
-
findings.push({
|
|
267
|
-
message: `Visible text contains ${name}: "…${snippet}…"`,
|
|
268
|
-
path: page.path
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
const seen = /* @__PURE__ */ new Set();
|
|
272
|
-
for (const el of page.document.querySelectorAll("[href], [src], [srcset], [poster]")) for (const value of referencedUrls(el)) {
|
|
273
|
-
const v = value.trim();
|
|
274
|
-
if (!DEV_HOSTS.test(v) || seen.has(v)) continue;
|
|
275
|
-
seen.add(v);
|
|
276
|
-
findings.push({
|
|
277
|
-
message: `References a development or example host: ${v}`,
|
|
278
|
-
path: page.path
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
return {
|
|
283
|
-
visit,
|
|
284
|
-
finish: () => findings
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/distChecks/siteManifest.ts
|
|
290
|
-
const FILE = "site-manifest.json";
|
|
291
|
-
const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
292
|
-
const manifestFindings = (ctx) => {
|
|
293
|
-
if (!ctx.has(FILE)) return [{
|
|
294
|
-
message: "No site-manifest.json in the build: the site has not adopted @v-office/site-manifest and no rollout can reach it",
|
|
295
|
-
path: FILE
|
|
296
|
-
}];
|
|
297
|
-
let doc;
|
|
298
|
-
try {
|
|
299
|
-
doc = JSON.parse(ctx.read(FILE));
|
|
300
|
-
} catch {
|
|
301
|
-
return [{
|
|
302
|
-
message: "site-manifest.json is not valid JSON",
|
|
303
|
-
path: FILE
|
|
304
|
-
}];
|
|
305
|
-
}
|
|
306
|
-
if (!isRecord(doc)) return [{
|
|
307
|
-
message: "site-manifest.json is not a JSON object",
|
|
308
|
-
path: FILE
|
|
309
|
-
}];
|
|
310
|
-
if (doc.manifestVersion !== 1) return [{
|
|
311
|
-
message: `manifestVersion ${JSON.stringify(doc.manifestVersion)} is not one of the versions the controller reads (1); the build is reported without a manifest`,
|
|
312
|
-
path: FILE
|
|
313
|
-
}];
|
|
314
|
-
if (!isRecord(doc.packages) || Object.keys(doc.packages).length === 0) return [{
|
|
315
|
-
message: "packages is empty: no installed version was recorded",
|
|
316
|
-
path: FILE
|
|
317
|
-
}];
|
|
318
|
-
return [];
|
|
319
|
-
};
|
|
320
|
-
/** A site without a readable manifest is outside every rollout: the controller
|
|
321
|
-
* reads manifestVersion 1 and skips everything else. */
|
|
322
|
-
const siteManifest = {
|
|
323
|
-
id: "site-manifest",
|
|
324
|
-
title: "The build wrote a readable site-manifest.json",
|
|
325
|
-
severity: "warning",
|
|
326
|
-
begin: (ctx) => ({ finish: () => manifestFindings(ctx) })
|
|
327
|
-
};
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/distChecks/sitemap.ts
|
|
330
|
-
const pathOf = (url) => {
|
|
331
|
-
try {
|
|
332
|
-
return new URL(url.trim(), "http://site.invalid").pathname;
|
|
333
|
-
} catch {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
//#endregion
|
|
338
|
-
//#region src/distChecks/index.ts
|
|
339
|
-
/**
|
|
340
|
-
* The dist checks: the platform's checks over a build's `dist/`, run by the build worker on every
|
|
341
|
-
* build of every website at the worker's pinned version of this package — public sites, the guest
|
|
342
|
-
* and owner apps, and sites that never installed it. The site checks (`checks/`) are the other
|
|
343
|
-
* family: they run inside a site's own `astro build`, at the site's pinned version. What decides
|
|
344
|
-
* the family is who runs a check, not what it reads: several site checks read `dist/` too. A check
|
|
345
|
-
* every website must pass, whether or not it adopted this package, belongs here.
|
|
346
|
-
* `@v-office/site-checks/dist-checks` is this file; the integration never runs these.
|
|
347
|
-
* See docs/website-platform/process/10-dist-checks.md.
|
|
348
|
-
*/
|
|
349
|
-
const distChecks = [
|
|
350
|
-
siteManifest,
|
|
351
|
-
keyPages,
|
|
352
|
-
notFoundBeacon,
|
|
353
|
-
internalLinks,
|
|
354
|
-
legalPages,
|
|
355
|
-
pageMetadata,
|
|
356
|
-
placeholderContent,
|
|
357
|
-
insecureResources,
|
|
358
|
-
{
|
|
359
|
-
id: "sitemap",
|
|
360
|
-
title: "robots.txt and the sitemap point at files of the build",
|
|
361
|
-
severity: "warning",
|
|
362
|
-
begin(ctx) {
|
|
363
|
-
if (!ctx.isAstro) return null;
|
|
364
|
-
const findings = [];
|
|
365
|
-
const sitemaps = new Set(ctx.files.filter((f) => /^sitemap[^/]*\.xml$/i.test(f)));
|
|
366
|
-
if (!ctx.has("robots.txt")) findings.push({
|
|
367
|
-
message: "No robots.txt",
|
|
368
|
-
path: "robots.txt"
|
|
369
|
-
});
|
|
370
|
-
else for (const line of ctx.read("robots.txt").split(/\r?\n/)) {
|
|
371
|
-
const match = /^\s*sitemap\s*:\s*(\S+)/i.exec(line);
|
|
372
|
-
if (!match) continue;
|
|
373
|
-
const file = pathOf(match[1])?.replace(/^\/+/, "");
|
|
374
|
-
if (file && !ctx.has(file)) findings.push({
|
|
375
|
-
message: `robots.txt names sitemap ${match[1]}, which is not in the build`,
|
|
376
|
-
path: "robots.txt"
|
|
377
|
-
});
|
|
378
|
-
else if (file) sitemaps.add(file);
|
|
379
|
-
}
|
|
380
|
-
if (sitemaps.size === 0) findings.push({
|
|
381
|
-
message: "No sitemap in the build",
|
|
382
|
-
path: "sitemap-index.xml"
|
|
383
|
-
});
|
|
384
|
-
for (const file of sitemaps) {
|
|
385
|
-
if (!ctx.has(file)) continue;
|
|
386
|
-
for (const match of ctx.read(file).matchAll(/<loc>\s*([^<]+?)\s*<\/loc>/g)) {
|
|
387
|
-
const target = pathOf(xmlText(match[1]));
|
|
388
|
-
if (target === null) continue;
|
|
389
|
-
const asFile = target.replace(/^\/+/, "");
|
|
390
|
-
if (/\.xml$/i.test(asFile)) {
|
|
391
|
-
if (ctx.has(asFile)) sitemaps.add(asFile);
|
|
392
|
-
else findings.push({
|
|
393
|
-
message: `Sitemap index lists ${target}, which is not in the build`,
|
|
394
|
-
path: file
|
|
395
|
-
});
|
|
396
|
-
} else if (!ctx.serves(target)) findings.push({
|
|
397
|
-
message: `Sitemap lists ${target}, which no file in the build serves`,
|
|
398
|
-
path: file
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return { finish: () => findings };
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
];
|
|
406
|
-
/** Runs every dist check over `distDir`. Never throws: a check that throws is a `failed` result,
|
|
407
|
-
* an unreadable `distDir` fails every check the same way. */
|
|
408
|
-
const runDistChecks = (distDir, opts, list = distChecks) => runChecks(() => loadDistContext(distDir, opts), list);
|
|
409
|
-
//#endregion
|
|
410
|
-
export { MAX_FINDINGS_PER_CHECK, MAX_MESSAGE_CHARS, MAX_PATH_CHARS, SITE_CHECKS_FILE, blockingResults, distChecks, runDistChecks, summarizeBlocking };
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
//#region src/options.d.ts
|
|
2
|
-
/** A wording a recorded customer correction bans from the rendered pages. */
|
|
3
|
-
interface BannedCopy {
|
|
4
|
-
/** A regular expression (source), matched against each page's visible text, whitespace
|
|
5
|
-
* collapsed, so a line break cannot hide a match. */
|
|
6
|
-
pattern: string;
|
|
7
|
-
/** The correction behind it, shown with every finding. */
|
|
8
|
-
why: string;
|
|
9
|
-
}
|
|
10
|
-
/** Markup that stays inert until an initializer in `src/scripts/*.ts` binds it. */
|
|
11
|
-
interface WiringHook {
|
|
12
|
-
/** The exported initializer, e.g. `initImageCarousels`. */
|
|
13
|
-
init: string;
|
|
14
|
-
/** The text (a class, a data attribute) that identifies the markup it binds. */
|
|
15
|
-
marker: string;
|
|
16
|
-
/** "section": every component carrying the marker calls the initializer itself (a leaf that
|
|
17
|
-
* ships the markup for its parent opts out with `@bound-by-parent <init>`). "global": one call
|
|
18
|
-
* anywhere in `src/` binds every carrier. */
|
|
19
|
-
scope: "section" | "global";
|
|
20
|
-
/** Optional: a project-relative file that must still carry the marker in code; without it a
|
|
21
|
-
* renamed marker leaves nothing to bind and the call can go unnoticed. */
|
|
22
|
-
file?: string;
|
|
23
|
-
}
|
|
24
|
-
/** A text that must stay in a file: behaviour a site keeps apart from what it was built from. */
|
|
25
|
-
interface WiringKept {
|
|
26
|
-
/** Project-relative path. */
|
|
27
|
-
file: string;
|
|
28
|
-
/** The exact text, in code (a copy left in a comment does not count). */
|
|
29
|
-
contains: string;
|
|
30
|
-
/** Why it must stay, shown when it is gone. */
|
|
31
|
-
guard: string;
|
|
32
|
-
}
|
|
33
|
-
type WiringEntry = WiringHook | WiringKept;
|
|
34
|
-
/** What a site configures: data for the checks, never their severity. The same keys are read from
|
|
35
|
-
* `site-checks.config.json` at the project root and accepted by `siteChecks({ … })`; an option
|
|
36
|
-
* given to the integration wins over the file's key. */
|
|
37
|
-
interface SiteChecksOptions {
|
|
38
|
-
/** Terms that must not ship: the template ("donor") site's brand, people, places, phone, email,
|
|
39
|
-
* domain, asset names. Matched case-insensitively, whitespace collapsed. Empty: the check skips. */
|
|
40
|
-
donorTerms?: string[];
|
|
41
|
-
/** Packages imported from `src/` that may stay out of `vite.optimizeDeps.include`: a package
|
|
42
|
-
* only the server-side code imports, or one Vite handles itself. Exact specifier or package name. */
|
|
43
|
-
optimizeDepsIgnore?: string[];
|
|
44
|
-
/** Raster images under `public/` that ship without an AVIF sibling on purpose, as paths
|
|
45
|
-
* relative to the project root (`public/brand/logo.png`). */
|
|
46
|
-
imageIgnore?: string[];
|
|
47
|
-
/** Regular expressions (sources, case-insensitive) matching a feed photo URL that is still
|
|
48
|
-
* requested as JPEG or PNG. Defaults to the vOffice image hosts. */
|
|
49
|
-
feedImagePatterns?: string[];
|
|
50
|
-
/** URL paths of pages that list rentals, in addition to the pages the check recognizes by their
|
|
51
|
-
* markup (`/angebote`). */
|
|
52
|
-
listingPages?: string[];
|
|
53
|
-
/** Listing pages whose list stays client-only, with the reason: their list is the rentals free
|
|
54
|
-
* in a window, and a build-time list would show booked-out flats. */
|
|
55
|
-
listingClientOnly?: {
|
|
56
|
-
path: string;
|
|
57
|
-
reason: string;
|
|
58
|
-
}[];
|
|
59
|
-
/** Hosts a `<script src>` or `<iframe src>` may load before consent: the site's own CDN, a
|
|
60
|
-
* consent-free host. The site's own host (`site` in the Astro config) is always allowed. */
|
|
61
|
-
consentAllowedHosts?: string[];
|
|
62
|
-
/** Wordings recorded customer corrections ban. Empty: `banned-copy` skips. */
|
|
63
|
-
bannedCopy?: BannedCopy[];
|
|
64
|
-
/** URL paths (and everything below them) the copy checks do not read: legal pages ported
|
|
65
|
-
* verbatim. `/impressum` also covers `/de/impressum`. */
|
|
66
|
-
copyExcludePaths?: string[];
|
|
67
|
-
/** URL paths only `banned-copy` skips: pages whose prose is the site's but whose answers port
|
|
68
|
-
* verbatim (an FAQ). */
|
|
69
|
-
bannedCopyExcludePaths?: string[];
|
|
70
|
-
/** Sentences `duplicate-sentences` accepts twice on one page. */
|
|
71
|
-
allowDuplicateSentences?: string[];
|
|
72
|
-
/** Files or directories (project-relative) holding the text a `<blockquote>` may quote: content
|
|
73
|
-
* captures, the feed's review texts written by the build. Empty: `quote-sources` skips. */
|
|
74
|
-
quoteSources?: string[];
|
|
75
|
-
/** `rental-facts` disagreements the customer confirmed must ship as they are, one per line in
|
|
76
|
-
* the form the finding prints: `<slug> <kind> prose=<n> feed=<n>`. Either side changing makes
|
|
77
|
-
* it a finding again. */
|
|
78
|
-
factCheckAccepted?: string[];
|
|
79
|
-
/** The markup hooks and kept texts `wiring` holds (the former `scripts/wiring.json` `hooks`).
|
|
80
|
-
* Empty: the check skips. */
|
|
81
|
-
wiring?: WiringEntry[];
|
|
82
|
-
/** Rules of `page-structure` this site declines: `one-h1`, `heading-skip`, `landmark-main`,
|
|
83
|
-
* `img-alt`, `control-label`, `table-headers`, `heading-ratio`. */
|
|
84
|
-
structureIgnore?: string[];
|
|
85
|
-
/** v9 only: the Website SDK options the site's `website-sdk hub-filters check` needs
|
|
86
|
-
* (`rentalScope`, `customAttributeFilterDefinitions`), as the site passes them to the SDK. */
|
|
87
|
-
hubFilterOptions?: Record<string, unknown>;
|
|
88
|
-
}
|
|
89
|
-
type ResolvedOptions = Required<SiteChecksOptions>;
|
|
90
|
-
declare const CONFIG_FILE = "site-checks.config.json";
|
|
91
|
-
/** The file's keys with the integration's options on top. A file that cannot be parsed throws:
|
|
92
|
-
* a broken config must not silently disable a check. */
|
|
93
|
-
declare function loadOptions(root: string, overrides?: SiteChecksOptions): ResolvedOptions;
|
|
94
|
-
//#endregion
|
|
95
|
-
export { WiringEntry as a, loadOptions as c, SiteChecksOptions as i, CONFIG_FILE as n, WiringHook as o, ResolvedOptions as r, WiringKept as s, BannedCopy as t };
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { i as SiteChecksOptions, r as ResolvedOptions } from "./options-CANJso9Q.mjs";
|
|
2
|
-
import { parseHTML } from "linkedom";
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
/** Two families of checks share these types, one runner and one report shape:
|
|
5
|
-
* - the site checks (`checks/`) over a site's source and built output, run inside the site's own
|
|
6
|
-
* `astro build` and written to `dist/site-checks.json`;
|
|
7
|
-
* - the dist checks (`distChecks/`) over the built output only, run by the build worker on every
|
|
8
|
-
* build of every website, the guest and owner apps included.
|
|
9
|
-
* The worker merges both into one report, which the controller validates and stores alike. Only a
|
|
10
|
-
* check whose severity is `error` refuses the build, the way a failed `astro check` does. */
|
|
11
|
-
type Severity = "warning" | "error";
|
|
12
|
-
/** `skipped`: the check does not apply to this site (no config, no built pages). `failed`: the
|
|
13
|
-
* check itself threw — reported, never blocking. */
|
|
14
|
-
type CheckStatus = "ok" | Severity | "skipped" | "failed";
|
|
15
|
-
/** One thing a check found: what, and on which file when known. Paths of the built output are
|
|
16
|
-
* relative to `dist/`, source paths relative to the project root. */
|
|
17
|
-
type Finding = {
|
|
18
|
-
message: string;
|
|
19
|
-
path?: string;
|
|
20
|
-
};
|
|
21
|
-
type CheckResult = {
|
|
22
|
-
id: string;
|
|
23
|
-
status: CheckStatus;
|
|
24
|
-
/** Capped by the runner; `omitted` counts what the cap cut. */
|
|
25
|
-
findings: Finding[];
|
|
26
|
-
omitted: number;
|
|
27
|
-
};
|
|
28
|
-
type CheckReport = {
|
|
29
|
-
ranAt: string;
|
|
30
|
-
durationMs: number;
|
|
31
|
-
results: CheckResult[];
|
|
32
|
-
};
|
|
33
|
-
type Document = ReturnType<typeof parseHTML>["document"];
|
|
34
|
-
/** One HTML file of the build, parsed once, shown to every check, then let go: the runner holds
|
|
35
|
-
* one page at a time, so memory follows the largest page and not the page count. */
|
|
36
|
-
type Page = {
|
|
37
|
-
/** Posix path relative to `dist/`, e.g. `about-us/index.html`. */
|
|
38
|
-
path: string;
|
|
39
|
-
/** The URL path the file is served at, e.g. `/about-us/`. */
|
|
40
|
-
url: string;
|
|
41
|
-
/** What relative references resolve against: `<base href>` when the page has one, else `url`. */
|
|
42
|
-
base: string;
|
|
43
|
-
/** A redirect stub (`<meta http-equiv="refresh">`): nobody reads it, so page checks skip it. */
|
|
44
|
-
redirect: boolean;
|
|
45
|
-
/** `<meta name="robots">` says `noindex`. */
|
|
46
|
-
noindex: boolean;
|
|
47
|
-
document: Document;
|
|
48
|
-
/** The text a visitor can read: script, style, noscript and template contents left out. */
|
|
49
|
-
visibleText: () => string;
|
|
50
|
-
/** Every attribute value on the page (`alt`, `title`, `href`, island props, …). */
|
|
51
|
-
attributeValues: () => string[];
|
|
52
|
-
/** The data of every HTML comment node, outside script and style text. */
|
|
53
|
-
comments: () => string[];
|
|
54
|
-
};
|
|
55
|
-
/** A build's output, listed once: what both families read of `dist/`. */
|
|
56
|
-
type BuildOutput = {
|
|
57
|
-
distDir: string;
|
|
58
|
-
/** Every file of the build, as a posix path relative to `distDir`. */
|
|
59
|
-
files: string[];
|
|
60
|
-
has: (file: string) => boolean;
|
|
61
|
-
read: (file: string) => string;
|
|
62
|
-
/** Whether a same-site URL path is served by a file of the build: the file itself,
|
|
63
|
-
* `<path>/index.html` or `<path>.html`. Query and fragment ignored. */
|
|
64
|
-
serves: (urlPath: string) => boolean;
|
|
65
|
-
};
|
|
66
|
-
/** What a dist check gets: the build's output, and which kind of build it is. */
|
|
67
|
-
type DistContext = BuildOutput & {
|
|
68
|
-
/** An Astro build (public website: many pages, a 404 page, a sitemap) as opposed to a Vite
|
|
69
|
-
* single-page app (guest, owner: one index.html, routes handled by the app). Checks that only
|
|
70
|
-
* make sense for one kind skip the other. */
|
|
71
|
-
isAstro: boolean;
|
|
72
|
-
/** The site's own origin (`https://www.example-fewo.de`) when the build knows its public URL:
|
|
73
|
-
* absolute links to it are the site's own and are checked like relative ones — with a `site`,
|
|
74
|
-
* canonical, alternate and sitemap URLs are absolute. */
|
|
75
|
-
origin: string | undefined;
|
|
76
|
-
};
|
|
77
|
-
/** What a site check gets. The built output may be absent (a programmatic run before a build):
|
|
78
|
-
* checks that need pages return `null` from `begin` then. */
|
|
79
|
-
type SiteCheckContext = BuildOutput & {
|
|
80
|
-
root: string;
|
|
81
|
-
srcDir: string;
|
|
82
|
-
publicDir: string;
|
|
83
|
-
hasDist: boolean;
|
|
84
|
-
config: {
|
|
85
|
-
/** `site` from the Astro config, when set. */
|
|
86
|
-
site: string | undefined;
|
|
87
|
-
/** `vite.optimizeDeps.include` from the resolved Astro config. */
|
|
88
|
-
optimizeDepsInclude: string[];
|
|
89
|
-
/** `trailingSlash` from the Astro config ("always", "never", "ignore"), when known. */
|
|
90
|
-
trailingSlash: string | undefined;
|
|
91
|
-
};
|
|
92
|
-
options: ResolvedOptions;
|
|
93
|
-
/** Files under `srcDir` with one of the extensions (`.astro`, …), as absolute paths. */
|
|
94
|
-
sourceFiles: (extensions: ReadonlySet<string>) => string[];
|
|
95
|
-
readSource: (absolute: string) => string;
|
|
96
|
-
/** A finding path for a file of the project: relative to `root`, posix. */
|
|
97
|
-
rel: (absolute: string) => string;
|
|
98
|
-
packageJson: {
|
|
99
|
-
dependencies: Record<string, string>;
|
|
100
|
-
devDependencies: Record<string, string>;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
/** One check on one build. The runner parses the HTML pages one after the other and shows each to
|
|
104
|
-
* `visit`; a page is gone after its visit, so a check keeps what it needs from it, never the page.
|
|
105
|
-
* `finish` runs after the last page. */
|
|
106
|
-
type CheckRun = {
|
|
107
|
-
visit?: (page: Page) => void;
|
|
108
|
-
finish: () => Finding[] | Promise<Finding[]>;
|
|
109
|
-
};
|
|
110
|
-
type Check<Context> = {
|
|
111
|
-
/** Stable kebab-case id; the controller stores results by it. Unique across both families: the
|
|
112
|
-
* worker merges them into one report (a test holds the rule). */
|
|
113
|
-
id: string;
|
|
114
|
-
title: string;
|
|
115
|
-
/** Fixed here, never by a site. A check whose outcome depends on PMS data, not on the site's
|
|
116
|
-
* code, must be `warning`: an `error` also refuses the nightly deploy builds. */
|
|
117
|
-
severity: Severity;
|
|
118
|
-
/** Starts the check, or returns `null` when it does not apply to this site. Deterministic,
|
|
119
|
-
* touches no network. */
|
|
120
|
-
begin: (ctx: Context) => CheckRun | null;
|
|
121
|
-
};
|
|
122
|
-
type SiteCheck = Check<SiteCheckContext>;
|
|
123
|
-
type DistCheck = Check<DistContext>;
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/report.d.ts
|
|
126
|
-
/** The report's file name under `dist/`. The build worker reads it after `astro build`, merges it
|
|
127
|
-
* with its own checks and never uploads it (it names source paths and configured terms). */
|
|
128
|
-
declare const SITE_CHECKS_FILE = "site-checks.json";
|
|
129
|
-
declare const writeSiteChecksReport: (distDir: string, report: CheckReport) => void;
|
|
130
|
-
/** One line per check that found something or could not run, for the build log. */
|
|
131
|
-
declare const summaryLines: (report: CheckReport) => string[];
|
|
132
|
-
/** The error `astro build` ends with when a check refuses: every failing check, its first findings,
|
|
133
|
-
* and where the whole report is. */
|
|
134
|
-
declare const refusalMessage: (report: CheckReport) => string;
|
|
135
|
-
/** One line naming what refused the build, for the studio: the failing checks and their counts. */
|
|
136
|
-
declare const summarizeBlocking: (report: CheckReport) => string;
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region src/context.d.ts
|
|
139
|
-
type ContextInput = {
|
|
140
|
-
root: string;
|
|
141
|
-
srcDir: string;
|
|
142
|
-
publicDir: string;
|
|
143
|
-
distDir: string;
|
|
144
|
-
config: SiteCheckContext["config"];
|
|
145
|
-
options: ResolvedOptions;
|
|
146
|
-
};
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/runner.d.ts
|
|
149
|
-
/** Findings kept per check in the report; the rest is counted in `omitted`. */
|
|
150
|
-
declare const MAX_FINDINGS_PER_CHECK = 25;
|
|
151
|
-
/** The controller's `siteCheckReportSchema` accepts a finding message of at most 2000 characters
|
|
152
|
-
* and a path of at most 1000, and skips a report it cannot read as a whole: one over-long finding
|
|
153
|
-
* (a check that quotes a long URL or template expression) must not cost the whole report. */
|
|
154
|
-
declare const MAX_MESSAGE_CHARS = 2000;
|
|
155
|
-
declare const MAX_PATH_CHARS = 1000;
|
|
156
|
-
type RunInput = {
|
|
157
|
-
root: string;
|
|
158
|
-
distDir: string;
|
|
159
|
-
srcDir?: string | undefined;
|
|
160
|
-
publicDir?: string | undefined;
|
|
161
|
-
config?: Partial<ContextInput["config"]> | undefined;
|
|
162
|
-
options?: SiteChecksOptions | undefined;
|
|
163
|
-
};
|
|
164
|
-
/** Runs every site check over the project and its build. */
|
|
165
|
-
declare const runSiteChecks: (input: RunInput, list?: readonly SiteCheck[]) => Promise<CheckReport>;
|
|
166
|
-
/** Results with status `error`: the only ones that refuse a build. */
|
|
167
|
-
declare const blockingResults: (report: CheckReport) => CheckResult[];
|
|
168
|
-
//#endregion
|
|
169
|
-
export { SiteCheck as C, Severity as S, CheckStatus as _, blockingResults as a, Finding as b, refusalMessage as c, writeSiteChecksReport as d, BuildOutput as f, CheckRun as g, CheckResult as h, RunInput as i, summarizeBlocking as l, CheckReport as m, MAX_MESSAGE_CHARS as n, runSiteChecks as o, Check as p, MAX_PATH_CHARS as r, SITE_CHECKS_FILE as s, MAX_FINDINGS_PER_CHECK as t, summaryLines as u, DistCheck as v, SiteCheckContext as w, Page as x, DistContext as y };
|