@v-office/site-checks 0.3.3 → 0.4.1

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 CHANGED
@@ -9,9 +9,8 @@ AI Studio's build worker runs the checks itself on every build, from its own pin
9
9
  package and with the site's `site-checks.config.json`: for an Astro site the `src` stage before
10
10
  `astro check` and the whole `dist` stage after the build, for any other website (the guest and
11
11
  owner apps) the platform's dist checks alone. What a build checks does not depend on whether the
12
- site installed this package. A refused stage never goes live and the previous build stays up; the
13
- report lands in the studio and on the admin page. Locally the two commands are how a developer
14
- looks before pushing.
12
+ site installed this package. What the checks find lands on the studio's admin pages; it never
13
+ stops a deploy. Locally the two commands are how a developer looks before pushing.
15
14
 
16
15
  ## Use
17
16
 
@@ -26,16 +25,20 @@ pnpm add --save-exact --save-dev @v-office/site-checks
26
25
  {
27
26
  "scripts": {
28
27
  "check:src": "site-checks src",
29
- "check:dist": "site-checks dist"
28
+ "check:dist": "site-checks dist",
29
+ "check:all": "site-checks verify"
30
30
  }
31
31
  }
32
32
  ```
33
33
 
34
+ A pre-push hook (`.githooks/pre-push`) runs `pnpm exec site-checks verify` on a push to `main`.
35
+
34
36
  The scripts are for developers; the build worker never runs the site's installed copy, it runs
35
37
  both stages from its own. Nothing goes into `astro.config`.
36
38
 
37
39
  ```
38
40
  site-checks <src | dist> [--root <dir>] [--dist <dir>] [--site <url>] [--report <file>]
41
+ site-checks verify [--root <dir>] [--site <url>]
39
42
  ```
40
43
 
41
44
  - `src` runs the source checks over the project. It never reads `dist/`, so it gives the same
@@ -49,8 +52,11 @@ site-checks <src | dist> [--root <dir>] [--dist <dir>] [--site <url>] [--report
49
52
  do for a preview host. `trailingSlash` is read from the config file the same way. The checks
50
53
  read `src/` and `public/` under the root (Astro's default layout); a config that names `root`,
51
54
  `srcDir` or `publicDir` stops the command.
55
+ - `verify` runs what the build worker runs, in its order, and stops at the first failure: `src`,
56
+ `astro check` (skipped without `@astrojs/check`), the `build` script (pnpm or npm) and `dist`.
52
57
 
53
- Exit codes: 0 when nothing refused, 1 when a check with severity `error` found something, 2 on a
58
+ Exit codes: 0 when nothing refused, 1 when a check with severity `error` found something (for `verify`,
59
+ also when `astro check` or the build fails), 2 on a
54
60
  usage or configuration error (a `site-checks.config.json` that cannot be read stops the command).
55
61
 
56
62
  A refused stage ends with the failing checks and their first findings:
@@ -67,8 +73,8 @@ A refused stage ends with the failing checks and their first findings:
67
73
 
68
74
  ## Configuration
69
75
 
70
- `site-checks.config.json` at the project root holds the site's data for the checks. Severities
71
- are fixed by the package: a site configures data, never whether a check blocks. A key of a check
76
+ `site-checks.config.json` at the project root holds the site's data for the checks and the
77
+ findings it excludes (below). Severities are fixed by the package. A key of a check
72
78
  an earlier version had (`wiring`, `optimizeDepsIgnore`) is noted and ignored; an unknown key stops
73
79
  the command.
74
80
 
@@ -88,6 +94,97 @@ the command.
88
94
  | `allowDuplicateSentences` | `duplicate-sentences` | Sentences a page may render twice. |
89
95
  | `quoteSources` | `quote-sources` | Files or directories holding the text a `<blockquote>` may quote (content captures, the feed's reviews written by the build). |
90
96
  | `factCheckAccepted` | `rental-facts` | Disagreements the customer confirmed, as the finding prints them: `<slug> <kind> prose=<n> feed=<n>`. |
97
+ | `exclude` | every check | The findings the site accepts, by check id: see [Excluding findings](#excluding-findings). |
98
+
99
+ ## Excluding findings
100
+
101
+ `exclude` takes the findings a site accepts, by check id. Every check reads it, the platform's dist
102
+ checks included:
103
+
104
+ ```json
105
+ {
106
+ "exclude": {
107
+ "trailing-slash": true,
108
+ "canonical-link": ["/impressum"],
109
+ "image-formats": ["public/brand/logo.png"],
110
+ "html-comments": ["src/legacy/"],
111
+ "donor-terms": [
112
+ { "path": "/ueber-uns", "match": "Bauernhof", "reason": "the customer's own farm" }
113
+ ],
114
+ "internal-links": [{ "match": "/alte-seite" }]
115
+ }
116
+ }
117
+ ```
118
+
119
+ - `true`: the check does not run for the site; the report lists it as skipped.
120
+ - A path hides the check's findings on it. A path starting with `/` is a URL path: it covers a built
121
+ page and every page below it, with or without a language prefix (`/impressum` also covers
122
+ `/de/impressum`). `/` is the home page alone; every page is `true`, or a `match` without a
123
+ `path`. Any other path is a file or a folder, project-relative (`public/brand/logo.png`,
124
+ `src/legacy/`, whatever line a source finding names) or relative to `dist/` (`_astro/`).
125
+ - `{ "path", "match", "reason" }` hides the findings whose message contains `match`
126
+ (case-insensitive), on `path` when it is given. Give at least one of the two, neither empty;
127
+ `reason` is for whoever reads the config next.
128
+
129
+ An excluded finding is dropped before the check's status is decided: a check whose findings are all
130
+ excluded is `ok`. A check id this version does not know stops the command, like an unknown key. The
131
+ keys above (`imageIgnore`, `copyExcludePaths`, `structureIgnore`, …) keep working. The build's
132
+ `astro-check` result is the build worker's own, not a check of this package, and cannot be excluded.
133
+
134
+ ### One example per check
135
+
136
+ A `match` is text of the finding's message, as the report prints it: copy it from there. Where a
137
+ check's findings all name the same file or page, a path is enough; where one page or file holds
138
+ unrelated findings, `match` picks one.
139
+
140
+ `src` stage:
141
+
142
+ | Check | Example | Exempts |
143
+ | ---------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------- |
144
+ | `html-comments` | `"src/components/legacy/"` | the comments in that folder (a finding names `file:line`, so a file or a folder is the way) |
145
+ | `image-formats` | `"public/brand/logo.png"` | that image; `"public/brand/"` the folder |
146
+ | `sync-once` | `true` | the loader finding (`src/content.config.ts`) |
147
+ | `v9-hub-filters` | `true`, or `{ "match": "could not be asked" }` | the check, or only "the Hub could not be asked" |
148
+
149
+ `dist` stage, site checks:
150
+
151
+ | Check | Example | Exempts |
152
+ | --------------------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
153
+ | `view-source` | `{ "match": "comment in shipped JS" }` | every comment in the shipped JS |
154
+ | | `{ "path": "/kontakt", "match": "HTML comment" }` | the HTML comments on one page |
155
+ | `donor-terms` | `{ "path": "/ueber-uns", "match": "\"Bauernhof\"" }` | that term on that page only |
156
+ | `consent-gate` | `{ "match": "from www.youtube-nocookie.com" }` | that host (or list it in `consentAllowedHosts`) |
157
+ | | `{ "match": "vendor \"matomo\"" }` | that vendor's registry finding |
158
+ | `feed-image-formats` | `"/angebote"` | the feed photos on that page |
159
+ | `listing-noindex` | `"/suche/last-minute"` | that listing page |
160
+ | `listing-links` | `"/merkliste"` | that listing page (or `listingClientOnly`, with the reason) |
161
+ | `sitemap-noindex` | `{ "match": "https://www.example.de/agb" }` | that sitemap entry: the finding's path is the sitemap file, so `match` names the URL |
162
+ | `page-heads` | `"/blog"` | the title and description lengths on the blog |
163
+ | | `{ "match": "description \"Ferienwohnungen an der Ostsee\"" }` | one repeated description |
164
+ | `canonical-link` | `"/impressum"` | that page |
165
+ | `open-graph` | `{ "path": "/impressum", "match": "og:image" }` | the findings naming `og:image` on that page (a page missing both tags has one finding naming both) |
166
+ | `trailing-slash` | `true` | the check: its one finding is about the whole site |
167
+ | `v9-production-hub` | `{ "match": ".env.local is committed" }` | that finding alone |
168
+ | `page-structure` | `{ "path": "/impressum", "match": "heading-skip:" }` | one rule on one page (`structureIgnore` declines a rule on every page) |
169
+ | `load-order` | `{ "match": "leaflet" }` | the findings about that library |
170
+ | `banned-copy` | `"/faq"` | that page (or `bannedCopyExcludePaths`) |
171
+ | `duplicate-sentences` | `{ "match": "Wir freuen uns auf Ihre Anfrage" }` | that sentence on every page (or `allowDuplicateSentences`) |
172
+ | `quote-sources` | `"/bewertungen"` | that page |
173
+ | `rental-facts` | `"/unterkunft/seeblick"` | that rental (`factCheckAccepted` accepts one exact disagreement) |
174
+
175
+ `dist` stage, the platform's dist checks:
176
+
177
+ | Check | Example | Exempts |
178
+ | --------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------- |
179
+ | `site-manifest` | `true` | the check |
180
+ | `key-pages` | `"404.html"` | "No 404.html" |
181
+ | `not-found-beacon` | `true` | the check |
182
+ | `internal-links` | `{ "match": "references /alte-seite," }` | the references to that target (the path is only the first page that has one) |
183
+ | `legal-pages` | `{ "path": "/landing", "match": "Impressum" }` | the missing Impressum link on that page |
184
+ | `page-metadata` | `{ "path": "/danke", "match": "description" }` | the missing description on that page |
185
+ | `placeholder-content` | `{ "match": "example.com" }` | that example host |
186
+ | `insecure-resources` | `{ "match": "http://partner.example.de" }` | that resource |
187
+ | `sitemap` | `"robots.txt"` | "No robots.txt" |
91
188
 
92
189
  ## The checks
93
190
 
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as cli } from "./cli-C2uCbjyQ.mjs";
2
+ import { n as cli } from "./cli-CYG52KHL.mjs";
3
3
  //#region src/bin.ts
4
4
  process.exitCode = await cli(process.argv.slice(2), {
5
5
  out: (line) => console.log(line),
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { parseHTML } from "linkedom";
4
4
  import { brotliCompressSync, constants } from "node:zlib";
5
5
  import os from "node:os";
6
+ import { spawn } from "node:child_process";
6
7
  import { parseArgs } from "node:util";
7
8
  //#region src/jsComments.ts
8
9
  /** One pass over JavaScript (or the script parts of a component): its comments, and the code with
@@ -506,19 +507,50 @@ const xmlText = (text) => text.replace(/&(?:#x([0-9a-f]+)|#(\d+)|(amp|lt|gt|quot
506
507
  }[name.toLowerCase()] ?? entity;
507
508
  });
508
509
  //#endregion
510
+ //#region src/exclude.ts
511
+ const LOCALE = /^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i;
512
+ /** The `:line` (and `:column`) a source finding's path ends with. */
513
+ const LINE = /:\d+(?::\d+)?$/;
514
+ /** Whether a URL path entry covers `url`: the path and everything below it, with or without a
515
+ * locale prefix, so `/impressum` also covers `/de/impressum`. `/` is the home page alone: the whole
516
+ * site is the check's `true`, or a `match` without a `path`. */
517
+ const coversUrl = (entry, url) => {
518
+ const own = url.length > 1 ? url.replace(/\/+$/, "") : url;
519
+ const unprefixed = own.replace(LOCALE, "") || "/";
520
+ const p = `/${entry.replace(/^\/+|\/+$/g, "")}`;
521
+ return [own, unprefixed].some((u) => u === p || u.startsWith(`${p}/`));
522
+ };
523
+ /** Whether a path entry covers a finding's path. An entry starting with `/` is a URL path, matched
524
+ * against the URL a built file is served at; any other entry is a file path, project-relative
525
+ * (`public/brand/logo.png`, `src/legacy/`) or relative to `dist/`, and covers that file or
526
+ * everything in that folder. */
527
+ const coversPath = (entry, findingPath) => {
528
+ if (findingPath === void 0) return false;
529
+ const file = findingPath.replace(LINE, "");
530
+ if (entry.startsWith("/")) return coversUrl(entry, fileToUrl(file));
531
+ const folder = entry.replace(/\/+$/, "");
532
+ return file === folder || file.startsWith(`${folder}/`);
533
+ };
534
+ /** Whether one of a check's exclusions covers a finding: its path, and the text its message
535
+ * contains (case-insensitive), each when the entry gives one. */
536
+ const isExcluded = (entries, finding) => entries.some((entry) => {
537
+ if (typeof entry === "string") return coversPath(entry, finding.path);
538
+ if (entry.path !== void 0 && !coversPath(entry.path, finding.path)) return false;
539
+ return entry.match === void 0 || finding.message.toLowerCase().includes(entry.match.toLowerCase());
540
+ });
541
+ /** An `exclude` naming a check this version does not have stops the command: a typo would
542
+ * otherwise hide nothing, silently. */
543
+ const assertKnownChecks = (exclude, ids) => {
544
+ const known = new Set(ids);
545
+ const unknown = Object.keys(exclude).filter((id) => !known.has(id));
546
+ if (unknown.length > 0) throw new Error(`[site-checks] "exclude" names ${unknown.length === 1 ? "an unknown check" : "unknown checks"}: ${unknown.join(", ")}`);
547
+ };
548
+ //#endregion
509
549
  //#region src/checks/copy.ts
510
550
  /** Pages the copy checks read: not a redirect stub, not the 404 page, not an excluded path. An
511
551
  * entry covers the path and everything below it, with or without a locale prefix: `/impressum`
512
552
  * also covers `/de/impressum`. */
513
- const excluded = (page, paths) => {
514
- if (page.redirect || page.path === "404.html") return true;
515
- const url = page.url.length > 1 ? page.url.replace(/\/+$/, "") : page.url;
516
- const unprefixed = url.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i, "") || "/";
517
- return paths.some((entry) => {
518
- const p = `/${entry.replace(/^\/+|\/+$/g, "")}`;
519
- return [url, unprefixed].some((u) => u === p || u.startsWith(`${p}/`));
520
- });
521
- };
553
+ const excluded = (page, paths) => page.redirect || page.path === "404.html" || paths.some((entry) => coversUrl(entry, page.url));
522
554
  const excerpt$2 = (text, max = 90) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
523
555
  /** Quotes and whitespace removed, lower-cased: two renderings of one sentence compare equal. */
524
556
  const normalize$3 = (text) => text.toLowerCase().replace(/[„“”"‚’'«»]/g, "").replace(/\s+/g, " ").trim();
@@ -736,6 +768,8 @@ const donorTerms = {
736
768
  re: wholeWord(term)
737
769
  }));
738
770
  if (terms.length === 0 || !ctx.hasDist) return null;
771
+ const exclusions = ctx.options.exclude["donor-terms"];
772
+ const excluded = Array.isArray(exclusions) ? exclusions : [];
739
773
  const findings = [];
740
774
  /** One finding per term and place: the first text of `texts` that contains it. */
741
775
  const scan = (texts, path, where) => {
@@ -745,10 +779,11 @@ const donorTerms = {
745
779
  for (const haystack of haystacks) {
746
780
  const match = re.exec(haystack);
747
781
  if (!match) continue;
748
- findings.push({
782
+ const finding = {
749
783
  path,
750
784
  message: `donor term "${term}" in ${where}: "${excerpt$1(haystack, match.index, term.length)}"`
751
- });
785
+ };
786
+ if (!isExcluded(excluded, finding)) findings.push(finding);
752
787
  break;
753
788
  }
754
789
  }
@@ -2245,6 +2280,10 @@ const compiles = (source, key, pattern, flags) => {
2245
2280
  throw new Error(`[site-checks] ${source}: "${key}" has an invalid regular expression ${JSON.stringify(pattern)}: ${err.message}`);
2246
2281
  }
2247
2282
  };
2283
+ /** An `exclude` entry: a path, or an object with a path, a match or both, and a reason at will.
2284
+ * `path` and `match` are never empty: an entry with neither, or an empty `match`, which every
2285
+ * message contains, would hide every finding (that is `true`). */
2286
+ const isExclusion = (entry) => nonEmpty(entry) || isObject(entry) && (entry.path !== void 0 || entry.match !== void 0) && Object.entries(entry).every(([field, value]) => field === "reason" ? isString(value) : (field === "path" || field === "match") && nonEmpty(value));
2248
2287
  const stringList = (source, key, value) => {
2249
2288
  if (!isStringList(value)) throw new Error(`[site-checks] ${source}: "${key}" must be an array of strings`);
2250
2289
  };
@@ -2276,6 +2315,10 @@ const VALIDATORS = {
2276
2315
  },
2277
2316
  hubFilterOptions: (source, key, value) => {
2278
2317
  if (!isObject(value)) throw new Error(`[site-checks] ${source}: "${key}" must be an object`);
2318
+ },
2319
+ exclude: (source, key, value) => {
2320
+ if (!isObject(value)) throw new Error(`[site-checks] ${source}: "${key}" must be an object of check ids`);
2321
+ for (const [id, entries] of Object.entries(value)) if (entries !== true && !(Array.isArray(entries) && entries.every(isExclusion))) throw new Error(`[site-checks] ${source}: "${key}.${id}" must be true or an array of paths and { path, match, reason }`);
2279
2322
  }
2280
2323
  };
2281
2324
  const validate = (source, raw, note) => {
@@ -2327,7 +2370,8 @@ function loadOptions(root, overrides = {}, note = () => {}) {
2327
2370
  quoteSources: pick("quoteSources", []),
2328
2371
  factCheckAccepted: pick("factCheckAccepted", []),
2329
2372
  structureIgnore: pick("structureIgnore", []),
2330
- hubFilterOptions: pick("hubFilterOptions", {})
2373
+ hubFilterOptions: pick("hubFilterOptions", {}),
2374
+ exclude: pick("exclude", {})
2331
2375
  };
2332
2376
  }
2333
2377
  //#endregion
@@ -2357,9 +2401,9 @@ const failed = (check, message) => ({
2357
2401
  });
2358
2402
  const broken = (check, err) => failed(check, `The check itself failed: ${errorMessage(err)}`);
2359
2403
  const unreadable = (check, err) => failed(check, `The build output could not be read: ${errorMessage(err)}`);
2360
- const finish = async (check, run) => {
2404
+ const finish = async (check, run, excluded) => {
2361
2405
  try {
2362
- const findings = await run.finish();
2406
+ const findings = (await run.finish()).filter((finding) => !isExcluded(excluded, finding));
2363
2407
  return {
2364
2408
  id: check.id,
2365
2409
  status: findings.length === 0 ? "ok" : check.severity,
@@ -2372,8 +2416,9 @@ const finish = async (check, run) => {
2372
2416
  };
2373
2417
  /** Runs every check of `list` over the context `load` returns. Never throws: a check that throws
2374
2418
  * is a `failed` result, a context that cannot be loaded fails every check the same way. The HTML
2375
- * pages are parsed one at a time and shown to every check before the next one is read. */
2376
- const runChecks = async (load, list) => {
2419
+ * pages are parsed one at a time and shown to every check before the next one is read. The
2420
+ * site's exclusions (`exclusionsOf` the loaded context) skip a check or drop its findings. */
2421
+ const runChecks = async (load, list, exclusionsOf = () => ({})) => {
2377
2422
  const started = Date.now();
2378
2423
  const ranAt = new Date(started).toISOString();
2379
2424
  let ctx;
@@ -2386,19 +2431,31 @@ const runChecks = async (load, list) => {
2386
2431
  results: list.map((check) => unreadable(check, err))
2387
2432
  };
2388
2433
  }
2434
+ const exclude = exclusionsOf(ctx);
2389
2435
  const results = /* @__PURE__ */ new Map();
2390
2436
  const runs = /* @__PURE__ */ new Map();
2391
- for (const check of list) try {
2392
- const run = check.begin(ctx);
2393
- if (run) runs.set(check, run);
2394
- else results.set(check, {
2395
- id: check.id,
2396
- status: "skipped",
2397
- findings: [],
2398
- omitted: 0
2399
- });
2400
- } catch (err) {
2401
- results.set(check, broken(check, err));
2437
+ for (const check of list) {
2438
+ if (exclude[check.id] === true) {
2439
+ results.set(check, {
2440
+ id: check.id,
2441
+ status: "skipped",
2442
+ findings: [],
2443
+ omitted: 0
2444
+ });
2445
+ continue;
2446
+ }
2447
+ try {
2448
+ const run = check.begin(ctx);
2449
+ if (run) runs.set(check, run);
2450
+ else results.set(check, {
2451
+ id: check.id,
2452
+ status: "skipped",
2453
+ findings: [],
2454
+ omitted: 0
2455
+ });
2456
+ } catch (err) {
2457
+ results.set(check, broken(check, err));
2458
+ }
2402
2459
  }
2403
2460
  for (const file of ctx.files) {
2404
2461
  if (!file.endsWith(".html")) continue;
@@ -2421,7 +2478,10 @@ const runChecks = async (load, list) => {
2421
2478
  results.set(check, broken(check, err));
2422
2479
  }
2423
2480
  }
2424
- for (const [check, run] of runs) results.set(check, await finish(check, run));
2481
+ for (const [check, run] of runs) {
2482
+ const entries = exclude[check.id];
2483
+ results.set(check, await finish(check, run, Array.isArray(entries) ? entries : []));
2484
+ }
2425
2485
  return {
2426
2486
  ranAt,
2427
2487
  durationMs: Date.now() - started,
@@ -2443,8 +2503,8 @@ const contextInput = (input) => ({
2443
2503
  });
2444
2504
  /** Runs the given site checks over the project, with its build when there is one and the stage
2445
2505
  * does not exclude it. The stages (`stages.ts`) are built on this; tests run one check through it. */
2446
- const runSiteChecks = (input, list = checks) => runChecks(() => loadContext(contextInput(input)), list);
2447
- /** Results with status `error`: the only ones that refuse a build. */
2506
+ const runSiteChecks = (input, list = checks) => runChecks(() => loadContext(contextInput(input)), list, (ctx) => ctx.options.exclude);
2507
+ /** Results with status `error`: the ones `site-checks` exits non-zero for. */
2448
2508
  const blockingResults = (report) => report.results.filter((r) => r.status === "error");
2449
2509
  //#endregion
2450
2510
  //#region src/report.ts
@@ -2817,8 +2877,8 @@ const pathOf = (url) => {
2817
2877
  * The dist checks: the platform's checks over a build's `dist/`. They are part of the `dist`
2818
2878
  * stage (`site-checks dist` runs them after the site's own), and the build worker also runs them
2819
2879
  * on its own, at its pinned version, over every build of every website: public sites, the guest
2820
- * and owner apps, and sites without this package. A site configures nothing for them. A check
2821
- * every website must pass, whether or not it has this package, belongs here.
2880
+ * and owner apps, and sites without this package. A site configures nothing for them but its
2881
+ * exclusions. A check every website must pass, whether or not it has this package, belongs here.
2822
2882
  * See docs/website-platform/process/10-dist-checks.md.
2823
2883
  */
2824
2884
  const distChecks = [
@@ -2878,9 +2938,15 @@ const distChecks = [
2878
2938
  }
2879
2939
  }
2880
2940
  ];
2881
- /** Runs every dist check over `distDir`. Never throws: a check that throws is a `failed` result,
2882
- * an unreadable `distDir` fails every check the same way. */
2883
- const runDistChecks = (distDir, opts, list = distChecks) => runChecks(() => loadDistContext(distDir, opts), list);
2941
+ /** Runs every dist check over `distDir`, with the exclusions of the `site-checks.config.json` at
2942
+ * `root` when given. Never throws for a check's sake: a check that throws is a `failed` result, an
2943
+ * unreadable `distDir` fails every check the same way. A config that cannot be read throws, as in
2944
+ * `runStage`. */
2945
+ const runDistChecks = (distDir, opts, list = distChecks) => {
2946
+ const exclude = opts.root === void 0 ? {} : loadOptions(opts.root).exclude;
2947
+ assertKnownChecks(exclude, [...checks, ...distChecks].map((check) => check.id));
2948
+ return runChecks(() => loadDistContext(distDir, opts), list, () => exclude);
2949
+ };
2884
2950
  //#endregion
2885
2951
  //#region src/stages.ts
2886
2952
  /**
@@ -2890,7 +2956,8 @@ const runDistChecks = (distDir, opts, list = distChecks) => runChecks(() => load
2890
2956
  * a `failed` result. A config file that cannot be read throws before anything runs, and so does
2891
2957
  * an Astro config that names `root`, `srcDir` or `publicDir`: the checks read `src/` and `public/`
2892
2958
  * under the root, and must not pass over folders the build does not use. A site URL that is no
2893
- * URL throws too: the dist stage would fail every check on it, and failed checks do not refuse.
2959
+ * URL throws too: the dist stage would fail every check on it. So does an `exclude` naming a check
2960
+ * this version does not have.
2894
2961
  */
2895
2962
  const runStage = async (stage, input) => {
2896
2963
  const astro = readAstroConfig(input.root);
@@ -2908,20 +2975,24 @@ const runStage = async (stage, input) => {
2908
2975
  options: input.options,
2909
2976
  note: input.note
2910
2977
  });
2911
- if (stage === "src") return runChecks(() => loadContext(base), checksOf("src"));
2978
+ const exclude = base.options.exclude;
2979
+ assertKnownChecks(exclude, [...checks, ...distChecks].map((check) => check.id));
2980
+ if (stage === "src") return runChecks(() => loadContext(base), checksOf("src"), () => exclude);
2912
2981
  const isAstro = astro.found || fs.existsSync(path.join(input.root, "node_modules", "astro"));
2913
2982
  const list = [...distChecks, ...checksOf("dist")];
2914
2983
  return runChecks(() => loadDistStageContext({
2915
2984
  ...base,
2916
2985
  isAstro
2917
- }), list);
2986
+ }), list, () => exclude);
2918
2987
  };
2919
2988
  //#endregion
2920
2989
  //#region src/cli.ts
2921
- const USAGE = `Usage: site-checks <src | dist> [options]
2990
+ const USAGE = `Usage: site-checks <src | dist | verify> [options]
2922
2991
 
2923
2992
  src the source checks, before the build (reads the project, never dist/)
2924
2993
  dist the checks over the built output, after the build
2994
+ verify what AI Studio's build runs, stopping at the first failure: src, astro check, the
2995
+ build script, dist (--root and --site only)
2925
2996
 
2926
2997
  Options:
2927
2998
  --root <dir> the project (default: the current directory)
@@ -2930,8 +3001,9 @@ Options:
2930
3001
  --report <file> write the report as JSON here (default for dist: <dist>/${SITE_CHECKS_FILE})
2931
3002
  -h, --help this text
2932
3003
 
2933
- Exits 0 when nothing refused, 1 when a check with severity error found something, 2 on a usage
2934
- or configuration error. Data for the checks: ${CONFIG_FILE} at the project root.`;
3004
+ Exits 0 when nothing refused, 1 when a check with severity error found something or (verify)
3005
+ astro check or the build failed, 2 on a usage or configuration error. Data for the checks:
3006
+ ${CONFIG_FILE} at the project root.`;
2935
3007
  const STAGES = ["src", "dist"];
2936
3008
  const isStage = (value) => value !== void 0 && STAGES.includes(value);
2937
3009
  const isUrl = (value) => {
@@ -2984,6 +3056,7 @@ async function cli(argv, io, cwd = process.cwd()) {
2984
3056
  return 0;
2985
3057
  }
2986
3058
  const [stage, ...rest] = positionals;
3059
+ if (stage === "verify" && rest.length === 0 && values.dist === void 0 && values.report === void 0) return verify(path.resolve(cwd, values.root ?? "."), values.site, io, cwd);
2987
3060
  if (!isStage(stage) || rest.length > 0) {
2988
3061
  io.err(USAGE);
2989
3062
  return 2;
@@ -3031,5 +3104,74 @@ async function cli(argv, io, cwd = process.cwd()) {
3031
3104
  io.out(`[site-checks] ${stage}: ${report.results.length} checks, nothing refused` + (shown ? ` (report: ${shown})` : ""));
3032
3105
  return 0;
3033
3106
  }
3107
+ /** Runs a child in the project with its output on ours: 0, 1 when it fails, 2 when it cannot
3108
+ * start. No stdin: a pre-push hook's stdin holds git's refs. */
3109
+ const exec = (command, args, root, env, io) => new Promise((resolve) => {
3110
+ const child = spawn(command, args, {
3111
+ cwd: root,
3112
+ env,
3113
+ stdio: [
3114
+ "ignore",
3115
+ "inherit",
3116
+ "inherit"
3117
+ ]
3118
+ });
3119
+ child.on("error", (err) => {
3120
+ io.err(`site-checks: cannot run ${command}: ${err.message}`);
3121
+ resolve(2);
3122
+ });
3123
+ child.on("close", (code) => resolve(code === 0 ? 0 : 1));
3124
+ });
3125
+ /**
3126
+ * `site-checks verify`: the build worker's sequence (services/worker/src/builder.ts), stopping at
3127
+ * the first failure: the src stage, `astro check` (skipped without @astrojs/check, as the worker
3128
+ * reports it), the project's build script, the dist stage. `astro check` and the build share one
3129
+ * CONTENT_SYNC_TOKEN, as the worker's `buildEnv`, so a content loader syncs the PMS once.
3130
+ */
3131
+ async function verify(root, site, io, cwd) {
3132
+ let pkg;
3133
+ try {
3134
+ pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
3135
+ } catch {
3136
+ pkg = void 0;
3137
+ }
3138
+ if (typeof pkg?.scripts?.build !== "string") {
3139
+ io.err(`site-checks: no \`build\` script in ${path.join(root, "package.json")}.`);
3140
+ return 2;
3141
+ }
3142
+ const pm = fs.existsSync(path.join(root, "pnpm-lock.yaml")) || String(pkg.packageManager).startsWith("pnpm@") ? "pnpm" : "npm";
3143
+ const env = {
3144
+ ...process.env,
3145
+ CONTENT_SYNC_TOKEN: `${process.pid}-${Date.now()}`
3146
+ };
3147
+ const stageArgs = [
3148
+ "--root",
3149
+ root,
3150
+ ...site !== void 0 ? ["--site", site] : []
3151
+ ];
3152
+ const steps = [
3153
+ ["src", () => cli(["src", ...stageArgs], io, cwd)],
3154
+ ["astro check", async () => {
3155
+ if (fs.existsSync(path.join(root, "node_modules/@astrojs/check"))) return exec(path.join(root, "node_modules/.bin/astro"), ["check"], root, env, io);
3156
+ io.out("[site-checks] astro check skipped: @astrojs/check is not installed.");
3157
+ return "skipped";
3158
+ }],
3159
+ ["build", () => exec(pm, ["run", "build"], root, env, io)],
3160
+ ["dist", () => cli(["dist", ...stageArgs], io, cwd)]
3161
+ ];
3162
+ const passed = [];
3163
+ for (const [name, step] of steps) {
3164
+ io.out(`[site-checks] verify: ${name === "build" ? `build (${pm} run build)` : name}`);
3165
+ const code = await step();
3166
+ if (code === "skipped") continue;
3167
+ if (code !== 0) {
3168
+ io.err(`[site-checks] verify stopped at ${name}; passed: ${passed.join(", ") || "none"}`);
3169
+ return code;
3170
+ }
3171
+ passed.push(name);
3172
+ }
3173
+ io.out(`[site-checks] verify passed: ${passed.join(", ")}`);
3174
+ return 0;
3175
+ }
3034
3176
  //#endregion
3035
3177
  export { loadOptions as _, runDistChecks as a, readAstroConfig as b, refusalMessage as c, MAX_FINDINGS_PER_CHECK as d, MAX_MESSAGE_CHARS as f, CONFIG_FILE as g, runSiteChecks as h, distChecks as i, summarizeBlocking as l, blockingResults as m, cli as n, SITE_CHECKS_FILE as o, MAX_PATH_CHARS as p, runStage as r, findingLine as s, USAGE as t, summaryLines as u, checks as v, checksOf as y };
package/dist/index.d.mts CHANGED
@@ -19,6 +19,18 @@ type AstroConfigFacts = {
19
19
  * one the checks that need it wait. */
20
20
  export declare const readAstroConfig: (root: string) => AstroConfigFacts;
21
21
  //#endregion
22
+ //#region src/exclude.d.ts
23
+ /** One exclusion of a check's findings: a path, or a path and text the finding's message contains.
24
+ * `reason` is for whoever reads the config next. */
25
+ type Exclusion = string | {
26
+ path?: string;
27
+ match?: string;
28
+ reason?: string;
29
+ };
30
+ /** A site's exclusions (`exclude` in `site-checks.config.json`), by check id: `true` turns the
31
+ * check off for the site, a list hides the findings an entry covers. */
32
+ type Exclusions = Record<string, true | Exclusion[]>;
33
+ //#endregion
22
34
  //#region src/options.d.ts
23
35
  /** A wording a recorded customer correction bans from the rendered pages. */
24
36
  interface BannedCopy {
@@ -76,6 +88,10 @@ interface SiteChecksOptions {
76
88
  /** v9 only: the Website SDK options the site's `website-sdk hub-filters check` needs
77
89
  * (`rentalScope`, `customAttributeFilterDefinitions`), as the site passes them to the SDK. */
78
90
  hubFilterOptions?: Record<string, unknown>;
91
+ /** Findings the site excludes, by check id: `true` turns the check off for the site; a list
92
+ * hides the findings an entry covers, a path (`/impressum`, `public/brand/logo.png`) or
93
+ * `{ path, match, reason }` (`match`: text the finding's message contains). */
94
+ exclude?: Exclusions;
79
95
  }
80
96
  type ResolvedOptions = Required<SiteChecksOptions>;
81
97
  export declare const CONFIG_FILE = "site-checks.config.json";
@@ -226,7 +242,7 @@ type Io = {
226
242
  out: (line: string) => void;
227
243
  err: (line: string) => void;
228
244
  };
229
- export declare const USAGE = "Usage: site-checks <src | dist> [options]\n\n src the source checks, before the build (reads the project, never dist/)\n dist the checks over the built output, after the build\n\nOptions:\n --root <dir> the project (default: the current directory)\n --dist <dir> the build output, relative to the root (default: dist; dist stage only)\n --site <url> the site's public URL (default: `site` in the Astro config file)\n --report <file> write the report as JSON here (default for dist: <dist>/site-checks.json)\n -h, --help this text\n\nExits 0 when nothing refused, 1 when a check with severity error found something, 2 on a usage\nor configuration error. Data for the checks: site-checks.config.json at the project root.";
245
+ export declare const USAGE = "Usage: site-checks <src | dist | verify> [options]\n\n src the source checks, before the build (reads the project, never dist/)\n dist the checks over the built output, after the build\n verify what AI Studio's build runs, stopping at the first failure: src, astro check, the\n build script, dist (--root and --site only)\n\nOptions:\n --root <dir> the project (default: the current directory)\n --dist <dir> the build output, relative to the root (default: dist; dist stage only)\n --site <url> the site's public URL (default: `site` in the Astro config file)\n --report <file> write the report as JSON here (default for dist: <dist>/site-checks.json)\n -h, --help this text\n\nExits 0 when nothing refused, 1 when a check with severity error found something or (verify)\nastro check or the build failed, 2 on a usage or configuration error. Data for the checks:\nsite-checks.config.json at the project root.";
230
246
  /** The command line. Returns the exit code; prints to `io`. */
231
247
  export declare function cli(argv: readonly string[], io: Io, cwd?: string): Promise<number>;
232
248
  //#endregion
@@ -280,7 +296,7 @@ type RunInput = {
280
296
  /** Runs the given site checks over the project, with its build when there is one and the stage
281
297
  * does not exclude it. The stages (`stages.ts`) are built on this; tests run one check through it. */
282
298
  export declare const runSiteChecks: (input: RunInput, list?: readonly SiteCheck[]) => Promise<CheckReport>;
283
- /** Results with status `error`: the only ones that refuse a build. */
299
+ /** Results with status `error`: the ones `site-checks` exits non-zero for. */
284
300
  export declare const blockingResults: (report: CheckReport) => CheckResult[];
285
301
  //#endregion
286
302
  //#region src/distChecks/index.d.ts
@@ -288,16 +304,19 @@ export declare const blockingResults: (report: CheckReport) => CheckResult[];
288
304
  * The dist checks: the platform's checks over a build's `dist/`. They are part of the `dist`
289
305
  * stage (`site-checks dist` runs them after the site's own), and the build worker also runs them
290
306
  * on its own, at its pinned version, over every build of every website: public sites, the guest
291
- * and owner apps, and sites without this package. A site configures nothing for them. A check
292
- * every website must pass, whether or not it has this package, belongs here.
307
+ * and owner apps, and sites without this package. A site configures nothing for them but its
308
+ * exclusions. A check every website must pass, whether or not it has this package, belongs here.
293
309
  * See docs/website-platform/process/10-dist-checks.md.
294
310
  */
295
311
  export declare const distChecks: readonly DistCheck[];
296
- /** Runs every dist check over `distDir`. Never throws: a check that throws is a `failed` result,
297
- * an unreadable `distDir` fails every check the same way. */
312
+ /** Runs every dist check over `distDir`, with the exclusions of the `site-checks.config.json` at
313
+ * `root` when given. Never throws for a check's sake: a check that throws is a `failed` result, an
314
+ * unreadable `distDir` fails every check the same way. A config that cannot be read throws, as in
315
+ * `runStage`. */
298
316
  export declare const runDistChecks: (distDir: string, opts: {
299
317
  isAstro: boolean;
300
318
  siteUrl?: string | undefined;
319
+ root?: string | undefined;
301
320
  }, list?: readonly DistCheck[]) => Promise<CheckReport>;
302
321
  //#endregion
303
322
  //#region src/stages.d.ts
@@ -320,8 +339,9 @@ type StageInput = {
320
339
  * a `failed` result. A config file that cannot be read throws before anything runs, and so does
321
340
  * an Astro config that names `root`, `srcDir` or `publicDir`: the checks read `src/` and `public/`
322
341
  * under the root, and must not pass over folders the build does not use. A site URL that is no
323
- * URL throws too: the dist stage would fail every check on it, and failed checks do not refuse.
342
+ * URL throws too: the dist stage would fail every check on it. So does an `exclude` naming a check
343
+ * this version does not have.
324
344
  */
325
345
  export declare const runStage: (stage: Stage, input: StageInput) => Promise<CheckReport>;
326
346
  //#endregion
327
- export type { AstroConfigFacts, BannedCopy, BuildOutput, Check, CheckReport, CheckResult, CheckRun, CheckStatus, DistCheck, DistContext, DistStageContext, Finding, Io, Page, ResolvedOptions, RunInput, Severity, SiteCheck, SiteCheckContext, SiteChecksOptions, Stage, StageInput };
347
+ export type { AstroConfigFacts, BannedCopy, BuildOutput, Check, CheckReport, CheckResult, CheckRun, CheckStatus, DistCheck, DistContext, DistStageContext, Exclusion, Exclusions, Finding, Io, Page, ResolvedOptions, RunInput, Severity, SiteCheck, SiteCheckContext, SiteChecksOptions, Stage, StageInput };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as loadOptions, a as runDistChecks, b as readAstroConfig, c as refusalMessage, d as MAX_FINDINGS_PER_CHECK, f as MAX_MESSAGE_CHARS, g as CONFIG_FILE, h as runSiteChecks, i as distChecks, l as summarizeBlocking, m as blockingResults, n as cli, o as SITE_CHECKS_FILE, p as MAX_PATH_CHARS, r as runStage, s as findingLine, t as USAGE, u as summaryLines, v as checks, y as checksOf } from "./cli-C2uCbjyQ.mjs";
1
+ import { _ as loadOptions, a as runDistChecks, b as readAstroConfig, c as refusalMessage, d as MAX_FINDINGS_PER_CHECK, f as MAX_MESSAGE_CHARS, g as CONFIG_FILE, h as runSiteChecks, i as distChecks, l as summarizeBlocking, m as blockingResults, n as cli, o as SITE_CHECKS_FILE, p as MAX_PATH_CHARS, r as runStage, s as findingLine, t as USAGE, u as summaryLines, v as checks, y as checksOf } from "./cli-CYG52KHL.mjs";
2
2
  export { CONFIG_FILE, MAX_FINDINGS_PER_CHECK, MAX_MESSAGE_CHARS, MAX_PATH_CHARS, SITE_CHECKS_FILE, USAGE, blockingResults, checks, checksOf, cli, distChecks, findingLine, loadOptions, readAstroConfig, refusalMessage, runDistChecks, runSiteChecks, runStage, summarizeBlocking, summaryLines };
@@ -4,6 +4,8 @@
4
4
 
5
5
  Release notes of `@v-office/site-checks`, newest first. Each version has its own directory.
6
6
 
7
+ - `versions/0.4.1/CHANGELOG.md`: release notes for 0.4.1
8
+ - `versions/0.4.0/CHANGELOG.md`: release notes for 0.4.0
7
9
  - `versions/0.3.3/CHANGELOG.md`: release notes for 0.3.3
8
10
  - `versions/0.3.2/CHANGELOG.md`: release notes for 0.3.2
9
11
  - `versions/0.3.1/CHANGELOG.md`: release notes for 0.3.1
@@ -4,6 +4,8 @@
4
4
 
5
5
  Migration guides of `@v-office/site-checks`, newest first. Apply them in order when skipping versions.
6
6
 
7
+ - `versions/0.4.1/MIGRATION.md`: Migration: 0.4.0 to 0.4.1
8
+ - `versions/0.4.0/MIGRATION.md`: Migration: 0.3.3 to 0.4.0
7
9
  - `versions/0.3.3/MIGRATION.md`: Migration: 0.3.2 to 0.3.3
8
10
  - `versions/0.3.2/MIGRATION.md`: Migration: 0.3.1 to 0.3.2
9
11
  - `versions/0.3.1/MIGRATION.md`: Migration: 0.3.0 to 0.3.1
@@ -0,0 +1,23 @@
1
+ # Changelog: 0.4.0
2
+
3
+ A site can exclude the findings it accepts, for every check, in `site-checks.config.json`.
4
+
5
+ ## Added
6
+
7
+ - `exclude`, by check id. `true` turns a check off for the site (the report lists it as skipped).
8
+ A list hides the findings an entry covers: a URL path (`/impressum`, the page and every page
9
+ below it, with or without a language prefix), a file or folder path (`public/brand/logo.png`,
10
+ `src/legacy/`), or `{ "path", "match", "reason" }`, where `match` is text the finding's message
11
+ contains. The README's "Excluding findings" says which to use for which check.
12
+ - The platform's dist checks read `exclude` too. `runDistChecks` takes the project `root` to read
13
+ the config from; without it, nothing is excluded, as before.
14
+ - Exported types `Exclusion` and `Exclusions`.
15
+
16
+ ## Changed
17
+
18
+ - An excluded finding is dropped before a check's status is decided: a check whose findings are
19
+ all excluded is `ok`.
20
+ - `runStage` and `runDistChecks` stop on an `exclude` that names a check this version does not
21
+ have, as on an unknown key.
22
+ - The README and the package description say what AI Studio's build does with the findings: it
23
+ reports them and deploys; no check stops a deploy. The command's exit codes stay as they were.
@@ -0,0 +1,30 @@
1
+ # Migration: 0.3.3 to 0.4.0
2
+
3
+ No changes required: `exclude` is new and optional, and the existing keys keep working.
4
+
5
+ ## 1. Upgrade
6
+
7
+ ```sh
8
+ pnpm add --save-exact --save-dev @v-office/site-checks@0.4.0
9
+ ```
10
+
11
+ ## 2. Exclude what the site accepts (optional)
12
+
13
+ ```json
14
+ {
15
+ "exclude": {
16
+ "canonical-link": ["/impressum"],
17
+ "donor-terms": [{ "match": "Bauernhof", "reason": "the customer's own farm" }]
18
+ }
19
+ }
20
+ ```
21
+
22
+ ## What changes for the site
23
+
24
+ - Add `exclude` only once AI Studio's build worker runs 0.4.0 or later. An older worker does not
25
+ know the key: it reports the stage as not started, with no checks run.
26
+ - An `exclude` naming a check id that does not exist stops `site-checks src` and `site-checks dist`
27
+ (exit code 2) and the build's stage: check the spelling against the README's table.
28
+ - What stays the same: severities, the exit codes, the report's shape, and the older keys
29
+ (`imageIgnore`, `copyExcludePaths`, `structureIgnore`, `allowDuplicateSentences`,
30
+ `consentAllowedHosts`, `factCheckAccepted`, `listingClientOnly`).
@@ -0,0 +1,9 @@
1
+ # Changelog: 0.4.1
2
+
3
+ ## Added
4
+
5
+ - `site-checks verify [--root <dir>] [--site <url>]` runs what AI Studio's build runs, in its
6
+ order, and stops at the first failure: the `src` stage, `astro check` (skipped without
7
+ `@astrojs/check`), the site's `build` script (pnpm or npm), the `dist` stage.
8
+ - Exit codes: 0 when nothing failed (warnings pass), 1 when `astro check` or the build fails or a
9
+ check with severity `error` finds something, 2 on a usage or configuration error.
@@ -0,0 +1,4 @@
1
+ # Migration: 0.4.0 to 0.4.1
2
+
3
+ No changes required. To check a push the way the build will, add the script
4
+ `"check:all": "site-checks verify"` and call `pnpm exec site-checks verify` from the pre-push hook.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-office/site-checks",
3
- "version": "0.3.3",
4
- "description": "The checks over a v-office website in two stages, `site-checks src` before the build and `site-checks dist` after it, which AI Studio's build worker runs on every build from its own pinned copy; the report has the shape of the build worker's dist-check report. A check with severity error refuses the deploy",
3
+ "version": "0.4.1",
4
+ "description": "The checks over a v-office website in two stages, `site-checks src` before the build and `site-checks dist` after it, which AI Studio's build worker runs on every build from its own pinned copy; the report has the shape of the build worker's dist-check report, and a site excludes the findings it accepts in site-checks.config.json",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
7
7
  "type": "git",