@mark1russell7/site-pages 0.3.5 → 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
@@ -77,11 +77,13 @@ The text of the problem has the element, the box, the two widths, the width of t
77
77
  a table goes out of view at 360 px: table.api-table in div.table-scroll: content of 736 px in a box of 344 px, "Note". Make the table fit, give the box the class scroll-cue, or add data-overflow-ok to the box.
78
78
  ```
79
79
 
80
- The rule for a box that scrolls examines only tables, for these reasons:
80
+ A code block gets the same problem, with the words "a code block" and "Make the lines fit".
81
81
 
82
- - A code block, a hex view, a row of tabs and a carousel are meant to scroll, and a visitor sees that they scroll.
83
- - A table in a box that scrolls looks complete on a phone, with no scroll bar. The visitor does not see the last columns.
84
- - The class `scroll-cue` shows a fade at the edge of the box, so a table in such a box does not count. The check reads the computed style of the box. A box with the class, with no animation and no background image, counts.
82
+ The rule for a box that scrolls examines only tables and code blocks (`pre`), for these reasons:
83
+
84
+ - A table or a code block in a box that scrolls looks complete on a phone, with no scroll bar. The visitor does not see the end of the lines.
85
+ - A hex view, a row of tabs and a carousel are meant to scroll, and a visitor sees that they scroll.
86
+ - The class `scroll-cue` shows a fade at the edge of the box. So a table or a code block in such a box does not count. The check reads the computed style of the box. A box with the class, with no animation and no background image, counts.
85
87
  - A false alarm costs more than a miss, because each false alarm needs an exception in the site.
86
88
 
87
89
  A table is `table`, `role="table"` or `role="grid"`. A desktop view has a scroll bar, so a table in a box that scrolls is not a problem there. `report.json` still shows the table in `measure.cut`.
@@ -217,6 +219,20 @@ For a monorepo with one version for all its packages, give `--group` and the nam
217
219
 
218
220
  The option `from` leaves out older sections. The option `fixedGroup` passes a section with no change or with only PATCH changes, because its raise comes from another package of the group.
219
221
 
222
+ ### The changelog gate
223
+
224
+ The command `build` reads each changelog with `changelogReading`. A repository puts the oldest version of its gate in its root `package.json`:
225
+
226
+ ```json
227
+ { "sitePages": { "changelogFrom": "0.1.0" } }
228
+ ```
229
+
230
+ - With the field, a fault in a section of that version or newer stops the build with code 1. The error names each section and its fault.
231
+ - Without the field, the build gives a warning with the count of the sections with a fault, and it does not fail.
232
+ - In both cases, `status.json` holds the reading in the field `changelog`, and the Status page shows the count. A reader of all the sites can thus list each repository, also a repository with no gate.
233
+
234
+ To join the gate, a repository adds the field with no change to its code. Older sections can follow older habits, so the repository picks the first version that has no fault.
235
+
220
236
  `sectionMarksBreak(section)` tells if the text of a section marks a break. The marks are the heading `### Breaking` and the words "has breaking changes". A page that counts breaks uses this function.
221
237
 
222
238
  A repository can have no changelog and no GitHub release. Then each npm version of each package of `--packages` is a release:
@@ -410,7 +426,7 @@ import "@mark1russell7/site-pages/scroll-cue.css";
410
426
  <pre class="scroll-cue">pnpm add @mark1russell7/site-pages</pre>
411
427
  ```
412
428
 
413
- The class sets `overflow-x: auto` and the background color of the box. Set `--scroll-cue-bg` to the background color of the box. In a browser with no scroll timelines, `--scroll-cue-shade` is the color of the shade:
429
+ The class sets `overflow-x: auto`. A browser with scroll timelines keeps the background of the box, so a code block keeps the color of its theme. A browser with no scroll timelines gets the background color `--scroll-cue-bg` and a shade of the color `--scroll-cue-shade`. Set `--scroll-cue-bg` to the background color of the box:
414
430
 
415
431
  ```css
416
432
  .code {
@@ -418,7 +434,7 @@ The class sets `overflow-x: auto` and the background color of the box. Set `--sc
418
434
  }
419
435
  ```
420
436
 
421
- Markdown has no way to set the class of a table. For a Markdown page, add the plugin `rehypeScrollCue` of the entry `@mark1russell7/site-pages/vite`. It gives the class, a tab stop and a label to each table:
437
+ Markdown has no way to set the class of a table or a code block. For a Markdown page, add the plugin `rehypeScrollCue` of the entry `@mark1russell7/site-pages/vite`. It gives the class and a tab stop to each table and each code block. A table also gets a label. A code block keeps a tab stop that it has:
422
438
 
423
439
  ```js
424
440
  import { rehypeScrollCue } from "@mark1russell7/site-pages/vite";
@@ -229,6 +229,47 @@ function changelogFaults(markdown, options = {}) {
229
229
  return faults;
230
230
  }
231
231
  /**
232
+ * This function reads the changelog files of a repository against the rules of a version section.
233
+ * With a `from` version, it examines the sections of that version and newer. With null, it examines all the sections.
234
+ *
235
+ * @throws RangeError when `from` is not a version
236
+ */
237
+ function changelogReading(changelogs, from) {
238
+ const core = from === null ? null : versionCore(from);
239
+ if (from !== null && core === null) throw new RangeError(`"${from}" is not a version.`);
240
+ let sections = 0;
241
+ const faults = [];
242
+ for (const { file, markdown } of changelogs) {
243
+ for (const section of versionSections(markdown)) {
244
+ const own = versionCore(section.version);
245
+ if (own !== null && (core === null || compareCores(own, core) >= 0)) sections += 1;
246
+ }
247
+ for (const fault of changelogFaults(markdown, from === null ? {} : { from })) faults.push({
248
+ file,
249
+ ...fault
250
+ });
251
+ }
252
+ return {
253
+ from,
254
+ sections,
255
+ faults
256
+ };
257
+ }
258
+ /**
259
+ * This function gives the problem of a changelog reading for the build, or null. A reading with a
260
+ * `from` version and a fault fails the build. A reading with no `from` version only reports.
261
+ */
262
+ function changelogGateProblem(reading, limit = 20) {
263
+ if (reading.from === null || reading.faults.length === 0) return null;
264
+ const lines = reading.faults.slice(0, limit).map((fault) => ` ${fault.file} ${fault.version}: ${fault.kind}${fault.statement === "" ? "" : ` ("${fault.statement.slice(0, 80)}")`}`);
265
+ const more = reading.faults.length > limit ? [` and ${reading.faults.length - limit} more`] : [];
266
+ return [
267
+ `${reading.faults.length} of ${reading.sections} version sections from ${reading.from} break the rules of a changelog section:`,
268
+ ...lines,
269
+ ...more
270
+ ].join("\n");
271
+ }
272
+ /**
232
273
  * This function gives the changes of the text of a GitHub release: one change for each top-level
233
274
  * list item. Fenced code is not read.
234
275
  */
@@ -1063,6 +1104,28 @@ function releaseReading(listed, sources, now = Date.now()) {
1063
1104
  inFlight
1064
1105
  };
1065
1106
  }
1107
+ /**
1108
+ * This function gives the oldest version that the changelog gate of a repository examines: the field
1109
+ * `sitePages.changelogFrom` of its root `package.json`. It gives null when the file or the field is not there.
1110
+ *
1111
+ * @throws ReleaseDataError when the field is not a version
1112
+ */
1113
+ function readChangelogFrom(repoDir) {
1114
+ const path = join(repoDir, "package.json");
1115
+ if (!existsSync(path)) return null;
1116
+ let manifest;
1117
+ try {
1118
+ manifest = JSON.parse(readFileSync(path, "utf8"));
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ const settings = manifest.sitePages;
1123
+ if (settings === void 0 || settings === null || typeof settings !== "object") return null;
1124
+ const from = settings.changelogFrom;
1125
+ if (from === void 0) return null;
1126
+ if (typeof from !== "string" || !/^v?\d+\.\d+\.\d+$/.test(from)) throw new ReleaseDataError(`the field sitePages.changelogFrom of package.json must be a version, for example "0.1.0", not ${JSON.stringify(from)}.`);
1127
+ return from;
1128
+ }
1066
1129
  /** The default patterns of the changelog files: the first pattern that finds a file wins. */
1067
1130
  const DEFAULT_CHANGELOGS = ["packages/*/CHANGELOG.md", "CHANGELOG.md"];
1068
1131
  /**
@@ -2369,6 +2432,20 @@ function measures(data) {
2369
2432
  const commit = link(`https://github.com/${data.source.github}/commit/${kpi.commit}`, `<code>${kpi.commit.slice(0, 7)}</code>`);
2370
2433
  return `<section class="sp-section" aria-labelledby="measures"><h2 id="measures">Measures</h2><p>${ownDates ? "The data date of the file is" : "The data of these numbers is from"} <time datetime="${escapeHtml(kpi.at)}" data-sp-data-date>${escapeHtml(longDate(kpi.at))}</time>. The build of ${commit} published them.</p>` + (engines.length > 0 ? `<p>The engines of the data: ${listText(engines.map((engine) => `<code>${escapeHtml(engine.name)}</code> ${escapeHtml(engine.version)}`))}.</p>` : "") + `<div class="sp-table-box" tabindex="0" role="region" aria-label="Measures"><table class="sp-table"><thead><tr><th scope="col">Measure</th><th scope="col">Value</th>${ownDates ? "<th scope=\"col\">Data date</th>" : ""}</tr></thead><tbody>${rows}</tbody></table></div>` + limits + "</section>";
2371
2434
  }
2435
+ /**
2436
+ * This function renders the reading of the changelogs. It shows the count of the version sections that break
2437
+ * the rules, and the version that the gate starts from. A repository with no gate sees its count, so the gap stays in view.
2438
+ */
2439
+ function changelog(data) {
2440
+ const { changelog: reading } = data;
2441
+ if (reading === void 0) return "";
2442
+ const count = reading.faults.length;
2443
+ const scope = reading.from === null ? `of the ${plural(reading.sections, "version section")} of the changelogs` : `of the ${plural(reading.sections, "version section")} from ${escapeHtml(reading.from)}`;
2444
+ const gate = reading.from === null ? "The build does not fail on a fault, because <code>package.json</code> has no field <code>sitePages.changelogFrom</code>." : `The build fails on a fault in a section from ${escapeHtml(reading.from)}, the field <code>sitePages.changelogFrom</code> of <code>package.json</code>.`;
2445
+ const shown = reading.faults.slice(0, 10);
2446
+ const list = shown.length === 0 ? "" : `<ul>${shown.map((fault) => `<li><code>${escapeHtml(fault.file)}</code> ${escapeHtml(fault.version)}: ${escapeHtml(fault.kind)}</li>`).join("")}</ul>` + (count > shown.length ? `<p class="sp-small sp-muted">The list shows the first ${shown.length}.</p>` : "");
2447
+ return `<section class="sp-section" aria-labelledby="changelog"><h2 id="changelog">Changelog</h2><p data-sp-changelog-faults="${count}">${count === 0 ? "No section" : plural(count, "section")} ${scope} ${count <= 1 ? "breaks" : "break"} the rules of a changelog section. ${gate}</p>` + list + "</section>";
2448
+ }
2372
2449
  function when(date) {
2373
2450
  const text = escapeHtml(longDate(date));
2374
2451
  return `<time datetime="${escapeHtml(date)}" title="${text}" data-sp-rel>${text}</time>`;
@@ -2505,7 +2582,7 @@ function renderStatusPage(data, options) {
2505
2582
  title: "Status",
2506
2583
  description: lead,
2507
2584
  current: "status",
2508
- main: `<h1>Status</h1><p class="sp-lead">${escapeHtml(lead)}</p><p class="sp-small sp-muted">The build reads the roadmap file and GitHub again after each commit and on a schedule.</p>` + measures(data) + (data.source.roadmap ? openWork(data) : "") + pullRequests(data) + issues(data),
2585
+ main: `<h1>Status</h1><p class="sp-lead">${escapeHtml(lead)}</p><p class="sp-small sp-muted">The build reads the roadmap file and GitHub again after each commit and on a schedule.</p>` + measures(data) + changelog(data) + (data.source.roadmap ? openWork(data) : "") + pullRequests(data) + issues(data),
2509
2586
  script: STATUS_SCRIPT
2510
2587
  }, options);
2511
2588
  }
@@ -2550,6 +2627,11 @@ async function build(options) {
2550
2627
  const [owner = "", repo = ""] = repository.split("/");
2551
2628
  const out = isAbsolute(options.out) ? options.out : resolve(repoDir, options.out);
2552
2629
  const fetcher = options.fetch ? { fetch: options.fetch } : {};
2630
+ const changelogs = readChangelogs(repoDir, options.changesets);
2631
+ const reading = changelogs.length === 0 ? void 0 : changelogReading(changelogs, readChangelogFrom(repoDir));
2632
+ const problem = reading === void 0 ? null : changelogGateProblem(reading);
2633
+ if (problem !== null) throw new ReleaseDataError(problem);
2634
+ if (reading !== void 0 && reading.from === null && reading.faults.length > 0) warn(`${reading.faults.length} of ${reading.sections} version sections of the changelogs break the rules of a changelog section. The build does not fail, because package.json has no field sitePages.changelogFrom.`);
2553
2635
  const releases = await readReleases({
2554
2636
  repoDir,
2555
2637
  repository,
@@ -2564,19 +2646,19 @@ async function build(options) {
2564
2646
  });
2565
2647
  const kpiPath = join(out, KPI_FILE);
2566
2648
  const kpi = existsSync(kpiPath) ? readKpi(readFileSync(kpiPath, "utf8"), Date.parse(now)) : void 0;
2567
- const board = await readStatusBoard({
2568
- repoDir,
2569
- roadmap: options.roadmap ?? null,
2570
- owner,
2571
- repo,
2572
- token: options.token,
2573
- commit,
2574
- generatedAt: now,
2575
- ...fetcher
2576
- });
2577
- const status = kpi === void 0 ? board : {
2578
- ...board,
2579
- kpi
2649
+ const status = {
2650
+ ...await readStatusBoard({
2651
+ repoDir,
2652
+ roadmap: options.roadmap ?? null,
2653
+ owner,
2654
+ repo,
2655
+ token: options.token,
2656
+ commit,
2657
+ generatedAt: now,
2658
+ ...fetcher
2659
+ }),
2660
+ ...kpi === void 0 ? {} : { kpi },
2661
+ ...reading === void 0 ? {} : { changelog: reading }
2580
2662
  };
2581
2663
  if (!status.github.available) warn(`the status page has no GitHub data: ${status.github.reason ?? "no reason"}.`);
2582
2664
  const files = [];
@@ -2732,6 +2814,6 @@ async function runCli(argv, io) {
2732
2814
  throw error;
2733
2815
  }
2734
2816
  }
2735
- export { githubReleases as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, releaseReading as G, mergeReleases as H, readStatusBoard as I, GITHUB_GRAPHQL as J, globFiles as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, githubReleaseLag as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogs as U, ReleaseDataError as V, readReleases as W, githubGreenRun as X, checkStateOf as Y, githubOpenWork as Z, renderReleasesPage as _, runCli as a, headingAnchor as at, releaseSummary as b, STATUS_SCRIPT as c, sectionMarksBreak as ct, renderStatusPage as d, greenRunOf as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, firstSentence as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, statusLead as m, UsageError as n, changelogFaults as nt, TYPESCRIPT_PROBE as o, parseChangelog as ot, slugOf as p, GITHUB_API as q, build as r, changelogVersions as rt, probeScript as s, releaseBodyEntries as st, HELP as t, releaseLagOf as tt, openGroups as u, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2817
+ export { githubReleaseLag as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, readReleases as G, mergeReleases as H, readStatusBoard as I, GITHUB_API as J, releaseReading as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, githubOpenWork as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogFrom as U, ReleaseDataError as V, readChangelogs as W, checkStateOf as X, GITHUB_GRAPHQL as Y, githubGreenRun as Z, renderReleasesPage as _, runCli as a, changelogReading as at, releaseSummary as b, STATUS_SCRIPT as c, headingAnchor as ct, renderStatusPage as d, sectionMarksBreak as dt, githubReleases as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, changelogGateProblem as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, parseChangelog as lt, statusLead as m, UsageError as n, releaseLagOf as nt, TYPESCRIPT_PROBE as o, changelogVersions as ot, slugOf as p, globFiles as q, build as r, changelogFaults as rt, probeScript as s, firstSentence as st, HELP as t, greenRunOf as tt, openGroups as u, releaseBodyEntries as ut, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2736
2818
 
2737
2819
  //# sourceMappingURL=build.js.map