@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
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* The manifest of a library of commons (commons 0027-commons-libraries FR-011 to FR-014) and the requirements it makes: a library is a folder `commons/<name>/` that holds `library.ts`, an
|
|
55
|
+
* object literal read as data and never run, and this repository knows it from that file alone. The decoder of the manifest, the check that a manifest and its folder agree, and the generator of
|
|
56
|
+
* the section "The libraries" of 0027-commons-libraries and of its rows of `enforcement.tsv`.
|
|
57
|
+
*
|
|
58
|
+
* bun commons/libraries/src/libraries.ts write the section and the rows again from the manifests
|
|
59
|
+
* bun commons/libraries/src/libraries.ts --check write nothing and exit 1 where a file is not what the manifests make, or where a manifest and its folder disagree
|
|
60
|
+
* other flags: --repo DIR (the repository, the working folder by default)
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
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 -->`,
|
|
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
|
+
* running this command.
|
|
67
|
+
*
|
|
68
|
+
* @limits
|
|
69
|
+
* It reads files and writes two; it runs no library's `verify` (`check.ts --all` does, 0028-conformance-levels FR-012), and it does not read inside a library but its manifest, its package and the files that name its spec kit.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { decodeLibrarySource } from "./libraries.ts";
|
|
74
|
+
* const r = decodeLibrarySource('export const library = { name: "x", verify: "bun run verify", version: "0.1.0", exports: [] };');
|
|
75
|
+
* r.kind; // "ok"
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* Spec: 0001-libraries FR-001
|
|
79
|
+
*
|
|
80
|
+
* @module
|
|
81
|
+
*/
|
|
82
|
+
import process from "node:process";
|
|
83
|
+
import { array, describe, formatDecodeError, literal, object, string, err, ok, } from "@intellectual-frontiers/core";
|
|
84
|
+
import { exportedLiteral } from "@intellectual-frontiers/formats/ts-literal";
|
|
85
|
+
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
86
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
87
|
+
import { spawn } from "@intellectual-frontiers/system/proc";
|
|
88
|
+
import { DEFAULT_LIBRARY_LEVEL, LEVELS, rankOf } from "@intellectual-frontiers/mizan/levels";
|
|
89
|
+
/** The name of a library's manifest in its folder. */
|
|
90
|
+
export const LIBRARY_FILE = "library.ts";
|
|
91
|
+
/** The specification that holds the requirements of the libraries, and the first number of the requirements it generates. */
|
|
92
|
+
export const LIBRARIES_SPEC = "0027-commons-libraries";
|
|
93
|
+
/** The first requirement number of the section "The libraries", which is generated (0027-commons-libraries FR-011). */
|
|
94
|
+
export const FIRST_GENERATED = 101;
|
|
95
|
+
/** The marker that opens the generated section, and the one that closes it. */
|
|
96
|
+
export const BEGIN = "<!-- libraries:begin -->";
|
|
97
|
+
export const END = "<!-- libraries:end -->";
|
|
98
|
+
/** Where the generated section begins and ends: the markers on lines of their own (a requirement may name them in its text). */
|
|
99
|
+
function bounds(spec) {
|
|
100
|
+
const from = spec.indexOf(`\n${BEGIN}\n`);
|
|
101
|
+
const to = spec.indexOf(`\n${END}\n`, from);
|
|
102
|
+
return from < 0 || to < 0 ? undefined : { from: from + 1, to: to + 1 };
|
|
103
|
+
}
|
|
104
|
+
/** The registries a library may be published to: the kinds only, never a host or a credential (0027-commons-libraries FR-018). */
|
|
105
|
+
export const REGISTRIES = ["github", "npm"];
|
|
106
|
+
/** Where a manifest that declares no distribution is published. */
|
|
107
|
+
export const DEFAULT_DISTRIBUTION = ["github"];
|
|
108
|
+
const nonEmpty = (input, path = "$") => {
|
|
109
|
+
const r = string(input, path);
|
|
110
|
+
if (r.kind === "err")
|
|
111
|
+
return r;
|
|
112
|
+
return r.value.trim() === "" ? err({ kind: "decode", path, expected: "a non-empty string", found: describe(input) }) : r;
|
|
113
|
+
};
|
|
114
|
+
const nameDecoder = (input, path = "$") => {
|
|
115
|
+
const r = string(input, path);
|
|
116
|
+
if (r.kind === "err")
|
|
117
|
+
return r;
|
|
118
|
+
return /^[a-z][a-z0-9-]*$/.test(r.value)
|
|
119
|
+
? r
|
|
120
|
+
: err({ kind: "decode", path, expected: "a name of lower-case letters, digits and hyphens", found: describe(input) });
|
|
121
|
+
};
|
|
122
|
+
const body = object({ name: nameDecoder, verify: nonEmpty, version: nonEmpty, exports: array(nonEmpty) }, { level: literal(...LEVELS), specKit: nonEmpty, summary: nonEmpty, distribution: array(literal(...REGISTRIES)) });
|
|
123
|
+
const FIELDS = ["name", "level", "specKit", "verify", "version", "exports", "summary", "distribution"];
|
|
124
|
+
/** 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). */
|
|
125
|
+
export function decodeLibrarySource(source) {
|
|
126
|
+
const exports = source.split("\n").filter((l) => /^export\s/.test(l));
|
|
127
|
+
if (exports.length !== 1)
|
|
128
|
+
return err(`a manifest exports only library, and this file has ${exports.length} exports`);
|
|
129
|
+
const lit = exportedLiteral(source, "library");
|
|
130
|
+
if (lit.kind === "err")
|
|
131
|
+
return err(`the manifest is not a literal: ${lit.error.expected}`);
|
|
132
|
+
const input = lit.value;
|
|
133
|
+
if (typeof input === "object" && input !== null && !Array.isArray(input)) {
|
|
134
|
+
const known = FIELDS;
|
|
135
|
+
const bad = Object.keys(input).find((k) => !known.includes(k));
|
|
136
|
+
if (bad !== undefined)
|
|
137
|
+
return err(`library.${bad} is an unknown field (a manifest has ${FIELDS.join(", ")})`);
|
|
138
|
+
}
|
|
139
|
+
const r = body(input, "library");
|
|
140
|
+
if (r.kind === "err")
|
|
141
|
+
return err(formatDecodeError(r.error));
|
|
142
|
+
const v = r.value;
|
|
143
|
+
const distribution = v.distribution ?? DEFAULT_DISTRIBUTION;
|
|
144
|
+
if (distribution.length === 0 || new Set(distribution).size !== distribution.length)
|
|
145
|
+
return err("library.distribution lists each registry once and at least one (FR-015)");
|
|
146
|
+
if (!distribution.includes("github"))
|
|
147
|
+
return err("library.distribution includes github: a library is published to the GitHub package registry whatever else it is published to (FR-015, FR-016)");
|
|
148
|
+
return ok({
|
|
149
|
+
name: v.name,
|
|
150
|
+
level: v.level ?? DEFAULT_LIBRARY_LEVEL,
|
|
151
|
+
...(v.specKit === undefined ? {} : { specKit: v.specKit }),
|
|
152
|
+
verify: v.verify,
|
|
153
|
+
version: v.version,
|
|
154
|
+
exports: v.exports,
|
|
155
|
+
...(v.summary === undefined ? {} : { summary: v.summary }),
|
|
156
|
+
distribution,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** The manifests of `commons/*`, in the order of the folders' names: every folder that holds a `library.ts`. */
|
|
160
|
+
export function readLibraries(repo) {
|
|
161
|
+
const commons = `${repo.replace(/[\\/]$/, "")}/commons`;
|
|
162
|
+
if (!existsSync(commons))
|
|
163
|
+
return [];
|
|
164
|
+
return readDirSync(commons)
|
|
165
|
+
.filter((e) => e.isDirectory && existsSync(`${commons}/${e.name}/${LIBRARY_FILE}`))
|
|
166
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
167
|
+
.map((e) => {
|
|
168
|
+
const r = decodeLibrarySource(readTextFileSync(`${commons}/${e.name}/${LIBRARY_FILE}`));
|
|
169
|
+
return r.kind === "ok" ? { dir: e.name, library: r.value } : { dir: e.name, problem: r.error };
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** The keys of a package's `exports`, its name and version and the scripts it has, read from `package.json`. */
|
|
173
|
+
function packageOf(file) {
|
|
174
|
+
const raw = JSON.parse(readTextFileSync(file));
|
|
175
|
+
const o = typeof raw === "object" && raw !== null ? raw : {};
|
|
176
|
+
const field = (k) => Object.entries(o).find(([n]) => n === k)?.[1];
|
|
177
|
+
const keys = (v) => (typeof v === "object" && v !== null ? Object.keys(v) : []);
|
|
178
|
+
const name = field("name");
|
|
179
|
+
const version = field("version");
|
|
180
|
+
return {
|
|
181
|
+
...(typeof name === "string" ? { name } : {}),
|
|
182
|
+
...(typeof version === "string" ? { version } : {}),
|
|
183
|
+
exports: keys(field("exports")),
|
|
184
|
+
scripts: keys(field("scripts")),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The script a verify command runs: `bun run verify` runs the script `verify`. */
|
|
188
|
+
function scriptOf(verify) {
|
|
189
|
+
return /^bun run ([A-Za-z0-9:_-]+)$/.exec(verify)?.[1];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* What is wrong where a manifest and its folder disagree (0027-commons-libraries FR-013), one sentence each: a folder with a spec kit and no manifest, a manifest that cannot be read, that names another
|
|
193
|
+
* folder, a level above L0 with no spec kit, a spec kit that is not there, a package of another name, a version that is not the package's, exports that are not the package's, and a verify that is no script of the package.
|
|
194
|
+
*/
|
|
195
|
+
export function manifestFindings(repo) {
|
|
196
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
197
|
+
const commons = `${root}/commons`;
|
|
198
|
+
const found = [];
|
|
199
|
+
const have = readLibraries(root);
|
|
200
|
+
for (const e of existsSync(commons) ? readDirSync(commons) : [])
|
|
201
|
+
if (e.isDirectory && existsSync(`${commons}/${e.name}/spec-kit`) && !have.some((l) => l.dir === e.name))
|
|
202
|
+
found.push(`commons/${e.name} has a spec kit and no ${LIBRARY_FILE}: a library declares itself (FR-012)`);
|
|
203
|
+
for (const f of have) {
|
|
204
|
+
const dir = `${commons}/${f.dir}`;
|
|
205
|
+
if ("problem" in f) {
|
|
206
|
+
found.push(`commons/${f.dir}/${LIBRARY_FILE}: ${f.problem} (FR-012)`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const l = f.library;
|
|
210
|
+
if (l.name !== f.dir)
|
|
211
|
+
found.push(`commons/${f.dir}/${LIBRARY_FILE} is named ${l.name}, and its folder is ${f.dir} (FR-013)`);
|
|
212
|
+
if (rankOf(l.level) >= 1 && l.specKit === undefined)
|
|
213
|
+
found.push(`commons/${f.dir}/${LIBRARY_FILE} declares ${l.level} and no spec kit, which a level above L0 asks (FR-013)`);
|
|
214
|
+
if (l.specKit !== undefined && !existsSync(`${dir}/${l.specKit}/registry.tsv`))
|
|
215
|
+
found.push(`commons/${f.dir}: the spec kit ${l.specKit} the manifest names has no registry.tsv (FR-013)`);
|
|
216
|
+
if (!existsSync(`${dir}/package.json`)) {
|
|
217
|
+
found.push(`commons/${f.dir}/package.json is missing (FR-013)`);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const pkg = packageOf(`${dir}/package.json`);
|
|
221
|
+
if (pkg.name !== `@intellectual-frontiers/${l.name}`)
|
|
222
|
+
found.push(`commons/${f.dir}/package.json is not named @intellectual-frontiers/${l.name} (FR-013)`);
|
|
223
|
+
if (pkg.version !== l.version)
|
|
224
|
+
found.push(`commons/${f.dir}: the manifest says version ${l.version} and the package says ${pkg.version ?? "none"} (FR-013)`);
|
|
225
|
+
const missing = l.exports.filter((x) => !pkg.exports.includes(x));
|
|
226
|
+
const extra = pkg.exports.filter((x) => !l.exports.includes(x));
|
|
227
|
+
if (missing.length > 0 || extra.length > 0)
|
|
228
|
+
found.push(`commons/${f.dir}: the manifest and the package disagree on exports (${[...missing.map((x) => `${x} is not the package's`), ...extra.map((x) => `${x} is not the manifest's`)].join("; ")}) (FR-013)`);
|
|
229
|
+
const script = scriptOf(l.verify);
|
|
230
|
+
if (script === undefined || !pkg.scripts.includes(script))
|
|
231
|
+
found.push(`commons/${f.dir}: the verify command ${JSON.stringify(l.verify)} is not a script of the package (FR-013)`);
|
|
232
|
+
const verifyText = script === undefined ? "" : scriptText(`${dir}/package.json`, script);
|
|
233
|
+
if (rankOf(l.level) >= 1 && rankOf(l.level) < rankOf("L3") && !verifyText.includes(`--level ${l.level}`))
|
|
234
|
+
found.push(`commons/${f.dir}: the manifest declares ${l.level} and the verify script does not run the Mizan check with --level ${l.level} (0028-conformance-levels FR-013)`);
|
|
235
|
+
}
|
|
236
|
+
return found;
|
|
237
|
+
}
|
|
238
|
+
/** A field of a value read from JSON, `undefined` where the value is not an object or has no such field. */
|
|
239
|
+
function fieldOf(value, key) {
|
|
240
|
+
return typeof value === "object" && value !== null ? Object.entries(value).find(([n]) => n === key)?.[1] : undefined;
|
|
241
|
+
}
|
|
242
|
+
function scriptText(file, script) {
|
|
243
|
+
const raw = JSON.parse(readTextFileSync(file));
|
|
244
|
+
const text = fieldOf(fieldOf(raw, "scripts"), script);
|
|
245
|
+
return typeof text === "string" ? text : "";
|
|
246
|
+
}
|
|
247
|
+
/** The ontology's name for a level of a manifest: `mz:Registered`, `mz:Core`, `mz:Standards` or `mz:Governed`. */
|
|
248
|
+
const LEVEL_TERM = { L0: "mz:Registered", L1: "mz:Core", L2: "mz:Standards", L3: "mz:Governed" };
|
|
249
|
+
/** How a registry is named in the requirement of a library. */
|
|
250
|
+
const REGISTRY_NAME = { github: "the GitHub package registry", npm: "npm" };
|
|
251
|
+
const list = (items) => {
|
|
252
|
+
const quoted = items.map((i) => `\`${i}\``);
|
|
253
|
+
return quoted.length <= 1 ? (quoted[0] ?? "no exports") : `${quoted.slice(0, -1).join(", ")} and ${quoted[quoted.length - 1] ?? ""}`;
|
|
254
|
+
};
|
|
255
|
+
/** The requirement of a library, as the section "The libraries" holds it (FR-014): one line. */
|
|
256
|
+
export function requirementOf(id, l) {
|
|
257
|
+
const kit = l.specKit === undefined ? "" : `, its spec kit at \`commons/${l.name}/${l.specKit}\``;
|
|
258
|
+
const summary = l.summary === undefined ? "" : ` ${l.summary}`;
|
|
259
|
+
const where = l.distribution.map((r) => REGISTRY_NAME[r]).join(" and ");
|
|
260
|
+
return `- **${id}**: \`commons/${l.name}\` MUST be a library at conformance level ${l.level} (\`${LEVEL_TERM[l.level]}\`): the package \`@intellectual-frontiers/${l.name}\` at version \`${l.version}\`${kit}, exporting ${list(l.exports)}, published to ${where}, proved by \`cd commons/${l.name} && ${l.verify}\`.${summary}`;
|
|
261
|
+
}
|
|
262
|
+
/** The row of `enforcement.tsv` of a library's requirement. */
|
|
263
|
+
export function rowOf(id, l) {
|
|
264
|
+
const kit = l.specKit === undefined ? "its manifest" : "its compiler, specification checker, rules and tests";
|
|
265
|
+
return `${LIBRARIES_SPEC} ${id}\tcheck\t.github: cd commons/${l.name} && ${l.verify}\tcommons/${l.name}: the verify of the library (${kit}); the manifest ${LIBRARY_FILE} agrees with the folder and the package (commons-libraries.test.ts)`;
|
|
266
|
+
}
|
|
267
|
+
/** The ids the section already gives each library, by name, read from its text between the markers. */
|
|
268
|
+
export function idsIn(spec) {
|
|
269
|
+
const out = new Map();
|
|
270
|
+
const b = bounds(spec);
|
|
271
|
+
if (b === undefined)
|
|
272
|
+
return out;
|
|
273
|
+
for (const line of spec.slice(b.from, b.to).split("\n")) {
|
|
274
|
+
const m = /^- \*\*(FR-\d+)\*\*: `commons\/([a-z][a-z0-9-]*)`/.exec(line);
|
|
275
|
+
if (m?.[1] !== undefined && m[2] !== undefined)
|
|
276
|
+
out.set(m[2], m[1]);
|
|
277
|
+
}
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
/** The id each library has: the one it had, or the next number after the greatest. */
|
|
281
|
+
export function idsFor(libraries, had) {
|
|
282
|
+
const out = new Map();
|
|
283
|
+
let next = Math.max(FIRST_GENERATED - 1, ...[...had.values()].map((id) => Number(id.slice(3)))) + 1;
|
|
284
|
+
for (const l of libraries) {
|
|
285
|
+
const id = had.get(l.name);
|
|
286
|
+
if (id !== undefined)
|
|
287
|
+
out.set(l.name, id);
|
|
288
|
+
else
|
|
289
|
+
out.set(l.name, `FR-${String(next++).padStart(3, "0")}`);
|
|
290
|
+
}
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
/** The text of the specification and of the register, made again from the libraries: nothing where the specification has no markers. */
|
|
294
|
+
export function generated(spec, enforcement, libraries) {
|
|
295
|
+
const b = bounds(spec);
|
|
296
|
+
if (b === undefined)
|
|
297
|
+
return err(`${LIBRARIES_SPEC} has no ${BEGIN} and ${END}, each on a line of its own, around the section "The libraries"`);
|
|
298
|
+
const ids = idsFor(libraries, idsIn(spec));
|
|
299
|
+
// in the order of their numbers, which a library keeps for its life: a library added later is after those that were there, whatever its name
|
|
300
|
+
const byNumber = [...libraries].sort((a, b) => Number((ids.get(a.name) ?? "").slice(3)) - Number((ids.get(b.name) ?? "").slice(3)));
|
|
301
|
+
const lines = byNumber.map((l) => requirementOf(ids.get(l.name) ?? "", l));
|
|
302
|
+
const newSpec = `${spec.slice(0, b.from + BEGIN.length)}\n\n${lines.join("\n")}\n\n${spec.slice(b.to)}`;
|
|
303
|
+
const rows = byNumber.map((l) => rowOf(ids.get(l.name) ?? "", l));
|
|
304
|
+
const kept = enforcement.split("\n").filter((l) => l !== "" && !new RegExp(`^${LIBRARIES_SPEC} FR-(?:[1-9]\\d{2,})\\t`).test(l));
|
|
305
|
+
const last = kept.map((l, i) => (l.startsWith(`${LIBRARIES_SPEC} `) ? i : -1)).reduce((a, b) => Math.max(a, b), -1);
|
|
306
|
+
const at = last < 0 ? kept.length : last + 1;
|
|
307
|
+
return ok({ spec: newSpec, enforcement: `${[...kept.slice(0, at), ...rows, ...kept.slice(at)].join("\n")}\n` });
|
|
308
|
+
}
|
|
309
|
+
const SPEC_FILE = (repo) => `${repo}/commons/spec-kit/specs/${LIBRARIES_SPEC}/spec.md`;
|
|
310
|
+
const ENFORCEMENT_FILE = (repo) => `${repo}/commons/spec-kit/enforcement.tsv`;
|
|
311
|
+
/** The files that are not what the manifests make (relative to the repository), and what is wrong with the manifests; with `write`, the files are written. */
|
|
312
|
+
export function synchronize(repo, write) {
|
|
313
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
314
|
+
const have = readLibraries(root);
|
|
315
|
+
const problems = [
|
|
316
|
+
...have.flatMap((f) => ("problem" in f ? [`commons/${f.dir}/${LIBRARY_FILE}: ${f.problem}`] : [])),
|
|
317
|
+
...manifestFindings(root),
|
|
318
|
+
];
|
|
319
|
+
const libraries = have.flatMap((f) => ("library" in f ? [f.library] : []));
|
|
320
|
+
const spec = readTextFileSync(SPEC_FILE(root)).replace(/\r\n/g, "\n"); // a Windows checkout may hold CRLF; the markers are found on lines of LF
|
|
321
|
+
const enforcement = readTextFileSync(ENFORCEMENT_FILE(root)).replace(/\r\n/g, "\n");
|
|
322
|
+
const made = generated(spec, enforcement, libraries);
|
|
323
|
+
if (made.kind === "err")
|
|
324
|
+
return { stale: [], problems: [...problems, made.error] };
|
|
325
|
+
const stale = [];
|
|
326
|
+
if (made.value.spec !== spec) {
|
|
327
|
+
stale.push(`commons/spec-kit/specs/${LIBRARIES_SPEC}/spec.md`);
|
|
328
|
+
if (write)
|
|
329
|
+
writeTextFileSync(SPEC_FILE(root), made.value.spec);
|
|
330
|
+
}
|
|
331
|
+
if (made.value.enforcement !== enforcement) {
|
|
332
|
+
stale.push("commons/spec-kit/enforcement.tsv");
|
|
333
|
+
if (write)
|
|
334
|
+
writeTextFileSync(ENFORCEMENT_FILE(root), made.value.enforcement);
|
|
335
|
+
}
|
|
336
|
+
return { stale, problems };
|
|
337
|
+
}
|
|
338
|
+
/** Runs the `verify` of every library a manifest declares, each from its own folder, and gives each status (0028-conformance-levels FR-012). */
|
|
339
|
+
export async function verifyAll(repo) {
|
|
340
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
341
|
+
const out = [];
|
|
342
|
+
for (const f of readLibraries(root)) {
|
|
343
|
+
if ("problem" in f) {
|
|
344
|
+
out.push({ name: f.dir, code: 1 });
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
stdio.stderr.writeSync(`verify ${f.dir}: ${f.library.verify}\n`);
|
|
348
|
+
const [cmd, ...args] = f.library.verify.split(" ");
|
|
349
|
+
try {
|
|
350
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
351
|
+
try {
|
|
352
|
+
const child = __addDisposableResource(env_1, spawn([cmd ?? "", ...args], { cwd: `${root}/commons/${f.dir}` }), true);
|
|
353
|
+
const status = await child.status;
|
|
354
|
+
out.push({ name: f.dir, code: status.code });
|
|
355
|
+
}
|
|
356
|
+
catch (e_1) {
|
|
357
|
+
env_1.error = e_1;
|
|
358
|
+
env_1.hasError = true;
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
const result_1 = __disposeResources(env_1);
|
|
362
|
+
if (result_1)
|
|
363
|
+
await result_1;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch (e) {
|
|
367
|
+
stdio.stderr.writeSync(`verify ${f.dir}: ${e instanceof Error ? e.message : String(e)}\n`);
|
|
368
|
+
out.push({ name: f.dir, code: 1 });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
373
|
+
/** The command line. Returns the exit status: 0, or 1 where a file is not what the manifests make or a manifest and its folder disagree. */
|
|
374
|
+
export function main(argv) {
|
|
375
|
+
const at = argv.indexOf("--repo");
|
|
376
|
+
const repo = at >= 0 ? (argv[at + 1] ?? ".") : ".";
|
|
377
|
+
const check = argv.includes("--check");
|
|
378
|
+
const r = synchronize(repo, !check);
|
|
379
|
+
for (const p of r.problems)
|
|
380
|
+
stdio.stderr.writeSync(`${p}\n`);
|
|
381
|
+
for (const s of r.stale)
|
|
382
|
+
stdio.stderr.writeSync(check ? `${s} is not what the manifests make; run: bun commons/libraries/src/libraries.ts\n` : `wrote ${s}\n`);
|
|
383
|
+
return r.problems.length > 0 || (check && r.stale.length > 0) ? 1 : 0;
|
|
384
|
+
}
|
|
385
|
+
if (import.meta.main)
|
|
386
|
+
process.exitCode = main(process.argv.slice(2));
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What of Mizan is still in this package (commons 0032-lifting-libraries): the commands that need the whole repository. `check.ts` holds a repository's spec kit and ontologies, `versions.ts` and
|
|
3
|
+
* `changes.ts` are the commands of the release check and the change-control check, `libraries.ts` reads the manifests of the libraries, `newer.ts` reports a standard newer than its pin, `generate-ontology.ts` writes the Turtle of the ontologies and
|
|
4
|
+
* `oscal-register.ts` the register of proofs as OSCAL. The harness, the rules, the levels, the integrations, the change-control and release rules as plugins, and the trace of requirements are the
|
|
5
|
+
* library `mizan` (`@intellectual-frontiers/mizan`), and the ontologies are the library `ontology` (`@intellectual-frontiers/ontology`).
|
|
6
|
+
*
|
|
7
|
+
* Spec: 0001-libraries FR-010
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export { decodeLibrarySource, type Library, LIBRARY_FILE, manifestFindings, readLibraries, verifyAll } from "./libraries.js";
|
|
12
|
+
export { termRecordsOf } from "./check.js";
|
|
13
|
+
export { staleFindings, type Fetched, type LatestManifest } from "./newer.js";
|
|
14
|
+
export { checkVersions, run as runVersions, type VersionsCheck } from "./versions.js";
|
|
15
|
+
export { digestOf, findingsOf, RUN, TURTLE_PATH, turtleOf } from "./generate-ontology.js";
|
|
16
|
+
export { COMPONENT_FILE, registerDocuments, registerRows, RESULTS_FILE, type RegisterInput, type RegisterRow } from "./oscal-register.js";
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What of Mizan is still in this package (commons 0032-lifting-libraries): the commands that need the whole repository. `check.ts` holds a repository's spec kit and ontologies, `versions.ts` and
|
|
3
|
+
* `changes.ts` are the commands of the release check and the change-control check, `libraries.ts` reads the manifests of the libraries, `newer.ts` reports a standard newer than its pin, `generate-ontology.ts` writes the Turtle of the ontologies and
|
|
4
|
+
* `oscal-register.ts` the register of proofs as OSCAL. The harness, the rules, the levels, the integrations, the change-control and release rules as plugins, and the trace of requirements are the
|
|
5
|
+
* library `mizan` (`@intellectual-frontiers/mizan`), and the ontologies are the library `ontology` (`@intellectual-frontiers/ontology`).
|
|
6
|
+
*
|
|
7
|
+
* Spec: 0001-libraries FR-010
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export { decodeLibrarySource, LIBRARY_FILE, manifestFindings, readLibraries, verifyAll } from "./libraries.js";
|
|
12
|
+
export { termRecordsOf } from "./check.js";
|
|
13
|
+
export { staleFindings } from "./newer.js";
|
|
14
|
+
export { checkVersions, run as runVersions } from "./versions.js";
|
|
15
|
+
export { digestOf, findingsOf, RUN, TURTLE_PATH, turtleOf } from "./generate-ontology.js";
|
|
16
|
+
export { COMPONENT_FILE, registerDocuments, registerRows, RESULTS_FILE } from "./oscal-register.js";
|
package/dist/newer.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Result } from "@intellectual-frontiers/core";
|
|
2
|
+
import type { MizanFinding } from "@intellectual-frontiers/mizan/rules";
|
|
3
|
+
/** A manifest that names a `latest` source: its file, the standard it pins (id, version, SHA-256) and the URL that always serves the newest. */
|
|
4
|
+
export type LatestManifest = {
|
|
5
|
+
readonly file: string;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly pin: string;
|
|
9
|
+
readonly latest: string;
|
|
10
|
+
};
|
|
11
|
+
/** A manifest with the SHA-256 of what its `latest` source serves. */
|
|
12
|
+
export type Fetched = LatestManifest & {
|
|
13
|
+
readonly sha256: string;
|
|
14
|
+
};
|
|
15
|
+
/** The comment lines a baseline of this command begins with. */
|
|
16
|
+
export declare const NEWER_BASELINE_COMMENTS: readonly ["The standards whose latest source served other bytes than the pin when each was first held (commons 0018-standards-first FR-017).", "A new finding fails the check, and so does a line below that no longer occurs: when you repin an import, delete its line.", "Never add a line to make a check pass."];
|
|
17
|
+
/** The findings: one sentence for each manifest whose `latest` source serves other bytes than the pin (0018-standards-first FR-014). */
|
|
18
|
+
export declare function staleFindings(fetched: readonly Fetched[]): readonly MizanFinding[];
|
|
19
|
+
/** The manifests of a folder (`NAME.import.ts`, in the order of their names) that name a `latest` source, and a sentence for each that cannot be read. */
|
|
20
|
+
export declare function readLatestManifests(dir: string): Promise<{
|
|
21
|
+
readonly manifests: readonly LatestManifest[];
|
|
22
|
+
readonly problems: readonly string[];
|
|
23
|
+
}>;
|
|
24
|
+
/** The SHA-256 of what a URL serves, with its line ends normalised as an import's are (0019-mizan-integrations FR-014), or the sentence that says why it could not be fetched. */
|
|
25
|
+
export declare function latestHash(url: string): Promise<Result<string, string>>;
|
|
26
|
+
/** The command line. Returns the exit status: 0, 1 where a finding is new or a baseline line is stale, 2 where a source or a manifest cannot be read. */
|
|
27
|
+
export declare function main(argv: readonly string[]): Promise<number>;
|
package/dist/newer.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Report the standards whose newest version is not the one pinned (commons 0018-standards-first FR-006, FR-014, FR-017).
|
|
11
|
+
*
|
|
12
|
+
* bun commons/libraries/src/newer.ts read commons/libraries/src/imports/*.import.ts, fetch each `latest` source and hold the findings against commons/spec-kit/mizan.newer.baseline.txt
|
|
13
|
+
* bun commons/libraries/src/newer.ts --imports DIR read the manifests of DIR
|
|
14
|
+
* bun commons/libraries/src/newer.ts --root DIR hold the findings against DIR/mizan.newer.baseline.txt (DIR holds `mizan.baseline.txt` too, as for `check.ts`)
|
|
15
|
+
* bun commons/libraries/src/newer.ts --write-baseline write the baseline from today's findings (to start it, or to shrink it: never to add a line to pass)
|
|
16
|
+
*
|
|
17
|
+
* A manifest of an import (0019-mizan-integrations FR-014) may name, beside its versioned `source`, a `latest` source: an URL that always serves the newest version of the
|
|
18
|
+
* standard (schema.org's `.../version/latest/...`, a repository's latest tag). This command fetches each one and gives one finding, `mizan/standard-newer`, where the SHA-256 of
|
|
19
|
+
* what it serves differs from the pin. It is opt-in and the only part of Mizan that needs the network: `check.ts` and `import.ts --check` never do, so the network never fails the offline
|
|
20
|
+
* check. Its exit status is 0 (nothing new), 1 (a finding the baseline does not hold, or a baseline line that no longer occurs) or 2 (a `latest` source that cannot be fetched, or a
|
|
21
|
+
* manifest that cannot be read, named with its reason).
|
|
22
|
+
*
|
|
23
|
+
* @limits
|
|
24
|
+
* It compares bytes, not versions: a source that changes its prefixes or its date changes the hash, and a person reads the difference. It reads the manifests of one folder.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { staleFindings } from "./newer.ts";
|
|
29
|
+
* staleFindings([{ file: "imports/x.import.ts", id: "x", version: "1", pin: "a".repeat(64), latest: "https://example.org/latest", sha256: "b".repeat(64) }]).length; // 1
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Spec: 0001-libraries FR-008
|
|
33
|
+
*
|
|
34
|
+
* @module
|
|
35
|
+
*/
|
|
36
|
+
import process from "node:process";
|
|
37
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
38
|
+
import { err, ok } from "@intellectual-frontiers/core";
|
|
39
|
+
import { sha256 } from "@intellectual-frontiers/crypto/sha256";
|
|
40
|
+
import { formatBaseline, judge, parseBaseline, passes, report } from "@intellectual-frontiers/mizan/trace";
|
|
41
|
+
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
42
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
43
|
+
import { resolve } from "@intellectual-frontiers/system/path";
|
|
44
|
+
import { decodeManifest, isUrl } from "@intellectual-frontiers/mizan/integrations/host/import";
|
|
45
|
+
const isRecord = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
46
|
+
/** The comment lines a baseline of this command begins with. */
|
|
47
|
+
export const NEWER_BASELINE_COMMENTS = [
|
|
48
|
+
"The standards whose latest source served other bytes than the pin when each was first held (commons 0018-standards-first FR-017).",
|
|
49
|
+
"A new finding fails the check, and so does a line below that no longer occurs: when you repin an import, delete its line.",
|
|
50
|
+
"Never add a line to make a check pass.",
|
|
51
|
+
];
|
|
52
|
+
/** The findings: one sentence for each manifest whose `latest` source serves other bytes than the pin (0018-standards-first FR-014). */
|
|
53
|
+
export function staleFindings(fetched) {
|
|
54
|
+
return fetched.flatMap((f) => f.sha256 === f.pin
|
|
55
|
+
? []
|
|
56
|
+
: [
|
|
57
|
+
{
|
|
58
|
+
file: f.file,
|
|
59
|
+
line: 1,
|
|
60
|
+
rule: "mizan/standard-newer",
|
|
61
|
+
message: `${f.id} is pinned at version ${f.version} (SHA-256 ${f.pin}), and ${f.latest} now serves SHA-256 ${f.sha256}, so a newer version of the standard may be out`,
|
|
62
|
+
key: `mizan/standard-newer ${f.file} ${f.id} ${f.sha256}`,
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
/** The manifests of a folder (`NAME.import.ts`, in the order of their names) that name a `latest` source, and a sentence for each that cannot be read. */
|
|
67
|
+
export async function readLatestManifests(dir) {
|
|
68
|
+
const manifests = [];
|
|
69
|
+
const problems = [];
|
|
70
|
+
const base = resolve(dir);
|
|
71
|
+
const folder = base.split(/[\\/]/).pop() ?? "imports";
|
|
72
|
+
if (!existsSync(base))
|
|
73
|
+
return { manifests, problems: [`${dir}: no such folder`] };
|
|
74
|
+
const names = readDirSync(base)
|
|
75
|
+
.filter((e) => e.isFile && e.name.endsWith(".import.ts"))
|
|
76
|
+
.map((e) => e.name)
|
|
77
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
78
|
+
for (const name of names) {
|
|
79
|
+
const file = `${folder}/${name}`;
|
|
80
|
+
const loaded = await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(base, name)).href));
|
|
81
|
+
const raw = isRecord(loaded) ? loaded["manifest"] : undefined;
|
|
82
|
+
const m = decodeManifest(raw);
|
|
83
|
+
if (m.kind === "err") {
|
|
84
|
+
problems.push(`${file}: ${m.error}`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const latest = isRecord(raw) ? raw["latest"] : undefined;
|
|
88
|
+
if (latest === undefined)
|
|
89
|
+
continue;
|
|
90
|
+
if (typeof latest !== "string" || !isUrl(latest)) {
|
|
91
|
+
problems.push(`${file}: latest must be an https:// URL`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
manifests.push({ file, id: m.value.standard.id, version: m.value.standard.version, pin: m.value.standard.sha256, latest });
|
|
95
|
+
}
|
|
96
|
+
return { manifests, problems };
|
|
97
|
+
}
|
|
98
|
+
/** The SHA-256 of what a URL serves, with its line ends normalised as an import's are (0019-mizan-integrations FR-014), or the sentence that says why it could not be fetched. */
|
|
99
|
+
export async function latestHash(url) {
|
|
100
|
+
try {
|
|
101
|
+
const r = await fetch(url, { signal: AbortSignal.timeout(60_000) });
|
|
102
|
+
if (!r.ok)
|
|
103
|
+
return err(`${url}: HTTP ${r.status}`);
|
|
104
|
+
return ok(await sha256((await r.text()).replaceAll("\r\n", "\n")));
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
return err(`${url}: ${e instanceof Error ? e.message : String(e)}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** The command line. Returns the exit status: 0, 1 where a finding is new or a baseline line is stale, 2 where a source or a manifest cannot be read. */
|
|
111
|
+
export async function main(argv) {
|
|
112
|
+
const arg = (name) => {
|
|
113
|
+
const i = argv.indexOf(name);
|
|
114
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
115
|
+
};
|
|
116
|
+
const imports = arg("--imports") ?? fileURLToPath(new URL("./imports", import.meta.url));
|
|
117
|
+
const root = (arg("--root") ?? fileURLToPath(new URL("../../spec-kit", import.meta.url))).replace(/[\\/]$/, "");
|
|
118
|
+
const baselineFile = `${root}/mizan.newer.baseline.txt`;
|
|
119
|
+
const { manifests, problems: unread } = await readLatestManifests(imports);
|
|
120
|
+
const problems = [...unread];
|
|
121
|
+
const fetched = [];
|
|
122
|
+
for (const m of manifests) {
|
|
123
|
+
const h = await latestHash(m.latest);
|
|
124
|
+
if (h.kind === "err")
|
|
125
|
+
problems.push(`${m.file}: ${h.error}`);
|
|
126
|
+
else
|
|
127
|
+
fetched.push({ ...m, sha256: h.value });
|
|
128
|
+
}
|
|
129
|
+
const found = staleFindings(fetched);
|
|
130
|
+
if (argv.includes("--write-baseline")) {
|
|
131
|
+
if (problems.length === 0) {
|
|
132
|
+
writeTextFileSync(baselineFile, formatBaseline(found, NEWER_BASELINE_COMMENTS));
|
|
133
|
+
stdio.stdout.writeSync(`wrote ${baselineFile}: ${new Set(found.map((f) => f.key)).size} findings\n`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const p of problems)
|
|
138
|
+
stdio.stderr.writeSync(`${p}\n`);
|
|
139
|
+
if (problems.length > 0)
|
|
140
|
+
return 2;
|
|
141
|
+
const held = existsSync(baselineFile) ? parseBaseline(readTextFileSync(baselineFile)) : [];
|
|
142
|
+
const verdict = judge(found, held);
|
|
143
|
+
stdio.stderr.writeSync(`${report(verdict, "mizan-newer", baselineFile).join("\n")}\n`);
|
|
144
|
+
return passes(verdict) ? 0 : 1;
|
|
145
|
+
}
|
|
146
|
+
if (import.meta.main)
|
|
147
|
+
process.exitCode = await main(process.argv.slice(2));
|