@mark1russell7/site-pages 0.7.1 → 0.7.3
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 +3 -1
- package/build/chunks/build.js +81 -15
- package/build/chunks/build.js.map +1 -1
- package/build/cli.js +1 -0
- package/build/cli.js.map +1 -1
- package/build/index.d.ts +10 -0
- package/build/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,6 +143,8 @@ The folder of `--shots` gets a screenshot of each view, `report.json` and `summa
|
|
|
143
143
|
|
|
144
144
|
The check finds a browser in this order: `--browser`, `$SITE_CHECK_BROWSER`, the newest Chromium of Playwright, and then Chrome or Edge. The folder `src/check` imports only Node.js. Thus Node.js 22.18 or later can start `src/check/main.ts` with no install. The workflow `reusable-pages.yml` of the template uses it this way.
|
|
145
145
|
|
|
146
|
+
The browser starts with no graphics card, and it draws WebGL in software (`--enable-unsafe-swiftshader`). Thus a page with a 3D picture shows the same picture on Windows, on macOS and on Linux.
|
|
147
|
+
|
|
146
148
|
## The site bar
|
|
147
149
|
|
|
148
150
|
The command `site-pages bar` writes one shared bar into each HTML page of a built site. The bar comes first in the body of each page.
|
|
@@ -631,7 +633,7 @@ Two functions read a measure from GitHub at the build. Each result has the `at`
|
|
|
631
633
|
| Function | Measure |
|
|
632
634
|
| --- | --- |
|
|
633
635
|
| `githubGreenRun({ owner, repo, token, workflow })` | The scheduled runs of a workflow that passed in a row, from the newest run |
|
|
634
|
-
| `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the first-parent line of the branch that is not in the newest release of the tag prefix. A merge commit counts at its own date. Drafts and pre-releases do not count. |
|
|
636
|
+
| `githubReleaseLag({ owner, repo, token, tagPrefix, branch, paths })` | The age in days of the oldest commit of the first-parent line of the branch that is not in the newest release of the tag prefix. A merge commit counts at its own date. Drafts and pre-releases do not count. With `paths` (for example `["packages/", "!packages/site/"]`), only a commit that changes a file in the paths counts. The last entry that matches a file decides. |
|
|
635
637
|
|
|
636
638
|
## The shell of a site
|
|
637
639
|
|
package/build/chunks/build.js
CHANGED
|
@@ -576,22 +576,42 @@ function compareCommit(value) {
|
|
|
576
576
|
}
|
|
577
577
|
/**
|
|
578
578
|
* This function follows the first-parent line of `commits` from its tip. `commits` are the commits of a branch that a tag does
|
|
579
|
-
* not contain. The function gives the
|
|
580
|
-
*
|
|
581
|
-
*
|
|
579
|
+
* not contain. The function gives the commits of that line, the tip first and the oldest last. The tip is the one commit that is
|
|
580
|
+
* not a parent of another commit of the list. The function gives an empty list for no commit, and null when the list has no
|
|
581
|
+
* single tip.
|
|
582
582
|
*/
|
|
583
|
-
function
|
|
584
|
-
if (commits.length === 0) return
|
|
583
|
+
function firstParentLine(commits) {
|
|
584
|
+
if (commits.length === 0) return [];
|
|
585
585
|
const bySha = new Map(commits.map((commit) => [commit.sha, commit]));
|
|
586
586
|
const parents = new Set(commits.flatMap((commit) => commit.parents));
|
|
587
587
|
const tips = commits.filter((commit) => !parents.has(commit.sha));
|
|
588
588
|
if (tips.length !== 1 || tips[0] === void 0) return null;
|
|
589
|
-
|
|
590
|
-
for (let next = bySha.get(
|
|
591
|
-
return
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
589
|
+
const line = [tips[0]];
|
|
590
|
+
for (let next = bySha.get(tips[0].parents[0] ?? ""); next !== void 0; next = bySha.get(next.parents[0] ?? "")) line.push(next);
|
|
591
|
+
return line;
|
|
592
|
+
}
|
|
593
|
+
/** GitHub lists at most this many files of one comparison. A list of this length can be cut. */
|
|
594
|
+
const COMPARE_FILES = 300;
|
|
595
|
+
/** The most commits of the first-parent line that `githubReleaseLag` reads one at a time for the option `paths`. */
|
|
596
|
+
const COMMIT_READS = 100;
|
|
597
|
+
/** This function gives the paths of the files of a comparison of GitHub. A renamed file gives its new path and its old path. */
|
|
598
|
+
function filePaths(files) {
|
|
599
|
+
return files.flatMap((file) => [text(object(file)["filename"]), text(object(file)["previous_filename"])].filter((path) => path !== ""));
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* This function tells if a file is in the entries of the option `paths` of `githubReleaseLag`. An entry is a file or a folder of
|
|
603
|
+
* the repository, and an entry that starts with `!` takes its files out. The last entry that matches a file decides, as in a
|
|
604
|
+
* `.gitignore` file. A file that no entry matches is not in the paths.
|
|
605
|
+
*/
|
|
606
|
+
function inPaths(paths, file) {
|
|
607
|
+
let found = false;
|
|
608
|
+
for (const entry of paths) {
|
|
609
|
+
const out = entry.startsWith("!");
|
|
610
|
+
const raw = (out ? entry.slice(1) : entry).replace(/^(?:\.\/|\/)+/, "").replace(/\/+$/, "");
|
|
611
|
+
const path = raw === "." ? "" : raw;
|
|
612
|
+
if (path === "" || file === path || file.startsWith(`${path}/`)) found = !out;
|
|
613
|
+
}
|
|
614
|
+
return found;
|
|
595
615
|
}
|
|
596
616
|
/**
|
|
597
617
|
* This function reads how many days a branch is ahead of its newest release. That is the age of the oldest commit of the
|
|
@@ -607,9 +627,22 @@ function oldestFirstParent(commits) {
|
|
|
607
627
|
* that is not on that line gives `{ available: false, reason }`. So a merge commit counts at the time of the merge, not at the older
|
|
608
628
|
* dates of the commits that it brings. A commit that lands after the tag and before the release is published counts, because it
|
|
609
629
|
* is not in the release. The time of the release does not decide.
|
|
630
|
+
*
|
|
631
|
+
* The option `paths` counts only the commits that change a file in the paths, for example the folders of the packages that a
|
|
632
|
+
* release publishes. An entry is a file or a folder, and an entry that starts with `!` takes its files out. The last entry that
|
|
633
|
+
* matches a file decides. Then the age is that of the oldest commit of the line that changes such a file. When no file of the
|
|
634
|
+
* comparison is in the paths, the age is 0, with no more requests. Else the function reads the commits of the line one at a
|
|
635
|
+
* time, the oldest first, at most 100. It stops at the first commit that changes a file in the paths. A commit that a later
|
|
636
|
+
* commit reverts still counts while the branch has another change in the paths. Paths with no entry that adds files give
|
|
637
|
+
* `{ available: false, reason }`. So does a commit that changes 300 files or more with no file in the paths, because GitHub
|
|
638
|
+
* lists only 300 files of a comparison.
|
|
610
639
|
*/
|
|
611
640
|
async function githubReleaseLag(options) {
|
|
612
|
-
const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3 } = options;
|
|
641
|
+
const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3, paths } = options;
|
|
642
|
+
if (paths !== void 0 && !paths.some((entry) => !entry.startsWith("!"))) return {
|
|
643
|
+
available: false,
|
|
644
|
+
reason: "the option paths has no entry that adds files"
|
|
645
|
+
};
|
|
613
646
|
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d+Z$/, "Z");
|
|
614
647
|
const wanted = (release) => !release.prerelease && release.tag.startsWith(tagPrefix);
|
|
615
648
|
const releases = await readReleasePages(options, wanted);
|
|
@@ -633,6 +666,7 @@ async function githubReleaseLag(options) {
|
|
|
633
666
|
const commits = [];
|
|
634
667
|
let ahead = 0;
|
|
635
668
|
let base = "";
|
|
669
|
+
let range;
|
|
636
670
|
for (let page = 0; url !== null; page++) {
|
|
637
671
|
if (page === COMPARE_PAGES) return {
|
|
638
672
|
available: false,
|
|
@@ -661,6 +695,7 @@ async function githubReleaseLag(options) {
|
|
|
661
695
|
};
|
|
662
696
|
ahead = typeof body["ahead_by"] === "number" ? body["ahead_by"] : 0;
|
|
663
697
|
base = text(object(body["merge_base_commit"])["sha"]);
|
|
698
|
+
range = body["files"];
|
|
664
699
|
}
|
|
665
700
|
for (const value of listed) commits.push(compareCommit(value));
|
|
666
701
|
url = linkedPage(response.headers.get("link"), "next");
|
|
@@ -669,15 +704,29 @@ async function githubReleaseLag(options) {
|
|
|
669
704
|
available: false,
|
|
670
705
|
reason: `GitHub listed ${commits.length} of the ${ahead} commits after ${release.tag}`
|
|
671
706
|
};
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
707
|
+
const line = firstParentLine(commits);
|
|
708
|
+
if (line === null) return {
|
|
674
709
|
available: false,
|
|
675
710
|
reason: `the commits after ${release.tag} have no single tip`
|
|
676
711
|
};
|
|
677
|
-
|
|
712
|
+
const last = line.at(-1);
|
|
713
|
+
if (last !== void 0 && (last.parents[0] ?? "") !== base) return {
|
|
678
714
|
available: false,
|
|
679
715
|
reason: `the tag ${release.tag} is not on the first-parent line of ${branch}`
|
|
680
716
|
};
|
|
717
|
+
let oldest = last;
|
|
718
|
+
if (paths !== void 0) {
|
|
719
|
+
const found = await oldestInPaths(line, range, paths, release.tag, async (from, to) => {
|
|
720
|
+
const response = await read(`${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(from)}...${encodeURIComponent(to)}?per_page=1`);
|
|
721
|
+
if (!response.ok) return { reason: `GitHub answered with HTTP ${response.status} for the commit ${to.slice(0, 7)}` };
|
|
722
|
+
return { files: object(await response.json())["files"] };
|
|
723
|
+
});
|
|
724
|
+
if (found !== void 0 && "reason" in found) return {
|
|
725
|
+
available: false,
|
|
726
|
+
reason: found.reason
|
|
727
|
+
};
|
|
728
|
+
oldest = found;
|
|
729
|
+
}
|
|
681
730
|
if (oldest?.date === "") return {
|
|
682
731
|
available: false,
|
|
683
732
|
reason: "the oldest commit has no date"
|
|
@@ -698,6 +747,23 @@ async function githubReleaseLag(options) {
|
|
|
698
747
|
}
|
|
699
748
|
}
|
|
700
749
|
/**
|
|
750
|
+
* This function gives the oldest commit of a first-parent line that changes a file in `paths`. It gives undefined when no commit
|
|
751
|
+
* of the line changes one. `line` has the tip first, and `range` is the list of files of the comparison of the tag with the tip.
|
|
752
|
+
* `files` reads the list of files of one commit against its first parent. The function gives a reason when it cannot tell.
|
|
753
|
+
*/
|
|
754
|
+
async function oldestInPaths(line, range, paths, tag, files) {
|
|
755
|
+
if (Array.isArray(range) && range.length < COMPARE_FILES && !filePaths(range).some((file) => inPaths(paths, file))) return void 0;
|
|
756
|
+
const oldestFirst = [...line].reverse();
|
|
757
|
+
for (const [index, commit] of oldestFirst.entries()) {
|
|
758
|
+
if (index === COMMIT_READS) return { reason: `the first ${COMMIT_READS} commits after ${tag} change no file in the paths` };
|
|
759
|
+
const read = await files(commit.parents[0] ?? "", commit.sha);
|
|
760
|
+
if ("reason" in read) return read;
|
|
761
|
+
if (!Array.isArray(read.files)) return { reason: `GitHub gave no list of files for the commit ${commit.sha.slice(0, 7)}` };
|
|
762
|
+
if (filePaths(read.files).some((file) => inPaths(paths, file))) return commit;
|
|
763
|
+
if (read.files.length >= COMPARE_FILES) return { reason: `the commit ${commit.sha.slice(0, 7)} changes ${COMPARE_FILES} files or more, and GitHub lists only ${COMPARE_FILES}` };
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
701
767
|
* 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.
|
|
702
768
|
* Each other conclusion breaks the row, a cancelled run too. It gives null when no run ended.
|
|
703
769
|
*
|