zazz-ui 0.3.3 → 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 +13 -0
- package/README.md +29 -2
- package/dist/add-P8X_avx2.js +3 -0
- package/dist/{add-20ac-qTJ.js → add-TSAcIuda.js} +7 -2
- package/dist/cli.js +8 -4
- package/dist/codemod-D_Qdyjbn.js +553 -0
- package/dist/{diff-BAlklyPv.js → diff-SlSZRLDi.js} +6 -4
- package/dist/{init-CnDb64uK.js → init-DarNiijO.js} +1 -1
- package/dist/init-DuvWuYCt.js +3 -0
- package/dist/update-C32jRa_O.js +3 -0
- package/dist/{update-BJYS4fvC.js → update-CzvFHR7k.js} +147 -37
- package/dist/{wiring-BVwEMqB1.js → wiring-K8-qOImj.js} +15 -6
- package/package.json +3 -3
- package/dist/init-CKJXvUpN.js +0 -3
- package/dist/update-IzwW3BFA.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Notable changes to the `zazz-ui` CLI. The CLI versions independently of `@zazz-ui/core` (ADR-0010); the kit's own changelog is the one `update` and `diff` print.
|
|
4
4
|
|
|
5
|
+
## 0.3.4 (2026-11-27)
|
|
6
|
+
|
|
7
|
+
- New codemod: `codemod small-sizes [paths...]`, for the small control sizes the kit removed (`data-button-size` and `data-toggle-size` `"sm"` and `"icon-sm"`). It asks whether to remove them or keep them, and removing is the default (also under `-y` and without a terminal). Remove rewrites the markup: `"sm"` is dropped and `"icon-sm"` becomes `"icon"`. It lists selectors, sizes set from script, and template values, leaves them as written, and exits with code 2. Keep (`--restore`) leaves the markup and adds the removed rules back: to the vendored `button.css` and `toggle.css` in a vendored project (even when an older kit still ships them, so the next `update` keeps them), or to `zazz-small-sizes.css` without a `zazz.json` or for a primitive that isn't vendored. It takes no `@version`; one passed is ignored with a warning. Fields are not touched. `--dry-run` writes nothing.
|
|
8
|
+
- New command: `codemod data-font [@version] [paths...]`. It moves a project to typography roles in `data-font`: `data-ui="text-sm"` becomes `data-font="sm"`, `data-ui="text-link"` becomes `data-ui="link"`, and a quoted `[data-ui~="text-sm"]` selector becomes `[data-font="sm"]`. In a vendored project it first runs `update` when the recorded kit predates `data-font`, then `add` for the primitives the markup uses (`font`, `link`, `prose`). It never rewrites a vendored kit directory. It leaves what it cannot move safely (two roles on one element, template syntax in the value, a role set from script, an unquoted selector, a file that is not UTF-8), lists those places, and exits with code 2. `--dry-run` writes nothing.
|
|
9
|
+
- `add` and `update` vendor each primitive's data file (`primitives/<name>/<name>.json`: its hooks, attributes, slots, and states). Kits that predate the files vendor as before.
|
|
10
|
+
- A narrowed update (`update tabs`) vendors a shared script that the target version introduced. Before, it read the script from the version the base was recorded at, found nothing, and wrote no file, but still added the import to the entry script, so the page's scripts failed to load. A whole-kit `update` was not affected.
|
|
11
|
+
- `update` no longer deletes a script that a skipped primitive or your entry script still imports. Deleting one left the entry script (`index.js`) with a dead import, and then no script on the page loaded. Two cases:
|
|
12
|
+
- A primitive is skipped (a conflict in CI, or "Skip" at the prompt) and the kit moved or removed a shared script it imports. The script stays on disk. The first whole-kit `update` after the primitive moves deletes it.
|
|
13
|
+
- The entry script you end up with still imports a file the update would delete: you kept your version through a conflict, took conflict markers, or the base unit was skipped and the old entry stayed. This covers shared scripts, a script a primitive dropped, and the scripts of a primitive the kit removed. The file stays, and the output names it (`--dry-run` leaves it out of the plan without a note). Remove the import and run a whole-kit `zazz-ui update` to delete it. A commented-out import does not hold a file. If a later kit version ships the file again, its primitive takes it back.
|
|
14
|
+
- When the base unit is skipped, `update` still vendors the new shared scripts the updated primitives import, and lists them in its output. They were left out with the rest of the base unit, so the updated primitives imported files that did not exist.
|
|
15
|
+
- `zazz.json` has a new optional map, `base.sources`. It names the kit version a base file's recorded copy came from when that is not the base's own version. That happens when `update` or `add` vendors a shared script ahead of the base, when a skipped primitive keeps a script the kit moved, and when your entry still imports a removed file. `update` merges your edits to such a file against that version, and `diff --upstream` reads it from there. Without the record, an edited script could come back as a whole-file conflict. While the map has entries, a whole-kit `update` checks those files again instead of reporting `Already at`. `zazz-ui` 0.3.3 and earlier drop the map when they rewrite `zazz.json`.
|
|
16
|
+
- Re-running `update` after it skipped the base unit brings the entries up to date. Before, a narrowed re-run (`update tabs`) printed `Already at` and left `index.css` and the entry script without the updated primitive's imports, and a whole-kit re-run kept an edited entry script as it was, also without them. A skipped base unit now records the primitive versions its entries were generated for, in a new optional `base.entries` map in `zazz.json`. The next `update` sees the map, merges your entry edits against the entries for those versions, and removes the map once the base unit applies. `zazz-ui` 0.3.3 and earlier drop the map when they rewrite `zazz.json`.
|
|
17
|
+
|
|
5
18
|
## 0.3.3 (2026-11-16)
|
|
6
19
|
|
|
7
20
|
- An exact version (`update @0.14.1`, `diff @0.14.1`, `init 0.14.1`) resolves right after it is published. The CLI reads an exact version from npm's cache, and when the cached version list predated the release, it reported "No matching version found" until something like `@latest` refreshed the list. A cache miss now asks the registry once. `--offline` still never goes online.
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Flags: `--dir <path>`, `--ts` (vendor TypeScript sources instead of compiled js,
|
|
|
17
17
|
|
|
18
18
|
## What add does
|
|
19
19
|
|
|
20
|
-
`add <primitive...>` resolves the primitives you ask for plus everything they depend on (adding `combobox` brings `select`, `fields`, `popover`, `button`, `kbd`, and `badge`), copies the files at your project's recorded kit version, and inserts the entry imports at the right cascade position. Your edits to vendored files are never touched. `--examples` also copies the primitive's example markup.
|
|
20
|
+
`add <primitive...>` resolves the primitives you ask for plus everything they depend on (adding `combobox` brings `select`, `fields`, `popover`, `button`, `kbd`, and `badge`), copies the files at your project's recorded kit version (with each primitive's data file, `primitives/<name>/<name>.json`, from kits that ship one), and inserts the entry imports at the right cascade position. Your edits to vendored files are never touched. `--examples` also copies the primitive's example markup.
|
|
21
21
|
|
|
22
22
|
## What update does
|
|
23
23
|
|
|
@@ -27,13 +27,40 @@ Naming primitives narrows the update (`update @0.5.0 button`): only those move,
|
|
|
27
27
|
|
|
28
28
|
`diff [@version] [name...]` shows all of it read-only: your files against the target version's exact bytes, plus the changelog slice. `--upstream` compares pristine-to-pristine instead, ignoring your edits.
|
|
29
29
|
|
|
30
|
+
## What codemod does
|
|
31
|
+
|
|
32
|
+
`codemod data-font [@version] [paths...]` moves a project to typography roles in `data-font`. It rewrites `data-ui="text-sm"` to `data-font="sm"` and `data-ui="text-link"` to `data-ui="link"`, keeps any identity that shared the attribute (`data-ui="badge text-xs"` becomes `data-ui="badge" data-font="xs"`), and rewrites quoted selectors (`[data-ui~="text-sm"]` becomes `[data-font="sm"]`).
|
|
33
|
+
|
|
34
|
+
It reads markup, templates, scripts, and stylesheets under the project root, or under the paths you name. It skips every vendored kit directory, `node_modules` and other dependency and build folders, dot-directories, a top-level `vendor` or `tmp`, minified files, and plain Markdown. Name a file to rewrite it anyway; a vendored kit file is never rewritten.
|
|
35
|
+
|
|
36
|
+
In a vendored project it handles the kit as well. If the recorded kit predates `data-font`, it runs `update` first, to latest or to the `@version` you pass. That update brings the new `_variables.css` and `_typography.css`, and `--keep`, `--theirs`, and `--markers` answer its conflicts. Then it runs `add` for the primitives your markup uses: `font`, and `link` and `prose` where they appear. Without a `zazz.json` it rewrites the markup and leaves the kit to you.
|
|
37
|
+
|
|
38
|
+
It only moves what it can move safely. It leaves these as written, lists the ones it finds, and exits with code 2:
|
|
39
|
+
|
|
40
|
+
- an element with two roles, or one that already has `data-font`
|
|
41
|
+
- a value with template syntax among its tokens (`data-ui="text-sm {{ extra }}"`)
|
|
42
|
+
- a role set from script (`el.setAttribute("data-ui", "text-xs")`, `data-ui={…}`)
|
|
43
|
+
- an unquoted selector (`[data-ui~=text-sm]`)
|
|
44
|
+
- a file that is not UTF-8 or is over 2 MB
|
|
45
|
+
|
|
46
|
+
The list covers the common ways a role is set, not every one; search for `text-` afterward if your templates build `data-ui` in unusual ways. `--dry-run` prints the files and counts and writes nothing. A second run changes nothing.
|
|
47
|
+
|
|
48
|
+
### small-sizes
|
|
49
|
+
|
|
50
|
+
`codemod small-sizes [paths...]` handles the small control sizes the kit removed: `data-button-size` and `data-toggle-size` no longer take `"sm"` or `"icon-sm"`. It asks what to do; removing them is the default, and it is the answer under `-y` or without a terminal.
|
|
51
|
+
|
|
52
|
+
- **Remove**: rewrites the markup. `"sm"` is dropped and `"icon-sm"` becomes `"icon"`, quoted or not, with or without spaces around `=`. A selector (`[data-button-size="sm"]`), a size set from script, or a template value is listed for review, left as written, and the command exits with code 2.
|
|
53
|
+
- **Keep** (`--restore`, or pick it at the prompt): leaves the markup alone and adds the removed rules back. In a vendored project they go at the end of the vendored `button.css` and `toggle.css`, where `update` merges them like any edit of yours. Without a `zazz.json`, and for button or toggle when it isn't vendored, they go in `zazz-small-sizes.css` at the project root (added to the end if the file exists), which you load after the kit's stylesheet. It recognizes its own rules by their header, so running it again adds nothing twice, and on a vendored kit old enough to still have the sizes it adds them anyway, so the next `update` can't drop them. Inside an input group or a password group a small size wins over the size the group gives its buttons.
|
|
54
|
+
|
|
55
|
+
Fields never had a small size and are not touched. `--dry-run` writes nothing.
|
|
56
|
+
|
|
30
57
|
## Owning the code
|
|
31
58
|
|
|
32
59
|
There is no runtime dependency on `@zazz-ui/core`. The files in `zazz/` are yours: edit them, delete what you don't want, commit them like any other source. `zazz.json` is what makes that safe, and `update` is what makes it cheap.
|
|
33
60
|
|
|
34
61
|
## Requirements
|
|
35
62
|
|
|
36
|
-
Node 22.22+ (or 24.15+). Works with `@zazz-ui/core` 0.1 through 0.
|
|
63
|
+
Node 22.22+ (or 24.15+). Works with `@zazz-ui/core` 0.1 through 0.16 (manifest v1–v2); given a newer kit, the CLI tells you to upgrade it. Works offline once a kit version is cached; respects your `.npmrc` (registries, proxies, auth). `--registry`, `--offline`, and `--prefer-offline` are available on every command.
|
|
37
64
|
|
|
38
65
|
## License
|
|
39
66
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as resolveKit, a as renderIndexJs, c as createUi, d as baseCssSplit, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, l as apply, m as primitiveFiles, n as insertCssImports, o as sha256, p as baseScriptFiles, r as renderHead, s as vendorFiles, t as appendJsImports, u as describe,
|
|
1
|
+
import { _ as resolveKit, a as renderIndexJs, b as filterCollisions, c as createUi, d as baseCssSplit, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, l as apply, m as primitiveFiles, n as insertCssImports, o as sha256, p as baseScriptFiles, r as renderHead, s as vendorFiles, t as appendJsImports, u as describe, y as loadConfig } from "./wiring-K8-qOImj.js";
|
|
2
2
|
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
@@ -52,12 +52,17 @@ async function runAdd(names, flags, global) {
|
|
|
52
52
|
version: kit.version,
|
|
53
53
|
files: hashes
|
|
54
54
|
};
|
|
55
|
+
if (config.base.entries) config.base.entries[name] = kit.version;
|
|
55
56
|
}
|
|
56
57
|
const freshEntries = fresh.flatMap((name) => kit.manifest.primitives[name] ?? []);
|
|
57
58
|
const neededBase = baseScriptFiles(freshEntries, config.language).filter((file) => !(file in config.base.files));
|
|
58
59
|
const base = await vendorFiles(kit, neededBase, destRoot);
|
|
59
60
|
vendorWrites.push(...base.writes);
|
|
60
61
|
Object.assign(config.base.files, base.hashes);
|
|
62
|
+
if (kit.version !== (config.base.version ?? config.kit.version)) config.base.sources = {
|
|
63
|
+
...config.base.sources,
|
|
64
|
+
...Object.fromEntries(Object.keys(base.hashes).map((file) => [file, kit.version]))
|
|
65
|
+
};
|
|
61
66
|
const { kept, skipped } = await filterCollisions(vendorWrites, {
|
|
62
67
|
ui,
|
|
63
68
|
force: flags.force === true
|
|
@@ -128,4 +133,4 @@ async function wiringWrites(kit, config, destRoot, fresh) {
|
|
|
128
133
|
return writes;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
export { runAdd };
|
|
136
|
+
export { runAdd as t };
|
package/dist/cli.js
CHANGED
|
@@ -15,21 +15,25 @@ import { Command, Option } from "commander";
|
|
|
15
15
|
const { version } = createRequire(import.meta.url)("../package.json");
|
|
16
16
|
const program = new Command("zazz-ui").description("Vendor Zazz Design Framework primitives into your project").version(version).option("-c, --cwd <path>", "run as if started in <path>", process.cwd()).option("-y, --yes", "answer prompts with their defaults; never block").option("--silent", "no output except errors").option("--registry <url>", "npm registry override").option("--offline", "cache only; never touch the network").option("--prefer-offline", "use cached data without revalidating");
|
|
17
17
|
program.command("init").description("vendor the Zazz base (tokens, reset, runtime) into this project").argument("[version]", "kit version, @-prefixed (e.g. @0.5.0); default latest").option("--dir <path>", "target directory for vendored files", "zazz").option("--ts", "vendor TypeScript sources instead of compiled .js").option("--legacy <path>", "wire an existing stylesheet into the legacy.imports cascade sublayer").option("--no-fonts", "omit the Geist fonts block from head.html").option("--no-theme-script", "omit the theme-persistence script from head.html").option("--force", "overwrite existing files without asking").option("--dry-run", "print the plan without writing").action(async (versionArg, options) => {
|
|
18
|
-
const { runInit } = await import("./init-
|
|
18
|
+
const { runInit } = await import("./init-DuvWuYCt.js");
|
|
19
19
|
await runInit(versionArg, options, program.opts());
|
|
20
20
|
});
|
|
21
21
|
program.command("update").description("move vendored files to a new kit version with 3-way merges").argument("[args...]", "target version @-prefixed (default @latest) and/or primitive names to narrow to").addOption(new Option("--keep", "resolve every conflict by keeping your version").conflicts(["theirs", "markers"])).addOption(new Option("--theirs", "resolve every conflict by taking the new version").conflicts(["keep", "markers"])).addOption(new Option("--markers", "write diff3 conflict markers for every conflict").conflicts(["keep", "theirs"])).option("--force", "overwrite stray files without asking").option("--dry-run", "print the plan without writing").action(async (args, options) => {
|
|
22
|
-
const { runUpdate } = await import("./update-
|
|
22
|
+
const { runUpdate } = await import("./update-C32jRa_O.js");
|
|
23
23
|
await runUpdate(args, options, program.opts());
|
|
24
24
|
});
|
|
25
25
|
program.command("diff").description("preview what an update would change (read-only)").argument("[args...]", "target version @-prefixed (default @latest) and/or names to narrow to (base, button, …)").option("--upstream", "compare pristine recorded vs target instead of your files vs target").action(async (args, options) => {
|
|
26
|
-
const { runDiff } = await import("./diff-
|
|
26
|
+
const { runDiff } = await import("./diff-SlSZRLDi.js");
|
|
27
27
|
await runDiff(args, options, program.opts());
|
|
28
28
|
});
|
|
29
29
|
program.command("add").description("vendor primitives (and their dependencies) at the project's kit version").argument("<primitive...>", "primitive names (e.g. button combobox)").option("--examples", "also copy the primitives' example html").option("--force", "overwrite existing files without asking").option("--dry-run", "print the closure and file plan without writing").action(async (names, options) => {
|
|
30
|
-
const { runAdd } = await import("./add-
|
|
30
|
+
const { runAdd } = await import("./add-P8X_avx2.js");
|
|
31
31
|
await runAdd(names, options, program.opts());
|
|
32
32
|
});
|
|
33
|
+
program.command("codemod").description("rewrite your markup for a breaking kit change (data-font, small-sizes)").argument("<name>", "the codemod to run: data-font, small-sizes").argument("[args...]", "files or directories to rewrite (default the whole project), and/or the kit version to update to first, @-prefixed (default @latest)").addOption(new Option("--keep", "if the kit updates first: keep your version on every conflict").conflicts(["theirs", "markers"])).addOption(new Option("--theirs", "if the kit updates first: take the new version on every conflict").conflicts(["keep", "markers"])).addOption(new Option("--markers", "if the kit updates first: write diff3 conflict markers on every conflict").conflicts(["keep", "theirs"])).option("--force", "overwrite existing files when vendoring without asking").option("--restore", "small-sizes: keep the small sizes, adding their rules back, instead of removing them").option("--dry-run", "list what would change without writing").action(async (name, args, options) => {
|
|
34
|
+
const { runCodemod } = await import("./codemod-D_Qdyjbn.js");
|
|
35
|
+
await runCodemod(name, args, options, program.opts());
|
|
36
|
+
});
|
|
33
37
|
try {
|
|
34
38
|
await program.parseAsync();
|
|
35
39
|
} catch (error) {
|
|
@@ -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,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
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,
|
|
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
3
|
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
@@ -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);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as resolveKit, a as renderIndexJs, 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,
|
|
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
2
|
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as resolveKit, a as renderIndexJs, c as createUi, f as baseFiles, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, l as apply, m as primitiveFiles, o as sha256, p as baseScriptFiles, r as renderHead, t as appendJsImports, u as describe,
|
|
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, m as primitiveFiles, o as sha256, p as baseScriptFiles, r as renderHead, t as appendJsImports, u as describe, y as loadConfig } from "./wiring-K8-qOImj.js";
|
|
2
2
|
import { t as ZazzError } from "./errors--aALbpFB.js";
|
|
3
|
-
import { t as parseVersionArg } from "./init-
|
|
3
|
+
import { t as parseVersionArg } from "./init-DarNiijO.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { readFile } from "node:fs/promises";
|
|
@@ -181,6 +181,14 @@ function bytesEqual(a, b) {
|
|
|
181
181
|
* entries (index.css / index.js / head.html) belong to the base unit; their
|
|
182
182
|
* merge ancestor and target are regenerated, not read from the tarball.
|
|
183
183
|
* head.html is CLI-owned: it always takes the regenerated version.
|
|
184
|
+
*
|
|
185
|
+
* A base file can come from a version other than the base's own (a shared
|
|
186
|
+
* script a moved primitive needs before the base catches up); `base.sources`
|
|
187
|
+
* records that version so the file keeps its merge ancestor. No update deletes
|
|
188
|
+
* a file the resulting entry script still imports: it stays, tracked by the
|
|
189
|
+
* base unit, until the entry lets go. When the base unit is skipped,
|
|
190
|
+
* `base.entries` records the primitive versions the entries on disk were
|
|
191
|
+
* generated for, so a re-run has work to do and a true ancestor to merge from.
|
|
184
192
|
*/
|
|
185
193
|
/** Splits positional args: the @-prefixed one is the version, the rest names. */
|
|
186
194
|
function splitVersionArgs(args) {
|
|
@@ -220,18 +228,6 @@ async function runUpdate(args, flags, global) {
|
|
|
220
228
|
const scopeNames = wholeKit ? vendoredNames : names;
|
|
221
229
|
const survivors = scopeNames.filter((name) => target.manifest.primitives[name]);
|
|
222
230
|
const freshDeps = target.manifest.resolveClosure(survivors).filter((name) => !config.primitives[name]);
|
|
223
|
-
if (!(freshDeps.length > 0 || scopeNames.some((name) => config.primitives[name]?.version !== target.version) || wholeKit && (config.kit.version !== target.version || (config.base.version ?? config.kit.version) !== target.version))) {
|
|
224
|
-
ui.outro(`Already at ${target.version} — nothing to update.`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const changelog = await readChangelog(target);
|
|
228
|
-
if (changelog && compareVersions(target.version, config.kit.version) > 0) {
|
|
229
|
-
const slice = sliceChangelog(changelog, {
|
|
230
|
-
from: config.kit.version,
|
|
231
|
-
to: target.version
|
|
232
|
-
}, /* @__PURE__ */ new Set([...vendoredNames, ...freshDeps]));
|
|
233
|
-
if (slice) ui.step(slice);
|
|
234
|
-
}
|
|
235
231
|
const kitCache = /* @__PURE__ */ new Map();
|
|
236
232
|
kitCache.set(target.version, Promise.resolve(target));
|
|
237
233
|
const kitAt = (v) => {
|
|
@@ -251,6 +247,18 @@ async function runUpdate(args, flags, global) {
|
|
|
251
247
|
strategy,
|
|
252
248
|
interactive: ui.interactive
|
|
253
249
|
};
|
|
250
|
+
if (!(config.base.entries !== void 0 || freshDeps.length > 0 || scopeNames.some((name) => config.primitives[name]?.version !== target.version) || wholeKit && (config.kit.version !== target.version || (config.base.version ?? config.kit.version) !== target.version || Object.keys(config.base.sources ?? {}).length > 0))) {
|
|
251
|
+
ui.outro(`Already at ${target.version} — nothing to update.`);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const changelog = await readChangelog(target);
|
|
255
|
+
if (changelog && compareVersions(target.version, config.kit.version) > 0) {
|
|
256
|
+
const slice = sliceChangelog(changelog, {
|
|
257
|
+
from: config.kit.version,
|
|
258
|
+
to: target.version
|
|
259
|
+
}, /* @__PURE__ */ new Set([...vendoredNames, ...freshDeps]));
|
|
260
|
+
if (slice) ui.step(slice);
|
|
261
|
+
}
|
|
254
262
|
const units = [];
|
|
255
263
|
for (const name of scopeNames) units.push(await planPrimitiveUnit(name, context));
|
|
256
264
|
const primitiveVersionAfter = new Map(vendoredNames.map((name) => [name, config.primitives[name]?.version ?? target.version]));
|
|
@@ -275,6 +283,7 @@ async function runUpdate(args, flags, global) {
|
|
|
275
283
|
}
|
|
276
284
|
const baseUnit = await planBaseUnit(context, {
|
|
277
285
|
wholeKit,
|
|
286
|
+
claimed: new Set(units.filter((unit) => !unit.skipped).flatMap((unit) => Object.keys(unit.hashes))),
|
|
278
287
|
primitiveVersionAfter,
|
|
279
288
|
removedPrimitives: units.filter((unit) => unit.removedFromKit && !unit.skipped)
|
|
280
289
|
});
|
|
@@ -283,8 +292,33 @@ async function runUpdate(args, flags, global) {
|
|
|
283
292
|
ui,
|
|
284
293
|
force: flags.force === true
|
|
285
294
|
});
|
|
295
|
+
const entriesBefore = Object.fromEntries(Object.entries(config.primitives).map(([name, entry]) => [name, entry.version]));
|
|
286
296
|
const applied = units.filter((unit) => !unit.skipped);
|
|
287
297
|
const skippedUnits = units.filter((unit) => unit.skipped);
|
|
298
|
+
const baseVersionBefore = config.base.version ?? config.kit.version;
|
|
299
|
+
const baseVersionAfter = wholeKit && !baseUnit.skipped ? target.version : baseVersionBefore;
|
|
300
|
+
const entryScript = config.language === "ts" ? "index.ts" : "index.js";
|
|
301
|
+
const entryDest = path.join(root, config.dir, entryScript);
|
|
302
|
+
const stagedEntry = baseUnit.skipped ? void 0 : baseUnit.writes.findLast((write) => write.dest === entryDest)?.content;
|
|
303
|
+
const imported = importedStems(stagedEntry !== void 0 ? stagedEntry.toString() : existsSync(entryDest) ? await readFile(entryDest, "utf8") : "");
|
|
304
|
+
const kitRoot = path.join(root, config.dir);
|
|
305
|
+
const held = [];
|
|
306
|
+
for (const unit of applied) unit.deletes = unit.deletes.filter((dest) => {
|
|
307
|
+
const file = path.relative(kitRoot, dest).split(path.sep).join("/");
|
|
308
|
+
const stem = file.replace(/\.d\.ts$|\.js$|\.ts$/, "");
|
|
309
|
+
if (stem === file || !imported.has(stem)) return true;
|
|
310
|
+
const rel = path.relative(root, dest);
|
|
311
|
+
unit.notes = unit.notes.filter((note) => !note.startsWith(`${rel}: removed upstream`));
|
|
312
|
+
unit.notes.push(`${rel}: removed upstream — kept, because your ${entryScript} still imports it. Remove the import and run \`zazz-ui update\` again to delete it`);
|
|
313
|
+
const hash = unit.unit === "base" ? config.base.files[file] : config.primitives[unit.unit]?.files[file];
|
|
314
|
+
const source = unit.unit === "base" ? config.base.sources?.[file] ?? baseVersionBefore : unit.fromVersion;
|
|
315
|
+
if (hash !== void 0) held.push({
|
|
316
|
+
file,
|
|
317
|
+
hash,
|
|
318
|
+
source
|
|
319
|
+
});
|
|
320
|
+
return false;
|
|
321
|
+
});
|
|
288
322
|
for (const unit of applied) {
|
|
289
323
|
if (unit.unit === "base") continue;
|
|
290
324
|
if (unit.removedFromKit) delete config.primitives[unit.unit];
|
|
@@ -293,23 +327,38 @@ async function runUpdate(args, flags, global) {
|
|
|
293
327
|
files: unit.hashes
|
|
294
328
|
};
|
|
295
329
|
}
|
|
330
|
+
const required = baseUnit.skipped ? baseUnit.required ?? [] : [];
|
|
331
|
+
const sources = baseUnit.skipped ? { ...config.base.sources } : { ...baseUnit.sources };
|
|
296
332
|
if (!baseUnit.skipped) config.base.files = baseUnit.hashes;
|
|
333
|
+
if (baseUnit.skipped) for (const unit of applied) for (const file of Object.keys(unit.hashes)) delete config.base.files[file];
|
|
334
|
+
for (const { file, hash, source } of [...required, ...held]) {
|
|
335
|
+
config.base.files[file] = hash;
|
|
336
|
+
sources[file] = source;
|
|
337
|
+
}
|
|
338
|
+
for (const [file, source] of Object.entries(sources)) if (source === baseVersionAfter || !(file in config.base.files)) delete sources[file];
|
|
339
|
+
if (baseUnit.skipped) config.base.entries ??= entriesBefore;
|
|
340
|
+
else delete config.base.entries;
|
|
341
|
+
if (Object.keys(sources).length > 0) config.base.sources = sources;
|
|
342
|
+
else delete config.base.sources;
|
|
297
343
|
for (const dep of freshDeps) config.primitives[dep] = {
|
|
298
344
|
version: target.version,
|
|
299
345
|
files: freshHashes.get(dep) ?? {}
|
|
300
346
|
};
|
|
301
347
|
if (wholeKit) {
|
|
302
|
-
const oldBaseVersion = config.base.version ?? config.kit.version;
|
|
303
348
|
config.kit = {
|
|
304
349
|
version: target.version,
|
|
305
350
|
integrity: target.integrity
|
|
306
351
|
};
|
|
307
|
-
if (baseUnit.skipped) config.base.version =
|
|
352
|
+
if (baseUnit.skipped) config.base.version = baseVersionBefore;
|
|
308
353
|
else delete config.base.version;
|
|
309
354
|
}
|
|
310
355
|
const tx = {
|
|
311
356
|
root,
|
|
312
|
-
writes: [
|
|
357
|
+
writes: [
|
|
358
|
+
...applied.flatMap((unit) => unit.writes),
|
|
359
|
+
...required.map(({ write }) => write),
|
|
360
|
+
...keptFresh
|
|
361
|
+
],
|
|
313
362
|
deletes: applied.flatMap((unit) => unit.deletes),
|
|
314
363
|
config
|
|
315
364
|
};
|
|
@@ -320,6 +369,7 @@ async function runUpdate(args, flags, global) {
|
|
|
320
369
|
}
|
|
321
370
|
await apply(tx);
|
|
322
371
|
for (const unit of applied) for (const note of unit.notes) ui.step(note);
|
|
372
|
+
if (required.length > 0) ui.step(`base was skipped, but the shared scripts the updated primitives import were still vendored:\n ${required.map(({ write }) => path.relative(root, write.dest)).join("\n ")}`);
|
|
323
373
|
if (freshDeps.length > 0) ui.step(`New dependencies vendored at ${target.version}: ${freshDeps.join(", ")}`);
|
|
324
374
|
const straySkips = applied.reduce((count, unit) => count + unit.straySkips, 0);
|
|
325
375
|
if (skippedUnits.length > 0 || freshSkipped.length > 0 || straySkips > 0) {
|
|
@@ -362,12 +412,17 @@ async function planPrimitiveUnit(name, context) {
|
|
|
362
412
|
const wantExamples = newEntry.examples.some((file) => file in record.files);
|
|
363
413
|
const needed = primitiveFiles(newEntry, config.language, { examples: wantExamples });
|
|
364
414
|
const files = [.../* @__PURE__ */ new Set([...Object.keys(record.files), ...needed])];
|
|
365
|
-
for (const file of files)
|
|
366
|
-
file
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
415
|
+
for (const file of files) {
|
|
416
|
+
const held = file in record.files ? void 0 : config.base.files[file];
|
|
417
|
+
const heldVersion = config.base.sources?.[file] ?? config.base.version ?? config.kit.version;
|
|
418
|
+
if (!await resolveFile(unit, context, {
|
|
419
|
+
file,
|
|
420
|
+
recordedHash: record.files[file] ?? held ?? null,
|
|
421
|
+
base: async () => readKitFile(held === void 0 ? oldKit : await context.kitAt(heldVersion), file),
|
|
422
|
+
...held === void 0 ? {} : { baseLabel: heldVersion },
|
|
423
|
+
theirs: () => readKitFile(target, file)
|
|
424
|
+
})) return unit;
|
|
425
|
+
}
|
|
371
426
|
return unit;
|
|
372
427
|
}
|
|
373
428
|
/**
|
|
@@ -380,6 +435,8 @@ async function planBaseUnit(context, options) {
|
|
|
380
435
|
const baseVersion = config.base.version ?? config.kit.version;
|
|
381
436
|
const oldKit = await context.kitAt(baseVersion);
|
|
382
437
|
const entriesKit = options.wholeKit ? target : oldKit;
|
|
438
|
+
const required = [];
|
|
439
|
+
const sources = {};
|
|
383
440
|
const unit = {
|
|
384
441
|
unit: "base",
|
|
385
442
|
fromVersion: baseVersion,
|
|
@@ -389,7 +446,9 @@ async function planBaseUnit(context, options) {
|
|
|
389
446
|
skipped: false,
|
|
390
447
|
removedFromKit: false,
|
|
391
448
|
notes: [],
|
|
392
|
-
straySkips: 0
|
|
449
|
+
straySkips: 0,
|
|
450
|
+
required,
|
|
451
|
+
sources
|
|
393
452
|
};
|
|
394
453
|
const entryScript = config.language === "ts" ? "index.ts" : "index.js";
|
|
395
454
|
const generated = /* @__PURE__ */ new Set([
|
|
@@ -399,30 +458,70 @@ async function planBaseUnit(context, options) {
|
|
|
399
458
|
"head.html"
|
|
400
459
|
]);
|
|
401
460
|
const removed = new Set(options.removedPrimitives.map((plan) => plan.unit));
|
|
402
|
-
const beforeVersions = new Map(Object.entries(config.primitives).map(([name, entry]) => [name, entry.version]));
|
|
461
|
+
const beforeVersions = new Map(Object.entries(config.base.entries ?? Object.fromEntries(Object.entries(config.primitives).map(([name, entry]) => [name, entry.version]))));
|
|
403
462
|
const afterVersions = new Map([...options.primitiveVersionAfter].filter(([name]) => !removed.has(name)));
|
|
404
463
|
const entriesBefore = await entrySources(context, oldKit, beforeVersions);
|
|
405
464
|
const entriesAfter = await entrySources(context, entriesKit, afterVersions);
|
|
406
465
|
const afterEntries = [];
|
|
466
|
+
const neededFrom = /* @__PURE__ */ new Map();
|
|
407
467
|
for (const [name, primitiveVersion] of afterVersions) {
|
|
408
|
-
const
|
|
409
|
-
|
|
468
|
+
const kit = await context.kitAt(primitiveVersion);
|
|
469
|
+
const entry = kit.manifest.primitives[name];
|
|
470
|
+
if (!entry) continue;
|
|
471
|
+
afterEntries.push(entry);
|
|
472
|
+
for (const file of baseScriptFiles([entry], config.language)) if (!neededFrom.has(file) || kit === target) neededFrom.set(file, kit);
|
|
410
473
|
}
|
|
411
474
|
const neededScripts = baseScriptFiles(afterEntries, config.language);
|
|
475
|
+
const ancestorVersion = (file) => config.base.sources?.[file] ?? baseVersion;
|
|
476
|
+
const ancestor = async (file) => readKitFile(await context.kitAt(ancestorVersion(file)), file);
|
|
412
477
|
const vendorable = options.wholeKit ? [.../* @__PURE__ */ new Set([
|
|
413
478
|
...Object.keys(config.base.files).filter((file) => !generated.has(file)),
|
|
414
479
|
...baseFiles(target.manifest, config.language),
|
|
415
480
|
...neededScripts
|
|
416
|
-
])] : neededScripts.filter((file) => !(file in config.base.files));
|
|
481
|
+
])].filter((file) => !options.claimed.has(file)) : neededScripts.filter((file) => !(file in config.base.files));
|
|
417
482
|
if (!options.wholeKit) {
|
|
418
|
-
for (const [file, hash] of Object.entries(config.base.files)) if (!generated.has(file)) unit.hashes[file] = hash;
|
|
483
|
+
for (const [file, hash] of Object.entries(config.base.files)) if (!generated.has(file) && !options.claimed.has(file)) unit.hashes[file] = hash;
|
|
484
|
+
Object.assign(sources, config.base.sources);
|
|
485
|
+
}
|
|
486
|
+
const origin = /* @__PURE__ */ new Map();
|
|
487
|
+
const theirs = async (file) => {
|
|
488
|
+
const kits = options.wholeKit ? [target, neededFrom.get(file)] : [oldKit, target];
|
|
489
|
+
for (const kit of kits) {
|
|
490
|
+
const content = kit ? await readKitFile(kit, file) : null;
|
|
491
|
+
if (content !== null) {
|
|
492
|
+
origin.set(file, kit?.version ?? baseVersion);
|
|
493
|
+
return content;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return null;
|
|
497
|
+
};
|
|
498
|
+
for (const file of neededScripts) {
|
|
499
|
+
const dest = destPath(context, file);
|
|
500
|
+
if (file in config.base.files || existsSync(dest)) continue;
|
|
501
|
+
const content = await theirs(file);
|
|
502
|
+
if (content === null) continue;
|
|
503
|
+
required.push({
|
|
504
|
+
file,
|
|
505
|
+
hash: sha256(content),
|
|
506
|
+
source: origin.get(file) ?? baseVersion,
|
|
507
|
+
write: {
|
|
508
|
+
dest,
|
|
509
|
+
content,
|
|
510
|
+
note: "vendor"
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
for (const file of vendorable) {
|
|
515
|
+
if (!await resolveFile(unit, context, {
|
|
516
|
+
file,
|
|
517
|
+
recordedHash: config.base.files[file] ?? null,
|
|
518
|
+
base: () => ancestor(file),
|
|
519
|
+
baseLabel: ancestorVersion(file),
|
|
520
|
+
theirs: () => theirs(file)
|
|
521
|
+
})) return unit;
|
|
522
|
+
const source = origin.get(file);
|
|
523
|
+
if (file in unit.hashes && source !== void 0) sources[file] = source;
|
|
419
524
|
}
|
|
420
|
-
for (const file of vendorable) if (!await resolveFile(unit, context, {
|
|
421
|
-
file,
|
|
422
|
-
recordedHash: config.base.files[file] ?? null,
|
|
423
|
-
base: () => readKitFile(oldKit, file),
|
|
424
|
-
theirs: () => readKitFile(options.wholeKit ? target : oldKit, file)
|
|
425
|
-
})) return unit;
|
|
426
525
|
for (const file of ["index.css", entryScript]) if (!await resolveFile(unit, context, {
|
|
427
526
|
file,
|
|
428
527
|
recordedHash: config.base.files[file] ?? null,
|
|
@@ -482,7 +581,7 @@ async function resolveFile(unit, context, input) {
|
|
|
482
581
|
const base = await input.base();
|
|
483
582
|
const labels = {
|
|
484
583
|
ours: "yours",
|
|
485
|
-
base: unit.fromVersion,
|
|
584
|
+
base: input.baseLabel ?? unit.fromVersion,
|
|
486
585
|
theirs: context.target.version
|
|
487
586
|
};
|
|
488
587
|
const disposition = classify({
|
|
@@ -649,6 +748,17 @@ async function resolveConflict(unit, context, file) {
|
|
|
649
748
|
default: return true;
|
|
650
749
|
}
|
|
651
750
|
}
|
|
751
|
+
/**
|
|
752
|
+
* @description The kit files a script imports, without their extension
|
|
753
|
+
* (`base/engine`). Block comments and commented-out lines do not count; both
|
|
754
|
+
* sides of an unresolved conflict do, so nothing either side needs is deleted.
|
|
755
|
+
*/
|
|
756
|
+
function importedStems(source) {
|
|
757
|
+
const code = source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
758
|
+
const stems = /* @__PURE__ */ new Set();
|
|
759
|
+
for (const match of code.matchAll(/\b(?:import|from)\s*\(?\s*["']\.\/([^"']+?)(?:\.d\.ts|\.js|\.ts)["']/g)) if (match[1] !== void 0) stems.add(match[1]);
|
|
760
|
+
return stems;
|
|
761
|
+
}
|
|
652
762
|
function destPath(context, file) {
|
|
653
763
|
return path.join(context.root, context.config.dir, ...file.split("/"));
|
|
654
764
|
}
|
|
@@ -664,4 +774,4 @@ async function readChangelog(kit) {
|
|
|
664
774
|
}
|
|
665
775
|
}
|
|
666
776
|
|
|
667
|
-
export {
|
|
777
|
+
export { isBinary as a, splitVersionArgs as i, readChangelog as n, compareVersions as o, runUpdate as r, sliceChangelog as s, importedStems as t };
|
|
@@ -94,7 +94,9 @@ function serializeConfig(config) {
|
|
|
94
94
|
},
|
|
95
95
|
base: {
|
|
96
96
|
...config.base.version !== void 0 ? { version: config.base.version } : {},
|
|
97
|
-
files: sortKeys(config.base.files)
|
|
97
|
+
files: sortKeys(config.base.files),
|
|
98
|
+
...Object.keys(config.base.sources ?? {}).length > 0 ? { sources: sortKeys(config.base.sources ?? {}) } : {},
|
|
99
|
+
...config.base.entries !== void 0 ? { entries: sortKeys(config.base.entries) } : {}
|
|
98
100
|
},
|
|
99
101
|
primitives: Object.fromEntries(Object.keys(config.primitives).sort().map((name) => {
|
|
100
102
|
const entry = config.primitives[name];
|
|
@@ -127,6 +129,8 @@ function validateConfig(raw, source) {
|
|
|
127
129
|
const base = config.base;
|
|
128
130
|
if (typeof base !== "object" || base === null || !isFileHashes(base.files)) fail("base.files missing");
|
|
129
131
|
if (base && base.version !== void 0 && typeof base.version !== "string") fail("base.version must be a string");
|
|
132
|
+
if (base && base.sources !== void 0 && !isFileHashes(base.sources)) fail("base.sources must map files to versions");
|
|
133
|
+
if (base && base.entries !== void 0 && !isFileHashes(base.entries)) fail("base.entries must map primitives to versions");
|
|
130
134
|
const primitives = config.primitives;
|
|
131
135
|
if (typeof primitives !== "object" || primitives === null) fail("primitives missing");
|
|
132
136
|
for (const [name, entry] of Object.entries(primitives)) {
|
|
@@ -136,7 +140,7 @@ function validateConfig(raw, source) {
|
|
|
136
140
|
return raw;
|
|
137
141
|
}
|
|
138
142
|
function isFileHashes(value) {
|
|
139
|
-
return typeof value === "object" && value !== null && Object.values(value).every((hash) => typeof hash === "string");
|
|
143
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((hash) => typeof hash === "string");
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
// src/kit.ts
|
|
@@ -269,6 +273,7 @@ async function loadKitFromDir(extractDir, meta) {
|
|
|
269
273
|
if (typeof primitives !== "object" || primitives === null || !Array.isArray(cascade) || typeof resolveClosure !== "function" || typeof buildHead !== "function") throw kitTooNew(meta.version, "its manifest shape is unrecognized");
|
|
270
274
|
const baseCssPre = manifestModule.BASE_CSS_PRE;
|
|
271
275
|
const baseCssPost = manifestModule.BASE_CSS_POST;
|
|
276
|
+
const baseData = manifestModule.BASE_DATA;
|
|
272
277
|
const coreRuntime = manifestModule.CORE_RUNTIME;
|
|
273
278
|
const corePolyfills = manifestModule.CORE_POLYFILLS;
|
|
274
279
|
const coreFallbacks = Array.isArray(manifestModule.CORE_FALLBACKS) ? manifestModule.CORE_FALLBACKS.filter(isRuntimeFallback) : [];
|
|
@@ -283,6 +288,7 @@ async function loadKitFromDir(extractDir, meta) {
|
|
|
283
288
|
resolveClosure,
|
|
284
289
|
...Array.isArray(baseCssPre) ? { baseCssPre } : {},
|
|
285
290
|
...Array.isArray(baseCssPost) ? { baseCssPost } : {},
|
|
291
|
+
...Array.isArray(baseData) ? { baseData } : {},
|
|
286
292
|
...Array.isArray(coreRuntime) ? { coreRuntime } : {},
|
|
287
293
|
...Array.isArray(corePolyfills) && corePolyfills.every(isRuntimePolyfill) ? { corePolyfills } : {},
|
|
288
294
|
...coreFallbacks.length > 0 ? { coreFallbacks } : {}
|
|
@@ -402,14 +408,16 @@ function scriptVariants(jsPath, language) {
|
|
|
402
408
|
return [jsPath, jsPath.replace(/\.js$/, ".d.ts")];
|
|
403
409
|
}
|
|
404
410
|
/**
|
|
405
|
-
* Everything `init` vendors: base css
|
|
406
|
-
* fallbacks, per language. TypeScript also gets
|
|
407
|
-
* the sources type-check against (the emitted
|
|
411
|
+
* Everything `init` vendors: base css, the definitions' data files, the core
|
|
412
|
+
* runtime, its polyfills, and its fallbacks, per language. TypeScript also gets
|
|
413
|
+
* the ambient `globals.d.ts` the sources type-check against (the emitted
|
|
414
|
+
* `.d.ts` files don't need it).
|
|
408
415
|
*/
|
|
409
416
|
function baseFiles(manifest, language) {
|
|
410
417
|
return [
|
|
411
418
|
...language === "ts" ? ["globals.d.ts"] : [],
|
|
412
419
|
...baseCss(manifest),
|
|
420
|
+
...manifest.baseData ?? [],
|
|
413
421
|
...[
|
|
414
422
|
...coreRuntime(manifest),
|
|
415
423
|
...corePolyfills(manifest).map((polyfill) => polyfill.file),
|
|
@@ -422,6 +430,7 @@ function primitiveFiles(entry, language, options) {
|
|
|
422
430
|
return [
|
|
423
431
|
...entry.css,
|
|
424
432
|
...entry.js.flatMap((jsPath) => scriptVariants(jsPath, language)),
|
|
433
|
+
...entry.data ? [entry.data] : [],
|
|
425
434
|
...options.examples ? entry.examples : []
|
|
426
435
|
];
|
|
427
436
|
}
|
|
@@ -729,4 +738,4 @@ function renderHead(kit, config) {
|
|
|
729
738
|
})}\n`;
|
|
730
739
|
}
|
|
731
740
|
|
|
732
|
-
export { resolveKit as _, renderIndexJs as a, createUi as c, baseCssSplit as d, baseFiles as f, kitSpec as g, loadFetchOptions as h, renderIndexCss as i, apply as l, primitiveFiles as m, insertCssImports as n, sha256 as o, baseScriptFiles as p, renderHead as r, vendorFiles as s, appendJsImports as t, describe as u,
|
|
741
|
+
export { resolveKit as _, renderIndexJs as a, filterCollisions as b, createUi as c, baseCssSplit as d, baseFiles as f, kitSpec as g, loadFetchOptions as h, renderIndexCss as i, apply as l, primitiveFiles as m, insertCssImports as n, sha256 as o, baseScriptFiles as p, renderHead as r, vendorFiles as s, appendJsImports as t, describe as u, CONFIG_NAME as v, loadConfig as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zazz-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "CLI for the Zazz Design Framework — vendors primitives from @zazz-ui/core into your project, with provenance-tracked updates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@types/pacote": "^11.1.8",
|
|
46
46
|
"tar": "^7.5.22",
|
|
47
47
|
"typescript": "^7.0.2",
|
|
48
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@
|
|
49
|
-
"vite-plus": "1.
|
|
48
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000",
|
|
49
|
+
"vite-plus": "1.7.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
package/dist/init-CKJXvUpN.js
DELETED
package/dist/update-IzwW3BFA.js
DELETED