@jskit-ai/jskit-catalog 0.2.148 → 0.2.150
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 +809 -274
- package/package.json +1 -1
- package/scripts/capacitor.mjs +28 -0
- package/scripts/jskit.mjs +24 -2
- package/scripts/mobile-build.mjs +116 -0
- package/scripts/store-purchases.mjs +70 -0
- package/scripts/testing/command.mjs +11 -1
- package/scripts/verify.mjs +80 -1
package/package.json
CHANGED
package/scripts/capacitor.mjs
CHANGED
|
@@ -26,6 +26,23 @@ const CAPACITOR_PACKAGES = Object.freeze([
|
|
|
26
26
|
"@capacitor/status-bar", "@capacitor/text-zoom", "@capacitor/toast"
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
|
+
// The device plugins JSKIT's native interfaces are built and tested with, each at its major line for Capacitor 9: an
|
|
30
|
+
// app that installs one on another line gets a recommendation to move it. Three have no Capacitor 9 release yet and stay
|
|
31
|
+
// on their 8.x line, whose peer range admits Capacitor 9.
|
|
32
|
+
const SUPPORTED_PLUGINS = Object.freeze({
|
|
33
|
+
"@capawesome/capacitor-app-shortcuts": 8,
|
|
34
|
+
"@capawesome/capacitor-app-update": 8,
|
|
35
|
+
"@capawesome/capacitor-live-update": 8,
|
|
36
|
+
"@capgo/capacitor-document-scanner": 9,
|
|
37
|
+
"@capgo/capacitor-file-picker": 9,
|
|
38
|
+
"@capgo/capacitor-live-activities": 2,
|
|
39
|
+
"@capgo/capacitor-native-biometric": 9,
|
|
40
|
+
"@capgo/capacitor-share-target": 9,
|
|
41
|
+
"@capgo/capacitor-social-login": 9,
|
|
42
|
+
"@capgo/native-purchases": 9,
|
|
43
|
+
"capacitor-widget-bridge": 9
|
|
44
|
+
});
|
|
45
|
+
|
|
29
46
|
// What the Capacitor major JSKIT's packages need asks of an app, from its upgrade guide and its CLI's templates. Each
|
|
30
47
|
// version is the least the app may have.
|
|
31
48
|
const REQUIREMENTS = Object.freeze({
|
|
@@ -284,6 +301,17 @@ function packageFindings({ manifests, root, lockPackages, requirement, native })
|
|
|
284
301
|
`every Capacitor package of an app moves with its major.`
|
|
285
302
|
});
|
|
286
303
|
}
|
|
304
|
+
for (const [name, supportedMajor] of Object.entries(SUPPORTED_PLUGINS)) {
|
|
305
|
+
const spec = manifest.value?.[field]?.[name];
|
|
306
|
+
if (spec === undefined || specMajor(spec) === supportedMajor) continue;
|
|
307
|
+
findings.push({
|
|
308
|
+
file: source,
|
|
309
|
+
rule: "capacitor/plugins",
|
|
310
|
+
required: false,
|
|
311
|
+
message: `${field}.${name} is ${spec}; JSKIT's native interfaces support its ${supportedMajor}.x line. ` +
|
|
312
|
+
`Run npm install ${name}@^${supportedMajor}.`
|
|
313
|
+
});
|
|
314
|
+
}
|
|
287
315
|
}
|
|
288
316
|
}
|
|
289
317
|
const copies = Object.entries(lockPackages)
|
package/scripts/jskit.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
formatExportSummary
|
|
13
13
|
} from "./i18n.mjs";
|
|
14
14
|
import { formatAgentsBlockWrite, writeAgentsBlock } from "./agents-block.mjs";
|
|
15
|
+
import { runBuild } from "./mobile-build.mjs";
|
|
16
|
+
import { runStorePurchases } from "./store-purchases.mjs";
|
|
15
17
|
import { serveBrowserTestTarget } from "./browser-test-server.mjs";
|
|
16
18
|
import { checkMaterial3, formatMaterial3Report } from "./material3.mjs";
|
|
17
19
|
import { packageNix } from "./package-nix.mjs";
|
|
@@ -35,10 +37,13 @@ function usage() {
|
|
|
35
37
|
" jskit i18n export <locale> [--root <path>]",
|
|
36
38
|
" jskit i18n check <locale> [--root <path>]",
|
|
37
39
|
" jskit package nix [--root <path>]",
|
|
40
|
+
" jskit build --mobile [--root <path>]",
|
|
41
|
+
" jskit store-purchases reconcile --source app_store|google_play --report <file> --server <url> --as <user> --from <date> --before <date>",
|
|
38
42
|
" jskit test [node options] [files or globs]",
|
|
39
43
|
" jskit test --list [node options] [files or globs]",
|
|
40
44
|
" jskit migration-history",
|
|
41
45
|
" jskit verify [args for the last part]",
|
|
46
|
+
" jskit verify --list [files]",
|
|
42
47
|
" jskit verify-pass [--commit <name>=<sha> ...]",
|
|
43
48
|
" jskit browser-test-server [host] [port] [workers]",
|
|
44
49
|
"",
|
|
@@ -108,6 +113,10 @@ function usage() {
|
|
|
108
113
|
" <name>-migrate. The file is the same for every app, so a changed lock file needs no new one. It",
|
|
109
114
|
" writes nothing when the lock names a dependency it cannot fetch that way (git, a local file, no",
|
|
110
115
|
" integrity hash), the app has no start script, or a package.nix it did not write is there.",
|
|
116
|
+
" build --mobile: the app's screens for its Capacitor app, with Vite's relative base and mobile mode,",
|
|
117
|
+
" into capacitor.config.json's webDir, calling config.mobile.apiBaseUrl; no service worker.",
|
|
118
|
+
" store-purchases reconcile: sends a store's downloaded financial report to the app's server (a service key in",
|
|
119
|
+
" JSKIT_SERVICE_KEY, acting as --as), which matches it with its purchase ledger; prints the differences.",
|
|
111
120
|
" test Run node --test with these arguments, test files in parallel within the machine's test budget:",
|
|
112
121
|
" V64_TEST_CONCURRENCY when it is a positive whole number, otherwise half of the machine's CPUs",
|
|
113
122
|
" (at least 1). A file whose first line is `// jskit-test: alone - <reason>` runs after the others,",
|
|
@@ -140,7 +149,12 @@ function usage() {
|
|
|
140
149
|
" declares, Node's version, the JSKIT check's catalog and the parts), and a whole run on the same",
|
|
141
150
|
" inputs prints that record and runs nothing. Working changes, inputs it can't read, a failed or",
|
|
142
151
|
" interrupted run, a tree that changed while it ran and a run given args (they go to the last part",
|
|
143
|
-
" that runs) run and record nothing.",
|
|
152
|
+
" that runs) run and record nothing. --list [files] runs nothing, not even the JSKIT check: it",
|
|
153
|
+
" prints the files a run of those files would take, one per line, then Total: <n> file(s), as jskit",
|
|
154
|
+
" test --list does (npm run verify --list hands it over as npm_config_list), asking the part the",
|
|
155
|
+
" files go to, the last that runs: a jskit test part, or a playwright test part (Playwright's own",
|
|
156
|
+
" --list); the parts before it (lint, checks) are not listed. It exits 2, saying why, for an option,",
|
|
157
|
+
" a file that part doesn't take, or that part being one that can't list.",
|
|
144
158
|
" verify-pass A CI run's first step: name the pass for the project's exact tree and the given commits of the",
|
|
145
159
|
" other repositories it checks out, ask GitHub (GITHUB_TOKEN, GITHUB_REPOSITORY) whether an artifact",
|
|
146
160
|
" of that name is kept, and write name and reuse to GITHUB_OUTPUT; the run records the artifact only",
|
|
@@ -165,7 +179,7 @@ function parseArgs(argv = []) {
|
|
|
165
179
|
? "help"
|
|
166
180
|
: commandArgument;
|
|
167
181
|
if (command === "test" || command === "browser-test-server" || command === "migration-history" || command === "verify" ||
|
|
168
|
-
command === "verify-pass") {
|
|
182
|
+
command === "verify-pass" || command === "build" || command === "store-purchases") {
|
|
169
183
|
return { command, args };
|
|
170
184
|
}
|
|
171
185
|
const options = {
|
|
@@ -363,6 +377,14 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
363
377
|
await runPackageNix(options);
|
|
364
378
|
return;
|
|
365
379
|
}
|
|
380
|
+
if (options.command === "build") {
|
|
381
|
+
process.exitCode = await runBuild(options.args);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (options.command === "store-purchases") {
|
|
385
|
+
process.exitCode = await runStorePurchases(options.args);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
366
388
|
if (options.command === "test") {
|
|
367
389
|
process.exitCode = await runTests(options.args);
|
|
368
390
|
return;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { fileExists } from "./files.mjs";
|
|
6
|
+
|
|
7
|
+
// `jskit build --mobile`: the app's screens built to be bundled in its Capacitor app. Vite builds with a relative base
|
|
8
|
+
// (the screens load from capacitor://localhost or https://localhost, not the server), in the `mobile` mode
|
|
9
|
+
// (import.meta.env.MODE, so app code can leave out what only the web wants, such as install prompts), into the
|
|
10
|
+
// webDir capacitor.config.json names. The server's address is config.mobile.apiBaseUrl, which the client config
|
|
11
|
+
// already carries. JSKIT registers no service worker in an app; the build fails when one lands in the output anyway,
|
|
12
|
+
// since a service worker in a bundled app would serve stale screens.
|
|
13
|
+
|
|
14
|
+
const SERVICE_WORKER_NAMES = Object.freeze(["sw.js", "service-worker.js", "serviceWorker.js"]);
|
|
15
|
+
|
|
16
|
+
function usage() {
|
|
17
|
+
return "Usage: jskit build --mobile [--root <path>] (the web build stays npm run build)";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseBuildArgs(argv) {
|
|
21
|
+
const options = { mobile: false, appRoot: process.cwd() };
|
|
22
|
+
const args = [...argv];
|
|
23
|
+
while (args.length > 0) {
|
|
24
|
+
const argument = String(args.shift());
|
|
25
|
+
if (argument === "--mobile") {
|
|
26
|
+
options.mobile = true;
|
|
27
|
+
} else if (argument === "--root") {
|
|
28
|
+
const value = String(args.shift() || "").trim();
|
|
29
|
+
if (!value) throw new Error("--root requires a path.");
|
|
30
|
+
options.appRoot = path.resolve(value);
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error(`Unknown argument: ${argument}\n${usage()}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!options.mobile) {
|
|
36
|
+
throw new Error(usage());
|
|
37
|
+
}
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The webDir capacitor.config.json names, relative to the app root.
|
|
43
|
+
* @param {string} appRoot
|
|
44
|
+
*/
|
|
45
|
+
async function readWebDir(appRoot) {
|
|
46
|
+
const configPath = path.join(appRoot, "capacitor.config.json");
|
|
47
|
+
if (!(await fileExists(configPath))) {
|
|
48
|
+
throw new Error("jskit build --mobile reads capacitor.config.json, and this app has none (a .ts config is not read).");
|
|
49
|
+
}
|
|
50
|
+
const webDir = String(JSON.parse(await readFile(configPath, "utf8")).webDir || "").trim();
|
|
51
|
+
if (!webDir || path.isAbsolute(webDir) || webDir.split(/[\\/]/u).includes("..")) {
|
|
52
|
+
throw new Error("capacitor.config.json's webDir must name a folder inside the app, such as \"dist\".");
|
|
53
|
+
}
|
|
54
|
+
return webDir;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The app's config.mobile.apiBaseUrl, which must be an absolute https (or, for a local server, http) address.
|
|
59
|
+
* @param {string} appRoot
|
|
60
|
+
*/
|
|
61
|
+
async function readApiBaseUrl(appRoot) {
|
|
62
|
+
const { config } = await import(pathToFileURL(path.join(appRoot, "config/public.js")).href);
|
|
63
|
+
const apiBaseUrl = String(config?.mobile?.apiBaseUrl || "").trim();
|
|
64
|
+
let parsed = null;
|
|
65
|
+
try {
|
|
66
|
+
parsed = new URL(apiBaseUrl);
|
|
67
|
+
} catch {}
|
|
68
|
+
if (!parsed || (parsed.protocol !== "https:" && parsed.protocol !== "http:")) {
|
|
69
|
+
throw new Error("config.mobile.apiBaseUrl in config/public.js must be the server's absolute address for a mobile build.");
|
|
70
|
+
}
|
|
71
|
+
return apiBaseUrl;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runVite(appRoot, args) {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const child = spawn("npx", ["vite", "build", ...args], { cwd: appRoot, stdio: "inherit" });
|
|
77
|
+
child.on("error", reject);
|
|
78
|
+
child.on("exit", (code) => (code === 0 ? resolve() : reject(new Error(`vite build exited with ${code}.`))));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function serviceWorkersIn(directory) {
|
|
83
|
+
const found = [];
|
|
84
|
+
for (const entry of await readdir(directory, { withFileTypes: true, recursive: true })) {
|
|
85
|
+
if (entry.isFile() && SERVICE_WORKER_NAMES.includes(entry.name)) {
|
|
86
|
+
found.push(path.join(entry.parentPath, entry.name));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return found;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Builds the app's screens for its Capacitor app.
|
|
94
|
+
* @param {{ appRoot: string, build?: (appRoot: string, args: string[]) => Promise<void> }} options
|
|
95
|
+
* @returns {Promise<{ webDir: string, apiBaseUrl: string }>}
|
|
96
|
+
*/
|
|
97
|
+
async function buildMobile({ appRoot, build = runVite }) {
|
|
98
|
+
const webDir = await readWebDir(appRoot);
|
|
99
|
+
const apiBaseUrl = await readApiBaseUrl(appRoot);
|
|
100
|
+
await build(appRoot, ["--mode", "mobile", "--base", "./", "--outDir", webDir, "--emptyOutDir"]);
|
|
101
|
+
const workers = await serviceWorkersIn(path.join(appRoot, webDir));
|
|
102
|
+
if (workers.length > 0) {
|
|
103
|
+
throw new Error(`The mobile build holds a service worker, which a bundled app must not: ${workers.map((file) => path.relative(appRoot, file)).join(", ")}.`);
|
|
104
|
+
}
|
|
105
|
+
return { webDir, apiBaseUrl };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @param {string[]} argv */
|
|
109
|
+
async function runBuild(argv) {
|
|
110
|
+
const { appRoot } = parseBuildArgs(argv);
|
|
111
|
+
const { webDir, apiBaseUrl } = await buildMobile({ appRoot });
|
|
112
|
+
process.stdout.write(`Mobile build in ${webDir}, calling ${apiBaseUrl}. Next: npx cap sync\n`);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { buildMobile, runBuild };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const USAGE = [
|
|
5
|
+
"jskit store-purchases reconcile --source app_store|google_play --report <file> --server <url> --as <user>",
|
|
6
|
+
" --from <YYYY-MM-DD> --before <YYYY-MM-DD> [--environment production|sandbox]",
|
|
7
|
+
"",
|
|
8
|
+
"Sends a financial report downloaded from App Store Connect (Financial Reports) or the Play Console (earnings report)",
|
|
9
|
+
"to the app's server, which matches it with its store purchase ledger. The service key is read from",
|
|
10
|
+
"JSKIT_SERVICE_KEY; --as names the user it acts as, whom the app's authorize must let reconcile. It prints how many",
|
|
11
|
+
"rows were reconciled and each difference, and exits 1 when there is any."
|
|
12
|
+
].join("\n");
|
|
13
|
+
|
|
14
|
+
function parseReconcileArgs(args) {
|
|
15
|
+
const options = { environment: "production" };
|
|
16
|
+
const names = new Set(["source", "report", "server", "as", "from", "before", "environment"]);
|
|
17
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
18
|
+
const name = String(args[index]).replace(/^--/u, "");
|
|
19
|
+
if (!names.has(name)) throw new Error(`Unknown argument: ${args[index]}\n\n${USAGE}`);
|
|
20
|
+
const value = args[index + 1];
|
|
21
|
+
if (!value || value.startsWith("--")) throw new Error(`--${name} needs a value.\n\n${USAGE}`);
|
|
22
|
+
options[name] = value;
|
|
23
|
+
index += 1;
|
|
24
|
+
}
|
|
25
|
+
for (const name of ["source", "report", "server", "as", "from", "before"]) {
|
|
26
|
+
if (!options[name]) throw new Error(`--${name} is required.\n\n${USAGE}`);
|
|
27
|
+
}
|
|
28
|
+
if (!["app_store", "google_play"].includes(options.source)) throw new Error(`--source is app_store or google_play.\n\n${USAGE}`);
|
|
29
|
+
return options;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* `jskit store-purchases reconcile`: one report sent to the app's server, its answer printed.
|
|
34
|
+
* @param {string[]} argv The arguments after `store-purchases`.
|
|
35
|
+
* @param {{ env?: Record<string, string | undefined>, fetchImpl?: typeof fetch, write?: (text: string) => void }} [io]
|
|
36
|
+
* @returns {Promise<number>} The exit code.
|
|
37
|
+
*/
|
|
38
|
+
async function runStorePurchases(argv, { env = process.env, fetchImpl = globalThis.fetch, write = (text) => process.stdout.write(text) } = {}) {
|
|
39
|
+
const [subcommand, ...args] = argv;
|
|
40
|
+
if (subcommand !== "reconcile") {
|
|
41
|
+
write(`${USAGE}\n`);
|
|
42
|
+
return subcommand === "help" || subcommand === "--help" ? 0 : 1;
|
|
43
|
+
}
|
|
44
|
+
const options = parseReconcileArgs(args);
|
|
45
|
+
const key = String(env.JSKIT_SERVICE_KEY || "").trim();
|
|
46
|
+
if (!key) throw new Error("Set JSKIT_SERVICE_KEY to a service key of the app (local auth's service keys).");
|
|
47
|
+
const report = await readFile(path.resolve(options.report), "utf8");
|
|
48
|
+
const response = await fetchImpl(new URL("/api/store-purchases/reconcile", options.server), {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { authorization: `Bearer ${key}`, "act-as-user": options.as, "content-type": "application/json" },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
source: options.source,
|
|
53
|
+
environment: options.environment,
|
|
54
|
+
reportName: path.basename(options.report),
|
|
55
|
+
report,
|
|
56
|
+
from: options.from,
|
|
57
|
+
before: options.before
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
const answer = await response.json().catch(() => ({}));
|
|
61
|
+
if (!response.ok) throw new Error(`The server refused the report (${response.status}): ${answer.error || answer.message || answer.code || "no reason given"}.`);
|
|
62
|
+
write(`Reconciled ${answer.reconciled} ledger row(s) from ${path.basename(options.report)}.\n`);
|
|
63
|
+
for (const difference of answer.differences || []) {
|
|
64
|
+
const detail = difference.ledger !== undefined ? ` (ledger ${difference.ledger}, report ${difference.report ?? "-"})` : "";
|
|
65
|
+
write(` ${difference.kind}: ${difference.reference}${detail}\n`);
|
|
66
|
+
}
|
|
67
|
+
return (answer.differences || []).length ? 1 : 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { runStorePurchases };
|
|
@@ -403,9 +403,19 @@ function runNode(args, env) {
|
|
|
403
403
|
*/
|
|
404
404
|
const LIST_OPTION = "--list";
|
|
405
405
|
|
|
406
|
+
/**
|
|
407
|
+
* The files a run of `args` in `cwd` would take, without running them or preparing a database (`jskit test --list`'s,
|
|
408
|
+
* and `jskit verify --list`'s for a part that is `jskit test`).
|
|
409
|
+
* @param {string[]} args
|
|
410
|
+
* @param {{ cwd?: string }} [where]
|
|
411
|
+
*/
|
|
412
|
+
export function testFilesOf(args, { cwd = process.cwd() } = {}) {
|
|
413
|
+
return planTestRuns(args.filter((argument) => argument !== LIST_OPTION && argument !== DATABASES_OPTION), { cwd }).paths;
|
|
414
|
+
}
|
|
415
|
+
|
|
406
416
|
/** The files a run of `args` would take, and their count, without running them or preparing a database. */
|
|
407
417
|
function listTestFiles(args) {
|
|
408
|
-
const
|
|
418
|
+
const paths = testFilesOf(args);
|
|
409
419
|
process.stdout.write(`${[...paths, `Total: ${paths.length} ${paths.length === 1 ? "file" : "files"}`].join("\n")}\n`);
|
|
410
420
|
return 0;
|
|
411
421
|
}
|
package/scripts/verify.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import os from "node:os";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
9
|
import { PROJECT_CHECK, runProjectCheck } from "./project-check.mjs";
|
|
10
|
+
import { testFilesOf } from "./testing/command.mjs";
|
|
10
11
|
|
|
11
12
|
// `jskit verify`: an app's whole check (its Verification): first the app's JSKIT check (plain `jskit check`'s rules, run
|
|
12
13
|
// here, so no app can leave its JSKIT drift out), then the npm scripts package.json's jskitVerify.parts names, run in
|
|
@@ -121,6 +122,7 @@ export function readVerifyConfig(projectRoot) {
|
|
|
121
122
|
.flatMap((script) => (typeof script === "string" && projectCheckManifests(script)) || []))];
|
|
122
123
|
return Object.freeze({
|
|
123
124
|
parts: Object.freeze(parts), checkParts: Object.freeze(checkParts), checkManifests: Object.freeze(checkManifests),
|
|
125
|
+
commands: Object.freeze(Object.fromEntries(parts.map(({ script }) => [script, scripts[script]]))),
|
|
124
126
|
settings: Object.freeze([...settings]), checkouts
|
|
125
127
|
});
|
|
126
128
|
}
|
|
@@ -308,14 +310,21 @@ function passedAlready(pass, file, projectRoot) {
|
|
|
308
310
|
* @param {(app: { projectRoot: string, additionalManifests: string[] }) => Promise<{ ok: boolean, report: string }>}
|
|
309
311
|
* [tools.runCheck] the JSKIT check
|
|
310
312
|
* @param {(part: { script: string, args: string[], cwd: string, env: object }) => number} [tools.runPart]
|
|
313
|
+
* @param {typeof listPartFiles} [tools.listPart] the files a part would take, or null for a part that can't list them
|
|
311
314
|
* @param {(line: string) => void} [tools.print]
|
|
315
|
+
* @param {(line: string) => void} [tools.printError]
|
|
312
316
|
* @param {() => number} [tools.now]
|
|
313
317
|
*/
|
|
314
318
|
export async function runVerify({
|
|
315
319
|
projectRoot = process.cwd(), argv = [], env = process.env, nodeVersion = process.version, host = os.hostname(),
|
|
316
|
-
runCheck = runProjectCheck, runPart = npmPart, print = (line) => process.stdout.write(`${line}\n`),
|
|
320
|
+
runCheck = runProjectCheck, runPart = npmPart, listPart = listPartFiles, print = (line) => process.stdout.write(`${line}\n`),
|
|
321
|
+
printError = (line) => process.stderr.write(`${line}\n`), now = Date.now
|
|
317
322
|
} = {}) {
|
|
318
323
|
const config = readVerifyConfig(projectRoot);
|
|
324
|
+
// `npm run verify --list <files>` hands npm's --list to the script as npm_config_list, and only the files as words.
|
|
325
|
+
if (argv.includes(LIST_OPTION) || env.npm_config_list === "true") {
|
|
326
|
+
return listVerify({ projectRoot, config, words: argv.filter((word) => word !== LIST_OPTION), env, listPart, print, printError });
|
|
327
|
+
}
|
|
319
328
|
const log = (line) => print(`jskit verify: ${line}`);
|
|
320
329
|
const last = config.parts.findLastIndex(({ script }) => !config.checkParts.includes(script));
|
|
321
330
|
if (argv.length > 0 && last < 0) {
|
|
@@ -385,6 +394,76 @@ export async function runVerify({
|
|
|
385
394
|
return 0;
|
|
386
395
|
}
|
|
387
396
|
|
|
397
|
+
const LIST_OPTION = "--list";
|
|
398
|
+
const JSKIT_TEST = /^jskit\s+test(?:\s|$)/u;
|
|
399
|
+
const PLAYWRIGHT_TEST = /^(?:npx\s+)?playwright\s+test(?:\s|$)/u;
|
|
400
|
+
const toPosix = (file) => file.split(path.sep).join("/");
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The files a part would take, relative to the project, without running it: a `jskit test` part's as `jskit test --list`
|
|
404
|
+
* finds them, a `playwright test` part's from Playwright's own --list; null for a part that can't list them.
|
|
405
|
+
* @param {{ projectRoot: string, script: string, command: string, files: string[], env: object }} part
|
|
406
|
+
* @returns {Promise<string[] | null>}
|
|
407
|
+
*/
|
|
408
|
+
export async function listPartFiles({ projectRoot, script, command, files, env }) {
|
|
409
|
+
const text = String(command).trim();
|
|
410
|
+
if (JSKIT_TEST.test(text)) return testFilesOf([...text.split(/\s+/u).slice(2), ...files], { cwd: projectRoot });
|
|
411
|
+
if (!PLAYWRIGHT_TEST.test(text)) return null;
|
|
412
|
+
const ran = spawnSync("npm", ["run", "--silent", script, "--", "--list", "--pass-with-no-tests", "--reporter=json", ...files],
|
|
413
|
+
{ cwd: projectRoot, env, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
414
|
+
let report;
|
|
415
|
+
try {
|
|
416
|
+
report = JSON.parse(ran.stdout);
|
|
417
|
+
} catch {
|
|
418
|
+
throw new Error(`npm run ${script} -- --list could not list its files (exit ${ran.status ?? ran.signal}): ` +
|
|
419
|
+
`${String(ran.stderr || ran.error?.message || "").trim().slice(-2000)}`);
|
|
420
|
+
}
|
|
421
|
+
const rootDir = report.config?.rootDir || projectRoot;
|
|
422
|
+
const found = new Set();
|
|
423
|
+
const walk = (suites = []) => {
|
|
424
|
+
for (const suite of suites) {
|
|
425
|
+
if (suite.file) found.add(toPosix(path.relative(projectRoot, path.resolve(rootDir, suite.file))));
|
|
426
|
+
walk(suite.suites);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
walk(report.suites);
|
|
430
|
+
return [...found];
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* `jskit verify --list [files]`: the test files `jskit verify [files]` would run, one per line, then `Total: <n>
|
|
435
|
+
* file(s)`, as `jskit test --list` prints them, running nothing, not even the JSKIT check: those of the part the files go
|
|
436
|
+
* to, the last that runs, as in a run; the parts before it (lint, checks) take no files and are not listed. Exit 2,
|
|
437
|
+
* saying why on stderr, for an option, a file that part doesn't take, or that part being one that can't list its files.
|
|
438
|
+
*/
|
|
439
|
+
async function listVerify({ projectRoot, config, words, env, listPart, print, printError }) {
|
|
440
|
+
const refuse = (reason) => {
|
|
441
|
+
printError(`jskit verify --list: ${reason}`);
|
|
442
|
+
return 2;
|
|
443
|
+
};
|
|
444
|
+
const option = words.find((word) => word.startsWith("-"));
|
|
445
|
+
if (option) return refuse(`${option} is not a file: --list takes only the files to list.`);
|
|
446
|
+
const part = config.parts.findLast(({ script }) => !config.checkParts.includes(script));
|
|
447
|
+
const listed = new Set();
|
|
448
|
+
if (part) {
|
|
449
|
+
const command = config.commands[part.script];
|
|
450
|
+
const paths = await listPart({ projectRoot, script: part.script, command, files: words, env: { ...env, ...part.env } });
|
|
451
|
+
if (paths === null) {
|
|
452
|
+
return refuse(`npm run ${part.script} runs \`${command}\`, which can't list the files it takes (only jskit test and ` +
|
|
453
|
+
"playwright test can), so --list lists nothing and runs nothing.");
|
|
454
|
+
}
|
|
455
|
+
for (const file of paths) listed.add(file);
|
|
456
|
+
}
|
|
457
|
+
const untaken = words.filter((file) => !listed.has(toPosix(path.relative(projectRoot, path.resolve(projectRoot, file)))));
|
|
458
|
+
if (untaken.length > 0) {
|
|
459
|
+
const them = untaken.length === 1 ? "it" : "them";
|
|
460
|
+
return refuse(`no part of jskitVerify.parts takes ${untaken.join(", ")}, so a run of ${them} would run none of ${them}.`);
|
|
461
|
+
}
|
|
462
|
+
const files = [...listed].sort();
|
|
463
|
+
print([...files, `Total: ${files.length} ${files.length === 1 ? "file" : "files"}`].join("\n"));
|
|
464
|
+
return 0;
|
|
465
|
+
}
|
|
466
|
+
|
|
388
467
|
/**
|
|
389
468
|
* A CI run's name for a pass: the project's tree and the commits of the other repositories it checked out.
|
|
390
469
|
* @param {{ tree: string, commits: Record<string, string> }} inputs
|