@jskit-ai/jskit-catalog 0.2.147 → 0.2.148
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/catalog/packages.json +274 -273
- package/package.json +1 -1
- package/scripts/capacitor.mjs +663 -0
- package/scripts/data-access-files.mjs +4 -3
- package/scripts/jskit.mjs +33 -54
- package/scripts/project-check.mjs +69 -0
- package/scripts/project-manifests.mjs +80 -1
- package/scripts/project-packages.mjs +134 -28
- package/scripts/verify.mjs +73 -9
package/scripts/verify.mjs
CHANGED
|
@@ -6,15 +6,18 @@ import {
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { PROJECT_CHECK, runProjectCheck } from "./project-check.mjs";
|
|
9
10
|
|
|
10
|
-
// `jskit verify`: an app's whole check (its Verification)
|
|
11
|
-
//
|
|
11
|
+
// `jskit verify`: an app's whole check (its Verification): first the app's JSKIT check (plain `jskit check`'s rules, run
|
|
12
|
+
// here, so no app can leave its JSKIT drift out), then the npm scripts package.json's jskitVerify.parts names, run in
|
|
13
|
+
// order and stopped at the first that fails (a part whose script is `jskit check` is that check, run once), kept once
|
|
14
|
+
// per exact tree: a check that passed on the exact tree is never
|
|
12
15
|
// run again. A whole run that passes records exactly what it checked in node_modules/.cache/jskit/verify-passes/, and a
|
|
13
16
|
// whole run on the same inputs prints that record and runs nothing. The inputs are the project's tree (the tree of
|
|
14
17
|
// HEAD, with no working change), the trees of the other checkouts the run uses (jskitVerify.checkouts, a module of the
|
|
15
18
|
// app's that names them), every checkout's installed dependencies, the declared settings (jskitVerify.settings: a value
|
|
16
19
|
// naming a checkout, or a folder in one, is that checkout's tree, one naming a file is its contents, any other its
|
|
17
|
-
// digest, never the value itself), Node's version and the parts. A checkout with working changes, a setting naming a
|
|
20
|
+
// digest, never the value itself), Node's version, the JSKIT check (its catalog's version) and the parts. A checkout with working changes, a setting naming a
|
|
18
21
|
// folder outside Git or one Git ignores, inputs that can't be read, a failed or interrupted run, a tree that changed
|
|
19
22
|
// while it ran, and a run of named files (`jskit verify <args>`, which go to the last part) run and record nothing.
|
|
20
23
|
//
|
|
@@ -23,7 +26,7 @@ import { pathToFileURL } from "node:url";
|
|
|
23
26
|
// command names it, asks GitHub whether one is kept, and writes `name` and `reuse` to the step's outputs.
|
|
24
27
|
|
|
25
28
|
const GUIDE = "https://mobily-enterprises.github.io/jskit-ai/guide/framework/typed-features#a-check-runs-once-per-tree";
|
|
26
|
-
const SCHEMA = "jskit.verify-pass.
|
|
29
|
+
const SCHEMA = "jskit.verify-pass.v2";
|
|
27
30
|
const CI_SCHEMA = "jskit.verify-ci-pass.v1";
|
|
28
31
|
/** Where a project keeps its passes, relative to its root. */
|
|
29
32
|
export const PASS_FOLDER = path.join("node_modules", ".cache", "jskit", "verify-passes");
|
|
@@ -35,6 +38,22 @@ const COMMIT_ID = /^[0-9a-f]{40}$/u;
|
|
|
35
38
|
const CHECKOUT_NAME = /^[A-Za-z0-9][\w.-]*$/u;
|
|
36
39
|
const RUNS_ITSELF = /\bjskit\s+verify\b/u;
|
|
37
40
|
|
|
41
|
+
/**
|
|
42
|
+
* The --manifest files of a script that is plain `jskit check` (its words `jskit check`, then only `--manifest <file>`
|
|
43
|
+
* pairs, as the CLI takes them), or null for any other script: one that runs something else, or the check elsewhere.
|
|
44
|
+
* @param {string} script
|
|
45
|
+
*/
|
|
46
|
+
export function projectCheckManifests(script) {
|
|
47
|
+
const [command, subcommand, ...rest] = String(script).trim().split(/\s+/u);
|
|
48
|
+
if (command !== "jskit" || subcommand !== "check" || rest.length % 2 !== 0) return null;
|
|
49
|
+
const manifests = [];
|
|
50
|
+
for (let index = 0; index < rest.length; index += 2) {
|
|
51
|
+
if (rest[index] !== "--manifest" || rest[index + 1].startsWith("-")) return null;
|
|
52
|
+
manifests.push(rest[index + 1]);
|
|
53
|
+
}
|
|
54
|
+
return manifests;
|
|
55
|
+
}
|
|
56
|
+
|
|
38
57
|
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
39
58
|
const short = (id) => String(id || "").slice(0, 12);
|
|
40
59
|
|
|
@@ -48,7 +67,9 @@ function git(root, args) {
|
|
|
48
67
|
|
|
49
68
|
/**
|
|
50
69
|
* package.json's jskitVerify: the parts (npm scripts, each with the settings only it gets), the settings that are
|
|
51
|
-
* inputs, and the module naming the other checkouts
|
|
70
|
+
* inputs, and the module naming the other checkouts; the parts that are the JSKIT check itself (`checkParts`), and the
|
|
71
|
+
* --manifest files the app's own check reads (`checkManifests`: its jskit:check script's and those parts'). It throws,
|
|
72
|
+
* naming the fix, on a declaration it can't run.
|
|
52
73
|
* @param {string} projectRoot
|
|
53
74
|
*/
|
|
54
75
|
export function readVerifyConfig(projectRoot) {
|
|
@@ -83,7 +104,25 @@ export function readVerifyConfig(projectRoot) {
|
|
|
83
104
|
throw new Error(`jskitVerify.checkouts is ${JSON.stringify(checkouts)}: name the module, relative to package.json, ` +
|
|
84
105
|
`whose default export names the other checkouts the run uses (${GUIDE}).`);
|
|
85
106
|
}
|
|
86
|
-
|
|
107
|
+
const checkParts = parts.filter(({ script }) => projectCheckManifests(scripts[script]) !== null).map(({ script }) => script);
|
|
108
|
+
// jskit verify runs the check itself, never through npm: a check part's env or npm hooks would silently not run.
|
|
109
|
+
for (const { script, env } of parts.filter((part) => checkParts.includes(part.script))) {
|
|
110
|
+
const unrun = [
|
|
111
|
+
...(Object.keys(env).length > 0 ? [`env (${Object.keys(env).join(", ")})`] : []),
|
|
112
|
+
...[`pre${script}`, `post${script}`].filter((hook) => typeof scripts[hook] === "string").map((hook) => `${hook} script`)
|
|
113
|
+
];
|
|
114
|
+
if (unrun.length > 0) {
|
|
115
|
+
throw new Error(`jskitVerify.parts names ${script}, which is ${PROJECT_CHECK.command}: jskit verify runs that check first ` +
|
|
116
|
+
`itself, without a part's env or npm's pre${script} and post${script} scripts, so its ${unrun.join(" and ")} would never ` +
|
|
117
|
+
`run. Remove the part from jskitVerify.parts, and give what it needs a part of its own (${GUIDE}).`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const checkManifests = [...new Set([scripts["jskit:check"], ...checkParts.map((script) => scripts[script])]
|
|
121
|
+
.flatMap((script) => (typeof script === "string" && projectCheckManifests(script)) || []))];
|
|
122
|
+
return Object.freeze({
|
|
123
|
+
parts: Object.freeze(parts), checkParts: Object.freeze(checkParts), checkManifests: Object.freeze(checkManifests),
|
|
124
|
+
settings: Object.freeze([...settings]), checkouts
|
|
125
|
+
});
|
|
87
126
|
}
|
|
88
127
|
|
|
89
128
|
/** Whether Git ignores a path of a checkout (`git check-ignore` exits 0 for an ignored path, 1 for one it keeps). */
|
|
@@ -206,7 +245,8 @@ export async function verifyInputs({ projectRoot, config, env, nodeVersion }) {
|
|
|
206
245
|
if ("problem" in input) return input;
|
|
207
246
|
settings[name] = input;
|
|
208
247
|
}
|
|
209
|
-
const
|
|
248
|
+
const check = { ...PROJECT_CHECK, manifests: config.checkManifests };
|
|
249
|
+
const inputs = { schema: SCHEMA, command: "jskit verify", check, parts: config.parts, node: nodeVersion,
|
|
210
250
|
project: { ...project, dependencies: installedDependencies(projectRoot) }, checkouts, settings };
|
|
211
251
|
// The key is the trees', not the commits': a rebase or an empty commit keeps the tree, and so the pass.
|
|
212
252
|
const tree = ({ tree: id, path: inside, dependencies }) => ({ tree: id, path: inside, dependencies });
|
|
@@ -265,16 +305,24 @@ function passedAlready(pass, file, projectRoot) {
|
|
|
265
305
|
* @param {Record<string, string | undefined>} [tools.env]
|
|
266
306
|
* @param {string} [tools.nodeVersion]
|
|
267
307
|
* @param {string} [tools.host] the machine, as the record names it
|
|
308
|
+
* @param {(app: { projectRoot: string, additionalManifests: string[] }) => Promise<{ ok: boolean, report: string }>}
|
|
309
|
+
* [tools.runCheck] the JSKIT check
|
|
268
310
|
* @param {(part: { script: string, args: string[], cwd: string, env: object }) => number} [tools.runPart]
|
|
269
311
|
* @param {(line: string) => void} [tools.print]
|
|
270
312
|
* @param {() => number} [tools.now]
|
|
271
313
|
*/
|
|
272
314
|
export async function runVerify({
|
|
273
315
|
projectRoot = process.cwd(), argv = [], env = process.env, nodeVersion = process.version, host = os.hostname(),
|
|
274
|
-
runPart = npmPart, print = (line) => process.stdout.write(`${line}\n`), now = Date.now
|
|
316
|
+
runCheck = runProjectCheck, runPart = npmPart, print = (line) => process.stdout.write(`${line}\n`), now = Date.now
|
|
275
317
|
} = {}) {
|
|
276
318
|
const config = readVerifyConfig(projectRoot);
|
|
277
319
|
const log = (line) => print(`jskit verify: ${line}`);
|
|
320
|
+
const last = config.parts.findLastIndex(({ script }) => !config.checkParts.includes(script));
|
|
321
|
+
if (argv.length > 0 && last < 0) {
|
|
322
|
+
throw new Error(`jskit verify ${argv.join(" ")}: the words go to the last part that runs, but every part in ` +
|
|
323
|
+
`jskitVerify.parts is ${PROJECT_CHECK.command}, which takes no files and which jskit verify runs first: run ` +
|
|
324
|
+
"npm run verify without them.");
|
|
325
|
+
}
|
|
278
326
|
// The record only spares a second run: inputs it can't read never stop the check, which then runs whole.
|
|
279
327
|
const read = async () => {
|
|
280
328
|
try {
|
|
@@ -300,8 +348,24 @@ export async function runVerify({
|
|
|
300
348
|
}
|
|
301
349
|
}
|
|
302
350
|
const startedAt = new Date(now()).toISOString();
|
|
351
|
+
// The JSKIT check first, whatever the parts: a check that fails, or can't run, fails the run before any part.
|
|
352
|
+
let check;
|
|
353
|
+
try {
|
|
354
|
+
check = await runCheck({ projectRoot, additionalManifests: [...config.checkManifests] });
|
|
355
|
+
} catch (error) {
|
|
356
|
+
check = { ok: false, report: error instanceof Error ? error.message : String(error) };
|
|
357
|
+
}
|
|
358
|
+
print(check.report);
|
|
359
|
+
if (!check.ok) {
|
|
360
|
+
log(`the JSKIT check (${PROJECT_CHECK.command}) failed: no part ran, nothing recorded.`);
|
|
361
|
+
return 1;
|
|
362
|
+
}
|
|
303
363
|
for (const [index, part] of config.parts.entries()) {
|
|
304
|
-
|
|
364
|
+
if (config.checkParts.includes(part.script)) {
|
|
365
|
+
log(`npm run ${part.script} is ${PROJECT_CHECK.command}, which ran first: not run again.`);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const args = index === last ? argv : [];
|
|
305
369
|
const status = runPart({ script: part.script, args, cwd: projectRoot, env: { ...env, ...part.env } });
|
|
306
370
|
if (status !== 0) {
|
|
307
371
|
log(`npm run ${part.script} failed (exit ${status}): nothing recorded.`);
|