@jonmilner/ui 0.11.11 → 0.11.12
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/dist/cli/doctor.mjs +248 -0
- package/dist/cli/ui-doctor.mjs +32 -0
- package/dist/docs/doctor.md +49 -0
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/manifest.json +1 -1
- package/dist/docs/migrations/README.md +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { existsSync as e, readFileSync as t, readdirSync as n, writeFileSync as r } from "node:fs";
|
|
2
|
+
import { dirname as i, join as a, relative as o } from "node:path";
|
|
3
|
+
// src/cli/doctor.ts
|
|
4
|
+
var s = "@jonmilner/ui", c = "https://registry.npmjs.org/", l = 5e3, u = [
|
|
5
|
+
"dependencies",
|
|
6
|
+
"devDependencies",
|
|
7
|
+
"peerDependencies"
|
|
8
|
+
], d = "migratedTo", f = /^\d+\.\d+\.\d+$/;
|
|
9
|
+
function p(e) {
|
|
10
|
+
let t = /^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());
|
|
11
|
+
return t ? {
|
|
12
|
+
major: Number(t[1]),
|
|
13
|
+
minor: Number(t[2]),
|
|
14
|
+
patch: Number(t[3])
|
|
15
|
+
} : null;
|
|
16
|
+
}
|
|
17
|
+
function m(e) {
|
|
18
|
+
return `${e.major}.${e.minor}.${e.patch}`;
|
|
19
|
+
}
|
|
20
|
+
function h(e, t) {
|
|
21
|
+
return e.major - t.major || e.minor - t.minor || e.patch - t.patch;
|
|
22
|
+
}
|
|
23
|
+
function g(e) {
|
|
24
|
+
return e.major === 0 ? `0.${e.minor}` : `${e.major}`;
|
|
25
|
+
}
|
|
26
|
+
function _(e, t, n) {
|
|
27
|
+
let r = p(e), i = p(t);
|
|
28
|
+
if (!r || !i) return null;
|
|
29
|
+
if (h(r, i) >= 0) return {
|
|
30
|
+
majors: 0,
|
|
31
|
+
minors: 0,
|
|
32
|
+
patches: 0,
|
|
33
|
+
breaking: []
|
|
34
|
+
};
|
|
35
|
+
let a = /* @__PURE__ */ new Map();
|
|
36
|
+
for (let e of n) {
|
|
37
|
+
let t = e.includes("-") ? null : p(e);
|
|
38
|
+
if (!t || h(t, r) <= 0 || h(t, i) > 0) continue;
|
|
39
|
+
let n = g(t);
|
|
40
|
+
if (n === g(r)) continue;
|
|
41
|
+
let o = a.get(n);
|
|
42
|
+
(!o || h(t, o) < 0) && a.set(n, t);
|
|
43
|
+
}
|
|
44
|
+
let o = [...a.values()].sort(h).map(m), s = i.major - r.major, c = s === 0 ? i.minor - r.minor : 0;
|
|
45
|
+
return {
|
|
46
|
+
majors: s,
|
|
47
|
+
minors: c,
|
|
48
|
+
patches: s === 0 && c === 0 ? i.patch - r.patch : 0,
|
|
49
|
+
breaking: o
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function v(e) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(t(e, "utf8"));
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function y(e) {
|
|
60
|
+
for (let t = e;; t = i(t)) {
|
|
61
|
+
let e = a(t, "node_modules", s), n = v(a(e, "package.json"));
|
|
62
|
+
if (n && typeof n.version == "string") return {
|
|
63
|
+
dir: e,
|
|
64
|
+
version: n.version
|
|
65
|
+
};
|
|
66
|
+
if (i(t) === t) return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function b(e) {
|
|
70
|
+
let t = /^[^\d<]*(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(e.replace(/^workspace:/, ""));
|
|
71
|
+
return t ? m({
|
|
72
|
+
major: Number(t[1]),
|
|
73
|
+
minor: Number(t[2] ?? 0),
|
|
74
|
+
patch: Number(t[3] ?? 0)
|
|
75
|
+
}) : null;
|
|
76
|
+
}
|
|
77
|
+
function x(e) {
|
|
78
|
+
let t = e[s];
|
|
79
|
+
return typeof t == "object" && t && !Array.isArray(t) ? t : void 0;
|
|
80
|
+
}
|
|
81
|
+
function S(e, t, r, i) {
|
|
82
|
+
let s = p(r), c = p(i);
|
|
83
|
+
if (!s || !c) return [];
|
|
84
|
+
let l = a(t, "dist", "docs", "migrations"), u;
|
|
85
|
+
try {
|
|
86
|
+
u = n(l);
|
|
87
|
+
} catch {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return u.flatMap((e) => {
|
|
91
|
+
let t = e.slice(0, -3), n = e.endsWith(".md") && f.test(t) ? p(t) : null;
|
|
92
|
+
return n && h(n, s) > 0 && h(n, c) <= 0 ? [{
|
|
93
|
+
version: n,
|
|
94
|
+
file: e
|
|
95
|
+
}] : [];
|
|
96
|
+
}).sort((e, t) => h(e.version, t.version)).map(({ version: t, file: n }) => ({
|
|
97
|
+
version: m(t),
|
|
98
|
+
path: o(e, a(l, n))
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
function C(e) {
|
|
102
|
+
for (let t of u) {
|
|
103
|
+
let n = e[t]?.[s];
|
|
104
|
+
if (typeof n == "string") return {
|
|
105
|
+
range: n,
|
|
106
|
+
field: t
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
async function w(e, t, n) {
|
|
112
|
+
let r = new URL(s.replace("/", "%2f"), e.endsWith("/") ? e : `${e}/`), i = await n(r, {
|
|
113
|
+
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
114
|
+
signal: AbortSignal.timeout(t)
|
|
115
|
+
});
|
|
116
|
+
if (!i.ok) throw Error(`${r.href} answered ${i.status}`);
|
|
117
|
+
let a = await i.json(), o = a["dist-tags"]?.latest;
|
|
118
|
+
if (typeof o != "string") throw Error(`${r.href} has no latest dist-tag`);
|
|
119
|
+
if (typeof a.versions != "object" || a.versions === null) throw Error(`${r.href} lists no versions`);
|
|
120
|
+
return {
|
|
121
|
+
latest: o,
|
|
122
|
+
published: Object.keys(a.versions)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function T(e) {
|
|
126
|
+
if (e instanceof Error) {
|
|
127
|
+
if (e.name === "TimeoutError") return "timed out";
|
|
128
|
+
let t = e.cause;
|
|
129
|
+
return typeof t?.code == "string" ? `${e.message} (${t.code})` : e.message;
|
|
130
|
+
}
|
|
131
|
+
return String(e);
|
|
132
|
+
}
|
|
133
|
+
async function E(t) {
|
|
134
|
+
let { cwd: n, registry: r = c, timeoutMs: i = l, fetch: o = fetch } = t, p = [], m = [], h = a(n, "package.json"), g = e(h) ? v(h) : null;
|
|
135
|
+
g || m.push({
|
|
136
|
+
code: "no-package-json",
|
|
137
|
+
message: `No readable package.json in ${n}.`
|
|
138
|
+
});
|
|
139
|
+
let E = g ? C(g) : null;
|
|
140
|
+
g && !E && p.push({
|
|
141
|
+
code: "not-declared",
|
|
142
|
+
message: `package.json does not list ${s} in ${u.join(", ")}.`
|
|
143
|
+
});
|
|
144
|
+
let D = y(n), O = D?.version ?? null;
|
|
145
|
+
O || p.push({
|
|
146
|
+
code: "not-installed",
|
|
147
|
+
message: `${s} is not installed; run the package manager's install.`
|
|
148
|
+
});
|
|
149
|
+
let k = null, A = [];
|
|
150
|
+
try {
|
|
151
|
+
({latest: k, published: A} = await w(r, i, o));
|
|
152
|
+
} catch (e) {
|
|
153
|
+
m.push({
|
|
154
|
+
code: "registry",
|
|
155
|
+
message: `Could not read the latest version from ${r}: ${T(e)}. Version lag not checked.`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
let j = O && k ? _(O, k, A) : null;
|
|
159
|
+
if (j && j.breaking.length > 0) {
|
|
160
|
+
let e = j.breaking.length;
|
|
161
|
+
p.push({
|
|
162
|
+
code: "breaking-lag",
|
|
163
|
+
message: `${O} is ${e} breaking release${e === 1 ? "" : "s"} behind ${k}: ${j.breaking.join(", ")}. Upgrade, then apply each release's node_modules/${s}/dist/docs/migrations/<version>.md, oldest first.`
|
|
164
|
+
});
|
|
165
|
+
} else j && (j.minors > 0 || j.patches > 0) && m.push({
|
|
166
|
+
code: "minor-lag",
|
|
167
|
+
message: `${O} is behind ${k} by releases that break nothing; upgrading needs no migration.`
|
|
168
|
+
});
|
|
169
|
+
let M = g ? x(g)?.[d] : void 0, N = typeof M == "string" && f.test(M) ? M : null, P = E ? b(E.range) : null, F = N ?? P;
|
|
170
|
+
if (E && D && !N) {
|
|
171
|
+
let e = M === void 0 ? `package.json has no "${s}": { "${d}" } marker` : `package.json's "${s}".${d} is not a version: ${JSON.stringify(M)}`, t = P ? `migrations are listed from the declared ${E.range}` : "the declared range names no version, so migrations are not checked";
|
|
172
|
+
m.push({
|
|
173
|
+
code: "no-marker",
|
|
174
|
+
message: `${e}, so ${t}. Once the app has applied every migration up to ${D.version}, run \`ui-doctor migrated ${D.version}\`, before the next upgrade: an upgrade rewrites the declared range, and the migrations it skips are then listed only from the marker.`
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
let I = D && F ? S(n, D.dir, F, D.version) : null;
|
|
178
|
+
if (I && I.length > 0) {
|
|
179
|
+
let e = I.length, t = I[e - 1].version;
|
|
180
|
+
p.push({
|
|
181
|
+
code: "unapplied-migrations",
|
|
182
|
+
message: `${e} migration${e === 1 ? "" : "s"} above ${F} not applied: ${I.map((e) => e.version).join(", ")}. Apply each, oldest first, running \`ui-doctor migrated <version>\` after each (\`ui-doctor migrated ${t}\` after the last).`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
package: s,
|
|
187
|
+
installed: O,
|
|
188
|
+
declared: E,
|
|
189
|
+
latest: k,
|
|
190
|
+
behind: j,
|
|
191
|
+
migratedTo: N,
|
|
192
|
+
migrations: I,
|
|
193
|
+
findings: p,
|
|
194
|
+
warnings: m
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
var D = class extends Error {
|
|
198
|
+
argument;
|
|
199
|
+
constructor(e, t = !1) {
|
|
200
|
+
super(e), this.argument = t;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
function O(e, n) {
|
|
204
|
+
let i = f.test(n) ? p(n) : null;
|
|
205
|
+
if (!i) throw new D(`${JSON.stringify(n)} is not a version (x.y.z).`, !0);
|
|
206
|
+
let o = y(e)?.version, c = o ? p(o) : null;
|
|
207
|
+
if (!c) throw new D(`${s} is not installed here: install it, then mark its migrations.`);
|
|
208
|
+
if (h(i, c) > 0) throw new D(`${n} is above the installed ${o}.`, !0);
|
|
209
|
+
let l = a(e, "package.json"), u;
|
|
210
|
+
try {
|
|
211
|
+
u = t(l, "utf8");
|
|
212
|
+
} catch {
|
|
213
|
+
throw new D(`No readable package.json in ${e}.`);
|
|
214
|
+
}
|
|
215
|
+
let m;
|
|
216
|
+
try {
|
|
217
|
+
m = JSON.parse(u);
|
|
218
|
+
} catch {
|
|
219
|
+
throw new D(`${l} is not valid JSON.`);
|
|
220
|
+
}
|
|
221
|
+
if (typeof m != "object" || !m || Array.isArray(m)) throw new D(`${l} is not a JSON object.`);
|
|
222
|
+
let g = m;
|
|
223
|
+
g[s] = {
|
|
224
|
+
...x(g),
|
|
225
|
+
[d]: n
|
|
226
|
+
};
|
|
227
|
+
let _ = u.includes("\r\n") ? "\r\n" : "\n", v = /^[ \t]+(?=")/m.exec(u)?.[0] ?? (u.trim().includes("\n") ? 2 : 0), b = JSON.stringify(g, null, v).replaceAll("\n", _);
|
|
228
|
+
try {
|
|
229
|
+
r(l, b + (u.endsWith("\n") ? _ : ""));
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new D(`Could not write ${l}: ${T(e)}.`);
|
|
232
|
+
}
|
|
233
|
+
return l;
|
|
234
|
+
}
|
|
235
|
+
function k(e) {
|
|
236
|
+
let t = [
|
|
237
|
+
`${e.package} doctor`,
|
|
238
|
+
` installed ${e.installed ?? "not installed"}`,
|
|
239
|
+
` declared ${e.declared ? `${e.declared.range} (${e.declared.field})` : "not declared"}`,
|
|
240
|
+
` latest ${e.latest ?? "unknown"}`
|
|
241
|
+
];
|
|
242
|
+
e.behind && t.push(` behind ${e.behind.majors} major, ${e.behind.minors} minor, ${e.behind.patches} patch` + (e.behind.breaking.length > 0 ? `; breaking: ${e.behind.breaking.join(", ")}` : "")), t.push(` migrated ${e.migratedTo ?? "no valid marker"}`);
|
|
243
|
+
for (let n of e.migrations ?? []) t.push(` apply ${n.version} ${n.path}`);
|
|
244
|
+
for (let n of e.warnings) t.push(`warning: ${n.message}`);
|
|
245
|
+
for (let n of e.findings) t.push(`error: ${n.message}`);
|
|
246
|
+
return e.findings.length === 0 && t.push("ok: no findings"), `${t.join("\n")}\n`;
|
|
247
|
+
}
|
|
248
|
+
export { c as DEFAULT_REGISTRY, d as MARKER, D as MarkError, s as PACKAGE, l as TIMEOUT_MS, E as diagnose, k as formatReport, _ as lag, O as markMigrated, p as parseVersion, S as pendingMigrations, b as rangeFloor, w as registryVersions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { MARKER as e, MarkError as t, PACKAGE as n, diagnose as r, formatReport as i, markMigrated as a } from "./doctor.mjs";
|
|
3
|
+
// src/cli/ui-doctor.ts
|
|
4
|
+
var o = `Usage: ui-doctor [--json]
|
|
5
|
+
ui-doctor migrated <version>
|
|
6
|
+
Reports how far this app's ${n} lags npm's latest and which migration docs it has not applied.\n\`migrated <version>\` records, as package.json's "${n}".${e}, that the app has applied every migration up to <version>.\n`;
|
|
7
|
+
function s(e, t) {
|
|
8
|
+
process.stderr.write(`ui-doctor: ${e}\n${t === 2 ? o : ""}`), process.exitCode = t;
|
|
9
|
+
}
|
|
10
|
+
var c = process.argv.slice(2);
|
|
11
|
+
if (c[0] === "migrated") {
|
|
12
|
+
if (c.includes("--help") || c.includes("-h")) process.stdout.write(o);
|
|
13
|
+
else if (c.length !== 2) s("migrated takes one version, such as 0.10.0", 2);
|
|
14
|
+
else try {
|
|
15
|
+
let t = a(process.cwd(), c[1]);
|
|
16
|
+
process.stdout.write(`Recorded "${n}": { "${e}": "${c[1]}" } in ${t}.\n`);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (!(e instanceof t)) throw e;
|
|
19
|
+
s(e.message, e.argument ? 2 : 1);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
let e = c.filter((e) => e !== "--json" && e !== "--help" && e !== "-h");
|
|
23
|
+
if (e.length > 0) s(`unknown argument ${e.join(" ")}`, 2);
|
|
24
|
+
else if (c.includes("--help") || c.includes("-h")) process.stdout.write(o);
|
|
25
|
+
else {
|
|
26
|
+
let e = await r({
|
|
27
|
+
cwd: process.cwd(),
|
|
28
|
+
registry: process.env.npm_config_registry || void 0
|
|
29
|
+
});
|
|
30
|
+
process.stdout.write(c.includes("--json") ? `${JSON.stringify(e, null, 2)}\n` : i(e)), process.exitCode = +(e.findings.length > 0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Doctor
|
|
2
|
+
|
|
3
|
+
`ui-doctor` is a command the library installs in the app. Run it in the app's root to see how far its `@jonmilner/ui` lags npm's `latest`, which upgrades need a migration, and which migrations the app has not applied yet.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm exec ui-doctor
|
|
7
|
+
pnpm exec ui-doctor --json
|
|
8
|
+
pnpm exec ui-doctor migrated 0.10.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
It reports the installed version (the nearest `node_modules/@jonmilner/ui`), the range `package.json` declares, npm's `latest` (5 s timeout, from the registry the package manager is configured for), and the releases between, from the versions the registry lists. While 0.x every minor is breaking, from 1.0 every major; the doctor names the first published release of each, and each has a `migrations/<version>.md`.
|
|
12
|
+
|
|
13
|
+
## Applied migrations
|
|
14
|
+
|
|
15
|
+
The app records the last version whose migrations it has applied in its `package.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"@jonmilner/ui": { "migratedTo": "0.10.0" }
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The doctor lists every `migrations/<version>.md` the installed package ships above that marker and at most the installed version, oldest first, each with its path from the app's root (`node_modules/@jonmilner/ui/dist/docs/migrations/<version>.md`). Apply each in order and run `pnpm exec ui-doctor migrated <version>` after each, so a session that stops halfway leaves the marker on the last one applied. The command writes the marker, keeping the file's indentation, line endings and key order. It exits 2 for a version that is not `x.y.z` or is above the installed one, and 1 when the package is not installed or `package.json` is missing or not a JSON object.
|
|
24
|
+
|
|
25
|
+
With no marker, once the package is installed, the doctor warns and lists from the lowest version the declared range names (`>=0.8.0` gives 0.8.0). A package manager rewrites the range on upgrade, so under `^0.x` or `~0.x` that floor never sits below the installed line and nothing is listed: only the marker sees the releases an upgrade skipped. Set it before upgrading: an app at 0.8.4 runs `ui-doctor migrated 0.8.4`, as the warning says, then upgrades. A range that names no version (`*`, `workspace:*`, `<0.11.0`) lists nothing.
|
|
26
|
+
|
|
27
|
+
## Exit codes
|
|
28
|
+
|
|
29
|
+
- `0`: no findings. Warnings may still print: the registry was unreachable (the local checks still run), or the app trails `latest` only by releases that break nothing.
|
|
30
|
+
- `1`: a finding. The package is not installed, not declared, one or more breaking releases behind, or has migrations not yet applied.
|
|
31
|
+
- `2`: an unknown argument, or `migrated` without a valid version.
|
|
32
|
+
|
|
33
|
+
## Findings
|
|
34
|
+
|
|
35
|
+
- `breaking-lag`: upgrade, then apply each named release's [migration](migrations/README.md), oldest first.
|
|
36
|
+
- `unapplied-migrations`: apply each listed doc, oldest first, running `ui-doctor migrated <version>` after each.
|
|
37
|
+
- `not-installed`: run the package manager's install.
|
|
38
|
+
- `not-declared`: add `@jonmilner/ui` to `package.json`.
|
|
39
|
+
|
|
40
|
+
## Warnings
|
|
41
|
+
|
|
42
|
+
- `registry`: npm could not be read; the version lag is not checked.
|
|
43
|
+
- `minor-lag`: behind only by releases that break nothing.
|
|
44
|
+
- `no-marker`: `package.json` has no valid `migratedTo`; see [Applied migrations](#applied-migrations).
|
|
45
|
+
- `no-package-json`: run the doctor in the app's root.
|
|
46
|
+
|
|
47
|
+
## JSON
|
|
48
|
+
|
|
49
|
+
`--json` prints one object: `package`, `installed`, `declared` (`{ range, field }`), `latest`, `behind` (`{ majors, minors, patches, breaking }`, with `breaking` the versions whose migrations apply), `migratedTo` (the marker), `migrations` (`[{ version, path }]`, the docs not yet applied, oldest first), `findings` and `warnings` (each `{ code, message }`). Any value the doctor could not read is `null`. Branch on `code`, never on `message`.
|
package/dist/docs/llms.txt
CHANGED
|
@@ -48,4 +48,5 @@
|
|
|
48
48
|
- [manifest.json](manifest.json): every component, prop, variant, icon and token, as JSON
|
|
49
49
|
- [theming.md](theming.md): themes, brands and tokens
|
|
50
50
|
- [lint.md](lint.md): the `uiLint()` options the library ships
|
|
51
|
+
- [doctor.md](doctor.md): the `ui-doctor` command that reports how far the app lags the latest release and which migrations it has not applied
|
|
51
52
|
- [migrations/](migrations/README.md): upgrade notes for breaking releases
|
package/dist/docs/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
One file per breaking release, named for the version that introduces the break: `0.3.0.md`. While `@jonmilner/ui` is 0.x, every `minor` or `major` changeset is breaking and must ship its file (decision 0008). CI fails without it (`pnpm check:migrations`).
|
|
4
4
|
|
|
5
|
-
To upgrade, apply every file whose version is above the installed one and at most the target, oldest first.
|
|
5
|
+
To upgrade, apply every file whose version is above the installed one and at most the target, oldest first, and run `pnpm exec ui-doctor migrated <version>` after each. That records the version in the app's `package.json` as `"@jonmilner/ui": { "migratedTo": "<version>" }`, and `pnpm exec ui-doctor` lists every file above it that is not yet applied ([doctor.md](../doctor.md)). An app with no marker sets one at its installed version before upgrading.
|
|
6
6
|
|
|
7
7
|
## Template
|
|
8
8
|
|