@mark1russell7/site-pages 0.2.26 → 0.3.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 +14 -5
- package/build/chunks/build.js +114 -22
- package/build/chunks/build.js.map +1 -1
- package/build/chunks/data-stamp.js +21 -7
- package/build/chunks/data-stamp.js.map +1 -1
- package/build/chunks/freshness.d.ts +23 -4
- package/build/chunks/freshness.d.ts.map +1 -1
- package/build/chunks/freshness.js +50 -11
- package/build/chunks/freshness.js.map +1 -1
- package/build/cli.js +1 -1
- package/build/index.d.ts +37 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/vite.d.ts +1 -1
- package/build/vite.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,16 +161,18 @@ The gate has three rules. A fault of one rule gives the exit code 1.
|
|
|
161
161
|
2. The data of a page is at most 3 days old (`MAX_DATA_AGE_DAYS`), or a run on newer engines is in flight. The stamp of that run is at most 3 days old, so an old stamp does not hold the gate open.
|
|
162
162
|
3. The engines of the newest run are at most 1 minor version behind npm at the start of the run (`MAX_MINORS_BEHIND`). A release during a long run does not fail the gate.
|
|
163
163
|
|
|
164
|
-
Stamps that pass also show one failing case for each page, in the log of each build. A measured page must fail one day after its limit. A
|
|
164
|
+
Stamps that pass also show one failing case for each page, in the log of each build. A measured page must fail one day after its limit, and after the start of its limit. A study with no limit must fail before the date of its run. A page with no failing case gives the exit code 1, so each site that uses the gate shows that the gate holds it.
|
|
165
165
|
|
|
166
166
|
Two fields of a stamp change the age rule:
|
|
167
167
|
|
|
168
|
-
- `"study": true` marks a
|
|
169
|
-
- `"
|
|
168
|
+
- `"study": true` marks a study of the versions of its runs. The rule 3 does not apply. A study has a `limit`, or it has the field `noLimit`. Each other study fails the gate.
|
|
169
|
+
- `"noLimit"` is for a study that no scheduled run can refresh: `{ "reproduce": "The code of the study is gone.", "today": "The page tells of one day." }`. The first text tells why no run of the current code can reproduce the numbers. It names the subject of the study, pinned to an exact version. The second text tells why the page claims nothing about today. The stamp line shows both, and tells that the page is a fixed study of that version.
|
|
170
|
+
- `"limit"` sets a longer age limit: `{ "days": 7, "reason": "The scan is weekly.", "workflow": ".github/workflows/scan.yml" }`. The stamp line shows the limit and the reason. The schedule of that workflow must meet the limit, or the gate fails. A limit with no schedule fails. A limit over 14 days (`MAX_LIMIT_DAYS_WITHOUT_RULING`) also needs a `ruling`, a public https link for that site. A study has the same line, and its limit is at most 30 days (`MAX_STUDY_LIMIT_DAYS`), also with a ruling. Each run of the study names the full `commit` of the code that ran. A monthly line has a gap of 31 days, so it fails a limit of 30.
|
|
171
|
+
- `"startsAt"` in a limit is the time at which the age rule and the commit rule start. The schedule rule applies at once. A site removes the field at the first green read of its workflow. The gate refuses a time after 2026-12-07 (`LAST_LIMIT_START`), so each limit turns on by that date.
|
|
170
172
|
|
|
171
173
|
When npm does not answer, the gate prints the rule 3 under `Not run` and does not fail. A workflow turns the gate on with the input `data-stamps` of `reusable-pages.yml`. A site with its own Pages workflow uses the action `data-stamps` of the template. The gate then runs from the template commit, so it needs no install.
|
|
172
174
|
|
|
173
|
-
`renderDataStamp(stamp)` gives the line that the page shows with its data: the run, its date, its engine versions and the run in flight.
|
|
175
|
+
`renderDataStamp(stamp)` gives the line that the page shows with its data: the run, its date, its engine versions and the run in flight. The line also shows the age of the oldest run at the build.
|
|
174
176
|
|
|
175
177
|
A Vite site uses the plugin `siteStamps` from `@mark1russell7/site-pages/vite`. Give the stamps, or a function that reads them from the record of the run. The plugin replaces `<!-- data-stamp -->` in each measured page. It also adds `data-stamps.json` to the built site. So the page and the gate read one record:
|
|
176
178
|
|
|
@@ -360,7 +362,7 @@ The functions of the command are also in the package:
|
|
|
360
362
|
| `versionCommitTime(repoDir, file)` | The time of the commit that set the version of a `package.json`, for the version in flight |
|
|
361
363
|
| `changelogVersions(markdown)` | The versions of the headings of a changelog |
|
|
362
364
|
| `readStatusBoard(options)` | The status data of a repository on disk, with GitHub |
|
|
363
|
-
| `githubReleases`, `githubOpenWork`, `npmPublishTimes` | The data of one source. After an error, each function gives `{ available: false, reason }`. It does not throw. |
|
|
365
|
+
| `githubReleases`, `githubOpenWork`, `githubGreenRun`, `githubReleaseLag`, `npmPublishTimes` | The data of one source. After an error, each function gives `{ available: false, reason }`. It does not throw. |
|
|
364
366
|
| `renderReleasesPage(releases, options)`, `renderStatusPage(data, options)` | The HTML of a page |
|
|
365
367
|
| `timelineLayout(releases, { width })` | The positions of the marks of the timeline |
|
|
366
368
|
|
|
@@ -488,6 +490,13 @@ interface KpiFile {
|
|
|
488
490
|
- A site with no Vite build calls `writeKpi(out, input)` from the root entry, before `site-pages build`.
|
|
489
491
|
- `site-pages build` reads the file from the output folder. It adds the file to `data/status.json`, and the Status page shows the measures, the data date and the engines.
|
|
490
492
|
|
|
493
|
+
Two functions read a measure from GitHub at the build. Each result has the `at` of its data. Without a token, the result has only a reason, so leave the measure out.
|
|
494
|
+
|
|
495
|
+
| Function | Measure |
|
|
496
|
+
| --- | --- |
|
|
497
|
+
| `githubGreenRun({ owner, repo, token, workflow })` | The scheduled runs of a workflow that passed in a row, from the newest run |
|
|
498
|
+
| `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the branch after the newest release of the tag prefix. Drafts and pre-releases do not count. |
|
|
499
|
+
|
|
491
500
|
## The shell of a site
|
|
492
501
|
|
|
493
502
|
The shell is the part of a page that is not its content. The package has two parts of the shell, and each part is optional.
|
package/build/chunks/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as headCommit, B as versionOfTag, E as readKpi, I as npmPublishTimes, L as compareVersions, M as isShallow, N as originRepository, R as kindOf, S as KpiError, _ as listText, b as KPI_FILE, g as link, h as inlineMarkdown, j as headingDate, k as gitTagDates, m as escapeHtml, v as plural, z as parseVersion } from "./freshness.js";
|
|
2
2
|
import { stripTypeScriptTypes } from "node:module";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, isAbsolute, join, posix, resolve } from "node:path";
|
|
@@ -426,38 +426,36 @@ async function githubOpenWork(options) {
|
|
|
426
426
|
return failure(error, timeoutMs);
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
-
/** This function gives the URL of the
|
|
430
|
-
function
|
|
429
|
+
/** This function gives the URL of the page with the relation `rel` from a `Link` header of GitHub, or null. */
|
|
430
|
+
function linkedPage(link, rel) {
|
|
431
431
|
if (!link) return null;
|
|
432
432
|
for (const part of link.split(",")) {
|
|
433
|
-
const match = /<([^>]+)>\s*;\s*rel="
|
|
434
|
-
if (match?.[1]) return match[1];
|
|
433
|
+
const match = /<([^>]+)>\s*;\s*rel="([a-z]+)"/.exec(part);
|
|
434
|
+
if (match?.[1] && match[2] === rel) return match[1];
|
|
435
435
|
}
|
|
436
436
|
return null;
|
|
437
437
|
}
|
|
438
|
+
const restHeaders = (token) => ({
|
|
439
|
+
accept: "application/vnd.github+json",
|
|
440
|
+
authorization: `Bearer ${token}`,
|
|
441
|
+
"user-agent": USER_AGENT,
|
|
442
|
+
"x-github-api-version": "2022-11-28"
|
|
443
|
+
});
|
|
438
444
|
/**
|
|
439
|
-
* This function reads the published releases
|
|
440
|
-
* It
|
|
441
|
-
* It does not throw.
|
|
442
|
-
*
|
|
443
|
-
* @remarks The function reads 100 releases on each page, and at most `maxPages` pages (default 10).
|
|
445
|
+
* This function reads the published releases, the newest first, and stops after the first release for which `enough` is true.
|
|
446
|
+
* It reads 100 releases on each page, and at most `maxPages` pages.
|
|
444
447
|
*/
|
|
445
|
-
async function
|
|
448
|
+
async function readReleasePages(options, enough) {
|
|
446
449
|
const stop = precheck(options);
|
|
447
450
|
if (stop) return stop;
|
|
448
|
-
const { owner, repo, token, endpoint = GITHUB_API, maxPages = 10, timeoutMs = 15e3 } = options;
|
|
451
|
+
const { owner, repo, token = "", endpoint = GITHUB_API, maxPages = 10, timeoutMs = 15e3 } = options;
|
|
449
452
|
const fetcher = options.fetch ?? globalThis.fetch;
|
|
450
453
|
const releases = [];
|
|
451
454
|
let url = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/releases?per_page=100`;
|
|
452
455
|
try {
|
|
453
456
|
for (let page = 0; url !== null && page < maxPages; page++) {
|
|
454
457
|
const response = await fetcher(url, {
|
|
455
|
-
headers:
|
|
456
|
-
accept: "application/vnd.github+json",
|
|
457
|
-
authorization: `Bearer ${token}`,
|
|
458
|
-
"user-agent": USER_AGENT,
|
|
459
|
-
"x-github-api-version": "2022-11-28"
|
|
460
|
-
},
|
|
458
|
+
headers: restHeaders(token),
|
|
461
459
|
signal: AbortSignal.timeout(timeoutMs)
|
|
462
460
|
});
|
|
463
461
|
if (response.status === 404) return {
|
|
@@ -477,16 +475,21 @@ async function githubReleases(options) {
|
|
|
477
475
|
const release = object(value);
|
|
478
476
|
const tag = release["tag_name"];
|
|
479
477
|
if (release["draft"] === true || typeof tag !== "string") continue;
|
|
480
|
-
|
|
478
|
+
const entry = {
|
|
481
479
|
tag,
|
|
482
480
|
name: text(release["name"]) || tag,
|
|
483
481
|
body: text(release["body"]),
|
|
484
482
|
publishedAt: text(release["published_at"]) || text(release["created_at"]),
|
|
485
483
|
url: text(release["html_url"]),
|
|
486
484
|
prerelease: release["prerelease"] === true
|
|
487
|
-
}
|
|
485
|
+
};
|
|
486
|
+
releases.push(entry);
|
|
487
|
+
if (enough(entry)) return {
|
|
488
|
+
available: true,
|
|
489
|
+
releases
|
|
490
|
+
};
|
|
488
491
|
}
|
|
489
|
-
url =
|
|
492
|
+
url = linkedPage(response.headers.get("link"), "next");
|
|
490
493
|
}
|
|
491
494
|
return {
|
|
492
495
|
available: true,
|
|
@@ -497,6 +500,95 @@ async function githubReleases(options) {
|
|
|
497
500
|
}
|
|
498
501
|
}
|
|
499
502
|
/**
|
|
503
|
+
* This function reads the published releases of a repository with the REST API, the newest first.
|
|
504
|
+
* It skips the drafts. It gives `{ available: false, reason }` without a token or after an error.
|
|
505
|
+
* It does not throw.
|
|
506
|
+
*
|
|
507
|
+
* @remarks The function reads 100 releases on each page, and at most `maxPages` pages (default 10).
|
|
508
|
+
*/
|
|
509
|
+
async function githubReleases(options) {
|
|
510
|
+
return readReleasePages(options, () => false);
|
|
511
|
+
}
|
|
512
|
+
const DAY_MS$1 = 864e5;
|
|
513
|
+
/**
|
|
514
|
+
* This function gives the age in days of the oldest commit after a release, rounded to 2 decimals. It gives 0 when no commit
|
|
515
|
+
* follows the release.
|
|
516
|
+
*
|
|
517
|
+
* @param oldest - The commit date of the oldest commit after the release, or undefined for no commit.
|
|
518
|
+
* @param now - The time of the read, as an ISO date.
|
|
519
|
+
*/
|
|
520
|
+
function releaseLagOf(oldest, now) {
|
|
521
|
+
if (oldest === void 0) return 0;
|
|
522
|
+
const days = (Date.parse(now) - Date.parse(oldest)) / DAY_MS$1;
|
|
523
|
+
return Number.isFinite(days) ? Math.max(0, Math.round(days * 100) / 100) : NaN;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* This function reads how many days a branch is ahead of its newest release. That is the age of the oldest commit of the branch
|
|
527
|
+
* after the newest release whose tag starts with `tagPrefix`. It skips drafts and pre-releases, because a pre-release is not the
|
|
528
|
+
* version that most users get. It gives `{ available: false, reason }` without a token, after an error, or with no such release.
|
|
529
|
+
*
|
|
530
|
+
* @remarks The function reads the releases until it finds one, at most `maxPages` pages of 100 (default 10). It then reads one
|
|
531
|
+
* commit on each page of the branch since that release, and asks GitHub for the last page only.
|
|
532
|
+
*/
|
|
533
|
+
async function githubReleaseLag(options) {
|
|
534
|
+
const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3 } = options;
|
|
535
|
+
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d+Z$/, "Z");
|
|
536
|
+
const wanted = (release) => !release.prerelease && release.tag.startsWith(tagPrefix);
|
|
537
|
+
const releases = await readReleasePages(options, wanted);
|
|
538
|
+
if (!releases.available) return releases;
|
|
539
|
+
const release = releases.releases.find(wanted);
|
|
540
|
+
if (release === void 0) return {
|
|
541
|
+
available: false,
|
|
542
|
+
reason: `no release has a tag that starts with ${tagPrefix}`
|
|
543
|
+
};
|
|
544
|
+
if (!Number.isFinite(Date.parse(release.publishedAt))) return {
|
|
545
|
+
available: false,
|
|
546
|
+
reason: `the release ${release.tag} has no date`
|
|
547
|
+
};
|
|
548
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
549
|
+
const read = async (url) => fetcher(url, {
|
|
550
|
+
headers: restHeaders(token),
|
|
551
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
552
|
+
});
|
|
553
|
+
const first = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/commits?sha=${encodeURIComponent(branch)}&since=${encodeURIComponent(release.publishedAt)}&per_page=1`;
|
|
554
|
+
try {
|
|
555
|
+
let response = await read(first);
|
|
556
|
+
const last = response.ok ? linkedPage(response.headers.get("link"), "last") : null;
|
|
557
|
+
if (last !== null) response = await read(last);
|
|
558
|
+
if (response.status === 404) return {
|
|
559
|
+
available: false,
|
|
560
|
+
reason: `GitHub has no branch ${branch} in ${owner}/${repo}`
|
|
561
|
+
};
|
|
562
|
+
if (!response.ok) return {
|
|
563
|
+
available: false,
|
|
564
|
+
reason: `GitHub answered with HTTP ${response.status}`
|
|
565
|
+
};
|
|
566
|
+
const body = await response.json();
|
|
567
|
+
if (!Array.isArray(body)) return {
|
|
568
|
+
available: false,
|
|
569
|
+
reason: "GitHub gave no list of commits"
|
|
570
|
+
};
|
|
571
|
+
const commit = body.length === 0 ? void 0 : text(object(object(object(body.at(-1))["commit"])["committer"])["date"]);
|
|
572
|
+
if (commit === "") return {
|
|
573
|
+
available: false,
|
|
574
|
+
reason: "the oldest commit has no date"
|
|
575
|
+
};
|
|
576
|
+
const value = releaseLagOf(commit, now);
|
|
577
|
+
if (!Number.isFinite(value)) return {
|
|
578
|
+
available: false,
|
|
579
|
+
reason: "the time of the read is not a date"
|
|
580
|
+
};
|
|
581
|
+
return {
|
|
582
|
+
available: true,
|
|
583
|
+
value,
|
|
584
|
+
at: now,
|
|
585
|
+
release: release.tag
|
|
586
|
+
};
|
|
587
|
+
} catch (error) {
|
|
588
|
+
return failure(error, timeoutMs);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
500
592
|
* This function counts the runs that passed in a row, from the newest run. A run that has not ended does not count and does not break the row.
|
|
501
593
|
* Each other conclusion breaks the row, a cancelled run too. It gives null when no run ended.
|
|
502
594
|
*
|
|
@@ -2572,6 +2664,6 @@ async function runCli(argv, io) {
|
|
|
2572
2664
|
throw error;
|
|
2573
2665
|
}
|
|
2574
2666
|
}
|
|
2575
|
-
export {
|
|
2667
|
+
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 };
|
|
2576
2668
|
|
|
2577
2669
|
//# sourceMappingURL=build.js.map
|