@v-office/site-checks 0.2.0 → 0.2.2
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 +27 -27
- package/dist/astro.mjs +1 -1
- package/dist/dist-checks.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{report-xp_FHnYb.mjs → report-Dg5jtgGy.mjs} +111 -58
- package/instructions/CHANGELOG.md +2 -0
- package/instructions/MIGRATION.md +2 -0
- package/instructions/versions/0.2.1/CHANGELOG.md +18 -0
- package/instructions/versions/0.2.1/MIGRATION.md +9 -0
- package/instructions/versions/0.2.2/CHANGELOG.md +15 -0
- package/instructions/versions/0.2.2/MIGRATION.md +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,33 +62,33 @@ Severities are fixed by the package: a site configures data, never whether a che
|
|
|
62
62
|
|
|
63
63
|
## The checks
|
|
64
64
|
|
|
65
|
-
| id | Severity | What it refuses or reports
|
|
66
|
-
| --------------------- | -------- |
|
|
67
|
-
| `html-comments` | error | An HTML comment (`<!-- … -->`) in `src/**/*.{astro,tsx,jsx,md,mdx,html}`: Astro passes it into the built page, readable with View Source.
|
|
68
|
-
| `view-source` | error | A developer's note a visitor can read with View Source: an HTML comment in a built page (
|
|
69
|
-
| `donor-terms` | error | A configured term in the visible text, the title, inline scripts and styles (JSON-LD) or an attribute of a built page, in a built file name, or in the shipped JS and CSS. Skipped without configured terms.
|
|
70
|
-
| `optimize-deps` | warning | A runtime package (`dependencies`) imported from `src/` that is not listed, with the exact specifier, in `vite.optimizeDeps.include`. Vite discovers it mid-session instead and re-bundles every dependency.
|
|
71
|
-
| `sync-once` | warning | An inline content loader in `src/content.config.ts` that fetches the PMS without the `CONTENT_SYNC_TOKEN` reuse idiom: `astro check` and `astro build` each run it, twice per build.
|
|
72
|
-
| `consent-gate` | error | A third-party `<script src>` or `<iframe src>` outside the consent kit's `ConsentEmbed` frame, loading before consent; a vendor in `ENABLED_VENDOR_IDS` that is not `approved` in `consent-registry.snapshot.json`. Skipped without `src/lib/consent/`.
|
|
73
|
-
| `image-formats` | error | A raster image under `public/` without an `.avif` sibling.
|
|
74
|
-
| `feed-image-formats` | warning | A feed photo from the vOffice image hosts requested as JPEG or PNG in `src`, `srcset` or `poster`; a warning because the photos come from the PMS feed.
|
|
75
|
-
| `listing-noindex` | error | A page that lists rentals (the search page's `data-prerendered-results` container, the `SearchResults` island, or `listingPages`) that is noindex. Waits while every page is noindex.
|
|
76
|
-
| `listing-links` | warning | A page that lists rentals that carries no links to rentals in its HTML, so a crawler without JavaScript sees an empty list. Runs once some listing has links or the build has more than ten pages; a warning because the links come from the PMS feed.
|
|
77
|
-
| `sitemap-noindex` | error | A sitemap entry whose page says noindex or is not in the build; an `llms.txt` link to a page that is not there. Skipped without a sitemap and `llms.txt`.
|
|
78
|
-
| `page-heads` | warning | On indexable pages: a title over 60 characters, a description empty or over 160, a title or description another page repeats. A missing one is the build worker's `page-metadata`.
|
|
79
|
-
| `wiring` | error | A component carrying a configured hook's marker whose initializer nothing calls (`section`: the component itself; `global`: anything in `src/`), through leaves marked `@bound-by-parent <init>`; a kept text gone from its file. Comments are stripped first. Skipped without `wiring`.
|
|
80
|
-
| `unused-initializers` | warning | An `init*` exported from `src/scripts/*.ts` that nothing calls. Skipped without `src/scripts/`.
|
|
81
|
-
| `v9-hub-filters` | warning | v9 only (`CMS_BACKEND=v9` in the build's env or `.env` / `.env.production`, else AI Studio's `PMS_BACKEND=v9`): a Hub filter the site's search needs that the be-on! Hub does not serve, asked through the site's own `website-sdk hub-filters check`; a Hub that cannot be asked. A warning: the outcome is the Hub's data.
|
|
82
|
-
| `canonical-link` | error | On the launched site (a production `site`, some indexable page): an indexable page without an absolute `<link rel="canonical">`.
|
|
83
|
-
| `open-graph` | warning | On the launched site: an indexable page without an absolute `og:url` and `og:image`.
|
|
84
|
-
| `trailing-slash` | warning | On the launched site: `trailingSlash` is not `"never"`.
|
|
85
|
-
| `v9-production-hub` | error | v9 only, on the launched site: the build's env does not call the production Hub (`CMS_STAGE=production` or the production Hub URLs); a committed `.env.local`; a committed `HUB_API_KEY` equal to `.env.local`'s. Waits for a production `site` and an indexable page.
|
|
86
|
-
| `page-structure` | warning | One `<h1>`, no skipped heading level, no flood of `<h3>` under few `<h2>`, a `<main>`, `alt` on every image, a label on every control, a caption and scoped `<th>` on every table.
|
|
87
|
-
| `load-order` | warning | At start: an on-demand library (map, chart, 3D) in the start-up code, a start-up chunk over 150 KB compressed, photos after the first in card swipe strips with a URL, a first-paint photo from 100 KB up in one size only, a preloaded swap face without a `size-adjust` stand-in.
|
|
88
|
-
| `banned-copy` | warning | A `bannedCopy` wording in a page's visible text. Skipped without configured wordings.
|
|
89
|
-
| `duplicate-sentences` | warning | The same sentence rendered twice on one page. Waits while every page is noindex.
|
|
90
|
-
| `quote-sources` | warning | A `<blockquote>` not word for word in `quoteSources`; a configured source that is missing. Skipped without sources.
|
|
91
|
-
| `rental-facts` | warning | On rental pages (the rental blocks' `data-rental-stats` / `data-rental-description` markers): the fact row against the same number in the owner's German description; a perk line of `src/data/perks.ts` a unit's amenities do not back.
|
|
65
|
+
| id | Severity | What it refuses or reports | How to fix |
|
|
66
|
+
| --------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `html-comments` | error | An HTML comment (`<!-- … -->`) in `src/**/*.{astro,tsx,jsx,md,mdx,html}`: Astro passes it into the built page, readable with View Source. | `{/* … */}` in `.astro` and JSX markup, `//` in frontmatter, remove it from Markdown. |
|
|
68
|
+
| `view-source` | error | A developer's note a visitor can read with View Source: an HTML comment in a built page (framework markers are allowed), a comment in an inline `<script>`, `<style>` or event handler that is also in `src/` or `public/`, a comment in CSS or a line comment in JS copied from `public/`, a source map or a reference to one in any shipped file. Bundled JS and CSS are not scanned for comments. | Remove the comment; turn source maps off in the build. |
|
|
69
|
+
| `donor-terms` | error | A configured term in the visible text, the title, inline scripts and styles (JSON-LD) or an attribute of a built page, in a built file name, or in the shipped JS and CSS. Skipped without configured terms. | Replace the term; list the template site's terms in `donorTerms`. |
|
|
70
|
+
| `optimize-deps` | warning | A runtime package (`dependencies`) imported from `src/` that is not listed, with the exact specifier, in `vite.optimizeDeps.include`. Vite discovers it mid-session instead and re-bundles every dependency. | Add the specifier to `vite.optimizeDeps.include` in `astro.config`, or to `optimizeDepsIgnore` when only server-side code uses it. |
|
|
71
|
+
| `sync-once` | warning | An inline content loader in `src/content.config.ts` that fetches the PMS without the `CONTENT_SYNC_TOKEN` reuse idiom: `astro check` and `astro build` each run it, twice per build. | Keep the token in the store's meta (`meta.get`) and reuse the entries (`store.keys()`) when it matches. |
|
|
72
|
+
| `consent-gate` | error | A third-party `<script src>` or `<iframe src>` outside the consent kit's `ConsentEmbed` frame, loading before consent; a vendor in `ENABLED_VENDOR_IDS` that is not `approved` in `consent-registry.snapshot.json`. Skipped without `src/lib/consent/`. | Frame it with `ConsentEmbed`, or register the vendor so the kit injects it after consent; list a consent-free host in `consentAllowedHosts`. |
|
|
73
|
+
| `image-formats` | error | A raster image under `public/` without an `.avif` sibling. | Encode the AVIF (or list the file in `imageIgnore`). |
|
|
74
|
+
| `feed-image-formats` | warning | A feed photo from the vOffice image hosts requested as JPEG or PNG in `src`, `srcset` or `poster`; a warning because the photos come from the PMS feed. | Pass feed photos through `webpUrl()`. |
|
|
75
|
+
| `listing-noindex` | error | A page that lists rentals (the search page's `data-prerendered-results` container, the `SearchResults` island, or `listingPages`) that is noindex. Waits while every page is noindex. | Take the page out of the noindex routes. |
|
|
76
|
+
| `listing-links` | warning | A page that lists rentals that carries no links to rentals in its HTML, so a crawler without JavaScript sees an empty list. Runs once some listing has links or the build has more than ten pages; a warning because the links come from the PMS feed. | Render the list server-side, or list the page in `listingClientOnly` with the reason. |
|
|
77
|
+
| `sitemap-noindex` | error | A sitemap entry whose page says noindex or is not in the build; an `llms.txt` link to a page that is not there. Skipped without a sitemap and `llms.txt`. | Make the sitemap filter and the noindex routes agree; fix the link. |
|
|
78
|
+
| `page-heads` | warning | On indexable pages: a title over 60 characters, a description empty or over 160, a title or description another page repeats. A missing one is the build worker's `page-metadata`. | Shorten; give each page its own. |
|
|
79
|
+
| `wiring` | error | A component carrying a configured hook's marker whose initializer nothing calls (`section`: the component itself; `global`: anything in `src/`), through leaves marked `@bound-by-parent <init>`; a kept text gone from its file. Comments are stripped first. Skipped without `wiring`. | Call the initializer, mark the leaf `@bound-by-parent`, or put the kept text back. |
|
|
80
|
+
| `unused-initializers` | warning | An `init*` exported from `src/scripts/*.ts` that nothing calls. Skipped without `src/scripts/`. | Wire the feature, or delete the leftover. |
|
|
81
|
+
| `v9-hub-filters` | warning | v9 only (`CMS_BACKEND=v9` in the build's env or `.env` / `.env.production`, else AI Studio's `PMS_BACKEND=v9`): a Hub filter the site's search needs that the be-on! Hub does not serve, asked through the site's own `website-sdk hub-filters check`; a Hub that cannot be asked. A warning: the outcome is the Hub's data. | Add the entry in the Hub (`website-sdk hub-filters request`), or drop it from the SDK options. |
|
|
82
|
+
| `canonical-link` | error | On the launched site (a production `site`, some indexable page): an indexable page without an absolute `<link rel="canonical">`. | Build it from the Astro `site` and the page path. |
|
|
83
|
+
| `open-graph` | warning | On the launched site: an indexable page without an absolute `og:url` and `og:image`. | Add them, absolute. |
|
|
84
|
+
| `trailing-slash` | warning | On the launched site: `trailingSlash` is not `"never"`. | Set `trailingSlash: "never"`; write internal links without a trailing slash. |
|
|
85
|
+
| `v9-production-hub` | error | v9 only, on the launched site: the build's env does not call the production Hub (`CMS_STAGE=production` or the production Hub URLs); a committed `.env.local`; a committed `HUB_API_KEY` equal to `.env.local`'s. Waits for a production `site` and an indexable page. | Set the production stage or URLs and the customer's production key; untrack `.env.local`. |
|
|
86
|
+
| `page-structure` | warning | One `<h1>`, no skipped heading level, no flood of `<h3>` under few `<h2>`, a `<main>`, `alt` on every image, a label on every control, a caption and scoped `<th>` on every table. | Fix the component where a fault repeats; decline a rule in `structureIgnore`. |
|
|
87
|
+
| `load-order` | warning | At start: an on-demand library (map, chart, 3D) in the start-up code, a start-up chunk over 150 KB compressed, photos after the first in card swipe strips with a URL, a first-paint photo from 100 KB up in one size only, a preloaded swap face without a `size-adjust` stand-in. | `import()` on demand; first slide only; width `srcset`; a `local()` stand-in. |
|
|
88
|
+
| `banned-copy` | warning | A `bannedCopy` wording in a page's visible text. Skipped without configured wordings. | Reword. |
|
|
89
|
+
| `duplicate-sentences` | warning | The same sentence rendered twice on one page. Waits while every page is noindex. | Remove one, or list it in `allowDuplicateSentences`. |
|
|
90
|
+
| `quote-sources` | warning | A `<blockquote>` not word for word in `quoteSources`; a configured source that is missing. Skipped without sources. | Quote the source exactly; restore the step that writes the source. |
|
|
91
|
+
| `rental-facts` | warning | On rental pages (the rental blocks' `data-rental-stats` / `data-rental-description` markers): the fact row against the same number in the owner's German description; a perk line of `src/data/perks.ts` a unit's amenities do not back. | The customer corrects the PMS; a confirmed one goes into `factCheckAccepted`. |
|
|
92
92
|
|
|
93
93
|
A check that does not apply to the site reports `skipped`; a check that fails itself reports
|
|
94
94
|
`failed` and never blocks.
|
package/dist/astro.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as writeSiteChecksReport, d as runSiteChecks, i as summaryLines, l as blockingResults, m as checks, n as refusalMessage, p as loadOptions } from "./report-
|
|
1
|
+
import { a as writeSiteChecksReport, d as runSiteChecks, i as summaryLines, l as blockingResults, m as checks, n as refusalMessage, p as loadOptions } from "./report-Dg5jtgGy.mjs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
//#region src/astro.ts
|
|
4
4
|
/**
|
package/dist/dist-checks.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-Dg5jtgGy.mjs";
|
|
2
2
|
//#region src/distChecks/insecureResources.ts
|
|
3
3
|
/** `<link>` relations the browser fetches as a subresource; canonical,
|
|
4
4
|
* alternate, preconnect and friends are hints or metadata, not loads. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as writeSiteChecksReport, c as MAX_PATH_CHARS, d as runSiteChecks, f as CONFIG_FILE, i as summaryLines, l as blockingResults, m as checks, n as refusalMessage, o as MAX_FINDINGS_PER_CHECK, p as loadOptions, r as summarizeBlocking, s as MAX_MESSAGE_CHARS, t as SITE_CHECKS_FILE } from "./report-
|
|
1
|
+
import { a as writeSiteChecksReport, c as MAX_PATH_CHARS, d as runSiteChecks, f as CONFIG_FILE, i as summaryLines, l as blockingResults, m as checks, n as refusalMessage, o as MAX_FINDINGS_PER_CHECK, p as loadOptions, r as summarizeBlocking, s as MAX_MESSAGE_CHARS, t as SITE_CHECKS_FILE } from "./report-Dg5jtgGy.mjs";
|
|
2
2
|
export { CONFIG_FILE, MAX_FINDINGS_PER_CHECK, MAX_MESSAGE_CHARS, MAX_PATH_CHARS, SITE_CHECKS_FILE, blockingResults, checks, loadOptions, refusalMessage, runSiteChecks, summarizeBlocking, summaryLines, writeSiteChecksReport };
|
|
@@ -536,7 +536,7 @@ const donorTerms = {
|
|
|
536
536
|
//#region src/checks/htmlComments.ts
|
|
537
537
|
/** Astro passes an HTML comment in a template straight into the built page, where a visitor reads
|
|
538
538
|
* it with View Source. Markdown pages too. */
|
|
539
|
-
const SOURCE_EXTENSIONS$
|
|
539
|
+
const SOURCE_EXTENSIONS$2 = /* @__PURE__ */ new Set([
|
|
540
540
|
".astro",
|
|
541
541
|
".tsx",
|
|
542
542
|
".jsx",
|
|
@@ -551,7 +551,7 @@ const htmlComments = {
|
|
|
551
551
|
severity: "error",
|
|
552
552
|
begin: (ctx) => ({ finish: () => {
|
|
553
553
|
const findings = [];
|
|
554
|
-
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS$
|
|
554
|
+
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS$2)) {
|
|
555
555
|
const text = ctx.readSource(file);
|
|
556
556
|
let index = text.indexOf("<!--");
|
|
557
557
|
while (index !== -1) {
|
|
@@ -1025,7 +1025,7 @@ const loadOrder = {
|
|
|
1025
1025
|
};
|
|
1026
1026
|
//#endregion
|
|
1027
1027
|
//#region src/checks/optimizeDeps.ts
|
|
1028
|
-
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1028
|
+
const SOURCE_EXTENSIONS$1 = /* @__PURE__ */ new Set([
|
|
1029
1029
|
".ts",
|
|
1030
1030
|
".tsx",
|
|
1031
1031
|
".js",
|
|
@@ -1059,7 +1059,7 @@ const optimizeDeps = {
|
|
|
1059
1059
|
const ignored = new Set(ctx.options.optimizeDepsIgnore);
|
|
1060
1060
|
const runtime = ctx.packageJson.dependencies;
|
|
1061
1061
|
const importers = /* @__PURE__ */ new Map();
|
|
1062
|
-
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS)) {
|
|
1062
|
+
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS$1)) {
|
|
1063
1063
|
const text = ctx.readSource(file);
|
|
1064
1064
|
for (const match of text.matchAll(IMPORT_RE)) {
|
|
1065
1065
|
const [, typeOnly, fromSpecifier, dynamicSpecifier] = match;
|
|
@@ -1850,10 +1850,24 @@ const v9HubFilters = {
|
|
|
1850
1850
|
* or a keyword that takes an expression. Never after a lone `<` or `>`, so markup paths stay text,
|
|
1851
1851
|
* and never after `)`, where a division is the common case. */
|
|
1852
1852
|
const BEFORE_REGEX = /* @__PURE__ */ new Set("(,=:[!&|?{};");
|
|
1853
|
-
const KEYWORD_BEFORE = /\b(?:return|typeof|case|do|else|in|of|void|yield|await|delete|new)
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1853
|
+
const KEYWORD_BEFORE = /\b(?:return|typeof|case|do|else|in|of|void|yield|await|delete|new)$/;
|
|
1854
|
+
/** Longer than the longest keyword, so the tail holds the character before it. */
|
|
1855
|
+
const KEYWORD_TAIL = 8;
|
|
1856
|
+
const SPACE = /\s/;
|
|
1857
|
+
/** A line comment ends at any line terminator, not only LF. */
|
|
1858
|
+
const LINE_END = /[\n\r\u2028\u2029]/g;
|
|
1859
|
+
/** Whether a `/` at `at` starts a regular expression, judged by the last code before it: the text
|
|
1860
|
+
* read backwards past whitespace and the comments found so far. Only that short tail is read, so a
|
|
1861
|
+
* multi-megabyte bundle scans in linear time. */
|
|
1862
|
+
const startsRegex = (text, at, comments) => {
|
|
1863
|
+
let end = at;
|
|
1864
|
+
let c = comments.length - 1;
|
|
1865
|
+
while (end > 0) if (c >= 0 && comments[c].end === end) end = comments[c--].start;
|
|
1866
|
+
else if (SPACE.test(text[end - 1])) end -= 1;
|
|
1867
|
+
else break;
|
|
1868
|
+
if (end === 0) return true;
|
|
1869
|
+
const last = text[end - 1];
|
|
1870
|
+
return BEFORE_REGEX.has(last) || last === ">" && text[end - 2] === "=" || KEYWORD_BEFORE.test(text.slice(Math.max(0, end - KEYWORD_TAIL), end));
|
|
1857
1871
|
};
|
|
1858
1872
|
/** The index past a regular expression literal starting at `start`, its flags included: `/` inside
|
|
1859
1873
|
* a character class or after `\` does not end it. A newline first means it was no literal: the
|
|
@@ -1874,8 +1888,8 @@ const regexEnd = (text, start) => {
|
|
|
1874
1888
|
}
|
|
1875
1889
|
return start + 1;
|
|
1876
1890
|
};
|
|
1877
|
-
|
|
1878
|
-
|
|
1891
|
+
/** Every comment in the text, in order, with its position. Everything else is code, as written. */
|
|
1892
|
+
const findComments = (text) => {
|
|
1879
1893
|
const comments = [];
|
|
1880
1894
|
let i = 0;
|
|
1881
1895
|
const n = text.length;
|
|
@@ -1884,51 +1898,44 @@ const scan = (text) => {
|
|
|
1884
1898
|
while (i < n) {
|
|
1885
1899
|
const c = text[i];
|
|
1886
1900
|
if (templates.length > 0 && templates.at(-1) === -1) {
|
|
1887
|
-
if (c === "\\")
|
|
1888
|
-
|
|
1889
|
-
i += 2;
|
|
1890
|
-
} else if (c === "`") {
|
|
1901
|
+
if (c === "\\") i += 2;
|
|
1902
|
+
else if (c === "`") {
|
|
1891
1903
|
templates.pop();
|
|
1892
|
-
out += c;
|
|
1893
1904
|
i += 1;
|
|
1894
|
-
} else if (
|
|
1905
|
+
} else if (c === "$" && text[i + 1] === "{") {
|
|
1895
1906
|
templates[templates.length - 1] = depth;
|
|
1896
1907
|
depth += 1;
|
|
1897
|
-
out += "${";
|
|
1898
1908
|
i += 2;
|
|
1899
|
-
} else
|
|
1900
|
-
out += c;
|
|
1901
|
-
i += 1;
|
|
1902
|
-
}
|
|
1909
|
+
} else i += 1;
|
|
1903
1910
|
continue;
|
|
1904
1911
|
}
|
|
1905
|
-
if (c === "\\")
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1912
|
+
if (c === "\\") i += 2;
|
|
1913
|
+
else if (c === "/" && text[i + 1] === "/") {
|
|
1914
|
+
LINE_END.lastIndex = i;
|
|
1915
|
+
const end = LINE_END.exec(text)?.index ?? n;
|
|
1916
|
+
comments.push({
|
|
1917
|
+
start: i,
|
|
1918
|
+
end,
|
|
1919
|
+
text: text.slice(i, end)
|
|
1920
|
+
});
|
|
1921
|
+
i = end;
|
|
1922
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
1914
1923
|
const close = text.indexOf("*/", i + 2);
|
|
1915
1924
|
const end = close === -1 ? n : close + 2;
|
|
1916
|
-
comments.push(
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
out += text.slice(i, end);
|
|
1925
|
+
comments.push({
|
|
1926
|
+
start: i,
|
|
1927
|
+
end,
|
|
1928
|
+
text: text.slice(i, end)
|
|
1929
|
+
});
|
|
1922
1930
|
i = end;
|
|
1923
|
-
} else if (c === "
|
|
1931
|
+
} else if (c === "/" && startsRegex(text, i, comments)) i = regexEnd(text, i);
|
|
1932
|
+
else if (c === "'" || c === "\"") {
|
|
1924
1933
|
let j = i + 1;
|
|
1925
1934
|
while (j < n && text[j] !== c && text[j] !== "\n") j += text[j] === "\\" ? 2 : 1;
|
|
1926
1935
|
if (j < n && text[j] === c) j += 1;
|
|
1927
|
-
out += text.slice(i, j);
|
|
1928
1936
|
i = j;
|
|
1929
1937
|
} else if (c === "`") {
|
|
1930
1938
|
templates.push(-1);
|
|
1931
|
-
out += c;
|
|
1932
1939
|
i += 1;
|
|
1933
1940
|
} else {
|
|
1934
1941
|
if (c === "{") depth += 1;
|
|
@@ -1936,19 +1943,24 @@ const scan = (text) => {
|
|
|
1936
1943
|
depth -= 1;
|
|
1937
1944
|
if (templates.length > 0 && templates.at(-1) === depth) templates[templates.length - 1] = -1;
|
|
1938
1945
|
}
|
|
1939
|
-
out += c;
|
|
1940
1946
|
i += 1;
|
|
1941
1947
|
}
|
|
1942
1948
|
}
|
|
1943
|
-
return
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1949
|
+
return comments;
|
|
1950
|
+
};
|
|
1951
|
+
/** The text with its comments blanked: a line comment becomes a space, a block comment a space
|
|
1952
|
+
* and its newlines. */
|
|
1953
|
+
const stripComments = (text) => {
|
|
1954
|
+
let out = "";
|
|
1955
|
+
let from = 0;
|
|
1956
|
+
for (const { start, end, text: comment } of findComments(text)) {
|
|
1957
|
+
out += `${text.slice(from, start)} ${"\n".repeat((comment.match(/\n/g) ?? []).length)}`;
|
|
1958
|
+
from = end;
|
|
1959
|
+
}
|
|
1960
|
+
return out + text.slice(from);
|
|
1947
1961
|
};
|
|
1948
|
-
/** The text with its comments blanked. */
|
|
1949
|
-
const stripComments = (text) => scan(text).code;
|
|
1950
1962
|
/** Every comment in the text, as written. */
|
|
1951
|
-
const jsComments = (text) =>
|
|
1963
|
+
const jsComments = (text) => findComments(text).map((c) => c.text);
|
|
1952
1964
|
//#endregion
|
|
1953
1965
|
//#region src/checks/viewSource.ts
|
|
1954
1966
|
/** Comments the frameworks themselves write into static HTML, and no developer did: Astro's
|
|
@@ -1981,22 +1993,58 @@ const isFrameworkComment = (data) => {
|
|
|
1981
1993
|
/** Licence banners and bundler annotations survive minification on purpose and say nothing. */
|
|
1982
1994
|
const LEGAL_BLOCK_COMMENT = /^\/\*\s*[!@#]|@license|@preserve/;
|
|
1983
1995
|
const BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1984
|
-
/** A line comment at the start of a line. `//` elsewhere is usually a URL. `//#` and `//!` are
|
|
1985
|
-
* directives (source maps, legal comments), reported or allowed on their own. */
|
|
1986
|
-
const LINE_COMMENT = /^[ \t]*\/\/(?![#!])(.*)$/gm;
|
|
1987
1996
|
const SOURCE_MAP_URL = /(?:\/\/|\/\*)# sourceMappingURL=/;
|
|
1988
|
-
/**
|
|
1997
|
+
/** Line-comment directives: a source-map pointer (reported on its own) and a legal comment. */
|
|
1989
1998
|
const DIRECTIVE = /^\/\/[#!]/;
|
|
1999
|
+
const LINE_BREAK = /* @__PURE__ */ new Set("\n\r\u2028\u2029");
|
|
1990
2000
|
const excerpt = (text) => {
|
|
1991
2001
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
1992
2002
|
return flat.length > 80 ? `${flat.slice(0, 79)}…` : flat;
|
|
1993
2003
|
};
|
|
1994
2004
|
const blockComments = (text) => (text.match(BLOCK_COMMENT) ?? []).filter((comment) => !LEGAL_BLOCK_COMMENT.test(comment));
|
|
1995
|
-
|
|
2005
|
+
/** Line comments at the start of a line, read as JavaScript: a `//` line inside a string or
|
|
2006
|
+
* template literal (a bundled library's shader source or CSS-in-JS) is text. `//` after code on
|
|
2007
|
+
* the same line is not read, and `//#` and `//!` are directives (source maps, legal comments),
|
|
2008
|
+
* reported or allowed on their own. */
|
|
2009
|
+
const lineComments = (text) => findComments(text).filter(({ start, text: comment }) => {
|
|
2010
|
+
if (!comment.startsWith("//") || DIRECTIVE.test(comment)) return false;
|
|
2011
|
+
let k = start;
|
|
2012
|
+
while (k > 0 && (text[k - 1] === " " || text[k - 1] === " ")) k -= 1;
|
|
2013
|
+
return k === 0 || LINE_BREAK.has(text[k - 1]);
|
|
2014
|
+
}).map((comment) => comment.text);
|
|
2015
|
+
/** The site's own text files, where a comment it wrote into an inline script, style or handler
|
|
2016
|
+
* lives. */
|
|
2017
|
+
const SOURCE_EXTENSIONS = new Set(".astro .tsx .jsx .ts .js .mjs .cjs .css .scss .vue .md .mdx .html .json .svg".split(" "));
|
|
2018
|
+
/** Below this length a comment's inner text appears in almost any source by accident; such a
|
|
2019
|
+
* comment is matched whole, with its markers. */
|
|
2020
|
+
const MIN_INNER_TEXT = 8;
|
|
2021
|
+
const collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
2022
|
+
/** Whether the site wrote a comment found in an inline script, style or handler: its text,
|
|
2023
|
+
* whitespace collapsed, appears in a file under `src/` or `public/`. A comment in none of them
|
|
2024
|
+
* was rendered by a dependency during the build (c15t's theme `<style>` in the consent kit) and
|
|
2025
|
+
* is not the site's to remove. The files are read once, on the first inline comment. */
|
|
2026
|
+
const siteWrote = (ctx) => {
|
|
2027
|
+
let corpus;
|
|
2028
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2029
|
+
return (comment) => {
|
|
2030
|
+
let wrote = seen.get(comment);
|
|
2031
|
+
if (wrote === void 0) {
|
|
2032
|
+
corpus ??= [...filesUnder(ctx.srcDir, SOURCE_EXTENSIONS), ...filesUnder(ctx.publicDir, SOURCE_EXTENSIONS)].map((file) => collapse(ctx.readSource(file))).join("\n");
|
|
2033
|
+
const inner = collapse(comment.startsWith("//") ? comment.slice(2) : comment.slice(2, -2));
|
|
2034
|
+
wrote = corpus.includes(inner.length < MIN_INNER_TEXT ? collapse(comment) : inner);
|
|
2035
|
+
seen.set(comment, wrote);
|
|
2036
|
+
}
|
|
2037
|
+
return wrote;
|
|
2038
|
+
};
|
|
2039
|
+
};
|
|
1996
2040
|
/** What a visitor can read with View Source, and no developer meant for them: comments in the
|
|
1997
|
-
* built pages
|
|
1998
|
-
*
|
|
1999
|
-
* JS
|
|
2041
|
+
* built pages; comments in their inline scripts, styles and event handlers that the site's own
|
|
2042
|
+
* source contains (one a dependency rendered during the build is not the site's); comments in
|
|
2043
|
+
* the JS and CSS copied verbatim from `public/` (line comments at a line start in JS, block
|
|
2044
|
+
* comments in CSS); source maps and references to them in every shipped file. JS and CSS the
|
|
2045
|
+
* bundler produced (`_astro/…`) are not scanned for comments: Vite minifies them and keeps only
|
|
2046
|
+
* licence banners, so what still looks like one is text inside a string (a bundled library's
|
|
2047
|
+
* shader or styles). */
|
|
2000
2048
|
const viewSource = {
|
|
2001
2049
|
id: "view-source",
|
|
2002
2050
|
title: "Developer notes visible in View Source",
|
|
@@ -2008,21 +2056,25 @@ const viewSource = {
|
|
|
2008
2056
|
path,
|
|
2009
2057
|
message: `${what}: "${excerpt(text)}"`
|
|
2010
2058
|
});
|
|
2059
|
+
const wrote = siteWrote(ctx);
|
|
2060
|
+
const reportInline = (path, what, comment) => {
|
|
2061
|
+
if (wrote(comment)) report(path, what, comment);
|
|
2062
|
+
};
|
|
2011
2063
|
const visit = (page) => {
|
|
2012
2064
|
for (const comment of page.comments()) if (!isFrameworkComment(comment)) report(page.path, "HTML comment in the page", comment);
|
|
2013
2065
|
for (const el of page.document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
|
|
2014
2066
|
if (!name.startsWith("on")) continue;
|
|
2015
2067
|
const code = el.getAttribute(name) ?? "";
|
|
2016
2068
|
const what = `comment in an inline ${name} handler`;
|
|
2017
|
-
for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment))
|
|
2069
|
+
for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment)) reportInline(page.path, what, comment);
|
|
2018
2070
|
}
|
|
2019
2071
|
for (const el of page.document.querySelectorAll("script, style")) {
|
|
2020
2072
|
const text = el.textContent ?? "";
|
|
2021
2073
|
const what = `comment in an inline <${el.tagName.toLowerCase()}>`;
|
|
2022
|
-
for (const comment of blockComments(text))
|
|
2074
|
+
for (const comment of blockComments(text)) reportInline(page.path, what, comment);
|
|
2023
2075
|
if (el.tagName === "SCRIPT") {
|
|
2024
2076
|
if (SOURCE_MAP_URL.test(text)) report(page.path, "source map reference in an inline <script>", text);
|
|
2025
|
-
for (const comment of lineComments(text))
|
|
2077
|
+
for (const comment of lineComments(text)) reportInline(page.path, what, comment);
|
|
2026
2078
|
}
|
|
2027
2079
|
}
|
|
2028
2080
|
};
|
|
@@ -2040,6 +2092,7 @@ const viewSource = {
|
|
|
2040
2092
|
if (!isJs && !isCss) continue;
|
|
2041
2093
|
const text = ctx.read(file);
|
|
2042
2094
|
if (SOURCE_MAP_URL.test(text)) report(file, "source map reference", "sourceMappingURL");
|
|
2095
|
+
if (!fs.existsSync(path.join(ctx.publicDir, file))) continue;
|
|
2043
2096
|
if (isCss) for (const comment of blockComments(text)) report(file, "comment in shipped CSS", comment);
|
|
2044
2097
|
if (isJs) for (const comment of lineComments(text)) report(file, "comment in shipped JS", comment);
|
|
2045
2098
|
}
|
|
@@ -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.2.2/CHANGELOG.md`: release notes for 0.2.2
|
|
8
|
+
- `versions/0.2.1/CHANGELOG.md`: release notes for 0.2.1
|
|
7
9
|
- `versions/0.2.0/CHANGELOG.md`: release notes for 0.2.0
|
|
8
10
|
- `versions/0.1.0/CHANGELOG.md`: release notes for 0.1.0
|
|
9
11
|
- `versions/0.0.1/CHANGELOG.md`: release notes for 0.0.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.2.2/MIGRATION.md`: Migration: 0.2.1 to 0.2.2
|
|
8
|
+
- `versions/0.2.1/MIGRATION.md`: Migration: 0.2.0 to 0.2.1
|
|
7
9
|
- `versions/0.2.0/MIGRATION.md`: Migration: 0.1.0 to 0.2.0
|
|
8
10
|
- `versions/0.1.0/MIGRATION.md`: Migration: 0.1.0
|
|
9
11
|
- `versions/0.0.1/MIGRATION.md`: Migration: 0.0.1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog: 0.2.1
|
|
2
|
+
|
|
3
|
+
A fix for sites that bundle a library with `//` lines inside its strings, such as Mermaid:
|
|
4
|
+
`view-source` refused their build over text that is no comment.
|
|
5
|
+
|
|
6
|
+
## Changed
|
|
7
|
+
|
|
8
|
+
- `view-source` scans shipped JS and CSS for comments only in files copied as they are from
|
|
9
|
+
`public/`. JS and CSS the bundler produced (`_astro/…`) are minified, which strips every comment
|
|
10
|
+
but licence banners, and are no longer scanned for comments, so a bundled library can no longer
|
|
11
|
+
refuse the build. Source maps and `sourceMappingURL` references are still refused in every
|
|
12
|
+
shipped file, bundled or not.
|
|
13
|
+
|
|
14
|
+
## Fixed
|
|
15
|
+
|
|
16
|
+
- `view-source` no longer reports `//` lines inside the string and template literals of JS copied
|
|
17
|
+
from `public/` and of inline `<script>`s: JS is read as JavaScript. A line comment at the start
|
|
18
|
+
of a line is still refused.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog: 0.2.2
|
|
2
|
+
|
|
3
|
+
A fix for consent-kit sites: `view-source` refused their build over a comment that c15t writes into
|
|
4
|
+
the theme `<style>` it renders on every page, which the site never wrote and cannot remove.
|
|
5
|
+
|
|
6
|
+
## Changed
|
|
7
|
+
|
|
8
|
+
- `view-source` refuses a comment in an inline `<script>`, `<style>` or event handler only when the
|
|
9
|
+
site's own source contains it: its text, whitespace aside, appears in a file under `src/` or
|
|
10
|
+
`public/`. A comment a dependency renders during the build, such as c15t's theme style in the
|
|
11
|
+
consent kit (`/* Utility class to disable transitions during theme switching */`), no longer
|
|
12
|
+
refuses the build. A comment you wrote into an inline script, style or handler is still
|
|
13
|
+
refused; remove it from your source.
|
|
14
|
+
- HTML comments in the built pages, comments in JS and CSS copied from `public/`, and source maps
|
|
15
|
+
are refused as before.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-office/site-checks",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
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
6
|
"repository": {
|