zazz-ui 0.3.2 → 0.3.4
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/CHANGELOG.md +18 -0
- package/README.md +29 -2
- package/dist/add-P8X_avx2.js +3 -0
- package/dist/{add-Cvilkl7S.js → add-TSAcIuda.js} +9 -5
- package/dist/cli.js +10 -7
- package/dist/codemod-D_Qdyjbn.js +553 -0
- package/dist/{diff-BRTyzqhQ.js → diff-SlSZRLDi.js} +8 -7
- package/dist/{errors-DC2U2USS.js → errors--aALbpFB.js} +1 -2
- package/dist/{init-m26gsqEa.js → init-DarNiijO.js} +3 -4
- package/dist/init-DuvWuYCt.js +3 -0
- package/dist/update-C32jRa_O.js +3 -0
- package/dist/{update-CaIG25mx.js → update-CzvFHR7k.js} +151 -44
- package/dist/{wiring-CWDMdCmo.js → wiring-K8-qOImj.js} +37 -27
- package/package.json +3 -4
- package/dist/init-DqkIVXKV.js +0 -3
- package/dist/update-BPtPsPr7.js +0 -3
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { _ as resolveKit, c as createUi, g as kitSpec, h as loadFetchOptions, v as CONFIG_NAME, y as loadConfig } from "./wiring-K8-qOImj.js";
|
|
2
|
+
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
3
|
+
import { t as runAdd } from "./add-TSAcIuda.js";
|
|
4
|
+
import { r as runUpdate } from "./update-CzvFHR7k.js";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
// src/codemods/data-font.ts
|
|
10
|
+
/**
|
|
11
|
+
* @fileoverview The `data-font` codemod's source transform.
|
|
12
|
+
* @description Typography roles left `data-ui`: `data-ui="text-sm"` is
|
|
13
|
+
* `data-font="sm"`, and `data-ui="text-link"` is the `link` identity. This
|
|
14
|
+
* rewrites the attribute where it is written out in quotes with plain tokens
|
|
15
|
+
* (in any markup, template, or string) and the quoted attribute selectors that
|
|
16
|
+
* match it. Anything it cannot move safely it leaves as written and lists: two
|
|
17
|
+
* roles on one element, a value with template syntax, an element that already
|
|
18
|
+
* has `data-font`, a role set from script, and an unquoted selector. Pure text
|
|
19
|
+
* in, text out; the command (`commands/codemod.ts`) owns the files.
|
|
20
|
+
*/
|
|
21
|
+
/** The roles that were `text-<role>` tokens; `text-link` is handled apart. */
|
|
22
|
+
const ROLES = [
|
|
23
|
+
"display",
|
|
24
|
+
"h1",
|
|
25
|
+
"h2",
|
|
26
|
+
"h3",
|
|
27
|
+
"h4",
|
|
28
|
+
"h5",
|
|
29
|
+
"h6",
|
|
30
|
+
"2xl",
|
|
31
|
+
"xl",
|
|
32
|
+
"lg",
|
|
33
|
+
"md",
|
|
34
|
+
"sm",
|
|
35
|
+
"xs",
|
|
36
|
+
"2xs",
|
|
37
|
+
"eyebrow"
|
|
38
|
+
];
|
|
39
|
+
const ROLE = ROLES.join("|");
|
|
40
|
+
const RETIRED = `text-(?:${ROLE}|link)`;
|
|
41
|
+
const ROLE_TOKEN = new RegExp(`^text-(${ROLE})$`);
|
|
42
|
+
/** A token the codemod may move: a plain word, no template syntax. */
|
|
43
|
+
const PLAIN = /^[\w-]+$/;
|
|
44
|
+
/** `data-ui="…"` in plain, single, or backslash-escaped quotes; not `x-data-ui` or `:data-ui`. */
|
|
45
|
+
const ATTRIBUTE$1 = /(?<![\w:.@-])data-ui=(\\?["'])([^"'\\]*)\1/g;
|
|
46
|
+
/** `[data-ui~="text-sm"]`, with `=` or `~=`, in quotes. A bare value may sit inside a quoted string, so it is left. */
|
|
47
|
+
const SELECTOR = new RegExp(`\\[data-ui~?=(\\\\?["'])text-(${ROLE}|link)\\1\\]`, "g");
|
|
48
|
+
/**
|
|
49
|
+
* Where a retired token is still set through `data-ui` after the rewrite: a
|
|
50
|
+
* quoted value (any content), a `{…}` expression, `setAttribute("data-ui", …)`,
|
|
51
|
+
* `dataset.ui = …`, and an attribute selector. Text that only mentions a token
|
|
52
|
+
* is not one of these.
|
|
53
|
+
*/
|
|
54
|
+
const LEFTOVERS$1 = [
|
|
55
|
+
new RegExp(`(?<![\\w:.@-]|data-ui)[:@]?data-ui=(\\\\?["'])(?:(?!\\1)[\\s\\S]){0,400}?\\b${RETIRED}\\b`, "g"),
|
|
56
|
+
new RegExp(`(?<![\\w.@-])data-ui=\\{(?:(?!\\n\\s*[\\w:@.-]+=)[\\s\\S]){0,400}?\\b${RETIRED}\\b`, "g"),
|
|
57
|
+
new RegExp(`["'\`]data-ui["'\`]\\s*,[^\\n]{0,120}?\\b${RETIRED}\\b`, "g"),
|
|
58
|
+
new RegExp(`\\bdataset\\.ui\\b[^\\n]{0,120}?\\b${RETIRED}\\b`, "g"),
|
|
59
|
+
new RegExp(`\\[data-ui[~|^$*]?=[^\\]\\n]{0,80}?\\b${RETIRED}\\b`, "g")
|
|
60
|
+
];
|
|
61
|
+
/** True when the tag around `[start, end)` already carries a `data-font`. */
|
|
62
|
+
function tagHasFont(source, start, end) {
|
|
63
|
+
const open = source.lastIndexOf("<", start);
|
|
64
|
+
const close = source.indexOf(">", end);
|
|
65
|
+
const tag = source.slice(Math.max(open, start - 2e3), close === -1 ? end + 2e3 : close);
|
|
66
|
+
return /(?<![\w:.@-])data-font=/.test(tag);
|
|
67
|
+
}
|
|
68
|
+
function rewriteDataFont(source) {
|
|
69
|
+
let count = 0;
|
|
70
|
+
const output = source.replace(ATTRIBUTE$1, (whole, quote, value, offset) => {
|
|
71
|
+
const tokens = value.split(/\s+/).filter(Boolean);
|
|
72
|
+
const roles = tokens.flatMap((token) => ROLE_TOKEN.exec(token)?.[1] ?? []);
|
|
73
|
+
const link = tokens.includes("text-link");
|
|
74
|
+
if (!roles.length && !link) return whole;
|
|
75
|
+
if (roles.length > 1 || !tokens.every((token) => PLAIN.test(token))) return whole;
|
|
76
|
+
if (roles.length && tagHasFont(source, offset, offset + whole.length)) return whole;
|
|
77
|
+
const rest = tokens.filter((token) => !ROLE_TOKEN.test(token)).map((token) => token === "text-link" ? "link" : token);
|
|
78
|
+
count += 1;
|
|
79
|
+
return [...rest.length ? [`data-ui=${quote}${rest.join(" ")}${quote}`] : [], ...roles.length ? [`data-font=${quote}${roles[0]}${quote}`] : []].join(" ");
|
|
80
|
+
}).replace(SELECTOR, (_whole, quote, role) => {
|
|
81
|
+
count += 1;
|
|
82
|
+
return role === "link" ? `[data-ui~=${quote}link${quote}]` : `[data-font=${quote}${role}${quote}]`;
|
|
83
|
+
});
|
|
84
|
+
const lines = output.split("\n");
|
|
85
|
+
const flagged = /* @__PURE__ */ new Set();
|
|
86
|
+
for (const pattern of LEFTOVERS$1) for (const match of output.matchAll(pattern)) flagged.add(output.slice(0, match.index).split("\n").length);
|
|
87
|
+
const review = [...flagged].sort((a, b) => a - b).map((line) => ({
|
|
88
|
+
line,
|
|
89
|
+
text: lines[line - 1].trim()
|
|
90
|
+
}));
|
|
91
|
+
return {
|
|
92
|
+
output,
|
|
93
|
+
count,
|
|
94
|
+
review
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** The primitives markup needs loaded for its roles, links, and prose, in a stable order. */
|
|
98
|
+
function primitivesUsed(source) {
|
|
99
|
+
const identities = new Set([...source.matchAll(ATTRIBUTE$1)].flatMap((match) => match[2].split(/\s+/)));
|
|
100
|
+
return [
|
|
101
|
+
.../(?<![\w:.@-])data-font=/.test(source) ? ["font"] : [],
|
|
102
|
+
...identities.has("link") ? ["link"] : [],
|
|
103
|
+
...identities.has("prose") ? ["prose"] : []
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/codemods/small-sizes.ts
|
|
108
|
+
/**
|
|
109
|
+
* A written-out attribute with exactly `sm` or `icon-sm`: in plain, single, or
|
|
110
|
+
* backslash-escaped quotes or unquoted, with or without spaces around `=`, in
|
|
111
|
+
* any case. The leading whitespace is captured so a removed attribute takes its
|
|
112
|
+
* separator (or its own line) with it. `:data-…` and `x-data-…` are not
|
|
113
|
+
* matched: they are bindings, not values.
|
|
114
|
+
*/
|
|
115
|
+
const ATTRIBUTE = /(\s+)(data-(?:button|toggle)-size)\s*=\s*(?:(\\?["'])(sm|icon-sm)\3|(sm|icon-sm)(?=[\s/>]))/gi;
|
|
116
|
+
const SMALL = String.raw`(?:icon-sm|sm)`;
|
|
117
|
+
const QUOTED_SMALL = String.raw`["'\x60]${SMALL}["'\x60]`;
|
|
118
|
+
/** Places that still set a small size after the rewrite, each matched per line. */
|
|
119
|
+
const LEFTOVERS = [
|
|
120
|
+
new RegExp(String.raw`\[data-(?:button|toggle)-size\s*[~|^$*]?=[^\]\n]{0,40}?\b${SMALL}\b`, "gi"),
|
|
121
|
+
new RegExp(String.raw`\bdataset\.(?:button|toggle)Size\b[^\n]{0,80}?${QUOTED_SMALL}`, "g"),
|
|
122
|
+
new RegExp(String.raw`["'\x60]data-(?:button|toggle)-size["'\x60]\s*[,:][^\n]{0,80}?${QUOTED_SMALL}`, "gi"),
|
|
123
|
+
new RegExp(String.raw`[:@]?data-(?:button|toggle)-size\s*=\s*\{[^\n]{0,200}?${QUOTED_SMALL}`, "gi"),
|
|
124
|
+
new RegExp(String.raw`[:@]?data-(?:button|toggle)-size\s*=\s*(\\?["'])(?:(?!\1)[^\n]){0,200}?\b${SMALL}\b(?:(?!\1)[^\n]){0,200}?\1`, "gi")
|
|
125
|
+
];
|
|
126
|
+
/** Drops `"sm"` and turns `"icon-sm"` into `"icon"` on buttons and toggles; lists what it can't rewrite. */
|
|
127
|
+
function removeSmallSizes(source) {
|
|
128
|
+
let count = 0;
|
|
129
|
+
const output = source.replace(ATTRIBUTE, (_match, space, name, quote, quoted, bare) => {
|
|
130
|
+
count++;
|
|
131
|
+
const size = (quoted ?? bare).toLowerCase();
|
|
132
|
+
const q = quote ?? "\"";
|
|
133
|
+
return size === "sm" ? "" : `${space}${name}=${q}icon${q}`;
|
|
134
|
+
});
|
|
135
|
+
const seen = /* @__PURE__ */ new Set();
|
|
136
|
+
const review = [];
|
|
137
|
+
for (const pattern of LEFTOVERS) for (const match of output.matchAll(pattern)) {
|
|
138
|
+
const line = output.slice(0, match.index).split("\n").length;
|
|
139
|
+
if (seen.has(line)) continue;
|
|
140
|
+
seen.add(line);
|
|
141
|
+
review.push({
|
|
142
|
+
line,
|
|
143
|
+
text: output.split("\n")[line - 1].trim()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
review.sort((a, b) => a.line - b.line);
|
|
147
|
+
return {
|
|
148
|
+
output,
|
|
149
|
+
count,
|
|
150
|
+
review
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const MARKER = "Added by `zazz-ui codemod small-sizes`";
|
|
154
|
+
/**
|
|
155
|
+
* True when a stylesheet already has the rules this codemod adds, so they are
|
|
156
|
+
* not added twice. It looks for the codemod's own header, not the selectors: a
|
|
157
|
+
* vendored kit from before the removal still ships its own copy, which the
|
|
158
|
+
* next `update` deletes, so that copy must not count.
|
|
159
|
+
*/
|
|
160
|
+
function hasRestoredSmallSizes(css, primitive) {
|
|
161
|
+
return primitive ? css.includes(`${MARKER}: the small ${primitive} sizes`) : css.includes(MARKER);
|
|
162
|
+
}
|
|
163
|
+
const HEADER = (primitive) => `/* ${MARKER}: the small ${primitive} sizes the kit removed
|
|
164
|
+
(data-${primitive}-size="sm" and "icon-sm"), kept for this project. */`;
|
|
165
|
+
const BUTTON_RULES = String.raw` :where([data-ui~="button"][data-button-size="sm"]) {
|
|
166
|
+
--_button-min-h: calc(var(--spacing) * 6);
|
|
167
|
+
/* a 16px icon, this, and the border fit the 24px box */
|
|
168
|
+
--_button-py: calc(var(--spacing) * 0.75);
|
|
169
|
+
--_button-px: calc(var(--spacing) * 2);
|
|
170
|
+
--_button-radius: var(--radius-sm);
|
|
171
|
+
--_button-font-size: var(--font-size-xs);
|
|
172
|
+
/* dense by choice: the box stays small and ::after takes the touch floor */
|
|
173
|
+
--_touch-floor: 0px;
|
|
174
|
+
position: relative;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
:where(
|
|
178
|
+
:is(ui-button-group, [data-ui~="button-group"]):has([data-ui~="button"][data-button-size="sm"])
|
|
179
|
+
) {
|
|
180
|
+
--ui-button-group-radius: var(--radius-sm);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
:where([data-ui~="button"][data-button-size="icon-sm"]) {
|
|
184
|
+
--_button-min-h: calc(var(--spacing) * 6);
|
|
185
|
+
--_button-px: calc(var(--spacing) * 2);
|
|
186
|
+
--_button-radius: var(--radius-sm);
|
|
187
|
+
/* the hook, not a private: it must inherit to reach the icon */
|
|
188
|
+
--ui-button-icon-size: calc(var(--spacing) * 3.5);
|
|
189
|
+
--_touch-floor: 0px;
|
|
190
|
+
position: relative;
|
|
191
|
+
|
|
192
|
+
block-size: calc(var(--_min-h-len) + var(--_min-h-num) * var(--spacing));
|
|
193
|
+
inline-size: calc(var(--_min-h-len) + var(--_min-h-num) * var(--spacing));
|
|
194
|
+
padding: 0;
|
|
195
|
+
aspect-ratio: 1 / 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* touch: sm and icon-sm keep their box; a transparent ::after centred on the button
|
|
199
|
+
is at least --_touch-min square (it collapses to the box on a mouse) */
|
|
200
|
+
:where([data-ui~="button"]:is([data-button-size="sm"], [data-button-size="icon-sm"]))::after {
|
|
201
|
+
content: "";
|
|
202
|
+
position: absolute;
|
|
203
|
+
inset: min(0px, calc((100% - var(--_touch-min)) / 2));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
:where([data-ui~="button"][data-button-size="sm"]):has(
|
|
207
|
+
> :where(kbd, ui-kbd-group, [data-ui~="kbd-group"]):last-child:not(:only-child)
|
|
208
|
+
) {
|
|
209
|
+
padding-inline-end: calc(var(--spacing) * 0.5 + var(--_touch-px));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
:where([data-ui~="button"][data-button-size="sm"]):has(
|
|
213
|
+
> :where(kbd, ui-kbd-group, [data-ui~="kbd-group"]):first-child:not(:only-child)
|
|
214
|
+
) {
|
|
215
|
+
padding-inline-start: calc(var(--spacing) * 0.5 + var(--_touch-px));
|
|
216
|
+
}`;
|
|
217
|
+
const TOGGLE_RULES = String.raw` :where([data-ui~="toggle"][data-toggle-size="sm"]) {
|
|
218
|
+
--_toggle-min-h: calc(var(--spacing) * 6);
|
|
219
|
+
/* a 16px icon, this, and the border fit the 24px box */
|
|
220
|
+
--_toggle-py: calc(var(--spacing) * 0.75);
|
|
221
|
+
--_toggle-px: calc(var(--spacing) * 2);
|
|
222
|
+
--_toggle-radius: var(--radius-sm);
|
|
223
|
+
--_toggle-font-size: var(--font-size-xs);
|
|
224
|
+
/* dense by choice: the box stays small and ::after takes the touch floor */
|
|
225
|
+
--_touch-floor: 0px;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
:where([data-ui~="toggle"][data-toggle-size="icon-sm"]) {
|
|
229
|
+
--_toggle-min-h: calc(var(--spacing) * 6);
|
|
230
|
+
--_toggle-px: calc(var(--spacing) * 2);
|
|
231
|
+
--_toggle-radius: var(--radius-sm);
|
|
232
|
+
/* the hook, not a private: it must inherit to reach the icon */
|
|
233
|
+
--ui-toggle-icon-size: calc(var(--spacing) * 3.5);
|
|
234
|
+
--_touch-floor: 0px;
|
|
235
|
+
|
|
236
|
+
block-size: calc(var(--_min-h-len) + var(--_min-h-num) * var(--spacing));
|
|
237
|
+
inline-size: calc(var(--_min-h-len) + var(--_min-h-num) * var(--spacing));
|
|
238
|
+
padding: 0;
|
|
239
|
+
aspect-ratio: 1 / 1;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* touch: sm and icon-sm keep their box; a transparent ::after centred on the toggle
|
|
243
|
+
(already position: relative) is at least --_touch-min square */
|
|
244
|
+
:where([data-ui~="toggle"]:is([data-toggle-size="sm"], [data-toggle-size="icon-sm"]))::after {
|
|
245
|
+
content: "";
|
|
246
|
+
position: absolute;
|
|
247
|
+
inset: min(0px, calc((100% - var(--_touch-min)) / 2));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
:where([data-ui~="toggle"][data-toggle-size="sm"]):has(
|
|
251
|
+
> :where(kbd, ui-kbd-group, [data-ui~="kbd-group"]):nth-last-child(1 of :not(input)):not(
|
|
252
|
+
:nth-child(1 of :not(input))
|
|
253
|
+
)
|
|
254
|
+
) {
|
|
255
|
+
padding-inline-end: calc(var(--spacing) * 0.5 + var(--_touch-px));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
:where([data-ui~="toggle"][data-toggle-size="sm"]):has(
|
|
259
|
+
> :where(kbd, ui-kbd-group, [data-ui~="kbd-group"]):nth-child(1 of :not(input)):not(
|
|
260
|
+
:nth-last-child(1 of :not(input))
|
|
261
|
+
)
|
|
262
|
+
) {
|
|
263
|
+
padding-inline-start: calc(var(--spacing) * 0.5 + var(--_touch-px));
|
|
264
|
+
}`;
|
|
265
|
+
/** The removed rules for one primitive, in the layer the kit's own presets use. */
|
|
266
|
+
function smallSizesCss(primitive) {
|
|
267
|
+
const rules = primitive === "button" ? BUTTON_RULES : TOGGLE_RULES;
|
|
268
|
+
return `${HEADER(primitive)}\n@layer ui.components {\n${rules}\n}\n`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/commands/codemod.ts
|
|
272
|
+
/**
|
|
273
|
+
* @fileoverview `zazz-ui codemod` — rewrite a project's markup for a breaking
|
|
274
|
+
* kit change.
|
|
275
|
+
* @description Two codemods. `small-sizes`: the kit removed the small control
|
|
276
|
+
* sizes (`data-button-size` and `data-toggle-size` lost `"sm"` and
|
|
277
|
+
* `"icon-sm"`); it asks whether to remove them from the markup (the default)
|
|
278
|
+
* or keep them by adding their rules back (`runSmallSizes` below).
|
|
279
|
+
* `data-font`: typography roles left `data-ui`
|
|
280
|
+
* for `data-font`, and `text-link` became the `link` identity. In a vendored
|
|
281
|
+
* project it first moves the kit forward when the recorded version predates
|
|
282
|
+
* the change (`update`, to latest or to an `@version` argument; that brings the
|
|
283
|
+
* new `_variables.css` and `_typography.css`), vendors the primitives the
|
|
284
|
+
* markup now needs (`add`: font, link, prose), then rewrites the source files.
|
|
285
|
+
* A project that loads the kit from npm or a CDN gets the rewrite alone. It
|
|
286
|
+
* never touches a vendored kit directory. The transform is
|
|
287
|
+
* `codemods/data-font.ts`.
|
|
288
|
+
*/
|
|
289
|
+
const CODEMODS = {
|
|
290
|
+
"data-font": "data-ui=\"text-sm\" → data-font=\"sm\"; data-ui=\"text-link\" → data-ui=\"link\"",
|
|
291
|
+
"small-sizes": "removes data-button-size / data-toggle-size \"sm\" (\"icon-sm\" → \"icon\"), or keeps them with --restore"
|
|
292
|
+
};
|
|
293
|
+
/** The stylesheet a project without zazz.json gets when it keeps the small sizes. */
|
|
294
|
+
const SMALL_SIZES_FILE = "zazz-small-sizes.css";
|
|
295
|
+
/**
|
|
296
|
+
* Markup, templates, scripts, and stylesheets: anywhere the attribute or its
|
|
297
|
+
* selector is written. Plain Markdown is left out (a changelog that names the
|
|
298
|
+
* old token is history, not markup); name a file to rewrite it anyway.
|
|
299
|
+
*/
|
|
300
|
+
const EXTENSIONS = new Set("html htm xhtml astro vue svelte marko webc jsx tsx js mjs cjs ts mts cts mdx json css scss sass less styl pcss erb haml slim php twig latte tpl njk jinja j2 liquid hbs handlebars mustache ejs pug cshtml vbhtml razor aspx asp jsp heex eex leex ex exs templ rb py cs go".split(" "));
|
|
301
|
+
/** Dependencies and build output, at any depth; dot-directories are skipped too. */
|
|
302
|
+
const SKIPPED_DIRS = /* @__PURE__ */ new Set([
|
|
303
|
+
"node_modules",
|
|
304
|
+
"bower_components",
|
|
305
|
+
"dist",
|
|
306
|
+
"build",
|
|
307
|
+
"out",
|
|
308
|
+
"coverage",
|
|
309
|
+
"target",
|
|
310
|
+
"bin",
|
|
311
|
+
"obj",
|
|
312
|
+
"deps",
|
|
313
|
+
"_build",
|
|
314
|
+
"_site",
|
|
315
|
+
"storybook-static"
|
|
316
|
+
]);
|
|
317
|
+
/** Skipped only at the top of the scan: Composer's and Bundler's `vendor`, and `tmp`. Deeper ones are authored (`resources/views/vendor`). */
|
|
318
|
+
const SKIPPED_AT_ROOT = /* @__PURE__ */ new Set(["vendor", "tmp"]);
|
|
319
|
+
/** Larger files are generated or bundled, not authored. */
|
|
320
|
+
const MAX_BYTES = 2e6;
|
|
321
|
+
const MINIFIED = /\.min\.[a-z]+$/i;
|
|
322
|
+
const within = (file, dir) => file === dir || file.startsWith(dir + path.sep);
|
|
323
|
+
/**
|
|
324
|
+
* Every source file under `start` (a file or a directory). A directory holding
|
|
325
|
+
* a `zazz.json` adds its kit directory to `kits`, which the caller filters out:
|
|
326
|
+
* the kit's own stylesheets are `update`'s to change, never the codemod's.
|
|
327
|
+
*/
|
|
328
|
+
async function sourceFiles(start, kits) {
|
|
329
|
+
const info = await stat(start).catch(() => null);
|
|
330
|
+
if (!info) throw new ZazzError(`no such file or directory: ${start}`);
|
|
331
|
+
if (info.isFile()) return [start];
|
|
332
|
+
const found = [];
|
|
333
|
+
const walk = async (dir, top) => {
|
|
334
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
335
|
+
if (entries.some((entry) => entry.isFile() && entry.name === "zazz.json")) {
|
|
336
|
+
const nested = await loadConfig(dir).catch(() => null);
|
|
337
|
+
if (nested) kits.add(path.resolve(nested.root, nested.config.dir));
|
|
338
|
+
}
|
|
339
|
+
for (const entry of entries) {
|
|
340
|
+
const full = path.join(dir, entry.name);
|
|
341
|
+
if (entry.isDirectory()) {
|
|
342
|
+
if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
343
|
+
if (top && SKIPPED_AT_ROOT.has(entry.name)) continue;
|
|
344
|
+
await walk(full, false);
|
|
345
|
+
} else if (entry.isFile() && EXTENSIONS.has(path.extname(entry.name).slice(1).toLowerCase()) && !MINIFIED.test(entry.name)) found.push(full);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
await walk(start, true);
|
|
349
|
+
return found.sort();
|
|
350
|
+
}
|
|
351
|
+
async function runCodemod(name, args, flags, global) {
|
|
352
|
+
if (!CODEMODS[name]) throw new ZazzError(`unknown codemod "${name}"`, { hint: `available: ${Object.keys(CODEMODS).join(", ")}` });
|
|
353
|
+
if (name === "small-sizes") return runSmallSizes(args, flags, global);
|
|
354
|
+
const cwd = path.resolve(global.cwd);
|
|
355
|
+
const ui = createUi({
|
|
356
|
+
silent: global.silent === true,
|
|
357
|
+
yes: global.yes === true
|
|
358
|
+
});
|
|
359
|
+
const dryRun = flags.dryRun === true;
|
|
360
|
+
const isVersion = (arg) => arg.startsWith("@") && !existsSync(path.resolve(cwd, arg));
|
|
361
|
+
const target = args.filter(isVersion);
|
|
362
|
+
const paths = args.filter((arg) => !isVersion(arg));
|
|
363
|
+
const loaded = await loadConfig(cwd);
|
|
364
|
+
const root = loaded?.root ?? cwd;
|
|
365
|
+
ui.intro(`zazz-ui codemod ${name}`);
|
|
366
|
+
const kits = new Set(loaded ? [path.resolve(root, loaded.config.dir)] : []);
|
|
367
|
+
const starts = paths.length ? paths.map((given) => path.resolve(cwd, given)) : [root];
|
|
368
|
+
const walked = (await Promise.all(starts.map((start) => sourceFiles(start, kits)))).flat();
|
|
369
|
+
const files = [...new Set(walked)].filter((file) => ![...kits].some((kit) => within(file, kit)));
|
|
370
|
+
const changed = [];
|
|
371
|
+
const review = [];
|
|
372
|
+
const unread = [];
|
|
373
|
+
const used = /* @__PURE__ */ new Set();
|
|
374
|
+
for (const file of files) {
|
|
375
|
+
const bytes = await readFile(file);
|
|
376
|
+
const source = bytes.toString("utf8");
|
|
377
|
+
if (bytes.length > MAX_BYTES || !Buffer.from(source, "utf8").equals(bytes)) {
|
|
378
|
+
if (/data-ui/.test(bytes.toString("latin1"))) unread.push(file);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const result = rewriteDataFont(source);
|
|
382
|
+
if (result.output !== source) changed.push({
|
|
383
|
+
file,
|
|
384
|
+
...result
|
|
385
|
+
});
|
|
386
|
+
for (const item of result.review) review.push({
|
|
387
|
+
file,
|
|
388
|
+
...item
|
|
389
|
+
});
|
|
390
|
+
for (const primitive of primitivesUsed(result.output)) used.add(primitive);
|
|
391
|
+
}
|
|
392
|
+
const total = changed.reduce((sum, { count }) => sum + count, 0);
|
|
393
|
+
const relative = (file) => path.relative(root, file) || path.basename(file);
|
|
394
|
+
if (loaded) {
|
|
395
|
+
const fetch = await loadFetchOptions({
|
|
396
|
+
cwd,
|
|
397
|
+
registry: global.registry,
|
|
398
|
+
offline: global.offline,
|
|
399
|
+
preferOffline: global.preferOffline
|
|
400
|
+
});
|
|
401
|
+
let { config } = loaded;
|
|
402
|
+
let kit = await resolveKit(kitSpec(config.kit.version), fetch);
|
|
403
|
+
if (!kit.manifest.primitives["font"]) {
|
|
404
|
+
ui.step(`@zazz-ui/core@${kit.version} predates data-font: updating the kit first (base, _variables.css, _typography.css, and what you have vendored).`);
|
|
405
|
+
await runUpdate(target, flags, global);
|
|
406
|
+
if (dryRun) ui.step("After that update, the codemod vendors font (and link, prose where used).");
|
|
407
|
+
else {
|
|
408
|
+
config = (await loadConfig(cwd)).config;
|
|
409
|
+
kit = await resolveKit(kitSpec(config.kit.version), fetch);
|
|
410
|
+
if (!kit.manifest.primitives["font"]) throw new ZazzError(`@zazz-ui/core@${kit.version} has no \`font\` primitive`, { hint: "that kit predates data-font; pass the version that has it (`zazz-ui codemod data-font @<version>`)" });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const missing = [...used].filter((primitive) => kit.manifest.primitives[primitive] && !config.primitives[primitive]);
|
|
414
|
+
if (missing.length) try {
|
|
415
|
+
await runAdd(missing, {
|
|
416
|
+
force: flags.force,
|
|
417
|
+
dryRun
|
|
418
|
+
}, global);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
ui.warn(`Vendoring ${missing.join(", ")} failed, so no markup was rewritten. Run the codemod again once that is fixed; it picks up where it stopped.`);
|
|
421
|
+
throw error;
|
|
422
|
+
}
|
|
423
|
+
} else ui.step("No zazz.json here, so only the markup is rewritten. A page that loads the kit per primitive also needs font.css (and link.css) from a kit that has data-font.");
|
|
424
|
+
if (changed.length) ui.step(`${dryRun ? "Would rewrite" : "Rewriting"} ${total} place(s) in ${changed.length} file(s):\n${changed.map(({ file, count }) => ` ${relative(file)} (${count})`).join("\n")}`);
|
|
425
|
+
if (!dryRun) await Promise.all(changed.map(({ file, output }) => writeFile(file, output)));
|
|
426
|
+
if (unread.length) {
|
|
427
|
+
ui.warn(`Skipped ${unread.length} file(s) that mention data-ui but are not UTF-8 or are over 2 MB; check them by hand:\n${unread.map((file) => ` ${relative(file)}`).join("\n")}`);
|
|
428
|
+
process.exitCode = 2;
|
|
429
|
+
}
|
|
430
|
+
if (review.length) {
|
|
431
|
+
ui.warn(`${review.length} place(s) still set a text-* token through data-ui and need a hand (two roles on one element, a value with template syntax or built in script, an unquoted selector):\n${review.map(({ file, line, text }) => ` ${relative(file)}:${line} ${text.slice(0, 100)}`).join("\n")}`);
|
|
432
|
+
process.exitCode = 2;
|
|
433
|
+
}
|
|
434
|
+
ui.outro(dryRun ? "Dry run — nothing written." : changed.length ? `Rewrote ${total} place(s) in ${changed.length} file(s).` : "Nothing to rewrite.");
|
|
435
|
+
}
|
|
436
|
+
/** Source files under the given paths (or the project root), outside any vendored kit. */
|
|
437
|
+
async function projectFiles(root, cwd, paths, kits) {
|
|
438
|
+
const starts = paths.length ? paths.map((given) => path.resolve(cwd, given)) : [root];
|
|
439
|
+
const walked = (await Promise.all(starts.map((start) => sourceFiles(start, kits)))).flat();
|
|
440
|
+
return [...new Set(walked)].filter((file) => ![...kits].some((kit) => within(file, kit)));
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* `zazz-ui codemod small-sizes`. Remove (the default, and the answer under
|
|
444
|
+
* `-y` or without a terminal): rewrite the markup, `"sm"` dropped and
|
|
445
|
+
* `"icon-sm"` made `"icon"`. Keep (`--restore`, or picked at the prompt): add
|
|
446
|
+
* the removed rules back and leave the markup alone. In a vendored project they
|
|
447
|
+
* go at the end of the vendored button.css and toggle.css, where `update`
|
|
448
|
+
* merges them like any local edit; without a zazz.json they go in a stylesheet
|
|
449
|
+
* of the project's own (`zazz-small-sizes.css`), loaded after the kit's.
|
|
450
|
+
* Fields never had a small size and are not touched.
|
|
451
|
+
*/
|
|
452
|
+
async function runSmallSizes(args, flags, global) {
|
|
453
|
+
const cwd = path.resolve(global.cwd);
|
|
454
|
+
const ui = createUi({
|
|
455
|
+
silent: global.silent === true,
|
|
456
|
+
yes: global.yes === true
|
|
457
|
+
});
|
|
458
|
+
const dryRun = flags.dryRun === true;
|
|
459
|
+
const loaded = await loadConfig(cwd);
|
|
460
|
+
const root = loaded?.root ?? cwd;
|
|
461
|
+
const relative = (file) => path.relative(root, file) || path.basename(file);
|
|
462
|
+
const isVersion = (arg) => arg.startsWith("@") && !existsSync(path.resolve(cwd, arg));
|
|
463
|
+
const versions = args.filter(isVersion);
|
|
464
|
+
const paths = args.filter((arg) => !isVersion(arg));
|
|
465
|
+
ui.intro("zazz-ui codemod small-sizes");
|
|
466
|
+
if (versions.length) ui.warn(`small-sizes doesn't update the kit, so ${versions.join(", ")} is ignored.`);
|
|
467
|
+
if ((flags.restore ? "keep" : await ui.select("The kit no longer has data-button-size or data-toggle-size \"sm\" and \"icon-sm\". What should happen to them?", [{
|
|
468
|
+
value: "remove",
|
|
469
|
+
label: "Remove them from the markup",
|
|
470
|
+
hint: "\"sm\" goes, \"icon-sm\" becomes \"icon\""
|
|
471
|
+
}, {
|
|
472
|
+
value: "keep",
|
|
473
|
+
label: "Keep them",
|
|
474
|
+
hint: loaded ? "add their rules back to the vendored button and toggle" : `write their rules to ${"zazz-small-sizes.css"}`
|
|
475
|
+
}], "remove")) === "keep") {
|
|
476
|
+
const writes = [];
|
|
477
|
+
const own = [];
|
|
478
|
+
for (const primitive of ["button", "toggle"]) {
|
|
479
|
+
const vendored = loaded?.config.primitives[primitive];
|
|
480
|
+
const key = vendored ? Object.keys(vendored.files).find((file) => file.endsWith(`${primitive}/${primitive}.css`)) : void 0;
|
|
481
|
+
const file = loaded && key ? path.join(root, loaded.config.dir, key) : void 0;
|
|
482
|
+
if (!file || !existsSync(file)) {
|
|
483
|
+
own.push(primitive);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const css = await readFile(file, "utf8");
|
|
487
|
+
if (hasRestoredSmallSizes(css, primitive)) {
|
|
488
|
+
ui.step(`${relative(file)} already has the small ${primitive} sizes.`);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
writes.push({
|
|
492
|
+
file,
|
|
493
|
+
content: `${css.replace(/\n*$/, "\n")}\n${smallSizesCss(primitive)}`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
if (own.length) {
|
|
497
|
+
const file = path.join(root, SMALL_SIZES_FILE);
|
|
498
|
+
const existing = existsSync(file) ? await readFile(file, "utf8") : "";
|
|
499
|
+
const missing = own.filter((primitive) => !hasRestoredSmallSizes(existing, primitive));
|
|
500
|
+
if (missing.length) {
|
|
501
|
+
const added = missing.map((primitive) => smallSizesCss(primitive)).join("\n");
|
|
502
|
+
writes.push({
|
|
503
|
+
file,
|
|
504
|
+
content: existing ? `${existing.replace(/\n*$/, "\n")}\n${added}` : added
|
|
505
|
+
});
|
|
506
|
+
ui.step(`Load ${SMALL_SIZES_FILE} after the kit's stylesheet; it adds the rules to the kit's ui.components layer.`);
|
|
507
|
+
} else ui.step(`${relative(file)} already has the small sizes.`);
|
|
508
|
+
}
|
|
509
|
+
if (writes.length) {
|
|
510
|
+
ui.step(`${dryRun ? "Would add" : "Adding"} the small sizes to:\n${writes.map(({ file }) => ` ${relative(file)}`).join("\n")}`);
|
|
511
|
+
ui.step("Inside an input group or a password group, a small size wins over the size the group gives its buttons; drop it there to let the group size them.");
|
|
512
|
+
}
|
|
513
|
+
if (!dryRun) await Promise.all(writes.map(({ file, content }) => writeFile(file, content)));
|
|
514
|
+
ui.outro(dryRun ? "Dry run — nothing written." : writes.length ? "Kept the small sizes. The markup is unchanged." : "Nothing to add.");
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const files = await projectFiles(root, cwd, paths, new Set(loaded ? [path.resolve(root, loaded.config.dir)] : []));
|
|
518
|
+
const changed = [];
|
|
519
|
+
const review = [];
|
|
520
|
+
const unread = [];
|
|
521
|
+
for (const file of files) {
|
|
522
|
+
const bytes = await readFile(file);
|
|
523
|
+
const source = bytes.toString("utf8");
|
|
524
|
+
if (bytes.length > MAX_BYTES || !Buffer.from(source, "utf8").equals(bytes)) {
|
|
525
|
+
if (/data-(?:button|toggle)-size/i.test(bytes.toString("latin1"))) unread.push(file);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
const result = removeSmallSizes(source);
|
|
529
|
+
if (result.output !== source) changed.push({
|
|
530
|
+
file,
|
|
531
|
+
output: result.output,
|
|
532
|
+
count: result.count
|
|
533
|
+
});
|
|
534
|
+
for (const item of result.review) review.push({
|
|
535
|
+
file,
|
|
536
|
+
...item
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
const total = changed.reduce((sum, { count }) => sum + count, 0);
|
|
540
|
+
if (changed.length) ui.step(`${dryRun ? "Would rewrite" : "Rewriting"} ${total} place(s) in ${changed.length} file(s):\n${changed.map(({ file, count }) => ` ${relative(file)} (${count})`).join("\n")}`);
|
|
541
|
+
if (!dryRun) await Promise.all(changed.map(({ file, output }) => writeFile(file, output)));
|
|
542
|
+
if (unread.length) {
|
|
543
|
+
ui.warn(`Skipped ${unread.length} file(s) that mention a size but are not UTF-8 or are over 2 MB; check them by hand:\n${unread.map((file) => ` ${relative(file)}`).join("\n")}`);
|
|
544
|
+
process.exitCode = 2;
|
|
545
|
+
}
|
|
546
|
+
if (review.length) {
|
|
547
|
+
ui.warn(`${review.length} place(s) still set a small size and need a hand (a selector, a value built in script or a template):\n${review.map(({ file, line, text }) => ` ${relative(file)}:${line} ${text.slice(0, 100)}`).join("\n")}`);
|
|
548
|
+
process.exitCode = 2;
|
|
549
|
+
}
|
|
550
|
+
ui.outro(dryRun ? "Dry run — nothing written." : changed.length ? `Rewrote ${total} place(s) in ${changed.length} file(s).` : "Nothing to rewrite.");
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export { runCodemod };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _ as resolveKit, a as renderIndexJs, c as createUi, f as baseFiles, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, m as primitiveFiles, o as sha256, r as renderHead, t as appendJsImports,
|
|
3
|
-
import {
|
|
1
|
+
import { a as isBinary, i as splitVersionArgs, n as readChangelog, o as compareVersions, s as sliceChangelog } from "./update-CzvFHR7k.js";
|
|
2
|
+
import { _ as resolveKit, a as renderIndexJs, c as createUi, f as baseFiles, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, m as primitiveFiles, o as sha256, r as renderHead, t as appendJsImports, y as loadConfig } from "./wiring-K8-qOImj.js";
|
|
3
|
+
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { readFile } from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { structuredPatch } from "diff";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// src/commands/diff.ts
|
|
11
11
|
/**
|
|
12
12
|
* @fileoverview `zazz-ui diff` — preview what an update would change.
|
|
13
13
|
* @description Read-only, always exit 0. Default compares your on-disk files
|
|
@@ -59,9 +59,11 @@ async function runDiff(args, flags, global) {
|
|
|
59
59
|
const lines = [];
|
|
60
60
|
for (const spec of files) {
|
|
61
61
|
const theirs = await spec.theirs();
|
|
62
|
-
const
|
|
62
|
+
const source = unit === "base" ? config.base.sources?.[spec.file] : void 0;
|
|
63
|
+
const fromKit = source !== void 0 && oldKit !== null ? await kitAt(source) : oldKit;
|
|
64
|
+
const mine = flags.upstream === true ? fromKit === null ? null : await upstreamSource(spec, fromKit, {
|
|
63
65
|
config,
|
|
64
|
-
target:
|
|
66
|
+
target: fromKit
|
|
65
67
|
}) : await localSource(spec, root, config);
|
|
66
68
|
const rendered = renderFileDiff(spec.file, mine, theirs, { editedLocally: flags.upstream !== true && mine !== null && spec.recordedHash !== null && sha256(mine) !== spec.recordedHash });
|
|
67
69
|
if (rendered) lines.push(rendered);
|
|
@@ -193,5 +195,4 @@ function sortedByCascade(names, kit) {
|
|
|
193
195
|
return [...names].sort((a, b) => (cascade.get(a) ?? Infinity) - (cascade.get(b) ?? Infinity));
|
|
194
196
|
}
|
|
195
197
|
|
|
196
|
-
//#endregion
|
|
197
198
|
export { runDiff };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/errors.ts
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview The CLI's one error type and its canonical messages.
|
|
4
4
|
* @description Commands and modules throw `ZazzError` for every expected
|
|
@@ -29,5 +29,4 @@ function kitTooOld(version, detail) {
|
|
|
29
29
|
return new ZazzError(`@zazz-ui/core@${version} is older than this CLI supports (${detail})`, { hint: "target a newer kit version (e.g. @latest), or use an older zazz-ui" });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//#endregion
|
|
33
32
|
export { offlineMiss as i, kitTooNew as n, kitTooOld as r, ZazzError as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { _ as resolveKit, a as renderIndexJs, b as filterCollisions, c as createUi, f as baseFiles, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, l as apply, o as sha256, r as renderHead, s as vendorFiles, t as appendJsImports, u as describe, y as loadConfig } from "./wiring-K8-qOImj.js";
|
|
2
|
+
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/commands/init.ts
|
|
8
8
|
/**
|
|
9
9
|
* @fileoverview `zazz-ui init` — vendor the Zazz base platform.
|
|
10
10
|
* @description Fresh projects get the base css layers, the core runtime,
|
|
@@ -190,5 +190,4 @@ async function pristineContent(kit, config, file) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
//#endregion
|
|
194
193
|
export { runInit as n, parseVersionArg as t };
|