@reqvire-org/ads 0.5.17 → 0.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ads-errors.mjs +1 -1
- package/dist/analysis/syntax.mjs +10 -0
- package/dist/design-usage.mjs +31 -2
- package/dist/guard/components.mjs +235 -0
- package/dist/guard/run.mjs +3 -3
- package/dist/render-audit/worker.mjs +17 -9
- package/dist/render-audit/worker.page.mjs +18 -0
- package/dist/render-audit.mjs +1 -0
- package/dist/skills/ads-designer/references/scenarios.md +9 -2
- package/dist/skills/ads-designer/references/stress-test.md +2 -1
- package/dist/skills/ads-import/references/scenarios.md +9 -2
- package/dist/skills/ads-port/references/scenarios.md +9 -2
- package/docs/CHANGELOG.md +121 -0
- package/docs/GUIDE.md +19 -1
- package/package.json +1 -1
package/dist/ads-errors.mjs
CHANGED
|
@@ -2726,7 +2726,7 @@ export const runtimeErrors = {
|
|
|
2726
2726
|
guides: ["ads://guides/tokens", "ads://guides/layout"],
|
|
2727
2727
|
repair: "Make the element fluid (%, fr, min(100%, ...)), wrap it or scroll it with overflow-x: auto.",
|
|
2728
2728
|
emitters: ["src/render-audit.mts"],
|
|
2729
|
-
situations:
|
|
2729
|
+
situations: `the same overflow kinds as layout-overflow, measured in the container render (first theme, widest viewport). A review, except kind "escaped": a control spilling over its own painted box is an error in a narrow pane too. A page section (its outermost grid lays out differently at a phone's and a desktop's viewport inside the 240 px container) is not measured: a render-audit-skipped info item names it. Code passes guidanceUri ads://guides/tokens.`
|
|
2730
2730
|
},
|
|
2731
2731
|
"layout-shift": {
|
|
2732
2732
|
group: "rendered-check",
|
package/dist/analysis/syntax.mjs
CHANGED
|
@@ -97,6 +97,16 @@ export async function parseSource(file, text, scriptKind) {
|
|
|
97
97
|
return (await lease).sourceFile;
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
export function withOpenFiles(files, run) {
|
|
101
|
+
return use(async (current) => {
|
|
102
|
+
const snapshot = await current.createSnapshot({ openFiles: files.map((file) => path.resolve(file)) });
|
|
103
|
+
try {
|
|
104
|
+
return await run(snapshot);
|
|
105
|
+
} finally {
|
|
106
|
+
await snapshot.dispose();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
100
110
|
export function parseConfigText(file, text) {
|
|
101
111
|
return use(async (current) => {
|
|
102
112
|
const virtual = path.resolve(path.dirname(file), `.ads-config-${++sequence}.json`);
|
package/dist/design-usage.mjs
CHANGED
|
@@ -2,14 +2,23 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { isExportDeclaration, isNamedExports, isStringLiteral } from "typescript/ast";
|
|
4
4
|
import { designUsageProblems } from "./analysis/design-usage.mjs";
|
|
5
|
-
import { closeSyntax, parseSource } from "./analysis/syntax.mjs";
|
|
5
|
+
import { closeSyntax, parseSource, withOpenFiles } from "./analysis/syntax.mjs";
|
|
6
|
+
import { typedDesignUsage } from "./guard/components.mjs";
|
|
6
7
|
const wording = {
|
|
7
8
|
"design-import": (problem) => [`${problem.specifier} authors design, which belongs to the design system.`, "Declare the design in the design system and import the owner from its public entry."],
|
|
8
9
|
"component-outside-pattern": (problem) => [
|
|
9
10
|
`The component ${problem.name} is rendered outside every pattern, so nothing owns its place on the screen.`,
|
|
10
11
|
"Render it inside the pattern that arranges this screen (as its child or in a slot prop); if no pattern does, add one to the design system."
|
|
11
12
|
],
|
|
12
|
-
"local-markup": (problem) => [`<${problem.tag}> is
|
|
13
|
+
"local-markup": (problem) => [`<${problem.tag}> is markup the application creates itself, not a design-system owner.`, "Render a design-system owner; an arrangement or element the screen needs belongs in a pattern of the design system."],
|
|
14
|
+
"unlisted-component": (problem) => [
|
|
15
|
+
`${problem.name} is a component of ${problem.from}, which the guard does not list: its markup and styles are not the design system's.`,
|
|
16
|
+
`Render a design-system owner instead. If it renders no design of its own (a router's outlet, a provider, Suspense), list it in "allow" under "${problem.from}".`
|
|
17
|
+
],
|
|
18
|
+
"unchecked-component": (problem) => [
|
|
19
|
+
`${problem.name} is declared in ${problem.file}, which the guard does not check, so its markup and styles are not seen.`,
|
|
20
|
+
`Check that file too (in the guard's "include", not "exclude"), or render a design-system owner.`
|
|
21
|
+
],
|
|
13
22
|
"spread-props": () => ["A spread passes props nothing can see.", "Pass each prop explicitly."],
|
|
14
23
|
"design-prop": (problem) => [`${problem.attribute} supplies design from outside the design system.`, "Remove it; choose the treatment through the owner's own props."],
|
|
15
24
|
"imperative-design": (problem) => [`${problem.member} writes styles or creates DOM by hand.`, "Remove the write; render design-system owners with props."],
|
|
@@ -29,6 +38,26 @@ export async function checkDesignUsage(sources, entry, allowance = {}) {
|
|
|
29
38
|
}
|
|
30
39
|
return findings;
|
|
31
40
|
}
|
|
41
|
+
export async function checkApplicationDesignUsage(root, files, entry, designSystem, allowance = {}) {
|
|
42
|
+
const absolute = files.map((file) => path.resolve(root, file));
|
|
43
|
+
if (absolute.length === 0)
|
|
44
|
+
return [];
|
|
45
|
+
const scope = { root: path.resolve(root), checked: new Set(absolute), designSystem: path.resolve(designSystem), publicEntry: entry.publicEntry, allow: allowance.components ?? new Map };
|
|
46
|
+
return withOpenFiles(absolute, async (snapshot) => {
|
|
47
|
+
const findings = [];
|
|
48
|
+
for (const [index, file] of absolute.entries()) {
|
|
49
|
+
const project = await snapshot.getDefaultProjectForFile(file), source = project === void 0 ? void 0 : await project.program.getSourceFile(file);
|
|
50
|
+
if (project === void 0 || source === void 0)
|
|
51
|
+
throw Error(`TypeScript could not open ${files[index]} in a project.`);
|
|
52
|
+
const syntactic = designUsageProblems(source, entry, allowance);
|
|
53
|
+
for (const { node, problem } of await typedDesignUsage(source, project.checker, scope, syntactic)) {
|
|
54
|
+
const at = source.getLineAndCharacterOfPosition(node.getStart(source)), [message, repair] = describe(problem);
|
|
55
|
+
findings.push({ file: files[index] ?? file, line: at.line + 1, column: at.character + 1, code: `design-usage/${problem.kind}`, message, repair });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return findings;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
32
61
|
export async function designSystemEntry(publicEntry, entryFile) {
|
|
33
62
|
const source = await parseSource(path.resolve(entryFile), readFileSync(entryFile, "utf8")), patterns = new Set;
|
|
34
63
|
for (const statement of source.statements) {
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
SyntaxKind,
|
|
4
|
+
isArrowFunction,
|
|
5
|
+
isCallExpression,
|
|
6
|
+
isFunctionExpression,
|
|
7
|
+
isIdentifier,
|
|
8
|
+
isImportDeclaration,
|
|
9
|
+
isJsxElement,
|
|
10
|
+
isJsxOpeningElement,
|
|
11
|
+
isJsxSelfClosingElement,
|
|
12
|
+
isNamedImports,
|
|
13
|
+
isNamespaceImport,
|
|
14
|
+
isNoSubstitutionTemplateLiteral,
|
|
15
|
+
isObjectLiteralExpression,
|
|
16
|
+
isArrayLiteralExpression,
|
|
17
|
+
isPropertyAccessExpression,
|
|
18
|
+
isStringLiteral,
|
|
19
|
+
isTaggedTemplateExpression,
|
|
20
|
+
isTemplateExpression
|
|
21
|
+
} from "typescript/ast";
|
|
22
|
+
import { SignatureKind, SymbolFlags, TypeFlags } from "typescript/async";
|
|
23
|
+
const FRAMEWORK_FACTORIES = new Set(["h", "createElement", "jsx", "jsxs", "jsxDEV"]), NOT_A_VALUE = TypeFlags.Any | TypeFlags.Unknown | TypeFlags.Never | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null, intrinsic = (tag) => /^[a-z]/.test(tag) && !tag.includes("."), relative = (specifier) => specifier.startsWith(".") || specifier.startsWith("/"), walk = (node, visit) => {
|
|
24
|
+
visit(node);
|
|
25
|
+
node.forEachChild((child) => walk(child, visit));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class FileReading {
|
|
29
|
+
source;
|
|
30
|
+
checker;
|
|
31
|
+
scope;
|
|
32
|
+
#element;
|
|
33
|
+
constructor(source, checker, scope) {
|
|
34
|
+
this.source = source;
|
|
35
|
+
this.checker = checker;
|
|
36
|
+
this.scope = scope;
|
|
37
|
+
}
|
|
38
|
+
async element() {
|
|
39
|
+
if (this.#element !== void 0)
|
|
40
|
+
return this.#element;
|
|
41
|
+
let first;
|
|
42
|
+
walk(this.source, (node) => {
|
|
43
|
+
if (first === void 0 && (isJsxElement(node) || isJsxSelfClosingElement(node)))
|
|
44
|
+
first = node;
|
|
45
|
+
});
|
|
46
|
+
this.#element = first === void 0 ? null : await this.checker.getTypeAtLocation(first);
|
|
47
|
+
if (this.#element !== null && (this.#element.flags & NOT_A_VALUE) !== 0)
|
|
48
|
+
this.#element = null;
|
|
49
|
+
return this.#element;
|
|
50
|
+
}
|
|
51
|
+
async renders(type, depth = 0) {
|
|
52
|
+
if ((type.flags & NOT_A_VALUE) !== 0 || depth > 2)
|
|
53
|
+
return !1;
|
|
54
|
+
if ((type.flags & TypeFlags.Union) !== 0) {
|
|
55
|
+
for (const member of await type.getTypes() ?? [])
|
|
56
|
+
if (await this.renders(member, depth + 1))
|
|
57
|
+
return !0;
|
|
58
|
+
return !1;
|
|
59
|
+
}
|
|
60
|
+
const element = await this.element();
|
|
61
|
+
if (element === null)
|
|
62
|
+
return !1;
|
|
63
|
+
for (const signature of await this.checker.getSignaturesOfType(type, SignatureKind.Call)) {
|
|
64
|
+
const result = await this.checker.getReturnTypeOfSignature(signature);
|
|
65
|
+
if ((result.flags & NOT_A_VALUE) === 0 && await this.checker.isTypeAssignableTo(element, result))
|
|
66
|
+
return !0;
|
|
67
|
+
}
|
|
68
|
+
for (const signature of await this.checker.getSignaturesOfType(type, SignatureKind.Construct)) {
|
|
69
|
+
const instance = await this.checker.getReturnTypeOfSignature(signature);
|
|
70
|
+
if ((await this.checker.getPropertiesOfType(instance)).some((property) => property.name === "render"))
|
|
71
|
+
return !0;
|
|
72
|
+
}
|
|
73
|
+
return !1;
|
|
74
|
+
}
|
|
75
|
+
async origin(node) {
|
|
76
|
+
let symbol = await this.checker.getSymbolAtLocation(node);
|
|
77
|
+
if (symbol === void 0)
|
|
78
|
+
return { kind: "unknown" };
|
|
79
|
+
if ((symbol.flags & SymbolFlags.Alias) !== 0)
|
|
80
|
+
symbol = await this.checker.getAliasedSymbol(symbol);
|
|
81
|
+
const files = symbol.declarations.map((declaration) => path.resolve(String(declaration.path)));
|
|
82
|
+
if (files.length === 0)
|
|
83
|
+
return { kind: "unknown" };
|
|
84
|
+
if (files.some((file) => this.#checked(file)))
|
|
85
|
+
return { kind: "application" };
|
|
86
|
+
if (files.some((file) => this.#inDesignSystem(file)))
|
|
87
|
+
return { kind: "design-system" };
|
|
88
|
+
return { kind: "elsewhere", file: files[0] ?? "" };
|
|
89
|
+
}
|
|
90
|
+
#checked(file) {
|
|
91
|
+
return this.scope.checked.has(file) || [...this.scope.checked].some((checked) => checked.toLowerCase() === file.toLowerCase());
|
|
92
|
+
}
|
|
93
|
+
#inDesignSystem(file) {
|
|
94
|
+
const folder = this.scope.designSystem.toLowerCase() + path.sep;
|
|
95
|
+
return file.toLowerCase().startsWith(folder);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function packageOf(file) {
|
|
99
|
+
const parts = file.split(path.sep), at = parts.lastIndexOf("node_modules");
|
|
100
|
+
if (at < 0)
|
|
101
|
+
return file;
|
|
102
|
+
const first = parts[at + 1] ?? "";
|
|
103
|
+
return first.startsWith("@") ? `${first}/${parts[at + 2] ?? ""}` : first;
|
|
104
|
+
}
|
|
105
|
+
export async function typedDesignUsage(source, checker, scope, syntactic) {
|
|
106
|
+
const reading = new FileReading(source, checker, scope), settled = [], imported = new Map, namespaces = new Map, flagged = new Set, flaggedNames = new Set;
|
|
107
|
+
for (const statement of source.statements) {
|
|
108
|
+
if (!isImportDeclaration(statement) || !isStringLiteral(statement.moduleSpecifier) || statement.importClause?.phaseModifier === SyntaxKind.TypeKeyword)
|
|
109
|
+
continue;
|
|
110
|
+
const specifier = statement.moduleSpecifier.text;
|
|
111
|
+
if (relative(specifier) || specifier === scope.publicEntry || specifier.startsWith("node:"))
|
|
112
|
+
continue;
|
|
113
|
+
const clause = statement.importClause;
|
|
114
|
+
if (clause === void 0)
|
|
115
|
+
continue;
|
|
116
|
+
if (clause.name !== void 0)
|
|
117
|
+
imported.set(clause.name.text, [specifier, "default"]);
|
|
118
|
+
const bindings = clause.namedBindings;
|
|
119
|
+
if (bindings !== void 0 && isNamespaceImport(bindings))
|
|
120
|
+
namespaces.set(bindings.name.text, specifier);
|
|
121
|
+
else if (bindings !== void 0 && isNamedImports(bindings)) {
|
|
122
|
+
for (const element of bindings.elements)
|
|
123
|
+
if (!element.isTypeOnly)
|
|
124
|
+
imported.set(element.name.text, [specifier, (element.propertyName ?? element.name).text]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const allowed = (specifier, name) => scope.allow.get(specifier)?.has(name) === !0, unlisted = (node, name, from) => {
|
|
128
|
+
if (flagged.has(node))
|
|
129
|
+
return;
|
|
130
|
+
flagged.add(node);
|
|
131
|
+
settled.push({ node, problem: { kind: "unlisted-component", name, from } });
|
|
132
|
+
};
|
|
133
|
+
for (const statement of source.statements) {
|
|
134
|
+
if (!isImportDeclaration(statement) || !isStringLiteral(statement.moduleSpecifier))
|
|
135
|
+
continue;
|
|
136
|
+
const clause = statement.importClause;
|
|
137
|
+
if (clause === void 0 || clause.phaseModifier === SyntaxKind.TypeKeyword)
|
|
138
|
+
continue;
|
|
139
|
+
const names = [clause.name, ...clause.namedBindings !== void 0 && isNamedImports(clause.namedBindings) ? clause.namedBindings.elements.filter((element) => !element.isTypeOnly).map((element) => element.name) : []];
|
|
140
|
+
for (const name of names) {
|
|
141
|
+
if (name === void 0)
|
|
142
|
+
continue;
|
|
143
|
+
const binding = imported.get(name.text);
|
|
144
|
+
if (binding === void 0 || allowed(...binding) || FRAMEWORK_FACTORIES.has(binding[1]))
|
|
145
|
+
continue;
|
|
146
|
+
if (await reading.renders(await checker.getTypeAtLocation(name))) {
|
|
147
|
+
unlisted(name, binding[1] === "default" ? name.text : binding[1], binding[0]);
|
|
148
|
+
flaggedNames.add(name.text);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const designProblems = new Map;
|
|
153
|
+
for (const usage of syntactic) {
|
|
154
|
+
if (usage.problem.kind !== "local-markup") {
|
|
155
|
+
settled.push(usage);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
designProblems.set(usage.node, usage);
|
|
159
|
+
}
|
|
160
|
+
const members = [];
|
|
161
|
+
walk(source, (node) => {
|
|
162
|
+
if (isPropertyAccessExpression(node) && isIdentifier(node.expression)) {
|
|
163
|
+
const base = node.expression.text, specifier = namespaces.get(base) ?? imported.get(base)?.[0];
|
|
164
|
+
if (specifier !== void 0 && !allowed(specifier, node.name.text))
|
|
165
|
+
members.push(node);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
for (const member of members) {
|
|
169
|
+
if (!isPropertyAccessExpression(member) || !isIdentifier(member.expression))
|
|
170
|
+
continue;
|
|
171
|
+
const specifier = namespaces.get(member.expression.text) ?? imported.get(member.expression.text)?.[0] ?? "";
|
|
172
|
+
if (flaggedNames.has(member.expression.text))
|
|
173
|
+
continue;
|
|
174
|
+
if (await reading.renders(await checker.getTypeAtLocation(member)))
|
|
175
|
+
unlisted(member, `${member.expression.text}.${member.name.text}`, specifier);
|
|
176
|
+
}
|
|
177
|
+
const calls = [];
|
|
178
|
+
walk(source, (node) => {
|
|
179
|
+
if (isCallExpression(node) || isTaggedTemplateExpression(node))
|
|
180
|
+
calls.push(node);
|
|
181
|
+
});
|
|
182
|
+
for (const call of calls) {
|
|
183
|
+
const callee = isCallExpression(call) ? call.expression : isTaggedTemplateExpression(call) ? call.tag : void 0;
|
|
184
|
+
if (callee === void 0)
|
|
185
|
+
continue;
|
|
186
|
+
const root = isIdentifier(callee) ? callee : isPropertyAccessExpression(callee) && isIdentifier(callee.expression) ? callee.expression : void 0;
|
|
187
|
+
if (root === void 0)
|
|
188
|
+
continue;
|
|
189
|
+
const specifier = imported.get(root.text)?.[0] ?? namespaces.get(root.text);
|
|
190
|
+
if (specifier === void 0)
|
|
191
|
+
continue;
|
|
192
|
+
const name = isIdentifier(callee) ? imported.get(callee.text)?.[1] ?? callee.text : isPropertyAccessExpression(callee) ? callee.name.text : "";
|
|
193
|
+
if (isCallExpression(call) && FRAMEWORK_FACTORIES.has(name)) {
|
|
194
|
+
const [first] = call.arguments;
|
|
195
|
+
if (first !== void 0 && (isStringLiteral(first) || isNoSubstitutionTemplateLiteral(first) || ((await checker.getTypeAtLocation(first)).flags & TypeFlags.StringLike) !== 0))
|
|
196
|
+
settled.push({ node: call, problem: { kind: "local-markup", tag: isStringLiteral(first) || isNoSubstitutionTemplateLiteral(first) ? first.text : first.getText() } });
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (allowed(specifier, name))
|
|
200
|
+
continue;
|
|
201
|
+
if (!await reading.renders(await checker.getTypeAtLocation(call)))
|
|
202
|
+
continue;
|
|
203
|
+
const literal = (argument) => isStringLiteral(argument) || isNoSubstitutionTemplateLiteral(argument) || isTemplateExpression(argument) || isObjectLiteralExpression(argument) || isArrayLiteralExpression(argument), args = isCallExpression(call) ? [...call.arguments] : [];
|
|
204
|
+
if (!(!isTaggedTemplateExpression(call) && args.length > 0 && args.every((argument) => !literal(argument)) && (await Promise.all(args.map(async (argument) => isArrowFunction(argument) || isFunctionExpression(argument) || (await reading.origin(argument)).kind !== "elsewhere"))).every(Boolean)))
|
|
205
|
+
unlisted(call, name, specifier);
|
|
206
|
+
}
|
|
207
|
+
for (const [node, usage] of designProblems) {
|
|
208
|
+
if (usage.problem.kind !== "local-markup")
|
|
209
|
+
continue;
|
|
210
|
+
const tag = isJsxOpeningElement(node) || isJsxSelfClosingElement(node) ? node.tagName : void 0;
|
|
211
|
+
if (tag === void 0 || intrinsic(usage.problem.tag)) {
|
|
212
|
+
settled.push(usage);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (((await checker.getTypeAtLocation(tag)).flags & TypeFlags.StringLike) !== 0) {
|
|
216
|
+
settled.push(usage);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const root = isIdentifier(tag) ? tag : isPropertyAccessExpression(tag) && isIdentifier(tag.expression) ? tag.expression : void 0;
|
|
220
|
+
if (root !== void 0 && (imported.has(root.text) || namespaces.has(root.text))) {
|
|
221
|
+
const [specifier, name] = imported.get(root.text) ?? [namespaces.get(root.text) ?? "", root.text], exported = isPropertyAccessExpression(tag) ? tag.name.text : name;
|
|
222
|
+
if (!allowed(specifier, exported) && !flaggedNames.has(root.text) && !flagged.has(tag))
|
|
223
|
+
unlisted(tag, isPropertyAccessExpression(tag) ? tag.getText() : exported, specifier);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const origin = await reading.origin(tag);
|
|
227
|
+
if (origin.kind !== "elsewhere")
|
|
228
|
+
continue;
|
|
229
|
+
if (origin.file.split(path.sep).includes("node_modules"))
|
|
230
|
+
unlisted(tag, tag.getText(), packageOf(origin.file));
|
|
231
|
+
else
|
|
232
|
+
settled.push({ node: tag, problem: { kind: "unchecked-component", name: tag.getText(), file: path.relative(scope.root, origin.file).split(path.sep).join("/") } });
|
|
233
|
+
}
|
|
234
|
+
return settled.sort((a, b) => a.node.pos - b.node.pos);
|
|
235
|
+
}
|
package/dist/guard/run.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { checkApplicationDesignUsage, designSystemEntry } from "../design-usage.mjs";
|
|
5
5
|
import { err, ok } from "../result.mjs";
|
|
6
6
|
import { readGuardConfig } from "./config.mjs";
|
|
7
7
|
import { guardScope } from "./files.mjs";
|
|
@@ -30,7 +30,7 @@ export async function runGuard(root) {
|
|
|
30
30
|
const located = entryFile(absolute, config.value);
|
|
31
31
|
if (located.kind === "err")
|
|
32
32
|
return err([located.error]);
|
|
33
|
-
const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null),
|
|
33
|
+
const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null), findings = await checkApplicationDesignUsage(absolute, scope.files, entry, folder, { components: config.value.allow, metadata: !0 }), inside = located.value.startsWith(absolute + path.sep), externals = await verifyExternals(absolute, located.value);
|
|
34
34
|
return ok({
|
|
35
35
|
ok: findings.length === 0 && externals.every((item) => item.problem === null),
|
|
36
36
|
designSystem: config.value.designSystem,
|
|
@@ -12,7 +12,7 @@ import { cornerOverpaint } from "./corner-overpaint.page.mjs";
|
|
|
12
12
|
import { forcedStates } from "./forced-states.page.mjs";
|
|
13
13
|
import { overflowOnly, overridePasses, viewportPasses } from "./text-scale.mjs";
|
|
14
14
|
import { auditRenderStates, listTargets } from "./render-states.mjs";
|
|
15
|
-
import { brandReady, hasAxe, hasMainLandmark, markRenderAudit, setScenarioState, themeReady } from "./worker.page.mjs";
|
|
15
|
+
import { brandReady, hasAxe, hasMainLandmark, outermostGridLayout, markRenderAudit, setScenarioState, themeReady } from "./worker.page.mjs";
|
|
16
16
|
const argument = process.argv[2];
|
|
17
17
|
if (!argument)
|
|
18
18
|
throw Error("The render audit worker needs its request file as its first argument.");
|
|
@@ -238,15 +238,23 @@ try {
|
|
|
238
238
|
delete result.derivedCorners;
|
|
239
239
|
if (app.container && !await frame.evaluate(hasMainLandmark)) {
|
|
240
240
|
await frame.addStyleTag({ content: `#root { inline-size: ${app.container}px; }` });
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
241
|
+
const wide = await frame.evaluate(outermostGridLayout), widest = request.overflowWidths.at(-1) ?? request.overflowWidths[0];
|
|
242
|
+
await page.setViewportSize({ width: request.overflowWidths[0], height: request.viewport.height });
|
|
243
|
+
const narrow = await frame.evaluate(outermostGridLayout);
|
|
244
|
+
await page.setViewportSize({ width: widest, height: request.viewport.height });
|
|
245
|
+
if (wide !== null && wide !== narrow)
|
|
246
|
+
coverage.skipped.push({ reason: "page-section", name: "the 240 px pane render" });
|
|
247
|
+
else {
|
|
248
|
+
const options = { nodeLimit: request.nodeLimit, container: app.container, smallPart: request.smallPart };
|
|
249
|
+
let narrowed = await frame.evaluate(layoutOverflow, { ...options, width: widest });
|
|
250
|
+
if (narrowed.issues.length) {
|
|
251
|
+
await page.setViewportSize({ width: request.overflowWidths[0], height: request.viewport.height });
|
|
252
|
+
const folded = await frame.evaluate(layoutOverflow, { ...options, width: request.overflowWidths[0] }), total = (result) => Object.values(result.counts).reduce((sum, count) => sum + (count ?? 0), 0);
|
|
253
|
+
if (total(folded) < total(narrowed))
|
|
254
|
+
narrowed = folded;
|
|
255
|
+
}
|
|
256
|
+
layout.push({ width: app.container, container: !0, ...narrowed });
|
|
248
257
|
}
|
|
249
|
-
layout.push({ width: app.container, container: !0, ...narrowed });
|
|
250
258
|
}
|
|
251
259
|
if (await frame.locator("html").getAttribute("data-ads-preview-state") !== "ready")
|
|
252
260
|
throw Error(`Scenario ${app.scenario} stopped being ready during the audit.`);
|
|
@@ -16,6 +16,24 @@ export function scenarioStateReady(state) {
|
|
|
16
16
|
export function hasAxe() {
|
|
17
17
|
return !!window.axe;
|
|
18
18
|
}
|
|
19
|
+
export function outermostGridLayout() {
|
|
20
|
+
const root = document.getElementById("root");
|
|
21
|
+
if (!root)
|
|
22
|
+
return null;
|
|
23
|
+
const queue = [...root.children];
|
|
24
|
+
while (queue.length > 0) {
|
|
25
|
+
const element = queue.shift(), style = getComputedStyle(element);
|
|
26
|
+
if (style.display === "grid" || style.display === "inline-grid") {
|
|
27
|
+
const cells = [...element.children].map((child) => {
|
|
28
|
+
const cell = getComputedStyle(child);
|
|
29
|
+
return `${cell.gridColumnStart}/${cell.gridColumnEnd}/${cell.gridRowStart}/${cell.gridRowEnd}/${cell.display}`;
|
|
30
|
+
});
|
|
31
|
+
return JSON.stringify([style.gridTemplateColumns, style.gridTemplateRows, style.gridTemplateAreas, cells]);
|
|
32
|
+
}
|
|
33
|
+
queue.push(...element.children);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
19
37
|
export function hasMainLandmark() {
|
|
20
38
|
return !!document.querySelector('main, [role="main"]');
|
|
21
39
|
}
|
package/dist/render-audit.mjs
CHANGED
|
@@ -245,6 +245,7 @@ const skipReasons = {
|
|
|
245
245
|
"derived-detached": "an element left the page while a derived owner state was measured",
|
|
246
246
|
"derived-failed": "measuring a derived owner state failed",
|
|
247
247
|
"content-still-changing": "the page kept changing past 5 s, so what it measured may be mid-change",
|
|
248
|
+
"page-section": "in the 240 px container its outermost grid lays out differently at a phone's viewport than at a desktop's, so its tiers follow the screen: a page section, which no pane hosts, so the container render was not measured",
|
|
248
249
|
"focus-not-reachable": "a control a keyboard cannot reach (aria-hidden, inert, or tabindex -1 outside a roving widget): hover measured, focus not"
|
|
249
250
|
}, overflowKinds = {
|
|
250
251
|
document: {
|
|
@@ -180,8 +180,15 @@ An application follows the same rule as a mock, and can prove it with
|
|
|
180
180
|
- **Links.** A link owner renders `<a href>` and reports the click (an
|
|
181
181
|
`onNavigate` prop), so the application can navigate with its router.
|
|
182
182
|
- **Libraries.** Functions and hooks are behavior and stay in the application.
|
|
183
|
-
A component that renders nothing (a provider, an outlet) is the
|
|
184
|
-
to place
|
|
183
|
+
A component that renders nothing (a provider, an outlet, `Suspense`) is the
|
|
184
|
+
application's to place, listed in the guard's `allow`. A component with its
|
|
185
|
+
own design is not used.
|
|
186
|
+
- **The application's own components are composition.** Routing (`App`), a
|
|
187
|
+
route's page, a lazily loaded dialog host stay in the application, rendering
|
|
188
|
+
design-system owners: the guard checks their bodies, not their names. Never
|
|
189
|
+
add an element, a class or a string tag there, and never settle a guard
|
|
190
|
+
finding by excluding the file or listing a component in `allow` that renders
|
|
191
|
+
design.
|
|
185
192
|
|
|
186
193
|
### The guard
|
|
187
194
|
|
|
@@ -5,7 +5,8 @@ Adapted from Emil Kowalski's break-ui skill (MIT); see the skill README for cred
|
|
|
5
5
|
ADS already proves the construction: `ads check` validates layout, tokens, contrast and
|
|
6
6
|
accessibility rules, and the render audit fails horizontal overflow at 390, 768 and 1280 px
|
|
7
7
|
(`layout-overflow`) and lists narrow-container overflow for review (`layout-overflow-narrow`),
|
|
8
|
-
except a control spilling over its own box (kind `escaped`), an error at any width.
|
|
8
|
+
except a control spilling over its own box (kind `escaped`), an error at any width. A page
|
|
9
|
+
section, whose grid follows viewport tiers, is not rendered in that pane (a skipped info item).
|
|
9
10
|
A stress test adds what no guard knows: **which real content and states break this UI**.
|
|
10
11
|
|
|
11
12
|
## Choose the work
|
|
@@ -180,8 +180,15 @@ An application follows the same rule as a mock, and can prove it with
|
|
|
180
180
|
- **Links.** A link owner renders `<a href>` and reports the click (an
|
|
181
181
|
`onNavigate` prop), so the application can navigate with its router.
|
|
182
182
|
- **Libraries.** Functions and hooks are behavior and stay in the application.
|
|
183
|
-
A component that renders nothing (a provider, an outlet) is the
|
|
184
|
-
to place
|
|
183
|
+
A component that renders nothing (a provider, an outlet, `Suspense`) is the
|
|
184
|
+
application's to place, listed in the guard's `allow`. A component with its
|
|
185
|
+
own design is not used.
|
|
186
|
+
- **The application's own components are composition.** Routing (`App`), a
|
|
187
|
+
route's page, a lazily loaded dialog host stay in the application, rendering
|
|
188
|
+
design-system owners: the guard checks their bodies, not their names. Never
|
|
189
|
+
add an element, a class or a string tag there, and never settle a guard
|
|
190
|
+
finding by excluding the file or listing a component in `allow` that renders
|
|
191
|
+
design.
|
|
185
192
|
|
|
186
193
|
### The guard
|
|
187
194
|
|
|
@@ -180,8 +180,15 @@ An application follows the same rule as a mock, and can prove it with
|
|
|
180
180
|
- **Links.** A link owner renders `<a href>` and reports the click (an
|
|
181
181
|
`onNavigate` prop), so the application can navigate with its router.
|
|
182
182
|
- **Libraries.** Functions and hooks are behavior and stay in the application.
|
|
183
|
-
A component that renders nothing (a provider, an outlet) is the
|
|
184
|
-
to place
|
|
183
|
+
A component that renders nothing (a provider, an outlet, `Suspense`) is the
|
|
184
|
+
application's to place, listed in the guard's `allow`. A component with its
|
|
185
|
+
own design is not used.
|
|
186
|
+
- **The application's own components are composition.** Routing (`App`), a
|
|
187
|
+
route's page, a lazily loaded dialog host stay in the application, rendering
|
|
188
|
+
design-system owners: the guard checks their bodies, not their names. Never
|
|
189
|
+
add an element, a class or a string tag there, and never settle a guard
|
|
190
|
+
finding by excluding the file or listing a component in `allow` that renders
|
|
191
|
+
design.
|
|
185
192
|
|
|
186
193
|
### The guard
|
|
187
194
|
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,126 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.19
|
|
4
|
+
|
|
5
|
+
<!-- ads-local-tests:start -->
|
|
6
|
+
Hot patch: the unit and integration groups; the browser group was not run.
|
|
7
|
+
Quick hot patch (on the owner's instruction, only the tests the fix may affect): unit render-audit-states.test.ts, render-audit-derived.test.ts, escaped-severity.test.ts; integration guard-components.test.ts, guard-package.test.mjs, design-usage.test.ts, guard-externals.test.ts; not the whole unit or integration group. The changed audit worker runs only in tests/browser/render-audit.test.mjs, which passed 38/38 on this source separately.
|
|
8
|
+
Local verification: **18/18 passed** (unit 8, integration 10).
|
|
9
|
+
Tested commit: `f4ccd26f02e5f8812f0a99891e3db21811c4657c`; Bun 1.4.4.
|
|
10
|
+
Completed 2026-11-26T18:24:21.095Z (2 seconds).
|
|
11
|
+
|
|
12
|
+
<!-- ads-local-test-proof
|
|
13
|
+
{
|
|
14
|
+
"schema": 3,
|
|
15
|
+
"version": "0.5.19",
|
|
16
|
+
"commit": "f4ccd26f02e5f8812f0a99891e3db21811c4657c",
|
|
17
|
+
"sourceSha256": "34284323140a5e289b261623eb489d022f8b1f77349fcaee5b38b0dfcdba89d6",
|
|
18
|
+
"command": "bun run test:hotpatch",
|
|
19
|
+
"scope": "hotpatch",
|
|
20
|
+
"result": "pass",
|
|
21
|
+
"tests": 18,
|
|
22
|
+
"pass": 18,
|
|
23
|
+
"fail": 0,
|
|
24
|
+
"skipped": 0,
|
|
25
|
+
"groups": [
|
|
26
|
+
{
|
|
27
|
+
"name": "unit",
|
|
28
|
+
"tests": 8,
|
|
29
|
+
"pass": 8,
|
|
30
|
+
"fail": 0,
|
|
31
|
+
"skipped": 0,
|
|
32
|
+
"reportSha256": "ca7eeb2e9a60e6dd5c113096463e03eea7edcc4f6dc1625ca74fb797826ccb2c"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "integration",
|
|
36
|
+
"tests": 10,
|
|
37
|
+
"pass": 10,
|
|
38
|
+
"fail": 0,
|
|
39
|
+
"skipped": 0,
|
|
40
|
+
"reportSha256": "2b54f3b8443ec52a1d2e322aa232b18dbbaca7fbf0f20cd7cfe01069c1e63bd3"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"testOverrides": {},
|
|
44
|
+
"bun": "1.4.4",
|
|
45
|
+
"completedAt": "2026-11-26T18:24:21.095Z",
|
|
46
|
+
"durationMs": 2171,
|
|
47
|
+
"logSha256": "40e04ff8fd3b03408376ea5c1a1a4e287741f6e53a44f9ec1af2c2ee1207005c"
|
|
48
|
+
}
|
|
49
|
+
-->
|
|
50
|
+
<!-- ads-local-tests:end -->
|
|
51
|
+
|
|
52
|
+
- *ads-guard: components are composition* (#81): the guard reads the
|
|
53
|
+
application with its own TypeScript types. Its own components (an `App` that
|
|
54
|
+
routes, a route's `Page` held in state, a lazily loaded dialog body, `memo`
|
|
55
|
+
and `lazy` of its components) pass, and their bodies are checked. Markup it
|
|
56
|
+
creates stays `design-usage/local-markup`, now also a tag whose type is a
|
|
57
|
+
string and `h("div")`. New: `design-usage/unlisted-component` for a component
|
|
58
|
+
read from a package not in `allow` (imported, off a namespace, or from a
|
|
59
|
+
factory such as `styled("div")`), and `design-usage/unchecked-component` for
|
|
60
|
+
one declared in a file the guard does not check. `Fragment` and `Suspense`
|
|
61
|
+
now need listing in `allow` when imported.
|
|
62
|
+
- *Render audit: page sections are not measured in a pane*: in the 240 px
|
|
63
|
+
container the audit lays a scenario out at a desktop and a phone viewport;
|
|
64
|
+
when its outermost grid's layout differs, its tiers follow the screen, so no
|
|
65
|
+
pane hosts it. The container render is skipped, reported as a
|
|
66
|
+
`render-audit-skipped` info item. Container-context grids are still measured.
|
|
67
|
+
|
|
68
|
+
## 0.5.18
|
|
69
|
+
|
|
70
|
+
<!-- ads-local-tests:start -->
|
|
71
|
+
Hot patch: the unit and integration groups; the browser group was not run.
|
|
72
|
+
Quick hot patch (on the owner's instruction, only the tests the fix may affect): unit render-audit-states.test.ts, render-audit-derived.test.ts, escaped-severity.test.ts; integration analysis-acceptance.test.mjs, analysis-contrast.test.mjs; not the whole unit or integration group. The changed audit worker runs only in tests/browser/render-audit.test.mjs, which passed 38/38 on this source separately.
|
|
73
|
+
Local verification: **23/23 passed** (unit 8, integration 15).
|
|
74
|
+
Tested commit: `e4c45f21f127335dc5526a93c5ebb527ea2c8b75`; Bun 1.4.4.
|
|
75
|
+
Completed 2026-11-26T17:00:38.367Z (46 seconds).
|
|
76
|
+
|
|
77
|
+
<!-- ads-local-test-proof
|
|
78
|
+
{
|
|
79
|
+
"schema": 3,
|
|
80
|
+
"version": "0.5.18",
|
|
81
|
+
"commit": "e4c45f21f127335dc5526a93c5ebb527ea2c8b75",
|
|
82
|
+
"sourceSha256": "473527688ce2848be8a4b35249172b0637db06fc1b036388222696a0698015b7",
|
|
83
|
+
"command": "bun run test:hotpatch",
|
|
84
|
+
"scope": "hotpatch",
|
|
85
|
+
"result": "pass",
|
|
86
|
+
"tests": 23,
|
|
87
|
+
"pass": 23,
|
|
88
|
+
"fail": 0,
|
|
89
|
+
"skipped": 0,
|
|
90
|
+
"groups": [
|
|
91
|
+
{
|
|
92
|
+
"name": "unit",
|
|
93
|
+
"tests": 8,
|
|
94
|
+
"pass": 8,
|
|
95
|
+
"fail": 0,
|
|
96
|
+
"skipped": 0,
|
|
97
|
+
"reportSha256": "6ef98ff08a6db45de3f6676848771b1037c5f332e58fd81901351b013044fe14"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"name": "integration",
|
|
101
|
+
"tests": 15,
|
|
102
|
+
"pass": 15,
|
|
103
|
+
"fail": 0,
|
|
104
|
+
"skipped": 0,
|
|
105
|
+
"reportSha256": "75d44a5587e03922ec264bc0d8868907f7c4653bcfb2a58a524ce25939f2939a"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"testOverrides": {},
|
|
109
|
+
"bun": "1.4.4",
|
|
110
|
+
"completedAt": "2026-11-26T17:00:38.367Z",
|
|
111
|
+
"durationMs": 46056,
|
|
112
|
+
"logSha256": "4b465972476daa4b06cfc5e78613389de39596575e3db3166eb7dcc4c5a147cd"
|
|
113
|
+
}
|
|
114
|
+
-->
|
|
115
|
+
<!-- ads-local-tests:end -->
|
|
116
|
+
|
|
117
|
+
- *Fixed: page sections reported as escaping in the 240 px pane*: a layout
|
|
118
|
+
whose tiers follow the viewport (LinkCardGrid's three columns, two-column
|
|
119
|
+
pricing cards) kept its desktop layout in the pane render, which no screen
|
|
120
|
+
shows. That render now measures it at the 390 px viewport, where it folds,
|
|
121
|
+
whenever that reports less, not only when it is clean; what still does not
|
|
122
|
+
fit there is reported.
|
|
123
|
+
|
|
3
124
|
## 0.5.17
|
|
4
125
|
|
|
5
126
|
<!-- ads-local-tests:start -->
|
package/docs/GUIDE.md
CHANGED
|
@@ -677,7 +677,16 @@ What the audit measures in each render:
|
|
|
677
677
|
- Scrollers, ellipsis text, carousels, pannable widgets, native text fields,
|
|
678
678
|
fixed layers and visually hidden content are exempt.
|
|
679
679
|
- Components and patterns are also rendered in a 240 px container. What does
|
|
680
|
-
not fit a side pane is a `layout-overflow-narrow` review item
|
|
680
|
+
not fit a side pane is a `layout-overflow-narrow` review item (an escaping
|
|
681
|
+
control is an error).
|
|
682
|
+
- A page section is not measured there. In the 240 px container the audit
|
|
683
|
+
lays the scenario out at a desktop and at a phone viewport; when its
|
|
684
|
+
outermost grid's tracks or cell placement differ, its tiers follow the
|
|
685
|
+
screen, so no pane hosts it (a hero, a pricing band, a page-wide card grid).
|
|
686
|
+
The skip is a `render-audit-skipped` info item naming the scenario. A grid
|
|
687
|
+
with `context: "container"` lays out the same at both and is measured.
|
|
688
|
+
- A layout whose tiers follow the viewport further in is measured in that
|
|
689
|
+
container at the 390 px viewport, where it folds, when that reports less.
|
|
681
690
|
- **Text scaling** (WCAG 1.4.4, 1.4.10, 1.4.12), once per scenario in the first
|
|
682
691
|
theme and brand, because text does not follow colour. The passes add about a
|
|
683
692
|
tenth to the audit's time.
|
|
@@ -1559,6 +1568,15 @@ Where to run it:
|
|
|
1559
1568
|
that does not exist is an error, so the list cannot hide anything.
|
|
1560
1569
|
- `allow` lists components of other packages that carry no design, one by one:
|
|
1561
1570
|
a router's outlet, providers, the framework's own markers.
|
|
1571
|
+
- Design is markup and style; components are composition. The application's
|
|
1572
|
+
own components (an `App` that routes, a route's page held in state, a lazily
|
|
1573
|
+
loaded dialog body, `memo` and `lazy` of its components) pass wherever they
|
|
1574
|
+
are rendered, and their bodies are checked. What the application creates
|
|
1575
|
+
itself is `design-usage/local-markup`: an element, a tag whose type is a
|
|
1576
|
+
string, `h("div")`. A component read from a package not in `allow` is
|
|
1577
|
+
`design-usage/unlisted-component`, where it is read; one declared in a file
|
|
1578
|
+
the guard does not check is `design-usage/unchecked-component`. The guard
|
|
1579
|
+
reads each file with the application's own TypeScript project.
|
|
1562
1580
|
- Tests and the design system's own files are never checked; the report counts
|
|
1563
1581
|
them. Document metadata (`<title>`, `<meta>`, `<script>`, a `<link>` that is
|
|
1564
1582
|
not a stylesheet) is accepted anywhere.
|