@jskit-ai/jskit-catalog 0.2.146 → 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
|
@@ -14,11 +14,12 @@ const VUE_FILE = /\.vue$/u;
|
|
|
14
14
|
const APP_FILE = /\.(?:[cm]?js|vue)$/u;
|
|
15
15
|
const SKIPPED_FILE = /\.(?:test|spec|vitest)\.[cm]?js$/u;
|
|
16
16
|
// Code that defines no table resource or system scope an app runs: dependencies, anywhere; and, at the root of the app or
|
|
17
|
-
// of one of its packages (PACKAGE_DIRECTORY), build output, tests and fixtures, migrations and seeds,
|
|
18
|
-
// templates and documentation JSKIT packages carry
|
|
17
|
+
// of one of its packages (PACKAGE_DIRECTORY), build output, tests and fixtures, migrations and seeds, the examples,
|
|
18
|
+
// templates and documentation JSKIT packages carry, and the native projects Capacitor makes (android/, ios/: its bridge
|
|
19
|
+
// script, the web build `npx cap sync` copies in, and Gradle's and Xcode's build output).
|
|
19
20
|
const SKIPPED_ROOT_DIRECTORIES = new Set([
|
|
20
21
|
"dist", "build", "coverage", "test", "tests", "__tests__", "e2e", "fixtures", "test-results", "migrations", "seed",
|
|
21
|
-
"seeds", "templates", "patterns", "examples", "docs", "site", "skills", "test-support", "src/test"
|
|
22
|
+
"seeds", "templates", "patterns", "examples", "docs", "site", "skills", "test-support", "src/test", "android", "ios"
|
|
22
23
|
]);
|
|
23
24
|
const PACKAGE_DIRECTORY = /^(?:packages|tooling)\/[^/]+\/(.+)$/u;
|
|
24
25
|
const skipsDirectory = (name) => path.posix.basename(name) === "node_modules" ||
|
package/scripts/jskit.mjs
CHANGED
|
@@ -11,23 +11,18 @@ import {
|
|
|
11
11
|
formatCheckReport,
|
|
12
12
|
formatExportSummary
|
|
13
13
|
} from "./i18n.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { formatAgentsBlockWrite, writeAgentsBlock } from "./agents-block.mjs";
|
|
15
15
|
import { serveBrowserTestTarget } from "./browser-test-server.mjs";
|
|
16
|
-
import { checkDataAccess, formatDataAccessReport } from "./data-access.mjs";
|
|
17
|
-
import { checkManifestCapabilities, formatManifestCapabilitiesReport } from "./manifest-capabilities.mjs";
|
|
18
16
|
import { checkMaterial3, formatMaterial3Report } from "./material3.mjs";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
17
|
+
import { packageNix } from "./package-nix.mjs";
|
|
18
|
+
import { CATALOG_PATH, runProjectCheck } from "./project-check.mjs";
|
|
19
|
+
import { updateProject } from "./project-packages.mjs";
|
|
20
|
+
import { formatRedundantReleaseManifests } from "./project-manifests.mjs";
|
|
22
21
|
import { runTests } from "./testing/command.mjs";
|
|
23
22
|
import { runMigrationHistory } from "./testing/databases.mjs";
|
|
24
|
-
import { checkTestRuns, formatTestRunsReport } from "./testing/runs.mjs";
|
|
25
|
-
import { checkTestSources, formatTestSourcesReport } from "./testing/sources.mjs";
|
|
26
23
|
import { runVerify, runVerifyPass } from "./verify.mjs";
|
|
27
24
|
|
|
28
25
|
const SCRIPT_PATH = fileURLToPath(import.meta.url);
|
|
29
|
-
const PACKAGE_ROOT = path.resolve(path.dirname(SCRIPT_PATH), "..");
|
|
30
|
-
const CATALOG_PATH = path.join(PACKAGE_ROOT, "catalog", "packages.json");
|
|
31
26
|
const I18N_SUBCOMMANDS = new Set(["export", "check"]);
|
|
32
27
|
|
|
33
28
|
function usage() {
|
|
@@ -48,10 +43,14 @@ function usage() {
|
|
|
48
43
|
" jskit browser-test-server [host] [port] [workers]",
|
|
49
44
|
"",
|
|
50
45
|
"Commands:",
|
|
51
|
-
" update
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
46
|
+
" update Set the root's @jskit-ai/jskit-catalog to this published catalog's exact version and every other",
|
|
47
|
+
" @jskit-ai/* entry, in the root and in each module its npm workspaces or its jskitRelease.manifests",
|
|
48
|
+
" name, to this catalog's version of the package, run npm install, and write this catalog's JSKIT",
|
|
49
|
+
" block in AGENTS.md (jskit agents).",
|
|
50
|
+
" check Fail when manifests or package-lock.json contain stale, mixed, or private singleton JSKIT stacks",
|
|
51
|
+
" (a root without @jskit-ai/jskit-catalog, or a root or module @jskit-ai/* entry that is not this",
|
|
52
|
+
" catalog's exact version of the package, or a package it does not list, each naming its file and",
|
|
53
|
+
" npm run jskit:update), or when application source breaks a rule of the JSKIT Material 3 guide: a navigation rule (nav/*),",
|
|
55
54
|
" such as history or window.location navigation, a hand-built in-app path, a back control other than",
|
|
56
55
|
" the shell's Up arrow, an inner page without a declared parent or a main-navigation page that",
|
|
57
56
|
" declares one, a visual rule (m3/*), such as a raw colour, an MDI icon, an outlined card or a",
|
|
@@ -87,7 +86,11 @@ function usage() {
|
|
|
87
86
|
" (package/nix-offline). In an app whose package.json declares @jskit-ai/jskit-catalog, it fails when",
|
|
88
87
|
" AGENTS.md lacks this catalog's JSKIT block, or its block differs (agents/jskit-block). It fails",
|
|
89
88
|
" when the app's server.js creates Fastify without a trustProxy option (server/trust-proxy), which",
|
|
90
|
-
" behind a reverse proxy sees every request as the proxy's; options it cannot read pass.",
|
|
89
|
+
" behind a reverse proxy sees every request as the proxy's; options it cannot read pass. In an app",
|
|
90
|
+
" whose JSKIT packages need Capacitor (@jskit-ai/mobile-capacitor), it fails when a Capacitor package",
|
|
91
|
+
" the app declares, its native android/ or ios/ project, its Capacitor config or config/public.js's",
|
|
92
|
+
" config.mobile.android is not on the Capacitor major they need (capacitor/*), and update refuses",
|
|
93
|
+
" before changing anything, naming npx cap migrate and the other steps.",
|
|
91
94
|
" check m3 Check application UI source against the JSKIT Material 3 guide alone, with each finding's guide",
|
|
92
95
|
" section and every exception: the whole app, or only the given files and directories (a section,",
|
|
93
96
|
" or a task's changed files). Plain jskit check applies the same rules to the whole app.",
|
|
@@ -128,13 +131,16 @@ function usage() {
|
|
|
128
131
|
" compare the tables, definitions and rows built with the test snapshot (all but when each migration",
|
|
129
132
|
" ran), and leave TEST_DB_NAME as the snapshot. It fails, saying what differs, when a migration builds",
|
|
130
133
|
" something else on each replay. Run it as its own check, beside the test suite.",
|
|
131
|
-
" verify Run the app's whole check
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
+
" verify Run the app's whole check: first its JSKIT check (plain jskit check's rules), which fails the run",
|
|
135
|
+
" before anything else when it fails, then the npm scripts package.json's jskitVerify.parts names, in",
|
|
136
|
+
" order (a part whose script is jskit check is not run again), stopping at the first that fails with",
|
|
137
|
+
" its exit status, once per exact tree: a whole run that passes records what it checked in",
|
|
138
|
+
" node_modules/.cache/jskit/verify-passes/ (the project's tree, the other checkouts",
|
|
134
139
|
" jskitVerify.checkouts names, each one's installed dependencies, the settings jskitVerify.settings",
|
|
135
|
-
" declares, Node's version and the parts), and a whole run on the same
|
|
136
|
-
" runs nothing. Working changes, inputs it can't read, a failed or
|
|
137
|
-
" while it ran and a run given args (they go to the last part
|
|
140
|
+
" declares, Node's version, the JSKIT check's catalog and the parts), and a whole run on the same",
|
|
141
|
+
" inputs prints that record and runs nothing. Working changes, inputs it can't read, a failed or",
|
|
142
|
+
" 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.",
|
|
138
144
|
" verify-pass A CI run's first step: name the pass for the project's exact tree and the given commits of the",
|
|
139
145
|
" other repositories it checks out, ask GitHub (GITHUB_TOKEN, GITHUB_REPOSITORY) whether an artifact",
|
|
140
146
|
" of that name is kept, and write name and reuse to GITHUB_OUTPUT; the run records the artifact only",
|
|
@@ -390,6 +396,9 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
390
396
|
additionalManifests: options.additionalManifests,
|
|
391
397
|
install: options.install
|
|
392
398
|
});
|
|
399
|
+
if (result.redundantReleaseManifests.length > 0) {
|
|
400
|
+
process.stdout.write(`${formatRedundantReleaseManifests(result.redundantReleaseManifests)}\n`);
|
|
401
|
+
}
|
|
393
402
|
for (const { packageId, replacedBy } of result.retiredPackages) {
|
|
394
403
|
process.stdout.write(`Removed ${packageId}, which this release retired: ${replacedBy} replaced it.\n`);
|
|
395
404
|
}
|
|
@@ -426,39 +435,9 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
426
435
|
return;
|
|
427
436
|
}
|
|
428
437
|
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
checkInstalled: true,
|
|
433
|
-
catalog
|
|
434
|
-
});
|
|
435
|
-
const ui = await checkMaterial3({ projectRoot: options.projectRoot });
|
|
436
|
-
const tests = await checkTestRuns({ projectRoot: options.projectRoot, manifests: result.manifests });
|
|
437
|
-
const sources = await checkTestSources({ projectRoot: options.projectRoot });
|
|
438
|
-
const data = await checkDataAccess({ projectRoot: options.projectRoot });
|
|
439
|
-
const capabilities = await checkManifestCapabilities({ projectRoot: options.projectRoot, manifests: result.manifests });
|
|
440
|
-
const nixPackage = await checkPackageNix({ projectRoot: options.projectRoot });
|
|
441
|
-
const agents = await checkAgentsBlock({ projectRoot: options.projectRoot });
|
|
442
|
-
const server = await checkServerSetup({ projectRoot: options.projectRoot });
|
|
443
|
-
// The data rules first: a graph that fails on many pin versions would otherwise bury them.
|
|
444
|
-
const reports = [
|
|
445
|
-
formatDataAccessReport(data),
|
|
446
|
-
result.ok
|
|
447
|
-
? `JSKIT project graph is coordinated across ${result.manifests.length} manifest(s) and ` +
|
|
448
|
-
`${result.installations.length} resolved package installation(s).`
|
|
449
|
-
: `JSKIT project graph is inconsistent:\n- ${result.issues.join("\n- ")}`,
|
|
450
|
-
formatMaterial3Report(ui),
|
|
451
|
-
formatTestRunsReport(tests),
|
|
452
|
-
formatTestSourcesReport(sources),
|
|
453
|
-
formatManifestCapabilitiesReport(capabilities),
|
|
454
|
-
formatPackageNixReport(nixPackage),
|
|
455
|
-
formatAgentsBlockReport(agents),
|
|
456
|
-
formatServerSetupReport(server)
|
|
457
|
-
];
|
|
458
|
-
if (!result.ok || !ui.ok || !tests.ok || !sources.ok || !data.ok || !capabilities.ok || !nixPackage.ok || !agents.ok || !server.ok) {
|
|
459
|
-
throw new Error(reports.join("\n"));
|
|
460
|
-
}
|
|
461
|
-
process.stdout.write(`${reports.join("\n")}\n`);
|
|
438
|
+
const { ok, report } = await runProjectCheck(options);
|
|
439
|
+
if (!ok) throw new Error(report);
|
|
440
|
+
process.stdout.write(`${report}\n`);
|
|
462
441
|
}
|
|
463
442
|
|
|
464
443
|
function isCliEntrypoint(argvPath = process.argv[1]) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { checkAgentsBlock, formatAgentsBlockReport } from "./agents-block.mjs";
|
|
6
|
+
import { checkCapacitor, formatCapacitorReport } from "./capacitor.mjs";
|
|
7
|
+
import { checkDataAccess, formatDataAccessReport } from "./data-access.mjs";
|
|
8
|
+
import { checkManifestCapabilities, formatManifestCapabilitiesReport } from "./manifest-capabilities.mjs";
|
|
9
|
+
import { checkMaterial3, formatMaterial3Report } from "./material3.mjs";
|
|
10
|
+
import { checkPackageNix, formatPackageNixReport } from "./package-nix.mjs";
|
|
11
|
+
import { checkProject } from "./project-packages.mjs";
|
|
12
|
+
import { checkServerSetup, formatServerSetupReport } from "./server-setup.mjs";
|
|
13
|
+
import { checkTestRuns, formatTestRunsReport } from "./testing/runs.mjs";
|
|
14
|
+
import { checkTestSources, formatTestSourcesReport } from "./testing/sources.mjs";
|
|
15
|
+
|
|
16
|
+
// Plain `jskit check`, the app's JSKIT check: every rule, on the catalog this copy of JSKIT carries. `jskit verify` runs
|
|
17
|
+
// it first.
|
|
18
|
+
|
|
19
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
20
|
+
export const CATALOG_PATH = path.join(PACKAGE_ROOT, "catalog", "packages.json");
|
|
21
|
+
|
|
22
|
+
/** The check as a pass records it: the command and the catalog whose rules and versions it checked. */
|
|
23
|
+
export const PROJECT_CHECK = Object.freeze({
|
|
24
|
+
command: "jskit check",
|
|
25
|
+
catalog: JSON.parse(readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8")).version
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Runs every rule of plain `jskit check` on the app.
|
|
30
|
+
* @param {{ projectRoot: string, additionalManifests?: string[] }} options
|
|
31
|
+
* @returns {Promise<{ ok: boolean, report: string }>} whether it passed, and its report: each rule's line, a failing
|
|
32
|
+
* rule's findings with their fixes
|
|
33
|
+
*/
|
|
34
|
+
export async function runProjectCheck({ projectRoot, additionalManifests }) {
|
|
35
|
+
const catalog = JSON.parse(await readFile(CATALOG_PATH, "utf8"));
|
|
36
|
+
const result = await checkProject({ projectRoot, additionalManifests, checkInstalled: true, catalog });
|
|
37
|
+
const ui = await checkMaterial3({ projectRoot });
|
|
38
|
+
const tests = await checkTestRuns({ projectRoot, manifests: result.manifests });
|
|
39
|
+
const sources = await checkTestSources({ projectRoot });
|
|
40
|
+
const data = await checkDataAccess({ projectRoot });
|
|
41
|
+
const capabilities = await checkManifestCapabilities({ projectRoot, manifests: result.manifests });
|
|
42
|
+
const nixPackage = await checkPackageNix({ projectRoot });
|
|
43
|
+
const agents = await checkAgentsBlock({ projectRoot });
|
|
44
|
+
const server = await checkServerSetup({ projectRoot });
|
|
45
|
+
const capacitor = await checkCapacitor({
|
|
46
|
+
projectRoot,
|
|
47
|
+
catalog,
|
|
48
|
+
manifests: result.manifests,
|
|
49
|
+
declaredPackageIds: new Set(result.declarations.map((entry) => entry.packageId))
|
|
50
|
+
});
|
|
51
|
+
// The data rules first: a graph that fails on many pin versions would otherwise bury them.
|
|
52
|
+
const reports = [
|
|
53
|
+
formatDataAccessReport(data),
|
|
54
|
+
result.ok
|
|
55
|
+
? `JSKIT project graph is coordinated across ${result.manifests.length} manifest(s) and ` +
|
|
56
|
+
`${result.installations.length} resolved package installation(s).`
|
|
57
|
+
: `JSKIT project graph is inconsistent:\n- ${result.issues.join("\n- ")}`,
|
|
58
|
+
formatMaterial3Report(ui),
|
|
59
|
+
formatTestRunsReport(tests),
|
|
60
|
+
formatTestSourcesReport(sources),
|
|
61
|
+
formatManifestCapabilitiesReport(capabilities),
|
|
62
|
+
formatPackageNixReport(nixPackage),
|
|
63
|
+
formatAgentsBlockReport(agents),
|
|
64
|
+
formatServerSetupReport(server),
|
|
65
|
+
formatCapacitorReport(capacitor)
|
|
66
|
+
].filter(Boolean);
|
|
67
|
+
const ok = [result, ui, tests, sources, data, capabilities, nixPackage, agents, server, capacitor].every(({ ok: passed }) => passed);
|
|
68
|
+
return { ok, report: reports.join("\n") };
|
|
69
|
+
}
|
|
@@ -17,6 +17,8 @@ const SKIPPED_DIRECTORY_NAMES = new Set([
|
|
|
17
17
|
"node_modules",
|
|
18
18
|
"tmp"
|
|
19
19
|
]);
|
|
20
|
+
const DEPENDENCY_FIELDS = Object.freeze(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]);
|
|
21
|
+
|
|
20
22
|
function normalizeWorkspacePatterns(value) {
|
|
21
23
|
if (Array.isArray(value)) {
|
|
22
24
|
return value;
|
|
@@ -124,10 +126,87 @@ async function discoverProjectManifests(projectRoot, additionalManifests = []) {
|
|
|
124
126
|
return Object.freeze(manifests);
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
// A root's jskitRelease.manifests: the module folders an app composes itself (into another app, say) rather than
|
|
130
|
+
// installing as npm workspaces, each a folder or a `*` pattern. An app's modules are its workspaces and these folders:
|
|
131
|
+
// the update and the pin rewrite the JSKIT entries of all of them, and the check checks all of them, a composed module
|
|
132
|
+
// as a separately composed manifest, without an entry in the root's lockfile. Returns `composed`, the package.json of
|
|
133
|
+
// each folder it names that no workspace pattern matches, and `redundant`, its entries the workspaces already cover
|
|
134
|
+
// (each folder they name is a workspace), in the app's order. A folder it names that holds no package.json is refused.
|
|
135
|
+
async function readReleaseManifests(projectRoot, rootManifest) {
|
|
136
|
+
const entries = rootManifest.value?.jskitRelease?.manifests;
|
|
137
|
+
if (entries === undefined) return Object.freeze({ composed: Object.freeze([]), redundant: Object.freeze([]) });
|
|
138
|
+
if (!Array.isArray(entries) || !entries.every((entry) => typeof entry === "string" && entry.trim() !== "")) {
|
|
139
|
+
throw new Error(`package.json jskitRelease.manifests must be a list of module folders; it is ${JSON.stringify(entries)}.`);
|
|
140
|
+
}
|
|
141
|
+
const root = path.resolve(projectRoot);
|
|
142
|
+
const matchesWorkspace = createWorkspaceMatcher(rootManifest.value.workspaces);
|
|
143
|
+
let folders = null;
|
|
144
|
+
const composed = new Set();
|
|
145
|
+
const redundant = [];
|
|
146
|
+
const missing = [];
|
|
147
|
+
for (const entry of entries.filter((value) => !value.startsWith("!"))) {
|
|
148
|
+
const pattern = toPosixPath(entry).replace(/^\.\//u, "").replace(/\/$/u, "");
|
|
149
|
+
if (!/[*?]/u.test(pattern) && path.resolve(root, pattern) === root) {
|
|
150
|
+
throw new Error(`package.json jskitRelease.manifests names ${entry}, which is the app's root, not a module: the root ` +
|
|
151
|
+
"is always read as the root. Remove the entry.");
|
|
152
|
+
}
|
|
153
|
+
let named;
|
|
154
|
+
if (/[*?]/u.test(pattern)) {
|
|
155
|
+
folders ||= (await collectNestedPackageJsonPaths(root)).map((file) => toPosixPath(path.relative(root, path.dirname(file))));
|
|
156
|
+
named = folders.filter((folder) => globToRegExp(pattern).test(folder));
|
|
157
|
+
} else if (await fileExists(path.join(root, pattern, "package.json"))) {
|
|
158
|
+
named = [pattern];
|
|
159
|
+
} else {
|
|
160
|
+
missing.push(pattern);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (named.length > 0 && named.every((folder) => matchesWorkspace(folder))) redundant.push(entry);
|
|
164
|
+
for (const folder of named) if (!matchesWorkspace(folder)) composed.add(path.join(root, folder, "package.json"));
|
|
165
|
+
}
|
|
166
|
+
if (missing.length > 0) {
|
|
167
|
+
throw new Error(`package.json jskitRelease.manifests names ${missing.join(", ")}, which holds no package.json: each folder ` +
|
|
168
|
+
"it names is one of the app's modules, whose @jskit-ai/* entries npm run jskit:update and the pin rewrite and jskit " +
|
|
169
|
+
"check checks. Remove the entry, or restore the module's package.json.");
|
|
170
|
+
}
|
|
171
|
+
return Object.freeze({ composed: Object.freeze([...composed].sort()), redundant: Object.freeze(redundant) });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The modules an app installs through `file:` dependencies inside it, followed from module to module, beside the given
|
|
175
|
+
// manifests (records): each one's package.json path, sorted. A `file:` outside the app, or one naming no folder with a
|
|
176
|
+
// package.json (a tarball, say), names none.
|
|
177
|
+
async function linkedManifests(projectRoot, records) {
|
|
178
|
+
const root = path.resolve(projectRoot);
|
|
179
|
+
const seen = new Set(records.map(({ absolutePath }) => absolutePath));
|
|
180
|
+
const queue = [...records];
|
|
181
|
+
const linked = [];
|
|
182
|
+
while (queue.length > 0) {
|
|
183
|
+
const { absolutePath, value } = queue.shift();
|
|
184
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
185
|
+
for (const spec of Object.values(value?.[field] || {})) {
|
|
186
|
+
if (!String(spec).startsWith("file:")) continue;
|
|
187
|
+
const folder = path.resolve(path.dirname(absolutePath), String(spec).slice("file:".length));
|
|
188
|
+
const file = path.join(folder, "package.json");
|
|
189
|
+
if (!folder.startsWith(`${root}${path.sep}`) || seen.has(file) || !(await fileExists(file))) continue;
|
|
190
|
+
seen.add(file);
|
|
191
|
+
linked.push(file);
|
|
192
|
+
queue.push(await readJsonRecord(file));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return Object.freeze(linked.sort());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function formatRedundantReleaseManifests(entries) {
|
|
200
|
+
return `package.json jskitRelease.manifests names ${entries.join(", ")}, which the root's workspaces already name: ` +
|
|
201
|
+
"remove those entries; the workspaces find each module.";
|
|
202
|
+
}
|
|
203
|
+
|
|
127
204
|
function serializePackageJson(value, originalContents = "") {
|
|
128
205
|
const indentMatch = /\n([ \t]+)"/u.exec(String(originalContents || ""));
|
|
129
206
|
const indentation = indentMatch?.[1] || " ";
|
|
130
207
|
return `${JSON.stringify(value, null, indentation)}\n`;
|
|
131
208
|
}
|
|
132
209
|
|
|
133
|
-
export {
|
|
210
|
+
export {
|
|
211
|
+
discoverProjectManifests, formatRedundantReleaseManifests, linkedManifests, readJsonRecord, readReleaseManifests, serializePackageJson
|
|
212
|
+
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { readdir, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { capacitorMigrationSteps, checkCapacitor, formatCapacitorFinding } from "./capacitor.mjs";
|
|
3
4
|
import { fileExists, toPosixPath } from "./files.mjs";
|
|
4
5
|
import { readOptionalFile, restoreProjectFiles, runNpmInstall, writeManifestUpdates } from "./project-install.mjs";
|
|
5
6
|
import { installedPackageMigrations, packageMigrationChanges } from "./project-migrations.mjs";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
discoverProjectManifests, linkedManifests, readJsonRecord, readReleaseManifests, serializePackageJson
|
|
9
|
+
} from "./project-manifests.mjs";
|
|
7
10
|
|
|
8
11
|
const JSKIT_SCOPE_PREFIX = "@jskit-ai/";
|
|
9
12
|
const CATALOG_PACKAGE_ID = "@jskit-ai/jskit-catalog";
|
|
@@ -13,6 +16,8 @@ const DEPENDENCY_FIELDS = Object.freeze([
|
|
|
13
16
|
"peerDependencies",
|
|
14
17
|
"optionalDependencies"
|
|
15
18
|
]);
|
|
19
|
+
// The fields a root declares the catalog in: an ordinary dependency, never a peer.
|
|
20
|
+
const CATALOG_FIELDS = Object.freeze(["dependencies", "devDependencies", "optionalDependencies"]);
|
|
16
21
|
const UPDATE_SCRIPT = "npx --yes @jskit-ai/jskit-catalog@latest update";
|
|
17
22
|
const UPDATE_FIX = "Run npm run jskit:update, which moves every JSKIT pin to this catalog and installs it.";
|
|
18
23
|
// JSKIT packages a release retired, each with what replaced it. The updater removes their declarations itself, and
|
|
@@ -190,19 +195,64 @@ function collectJskitOverridePaths(value, currentPath = "overrides", results = [
|
|
|
190
195
|
return results;
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
|
|
198
|
+
// The manifests beside the root's workspaces: the given ones, the modules the root's jskitRelease.manifests names
|
|
199
|
+
// outside the workspaces, which the app composes itself (readReleaseManifests), and the modules the app installs
|
|
200
|
+
// through file: dependencies inside it (`linked`, linkedManifests). A composed module has no root lockfile entry.
|
|
201
|
+
async function composedManifests(root, additionalManifests) {
|
|
202
|
+
const releaseManifests = await readReleaseManifests(root, await readJsonRecord(path.join(root, "package.json")));
|
|
203
|
+
const named = [...new Set([...additionalManifests.map((file) => path.resolve(root, file)), ...releaseManifests.composed])];
|
|
204
|
+
const linked = await linkedManifests(root, await discoverProjectManifests(root, named));
|
|
205
|
+
return { releaseManifests, linked, additionalManifests: [...named, ...linked] };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* An app's modules, the one set jskit check, jskit update and jskit-release pin read: the root, its workspaces, the
|
|
210
|
+
* folders its jskitRelease.manifests names, the files given, and the folders its file: dependencies name inside it.
|
|
211
|
+
* @param {string} [projectRoot]
|
|
212
|
+
* @param {string[]} [givenManifests] package.json files given beside them (`--manifest`)
|
|
213
|
+
* @returns {Promise<readonly string[]>} each module's package.json path, the root's first
|
|
214
|
+
*/
|
|
215
|
+
async function appManifests(projectRoot = process.cwd(), givenManifests = []) {
|
|
216
|
+
const root = path.resolve(projectRoot);
|
|
217
|
+
const { additionalManifests } = await composedManifests(root, givenManifests);
|
|
218
|
+
return Object.freeze((await discoverProjectManifests(root, additionalManifests)).map(({ absolutePath }) => absolutePath));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function checkProject({ projectRoot = process.cwd(), catalog, additionalManifests: givenManifests = [], checkInstalled = false, sourcePackages = {} } = {}) {
|
|
194
222
|
const root = path.resolve(projectRoot);
|
|
195
223
|
const normalizedCatalog = normalizeCatalog(catalog);
|
|
224
|
+
const { additionalManifests, releaseManifests, linked } = await composedManifests(root, givenManifests);
|
|
196
225
|
const manifests = await discoverProjectManifests(root, additionalManifests);
|
|
226
|
+
// A module only jskitRelease.manifests or a file: dependency names loads only through the app, so the app's other
|
|
227
|
+
// checks, which read the returned manifests, read the root, its workspaces and the files --manifest names, as before.
|
|
228
|
+
const given = new Set(givenManifests.map((file) => path.resolve(root, file)));
|
|
229
|
+
const modulesOnly = new Set([...releaseManifests.composed, ...linked]);
|
|
230
|
+
const checkedManifests = manifests.filter((manifest) => !modulesOnly.has(manifest.absolutePath) || given.has(manifest.absolutePath));
|
|
197
231
|
const localPackageNames = collectLocalPackageNames(manifests);
|
|
198
232
|
const declarations = collectManifestDeclarations(manifests, root)
|
|
199
233
|
.filter((entry) => !localPackageNames.has(entry.packageId) && !Object.hasOwn(sourcePackages, entry.packageId));
|
|
200
234
|
const issues = [];
|
|
235
|
+
const catalogVersion = normalizedCatalog.versions.get(CATALOG_PACKAGE_ID);
|
|
236
|
+
|
|
237
|
+
// The app's JSKIT version is the one exact catalog version its root declares; every other JSKIT entry copies it. A
|
|
238
|
+
// project that declares no JSKIT package has no version to keep.
|
|
239
|
+
const rootManifest = manifests[0].value;
|
|
240
|
+
const declaresCatalog = CATALOG_FIELDS.some((field) => Object.hasOwn(rootManifest?.[field] || {}, CATALOG_PACKAGE_ID));
|
|
241
|
+
if (declarations.length > 0 && !declaresCatalog) {
|
|
242
|
+
issues.push(
|
|
243
|
+
`package.json declares no ${CATALOG_PACKAGE_ID}: an app's JSKIT version is that package's exact version in its root ` +
|
|
244
|
+
`manifest, and each other @jskit-ai/* entry is that catalog's version of its package. ${UPDATE_FIX}`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
201
247
|
|
|
202
248
|
for (const declaration of declarations) {
|
|
203
249
|
const expectedVersion = normalizedCatalog.versions.get(declaration.packageId);
|
|
204
250
|
if (!expectedVersion) {
|
|
205
|
-
issues.push(
|
|
251
|
+
issues.push(
|
|
252
|
+
`${declaration.source}#${declaration.field}.${declaration.packageId} is not in JSKIT catalog ${catalogVersion || "(unversioned)"}. ` +
|
|
253
|
+
`Run npm run jskit:update, which moves every JSKIT pin to the latest catalog; if that catalog does not list ` +
|
|
254
|
+
`${declaration.packageId} either, remove it.`
|
|
255
|
+
);
|
|
206
256
|
continue;
|
|
207
257
|
}
|
|
208
258
|
if (declaration.declaredVersion !== expectedVersion) {
|
|
@@ -255,7 +305,10 @@ async function checkProject({ projectRoot = process.cwd(), catalog, additionalMa
|
|
|
255
305
|
const locked = record?.[field] || {};
|
|
256
306
|
for (const name of new Set([...Object.keys(declared), ...Object.keys(locked)])) {
|
|
257
307
|
if (Object.hasOwn(sourcePackages, name)) continue;
|
|
258
|
-
if (declared[name]
|
|
308
|
+
if (declared[name] === locked[name]) continue;
|
|
309
|
+
// npm install would lock a hand-changed JSKIT entry in; the update puts the catalog's version back and installs it.
|
|
310
|
+
const fix = normalizedCatalog.versions.has(name) ? UPDATE_FIX : "Run npm install and commit the lockfile.";
|
|
311
|
+
issues.push(`${manifest.absolutePath}#${field}.${name} is ${declared[name] || "absent"}; lockfile records ${locked[name] || "absent"}. ${fix}`);
|
|
259
312
|
}
|
|
260
313
|
}
|
|
261
314
|
}
|
|
@@ -332,7 +385,7 @@ async function checkProject({ projectRoot = process.cwd(), catalog, additionalMa
|
|
|
332
385
|
return Object.freeze({
|
|
333
386
|
ok: issues.length < 1,
|
|
334
387
|
issues: Object.freeze(issues),
|
|
335
|
-
manifests,
|
|
388
|
+
manifests: checkedManifests,
|
|
336
389
|
declarations,
|
|
337
390
|
installations: Object.freeze(installations)
|
|
338
391
|
});
|
|
@@ -537,20 +590,21 @@ function approveInstallScripts(manifest, declared) {
|
|
|
537
590
|
}
|
|
538
591
|
|
|
539
592
|
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
593
|
+
* The one writer of an app's JSKIT versions, which `jskit update` and `jskit-release pin` both run: it sets the root's
|
|
594
|
+
* @jskit-ai/jskit-catalog to the catalog's exact version and every other @jskit-ai/* entry, in the root and in each
|
|
595
|
+
* of its modules (appManifests: its workspaces, its jskitRelease.manifests folders, its file: dependencies' folders and
|
|
596
|
+
* each additional manifest), to that catalog's version of the package. It changes no file: it refuses what it cannot write (an unknown or private JSKIT package, an import of
|
|
597
|
+
* a retired one, a jskitRelease.manifests folder without a package.json) and returns each manifest's new contents.
|
|
542
598
|
* @param {object} options
|
|
543
|
-
* @
|
|
599
|
+
* @returns {Promise<object>} `updates` ({ manifest, contents, changes }, each change `field.name old -> new`),
|
|
600
|
+
* `catalogVersion`, `retiredPackageIds`, `additionalManifests` (the given ones, the composed modules and the file:
|
|
601
|
+
* ones), `manifests` (every module's package.json path, appManifests' set) and `redundantReleaseManifests` (the
|
|
602
|
+
* jskitRelease.manifests entries the workspaces cover)
|
|
544
603
|
*/
|
|
545
|
-
async function
|
|
546
|
-
projectRoot = process.cwd(),
|
|
547
|
-
catalog,
|
|
548
|
-
install = true,
|
|
549
|
-
installProject = runNpmInstall,
|
|
550
|
-
additionalManifests = []
|
|
551
|
-
} = {}) {
|
|
604
|
+
async function planProjectUpdate({ projectRoot = process.cwd(), catalog, additionalManifests: givenManifests = [] } = {}) {
|
|
552
605
|
const root = path.resolve(projectRoot);
|
|
553
606
|
const normalizedCatalog = normalizeCatalog(catalog);
|
|
607
|
+
const { releaseManifests, additionalManifests } = await composedManifests(root, givenManifests);
|
|
554
608
|
const manifests = await discoverProjectManifests(root, additionalManifests);
|
|
555
609
|
const localPackageNames = collectLocalPackageNames(manifests);
|
|
556
610
|
const declarations = collectManifestDeclarations(manifests, root)
|
|
@@ -589,6 +643,22 @@ async function updateProject({
|
|
|
589
643
|
const declaredPackageIds = new Set(
|
|
590
644
|
declarations.map((entry) => entry.packageId).filter((packageId) => !retiredPackageIds.includes(packageId))
|
|
591
645
|
);
|
|
646
|
+
// An app on another Capacitor major than its JSKIT packages need moves with Capacitor's own migration first: its native
|
|
647
|
+
// projects are its own source, which no package install changes. The update waits only for what that major's upgrade
|
|
648
|
+
// guide requires; the rest, such as a second @capacitor/core inside a JSKIT package this update replaces, jskit check
|
|
649
|
+
// names after it.
|
|
650
|
+
const capacitor = await checkCapacitor({ projectRoot: root, catalog, manifests, declaredPackageIds });
|
|
651
|
+
if (capacitor.applies && capacitor.required.length > 0) {
|
|
652
|
+
const { major, range } = capacitor.requirement;
|
|
653
|
+
const others = capacitor.findings.length - capacitor.required.length;
|
|
654
|
+
throw new Error(
|
|
655
|
+
`Cannot update while the application is not on Capacitor ${major}, which ${capacitor.needing.join(", ")} ` +
|
|
656
|
+
`need${capacitor.needing.length > 1 ? "" : "s"} (@capacitor/core ${range}); nothing was changed:\n` +
|
|
657
|
+
`${capacitor.required.map((finding) => `- ${formatCapacitorFinding(finding)}`).join("\n")}\n` +
|
|
658
|
+
(others > 0 ? `jskit check also names ${others} item(s) that do not stop the update.\n` : "") +
|
|
659
|
+
capacitorMigrationSteps(capacitor.requirement, capacitor.fromMajor)
|
|
660
|
+
);
|
|
661
|
+
}
|
|
592
662
|
const catalogVersion = normalizedCatalog.versions.get(CATALOG_PACKAGE_ID);
|
|
593
663
|
if (!catalogVersion) {
|
|
594
664
|
throw new Error(`Coordinated catalog is missing ${CATALOG_PACKAGE_ID}.`);
|
|
@@ -599,49 +669,55 @@ async function updateProject({
|
|
|
599
669
|
const updates = [];
|
|
600
670
|
for (const [index, manifest] of manifests.entries()) {
|
|
601
671
|
const next = structuredClone(manifest.value);
|
|
672
|
+
const changes = [];
|
|
602
673
|
let changed = false;
|
|
674
|
+
const set = (field, name, version) => {
|
|
675
|
+
changes.push(`${field}.${name} ${next[field][name] ?? "(absent)"} -> ${version ?? "(removed)"}`);
|
|
676
|
+
if (version === undefined) delete next[field][name];
|
|
677
|
+
else next[field][name] = version;
|
|
678
|
+
changed = true;
|
|
679
|
+
};
|
|
603
680
|
for (const field of DEPENDENCY_FIELDS) {
|
|
604
681
|
for (const packageId of Object.keys(next?.[field] || {})) {
|
|
605
682
|
if (!packageId.startsWith(JSKIT_SCOPE_PREFIX) || localPackageNames.has(packageId)) {
|
|
606
683
|
continue;
|
|
607
684
|
}
|
|
608
685
|
if (retiredPackageIds.includes(packageId)) {
|
|
609
|
-
|
|
610
|
-
changed = true;
|
|
686
|
+
set(field, packageId, undefined);
|
|
611
687
|
continue;
|
|
612
688
|
}
|
|
613
689
|
const expectedVersion = normalizedCatalog.versions.get(packageId);
|
|
614
690
|
if (next[field][packageId] !== expectedVersion) {
|
|
615
|
-
|
|
616
|
-
changed = true;
|
|
691
|
+
set(field, packageId, expectedVersion);
|
|
617
692
|
}
|
|
618
693
|
}
|
|
619
694
|
for (const [name, { version }] of singleCopies) {
|
|
620
695
|
if (Object.hasOwn(next?.[field] || {}, name) && next[field][name] !== version) {
|
|
621
|
-
|
|
622
|
-
changed = true;
|
|
696
|
+
set(field, name, version);
|
|
623
697
|
}
|
|
624
698
|
}
|
|
625
699
|
}
|
|
626
700
|
|
|
627
701
|
if (index === 0) {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (next
|
|
632
|
-
|
|
633
|
-
changed = true;
|
|
702
|
+
// The app's one JSKIT version: kept in whichever ordinary field the root declares it, else a development one.
|
|
703
|
+
const catalogField = CATALOG_FIELDS.find((field) => Object.hasOwn(next[field] || {}, CATALOG_PACKAGE_ID)) || "devDependencies";
|
|
704
|
+
next[catalogField] = next[catalogField] && typeof next[catalogField] === "object" ? next[catalogField] : {};
|
|
705
|
+
if (next[catalogField][CATALOG_PACKAGE_ID] !== catalogVersion) {
|
|
706
|
+
set(catalogField, CATALOG_PACKAGE_ID, catalogVersion);
|
|
634
707
|
}
|
|
635
708
|
next.scripts = next.scripts && typeof next.scripts === "object" ? next.scripts : {};
|
|
636
709
|
if (!next.scripts["jskit:update"]) {
|
|
637
710
|
next.scripts["jskit:update"] = UPDATE_SCRIPT;
|
|
711
|
+
changes.push("scripts.jskit:update added");
|
|
638
712
|
changed = true;
|
|
639
713
|
}
|
|
640
714
|
if (!next.scripts["jskit:check"]) {
|
|
641
715
|
next.scripts["jskit:check"] = CHECK_SCRIPT;
|
|
716
|
+
changes.push("scripts.jskit:check added");
|
|
642
717
|
changed = true;
|
|
643
718
|
}
|
|
644
719
|
if (approveInstallScripts(next, declaredPackageIds)) {
|
|
720
|
+
changes.push("allowScripts approves a JSKIT package's install script");
|
|
645
721
|
changed = true;
|
|
646
722
|
}
|
|
647
723
|
}
|
|
@@ -649,11 +725,38 @@ async function updateProject({
|
|
|
649
725
|
if (changed) {
|
|
650
726
|
updates.push(Object.freeze({
|
|
651
727
|
manifest,
|
|
652
|
-
contents: serializePackageJson(next, manifest.contents)
|
|
728
|
+
contents: serializePackageJson(next, manifest.contents),
|
|
729
|
+
changes: Object.freeze(changes)
|
|
653
730
|
}));
|
|
654
731
|
}
|
|
655
732
|
}
|
|
656
733
|
|
|
734
|
+
return Object.freeze({
|
|
735
|
+
root,
|
|
736
|
+
updates: Object.freeze(updates),
|
|
737
|
+
catalogVersion,
|
|
738
|
+
retiredPackageIds: Object.freeze(retiredPackageIds),
|
|
739
|
+
additionalManifests: Object.freeze(additionalManifests),
|
|
740
|
+
manifests: Object.freeze(manifests.map(({ absolutePath }) => absolutePath)),
|
|
741
|
+
redundantReleaseManifests: releaseManifests.redundant
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Pins a project's JSKIT dependencies to the catalog (planProjectUpdate) and installs them; a
|
|
747
|
+
* failed install or check restores the manifests, lockfile and node_modules.
|
|
748
|
+
* @param {object} options
|
|
749
|
+
* @param {typeof runNpmInstall} [options.installProject] installs the project and returns the transaction that commits or rolls back its node_modules
|
|
750
|
+
*/
|
|
751
|
+
async function updateProject({
|
|
752
|
+
projectRoot = process.cwd(),
|
|
753
|
+
catalog,
|
|
754
|
+
install = true,
|
|
755
|
+
installProject = runNpmInstall,
|
|
756
|
+
additionalManifests: givenManifests = []
|
|
757
|
+
} = {}) {
|
|
758
|
+
const plan = await planProjectUpdate({ projectRoot, catalog, additionalManifests: givenManifests });
|
|
759
|
+
const { root, updates, catalogVersion, retiredPackageIds, additionalManifests, redundantReleaseManifests: releaseManifests } = plan;
|
|
657
760
|
const packageLockPath = path.join(root, "package-lock.json");
|
|
658
761
|
const packageLockSnapshot = install ? await readOptionalFile(packageLockPath) : null;
|
|
659
762
|
// npm install replaces node_modules, so the migrations the packages shipped are read before it.
|
|
@@ -707,6 +810,7 @@ async function updateProject({
|
|
|
707
810
|
updates.map((update) => toPosixPath(path.relative(root, update.manifest.absolutePath)))
|
|
708
811
|
),
|
|
709
812
|
catalogVersion,
|
|
813
|
+
redundantReleaseManifests: releaseManifests,
|
|
710
814
|
addedMigrations: Object.freeze(migrationChanges.addedMigrations),
|
|
711
815
|
uncomparedPackages: Object.freeze(migrationChanges.uncomparedPackages),
|
|
712
816
|
retiredPackages: Object.freeze(retiredPackageIds.map((packageId) => Object.freeze({
|
|
@@ -721,11 +825,13 @@ export {
|
|
|
721
825
|
CHECK_SCRIPT,
|
|
722
826
|
DEPENDENCY_FIELDS,
|
|
723
827
|
UPDATE_SCRIPT,
|
|
828
|
+
appManifests,
|
|
724
829
|
checkProject,
|
|
725
830
|
checkInstalledGraph,
|
|
726
831
|
resolveInstalledPackage,
|
|
727
832
|
collectLockInstallations,
|
|
728
833
|
discoverProjectManifests,
|
|
729
834
|
normalizeCatalog,
|
|
835
|
+
planProjectUpdate,
|
|
730
836
|
updateProject
|
|
731
837
|
};
|