@tensor_1/react 2.63.0 → 2.65.0
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/README.md +18 -1
- package/component-inventory.json +8 -0
- package/dist/components/AuditLog.d.ts +1 -0
- package/dist/components/Card.d.ts +1 -1
- package/dist/components/Card.js +2 -2
- package/dist/components/EditorialHome.d.ts +1 -1
- package/dist/components/EditorialHome.js +2 -2
- package/dist/components/Field.d.ts +18 -3
- package/dist/components/Field.js +6 -6
- package/dist/components/InfoTip.d.ts +9 -3
- package/dist/components/InfoTip.js +6 -2
- package/dist/components/LinkTile.d.ts +28 -0
- package/dist/components/LinkTile.js +38 -0
- package/dist/components/Markdown.d.ts +12 -2
- package/dist/components/Markdown.js +3 -2
- package/dist/components/NumberInput.d.ts +28 -0
- package/dist/components/NumberInput.js +27 -0
- package/dist/components/PageHeader.d.ts +1 -1
- package/dist/components/PageHeader.js +2 -2
- package/dist/components/StatusPill.d.ts +11 -1
- package/dist/components/StatusPill.js +7 -2
- package/dist/components/Timeline.d.ts +14 -2
- package/dist/components/Timeline.js +6 -1
- package/dist/index.cjs +3415 -3325
- package/dist/index.d.cts +123 -12
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/info-tip-model.d.ts +12 -1
- package/dist/info-tip-model.js +10 -2
- package/dist/labels-context.d.ts +10 -0
- package/dist/markdown.cjs +3 -2
- package/dist/markdown.d.cts +12 -2
- package/dist/rich-text.cjs +3 -2
- package/dist/usage-roles.d.ts +14 -1
- package/dist/usage-roles.js +11 -0
- package/package.json +9 -3
- package/page-rules/README.md +74 -0
- package/page-rules/cli.mjs +5 -0
- package/page-rules/index.mjs +158 -0
- package/page-rules/rules.mjs +669 -0
- package/page-rules/scan.mjs +281 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// UIx page rules — the product walk, the config and the shrink-only baseline (HAR-3874).
|
|
2
|
+
// ./rules.mjs judges one source at a time; this file decides which sources and
|
|
3
|
+
// what counts as new.
|
|
4
|
+
//
|
|
5
|
+
// Config: `uix-page-rules.config.json` in the product root. Every key is
|
|
6
|
+
// optional except `roots`; an unknown key is an error, so a typo never turns a
|
|
7
|
+
// rule off quietly.
|
|
8
|
+
//
|
|
9
|
+
// {
|
|
10
|
+
// "roots": ["src"], directories to walk (must exist)
|
|
11
|
+
// "baseline": "uix-page-rules-baseline.json",
|
|
12
|
+
// "skip": { "src/legacy/": "reason" }, path prefixes not scanned, each with a reason
|
|
13
|
+
// "exempt": { "no-raw-table": { "src/print/invoice.tsx": "reason" } },
|
|
14
|
+
// "genericToneHelpers": ["statusTone"], helpers that must never colour a severity
|
|
15
|
+
// "pageTitleComponents": ["PageHeader"],
|
|
16
|
+
// "rowMenuComponents": ["Menu", "ActionMenu"]
|
|
17
|
+
// }
|
|
18
|
+
//
|
|
19
|
+
// Baseline: rule → file → count. A file may only lose findings. A file above
|
|
20
|
+
// its allowance (0 when unlisted) fails; an allowance above what the file still
|
|
21
|
+
// holds fails too (stale-baseline), so paid debt leaves the baseline in the PR
|
|
22
|
+
// that paid it. A skip prefix or exemption that matches nothing fails the same way.
|
|
23
|
+
|
|
24
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
25
|
+
import { join, relative, sep } from 'node:path';
|
|
26
|
+
import {
|
|
27
|
+
COUNTED_RULES,
|
|
28
|
+
DEFAULT_OPTIONS,
|
|
29
|
+
RULE_STALE_BASELINE,
|
|
30
|
+
RULE_STALE_EXEMPTION,
|
|
31
|
+
RULES,
|
|
32
|
+
scanSource,
|
|
33
|
+
} from './rules.mjs';
|
|
34
|
+
|
|
35
|
+
export const CONFIG_FILE = 'uix-page-rules.config.json';
|
|
36
|
+
export const DEFAULT_BASELINE = 'uix-page-rules-baseline.json';
|
|
37
|
+
|
|
38
|
+
const CONFIG_KEYS = new Set([
|
|
39
|
+
'$comment',
|
|
40
|
+
'roots',
|
|
41
|
+
'baseline',
|
|
42
|
+
'skip',
|
|
43
|
+
'exempt',
|
|
44
|
+
'genericToneHelpers',
|
|
45
|
+
'pageTitleComponents',
|
|
46
|
+
'rowMenuComponents',
|
|
47
|
+
]);
|
|
48
|
+
const SKIP_DIRS = new Set([
|
|
49
|
+
'node_modules', '.next', 'dist', 'build', 'out', 'coverage', '.git', '.turbo', 'storybook-static', '.worktrees',
|
|
50
|
+
// test code, like *.test.* files, is not a page
|
|
51
|
+
'__tests__', '__mocks__', '__fixtures__',
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
/** A skip prefix covers a file or a whole directory, on a path-segment boundary (`src/legacy` never covers `src/legacy-new/`). */
|
|
55
|
+
export const underPrefix = (rel, prefix) => {
|
|
56
|
+
const p = prefix.replace(/\/+$/, '');
|
|
57
|
+
return rel === p || rel.startsWith(`${p}/`);
|
|
58
|
+
};
|
|
59
|
+
const SOURCE_RE = /\.(tsx|jsx|ts|js|mjs|css)$/;
|
|
60
|
+
const NOT_SOURCE_RE = /\.(test|spec|stories)\.[cm]?[jt]sx?$|\.d\.ts$/;
|
|
61
|
+
|
|
62
|
+
/** A config problem: the CLI reports it and exits 2, never 0. */
|
|
63
|
+
export class ConfigError extends Error {}
|
|
64
|
+
|
|
65
|
+
const toPosix = (p) => p.split(sep).join('/');
|
|
66
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string' && x.length > 0);
|
|
67
|
+
const isReasonMap = (v) =>
|
|
68
|
+
v !== null && typeof v === 'object' && !Array.isArray(v) && Object.values(v).every((r) => typeof r === 'string' && r.trim().length > 0);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Read and validate the config. Throws ConfigError on anything it cannot use.
|
|
72
|
+
* @param {string} root the product root
|
|
73
|
+
* @param {string} [file] config path relative to root
|
|
74
|
+
*/
|
|
75
|
+
export function loadConfig(root, file = CONFIG_FILE) {
|
|
76
|
+
const path = join(root, file);
|
|
77
|
+
if (!existsSync(path)) throw new ConfigError(`${file} not found in ${root}. Add one: { "roots": ["src"] }`);
|
|
78
|
+
let raw;
|
|
79
|
+
try {
|
|
80
|
+
raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new ConfigError(`${file} is not valid JSON: ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) throw new ConfigError(`${file} must hold an object.`);
|
|
85
|
+
const unknown = Object.keys(raw).filter((k) => !CONFIG_KEYS.has(k));
|
|
86
|
+
if (unknown.length) throw new ConfigError(`${file} has unknown key(s): ${unknown.join(', ')}. Known: ${[...CONFIG_KEYS].join(', ')}.`);
|
|
87
|
+
if (!isStringArray(raw.roots) || raw.roots.length === 0) throw new ConfigError(`${file}: "roots" must list at least one directory.`);
|
|
88
|
+
for (const r of raw.roots) {
|
|
89
|
+
const abs = join(root, r);
|
|
90
|
+
if (!existsSync(abs) || !statSync(abs).isDirectory()) throw new ConfigError(`${file}: root "${r}" is not a directory.`);
|
|
91
|
+
}
|
|
92
|
+
if (raw.baseline !== undefined && (typeof raw.baseline !== 'string' || !raw.baseline)) throw new ConfigError(`${file}: "baseline" must be a path.`);
|
|
93
|
+
if (raw.skip !== undefined && !isReasonMap(raw.skip)) throw new ConfigError(`${file}: "skip" maps a path prefix to its reason.`);
|
|
94
|
+
if (raw.exempt !== undefined) {
|
|
95
|
+
if (raw.exempt === null || typeof raw.exempt !== 'object' || Array.isArray(raw.exempt)) {
|
|
96
|
+
throw new ConfigError(`${file}: "exempt" maps a rule to { file: reason }.`);
|
|
97
|
+
}
|
|
98
|
+
for (const [rule, files] of Object.entries(raw.exempt)) {
|
|
99
|
+
if (!COUNTED_RULES.includes(rule)) throw new ConfigError(`${file}: "exempt" names an unknown rule "${rule}".`);
|
|
100
|
+
if (!isReasonMap(files)) throw new ConfigError(`${file}: "exempt.${rule}" maps a file to its reason.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const key of ['genericToneHelpers', 'pageTitleComponents', 'rowMenuComponents']) {
|
|
104
|
+
if (raw[key] !== undefined && !Array.isArray(raw[key])) throw new ConfigError(`${file}: "${key}" must be a list of names.`);
|
|
105
|
+
if (raw[key] !== undefined && raw[key].some((x) => typeof x !== 'string' || !/^[A-Za-z_$][\w$.]*$/.test(x))) {
|
|
106
|
+
throw new ConfigError(`${file}: "${key}" must hold identifiers.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
roots: raw.roots.map((r) => toPosix(r).replace(/\/+$/, '')),
|
|
111
|
+
baseline: raw.baseline ?? DEFAULT_BASELINE,
|
|
112
|
+
skip: raw.skip ?? {},
|
|
113
|
+
options: {
|
|
114
|
+
genericToneHelpers: raw.genericToneHelpers ?? [...DEFAULT_OPTIONS.genericToneHelpers],
|
|
115
|
+
pageTitleComponents: raw.pageTitleComponents ?? [...DEFAULT_OPTIONS.pageTitleComponents],
|
|
116
|
+
rowMenuComponents: raw.rowMenuComponents ?? [...DEFAULT_OPTIONS.rowMenuComponents],
|
|
117
|
+
exempt: raw.exempt ?? {},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Every source file under the roots, repo-relative and posix, sorted. */
|
|
123
|
+
export function listSources(root, config) {
|
|
124
|
+
const out = [];
|
|
125
|
+
const walk = (dir) => {
|
|
126
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
127
|
+
if (entry.isDirectory()) {
|
|
128
|
+
if (!SKIP_DIRS.has(entry.name)) walk(join(dir, entry.name));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!entry.isFile() || !SOURCE_RE.test(entry.name) || NOT_SOURCE_RE.test(entry.name)) continue;
|
|
132
|
+
out.push(toPosix(relative(root, join(dir, entry.name))));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
for (const r of config.roots) walk(join(root, r));
|
|
136
|
+
return [...new Set(out)].sort();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Scan the product. Returns the findings, the per-rule per-file counts, the
|
|
141
|
+
* number of files read and the config problems the tree reveals (a skip prefix
|
|
142
|
+
* or exemption that matches nothing).
|
|
143
|
+
*/
|
|
144
|
+
export function scanProject(root, config) {
|
|
145
|
+
const all = listSources(root, config);
|
|
146
|
+
const skipped = (rel) => Object.keys(config.skip).some((p) => underPrefix(rel, p));
|
|
147
|
+
const files = all.filter((rel) => !skipped(rel));
|
|
148
|
+
/** @type {import('./rules.mjs').Finding[]} */
|
|
149
|
+
const findings = [];
|
|
150
|
+
for (const rel of files) findings.push(...scanSource(rel, readFileSync(join(root, rel), 'utf8'), config.options));
|
|
151
|
+
|
|
152
|
+
const problems = [];
|
|
153
|
+
for (const prefix of Object.keys(config.skip).sort()) {
|
|
154
|
+
if (!all.some((rel) => underPrefix(rel, prefix))) {
|
|
155
|
+
problems.push(stale(RULE_STALE_EXEMPTION, `skip "${prefix}" matches no source file; delete it from the config.`));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const [rule, entries] of Object.entries(config.options.exempt)) {
|
|
159
|
+
for (const file of Object.keys(entries).sort()) {
|
|
160
|
+
if (!files.includes(file)) {
|
|
161
|
+
problems.push(stale(RULE_STALE_EXEMPTION, `exempt.${rule} names ${file}, which is not a scanned file; delete the entry.`));
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const without = { ...config.options, exempt: {} };
|
|
165
|
+
const hits = scanSource(file, readFileSync(join(root, file), 'utf8'), without).filter((f) => f.rule === rule).length;
|
|
166
|
+
if (hits === 0) problems.push(stale(RULE_STALE_EXEMPTION, `exempt.${rule} names ${file}, which no longer breaks ${rule}; delete the entry.`));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { findings, counts: countFindings(findings), filesScanned: files.length, problems };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const stale = (rule, msg) => ({ rule, file: CONFIG_FILE, line: 1, text: '', msg });
|
|
173
|
+
|
|
174
|
+
/** rule → file → count. */
|
|
175
|
+
export function countFindings(findings) {
|
|
176
|
+
const counts = {};
|
|
177
|
+
for (const f of findings) {
|
|
178
|
+
counts[f.rule] ??= {};
|
|
179
|
+
counts[f.rule][f.file] = (counts[f.rule][f.file] ?? 0) + 1;
|
|
180
|
+
}
|
|
181
|
+
return counts;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The baseline counts (empty when the file is missing). Throws ConfigError when it is unreadable. */
|
|
185
|
+
export function loadBaseline(root, config) {
|
|
186
|
+
const path = join(root, config.baseline);
|
|
187
|
+
if (!existsSync(path)) return { exists: false, rules: {} };
|
|
188
|
+
let doc;
|
|
189
|
+
try {
|
|
190
|
+
doc = JSON.parse(readFileSync(path, 'utf8'));
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new ConfigError(`${config.baseline} is not valid JSON: ${error.message}`);
|
|
193
|
+
}
|
|
194
|
+
const rules = doc?.rules;
|
|
195
|
+
if (rules === null || typeof rules !== 'object' || Array.isArray(rules)) throw new ConfigError(`${config.baseline} has no "rules" object.`);
|
|
196
|
+
for (const [rule, files] of Object.entries(rules)) {
|
|
197
|
+
if (!COUNTED_RULES.includes(rule)) throw new ConfigError(`${config.baseline} names an unknown rule "${rule}".`);
|
|
198
|
+
if (files === null || typeof files !== 'object' || Array.isArray(files)) {
|
|
199
|
+
throw new ConfigError(`${config.baseline}: "${rule}" must map files to counts.`);
|
|
200
|
+
}
|
|
201
|
+
for (const n of Object.values(files)) {
|
|
202
|
+
if (!Number.isInteger(n) || n < 1) throw new ConfigError(`${config.baseline}: every ${rule} count must be a whole number ≥ 1.`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { exists: true, rules };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Compare a scan with the baseline. Returns the violations: every finding in a
|
|
210
|
+
* file above its allowance (all of that file's findings for the rule, so the
|
|
211
|
+
* new one is among them), and every allowance the tree no longer reaches.
|
|
212
|
+
*/
|
|
213
|
+
export function evaluate(scan, baseline) {
|
|
214
|
+
const violations = [...scan.problems];
|
|
215
|
+
const byKey = new Map();
|
|
216
|
+
for (const f of scan.findings) {
|
|
217
|
+
const key = `${f.rule}\u0000${f.file}`;
|
|
218
|
+
if (!byKey.has(key)) byKey.set(key, []);
|
|
219
|
+
byKey.get(key).push(f);
|
|
220
|
+
}
|
|
221
|
+
for (const rule of COUNTED_RULES) {
|
|
222
|
+
const have = scan.counts[rule] ?? {};
|
|
223
|
+
const allowed = baseline.rules[rule] ?? {};
|
|
224
|
+
for (const file of Object.keys(have).sort()) {
|
|
225
|
+
const limit = allowed[file] ?? 0;
|
|
226
|
+
if (have[file] <= limit) continue;
|
|
227
|
+
for (const f of byKey.get(`${rule}\u0000${file}`)) {
|
|
228
|
+
violations.push({ ...f, msg: `${f.msg} (${have[file]} in this file, ${limit} grandfathered)` });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const file of Object.keys(allowed).sort()) {
|
|
232
|
+
const n = have[file] ?? 0;
|
|
233
|
+
if (n >= allowed[file]) continue;
|
|
234
|
+
violations.push({
|
|
235
|
+
rule: RULE_STALE_BASELINE,
|
|
236
|
+
file,
|
|
237
|
+
line: 1,
|
|
238
|
+
text: '',
|
|
239
|
+
msg: `the baseline allows ${allowed[file]} × ${rule} here and ${n} are left; regenerate it so it shrinks.`,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return violations;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The baseline document for a scan. */
|
|
247
|
+
export function baselineDocument(counts) {
|
|
248
|
+
const rules = {};
|
|
249
|
+
let total = 0;
|
|
250
|
+
for (const rule of COUNTED_RULES) {
|
|
251
|
+
const files = counts[rule] ?? {};
|
|
252
|
+
const names = Object.keys(files).sort();
|
|
253
|
+
if (!names.length) continue;
|
|
254
|
+
rules[rule] = Object.fromEntries(names.map((f) => [f, files[f]]));
|
|
255
|
+
total += names.reduce((sum, f) => sum + files[f], 0);
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
$comment:
|
|
259
|
+
'Grandfathered UIx page-rule debt (@tensor_1/react page-rules, HAR-3874). Counts per rule per file; it only shrinks. Fix a finding, then run `uix-page-rules baseline`.',
|
|
260
|
+
generatedBy: 'uix-page-rules baseline',
|
|
261
|
+
total,
|
|
262
|
+
rules,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Where a regenerated baseline would grow: a file above its current allowance.
|
|
268
|
+
* The generator refuses to write these unless it is seeding on purpose.
|
|
269
|
+
*/
|
|
270
|
+
export function growth(counts, baseline) {
|
|
271
|
+
const out = [];
|
|
272
|
+
for (const rule of COUNTED_RULES) {
|
|
273
|
+
for (const [file, n] of Object.entries(counts[rule] ?? {})) {
|
|
274
|
+
const limit = baseline.rules[rule]?.[file] ?? 0;
|
|
275
|
+
if (n > limit) out.push(`${rule}: ${file} (${limit} → ${n})`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return out.sort();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { RULES };
|