@intellectual-frontiers/libraries 0.2.1 → 0.4.0
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/dist/affected.d.ts +15 -2
- package/dist/affected.js +51 -20
- package/dist/dev.d.ts +81 -0
- package/dist/dev.js +347 -0
- package/dist/family.d.ts +58 -0
- package/dist/family.js +124 -0
- package/dist/generate-workflows.js +2 -10
- package/dist/libraries.d.ts +3 -0
- package/dist/libraries.js +14 -3
- package/dist/link.d.ts +12 -0
- package/dist/link.js +98 -0
- package/dist/pack-library.js +6 -1
- package/dist/plan.d.ts +28 -0
- package/dist/plan.js +135 -0
- package/dist/releasing.d.ts +176 -0
- package/dist/releasing.js +680 -0
- package/dist/versions.js +4 -7
- package/dist/workflows/definitions.d.ts +33 -30
- package/dist/workflows/definitions.js +200 -277
- package/dist/workflows/model.d.ts +15 -3
- package/dist/workflows/render.js +10 -2
- package/package.json +23 -3
- package/src/affected.ts +56 -17
- package/src/dev.ts +368 -0
- package/src/family.ts +143 -0
- package/src/generate-workflows.ts +3 -11
- package/src/libraries.ts +15 -3
- package/src/link.ts +97 -0
- package/src/pack-library.ts +6 -1
- package/src/plan.ts +143 -0
- package/src/releasing.ts +735 -0
- package/src/versions.ts +3 -7
- package/src/workflows/definitions.ts +260 -395
- package/src/workflows/model.ts +11 -3
- package/src/workflows/render.ts +10 -2
package/dist/family.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The families of the libraries of commons and the names held for them (commons 0027-commons-libraries FR-023, FR-024; commons 0033-kanon FR-021, FR-024): what the `family` field of a manifest
|
|
3
|
+
* says, the reservations (names no library may take unless it is of the family they are held for), and the findings of the two sides of a family held together, the host's table and each member's
|
|
4
|
+
* manifest.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pure: it takes the libraries as data and returns one sentence for each finding. A library names its host and its role (`host`, `dialect` or `plugin`); the host's `kanon` table says what its
|
|
8
|
+
* dialects and plugins are and how their packages are named (`@intellectual-frontiers/kanon`: `family`, `instances`, `plugins`), so the name of a member is checked against the host's rule and
|
|
9
|
+
* never against a rule written here. A reservation is data: an exact name or a prefix, and the host that may hold it. It reserves a name without a folder, so that no empty library is created to hold one.
|
|
10
|
+
*
|
|
11
|
+
* Spec: 0001-libraries FR-016
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { absurd, err, ok } from "@intellectual-frontiers/core";
|
|
16
|
+
import { classify, parsePackageName } from "@intellectual-frontiers/kanon";
|
|
17
|
+
/** The roles a library has in a family: a closed union. */
|
|
18
|
+
export const ROLES = ["host", "dialect", "plugin"];
|
|
19
|
+
/** The scope of the packages of commons. */
|
|
20
|
+
const SCOPE = "@intellectual-frontiers/";
|
|
21
|
+
/** The reason the names of the retired fleet engine are held (intellectual-frontiers/.github#11). */
|
|
22
|
+
const ARCHON = "held for the fleet library and its dialects and plugins, which replace the retired fleet engine (intellectual-frontiers/.github#11)";
|
|
23
|
+
/** The names held, as data: the check reads them and no folder holds them. */
|
|
24
|
+
export const RESERVED = [
|
|
25
|
+
{ match: { kind: "exact", name: "archon" }, host: "archon", reason: ARCHON },
|
|
26
|
+
{ match: { kind: "prefix", prefix: "archon-" }, host: "archon", reason: ARCHON },
|
|
27
|
+
{ match: { kind: "exact", name: "signing" }, host: "signing", reason: "held for the signing library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
28
|
+
{ match: { kind: "exact", name: "gitops" }, host: "gitops", reason: "held for the gitops library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
29
|
+
{ match: { kind: "exact", name: "estate" }, host: "estate", reason: "held for the estate library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
30
|
+
];
|
|
31
|
+
/** Whether a library name is one a match holds. */
|
|
32
|
+
export function matches(match, name) {
|
|
33
|
+
switch (match.kind) {
|
|
34
|
+
case "exact":
|
|
35
|
+
return name === match.name;
|
|
36
|
+
case "prefix":
|
|
37
|
+
return name.startsWith(match.prefix);
|
|
38
|
+
default:
|
|
39
|
+
return absurd(match);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The family field of a manifest, from what it says: the host's name and the role, or why it is not one. */
|
|
43
|
+
export function decodeFamily(input) {
|
|
44
|
+
return /^[a-z][a-z0-9-]*$/.test(input.host)
|
|
45
|
+
? ok({ host: input.host, role: input.role })
|
|
46
|
+
: err(`library.family.host ${JSON.stringify(input.host)} is not a library name`);
|
|
47
|
+
}
|
|
48
|
+
/** The findings of the names held: a library whose name a reservation holds and that is not of the family the name is held for. */
|
|
49
|
+
export function reservationFindings(libraries, reserved = RESERVED) {
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const l of libraries)
|
|
52
|
+
for (const r of reserved) {
|
|
53
|
+
if (!matches(r.match, l.name))
|
|
54
|
+
continue;
|
|
55
|
+
if (l.family?.host !== r.host)
|
|
56
|
+
out.push(`commons/${l.name}: the name is ${r.reason}, so the manifest declares family: { host: "${r.host}", role } (0033-kanon FR-024)`);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** The findings of a family held together: each member's name against the host's rule, each declared member registered, and each registered member declared (0033-kanon FR-021). */
|
|
62
|
+
export function familyFindings(libraries) {
|
|
63
|
+
const out = [];
|
|
64
|
+
const by = new Map(libraries.map((l) => [l.name, l]));
|
|
65
|
+
for (const l of libraries) {
|
|
66
|
+
const f = l.family;
|
|
67
|
+
if (f === undefined) {
|
|
68
|
+
for (const h of libraries) {
|
|
69
|
+
const rule = h.kanon?.family;
|
|
70
|
+
const pkg = parsePackageName(`${SCOPE}${l.name}`);
|
|
71
|
+
if (rule !== undefined && h.kanon !== undefined && pkg.kind === "ok" && h.name !== l.name) {
|
|
72
|
+
const member = classify(rule, h.kanon.package, pkg.value);
|
|
73
|
+
if (member !== undefined && member.kind !== "host")
|
|
74
|
+
out.push(`commons/${l.name}: the name is a ${member.kind} of ${h.name} by its family rule, and the manifest declares no family (0033-kanon FR-021)`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
switch (f.role) {
|
|
80
|
+
case "host":
|
|
81
|
+
if (l.name !== f.host)
|
|
82
|
+
out.push(`commons/${l.name}: it declares itself the host of the family ${f.host}, and a host is named as its family (0033-kanon FR-021)`);
|
|
83
|
+
break;
|
|
84
|
+
case "dialect":
|
|
85
|
+
case "plugin": {
|
|
86
|
+
const host = by.get(f.host);
|
|
87
|
+
if (host === undefined || host.family?.role !== "host" || host.kanon === undefined) {
|
|
88
|
+
out.push(`commons/${l.name}: its family host ${f.host} is not a library that declares family role host and a kanon table (0033-kanon FR-021)`);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
const rule = host.kanon.family;
|
|
92
|
+
const pkg = parsePackageName(`${SCOPE}${l.name}`);
|
|
93
|
+
const member = rule === undefined || pkg.kind === "err" ? undefined : classify(rule, host.kanon.package, pkg.value);
|
|
94
|
+
if (member === undefined || member.kind !== f.role)
|
|
95
|
+
out.push(`commons/${l.name}: the family rule of ${f.host} does not read the name as a ${f.role} (0033-kanon FR-021)`);
|
|
96
|
+
const declared = f.role === "dialect"
|
|
97
|
+
? host.kanon.instances.some((i) => i.kind === "package" && i.package === `${SCOPE}${l.name}`)
|
|
98
|
+
: host.kanon.plugins.some((p) => p.package === `${SCOPE}${l.name}`);
|
|
99
|
+
if (!declared)
|
|
100
|
+
out.push(`commons/${l.name}: the kanon table of ${f.host} does not declare it as a ${f.role} (0033-kanon FR-020)`);
|
|
101
|
+
if (l.kanon === undefined || l.kanon.extends !== host.kanon.package)
|
|
102
|
+
out.push(`commons/${l.name}: a ${f.role} of ${f.host} declares a kanon table with extends: "${host.kanon.package}" (0033-kanon FR-020)`);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return absurd(f.role);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const h of libraries) {
|
|
110
|
+
if (h.kanon === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
const members = [
|
|
113
|
+
...h.kanon.instances.flatMap((i) => (i.kind === "package" ? [{ role: "dialect", pkg: i.package }] : [])),
|
|
114
|
+
...h.kanon.plugins.map((p) => ({ role: "plugin", pkg: p.package })),
|
|
115
|
+
];
|
|
116
|
+
for (const m of members) {
|
|
117
|
+
const name = m.pkg.slice(SCOPE.length);
|
|
118
|
+
const l = by.get(name);
|
|
119
|
+
if (l === undefined || l.family?.host !== h.name || l.family.role !== m.role)
|
|
120
|
+
out.push(`commons/${h.name}: its kanon table declares ${m.pkg} as a ${m.role}, and no library of that name declares family: { host: "${h.name}", role: "${m.role}" } (0033-kanon FR-021)`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
@@ -22,7 +22,6 @@ import process from "node:process";
|
|
|
22
22
|
import { ACTIONS, workflows } from "./workflows/definitions.js";
|
|
23
23
|
import { validateAction, validateWorkflow } from "./workflows/model.js";
|
|
24
24
|
import { renderAction, renderWorkflow } from "./workflows/render.js";
|
|
25
|
-
import { inputsOf } from "./affected.js";
|
|
26
25
|
import { readLibraries } from "./libraries.js";
|
|
27
26
|
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync, mkdirSync } from "@intellectual-frontiers/system/fs";
|
|
28
27
|
import { stdio } from "@intellectual-frontiers/system";
|
|
@@ -32,23 +31,16 @@ const FOLDER = ".github/workflows";
|
|
|
32
31
|
export function outputs(repo) {
|
|
33
32
|
const root = repo.replace(/[\\/]$/, "");
|
|
34
33
|
const problems = [];
|
|
35
|
-
const libraries = [];
|
|
36
34
|
for (const f of readLibraries(root)) {
|
|
37
35
|
if ("problem" in f)
|
|
38
36
|
problems.push(`commons/${f.dir}/library.ts: ${f.problem}`);
|
|
39
37
|
else {
|
|
40
38
|
if (f.library.distribution.includes("npm") && !existsSync(`${root}/commons/${f.library.name}/tools/pack.ts`))
|
|
41
|
-
problems.push(`commons/${f.library.name} is published to npm and has no tools/pack.ts, which
|
|
42
|
-
libraries.push({
|
|
43
|
-
name: f.library.name,
|
|
44
|
-
verify: f.library.verify,
|
|
45
|
-
paths: inputsOf(root, f.library.name).paths,
|
|
46
|
-
distribution: f.library.distribution,
|
|
47
|
-
});
|
|
39
|
+
problems.push(`commons/${f.library.name} is published to npm and has no tools/pack.ts, which the release workflow runs (0030-generated-workflows FR-009)`);
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
42
|
const files = new Map();
|
|
51
|
-
for (const w of workflows(
|
|
43
|
+
for (const w of workflows()) {
|
|
52
44
|
problems.push(...validateWorkflow(w));
|
|
53
45
|
files.set(`${FOLDER}/${w.file}.auto.yml`, renderWorkflow(w));
|
|
54
46
|
}
|
package/dist/libraries.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Result } from "@intellectual-frontiers/core";
|
|
2
2
|
import { type Table } from "@intellectual-frontiers/kanon";
|
|
3
3
|
import { type LevelKey } from "@intellectual-frontiers/mizan/levels";
|
|
4
|
+
import { type LibraryFamily } from "./family.js";
|
|
4
5
|
/** The name of a library's manifest in its folder. */
|
|
5
6
|
export declare const LIBRARY_FILE = "library.ts";
|
|
6
7
|
/** The specification that holds the requirements of the libraries, and the first number of the requirements it generates. */
|
|
@@ -30,6 +31,8 @@ export type Library = {
|
|
|
30
31
|
readonly distribution: readonly Registry[];
|
|
31
32
|
/** The table of its layers where it is built to Kanon (commons 0033-kanon FR-010); none where it is not. */
|
|
32
33
|
readonly kanon?: Table;
|
|
34
|
+
/** Its host and its role where it is of a family (a host, a dialect of it or a plugin of it; 0033-kanon FR-021, 0027-commons-libraries FR-023). */
|
|
35
|
+
readonly family?: LibraryFamily;
|
|
33
36
|
};
|
|
34
37
|
/** The lowest conformance level that requires a library to declare `kanon`; none yet (0033-kanon FR-014, OQ-1): a level asks for it by naming itself here. */
|
|
35
38
|
export declare const KANON_REQUIRED_FROM: LevelKey | undefined;
|
package/dist/libraries.js
CHANGED
|
@@ -61,7 +61,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
61
61
|
*
|
|
62
62
|
* @remarks
|
|
63
63
|
* A manifest declares the library's `name` (its folder), its conformance `level` (`L1` where it declares none, 0028-conformance-levels), the path of its spec kit, its `verify` command, its
|
|
64
|
-
* `version`, its `exports` (the keys of the package's `exports`) and its `distribution` (the registries it is published to: `github`, the default, and `npm` as well where a decision about that package has made it so; FR-015 to FR-018). The section "The libraries" of the specification is between the markers `<!-- libraries:begin -->` and `<!-- libraries:end -->`,
|
|
64
|
+
* `version`, its `exports` (the keys of the package's `exports`) its `family` (a host and a role in a family of libraries, FR-023) and its `distribution` (the registries it is published to: `github`, the default, and `npm` as well where a decision about that package has made it so; FR-015 to FR-018). The section "The libraries" of the specification is between the markers `<!-- libraries:begin -->` and `<!-- libraries:end -->`,
|
|
65
65
|
* one requirement for each library numbered from FR-101, an id kept for the life of the library; the rows of those requirements are in `enforcement.tsv`. Adding a library is adding a folder with a manifest and
|
|
66
66
|
* running this command.
|
|
67
67
|
*
|
|
@@ -87,6 +87,7 @@ import { existsSync, readDirSync, readTextFileSync, writeTextFileSync } from "@i
|
|
|
87
87
|
import { stdio } from "@intellectual-frontiers/system";
|
|
88
88
|
import { spawn } from "@intellectual-frontiers/system/proc";
|
|
89
89
|
import { DEFAULT_LIBRARY_LEVEL, LEVELS, rankOf } from "@intellectual-frontiers/mizan/levels";
|
|
90
|
+
import { decodeFamily, familyFindings, reservationFindings, ROLES } from "./family.js";
|
|
90
91
|
/** The name of a library's manifest in its folder. */
|
|
91
92
|
export const LIBRARY_FILE = "library.ts";
|
|
92
93
|
/** The specification that holds the requirements of the libraries, and the first number of the requirements it generates. */
|
|
@@ -122,8 +123,8 @@ const nameDecoder = (input, path = "$") => {
|
|
|
122
123
|
? r
|
|
123
124
|
: err({ kind: "decode", path, expected: "a name of lower-case letters, digits and hyphens", found: describe(input) });
|
|
124
125
|
};
|
|
125
|
-
const body = object({ name: nameDecoder, verify: nonEmpty, version: nonEmpty, exports: array(nonEmpty) }, { level: literal(...LEVELS), specKit: nonEmpty, summary: nonEmpty, distribution: array(literal(...REGISTRIES)), kanon: unknownValue });
|
|
126
|
-
const FIELDS = ["name", "level", "specKit", "verify", "version", "exports", "summary", "distribution", "kanon"];
|
|
126
|
+
const body = object({ name: nameDecoder, verify: nonEmpty, version: nonEmpty, exports: array(nonEmpty) }, { level: literal(...LEVELS), specKit: nonEmpty, summary: nonEmpty, distribution: array(literal(...REGISTRIES)), kanon: unknownValue, family: object({ host: nonEmpty, role: literal(...ROLES) }) });
|
|
127
|
+
const FIELDS = ["name", "level", "specKit", "verify", "version", "exports", "summary", "distribution", "kanon", "family"];
|
|
127
128
|
/** The manifest read from the text of its file: `export const library = { ... }` and no other export, read as data and never run (0027-commons-libraries FR-012). */
|
|
128
129
|
export function decodeLibrarySource(source) {
|
|
129
130
|
const exports = source.split("\n").filter((l) => /^export\s/.test(l));
|
|
@@ -155,6 +156,13 @@ export function decodeLibrarySource(source) {
|
|
|
155
156
|
return err(`library.${t.error} (0033-kanon FR-010)`);
|
|
156
157
|
kanon = t.value;
|
|
157
158
|
}
|
|
159
|
+
let family;
|
|
160
|
+
if (v.family !== undefined) {
|
|
161
|
+
const f = decodeFamily(v.family);
|
|
162
|
+
if (f.kind === "err")
|
|
163
|
+
return f;
|
|
164
|
+
family = f.value;
|
|
165
|
+
}
|
|
158
166
|
return ok({
|
|
159
167
|
name: v.name,
|
|
160
168
|
level: v.level ?? DEFAULT_LIBRARY_LEVEL,
|
|
@@ -165,6 +173,7 @@ export function decodeLibrarySource(source) {
|
|
|
165
173
|
...(v.summary === undefined ? {} : { summary: v.summary }),
|
|
166
174
|
distribution,
|
|
167
175
|
...(kanon === undefined ? {} : { kanon }),
|
|
176
|
+
...(family === undefined ? {} : { family }),
|
|
168
177
|
});
|
|
169
178
|
}
|
|
170
179
|
/** The manifests of `commons/*`, in the order of the folders' names: every folder that holds a `library.ts`. */
|
|
@@ -248,6 +257,8 @@ export function manifestFindings(repo) {
|
|
|
248
257
|
if (KANON_REQUIRED_FROM !== undefined && rankOf(l.level) >= rankOf(KANON_REQUIRED_FROM) && l.kanon === undefined)
|
|
249
258
|
found.push(`commons/${f.dir}: the manifest declares ${l.level}, which requires kanon, and declares none (0033-kanon FR-014)`);
|
|
250
259
|
}
|
|
260
|
+
const known = have.flatMap((f) => ("library" in f ? [f.library] : []));
|
|
261
|
+
found.push(...reservationFindings(known), ...familyFindings(known));
|
|
251
262
|
return found;
|
|
252
263
|
}
|
|
253
264
|
/** A field of a value read from JSON, `undefined` where the value is not an object or has no such field. */
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
|
|
2
|
+
export declare function linksOf(repo: string): ReadonlyMap<string, string>;
|
|
3
|
+
/** Links each package that is not linked yet, and gives how many it linked, or why it could not. */
|
|
4
|
+
export declare function linkAll(repo: string): {
|
|
5
|
+
readonly made: number;
|
|
6
|
+
} | {
|
|
7
|
+
readonly problem: string;
|
|
8
|
+
};
|
|
9
|
+
/** The repository above a folder: the nearest one that has `commons/libraries/library.ts`. */
|
|
10
|
+
export declare function rootAbove(from: string): string | undefined;
|
|
11
|
+
/** The command line: 0, or 1 where it could not link. */
|
|
12
|
+
export declare function main(argv: readonly string[]): number;
|
package/dist/link.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The links of the libraries (commons 0001-libraries FR-011): every package of commons linked under `commons/node_modules/@intellectual-frontiers`, so that a library imports another by its package name and reads the checkout's
|
|
3
|
+
* source. It is the first command of every script that imports a library of commons (`dev:check`, `release`, the plan of CI), and it imports none: a fresh checkout has no link yet, and the command that makes them cannot
|
|
4
|
+
* itself need one.
|
|
5
|
+
*
|
|
6
|
+
* bun commons/libraries/src/link.ts link what is not linked, from the repository above this folder (or --repo DIR)
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A folder of `commons/` whose `package.json` is named `@intellectual-frontiers/<name>` is linked as that name, and `commons/ts` as `@intellectual-frontiers/commons` (`commons/docs` bears the same name and is not linked). A link
|
|
10
|
+
* that is there is left as it is. Only the built-ins of Node are used, so it runs on Bun and on Node 26 before anything is installed.
|
|
11
|
+
*
|
|
12
|
+
* @limits
|
|
13
|
+
* It links and nothing else: the packages the root and a library install are `bun install`'s.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { linksOf } from "./link.ts";
|
|
18
|
+
* linksOf(".").get("@intellectual-frontiers/commons"); // the path of commons/ts
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Spec: 0001-libraries FR-011
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, symlinkSync } from "node:fs";
|
|
26
|
+
import { dirname, join, resolve } from "node:path";
|
|
27
|
+
import process from "node:process";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
const SCOPE = "@intellectual-frontiers/";
|
|
30
|
+
const nameOf = (file) => {
|
|
31
|
+
try {
|
|
32
|
+
const x = JSON.parse(readFileSync(file, "utf8"));
|
|
33
|
+
return typeof x === "object" && x !== null && "name" in x && typeof x.name === "string" ? x.name : undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
|
|
40
|
+
export function linksOf(repo) {
|
|
41
|
+
const links = new Map();
|
|
42
|
+
const dirs = readdirSync(join(repo, "commons"), { withFileTypes: true })
|
|
43
|
+
.filter((e) => e.isDirectory() && e.name !== "node_modules")
|
|
44
|
+
.map((e) => e.name)
|
|
45
|
+
.sort((a, b) => (a === "ts" ? -1 : b === "ts" ? 1 : a < b ? -1 : 1));
|
|
46
|
+
for (const d of dirs) {
|
|
47
|
+
const name = nameOf(join(repo, "commons", d, "package.json"));
|
|
48
|
+
if (name !== undefined && name.startsWith(SCOPE) && !links.has(name))
|
|
49
|
+
links.set(name, join(repo, "commons", d));
|
|
50
|
+
}
|
|
51
|
+
return links;
|
|
52
|
+
}
|
|
53
|
+
/** Links each package that is not linked yet, and gives how many it linked, or why it could not. */
|
|
54
|
+
export function linkAll(repo) {
|
|
55
|
+
try {
|
|
56
|
+
const scope = join(repo, "commons", "node_modules", "@intellectual-frontiers");
|
|
57
|
+
let made = 0;
|
|
58
|
+
for (const [name, dir] of linksOf(repo)) {
|
|
59
|
+
const at = join(scope, name.slice(SCOPE.length));
|
|
60
|
+
if (existsSync(at))
|
|
61
|
+
continue;
|
|
62
|
+
if (made === 0)
|
|
63
|
+
mkdirSync(scope, { recursive: true });
|
|
64
|
+
symlinkSync(dir, at, "junction");
|
|
65
|
+
made += 1;
|
|
66
|
+
}
|
|
67
|
+
return { made };
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return { problem: `the libraries could not be linked under commons/node_modules: ${e instanceof Error ? e.message : String(e)}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** The repository above a folder: the nearest one that has `commons/libraries/library.ts`. */
|
|
74
|
+
export function rootAbove(from) {
|
|
75
|
+
for (let d = resolve(from);; d = dirname(d)) {
|
|
76
|
+
if (existsSync(join(d, "commons", "libraries", "library.ts")))
|
|
77
|
+
return d;
|
|
78
|
+
if (dirname(d) === d)
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** The command line: 0, or 1 where it could not link. */
|
|
83
|
+
export function main(argv) {
|
|
84
|
+
const at = argv.indexOf("--repo");
|
|
85
|
+
const repo = at >= 0 ? resolve(argv[at + 1] ?? ".") : rootAbove(dirname(fileURLToPath(import.meta.url)));
|
|
86
|
+
if (repo === undefined) {
|
|
87
|
+
process.stderr.write("link: no repository with commons/libraries here; give --repo DIR\n");
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
const r = linkAll(repo);
|
|
91
|
+
if ("problem" in r) {
|
|
92
|
+
process.stderr.write(`link: ${r.problem}\n`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
if (import.meta.main)
|
|
98
|
+
process.exitCode = main(process.argv.slice(2));
|
package/dist/pack-library.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import { chmod, readTextFile, writeTextFile } from "@intellectual-frontiers/system/fs";
|
|
26
26
|
import { existsSync, mkdirSync, readDirSync, readTextFileSync, removeSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
27
27
|
import { basename, dirname, join, relative, resolve, toPosix } from "@intellectual-frontiers/system/path";
|
|
28
|
-
import { run, which } from "@intellectual-frontiers/system/proc";
|
|
28
|
+
import { env, run, which } from "@intellectual-frontiers/system/proc";
|
|
29
29
|
/** The scope of the packages of commons. */
|
|
30
30
|
export const SCOPE = "@intellectual-frontiers";
|
|
31
31
|
const obj = (v) => (isObject(v) ? v : {});
|
|
@@ -488,6 +488,11 @@ export async function packLibrary(root, options = {}) {
|
|
|
488
488
|
}
|
|
489
489
|
/** The command line of a library's `tools/pack.ts`: pack, print what was found (or the tarball) and the exit status. */
|
|
490
490
|
export async function main(root, argv, options = {}) {
|
|
491
|
+
// the check inside `verify` is left out where CI says the exports did not change (`IFC_SKIP_PACK`); the packing for a publication is never skipped
|
|
492
|
+
if (argv.includes("--check") && (env.get("IFC_SKIP_PACK") ?? "") !== "") {
|
|
493
|
+
console.log("pack check skipped: the exports of this library did not change in this push (IFC_SKIP_PACK); the release packs it");
|
|
494
|
+
return 0;
|
|
495
|
+
}
|
|
491
496
|
const r = await packLibrary(root, options);
|
|
492
497
|
for (const f of r.findings)
|
|
493
498
|
console.error(f);
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Cell } from "./workflows/definitions.js";
|
|
2
|
+
/** A library as the plan reads it. */
|
|
3
|
+
export type Planned = {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly folder: string;
|
|
6
|
+
readonly verify: string;
|
|
7
|
+
};
|
|
8
|
+
/** The cells of a job: what `strategy.matrix` reads as `{"include": [...]}`. */
|
|
9
|
+
export type Include = {
|
|
10
|
+
readonly include: readonly Cell[];
|
|
11
|
+
};
|
|
12
|
+
/** What CI runs for a change: the cells on Linux, and the cells on the other systems. */
|
|
13
|
+
export type Plan = {
|
|
14
|
+
readonly linux: Include;
|
|
15
|
+
readonly systems: Include;
|
|
16
|
+
};
|
|
17
|
+
/** The plan for these libraries: a cell on Linux for each, and one on each system its record names, in the order of the libraries; the packing is checked in the cells of the libraries named in `packs`. */
|
|
18
|
+
export declare function planOf(libs: readonly Planned[], packs?: ReadonlySet<string>): Plan;
|
|
19
|
+
/** The exports of a package.json as one line, the keys in order, so that two of them are the same where the entries are. */
|
|
20
|
+
export declare function exportsLine(packageJson: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* The libraries whose packing a push checks (FR-013): those that changed their `exports` since the base (a new library included), and every library where the packer itself changed. Git that cannot say gives every library.
|
|
23
|
+
*/
|
|
24
|
+
export declare function packsFor(repo: string, base: string, libs: readonly Planned[]): Promise<ReadonlySet<string>>;
|
|
25
|
+
/** The outputs of a step that a workflow reads: the matrices as one line of JSON each and whether each has a cell. */
|
|
26
|
+
export declare function outputsOf(p: Plan): string;
|
|
27
|
+
/** The command line. Returns the exit status: 0, or 2 for a command line that does not fit. */
|
|
28
|
+
export declare function main(argv: readonly string[]): Promise<number>;
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plan of CI (commons 0001-libraries FR-012): the libraries a push or a pull request affects, and for each the cells that the one workflow `ci` runs, so that a change proves what it touches and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* bun commons/libraries/src/plan.ts --base origin/main the plan for what changed since the merge base with origin/main, as JSON
|
|
5
|
+
* bun commons/libraries/src/plan.ts --all every library
|
|
6
|
+
* bun commons/libraries/src/plan.ts --files a.ts,b/c.ts the libraries these files affect
|
|
7
|
+
* bun commons/libraries/src/plan.ts --base REF --github-output "$GITHUB_OUTPUT" the same, written as the outputs of a step: has-linux, linux, has-systems, systems
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The libraries are those of `affected.ts` (the same code the development loop and every check read), with the reach of `verify`: what a library's `verify` reads, and what depends on it. Each library has a cell on Linux; a
|
|
11
|
+
* library whose record of CI (`LIBRARY_CI`) names Windows or macOS has a cell on each of them too, because it has code of its own for them. A matrix with no cell is not written as a matrix (a workflow cannot run
|
|
12
|
+
* one): `has-linux` and `has-systems` say whether there is one.
|
|
13
|
+
*
|
|
14
|
+
* @limits
|
|
15
|
+
* It decides nothing about a version, a tag or a release; those are the release's. It cannot say what changed where Git cannot: it plans every library then, and says why.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { planOf } from "./plan.ts";
|
|
20
|
+
* planOf([{ name: "net", folder: "commons/net", verify: "bun run verify" }]).systems.include.map((c) => c.os); // ["windows-latest", "macos-latest"]
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Spec: 0001-libraries FR-012
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import process from "node:process";
|
|
28
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
29
|
+
import { existsSync, readTextFileSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
30
|
+
import { join } from "@intellectual-frontiers/system/path";
|
|
31
|
+
import { run } from "@intellectual-frontiers/system/proc";
|
|
32
|
+
import { flag, formatUsageError, helpText, many, parseArgs, value } from "@intellectual-frontiers/terminal/args";
|
|
33
|
+
import { affectedBy, changedSince, everyLibrary } from "./affected.js";
|
|
34
|
+
import { cellOf, LIBRARY_CI } from "./workflows/definitions.js";
|
|
35
|
+
/** The plan for these libraries: a cell on Linux for each, and one on each system its record names, in the order of the libraries; the packing is checked in the cells of the libraries named in `packs`. */
|
|
36
|
+
export function planOf(libs, packs = new Set()) {
|
|
37
|
+
return {
|
|
38
|
+
linux: { include: libs.map((l) => cellOf(l, undefined, packs.has(l.name))) },
|
|
39
|
+
systems: { include: libs.flatMap((l) => (LIBRARY_CI[l.name]?.systems ?? []).map((os) => cellOf(l, os, packs.has(l.name)))) },
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** The exports of a package.json as one line, the keys in order, so that two of them are the same where the entries are. */
|
|
43
|
+
export function exportsLine(packageJson) {
|
|
44
|
+
try {
|
|
45
|
+
const x = JSON.parse(packageJson);
|
|
46
|
+
const e = typeof x === "object" && x !== null && "exports" in x ? x.exports : undefined;
|
|
47
|
+
const sorted = (v) => typeof v === "object" && v !== null && !Array.isArray(v)
|
|
48
|
+
? Object.fromEntries(Object.entries(v)
|
|
49
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
50
|
+
.map(([k, n]) => [k, sorted(n)]))
|
|
51
|
+
: v;
|
|
52
|
+
return JSON.stringify(sorted(e ?? null));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return "unreadable";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The libraries whose packing a push checks (FR-013): those that changed their `exports` since the base (a new library included), and every library where the packer itself changed. Git that cannot say gives every library.
|
|
60
|
+
*/
|
|
61
|
+
export async function packsFor(repo, base, libs) {
|
|
62
|
+
const all = new Set(libs.map((l) => l.name));
|
|
63
|
+
const mb = await run(["git", "-C", repo, "merge-base", base, "HEAD"]);
|
|
64
|
+
if (mb.code !== 0)
|
|
65
|
+
return all;
|
|
66
|
+
const packer = await run(["git", "-C", repo, "diff", "--name-only", mb.stdout.trim(), "--", "commons/libraries/src/pack-library.ts"]);
|
|
67
|
+
if (packer.code !== 0 || packer.stdout.trim() !== "")
|
|
68
|
+
return all;
|
|
69
|
+
const out = new Set();
|
|
70
|
+
for (const l of libs) {
|
|
71
|
+
const before = await run(["git", "-C", repo, "show", `${mb.stdout.trim()}:${l.folder}/package.json`]);
|
|
72
|
+
const now = join(repo, l.folder, "package.json");
|
|
73
|
+
if (before.code !== 0 || !existsSync(now) || exportsLine(before.stdout) !== exportsLine(readTextFileSync(now)))
|
|
74
|
+
out.add(l.name);
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** The outputs of a step that a workflow reads: the matrices as one line of JSON each and whether each has a cell. */
|
|
79
|
+
export function outputsOf(p) {
|
|
80
|
+
return [
|
|
81
|
+
`has-linux=${p.linux.include.length > 0}`,
|
|
82
|
+
`linux=${JSON.stringify(p.linux)}`,
|
|
83
|
+
`has-systems=${p.systems.include.length > 0}`,
|
|
84
|
+
`systems=${JSON.stringify(p.systems)}`,
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
87
|
+
const OPTIONS = {
|
|
88
|
+
base: value({ help: "The revision the change starts at (the merge base with it is compared with the head).", valueName: "REF" }),
|
|
89
|
+
files: many({ help: "A file that changed (from the repository's root); the libraries it affects. Repeat or separate with commas.", valueName: "FILE" }),
|
|
90
|
+
all: flag({ help: "Every library." }),
|
|
91
|
+
repo: value({ help: "The repository (the working folder by default).", valueName: "DIR", default: "." }),
|
|
92
|
+
githubOutput: value({ help: "Append the outputs to this file, as a step's `$GITHUB_OUTPUT` is read.", valueName: "FILE" }),
|
|
93
|
+
};
|
|
94
|
+
/** The command line. Returns the exit status: 0, or 2 for a command line that does not fit. */
|
|
95
|
+
export async function main(argv) {
|
|
96
|
+
const parsed = parseArgs(argv, OPTIONS);
|
|
97
|
+
if (parsed.kind === "err") {
|
|
98
|
+
stdio.stderr.writeSync(`${formatUsageError(parsed.error, "plan")}\n`);
|
|
99
|
+
return 2;
|
|
100
|
+
}
|
|
101
|
+
if (parsed.value.kind === "help") {
|
|
102
|
+
stdio.stdout.writeSync(`${helpText("plan", "The libraries a change affects and the cells CI runs for them.", OPTIONS)}\n`);
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
const o = parsed.value.options;
|
|
106
|
+
const files = (o.files ?? []).flatMap((f) => f.split(",")).filter((f) => f !== "");
|
|
107
|
+
let libs;
|
|
108
|
+
let packs = new Set();
|
|
109
|
+
if (o.all) {
|
|
110
|
+
libs = everyLibrary(o.repo);
|
|
111
|
+
packs = new Set(libs.map((l) => l.name));
|
|
112
|
+
}
|
|
113
|
+
else if (files.length > 0)
|
|
114
|
+
libs = affectedBy(o.repo, files);
|
|
115
|
+
else if (o.base !== undefined) {
|
|
116
|
+
const changed = await changedSince(o.repo, o.base);
|
|
117
|
+
if (changed === undefined)
|
|
118
|
+
stdio.stderr.writeSync(`plan: git cannot say what changed since ${o.base}; every library is planned\n`);
|
|
119
|
+
libs = changed === undefined ? everyLibrary(o.repo) : affectedBy(o.repo, changed);
|
|
120
|
+
packs = changed === undefined ? new Set(libs.map((l) => l.name)) : await packsFor(o.repo, o.base, libs);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
stdio.stderr.writeSync("plan: give --base REF, --files a,b or --all\n");
|
|
124
|
+
return 2;
|
|
125
|
+
}
|
|
126
|
+
const plan = planOf(libs, packs);
|
|
127
|
+
if (o.githubOutput === undefined)
|
|
128
|
+
stdio.stdout.writeSync(`${JSON.stringify(plan)}\n`);
|
|
129
|
+
else
|
|
130
|
+
writeTextFileSync(o.githubOutput, `${outputsOf(plan)}\n`, { append: true });
|
|
131
|
+
stdio.stderr.writeSync(`plan: ${libs.length} libraries: ${libs.map((l) => l.name).join(", ") || "none"}\n`);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
if (import.meta.main)
|
|
135
|
+
process.exitCode = await main(process.argv.slice(2));
|