@jonmilner/ui 0.11.11 → 0.11.13
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 +358 -0
- package/dist/cli/ui-doctor.mjs +32 -0
- package/dist/docs/doctor.md +59 -0
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/manifest.json +3 -2
- package/dist/docs/manifest.schema.json +15 -1
- package/dist/docs/migrations/README.md +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,358 @@
|
|
|
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
|
+
var T = ["vite.config", "oxlint.config"].flatMap((e) => [
|
|
126
|
+
"ts",
|
|
127
|
+
"mts",
|
|
128
|
+
"cts",
|
|
129
|
+
"js",
|
|
130
|
+
"mjs",
|
|
131
|
+
"cjs"
|
|
132
|
+
].map((t) => `${e}.${t}`)), E = (e) => e.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1"), D = (e) => e.includes("@jonmilner/oxlint-config") && /\buiLint\b/.test(e);
|
|
133
|
+
function O(n) {
|
|
134
|
+
for (let r = n;; r = i(r)) {
|
|
135
|
+
let s = !1;
|
|
136
|
+
for (let e of T) {
|
|
137
|
+
let i = a(r, e), c;
|
|
138
|
+
try {
|
|
139
|
+
c = E(t(i, "utf8"));
|
|
140
|
+
} catch {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (D(c)) return o(n, i);
|
|
144
|
+
s ||= e.startsWith("oxlint.") || /\blint\b/.test(c);
|
|
145
|
+
}
|
|
146
|
+
if (s || ["pnpm-workspace.yaml", ".git"].some((t) => e(a(r, t))) || i(r) === r) return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function k(e) {
|
|
150
|
+
let t = v(a(e, "dist", "docs", "manifest.json"))?.deprecated;
|
|
151
|
+
return typeof t != "object" || !t || Array.isArray(t) ? null : new Map(Object.entries(t).filter((e) => typeof e[1] == "string"));
|
|
152
|
+
}
|
|
153
|
+
var A = /\.(?:[cm]?[jt]s|[jt]sx)$/, j = /* @__PURE__ */ new Set([
|
|
154
|
+
"dist",
|
|
155
|
+
"build",
|
|
156
|
+
"coverage",
|
|
157
|
+
"out"
|
|
158
|
+
]);
|
|
159
|
+
function* M(e, t = !0) {
|
|
160
|
+
let r;
|
|
161
|
+
try {
|
|
162
|
+
r = n(e, { withFileTypes: !0 });
|
|
163
|
+
} catch {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
for (let n of r.sort((e, t) => e.name.localeCompare(t.name, "en"))) {
|
|
167
|
+
if (n.name.startsWith(".") || n.name === "node_modules" || t && n.isDirectory() && j.has(n.name)) continue;
|
|
168
|
+
let r = a(e, n.name);
|
|
169
|
+
n.isDirectory() ? yield* M(r, !1) : n.isFile() && A.test(n.name) && !/\.d\.[cm]?ts$/.test(n.name) && (yield r);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var N = /\b(?:import|export)\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?(?:\*\s+as\s+([\w$]+)|\{([^}]*)\})\s*from\s*["']@jonmilner\/ui(?:\/[^"']*)?["']/g, P = (e) => e.replaceAll("$", "\\$");
|
|
173
|
+
function F(e, t) {
|
|
174
|
+
let n = /* @__PURE__ */ new Map(), r = (e, t) => n.set(e, [...n.get(e) ?? [], new RegExp(t)]);
|
|
175
|
+
for (let n of e.matchAll(N)) {
|
|
176
|
+
let [e, i, a] = n;
|
|
177
|
+
if (i) for (let e of t.keys()) r(e, `(?<![\\w$.])${P(i)}\\.${P(e)}(?![\\w$])`);
|
|
178
|
+
for (let n of a?.split(",") ?? []) {
|
|
179
|
+
let i = n.trim().replace(/^type\s+/, "").split(/\s+as\s+/), a = i[0];
|
|
180
|
+
a && t.has(a) && r(a, `(?<![\\w$.])${P(e.startsWith("export") ? a : i[1] ?? a)}(?![\\w$])`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return n;
|
|
184
|
+
}
|
|
185
|
+
function I(e, n) {
|
|
186
|
+
if (n.size === 0) return [];
|
|
187
|
+
let r = /* @__PURE__ */ new Map();
|
|
188
|
+
for (let i of M(e)) {
|
|
189
|
+
let a;
|
|
190
|
+
try {
|
|
191
|
+
a = t(i, "utf8");
|
|
192
|
+
} catch {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (!a.includes("@jonmilner/ui")) continue;
|
|
196
|
+
let s = F(a, n);
|
|
197
|
+
if (s.size === 0) continue;
|
|
198
|
+
let c = a.split("\n");
|
|
199
|
+
for (let [t, n] of s) {
|
|
200
|
+
let a = r.get(t) ?? [];
|
|
201
|
+
c.forEach((t, r) => {
|
|
202
|
+
n.some((e) => e.test(t)) && a.push({
|
|
203
|
+
path: o(e, i),
|
|
204
|
+
line: r + 1
|
|
205
|
+
});
|
|
206
|
+
}), r.set(t, a);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return [...r].filter(([, e]) => e.length > 0).sort(([e], [t]) => e.localeCompare(t, "en")).map(([e, t]) => ({
|
|
210
|
+
name: e,
|
|
211
|
+
message: n.get(e),
|
|
212
|
+
uses: t
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
function L(e) {
|
|
216
|
+
if (e instanceof Error) {
|
|
217
|
+
if (e.name === "TimeoutError") return "timed out";
|
|
218
|
+
let t = e.cause;
|
|
219
|
+
return typeof t?.code == "string" ? `${e.message} (${t.code})` : e.message;
|
|
220
|
+
}
|
|
221
|
+
return String(e);
|
|
222
|
+
}
|
|
223
|
+
async function R(t) {
|
|
224
|
+
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;
|
|
225
|
+
g || m.push({
|
|
226
|
+
code: "no-package-json",
|
|
227
|
+
message: `No readable package.json in ${n}.`
|
|
228
|
+
});
|
|
229
|
+
let T = g ? C(g) : null;
|
|
230
|
+
g && !T && p.push({
|
|
231
|
+
code: "not-declared",
|
|
232
|
+
message: `package.json does not list ${s} in ${u.join(", ")}.`
|
|
233
|
+
});
|
|
234
|
+
let E = y(n), D = E?.version ?? null;
|
|
235
|
+
D || p.push({
|
|
236
|
+
code: "not-installed",
|
|
237
|
+
message: `${s} is not installed; run the package manager's install.`
|
|
238
|
+
});
|
|
239
|
+
let A = null, j = [];
|
|
240
|
+
try {
|
|
241
|
+
({latest: A, published: j} = await w(r, i, o));
|
|
242
|
+
} catch (e) {
|
|
243
|
+
m.push({
|
|
244
|
+
code: "registry",
|
|
245
|
+
message: `Could not read the latest version from ${r}: ${L(e)}. Version lag not checked.`
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
let M = D && A ? _(D, A, j) : null;
|
|
249
|
+
if (M && M.breaking.length > 0) {
|
|
250
|
+
let e = M.breaking.length;
|
|
251
|
+
p.push({
|
|
252
|
+
code: "breaking-lag",
|
|
253
|
+
message: `${D} is ${e} breaking release${e === 1 ? "" : "s"} behind ${A}: ${M.breaking.join(", ")}. Upgrade, then apply each release's node_modules/${s}/dist/docs/migrations/<version>.md, oldest first.`
|
|
254
|
+
});
|
|
255
|
+
} else M && (M.minors > 0 || M.patches > 0) && m.push({
|
|
256
|
+
code: "minor-lag",
|
|
257
|
+
message: `${D} is behind ${A} by releases that break nothing; upgrading needs no migration.`
|
|
258
|
+
});
|
|
259
|
+
let N = g ? x(g)?.[d] : void 0, P = typeof N == "string" && f.test(N) ? N : null, F = T ? b(T.range) : null, R = P ?? F;
|
|
260
|
+
if (T && E && !P) {
|
|
261
|
+
let e = N === void 0 ? `package.json has no "${s}": { "${d}" } marker` : `package.json's "${s}".${d} is not a version: ${JSON.stringify(N)}`, t = F ? `migrations are listed from the declared ${T.range}` : "the declared range names no version, so migrations are not checked";
|
|
262
|
+
m.push({
|
|
263
|
+
code: "no-marker",
|
|
264
|
+
message: `${e}, so ${t}. Once the app has applied every migration up to ${E.version}, run \`ui-doctor migrated ${E.version}\`, before the next upgrade: an upgrade rewrites the declared range, and the migrations it skips are then listed only from the marker.`
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
let z = E && R ? S(n, E.dir, R, E.version) : null;
|
|
268
|
+
if (z && z.length > 0) {
|
|
269
|
+
let e = z.length, t = z[e - 1].version;
|
|
270
|
+
p.push({
|
|
271
|
+
code: "unapplied-migrations",
|
|
272
|
+
message: `${e} migration${e === 1 ? "" : "s"} above ${R} not applied: ${z.map((e) => e.version).join(", ")}. Apply each, oldest first, running \`ui-doctor migrated <version>\` after each (\`ui-doctor migrated ${t}\` after the last).`
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
let B = O(n);
|
|
276
|
+
B || m.push({
|
|
277
|
+
code: "no-lint-preset",
|
|
278
|
+
message: "No vite.config.* or oxlint.config.* from here to the workspace root enables the ui lint preset, which checks raw values, raw text and the rest: add `...uiLint()` from @jonmilner/oxlint-config next to `lint`."
|
|
279
|
+
});
|
|
280
|
+
let V = E ? k(E.dir) : null, H = V ? I(n, V) : null;
|
|
281
|
+
if (H && H.length > 0) {
|
|
282
|
+
let e = new Set(H.flatMap((e) => e.uses.map((e) => `${e.path}:${e.line}`))).size;
|
|
283
|
+
m.push({
|
|
284
|
+
code: "deprecated-api",
|
|
285
|
+
message: `${e === 1 ? "1 line uses" : `${e} lines use`} deprecated ${H.map((e) => e.name).join(", ")}. Move each to the replacement its message names before upgrading to the release that removes it.`
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
package: s,
|
|
290
|
+
installed: D,
|
|
291
|
+
declared: T,
|
|
292
|
+
latest: A,
|
|
293
|
+
behind: M,
|
|
294
|
+
migratedTo: P,
|
|
295
|
+
migrations: z,
|
|
296
|
+
lintPreset: B,
|
|
297
|
+
deprecated: H,
|
|
298
|
+
findings: p,
|
|
299
|
+
warnings: m
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
var z = class extends Error {
|
|
303
|
+
argument;
|
|
304
|
+
constructor(e, t = !1) {
|
|
305
|
+
super(e), this.argument = t;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
function B(e, n) {
|
|
309
|
+
let i = f.test(n) ? p(n) : null;
|
|
310
|
+
if (!i) throw new z(`${JSON.stringify(n)} is not a version (x.y.z).`, !0);
|
|
311
|
+
let o = y(e)?.version, c = o ? p(o) : null;
|
|
312
|
+
if (!c) throw new z(`${s} is not installed here: install it, then mark its migrations.`);
|
|
313
|
+
if (h(i, c) > 0) throw new z(`${n} is above the installed ${o}.`, !0);
|
|
314
|
+
let l = a(e, "package.json"), u;
|
|
315
|
+
try {
|
|
316
|
+
u = t(l, "utf8");
|
|
317
|
+
} catch {
|
|
318
|
+
throw new z(`No readable package.json in ${e}.`);
|
|
319
|
+
}
|
|
320
|
+
let m;
|
|
321
|
+
try {
|
|
322
|
+
m = JSON.parse(u);
|
|
323
|
+
} catch {
|
|
324
|
+
throw new z(`${l} is not valid JSON.`);
|
|
325
|
+
}
|
|
326
|
+
if (typeof m != "object" || !m || Array.isArray(m)) throw new z(`${l} is not a JSON object.`);
|
|
327
|
+
let g = m;
|
|
328
|
+
g[s] = {
|
|
329
|
+
...x(g),
|
|
330
|
+
[d]: n
|
|
331
|
+
};
|
|
332
|
+
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", _);
|
|
333
|
+
try {
|
|
334
|
+
r(l, b + (u.endsWith("\n") ? _ : ""));
|
|
335
|
+
} catch (e) {
|
|
336
|
+
throw new z(`Could not write ${l}: ${L(e)}.`);
|
|
337
|
+
}
|
|
338
|
+
return l;
|
|
339
|
+
}
|
|
340
|
+
function V(e) {
|
|
341
|
+
let t = [
|
|
342
|
+
`${e.package} doctor`,
|
|
343
|
+
` installed ${e.installed ?? "not installed"}`,
|
|
344
|
+
` declared ${e.declared ? `${e.declared.range} (${e.declared.field})` : "not declared"}`,
|
|
345
|
+
` latest ${e.latest ?? "unknown"}`
|
|
346
|
+
];
|
|
347
|
+
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"}`);
|
|
348
|
+
for (let n of e.migrations ?? []) t.push(` apply ${n.version} ${n.path}`);
|
|
349
|
+
t.push(` lint ${e.lintPreset ?? "no ui preset"}`);
|
|
350
|
+
for (let n of e.deprecated ?? []) {
|
|
351
|
+
t.push(` deprecated ${n.name}: ${n.message}`);
|
|
352
|
+
for (let e of n.uses) t.push(` ${e.path}:${e.line}`);
|
|
353
|
+
}
|
|
354
|
+
for (let n of e.warnings) t.push(`warning: ${n.message}`);
|
|
355
|
+
for (let n of e.findings) t.push(`error: ${n.message}`);
|
|
356
|
+
return e.findings.length === 0 && t.push("ok: no findings"), `${t.join("\n")}\n`;
|
|
357
|
+
}
|
|
358
|
+
export { c as DEFAULT_REGISTRY, d as MARKER, z as MarkError, s as PACKAGE, l as TIMEOUT_MS, I as deprecatedUses, R as diagnose, V as formatReport, _ as lag, O as lintPreset, B 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, which migration docs it has not applied, whether its lint config enables the ui preset, and where it uses deprecated exports.\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,59 @@
|
|
|
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, which migrations the app has not applied yet, whether its lint config enables the `ui` preset, and where it still uses deprecated exports.
|
|
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
|
+
## Lint preset
|
|
28
|
+
|
|
29
|
+
The doctor reads each `vite.config.*` and `oxlint.config.*` from the app's root up to the workspace root (the nearest directory with a `pnpm-workspace.yaml` or `.git`) and checks the nearest directory with a lint config (an `oxlint.config.*`, or a `vite.config.*` that names `lint`): any config there may enable the preset. It enables the preset when it imports `@jonmilner/oxlint-config` and names `uiLint` outside a comment. It matches the text and never runs the config, so a miss is a warning, not a finding. The preset, not the doctor, checks raw values, raw text and the rest of the house rules: run the linter for those.
|
|
30
|
+
|
|
31
|
+
## Deprecated exports
|
|
32
|
+
|
|
33
|
+
The installed package's `dist/docs/manifest.json` lists, under `deprecated`, each export marked `@deprecated`, with the tag's text: the replacement and the release that removes it. The doctor lists every line of the app's source (`.ts`, `.tsx`, `.js` and the rest, skipping `node_modules` and hidden directories, and `dist`, `build`, `coverage` and `out` at the app's root) that names one, through a named import (by its local name), a re-export, or a namespace import (`UI.Name`). It matches names, not types, so a shadowed local of the same name counts too. Any use is the warning `deprecated-api` (exit 0): 0126 deprecates only what an app cannot leave in one step, so it may not be able to move yet. Move each to its replacement before upgrading to the release that removes it; that release's migration doc is then a finding. A manifest from before the list skips the check (`deprecated` is `null`).
|
|
34
|
+
|
|
35
|
+
## Exit codes
|
|
36
|
+
|
|
37
|
+
- `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.
|
|
38
|
+
- `1`: a finding. The package is not installed, not declared, one or more breaking releases behind, or has migrations not yet applied.
|
|
39
|
+
- `2`: an unknown argument, or `migrated` without a valid version.
|
|
40
|
+
|
|
41
|
+
## Findings
|
|
42
|
+
|
|
43
|
+
- `breaking-lag`: upgrade, then apply each named release's [migration](migrations/README.md), oldest first.
|
|
44
|
+
- `unapplied-migrations`: apply each listed doc, oldest first, running `ui-doctor migrated <version>` after each.
|
|
45
|
+
- `not-installed`: run the package manager's install.
|
|
46
|
+
- `not-declared`: add `@jonmilner/ui` to `package.json`.
|
|
47
|
+
|
|
48
|
+
## Warnings
|
|
49
|
+
|
|
50
|
+
- `registry`: npm could not be read; the version lag is not checked.
|
|
51
|
+
- `minor-lag`: behind only by releases that break nothing.
|
|
52
|
+
- `no-marker`: `package.json` has no valid `migratedTo`; see [Applied migrations](#applied-migrations).
|
|
53
|
+
- `no-package-json`: run the doctor in the app's root.
|
|
54
|
+
- `no-lint-preset`: no lint config enables the `ui` preset; add `...uiLint()` from `@jonmilner/oxlint-config` next to `lint`. See [Lint preset](#lint-preset).
|
|
55
|
+
- `deprecated-api`: move each listed line to the replacement its message names; see [Deprecated exports](#deprecated-exports).
|
|
56
|
+
|
|
57
|
+
## JSON
|
|
58
|
+
|
|
59
|
+
`--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), `lintPreset` (the config's path from the app's root, `null` for none), `deprecated` (`[{ name, message, uses: [{ path, line }] }]`, by name), `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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./manifest.schema.json",
|
|
3
3
|
"package": "@jonmilner/ui",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.13",
|
|
5
5
|
"components": [
|
|
6
6
|
{
|
|
7
7
|
"name": "AlertDialog",
|
|
@@ -3879,5 +3879,6 @@
|
|
|
3879
3879
|
"fontTrim.label.baseline": "var(--font-trim-label-baseline)",
|
|
3880
3880
|
"fontTrim.mono.cap": "var(--font-trim-mono-cap)",
|
|
3881
3881
|
"fontTrim.mono.baseline": "var(--font-trim-mono-baseline)"
|
|
3882
|
-
}
|
|
3882
|
+
},
|
|
3883
|
+
"deprecated": {}
|
|
3883
3884
|
}
|
|
@@ -4,7 +4,16 @@
|
|
|
4
4
|
"title": "@jonmilner/ui manifest",
|
|
5
5
|
"description": "Every component, prop, variant, icon and token in @jonmilner/ui, generated from the TypeScript types by scripts/docs.ts.",
|
|
6
6
|
"type": "object",
|
|
7
|
-
"required": [
|
|
7
|
+
"required": [
|
|
8
|
+
"$schema",
|
|
9
|
+
"package",
|
|
10
|
+
"version",
|
|
11
|
+
"components",
|
|
12
|
+
"styleProps",
|
|
13
|
+
"icons",
|
|
14
|
+
"tokens",
|
|
15
|
+
"deprecated"
|
|
16
|
+
],
|
|
8
17
|
"additionalProperties": false,
|
|
9
18
|
"properties": {
|
|
10
19
|
"$schema": { "const": "./manifest.schema.json" },
|
|
@@ -32,6 +41,11 @@
|
|
|
32
41
|
"type": "object",
|
|
33
42
|
"minProperties": 1,
|
|
34
43
|
"additionalProperties": { "type": "string", "pattern": "^var\\(--[\\w-]+\\)$" }
|
|
44
|
+
},
|
|
45
|
+
"deprecated": {
|
|
46
|
+
"description": "Exports, from any entry point, marked `@deprecated` in their JSDoc, to the tag's text: the replacement and the release that removes them. Read by ui-doctor.",
|
|
47
|
+
"type": "object",
|
|
48
|
+
"additionalProperties": { "type": "string" }
|
|
35
49
|
}
|
|
36
50
|
},
|
|
37
51
|
"$defs": {
|
|
@@ -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
|
|