@v-office/site-checks 0.2.1 → 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 CHANGED
@@ -65,7 +65,7 @@ Severities are fixed by the package: a site configures data, never whether a che
65
65
  | id | Severity | What it refuses or reports | How to fix |
66
66
  | --------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
67
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 (the frameworks' own markers are allowed), a comment in an inline `<script>`, `<style>` or event handler, 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 (`_astro/…`) are minified and not scanned for comments. | Remove the comment; turn source maps off in the build. |
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
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
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
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. |
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-DI-5w16K.mjs";
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
  /**
@@ -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-DI-5w16K.mjs";
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-DI-5w16K.mjs";
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$1 = /* @__PURE__ */ new Set([
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$1)) {
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;
@@ -2012,12 +2012,39 @@ const lineComments = (text) => findComments(text).filter(({ start, text: comment
2012
2012
  while (k > 0 && (text[k - 1] === " " || text[k - 1] === " ")) k -= 1;
2013
2013
  return k === 0 || LINE_BREAK.has(text[k - 1]);
2014
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
+ };
2015
2040
  /** What a visitor can read with View Source, and no developer meant for them: comments in the
2016
- * built pages and in their inline scripts, styles and event handlers; comments in the JS and CSS
2017
- * copied verbatim from `public/` (line comments at a line start in JS, block comments in CSS);
2018
- * source maps and references to them in every shipped file. JS and CSS the bundler produced
2019
- * (`_astro/…`) are not scanned for comments: Vite minifies them and keeps only licence banners,
2020
- * so what still looks like one is text inside a string (a bundled library's shader or styles). */
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). */
2021
2048
  const viewSource = {
2022
2049
  id: "view-source",
2023
2050
  title: "Developer notes visible in View Source",
@@ -2029,21 +2056,25 @@ const viewSource = {
2029
2056
  path,
2030
2057
  message: `${what}: "${excerpt(text)}"`
2031
2058
  });
2059
+ const wrote = siteWrote(ctx);
2060
+ const reportInline = (path, what, comment) => {
2061
+ if (wrote(comment)) report(path, what, comment);
2062
+ };
2032
2063
  const visit = (page) => {
2033
2064
  for (const comment of page.comments()) if (!isFrameworkComment(comment)) report(page.path, "HTML comment in the page", comment);
2034
2065
  for (const el of page.document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
2035
2066
  if (!name.startsWith("on")) continue;
2036
2067
  const code = el.getAttribute(name) ?? "";
2037
2068
  const what = `comment in an inline ${name} handler`;
2038
- for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment)) report(page.path, what, comment);
2069
+ for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment)) reportInline(page.path, what, comment);
2039
2070
  }
2040
2071
  for (const el of page.document.querySelectorAll("script, style")) {
2041
2072
  const text = el.textContent ?? "";
2042
2073
  const what = `comment in an inline <${el.tagName.toLowerCase()}>`;
2043
- for (const comment of blockComments(text)) report(page.path, what, comment);
2074
+ for (const comment of blockComments(text)) reportInline(page.path, what, comment);
2044
2075
  if (el.tagName === "SCRIPT") {
2045
2076
  if (SOURCE_MAP_URL.test(text)) report(page.path, "source map reference in an inline <script>", text);
2046
- for (const comment of lineComments(text)) report(page.path, what, comment);
2077
+ for (const comment of lineComments(text)) reportInline(page.path, what, comment);
2047
2078
  }
2048
2079
  }
2049
2080
  };
@@ -4,6 +4,7 @@
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
7
8
  - `versions/0.2.1/CHANGELOG.md`: release notes for 0.2.1
8
9
  - `versions/0.2.0/CHANGELOG.md`: release notes for 0.2.0
9
10
  - `versions/0.1.0/CHANGELOG.md`: release notes for 0.1.0
@@ -4,6 +4,7 @@
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
7
8
  - `versions/0.2.1/MIGRATION.md`: Migration: 0.2.0 to 0.2.1
8
9
  - `versions/0.2.0/MIGRATION.md`: Migration: 0.1.0 to 0.2.0
9
10
  - `versions/0.1.0/MIGRATION.md`: Migration: 0.1.0
@@ -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.
@@ -0,0 +1,9 @@
1
+ # Migration: 0.2.1 to 0.2.2
2
+
3
+ No changes required.
4
+
5
+ ## 1. Upgrade
6
+
7
+ ```sh
8
+ pnpm add --save-exact --save-dev @v-office/site-checks@0.2.2
9
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v-office/site-checks",
3
- "version": "0.2.1",
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": {