Skip to content

+ proj: derive the zui keyword from lib type and guard it - #246

Merged
catouse merged 2 commits into
dev_optimizefrom
dev_optimize_lib_keywords
Aug 31, 2026
Merged

+ proj: derive the zui keyword from lib type and guard it#246
catouse merged 2 commits into
dev_optimizefrom
dev_optimize_lib_keywords

Conversation

@Lwrless

@Lwrless Lwrless commented Aug 24, 2026

Copy link
Copy Markdown
Member

52 of 65 lib manifests disagreed with their own zui.type. This fixes them and adds a
guard so they cannot drift again.

The state before

Group n
zui: entry naming a different type 29
keywords present, no zui: entry 8
no keywords field at all 15
consistent 13

Two of the 29 were not drift but one-off strings matching no type at all: progress said
zui:css-progress and progress-circle said zui:js-progress-circle.

Why guard rather than just fix

keywords is read by nothing in this repo. scripts/libs/query.ts:106-137 groups and
orders libs from zui.type alone, and the field appears nowhere in scripts/,
vite.config.ts or tailwind.config.cjs. That is precisely why it drifted — nothing was
holding it in step, so fixing it once only resets the clock.

Deleting the field would have been equally defensible. Keeping it and deriving it means
the metadata stays true without anyone having to remember it.

Design

scripts/libs/check-keywords.ts is one rule with writes optionally enabled, so the
generator and the guard cannot disagree:

  • checkLibKeywords(manifests) is pure and returns violations.
  • --fix is that same check applied, then re-run to confirm it converged.
  • pnpm lib:keywords checks; pnpm lib:keywords --fix rewrites.

tests/unit/lib-keywords.test.ts asserts zero violations across every manifest under
lib/, comparing violation messages rather than a count so a failure names the libs
that drifted. It sits in the existing unit project, so pnpm check already runs it with
no script changes. Exts are excluded from the scan — they are gitignored and absent on CI,
so including them would make the result depend on the machine.

Scope of the rule

The zui: entry only. Free-form keywords (css, js, components) are left exactly as
they are, in order, and an existing zui: entry keeps its position. lib/table claims
js while shipping none — out of scope here, and left alone rather than quietly changed.

Commit order

The manifest churn comes first, the tooling second, so every commit in the series
passes pnpm check. Rule-first would leave one commit red for git bisect.

Verification

  • Both directions. Corrupting lib/panel's entry to zui:control fails the test with
    a message naming panel; --fix restores the file byte-identically.
  • Idempotent. A second --fix reports all 65 clean and produces no further diff.
  • Nothing but keywords moved. Comparing each manifest against its parent shows 0
    changes to any other key and 0 changes to key order — checked programmatically.
  • No behaviour change, confirmed rather than assumed: pnpm build output is identical
    across all 22 artifacts. The 20 CSS files are byte-identical; zui.js and zui.esm.js
    differ only in the embedded git hash and a wall-clock build stamp, which every build
    embeds regardless of this change.
  • pnpm check green: 10 test files / 76 tests, up from 9 / 60.

Rebased onto origin/dev_optimize @ 68d7e165d7. No file overlap with the six upstream
commits, and none with #243.

52 of 65 lib manifests disagreed with their own `zui.type`, in three ways:

- 29 carried a `zui:` entry naming a different type (`panel` said `zui:control`
  while its type is `component`; `progress` and `progress-circle` said
  `zui:css-progress` and `zui:js-progress-circle`, which are not types at all).
- 8 had `keywords` but no `zui:` entry.
- 15 had no `keywords` field.

Every manifest now carries exactly one `zui:<type>` entry matching `zui.type`.

This is the mechanical half, generated by `scripts/libs/check-keywords.ts --fix`,
which lands with its guard in the next commit. It comes first so that every
commit in the series passes `pnpm check`.

## Scope

Only the `zui:` entry. Free-form keywords (`css`, `js`, `components`) are left
exactly as they are, in their existing order, and an existing `zui:` entry keeps
its position in the array. Where the field was absent it is inserted after
`browserslist`, `browser` or `version`, which is where the 50 manifests that
already had it put it.

Verified that no line outside a `keywords` array moved: comparing each manifest
against its parent shows 0 changes to any other key, and 0 changes to key order.

`lib/table` declares `keywords: ["css", "js", "components"]` while shipping no
JS. Free-form keyword accuracy is outside this rule's scope, so it is left
alone rather than quietly corrected here.

## No behaviour change

`keywords` is read by nothing in this repo — `scripts/libs/query.ts:106-137`
groups and orders libs from `zui.type` alone, and the field appears nowhere in
`scripts/`, `vite.config.ts` or `tailwind.config.cjs`. This changes published
metadata only.
`keywords` is read by nothing in this repo, so nothing kept it in step with
`zui.type` and 52 of 65 manifests had drifted apart. Fixing them once only
resets the clock; this makes the drift fail the build instead.

## Design

`scripts/libs/check-keywords.ts` is one rule with writes optionally enabled, so
the generator and the guard cannot disagree:

- `checkLibKeywords(manifests)` is pure and returns a list of violations.
- `--fix` is the same check applied, then re-run to confirm it converged.
- `pnpm lib:keywords` runs it; `pnpm lib:keywords --fix` rewrites.

`tests/unit/lib-keywords.test.ts` asserts zero violations across every manifest
under `lib/`, and compares the violation *messages* rather than a count so a
failure names the libs that drifted. It sits in the existing `unit` project, so
`pnpm check` already runs it with no script changes.

Exts are deliberately excluded from the scan: they are gitignored and absent
on CI, so including them would make the guard's result depend on the machine.

## Writes stay surgical

`--fix` edits the `keywords` array as text rather than re-serializing the
manifest — a JSON round-trip expands the inline arrays this repo uses and turns
a one-line diff into a whole-file rewrite. It preserves inline vs. multi-line
arrays, indentation and CRLF endings, all covered by tests.

## Verified in both directions

Corrupting `lib/panel`'s entry to `zui:control` fails the test with a message
naming `panel`, and `--fix` restores the file byte-identically. `--fix` is
idempotent: a second run reports all 65 clean and produces no further diff.

An unusable `zui.type` is reported as `invalid-type` and marked unfixable
rather than guessed at — `query.ts:106` already rejects those at build time.
@catouse
catouse marked this pull request as ready for review August 31, 2026 02:49
@catouse
catouse merged commit a4cd6be into dev_optimize Aug 31, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants