@v-office/site-checks 0.0.0 → 0.1.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.
@@ -0,0 +1,167 @@
1
+ import { n as ResolvedOptions, r as SiteChecksOptions } from "./options-XdHJYRcb.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
+ };
90
+ options: ResolvedOptions;
91
+ /** Files under `srcDir` with one of the extensions (`.astro`, …), as absolute paths. */
92
+ sourceFiles: (extensions: ReadonlySet<string>) => string[];
93
+ readSource: (absolute: string) => string;
94
+ /** A finding path for a file of the project: relative to `root`, posix. */
95
+ rel: (absolute: string) => string;
96
+ packageJson: {
97
+ dependencies: Record<string, string>;
98
+ devDependencies: Record<string, string>;
99
+ };
100
+ };
101
+ /** One check on one build. The runner parses the HTML pages one after the other and shows each to
102
+ * `visit`; a page is gone after its visit, so a check keeps what it needs from it, never the page.
103
+ * `finish` runs after the last page. */
104
+ type CheckRun = {
105
+ visit?: (page: Page) => void;
106
+ finish: () => Finding[] | Promise<Finding[]>;
107
+ };
108
+ type Check<Context> = {
109
+ /** Stable kebab-case id; the controller stores results by it. Unique across both families: the
110
+ * worker merges them into one report (a test holds the rule). */
111
+ id: string;
112
+ title: string;
113
+ /** Fixed here, never by a site. A check whose outcome depends on PMS data, not on the site's
114
+ * code, must be `warning`: an `error` also refuses the nightly deploy builds. */
115
+ severity: Severity;
116
+ /** Starts the check, or returns `null` when it does not apply to this site. Deterministic,
117
+ * touches no network. */
118
+ begin: (ctx: Context) => CheckRun | null;
119
+ };
120
+ type SiteCheck = Check<SiteCheckContext>;
121
+ type DistCheck = Check<DistContext>;
122
+ //#endregion
123
+ //#region src/report.d.ts
124
+ /** The report's file name under `dist/`. The build worker reads it after `astro build`, merges it
125
+ * with its own checks and never uploads it (it names source paths and configured terms). */
126
+ declare const SITE_CHECKS_FILE = "site-checks.json";
127
+ declare const writeSiteChecksReport: (distDir: string, report: CheckReport) => void;
128
+ /** One line per check that found something or could not run, for the build log. */
129
+ declare const summaryLines: (report: CheckReport) => string[];
130
+ /** The error `astro build` ends with when a check refuses: every failing check, its first findings,
131
+ * and where the whole report is. */
132
+ declare const refusalMessage: (report: CheckReport) => string;
133
+ /** One line naming what refused the build, for the studio: the failing checks and their counts. */
134
+ declare const summarizeBlocking: (report: CheckReport) => string;
135
+ //#endregion
136
+ //#region src/context.d.ts
137
+ type ContextInput = {
138
+ root: string;
139
+ srcDir: string;
140
+ publicDir: string;
141
+ distDir: string;
142
+ config: SiteCheckContext["config"];
143
+ options: ResolvedOptions;
144
+ };
145
+ //#endregion
146
+ //#region src/runner.d.ts
147
+ /** Findings kept per check in the report; the rest is counted in `omitted`. */
148
+ declare const MAX_FINDINGS_PER_CHECK = 25;
149
+ /** The controller's `siteCheckReportSchema` accepts a finding message of at most 2000 characters
150
+ * and a path of at most 1000, and skips a report it cannot read as a whole: one over-long finding
151
+ * (a check that quotes a long URL or template expression) must not cost the whole report. */
152
+ declare const MAX_MESSAGE_CHARS = 2000;
153
+ declare const MAX_PATH_CHARS = 1000;
154
+ type RunInput = {
155
+ root: string;
156
+ distDir: string;
157
+ srcDir?: string | undefined;
158
+ publicDir?: string | undefined;
159
+ config?: Partial<ContextInput["config"]> | undefined;
160
+ options?: SiteChecksOptions | undefined;
161
+ };
162
+ /** Runs every site check over the project and its build. */
163
+ declare const runSiteChecks: (input: RunInput, list?: readonly SiteCheck[]) => Promise<CheckReport>;
164
+ /** Results with status `error`: the only ones that refuse a build. */
165
+ declare const blockingResults: (report: CheckReport) => CheckResult[];
166
+ //#endregion
167
+ 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 };
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ <!-- generated by `node .github/release/cli.mts index`; do not edit by hand -->
4
+
5
+ Release notes of `@v-office/site-checks`, newest first. Each version has its own directory.
6
+
7
+ - `versions/0.1.0/CHANGELOG.md`: release notes for 0.1.0
8
+ - `versions/0.0.1/CHANGELOG.md`: release notes for 0.0.1
@@ -0,0 +1,8 @@
1
+ # Migration
2
+
3
+ <!-- generated by `node .github/release/cli.mts index`; do not edit by hand -->
4
+
5
+ Migration guides of `@v-office/site-checks`, newest first. Apply them in order when skipping versions.
6
+
7
+ - `versions/0.1.0/MIGRATION.md`: Migration: 0.1.0
8
+ - `versions/0.0.1/MIGRATION.md`: Migration: 0.0.1
@@ -0,0 +1,4 @@
1
+ # Changelog: 0.0.1
2
+
3
+ Holds the package's name and its trusted publisher on npm until the checks move in. It
4
+ exports nothing; there is nothing to install it for yet.
@@ -0,0 +1,9 @@
1
+ # Migration: 0.0.1
2
+
3
+ ## 1. Upgrade
4
+
5
+ ```sh
6
+ pnpm add @v-office/site-checks@0.0.1
7
+ ```
8
+
9
+ No changes required.
@@ -0,0 +1,79 @@
1
+ # Changelog: 0.1.0
2
+
3
+ The first release with checks (0.0.1 only held the package name on npm). `@v-office/site-checks` runs checks over a site's source and built output at
4
+ the end of `astro build`, writes `dist/site-checks.json` and refuses the build when a check with
5
+ severity `error` finds something. It takes over the site-shipping guards of the sites' git commit
6
+ gate, as a pinned package that runs wherever the site is built. A refused build never goes live;
7
+ a build with warnings does, and the findings show up in AI Studio with the build.
8
+
9
+ ## Added
10
+
11
+ - The `siteChecks()` Astro integration (`@v-office/site-checks/astro`). It runs after the build,
12
+ prints one line per check that found something, and ends the build with
13
+ `[site-checks] build refused: …` naming the failing checks and their first findings when a check
14
+ with severity `error` found something.
15
+ - `site-checks.config.json` at the project root: the site's data for the checks (`donorTerms`,
16
+ `optimizeDepsIgnore`, `imageIgnore`, `feedImagePatterns`, `listingPages`, `listingClientOnly`,
17
+ `consentAllowedHosts`). The same keys can be given as `siteChecks({ … })` options, which win over
18
+ the file. A file that is not valid JSON fails the build before it starts.
19
+ - `html-comments` (error): an HTML comment in `src/**/*.{astro,tsx,jsx,md,mdx,html}`. Astro passes
20
+ it into the built page, where a visitor reads it with View Source. Use `{/* … */}` in `.astro`
21
+ and JSX markup, `//` in frontmatter, and remove it from Markdown. The finding names the file and
22
+ line.
23
+ - `view-source` (error): a developer's note a visitor can read with View Source. An HTML comment
24
+ in a built page (Astro's, React's and Vue's own markers are allowed), a comment in an inline
25
+ `<script>` or `<style>`, a comment in shipped CSS, a line comment in shipped JS, a source map file
26
+ or a reference to one. Remove the comment; turn source maps off in the build.
27
+ - `donor-terms` (error): a term from `donorTerms` in the visible text, the title, an inline script
28
+ or style (JSON-LD included) or an attribute of a built page, in a built file name, or in the
29
+ shipped JS and CSS. Terms are matched case-insensitively
30
+ with whitespace collapsed. Without configured terms the check reports `skipped`: list the
31
+ template site's brand, people, places, phone, email, domain and asset names.
32
+ - `optimize-deps` (warning): a runtime package imported from `src/` that is not listed, with the
33
+ exact specifier, in `vite.optimizeDeps.include`. Vite discovers it mid-session instead and
34
+ re-bundles every dependency, which leaves an open preview asking for files that no longer exist.
35
+ Add the specifier to `vite.optimizeDeps.include`, or to `optimizeDepsIgnore` when only
36
+ server-side code uses it.
37
+ - `sync-once` (warning): an inline content loader in `src/content.config.ts` that fetches the PMS
38
+ without the `CONTENT_SYNC_TOKEN` reuse idiom. `astro check` and `astro build` each run the
39
+ loader, so it syncs twice per build against a rate-limited PMS. Keep the token in the store's
40
+ meta (`meta.get`) and reuse the entries (`store.keys()`) when it matches.
41
+ - `consent-gate` (error): a third-party `<script src>` or `<iframe src>` in a built page outside
42
+ the consent kit's `ConsentEmbed` frame, so it loads before consent; or a vendor in
43
+ `ENABLED_VENDOR_IDS` (`src/data/consent.ts`) that is not `approved` in
44
+ `src/data/consent-registry.snapshot.json`. Frame it with `ConsentEmbed`, or register the vendor so
45
+ the kit injects it after consent; a consent-free host goes into `consentAllowedHosts`. Skipped in
46
+ a project without `src/lib/consent/`.
47
+ - `image-formats` (error): a raster image (`jpg`, `jpeg`, `png`, `webp`) under `public/` without an
48
+ `.avif` sibling, unless listed in `imageIgnore`. Encode the AVIF.
49
+ - `feed-image-formats` (warning): a feed photo from the vOffice image hosts requested as JPEG or
50
+ PNG in an `img`, `source` or `poster`. Pass feed photos through `webpUrl()`. A warning, because
51
+ the photos come from the PMS feed. `feedImagePatterns` overrides the host patterns; a pattern
52
+ that is not a valid regular expression fails the build before it starts.
53
+ - `listing-noindex` (error): a page that lists rentals is noindex, so the rentals it lists are
54
+ hidden with it. A listing page is one with the search page's `data-prerendered-results`
55
+ container, the `SearchResults` island, or a path in `listingPages`. Waits while every page is
56
+ noindex (before launch). Take the page out of the noindex routes.
57
+ - `listing-links` (warning): a listing page carries no links to rentals in its built HTML, so a
58
+ crawler running no JavaScript sees an empty list. Only the list's own links count, not the
59
+ header, navigation or footer. Runs once some listing has links or the build has more than ten
60
+ pages (a starter with an empty feed). A warning, because the links come from the PMS feed: an
61
+ empty or booked-out feed must not stop the builds that update prices. Render the list
62
+ server-side, or list the page in `listingClientOnly` with the reason.
63
+ - `sitemap-noindex` (error): a sitemap entry whose page says noindex or is not in the build, a
64
+ sitemap the index names that is not there, an `llms.txt` link to a page that is not served.
65
+ Skipped when the build has neither a sitemap nor `llms.txt`.
66
+ - `page-heads` (warning): on indexable pages, a title over 60 characters, a description that is
67
+ empty or over 160, a title or description another indexable page repeats. A missing title or
68
+ description is the build worker's `page-metadata` finding.
69
+ - `dist/site-checks.json`: the report, in the shape of the build worker's dist-check report
70
+ (`ranAt`, `durationMs`, `results` with `id`, `status`, `findings`, `omitted`). At most 25
71
+ findings per check are kept. The build worker reads and never uploads it.
72
+ - `runSiteChecks()` from `@v-office/site-checks` runs the checks programmatically; without a
73
+ `dist/`, the checks that need built pages report `skipped`.
74
+ - `@v-office/site-checks/dist-checks`: the checks AI Studio's build worker runs over `dist/` after
75
+ every build of every website (`site-manifest`, `key-pages`, `not-found-beacon`,
76
+ `internal-links`, `legal-pages`, `page-metadata`, `placeholder-content`, `insecure-resources`,
77
+ `sitemap`, all warnings), the same checks the worker runs today; it switches to this export
78
+ after the release. A site does nothing for them: the integration does not run them, and their
79
+ findings show up next to the site checks'.
@@ -0,0 +1,61 @@
1
+ # Migration: 0.1.0
2
+
3
+ ## 1. Install
4
+
5
+ ```sh
6
+ pnpm add --save-exact --save-dev @v-office/site-checks@0.1.0
7
+ ```
8
+
9
+ ## 2. Add the integration
10
+
11
+ ```js
12
+ // astro.config.mjs
13
+ import { siteManifest } from "@v-office/site-manifest/astro";
14
+ import { siteChecks } from "@v-office/site-checks/astro";
15
+
16
+ export default defineConfig({
17
+ integrations: [siteManifest(), siteChecks()],
18
+ });
19
+ ```
20
+
21
+ ## 3. Configure the site's data
22
+
23
+ Create `site-checks.config.json` at the project root:
24
+
25
+ ```json
26
+ {
27
+ "donorTerms": ["Brisenhof", "Familie Petersen", "+49 4651 123", "fewo-brisenhof.de"],
28
+ "optimizeDepsIgnore": [],
29
+ "imageIgnore": ["public/brand/logo.png"],
30
+ "listingClientOnly": []
31
+ }
32
+ ```
33
+
34
+ - `donorTerms`: the terms of the template site this site was started from, as plain strings,
35
+ one entry per spelling (the phone number with and without spaces). A site that already carries
36
+ `scripts/donor-terms.sh` moves its terms here.
37
+ - `optimizeDepsIgnore`: packages that only server-side code imports (a content loader's SDK, for
38
+ example), so `optimize-deps` does not ask for them in `vite.optimizeDeps.include`.
39
+ - `imageIgnore`: the lines of `scripts/image-check.ignore`, rasters that ship without an AVIF on
40
+ purpose.
41
+ - `listingClientOnly`: the entries of `scripts/listing-links.allow`, as `{ "path", "reason" }`.
42
+ - `listingPages`, `consentAllowedHosts`, `feedImagePatterns`: only when the defaults do not fit;
43
+ the README describes them.
44
+
45
+ ## 4. Build once and read the report
46
+
47
+ ```sh
48
+ pnpm build
49
+ cat dist/site-checks.json
50
+ ```
51
+
52
+ Fix what the checks with severity `error` refuse (the finding says how), then build again.
53
+ `optimize-deps`, `sync-once`, `feed-image-formats`, `listing-links` and `page-heads` findings are
54
+ warnings: the build goes through.
55
+
56
+ ## What stays the same
57
+
58
+ - The git commit gate (`.githooks/pre-commit`) keeps running as before; this package does not
59
+ touch it. Its site-shipping guards now also run inside every `astro build`, with the same
60
+ outcome wherever the site is built.
61
+ - `@v-office/site-manifest` and the rest of the build are unchanged.
package/package.json CHANGED
@@ -1,9 +1,53 @@
1
1
  {
2
2
  "name": "@v-office/site-checks",
3
- "version": "0.0.0",
4
- "description": "Placeholder that holds the name on npm until the first release",
3
+ "version": "0.1.0",
4
+ "description": "Build-time checks for the sites: runs inside `astro build`, writes dist/site-checks.json in the shape of the build worker's dist-check report, and refuses the build when a check with severity error finds something. The site-shipping guards of the commit gate, pinned and run where the site is built",
5
5
  "license": "UNLICENSED",
6
- "repository": { "type": "git", "url": "git+https://github.com/vofficeGmbh/ai-studio.git", "directory": "packages/site-checks" },
7
- "files": ["README.md"],
8
- "publishConfig": { "access": "public" }
9
- }
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vofficeGmbh/ai-studio.git",
9
+ "directory": "packages/site-checks"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "instructions"
15
+ ],
16
+ "type": "module",
17
+ "types": "./dist/index.d.mts",
18
+ "exports": {
19
+ ".": "./dist/index.mjs",
20
+ "./astro": "./dist/astro.mjs",
21
+ "./dist-checks": "./dist/dist-checks.mjs",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "linkedom": "0.18.13"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "26.5.1",
32
+ "astro": "7.3.2",
33
+ "oxfmt": "0.67.0",
34
+ "oxlint": "1.82.0",
35
+ "tsdown": "0.23.0",
36
+ "typescript": "7.0.2",
37
+ "vitest": "^5.0.0"
38
+ },
39
+ "engines": {
40
+ "node": "^22.0.0 || ^24.0.0 || ^25.0.0 || >=26.0.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsdown",
44
+ "dev": "tsdown --watch",
45
+ "typecheck": "tsc --noEmit",
46
+ "lint": "oxlint .",
47
+ "lint:fix": "oxlint --fix .",
48
+ "fmt": "oxfmt",
49
+ "fmt:check": "oxfmt --check",
50
+ "check": "pnpm run typecheck && pnpm run lint && pnpm run fmt:check",
51
+ "test": "vitest run"
52
+ }
53
+ }