@intellectual-frontiers/libraries 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/affected.d.ts +28 -0
- package/dist/affected.js +250 -0
- package/dist/changes.d.ts +27 -0
- package/dist/changes.js +470 -0
- package/dist/check.d.ts +15 -0
- package/dist/check.js +198 -0
- package/dist/generate-ontology.d.ts +37 -0
- package/dist/generate-ontology.js +293 -0
- package/dist/generate-workflows.d.ts +12 -0
- package/dist/generate-workflows.js +102 -0
- package/dist/imports/nist-sp-800-53.import.d.ts +33 -0
- package/dist/imports/nist-sp-800-53.import.js +34 -0
- package/dist/imports/schema-org.import.d.ts +33 -0
- package/dist/imports/schema-org.import.js +31 -0
- package/dist/install-bun.d.ts +1 -0
- package/dist/install-bun.js +58 -0
- package/dist/libraries.d.ts +79 -0
- package/dist/libraries.js +386 -0
- package/dist/mod.d.ts +16 -0
- package/dist/mod.js +16 -0
- package/dist/newer.d.ts +27 -0
- package/dist/newer.js +147 -0
- package/dist/oscal-register.d.ts +65 -0
- package/dist/oscal-register.js +344 -0
- package/dist/pack-library.d.ts +47 -0
- package/dist/pack-library.js +498 -0
- package/dist/pins.d.ts +15 -0
- package/dist/pins.js +29 -0
- package/dist/publish-ontology.d.ts +160 -0
- package/dist/publish-ontology.js +227 -0
- package/dist/versions.d.ts +26 -0
- package/dist/versions.js +556 -0
- package/dist/workflows/definitions.d.ts +65 -0
- package/dist/workflows/definitions.js +619 -0
- package/dist/workflows/mod.d.ts +10 -0
- package/dist/workflows/mod.js +10 -0
- package/dist/workflows/model.d.ts +143 -0
- package/dist/workflows/model.js +81 -0
- package/dist/workflows/render.d.ts +9 -0
- package/dist/workflows/render.js +179 -0
- package/package.json +129 -4
- package/src/affected.ts +265 -0
- package/src/changes.ts +546 -0
- package/src/check.ts +223 -0
- package/src/generate-ontology.ts +350 -0
- package/src/generate-workflows.ts +103 -0
- package/src/imports/nist-sp-800-53.import.ts +36 -0
- package/src/imports/schema-org.import.ts +31 -0
- package/src/install-bun.ts +53 -0
- package/src/libraries.ts +385 -0
- package/src/mod.ts +16 -0
- package/src/newer.ts +154 -0
- package/src/oscal-register.ts +443 -0
- package/src/pack-library.ts +522 -0
- package/src/pins.ts +30 -0
- package/src/publish-ontology.ts +354 -0
- package/src/versions.ts +594 -0
- package/src/workflows/definitions.ts +855 -0
- package/src/workflows/mod.ts +30 -0
- package/src/workflows/model.ts +187 -0
- package/src/workflows/render.ts +176 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Intellectual Frontiers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @intellectual-frontiers/libraries
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The libraries of a repository of commons as code: the manifest of a library and the check that it and its folder agree, which libraries a change affects, the typed workflows of GitHub Actions and their generator, the pinned Bun, the packer that builds, inspects and packs a library for npm with its declarations, and the commands that hold a whole repository to Mizan (check, change control, versions, the register and the ontologies).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add @intellectual-frontiers/libraries # or: npm install @intellectual-frontiers/libraries
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Sources and specifications: https://github.com/intellectual-frontiers/.github/tree/main/commons/libraries
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Library } from "./libraries.js";
|
|
2
|
+
/** What a library reads: its folder, the folders and files it takes from others, what it depends on, and the files it imports one by one. */
|
|
3
|
+
export type Inputs = {
|
|
4
|
+
/** The paths of the library's inputs: `commons/<name>/` and each folder (`commons/ts/kernel/**`) or file the library takes from another. */
|
|
5
|
+
readonly paths: readonly string[];
|
|
6
|
+
/** The folders of commons that the library depends on through its package. */
|
|
7
|
+
readonly dependsOn: readonly string[];
|
|
8
|
+
/** Every file of another folder that it reads, from the repository's root, in order. */
|
|
9
|
+
readonly files: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
/** The folders whose change is every library's change: the tools that check a library and the action that installs Bun. */
|
|
12
|
+
export declare const SHARED: readonly ["commons/tools/**", ".github/actions/**"];
|
|
13
|
+
/** What the library `name` reads (FR-020). */
|
|
14
|
+
export declare function inputsOf(repo: string, name: string): Inputs;
|
|
15
|
+
/** Whether a path of the repository is among the paths of an input: `dir/**` is the folder and what is under it, anything else the file. */
|
|
16
|
+
export declare function matches(paths: readonly string[], file: string): boolean;
|
|
17
|
+
/** The libraries that a list of changed files affects (FR-021): those with a changed file among their inputs, and those that depend on one of these, in order of their names. */
|
|
18
|
+
export declare function affectedBy(repo: string, changed: readonly string[]): readonly (Library & {
|
|
19
|
+
readonly folder: string;
|
|
20
|
+
})[];
|
|
21
|
+
/** The files changed since the merge base of `base` and the head, tracked files of the working tree included; undefined where Git cannot say. */
|
|
22
|
+
export declare function changedSince(repo: string, base: string): Promise<readonly string[] | undefined>;
|
|
23
|
+
/** The matrix a workflow reads: `{"include":[{"name","folder","verify"}]}`. */
|
|
24
|
+
export declare function matrixOf(libs: readonly (Library & {
|
|
25
|
+
readonly folder: string;
|
|
26
|
+
})[]): string;
|
|
27
|
+
/** The command line. Returns the exit status: 0, or 2 for a usage error. */
|
|
28
|
+
export declare function main(argv: readonly string[]): Promise<number>;
|
package/dist/affected.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a change affects (commons 0027-commons-libraries FR-019 to FR-022): the files a library's checks read, taken from its package and its sources, and the libraries that a list of changed files
|
|
3
|
+
* affects, so that CI runs what changed and nothing else.
|
|
4
|
+
*
|
|
5
|
+
* bun commons/libraries/src/affected.ts --base origin/main the libraries a change since the merge base with origin/main affects, as {"include":[{"name","folder","verify"}]}
|
|
6
|
+
* bun commons/libraries/src/affected.ts --files a.ts,b/c.ts the same for a list of files (paths from the repository's root)
|
|
7
|
+
* bun commons/libraries/src/affected.ts --all every library
|
|
8
|
+
* bun commons/libraries/src/affected.ts --inputs data the folders and files the library `data` reads, one a line
|
|
9
|
+
* other flags: --repo DIR (the repository, the working folder by default)
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* A library depends on another folder of commons where its `package.json` names it by path (`link:`, `file:` or `workspace:`), and what it reads of it is what its sources import from the package (the
|
|
13
|
+
* `exports` of the dependency say which file each import is), what its scripts run by a path to another folder (`bun ../libraries/src/check.ts`), and everything those files import by a relative path, followed
|
|
14
|
+
* file by file. An import that no entry of `exports` names takes the whole dependency. The library's inputs are also `commons/tools/**`, `.github/actions/**`, its own workflow and its own folder. A library is
|
|
15
|
+
* affected where a changed file is among its inputs, or where a library it depends on is affected. Nothing is run and nothing is written; the result is the same for the same files.
|
|
16
|
+
*
|
|
17
|
+
* @limits
|
|
18
|
+
* It reads sources with a pattern for `import`, `export ... from` and `import()`, which finds every file a source names (and at worst a file that a comment names, which only adds an input); a file that
|
|
19
|
+
* is read by a program through a path it builds at run time is not found, and a dependency that a library has outside commons is not followed. Where Git cannot say what changed, every library is affected.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { affectedBy } from "./affected.ts";
|
|
24
|
+
* affectedBy(".", ["commons/data/engine/api.ts"]).map((l) => l.name); // ["data"]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Spec: 0001-libraries FR-003
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
import process from "node:process";
|
|
32
|
+
import { existsSync, readDirSync, readTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
33
|
+
import { dirname, join, normalize, resolve, toPosix } from "@intellectual-frontiers/system/path";
|
|
34
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
35
|
+
import { run } from "@intellectual-frontiers/system/proc";
|
|
36
|
+
import { readLibraries } from "./libraries.js";
|
|
37
|
+
/** The folders whose change is every library's change: the tools that check a library and the action that installs Bun. */
|
|
38
|
+
export const SHARED = ["commons/tools/**", ".github/actions/**"];
|
|
39
|
+
const SOURCE = /\.(?:ts|mts|js|mjs)$/;
|
|
40
|
+
const SPECIFIER = /(?:\bimport|\bexport)\s+(?:type\s+)?(?:[^'";]*?\s+from\s+)?["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)/g;
|
|
41
|
+
const posix = (p) => toPosix(normalize(p));
|
|
42
|
+
function objectOf(x) {
|
|
43
|
+
return typeof x === "object" && x !== null && !Array.isArray(x) ? Object.fromEntries(Object.entries(x)) : {};
|
|
44
|
+
}
|
|
45
|
+
const stringOf = (x) => (typeof x === "string" ? x : undefined);
|
|
46
|
+
function readPackage(dir) {
|
|
47
|
+
const file = join(dir, "package.json");
|
|
48
|
+
if (!existsSync(file))
|
|
49
|
+
return undefined;
|
|
50
|
+
const o = objectOf(JSON.parse(readTextFileSync(file)));
|
|
51
|
+
const exports = new Map();
|
|
52
|
+
for (const [k, v] of Object.entries(objectOf(o["exports"]))) {
|
|
53
|
+
const target = stringOf(v) ??
|
|
54
|
+
Object.values(objectOf(v))
|
|
55
|
+
.map(stringOf)
|
|
56
|
+
.find((s) => s !== undefined);
|
|
57
|
+
if (target !== undefined)
|
|
58
|
+
exports.set(k, target);
|
|
59
|
+
}
|
|
60
|
+
const dependencies = new Map();
|
|
61
|
+
for (const field of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"])
|
|
62
|
+
for (const [k, v] of Object.entries(objectOf(o[field])))
|
|
63
|
+
if (typeof v === "string")
|
|
64
|
+
dependencies.set(k, v);
|
|
65
|
+
return {
|
|
66
|
+
name: stringOf(o["name"]),
|
|
67
|
+
exports,
|
|
68
|
+
dependencies,
|
|
69
|
+
scripts: Object.values(objectOf(o["scripts"])).flatMap((s) => (typeof s === "string" ? [s] : [])),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** The files under a folder that are sources, from the repository's root (`node_modules` and `dist` are not looked into). */
|
|
73
|
+
function sourcesUnder(root, dir) {
|
|
74
|
+
const out = [];
|
|
75
|
+
const walk = (d) => {
|
|
76
|
+
for (const e of readDirSync(join(root, d))) {
|
|
77
|
+
if (e.name === "node_modules" || e.name === "dist" || e.name.startsWith("."))
|
|
78
|
+
continue;
|
|
79
|
+
const p = `${d}/${e.name}`;
|
|
80
|
+
if (e.isDirectory)
|
|
81
|
+
walk(p);
|
|
82
|
+
else if (e.isFile && SOURCE.test(e.name))
|
|
83
|
+
out.push(p);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
walk(dir);
|
|
87
|
+
return out.sort();
|
|
88
|
+
}
|
|
89
|
+
const specifiersOf = (text) => [...text.matchAll(SPECIFIER)].map((m) => m[1] ?? m[2] ?? "").filter((s) => s !== "");
|
|
90
|
+
/** The file a relative specifier names, from the repository's root: the path as written, or with `.ts`, `/mod.ts` or `/index.ts`. */
|
|
91
|
+
function resolveFile(root, from, specifier) {
|
|
92
|
+
const base = posix(join(dirname(from), specifier));
|
|
93
|
+
if (base.startsWith(".."))
|
|
94
|
+
return undefined;
|
|
95
|
+
for (const c of [base, `${base}.ts`, `${base}/mod.ts`, `${base}/index.ts`])
|
|
96
|
+
if (SOURCE.test(c) && existsSync(join(root, c)))
|
|
97
|
+
return c;
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
/** Every file reached from the entries by relative imports, the entries included. */
|
|
101
|
+
function closure(root, entries) {
|
|
102
|
+
const seen = new Set();
|
|
103
|
+
const todo = [...entries];
|
|
104
|
+
for (let f = todo.pop(); f !== undefined; f = todo.pop()) {
|
|
105
|
+
if (seen.has(f) || !existsSync(join(root, f)))
|
|
106
|
+
continue;
|
|
107
|
+
seen.add(f);
|
|
108
|
+
if (!SOURCE.test(f))
|
|
109
|
+
continue;
|
|
110
|
+
for (const s of specifiersOf(readTextFileSync(join(root, f)))) {
|
|
111
|
+
if (!s.startsWith("."))
|
|
112
|
+
continue;
|
|
113
|
+
const r = resolveFile(root, f, s);
|
|
114
|
+
if (r !== undefined)
|
|
115
|
+
todo.push(r);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return seen;
|
|
119
|
+
}
|
|
120
|
+
/** The path as a filter reads it: the folder of a file two levels under `commons/<folder>/` is `commons/<folder>/<sub>/**`, one level `commons/<folder>/**`, and a file at the top is itself. */
|
|
121
|
+
function folderOf(file) {
|
|
122
|
+
const parts = file.split("/");
|
|
123
|
+
if (parts[0] === "commons" && parts.length >= 4)
|
|
124
|
+
return `commons/${parts[1] ?? ""}/${parts[2] ?? ""}/**`;
|
|
125
|
+
if (parts[0] === "commons" && parts.length === 3)
|
|
126
|
+
return `commons/${parts[1] ?? ""}/**`;
|
|
127
|
+
return file;
|
|
128
|
+
}
|
|
129
|
+
/** What the library `name` reads (FR-020). */
|
|
130
|
+
export function inputsOf(repo, name) {
|
|
131
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
132
|
+
const folder = `commons/${name}`;
|
|
133
|
+
const pkg = readPackage(join(root, folder));
|
|
134
|
+
const sources = sourcesUnder(root, folder);
|
|
135
|
+
const texts = sources.map((f) => ({ f, text: readTextFileSync(join(root, f)) }));
|
|
136
|
+
const entries = new Set();
|
|
137
|
+
const whole = new Set();
|
|
138
|
+
const dependsOn = new Set();
|
|
139
|
+
// a dependency by path: its folder, what the library's sources import from it, and the entries it maps them to
|
|
140
|
+
for (const [dep, spec] of pkg?.dependencies ?? []) {
|
|
141
|
+
const m = /^(?:link|file|workspace):(.+)$/.exec(spec);
|
|
142
|
+
if (m?.[1] === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
const dir = posix(join(folder, m[1]));
|
|
145
|
+
if (dir.startsWith("..") || !existsSync(join(root, dir)))
|
|
146
|
+
continue;
|
|
147
|
+
const depPkg = readPackage(join(root, dir));
|
|
148
|
+
dependsOn.add(dir.split("/")[1] ?? dir);
|
|
149
|
+
const imported = new Set();
|
|
150
|
+
for (const { text } of texts)
|
|
151
|
+
for (const s of specifiersOf(text))
|
|
152
|
+
if (s === dep || s.startsWith(`${dep}/`))
|
|
153
|
+
imported.add(s === dep ? "." : `.${s.slice(dep.length)}`);
|
|
154
|
+
for (const key of imported) {
|
|
155
|
+
const target = depPkg?.exports.get(key);
|
|
156
|
+
if (target === undefined)
|
|
157
|
+
whole.add(`${dir}/**`);
|
|
158
|
+
else
|
|
159
|
+
entries.add(posix(join(dir, target)));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// a path to another folder in a script of the package: `bun ../libraries/src/check.ts`
|
|
163
|
+
for (const script of pkg?.scripts ?? [])
|
|
164
|
+
for (const m of script.matchAll(/(?:^|\s)(\.\.\/[\w./-]+)/g)) {
|
|
165
|
+
const p = posix(join(folder, m[1] ?? ""));
|
|
166
|
+
if (!p.startsWith("..") && existsSync(join(root, p)) && SOURCE.test(p))
|
|
167
|
+
entries.add(p);
|
|
168
|
+
}
|
|
169
|
+
const files = [...closure(root, [...entries])].filter((f) => !f.startsWith(`${folder}/`)).sort();
|
|
170
|
+
const paths = [`${folder}/**`, ...new Set([...files.map(folderOf), ...whole, ...SHARED, `.github/workflows/${name}.auto.yml`])].sort();
|
|
171
|
+
for (const f of files) {
|
|
172
|
+
const d = f.split("/")[1];
|
|
173
|
+
if (d !== undefined && d !== name && existsSync(join(root, "commons", d, "library.ts")))
|
|
174
|
+
dependsOn.add(d);
|
|
175
|
+
}
|
|
176
|
+
return { paths, dependsOn: [...dependsOn].sort(), files };
|
|
177
|
+
}
|
|
178
|
+
/** Whether a path of the repository is among the paths of an input: `dir/**` is the folder and what is under it, anything else the file. */
|
|
179
|
+
export function matches(paths, file) {
|
|
180
|
+
return paths.some((p) => (p.endsWith("/**") ? file.startsWith(p.slice(0, -2)) : p === file));
|
|
181
|
+
}
|
|
182
|
+
/** The libraries that a list of changed files affects (FR-021): those with a changed file among their inputs, and those that depend on one of these, in order of their names. */
|
|
183
|
+
export function affectedBy(repo, changed) {
|
|
184
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
185
|
+
const libs = readLibraries(root).flatMap((f) => ("library" in f ? [f.library] : []));
|
|
186
|
+
const inputs = new Map(libs.map((l) => [l.name, inputsOf(root, l.name)]));
|
|
187
|
+
const hit = new Set(libs.filter((l) => changed.some((c) => matches(inputs.get(l.name)?.paths ?? [], c))).map((l) => l.name));
|
|
188
|
+
for (let grew = true; grew;) {
|
|
189
|
+
grew = false;
|
|
190
|
+
for (const l of libs) {
|
|
191
|
+
if (!hit.has(l.name) && (inputs.get(l.name)?.dependsOn ?? []).some((d) => hit.has(d))) {
|
|
192
|
+
hit.add(l.name);
|
|
193
|
+
grew = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return libs.filter((l) => hit.has(l.name)).map((l) => ({ ...l, folder: `commons/${l.name}` }));
|
|
198
|
+
}
|
|
199
|
+
/** The files changed since the merge base of `base` and the head, tracked files of the working tree included; undefined where Git cannot say. */
|
|
200
|
+
export async function changedSince(repo, base) {
|
|
201
|
+
const root = resolve(repo);
|
|
202
|
+
try {
|
|
203
|
+
const mb = await run(["git", "-C", root, "merge-base", base, "HEAD"]);
|
|
204
|
+
if (mb.code !== 0)
|
|
205
|
+
return undefined;
|
|
206
|
+
const d = await run(["git", "-C", root, "diff", "--name-only", mb.stdout.trim()]);
|
|
207
|
+
return d.code === 0 ? d.stdout.split("\n").filter((l) => l !== "") : undefined;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** The matrix a workflow reads: `{"include":[{"name","folder","verify"}]}`. */
|
|
214
|
+
export function matrixOf(libs) {
|
|
215
|
+
return JSON.stringify({ include: libs.map((l) => ({ name: l.name, folder: l.folder, verify: l.verify })) });
|
|
216
|
+
}
|
|
217
|
+
/** The command line. Returns the exit status: 0, or 2 for a usage error. */
|
|
218
|
+
export async function main(argv) {
|
|
219
|
+
const arg = (flag) => {
|
|
220
|
+
const at = argv.indexOf(flag);
|
|
221
|
+
return at >= 0 ? argv[at + 1] : undefined;
|
|
222
|
+
};
|
|
223
|
+
const repo = arg("--repo") ?? ".";
|
|
224
|
+
const inputs = arg("--inputs");
|
|
225
|
+
if (inputs !== undefined) {
|
|
226
|
+
const i = inputsOf(repo, inputs);
|
|
227
|
+
stdio.stdout.writeSync(`${[...i.paths, ...i.files.map((f) => ` ${f}`)].join("\n")}\n`);
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
const everything = readLibraries(repo).flatMap((f) => ("library" in f ? [{ ...f.library, folder: `commons/${f.dir}` }] : []));
|
|
231
|
+
const files = arg("--files");
|
|
232
|
+
const base = arg("--base");
|
|
233
|
+
if (argv.includes("--all"))
|
|
234
|
+
stdio.stdout.writeSync(`${matrixOf(everything)}\n`);
|
|
235
|
+
else if (files !== undefined)
|
|
236
|
+
stdio.stdout.writeSync(`${matrixOf(affectedBy(repo, files.split(",").filter((f) => f !== "")))}\n`);
|
|
237
|
+
else if (base !== undefined) {
|
|
238
|
+
const changed = await changedSince(repo, base);
|
|
239
|
+
if (changed === undefined)
|
|
240
|
+
stdio.stderr.writeSync(`affected: git cannot say what changed since ${base}; every library is affected\n`);
|
|
241
|
+
stdio.stdout.writeSync(`${matrixOf(changed === undefined ? everything : affectedBy(repo, changed))}\n`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
stdio.stderr.writeSync("affected: give --base REF, --files a,b, --all or --inputs NAME\n");
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
if (import.meta.main)
|
|
250
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GitHostClient, RepoRef } from "@intellectual-frontiers/githost/types";
|
|
2
|
+
/** One rule's result in a run of the check (0020-ifccm FR-031): its findings, or the reason it did not run. Its shape is the quality system's `CheckRule`, so a caller keeps it as a record without this file knowing the quality system. */
|
|
3
|
+
export type RuleResult = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly findings: readonly {
|
|
6
|
+
readonly file: string;
|
|
7
|
+
readonly line?: number;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
}[];
|
|
10
|
+
readonly notRun?: string;
|
|
11
|
+
};
|
|
12
|
+
/** What the command is given besides its arguments: the host's client and the repository it serves, which the command never makes, and where it writes. */
|
|
13
|
+
export type Deps = {
|
|
14
|
+
/** Called once with each rule's result where the check judged commits or a declaration (0020-ifccm FR-031), so that the caller can keep it as a record. */
|
|
15
|
+
readonly onRules?: (rules: readonly RuleResult[]) => void;
|
|
16
|
+
readonly client?: GitHostClient;
|
|
17
|
+
/** The repository on the host that the commits belong to; a reference `#N` is asked of it. */
|
|
18
|
+
readonly home?: RepoRef;
|
|
19
|
+
readonly out?: (text: string) => void;
|
|
20
|
+
readonly err?: (text: string) => void;
|
|
21
|
+
};
|
|
22
|
+
/** The default name of a harness's record, in the repository's top folder. */
|
|
23
|
+
export declare const RECORD_FILE = "ifccm.declaration.ts";
|
|
24
|
+
/** The default name of the baseline of the check's findings, in the repository's top folder. */
|
|
25
|
+
export declare const BASELINE_FILE = "changes.baseline.txt";
|
|
26
|
+
/** Run the command; the exit status (0 clean, 1 findings, 2 usage, 3 environment). */
|
|
27
|
+
export declare function run(argv: readonly string[], deps?: Deps, now?: () => string): Promise<number>;
|