@variance-authority/core 0.2.0 → 0.4.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/CHANGELOG.md +85 -36
- package/README.md +255 -128
- package/dist/attribute/call-site.d.ts +20 -2
- package/dist/attribute/call-site.js +17 -20
- package/dist/attribute/call-site.js.map +1 -1
- package/dist/attribute/composition.js +67 -11
- package/dist/attribute/composition.js.map +1 -1
- package/dist/attribute/index.d.ts +2 -0
- package/dist/attribute/index.js +1 -0
- package/dist/attribute/index.js.map +1 -1
- package/dist/attribute/landmark.d.ts +97 -0
- package/dist/attribute/landmark.js +144 -0
- package/dist/attribute/landmark.js.map +1 -0
- package/dist/attribute/lexicon.d.ts +25 -1
- package/dist/attribute/lexicon.js +87 -27
- package/dist/attribute/lexicon.js.map +1 -1
- package/dist/attribute/stack.d.ts +62 -1
- package/dist/attribute/stack.js +116 -5
- package/dist/attribute/stack.js.map +1 -1
- package/dist/judge/inspect.js +57 -4
- package/dist/judge/inspect.js.map +1 -1
- package/dist/relate/before.d.ts +137 -0
- package/dist/relate/before.js +155 -0
- package/dist/relate/before.js.map +1 -0
- package/dist/relate/graph.d.ts +28 -11
- package/dist/relate/graph.js +20 -9
- package/dist/relate/graph.js.map +1 -1
- package/dist/relate/index.d.ts +2 -1
- package/dist/relate/index.js +1 -0
- package/dist/relate/index.js.map +1 -1
- package/dist/relate/merkle.d.ts +6 -0
- package/dist/relate/merkle.js +6 -0
- package/dist/relate/merkle.js.map +1 -1
- package/dist/relate/records.d.ts +67 -1
- package/dist/relate/records.js +34 -7
- package/dist/relate/records.js.map +1 -1
- package/package.json +1 -1
package/dist/judge/inspect.js
CHANGED
|
@@ -55,6 +55,14 @@ export function inspect(snapshot) {
|
|
|
55
55
|
});
|
|
56
56
|
return findings;
|
|
57
57
|
function visit(node, insideControl) {
|
|
58
|
+
// Nothing below a node the browser never built. A responsive site renders
|
|
59
|
+
// the mobile navigation into the desktop document and hides it with a
|
|
60
|
+
// class, and a reader that counts it sees two `navigation` landmarks where
|
|
61
|
+
// Chrome's tree holds one — a duplicate nobody can reach, reported against
|
|
62
|
+
// markup that is correct. Every rule here is about what a screen reader
|
|
63
|
+
// encounters, so the gate belongs at the walk rather than in each rule.
|
|
64
|
+
if (!exposed(node))
|
|
65
|
+
return;
|
|
58
66
|
const interactive = node.role !== undefined && INTERACTIVE.has(node.role);
|
|
59
67
|
if (interactive && node.name === undefined) {
|
|
60
68
|
findings.push(finding('control-without-name', node, `<${node.tag}> is a ${node.role} with no accessible name`, snapshot));
|
|
@@ -124,6 +132,27 @@ export function inspect(snapshot) {
|
|
|
124
132
|
visit(child, insideControl || interactive);
|
|
125
133
|
}
|
|
126
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether a screen reader reaches this node at all.
|
|
137
|
+
*
|
|
138
|
+
* Three ways out of the accessibility tree, and only one of them is declared.
|
|
139
|
+
* `aria-hidden="true"` and the `hidden` attribute are the author saying so, and
|
|
140
|
+
* arrive as state. `display: none` is the one nobody says: it is a utility
|
|
141
|
+
* class, a media query, a `<details>` that is closed at this width. All three
|
|
142
|
+
* take the subtree with them — `aria-hidden` is not reversible by a descendant,
|
|
143
|
+
* and neither is a box that was never generated.
|
|
144
|
+
*
|
|
145
|
+
* `display` is read from the node's own computed style, which the capture
|
|
146
|
+
* already carries: it is in the style allowlist, so this costs no new field and
|
|
147
|
+
* moves no hash. Absent — a structural-only profile, where no style was
|
|
148
|
+
* computed — the answer is "exposed", because refusing to report on a document
|
|
149
|
+
* whose visibility could not be observed would silently empty the inspection.
|
|
150
|
+
*/
|
|
151
|
+
function exposed(node) {
|
|
152
|
+
if (node.state?.['hidden'] === true)
|
|
153
|
+
return false;
|
|
154
|
+
return node.style['display'] !== 'none';
|
|
155
|
+
}
|
|
127
156
|
function hasHeaders(node) {
|
|
128
157
|
if (node.role === 'columnheader' || node.role === 'rowheader')
|
|
129
158
|
return true;
|
|
@@ -137,11 +166,35 @@ function hasHeaders(node) {
|
|
|
137
166
|
* has nothing to compare.
|
|
138
167
|
*/
|
|
139
168
|
function visibleTextOf(node) {
|
|
140
|
-
|
|
169
|
+
return runsOf(node).replace(/\s+/g, ' ').trim();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The same separator rule accname uses, so the two readings can be compared.
|
|
173
|
+
*
|
|
174
|
+
* `label-mismatch` asks whether the accessible name contains the visible words,
|
|
175
|
+
* and that question is only meaningful if both sides were assembled the same
|
|
176
|
+
* way. Joining every child with a space while `accessibleName` concatenated
|
|
177
|
+
* them produced the failure this rule exists to prevent, in the rule itself: a
|
|
178
|
+
* flex button reading "Search ⌘K" and named "Search⌘K" was reported as
|
|
179
|
+
* unreachable by voice, against markup a browser names correctly.
|
|
180
|
+
*
|
|
181
|
+
* So a child contributes separated only when its computed `display` is not
|
|
182
|
+
* inline — which is what a browser does, and which makes `<b>` inside a
|
|
183
|
+
* sentence contribute as part of the word it is inside.
|
|
184
|
+
*/
|
|
185
|
+
function runsOf(node) {
|
|
186
|
+
if (!exposed(node))
|
|
141
187
|
return '';
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
188
|
+
let text = node.text ?? '';
|
|
189
|
+
for (const child of node.children) {
|
|
190
|
+
const contribution = runsOf(child);
|
|
191
|
+
if (contribution.length === 0)
|
|
192
|
+
continue;
|
|
193
|
+
const display = child.style['display'];
|
|
194
|
+
const separated = display !== undefined && display !== 'inline' && display !== 'contents';
|
|
195
|
+
text += separated ? ` ${contribution} ` : contribution;
|
|
196
|
+
}
|
|
197
|
+
return text;
|
|
145
198
|
}
|
|
146
199
|
function levelOf(node) {
|
|
147
200
|
// `aria-level` wins, because it is what an assistive technology reads. The tag
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/judge/inspect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,YAAY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AAE;YACrD,CAAC,CAAC,QAAQ;gBACR,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC;gBACxB,CAAC,CAAC,EAAE,CAAC;QAEX,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;aACpE,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC;aACpD,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb,OAAO;YACL,MAAM,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE;YACjC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI;YAC5D,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,WAAW,EAAE;SACnD,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { Band } from '../compare/band.js';\nimport type { OwnerFrame, SourceLocation } from '../format/provenance.js';\nimport type { NodePath, SemanticNode, SemanticSnapshot } from '../format/snapshot.js';\nimport { locate } from '../attribute/locate.js';\nimport { formatSource, resolveSource, type SourceIndex } from '../attribute/source.js';\n\n/**\n * What a render says without a baseline.\n *\n * Two producers, one `Finding` type. `inspect` reads a single snapshot;\n * `compareLocales` reads two renders of one subject in different languages,\n * which is also not a regression comparison — both renders are correct. Sharing\n * the type is what lets the report, the CLI and the MCP tools carry both without\n * knowing which produced what.\n *\n * The rest of this comment is about `inspect`, which reads one snapshot with no\n * baseline and no second run.\n *\n * Everything else in this package answers *what changed*, which requires two of\n * something. That framing has a blind spot the whole category shares: **a defect\n * that was present on the first run is invisible to a comparison forever.** A\n * button that never had an accessible name compares equal to itself on every run\n * until someone happens to edit it, and a picture of it is a perfectly good\n * picture. Approving the first baseline approves the defect.\n *\n * These rules read the normalized snapshot and report defects in it. Consequences\n * worth stating, because they are the practical argument for having the document\n * rather than an image of it:\n *\n * - **A fresh checkout with zero baselines is already useful.** The expensive\n * part of adopting a visual-regression tool is that it says nothing until it\n * has a history; this half says something on the first run.\n * - **Every finding names a component and a file**, through the same provenance\n * chain a delta uses. A rule engine that reports a DOM path reports where the\n * symptom is; this reports whose JSX wrote it.\n * - **They band as `a11y`**, so a project that writes `blocking: ['a11y']` gets\n * both halves under one policy: regressions found by comparison, and defects\n * found by inspection.\n *\n * Deliberately *not* an axe-core reimplementation. Axe runs against a live DOM\n * with computed visibility, contrast and focus order, and does dozens of things\n * this cannot. What is here is the subset a normalized snapshot can decide\n * without guessing — and the subset it can decide **offline, from a stored\n * artifact, months later**, which is a thing axe cannot do at all.\n *\n * There is no severity field. A rule that needs one to be tolerable is a rule\n * whose condition is too broad, and the fix is a better condition or no rule.\n *\n * **Why there is no contrast rule, stated here so nobody adds one badly later.**\n * The snapshot carries a resolved `color` and `background-color` per node, so a\n * check looks like four lines and would be wrong: the background a glyph is\n * actually painted on is whatever is behind it, which is a stacking question a\n * layout engine answers and a document does not. A node with a transparent\n * background over a dark ancestor, an image, a gradient, or a positioned sibling\n * all read as \"background-color: rgba(0,0,0,0)\" here. A rule that is right most\n * of the time about accessibility is worse than no rule: it gets disabled after\n * the second false alarm, and takes the four that work with it. Spec 0009\n * records the same for focus order and anything about motion.\n */\n\nexport type FindingRule =\n /** An interactive control with no accessible name. Nothing announces it. */\n | 'control-without-name'\n /** A meaningful image with neither a name nor an explicit `alt=\"\"`. */\n | 'image-without-alt'\n /** Heading levels jump forward by more than one. */\n | 'heading-level-skipped'\n /** A control inside another control. Only one of them is reachable. */\n | 'nested-interactive'\n /** An id reference that resolves to nothing inside this subject. */\n | 'dangling-reference'\n /** A control whose accessible name does not contain its visible label. */\n | 'label-mismatch'\n /** Two landmarks of one role that nothing tells apart. */\n | 'duplicate-landmark'\n /** A table with no header cells. */\n | 'table-without-headers'\n /** `tabindex` above zero, which reorders focus for the whole page. */\n | 'positive-tabindex'\n /**\n * The same string in two locales. From `compareLocales`, not from `inspect` —\n * one render cannot know whether its text was translated.\n */\n | 'untranslated'\n /** A box outside the box that contains it, in one locale and not the other. */\n | 'overflows-container';\n\n/**\n * The identity of a finding, as a string two runs can be compared on.\n *\n * A finding is *the same finding* when the same rule fires on the same node. Not\n * the same sentence: `what` quotes the text it found, so a copy edit beside a\n * control with no accessible name would read as the old defect going away and a\n * new one arriving in the same place. And not the same component either — a\n * component renders in many places, and every one of them would collapse to one.\n *\n * Small on purpose. This is what a baseline carries so that the next run can say\n * whether a defect it found was already there, and a baseline sidecar rides\n * beside a PNG in a tracked directory: a mark is a few dozen bytes and a stored\n * `Finding` is a paragraph. It can only answer membership, which is the only\n * question the next run is allowed to ask of it — the same restraint\n * `Described.components` is written under.\n */\nexport function findingMark(finding: { readonly rule: string; readonly path: string }): string {\n return `${finding.rule}@${finding.path}`;\n}\n\nexport interface Finding {\n readonly rule: FindingRule;\n\n /**\n * The band this finding would block under.\n *\n * Carried so that inspection and comparison answer to one policy. A team that\n * blocks `a11y` should not have to discover that it blocks regressions and not\n * defects.\n */\n readonly band: Band;\n\n readonly path: NodePath;\n\n /** One sentence, naming the thing rather than the rule. */\n readonly what: string;\n\n /** Spoken outside-in, from `locate` — `main → region \"Todos\" → item 2 of 3`. */\n readonly where?: string;\n\n /** The component whose JSX created the node, when provenance reached it. */\n readonly component?: string;\n readonly owners?: readonly OwnerFrame[];\n\n /**\n * The line that wrote *this element*, when a JSX runtime recorded one.\n *\n * Different from — and better than — resolving `component` through the source\n * index, which answers with where the component is *declared*. A defect is\n * rarely at a declaration: a button with no accessible name is a specific\n * element on a specific line inside that component, and that line is the edit.\n * The index stays as the fallback, because it needs no build change.\n *\n * Requires `@variance-authority/jsx-source` in the transform. Absent otherwise,\n * and absence is normal.\n */\n readonly source?: SourceLocation;\n}\n\n/** Roles that are operated. A control nobody can name is a control nobody can use. */\nconst INTERACTIVE = new Set([\n 'button', 'link', 'checkbox', 'radio', 'switch', 'textbox', 'searchbox',\n 'combobox', 'slider', 'spinbutton', 'menuitem', 'menuitemcheckbox',\n 'menuitemradio', 'tab', 'treeitem',\n]);\n\n/** Attributes whose value the aliaser rewrote, so `#extern:` means unresolved. */\nconst REFERENCE_ATTRIBUTES = new Set(['for', 'form', 'list', 'headers']);\n\nconst HEADING_TAGS: Readonly<Record<string, number>> = {\n h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6,\n};\n\n/** Regions of a page a screen reader user navigates between. */\nconst LANDMARKS = new Set([\n 'banner', 'navigation', 'main', 'complementary', 'contentinfo',\n 'region', 'form', 'search',\n]);\n\n/** Has at least one letter. A glyph is not a visible label. */\nconst HAS_LETTER = /\\p{L}/u;\n\nexport function inspect(snapshot: SemanticSnapshot): readonly Finding[] {\n const findings: Finding[] = [];\n const headings: { node: SemanticNode; level: number }[] = [];\n const landmarks = new Map<string, SemanticNode>();\n\n visit(snapshot.root, false);\n\n // Heading order is a property of the sequence, not of any one node, so it is\n // decided after the walk. Only *forward* jumps are reported: a component that\n // starts at `h3` is a component rendered inside something, not a defect, and a\n // subject is not a page.\n headings.forEach((heading, index) => {\n const previous = headings[index - 1];\n if (previous === undefined || heading.level <= previous.level + 1) return;\n\n findings.push(\n finding(\n 'heading-level-skipped',\n heading.node,\n `heading level jumps from ${previous.level} to ${heading.level}` +\n (heading.node.name !== undefined ? ` at \"${heading.node.name}\"` : ''),\n snapshot,\n ),\n );\n });\n\n return findings;\n\n function visit(node: SemanticNode, insideControl: boolean): void {\n const interactive = node.role !== undefined && INTERACTIVE.has(node.role);\n\n if (interactive && node.name === undefined) {\n findings.push(\n finding(\n 'control-without-name',\n node,\n `<${node.tag}> is a ${node.role} with no accessible name`,\n snapshot,\n ),\n );\n }\n\n if (interactive && insideControl) {\n findings.push(\n finding(\n 'nested-interactive',\n node,\n `a ${node.role} is nested inside another control; only one of the two is reachable`,\n snapshot,\n ),\n );\n }\n\n // `alt=\"\"` is the author saying \"decorative\", which is a correct answer and\n // must not be reported. A missing `alt` is the author saying nothing.\n if (node.role === 'img' && node.name === undefined && node.attributes['alt'] === undefined) {\n findings.push(\n finding(\n 'image-without-alt',\n node,\n `<${node.tag}> has an image role, no accessible name, and no alt=\"\" to say it is decorative`,\n snapshot,\n ),\n );\n }\n\n for (const [attribute, value] of Object.entries(node.attributes)) {\n if (!REFERENCE_ATTRIBUTES.has(attribute) || !value.includes('#extern:')) continue;\n\n findings.push(\n finding(\n 'dangling-reference',\n node,\n // Honest about the ambiguity the aliaser records: from inside the\n // subject, escaping the subtree and pointing at nothing look the same.\n `<${node.tag} ${attribute}> references an element that is not in this subject`,\n snapshot,\n ),\n );\n }\n\n if (node.role === 'heading') {\n const level = levelOf(node);\n if (level !== undefined) headings.push({ node, level });\n }\n\n if (node.role !== undefined && LANDMARKS.has(node.role)) {\n // Keyed by role *and* name: two `navigation` landmarks called \"Primary\"\n // and \"Footer\" are how a page is meant to be built. Two called nothing are\n // two identical entries in the landmark list.\n const key = `${node.role}\\u0000${node.name ?? ''}`;\n const first = landmarks.get(key);\n\n if (first === undefined) {\n landmarks.set(key, node);\n } else {\n findings.push(\n finding(\n 'duplicate-landmark',\n node,\n `a second ${node.role} landmark` +\n (node.name !== undefined ? ` also named \"${node.name}\"` : ' with no name') +\n ', so nothing tells the two apart in a landmark list',\n snapshot,\n ),\n );\n }\n }\n\n if (node.role === 'table' && !hasHeaders(node)) {\n findings.push(\n finding(\n 'table-without-headers',\n node,\n `<${node.tag}> is a table with no header cells, so every cell is announced without ` +\n 'the column it belongs to',\n snapshot,\n ),\n );\n }\n\n const tabindex = Number(node.attributes['tabindex']);\n if (Number.isInteger(tabindex) && tabindex > 0) {\n findings.push(\n finding(\n 'positive-tabindex',\n node,\n `<${node.tag}> has tabindex=${tabindex}, which pulls it ahead of every element in ` +\n 'the document that relies on source order',\n snapshot,\n ),\n );\n }\n\n // WCAG 2.5.3. A control whose accessible name does not contain its visible\n // label cannot be operated by voice: \"click Save\" does nothing when the\n // button reads Save and is named \"Submit form\".\n //\n // Only when the visible text carries a letter. An icon button labelled\n // `aria-label=\"Refresh\"` around a glyph is correct, and a rule that reported\n // it would fire on every icon in every design system.\n if (interactive && node.name !== undefined) {\n const visible = visibleTextOf(node);\n if (\n visible.length > 0 &&\n HAS_LETTER.test(visible) &&\n !node.name.toLowerCase().includes(visible.toLowerCase())\n ) {\n findings.push(\n finding(\n 'label-mismatch',\n node,\n `reads \"${visible}\" and is named \"${node.name}\", so a voice command using the ` +\n 'visible words does not reach it',\n snapshot,\n ),\n );\n }\n }\n\n for (const child of node.children) visit(child, insideControl || interactive);\n }\n}\n\nfunction hasHeaders(node: SemanticNode): boolean {\n if (node.role === 'columnheader' || node.role === 'rowheader') return true;\n return node.children.some(hasHeaders);\n}\n\n/**\n * Text a sighted user reads, normalized to single spaces.\n *\n * `aria-hidden` subtrees are excluded, which is what makes the icon-button case\n * work: the glyph is hidden, so the visible text is empty and `label-mismatch`\n * has nothing to compare.\n */\nfunction visibleTextOf(node: SemanticNode): string {\n if (node.state?.['hidden'] === true) return '';\n\n const own = node.text ?? '';\n const children = node.children.map(visibleTextOf).join(' ');\n\n return `${own} ${children}`.replace(/\\s+/g, ' ').trim();\n}\n\nfunction levelOf(node: SemanticNode): number | undefined {\n // `aria-level` wins, because it is what an assistive technology reads. The tag\n // is the fallback, and a `role=\"heading\"` with neither is not a level at all.\n const declared = node.state?.['level'];\n if (typeof declared === 'number') return declared;\n if (typeof declared === 'string' && /^\\d+$/.test(declared)) return Number(declared);\n\n return HEADING_TAGS[node.tag];\n}\n\nfunction finding(\n rule: FindingRule,\n node: SemanticNode,\n what: string,\n snapshot: SemanticSnapshot,\n): Finding {\n const where = locate(snapshot.root, node.path).where;\n const component = node.provenance?.createdBy ?? node.provenance?.owners[0]?.name;\n\n return {\n rule,\n band: 'a11y',\n path: node.path,\n what,\n ...(where !== '' ? { where } : {}),\n ...(component !== undefined ? { component } : {}),\n ...(node.provenance ? { owners: node.provenance.owners } : {}),\n ...(node.provenance?.source ? { source: node.provenance.source } : {}),\n };\n}\n\nexport interface InspectionReportOptions {\n /** Component → file, so a finding names an edit rather than an identifier. */\n readonly source?: SourceIndex;\n}\n\n/**\n * Findings as the thing a reviewer or an agent reads.\n *\n * Same shape as `summarizeAdjudication`: what, where, which file. A finding a\n * reader has to go and locate is a finding that gets skipped.\n */\nexport function summarizeFindings(\n findings: readonly Finding[],\n options: InspectionReportOptions = {},\n): string {\n if (findings.length === 0) return 'no findings.';\n\n const byRule = new Map<FindingRule, number>();\n for (const found of findings) byRule.set(found.rule, (byRule.get(found.rule) ?? 0) + 1);\n\n const header =\n `${findings.length} finding${findings.length === 1 ? '' : 's'}: ` +\n [...byRule].map(([rule, count]) => `${count} ${rule}`).join(', ');\n\n const lines = findings.flatMap((found) => {\n // The element's own line wins over the component's declaration. Both are\n // `file:line`, so the reader cannot tell them apart and does not need to —\n // either one opens at something worth editing, and the recorded one opens at\n // the element the finding is actually about.\n const declared =\n found.component !== undefined && options.source\n ? resolveSource(found.component, options.source)\n : null;\n const where =\n found.source !== undefined\n ? `${found.source.file}:${String(found.source.line)}`\n : declared\n ? formatSource(declared)\n : '';\n\n const attribution = [found.component, where === '' ? undefined : where]\n .filter((part): part is string => part !== undefined)\n .join(' ');\n\n return [\n ` [${found.rule}] ${found.what}`,\n found.where !== undefined ? ` in ${found.where}` : null,\n attribution === '' ? null : ` ${attribution}`,\n ].filter((line): line is string => line !== null);\n });\n\n return [header, ...lines].join('\\n');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/judge/inspect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,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AAC,CAAC,CAAC,YAAY,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI;YAC5D,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,WAAW,EAAE;SACnD,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { Band } from '../compare/band.js';\nimport type { OwnerFrame, SourceLocation } from '../format/provenance.js';\nimport type { NodePath, SemanticNode, SemanticSnapshot } from '../format/snapshot.js';\nimport { locate } from '../attribute/locate.js';\nimport { formatSource, resolveSource, type SourceIndex } from '../attribute/source.js';\n\n/**\n * What a render says without a baseline.\n *\n * Two producers, one `Finding` type. `inspect` reads a single snapshot;\n * `compareLocales` reads two renders of one subject in different languages,\n * which is also not a regression comparison — both renders are correct. Sharing\n * the type is what lets the report, the CLI and the MCP tools carry both without\n * knowing which produced what.\n *\n * The rest of this comment is about `inspect`, which reads one snapshot with no\n * baseline and no second run.\n *\n * Everything else in this package answers *what changed*, which requires two of\n * something. That framing has a blind spot the whole category shares: **a defect\n * that was present on the first run is invisible to a comparison forever.** A\n * button that never had an accessible name compares equal to itself on every run\n * until someone happens to edit it, and a picture of it is a perfectly good\n * picture. Approving the first baseline approves the defect.\n *\n * These rules read the normalized snapshot and report defects in it. Consequences\n * worth stating, because they are the practical argument for having the document\n * rather than an image of it:\n *\n * - **A fresh checkout with zero baselines is already useful.** The expensive\n * part of adopting a visual-regression tool is that it says nothing until it\n * has a history; this half says something on the first run.\n * - **Every finding names a component and a file**, through the same provenance\n * chain a delta uses. A rule engine that reports a DOM path reports where the\n * symptom is; this reports whose JSX wrote it.\n * - **They band as `a11y`**, so a project that writes `blocking: ['a11y']` gets\n * both halves under one policy: regressions found by comparison, and defects\n * found by inspection.\n *\n * Deliberately *not* an axe-core reimplementation. Axe runs against a live DOM\n * with computed visibility, contrast and focus order, and does dozens of things\n * this cannot. What is here is the subset a normalized snapshot can decide\n * without guessing — and the subset it can decide **offline, from a stored\n * artifact, months later**, which is a thing axe cannot do at all.\n *\n * There is no severity field. A rule that needs one to be tolerable is a rule\n * whose condition is too broad, and the fix is a better condition or no rule.\n *\n * **Why there is no contrast rule, stated here so nobody adds one badly later.**\n * The snapshot carries a resolved `color` and `background-color` per node, so a\n * check looks like four lines and would be wrong: the background a glyph is\n * actually painted on is whatever is behind it, which is a stacking question a\n * layout engine answers and a document does not. A node with a transparent\n * background over a dark ancestor, an image, a gradient, or a positioned sibling\n * all read as \"background-color: rgba(0,0,0,0)\" here. A rule that is right most\n * of the time about accessibility is worse than no rule: it gets disabled after\n * the second false alarm, and takes the four that work with it. Spec 0009\n * records the same for focus order and anything about motion.\n */\n\nexport type FindingRule =\n /** An interactive control with no accessible name. Nothing announces it. */\n | 'control-without-name'\n /** A meaningful image with neither a name nor an explicit `alt=\"\"`. */\n | 'image-without-alt'\n /** Heading levels jump forward by more than one. */\n | 'heading-level-skipped'\n /** A control inside another control. Only one of them is reachable. */\n | 'nested-interactive'\n /** An id reference that resolves to nothing inside this subject. */\n | 'dangling-reference'\n /** A control whose accessible name does not contain its visible label. */\n | 'label-mismatch'\n /** Two landmarks of one role that nothing tells apart. */\n | 'duplicate-landmark'\n /** A table with no header cells. */\n | 'table-without-headers'\n /** `tabindex` above zero, which reorders focus for the whole page. */\n | 'positive-tabindex'\n /**\n * The same string in two locales. From `compareLocales`, not from `inspect` —\n * one render cannot know whether its text was translated.\n */\n | 'untranslated'\n /** A box outside the box that contains it, in one locale and not the other. */\n | 'overflows-container';\n\n/**\n * The identity of a finding, as a string two runs can be compared on.\n *\n * A finding is *the same finding* when the same rule fires on the same node. Not\n * the same sentence: `what` quotes the text it found, so a copy edit beside a\n * control with no accessible name would read as the old defect going away and a\n * new one arriving in the same place. And not the same component either — a\n * component renders in many places, and every one of them would collapse to one.\n *\n * Small on purpose. This is what a baseline carries so that the next run can say\n * whether a defect it found was already there, and a baseline sidecar rides\n * beside a PNG in a tracked directory: a mark is a few dozen bytes and a stored\n * `Finding` is a paragraph. It can only answer membership, which is the only\n * question the next run is allowed to ask of it — the same restraint\n * `Described.components` is written under.\n */\nexport function findingMark(finding: { readonly rule: string; readonly path: string }): string {\n return `${finding.rule}@${finding.path}`;\n}\n\nexport interface Finding {\n readonly rule: FindingRule;\n\n /**\n * The band this finding would block under.\n *\n * Carried so that inspection and comparison answer to one policy. A team that\n * blocks `a11y` should not have to discover that it blocks regressions and not\n * defects.\n */\n readonly band: Band;\n\n readonly path: NodePath;\n\n /** One sentence, naming the thing rather than the rule. */\n readonly what: string;\n\n /** Spoken outside-in, from `locate` — `main → region \"Todos\" → item 2 of 3`. */\n readonly where?: string;\n\n /** The component whose JSX created the node, when provenance reached it. */\n readonly component?: string;\n readonly owners?: readonly OwnerFrame[];\n\n /**\n * The line that wrote *this element*, when a JSX runtime recorded one.\n *\n * Different from — and better than — resolving `component` through the source\n * index, which answers with where the component is *declared*. A defect is\n * rarely at a declaration: a button with no accessible name is a specific\n * element on a specific line inside that component, and that line is the edit.\n * The index stays as the fallback, because it needs no build change.\n *\n * Requires `@variance-authority/jsx-source` in the transform. Absent otherwise,\n * and absence is normal.\n */\n readonly source?: SourceLocation;\n}\n\n/** Roles that are operated. A control nobody can name is a control nobody can use. */\nconst INTERACTIVE = new Set([\n 'button', 'link', 'checkbox', 'radio', 'switch', 'textbox', 'searchbox',\n 'combobox', 'slider', 'spinbutton', 'menuitem', 'menuitemcheckbox',\n 'menuitemradio', 'tab', 'treeitem',\n]);\n\n/** Attributes whose value the aliaser rewrote, so `#extern:` means unresolved. */\nconst REFERENCE_ATTRIBUTES = new Set(['for', 'form', 'list', 'headers']);\n\nconst HEADING_TAGS: Readonly<Record<string, number>> = {\n h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6,\n};\n\n/** Regions of a page a screen reader user navigates between. */\nconst LANDMARKS = new Set([\n 'banner', 'navigation', 'main', 'complementary', 'contentinfo',\n 'region', 'form', 'search',\n]);\n\n/** Has at least one letter. A glyph is not a visible label. */\nconst HAS_LETTER = /\\p{L}/u;\n\nexport function inspect(snapshot: SemanticSnapshot): readonly Finding[] {\n const findings: Finding[] = [];\n const headings: { node: SemanticNode; level: number }[] = [];\n const landmarks = new Map<string, SemanticNode>();\n\n visit(snapshot.root, false);\n\n // Heading order is a property of the sequence, not of any one node, so it is\n // decided after the walk. Only *forward* jumps are reported: a component that\n // starts at `h3` is a component rendered inside something, not a defect, and a\n // subject is not a page.\n headings.forEach((heading, index) => {\n const previous = headings[index - 1];\n if (previous === undefined || heading.level <= previous.level + 1) return;\n\n findings.push(\n finding(\n 'heading-level-skipped',\n heading.node,\n `heading level jumps from ${previous.level} to ${heading.level}` +\n (heading.node.name !== undefined ? ` at \"${heading.node.name}\"` : ''),\n snapshot,\n ),\n );\n });\n\n return findings;\n\n function visit(node: SemanticNode, insideControl: boolean): void {\n // Nothing below a node the browser never built. A responsive site renders\n // the mobile navigation into the desktop document and hides it with a\n // class, and a reader that counts it sees two `navigation` landmarks where\n // Chrome's tree holds one — a duplicate nobody can reach, reported against\n // markup that is correct. Every rule here is about what a screen reader\n // encounters, so the gate belongs at the walk rather than in each rule.\n if (!exposed(node)) return;\n\n const interactive = node.role !== undefined && INTERACTIVE.has(node.role);\n\n if (interactive && node.name === undefined) {\n findings.push(\n finding(\n 'control-without-name',\n node,\n `<${node.tag}> is a ${node.role} with no accessible name`,\n snapshot,\n ),\n );\n }\n\n if (interactive && insideControl) {\n findings.push(\n finding(\n 'nested-interactive',\n node,\n `a ${node.role} is nested inside another control; only one of the two is reachable`,\n snapshot,\n ),\n );\n }\n\n // `alt=\"\"` is the author saying \"decorative\", which is a correct answer and\n // must not be reported. A missing `alt` is the author saying nothing.\n if (node.role === 'img' && node.name === undefined && node.attributes['alt'] === undefined) {\n findings.push(\n finding(\n 'image-without-alt',\n node,\n `<${node.tag}> has an image role, no accessible name, and no alt=\"\" to say it is decorative`,\n snapshot,\n ),\n );\n }\n\n for (const [attribute, value] of Object.entries(node.attributes)) {\n if (!REFERENCE_ATTRIBUTES.has(attribute) || !value.includes('#extern:')) continue;\n\n findings.push(\n finding(\n 'dangling-reference',\n node,\n // Honest about the ambiguity the aliaser records: from inside the\n // subject, escaping the subtree and pointing at nothing look the same.\n `<${node.tag} ${attribute}> references an element that is not in this subject`,\n snapshot,\n ),\n );\n }\n\n if (node.role === 'heading') {\n const level = levelOf(node);\n if (level !== undefined) headings.push({ node, level });\n }\n\n if (node.role !== undefined && LANDMARKS.has(node.role)) {\n // Keyed by role *and* name: two `navigation` landmarks called \"Primary\"\n // and \"Footer\" are how a page is meant to be built. Two called nothing are\n // two identical entries in the landmark list.\n const key = `${node.role}\\u0000${node.name ?? ''}`;\n const first = landmarks.get(key);\n\n if (first === undefined) {\n landmarks.set(key, node);\n } else {\n findings.push(\n finding(\n 'duplicate-landmark',\n node,\n `a second ${node.role} landmark` +\n (node.name !== undefined ? ` also named \"${node.name}\"` : ' with no name') +\n ', so nothing tells the two apart in a landmark list',\n snapshot,\n ),\n );\n }\n }\n\n if (node.role === 'table' && !hasHeaders(node)) {\n findings.push(\n finding(\n 'table-without-headers',\n node,\n `<${node.tag}> is a table with no header cells, so every cell is announced without ` +\n 'the column it belongs to',\n snapshot,\n ),\n );\n }\n\n const tabindex = Number(node.attributes['tabindex']);\n if (Number.isInteger(tabindex) && tabindex > 0) {\n findings.push(\n finding(\n 'positive-tabindex',\n node,\n `<${node.tag}> has tabindex=${tabindex}, which pulls it ahead of every element in ` +\n 'the document that relies on source order',\n snapshot,\n ),\n );\n }\n\n // WCAG 2.5.3. A control whose accessible name does not contain its visible\n // label cannot be operated by voice: \"click Save\" does nothing when the\n // button reads Save and is named \"Submit form\".\n //\n // Only when the visible text carries a letter. An icon button labelled\n // `aria-label=\"Refresh\"` around a glyph is correct, and a rule that reported\n // it would fire on every icon in every design system.\n if (interactive && node.name !== undefined) {\n const visible = visibleTextOf(node);\n if (\n visible.length > 0 &&\n HAS_LETTER.test(visible) &&\n !node.name.toLowerCase().includes(visible.toLowerCase())\n ) {\n findings.push(\n finding(\n 'label-mismatch',\n node,\n `reads \"${visible}\" and is named \"${node.name}\", so a voice command using the ` +\n 'visible words does not reach it',\n snapshot,\n ),\n );\n }\n }\n\n for (const child of node.children) visit(child, insideControl || interactive);\n }\n}\n\n/**\n * Whether a screen reader reaches this node at all.\n *\n * Three ways out of the accessibility tree, and only one of them is declared.\n * `aria-hidden=\"true\"` and the `hidden` attribute are the author saying so, and\n * arrive as state. `display: none` is the one nobody says: it is a utility\n * class, a media query, a `<details>` that is closed at this width. All three\n * take the subtree with them — `aria-hidden` is not reversible by a descendant,\n * and neither is a box that was never generated.\n *\n * `display` is read from the node's own computed style, which the capture\n * already carries: it is in the style allowlist, so this costs no new field and\n * moves no hash. Absent — a structural-only profile, where no style was\n * computed — the answer is \"exposed\", because refusing to report on a document\n * whose visibility could not be observed would silently empty the inspection.\n */\nfunction exposed(node: SemanticNode): boolean {\n if (node.state?.['hidden'] === true) return false;\n return node.style['display'] !== 'none';\n}\n\nfunction hasHeaders(node: SemanticNode): boolean {\n if (node.role === 'columnheader' || node.role === 'rowheader') return true;\n return node.children.some(hasHeaders);\n}\n\n/**\n * Text a sighted user reads, normalized to single spaces.\n *\n * `aria-hidden` subtrees are excluded, which is what makes the icon-button case\n * work: the glyph is hidden, so the visible text is empty and `label-mismatch`\n * has nothing to compare.\n */\nfunction visibleTextOf(node: SemanticNode): string {\n return runsOf(node).replace(/\\s+/g, ' ').trim();\n}\n\n/**\n * The same separator rule accname uses, so the two readings can be compared.\n *\n * `label-mismatch` asks whether the accessible name contains the visible words,\n * and that question is only meaningful if both sides were assembled the same\n * way. Joining every child with a space while `accessibleName` concatenated\n * them produced the failure this rule exists to prevent, in the rule itself: a\n * flex button reading \"Search ⌘K\" and named \"Search⌘K\" was reported as\n * unreachable by voice, against markup a browser names correctly.\n *\n * So a child contributes separated only when its computed `display` is not\n * inline — which is what a browser does, and which makes `<b>` inside a\n * sentence contribute as part of the word it is inside.\n */\nfunction runsOf(node: SemanticNode): string {\n if (!exposed(node)) return '';\n\n let text = node.text ?? '';\n\n for (const child of node.children) {\n const contribution = runsOf(child);\n if (contribution.length === 0) continue;\n\n const display = child.style['display'];\n const separated = display !== undefined && display !== 'inline' && display !== 'contents';\n text += separated ? ` ${contribution} ` : contribution;\n }\n\n return text;\n}\n\nfunction levelOf(node: SemanticNode): number | undefined {\n // `aria-level` wins, because it is what an assistive technology reads. The tag\n // is the fallback, and a `role=\"heading\"` with neither is not a level at all.\n const declared = node.state?.['level'];\n if (typeof declared === 'number') return declared;\n if (typeof declared === 'string' && /^\\d+$/.test(declared)) return Number(declared);\n\n return HEADING_TAGS[node.tag];\n}\n\nfunction finding(\n rule: FindingRule,\n node: SemanticNode,\n what: string,\n snapshot: SemanticSnapshot,\n): Finding {\n const where = locate(snapshot.root, node.path).where;\n const component = node.provenance?.createdBy ?? node.provenance?.owners[0]?.name;\n\n return {\n rule,\n band: 'a11y',\n path: node.path,\n what,\n ...(where !== '' ? { where } : {}),\n ...(component !== undefined ? { component } : {}),\n ...(node.provenance ? { owners: node.provenance.owners } : {}),\n ...(node.provenance?.source ? { source: node.provenance.source } : {}),\n };\n}\n\nexport interface InspectionReportOptions {\n /** Component → file, so a finding names an edit rather than an identifier. */\n readonly source?: SourceIndex;\n}\n\n/**\n * Findings as the thing a reviewer or an agent reads.\n *\n * Same shape as `summarizeAdjudication`: what, where, which file. A finding a\n * reader has to go and locate is a finding that gets skipped.\n */\nexport function summarizeFindings(\n findings: readonly Finding[],\n options: InspectionReportOptions = {},\n): string {\n if (findings.length === 0) return 'no findings.';\n\n const byRule = new Map<FindingRule, number>();\n for (const found of findings) byRule.set(found.rule, (byRule.get(found.rule) ?? 0) + 1);\n\n const header =\n `${findings.length} finding${findings.length === 1 ? '' : 's'}: ` +\n [...byRule].map(([rule, count]) => `${count} ${rule}`).join(', ');\n\n const lines = findings.flatMap((found) => {\n // The element's own line wins over the component's declaration. Both are\n // `file:line`, so the reader cannot tell them apart and does not need to —\n // either one opens at something worth editing, and the recorded one opens at\n // the element the finding is actually about.\n const declared =\n found.component !== undefined && options.source\n ? resolveSource(found.component, options.source)\n : null;\n const where =\n found.source !== undefined\n ? `${found.source.file}:${String(found.source.line)}`\n : declared\n ? formatSource(declared)\n : '';\n\n const attribution = [found.component, where === '' ? undefined : where]\n .filter((part): part is string => part !== undefined)\n .join(' ');\n\n return [\n ` [${found.rule}] ${found.what}`,\n found.where !== undefined ? ` in ${found.where}` : null,\n attribution === '' ? null : ` ${attribution}`,\n ].filter((line): line is string => line !== null);\n });\n\n return [header, ...lines].join('\\n');\n}\n"]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a run rests on that nothing in it imports.
|
|
3
|
+
*
|
|
4
|
+
* Selection walks one line. It starts at the test harness, moves right through
|
|
5
|
+
* the tests into the repository's own files, and goes out past them into the
|
|
6
|
+
* dependencies ([`records.ts`](./records.ts) holds all three as nodes). Every
|
|
7
|
+
* question it asks is asked *against* the arrows: what depends on the thing
|
|
8
|
+
* that moved.
|
|
9
|
+
*
|
|
10
|
+
* The far-left end of that line answers no such question. A `vitest.config.ts`,
|
|
11
|
+
* a `jest.config.js`, a Next.js setup, a CI workflow, the Node version in a
|
|
12
|
+
* `.nvmrc`: nothing imports them, so nothing has an edge to them, so a walk
|
|
13
|
+
* from one reaches nothing and a walk to one arrives never. They are *before
|
|
14
|
+
* reach* — able to repaint the whole suite and invisible to the only mechanism
|
|
15
|
+
* that could say so.
|
|
16
|
+
*
|
|
17
|
+
* ## Why the accident is not enough
|
|
18
|
+
*
|
|
19
|
+
* A diff that names only such a file already runs everything, because a diff no
|
|
20
|
+
* part of which is in the graph is refused. That holds only while it is the
|
|
21
|
+
* *whole* diff. A CI workflow edited beside one component file is a diff with a
|
|
22
|
+
* seed in it, and the walk from that seed answers confidently for a change it
|
|
23
|
+
* never looked at. The widening was a side effect of having nothing to say, and
|
|
24
|
+
* a side effect stops the moment somebody else has something to say.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the operator names them
|
|
27
|
+
*
|
|
28
|
+
* Because no rule can. *Every changed path the graph does not hold* is the
|
|
29
|
+
* README, the changelog, the fixture JSON, the editor settings: a whole run
|
|
30
|
+
* each, forever, and an operator who turns that off has turned off the config
|
|
31
|
+
* files too. Which paths govern a run is a fact about the repository that only
|
|
32
|
+
* the repository knows, so it is declared — and once declared it is exact,
|
|
33
|
+
* where a heuristic would be both too wide and too narrow on the same diff.
|
|
34
|
+
*
|
|
35
|
+
* ## What declaring one buys beyond its own name
|
|
36
|
+
*
|
|
37
|
+
* Everything below it. A `setup.ts` the config loads, a fixture module only
|
|
38
|
+
* that setup imports, a polyfill, the environment package it names: each is an
|
|
39
|
+
* ordinary file the scan already holds, that nothing imports, whose change
|
|
40
|
+
* reaches no component and narrows the run to nothing. Declared, the entry
|
|
41
|
+
* point is walked *along* the arrows once and that whole set comes with it.
|
|
42
|
+
*
|
|
43
|
+
* ## Where the descent stops
|
|
44
|
+
*
|
|
45
|
+
* At the first file the scan can already reason about. A setup file that
|
|
46
|
+
* imports `src/theme.ts` does not drag `src/theme.ts` in with it: that file has
|
|
47
|
+
* dependents, a change to it is answered exactly by walking them, and pulling
|
|
48
|
+
* it into the harness would trade an exact answer for a whole run — the one
|
|
49
|
+
* direction this is not allowed to be wrong in. The walk avoids sensed files,
|
|
50
|
+
* and avoiding a node stops the walk there rather than stepping over it: what
|
|
51
|
+
* lies below a sensed file is reached *through* it, and it already answers.
|
|
52
|
+
*
|
|
53
|
+
* ## Where the two ends meet
|
|
54
|
+
*
|
|
55
|
+
* The same walk carries into the package layer, and that is the whole of the
|
|
56
|
+
* mixed case. A config imports `jest-environment-jsdom`, which rests on
|
|
57
|
+
* `jsdom`; `jsdom` is bumped; the install comparison names it. It is a package
|
|
58
|
+
* the harness reaches, so the run does not narrow — and no file in the
|
|
59
|
+
* repository ever wrote the word. A change beyond reach, arriving before it.
|
|
60
|
+
*
|
|
61
|
+
* That cost is real and is the operator's to spend: a config that imports a
|
|
62
|
+
* bundler reaches everything the bundler rests on, so a bump inside that set
|
|
63
|
+
* widens. It is the correct answer — the harness did move — and a repository
|
|
64
|
+
* that finds it too wide narrows what it declares rather than what this
|
|
65
|
+
* concludes.
|
|
66
|
+
*/
|
|
67
|
+
import { type Relations } from './graph.js';
|
|
68
|
+
/** The part of a run that sits before the tests, as names. */
|
|
69
|
+
export interface BeforeReach {
|
|
70
|
+
/**
|
|
71
|
+
* The entry points as they were declared, matched against a diff by path.
|
|
72
|
+
*
|
|
73
|
+
* Kept apart from what they reach because they are matched differently: a
|
|
74
|
+
* declared path claims everything under it, so a directory of workflows is
|
|
75
|
+
* one entry, while a file the walk found is one file.
|
|
76
|
+
*/
|
|
77
|
+
readonly entries: readonly string[];
|
|
78
|
+
/** Files below the entry points that the scan does not otherwise sense. */
|
|
79
|
+
readonly files: ReadonlySet<string>;
|
|
80
|
+
/** Packages they rest on, direct and transitive. */
|
|
81
|
+
readonly packages: ReadonlySet<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Declared entry points the graph does not hold, and so has no closure for.
|
|
84
|
+
*
|
|
85
|
+
* Ordinary for most of them: a `.nvmrc`, a CI workflow and a `tsconfig` have
|
|
86
|
+
* nothing below them a scan could read, and they contribute their own name,
|
|
87
|
+
* which is all they have. Not ordinary for a config the scan should have
|
|
88
|
+
* read, where it means the closure that would have come with it — the setup
|
|
89
|
+
* module, the environment — is missing and those files still narrow to
|
|
90
|
+
* nothing. The two are indistinguishable from here, so both are reported and
|
|
91
|
+
* neither is guessed at.
|
|
92
|
+
*/
|
|
93
|
+
readonly unread: readonly string[];
|
|
94
|
+
}
|
|
95
|
+
export interface BeforeReachOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Files the scan already answers for, as the directories they live under.
|
|
98
|
+
*
|
|
99
|
+
* The descent stops at these. Absent, nothing stops it, and one setup import
|
|
100
|
+
* into `src/` would put the repository's own source before reach.
|
|
101
|
+
*/
|
|
102
|
+
readonly sensed?: readonly string[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Walk down from each declared entry point, stopping where the scan takes over.
|
|
106
|
+
*
|
|
107
|
+
* Along the arrows, unlike every other walk here, because this is the one
|
|
108
|
+
* question whose subject has no dependents: *what does the harness rest on*.
|
|
109
|
+
* Type-only edges are not followed — a config's `import type` is erased before
|
|
110
|
+
* the suite runs, exactly as a component's is.
|
|
111
|
+
*/
|
|
112
|
+
export declare function beforeReach(relations: Relations, entries: readonly string[], options?: BeforeReachOptions): BeforeReach;
|
|
113
|
+
/**
|
|
114
|
+
* Which of a diff's own inputs the harness rests on, as they were named.
|
|
115
|
+
*
|
|
116
|
+
* Files and packages together and in that order, because the caller's next act
|
|
117
|
+
* is to print them in one sentence and a reader does not care which list a name
|
|
118
|
+
* came out of. Empty is a real answer: the diff moved nothing the run rests on.
|
|
119
|
+
*
|
|
120
|
+
* A declared entry claims every path under it, so naming a directory of
|
|
121
|
+
* workflows is one line of configuration rather than one per file. A file the
|
|
122
|
+
* walk found claims only itself: it was reached, so it is known exactly, and
|
|
123
|
+
* widening it to its directory would put its neighbours before reach without
|
|
124
|
+
* anybody saying they were.
|
|
125
|
+
*/
|
|
126
|
+
export declare function movedBefore(before: BeforeReach, changed: readonly string[], packages?: readonly string[]): readonly string[];
|
|
127
|
+
/**
|
|
128
|
+
* Whether a path lies under one of these directories.
|
|
129
|
+
*
|
|
130
|
+
* On directory boundaries rather than characters: `src` must not claim
|
|
131
|
+
* `srcery/`, or a repository would put half of itself before reach and find out
|
|
132
|
+
* from the runs that never narrowed. Exported because every caller that draws
|
|
133
|
+
* this boundary over paths draws the same one, and two spellings of it would
|
|
134
|
+
* disagree on the day one of them was fixed.
|
|
135
|
+
*/
|
|
136
|
+
export declare function within(file: string, dirs: readonly string[]): boolean;
|
|
137
|
+
//# sourceMappingURL=before.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a run rests on that nothing in it imports.
|
|
3
|
+
*
|
|
4
|
+
* Selection walks one line. It starts at the test harness, moves right through
|
|
5
|
+
* the tests into the repository's own files, and goes out past them into the
|
|
6
|
+
* dependencies ([`records.ts`](./records.ts) holds all three as nodes). Every
|
|
7
|
+
* question it asks is asked *against* the arrows: what depends on the thing
|
|
8
|
+
* that moved.
|
|
9
|
+
*
|
|
10
|
+
* The far-left end of that line answers no such question. A `vitest.config.ts`,
|
|
11
|
+
* a `jest.config.js`, a Next.js setup, a CI workflow, the Node version in a
|
|
12
|
+
* `.nvmrc`: nothing imports them, so nothing has an edge to them, so a walk
|
|
13
|
+
* from one reaches nothing and a walk to one arrives never. They are *before
|
|
14
|
+
* reach* — able to repaint the whole suite and invisible to the only mechanism
|
|
15
|
+
* that could say so.
|
|
16
|
+
*
|
|
17
|
+
* ## Why the accident is not enough
|
|
18
|
+
*
|
|
19
|
+
* A diff that names only such a file already runs everything, because a diff no
|
|
20
|
+
* part of which is in the graph is refused. That holds only while it is the
|
|
21
|
+
* *whole* diff. A CI workflow edited beside one component file is a diff with a
|
|
22
|
+
* seed in it, and the walk from that seed answers confidently for a change it
|
|
23
|
+
* never looked at. The widening was a side effect of having nothing to say, and
|
|
24
|
+
* a side effect stops the moment somebody else has something to say.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the operator names them
|
|
27
|
+
*
|
|
28
|
+
* Because no rule can. *Every changed path the graph does not hold* is the
|
|
29
|
+
* README, the changelog, the fixture JSON, the editor settings: a whole run
|
|
30
|
+
* each, forever, and an operator who turns that off has turned off the config
|
|
31
|
+
* files too. Which paths govern a run is a fact about the repository that only
|
|
32
|
+
* the repository knows, so it is declared — and once declared it is exact,
|
|
33
|
+
* where a heuristic would be both too wide and too narrow on the same diff.
|
|
34
|
+
*
|
|
35
|
+
* ## What declaring one buys beyond its own name
|
|
36
|
+
*
|
|
37
|
+
* Everything below it. A `setup.ts` the config loads, a fixture module only
|
|
38
|
+
* that setup imports, a polyfill, the environment package it names: each is an
|
|
39
|
+
* ordinary file the scan already holds, that nothing imports, whose change
|
|
40
|
+
* reaches no component and narrows the run to nothing. Declared, the entry
|
|
41
|
+
* point is walked *along* the arrows once and that whole set comes with it.
|
|
42
|
+
*
|
|
43
|
+
* ## Where the descent stops
|
|
44
|
+
*
|
|
45
|
+
* At the first file the scan can already reason about. A setup file that
|
|
46
|
+
* imports `src/theme.ts` does not drag `src/theme.ts` in with it: that file has
|
|
47
|
+
* dependents, a change to it is answered exactly by walking them, and pulling
|
|
48
|
+
* it into the harness would trade an exact answer for a whole run — the one
|
|
49
|
+
* direction this is not allowed to be wrong in. The walk avoids sensed files,
|
|
50
|
+
* and avoiding a node stops the walk there rather than stepping over it: what
|
|
51
|
+
* lies below a sensed file is reached *through* it, and it already answers.
|
|
52
|
+
*
|
|
53
|
+
* ## Where the two ends meet
|
|
54
|
+
*
|
|
55
|
+
* The same walk carries into the package layer, and that is the whole of the
|
|
56
|
+
* mixed case. A config imports `jest-environment-jsdom`, which rests on
|
|
57
|
+
* `jsdom`; `jsdom` is bumped; the install comparison names it. It is a package
|
|
58
|
+
* the harness reaches, so the run does not narrow — and no file in the
|
|
59
|
+
* repository ever wrote the word. A change beyond reach, arriving before it.
|
|
60
|
+
*
|
|
61
|
+
* That cost is real and is the operator's to spend: a config that imports a
|
|
62
|
+
* bundler reaches everything the bundler rests on, so a bump inside that set
|
|
63
|
+
* widens. It is the correct answer — the harness did move — and a repository
|
|
64
|
+
* that finds it too wide narrows what it declares rather than what this
|
|
65
|
+
* concludes.
|
|
66
|
+
*/
|
|
67
|
+
import { nodeAt } from './graph.js';
|
|
68
|
+
import { dependenciesOf } from './reach.js';
|
|
69
|
+
/**
|
|
70
|
+
* Walk down from each declared entry point, stopping where the scan takes over.
|
|
71
|
+
*
|
|
72
|
+
* Along the arrows, unlike every other walk here, because this is the one
|
|
73
|
+
* question whose subject has no dependents: *what does the harness rest on*.
|
|
74
|
+
* Type-only edges are not followed — a config's `import type` is erased before
|
|
75
|
+
* the suite runs, exactly as a component's is.
|
|
76
|
+
*/
|
|
77
|
+
export function beforeReach(relations, entries, options = {}) {
|
|
78
|
+
const files = new Set();
|
|
79
|
+
const packages = new Set();
|
|
80
|
+
const unread = [];
|
|
81
|
+
if (entries.length === 0)
|
|
82
|
+
return { entries, files, packages, unread };
|
|
83
|
+
const sensed = options.sensed ?? [];
|
|
84
|
+
const held = new Map();
|
|
85
|
+
for (let id = 0; id < relations.names.length; id += 1) {
|
|
86
|
+
const node = nodeAt(relations, id);
|
|
87
|
+
if (node?.kind === 'file')
|
|
88
|
+
held.set(node.name, id);
|
|
89
|
+
}
|
|
90
|
+
const seeds = [];
|
|
91
|
+
for (const entry of entries) {
|
|
92
|
+
const id = held.get(entry);
|
|
93
|
+
if (id === undefined)
|
|
94
|
+
unread.push(entry);
|
|
95
|
+
else
|
|
96
|
+
seeds.push(id);
|
|
97
|
+
}
|
|
98
|
+
if (seeds.length === 0)
|
|
99
|
+
return { entries, files, packages, unread };
|
|
100
|
+
// Avoided before the walk rather than filtered after it. A sensed file is not
|
|
101
|
+
// a step on the way to something else here: whatever it imports, it imports
|
|
102
|
+
// as a file the scan holds, and the dependents of *that* file are the exact
|
|
103
|
+
// answer the harness would have replaced with a whole run.
|
|
104
|
+
const entered = new Set(seeds);
|
|
105
|
+
const avoid = [];
|
|
106
|
+
for (const [name, id] of held) {
|
|
107
|
+
if (!entered.has(id) && within(name, sensed))
|
|
108
|
+
avoid.push(id);
|
|
109
|
+
}
|
|
110
|
+
for (const id of dependenciesOf(relations, seeds, { avoid }).reached) {
|
|
111
|
+
const node = nodeAt(relations, id);
|
|
112
|
+
if (node === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
if (node.kind === 'file')
|
|
115
|
+
files.add(node.name);
|
|
116
|
+
else if (node.kind === 'package')
|
|
117
|
+
packages.add(node.name);
|
|
118
|
+
}
|
|
119
|
+
return { entries, files, packages, unread };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Which of a diff's own inputs the harness rests on, as they were named.
|
|
123
|
+
*
|
|
124
|
+
* Files and packages together and in that order, because the caller's next act
|
|
125
|
+
* is to print them in one sentence and a reader does not care which list a name
|
|
126
|
+
* came out of. Empty is a real answer: the diff moved nothing the run rests on.
|
|
127
|
+
*
|
|
128
|
+
* A declared entry claims every path under it, so naming a directory of
|
|
129
|
+
* workflows is one line of configuration rather than one per file. A file the
|
|
130
|
+
* walk found claims only itself: it was reached, so it is known exactly, and
|
|
131
|
+
* widening it to its directory would put its neighbours before reach without
|
|
132
|
+
* anybody saying they were.
|
|
133
|
+
*/
|
|
134
|
+
export function movedBefore(before, changed, packages = []) {
|
|
135
|
+
return [
|
|
136
|
+
...changed.filter((file) => before.files.has(file) || within(file, before.entries)),
|
|
137
|
+
...packages.filter((name) => before.packages.has(name)),
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Whether a path lies under one of these directories.
|
|
142
|
+
*
|
|
143
|
+
* On directory boundaries rather than characters: `src` must not claim
|
|
144
|
+
* `srcery/`, or a repository would put half of itself before reach and find out
|
|
145
|
+
* from the runs that never narrowed. Exported because every caller that draws
|
|
146
|
+
* this boundary over paths draws the same one, and two spellings of it would
|
|
147
|
+
* disagree on the day one of them was fixed.
|
|
148
|
+
*/
|
|
149
|
+
export function within(file, dirs) {
|
|
150
|
+
return dirs.some((dir) => {
|
|
151
|
+
const normalized = dir.replace(/\/+$/, '');
|
|
152
|
+
return normalized === '.' || file === normalized || file.startsWith(`${normalized}/`);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=before.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before.js","sourceRoot":"","sources":["../../src/relate/before.ts"],"names":[],"mappings":"AAAA;;;;;;;;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KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACnF,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,IAAuB;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACvB,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,OAAO,UAAU,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * What a run rests on that nothing in it imports.\n *\n * Selection walks one line. It starts at the test harness, moves right through\n * the tests into the repository's own files, and goes out past them into the\n * dependencies ([`records.ts`](./records.ts) holds all three as nodes). Every\n * question it asks is asked *against* the arrows: what depends on the thing\n * that moved.\n *\n * The far-left end of that line answers no such question. A `vitest.config.ts`,\n * a `jest.config.js`, a Next.js setup, a CI workflow, the Node version in a\n * `.nvmrc`: nothing imports them, so nothing has an edge to them, so a walk\n * from one reaches nothing and a walk to one arrives never. They are *before\n * reach* — able to repaint the whole suite and invisible to the only mechanism\n * that could say so.\n *\n * ## Why the accident is not enough\n *\n * A diff that names only such a file already runs everything, because a diff no\n * part of which is in the graph is refused. That holds only while it is the\n * *whole* diff. A CI workflow edited beside one component file is a diff with a\n * seed in it, and the walk from that seed answers confidently for a change it\n * never looked at. The widening was a side effect of having nothing to say, and\n * a side effect stops the moment somebody else has something to say.\n *\n * ## Why the operator names them\n *\n * Because no rule can. *Every changed path the graph does not hold* is the\n * README, the changelog, the fixture JSON, the editor settings: a whole run\n * each, forever, and an operator who turns that off has turned off the config\n * files too. Which paths govern a run is a fact about the repository that only\n * the repository knows, so it is declared — and once declared it is exact,\n * where a heuristic would be both too wide and too narrow on the same diff.\n *\n * ## What declaring one buys beyond its own name\n *\n * Everything below it. A `setup.ts` the config loads, a fixture module only\n * that setup imports, a polyfill, the environment package it names: each is an\n * ordinary file the scan already holds, that nothing imports, whose change\n * reaches no component and narrows the run to nothing. Declared, the entry\n * point is walked *along* the arrows once and that whole set comes with it.\n *\n * ## Where the descent stops\n *\n * At the first file the scan can already reason about. A setup file that\n * imports `src/theme.ts` does not drag `src/theme.ts` in with it: that file has\n * dependents, a change to it is answered exactly by walking them, and pulling\n * it into the harness would trade an exact answer for a whole run — the one\n * direction this is not allowed to be wrong in. The walk avoids sensed files,\n * and avoiding a node stops the walk there rather than stepping over it: what\n * lies below a sensed file is reached *through* it, and it already answers.\n *\n * ## Where the two ends meet\n *\n * The same walk carries into the package layer, and that is the whole of the\n * mixed case. A config imports `jest-environment-jsdom`, which rests on\n * `jsdom`; `jsdom` is bumped; the install comparison names it. It is a package\n * the harness reaches, so the run does not narrow — and no file in the\n * repository ever wrote the word. A change beyond reach, arriving before it.\n *\n * That cost is real and is the operator's to spend: a config that imports a\n * bundler reaches everything the bundler rests on, so a bump inside that set\n * widens. It is the correct answer — the harness did move — and a repository\n * that finds it too wide narrows what it declares rather than what this\n * concludes.\n */\n\nimport { nodeAt, type NodeId, type Relations } from './graph.js';\nimport { dependenciesOf } from './reach.js';\n\n/** The part of a run that sits before the tests, as names. */\nexport interface BeforeReach {\n /**\n * The entry points as they were declared, matched against a diff by path.\n *\n * Kept apart from what they reach because they are matched differently: a\n * declared path claims everything under it, so a directory of workflows is\n * one entry, while a file the walk found is one file.\n */\n readonly entries: readonly string[];\n /** Files below the entry points that the scan does not otherwise sense. */\n readonly files: ReadonlySet<string>;\n /** Packages they rest on, direct and transitive. */\n readonly packages: ReadonlySet<string>;\n /**\n * Declared entry points the graph does not hold, and so has no closure for.\n *\n * Ordinary for most of them: a `.nvmrc`, a CI workflow and a `tsconfig` have\n * nothing below them a scan could read, and they contribute their own name,\n * which is all they have. Not ordinary for a config the scan should have\n * read, where it means the closure that would have come with it — the setup\n * module, the environment — is missing and those files still narrow to\n * nothing. The two are indistinguishable from here, so both are reported and\n * neither is guessed at.\n */\n readonly unread: readonly string[];\n}\n\nexport interface BeforeReachOptions {\n /**\n * Files the scan already answers for, as the directories they live under.\n *\n * The descent stops at these. Absent, nothing stops it, and one setup import\n * into `src/` would put the repository's own source before reach.\n */\n readonly sensed?: readonly string[];\n}\n\n/**\n * Walk down from each declared entry point, stopping where the scan takes over.\n *\n * Along the arrows, unlike every other walk here, because this is the one\n * question whose subject has no dependents: *what does the harness rest on*.\n * Type-only edges are not followed — a config's `import type` is erased before\n * the suite runs, exactly as a component's is.\n */\nexport function beforeReach(\n relations: Relations,\n entries: readonly string[],\n options: BeforeReachOptions = {},\n): BeforeReach {\n const files = new Set<string>();\n const packages = new Set<string>();\n const unread: string[] = [];\n if (entries.length === 0) return { entries, files, packages, unread };\n\n const sensed = options.sensed ?? [];\n const held = new Map<string, NodeId>();\n for (let id = 0; id < relations.names.length; id += 1) {\n const node = nodeAt(relations, id);\n if (node?.kind === 'file') held.set(node.name, id);\n }\n\n const seeds: NodeId[] = [];\n for (const entry of entries) {\n const id = held.get(entry);\n if (id === undefined) unread.push(entry);\n else seeds.push(id);\n }\n if (seeds.length === 0) return { entries, files, packages, unread };\n\n // Avoided before the walk rather than filtered after it. A sensed file is not\n // a step on the way to something else here: whatever it imports, it imports\n // as a file the scan holds, and the dependents of *that* file are the exact\n // answer the harness would have replaced with a whole run.\n const entered = new Set(seeds);\n const avoid: NodeId[] = [];\n for (const [name, id] of held) {\n if (!entered.has(id) && within(name, sensed)) avoid.push(id);\n }\n\n for (const id of dependenciesOf(relations, seeds, { avoid }).reached) {\n const node = nodeAt(relations, id);\n if (node === undefined) continue;\n if (node.kind === 'file') files.add(node.name);\n else if (node.kind === 'package') packages.add(node.name);\n }\n\n return { entries, files, packages, unread };\n}\n\n/**\n * Which of a diff's own inputs the harness rests on, as they were named.\n *\n * Files and packages together and in that order, because the caller's next act\n * is to print them in one sentence and a reader does not care which list a name\n * came out of. Empty is a real answer: the diff moved nothing the run rests on.\n *\n * A declared entry claims every path under it, so naming a directory of\n * workflows is one line of configuration rather than one per file. A file the\n * walk found claims only itself: it was reached, so it is known exactly, and\n * widening it to its directory would put its neighbours before reach without\n * anybody saying they were.\n */\nexport function movedBefore(\n before: BeforeReach,\n changed: readonly string[],\n packages: readonly string[] = [],\n): readonly string[] {\n return [\n ...changed.filter((file) => before.files.has(file) || within(file, before.entries)),\n ...packages.filter((name) => before.packages.has(name)),\n ];\n}\n\n/**\n * Whether a path lies under one of these directories.\n *\n * On directory boundaries rather than characters: `src` must not claim\n * `srcery/`, or a repository would put half of itself before reach and find out\n * from the runs that never narrowed. Exported because every caller that draws\n * this boundary over paths draws the same one, and two spellings of it would\n * disagree on the day one of them was fixed.\n */\nexport function within(file: string, dirs: readonly string[]): boolean {\n return dirs.some((dir) => {\n const normalized = dir.replace(/\\/+$/, '');\n return normalized === '.' || file === normalized || file.startsWith(`${normalized}/`);\n });\n}\n"]}
|
package/dist/relate/graph.d.ts
CHANGED
|
@@ -42,15 +42,22 @@
|
|
|
42
42
|
*
|
|
43
43
|
* ## Nodes are typed, because files are not the last kind
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* That is deliberate rather than incidental. A
|
|
48
|
-
* renders `Chip`* — is another edge kind
|
|
49
|
-
* same structure, and
|
|
45
|
+
* Three kinds and the joins between them: a `file` graph built from imports, the
|
|
46
|
+
* `component` nodes the source index already knows how to find, and a `package`
|
|
47
|
+
* for each name an install resolved. That is deliberate rather than incidental. A
|
|
48
|
+
* component relation — *`TodoFooter` renders `Chip`* — is another edge kind
|
|
49
|
+
* between nodes of another kind in this same structure, and
|
|
50
50
|
* [`composition.md`](../../../../docs/composition.md) already computes exactly
|
|
51
51
|
* that relation from what a run rendered. One graph means the static answer and
|
|
52
52
|
* the rendered answer are joinable rather than adjacent.
|
|
53
53
|
*
|
|
54
|
+
* A `package` earns its kind for the same reason and one more: it is the far end
|
|
55
|
+
* of the same line. A run starts at the harness, arrives at our code through the
|
|
56
|
+
* tests, and leaves it again at the packages — so a bumped dependency is a node
|
|
57
|
+
* like any other, and *which of our files a new `jsdom` can have moved* is the
|
|
58
|
+
* one traversal this file already performs, seeded on the other side
|
|
59
|
+
* ([`docs/selecting.md`](../../../../docs/selecting.md)).
|
|
60
|
+
*
|
|
54
61
|
* ## What it is not
|
|
55
62
|
*
|
|
56
63
|
* **Not a build graph.** It has no notion of a task, an output or a cache key,
|
|
@@ -62,7 +69,7 @@
|
|
|
62
69
|
* disk.
|
|
63
70
|
*/
|
|
64
71
|
/** Node kinds, in id order. An id is an index into this, never the word. */
|
|
65
|
-
export declare const NODE_KINDS: readonly ['file', 'component'];
|
|
72
|
+
export declare const NODE_KINDS: readonly ['file', 'component', 'package'];
|
|
66
73
|
export type NodeKind = (typeof NODE_KINDS)[number];
|
|
67
74
|
/**
|
|
68
75
|
* Edge kinds, in id order.
|
|
@@ -86,16 +93,26 @@ export declare const EDGE_KINDS: readonly [
|
|
|
86
93
|
/** A stylesheet's `@import`, or a `url()` reaching a font or an image. */
|
|
87
94
|
'asset',
|
|
88
95
|
/** A component to the file that declares it. */
|
|
89
|
-
'declared-in'
|
|
96
|
+
'declared-in',
|
|
97
|
+
/** A package to a package its install resolved beneath it. */
|
|
98
|
+
'depends-on'];
|
|
90
99
|
export type EdgeKind = (typeof EDGE_KINDS)[number];
|
|
91
100
|
/**
|
|
92
101
|
* The edge kinds something at runtime can follow: every kind but `type`. The
|
|
93
|
-
* default for a reach
|
|
102
|
+
* default for a reach, and the list a caller widens from. A closure folds a
|
|
103
|
+
* shorter list (`CLOSURE_EDGES`), because a digest is a claim about bytes and
|
|
104
|
+
* one of these kinds leads nowhere any bytes are.
|
|
94
105
|
*/
|
|
95
106
|
export declare const RUNTIME_EDGES: readonly EdgeKind[];
|
|
96
107
|
export interface Node {
|
|
97
108
|
readonly kind: NodeKind;
|
|
98
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Repository-relative for a file, the identifier for a component, and for a
|
|
111
|
+
* package the name source code imports it by — `@mui/material`, never a
|
|
112
|
+
* version and never a resolution. Which copy a resolver handed any one
|
|
113
|
+
* importer is unanswerable without running that resolver, and the question
|
|
114
|
+
* this graph is asked never needs it ([`sense/lock`](../../../sense/src/lock/index.ts)).
|
|
115
|
+
*/
|
|
99
116
|
readonly name: string;
|
|
100
117
|
}
|
|
101
118
|
export interface Relation {
|
|
@@ -164,8 +181,8 @@ export interface Relations {
|
|
|
164
181
|
* The lookup key for a node.
|
|
165
182
|
*
|
|
166
183
|
* Runtime only; nothing serializes this, and no code parses it back — the
|
|
167
|
-
* separator only has to be injective, and it is, because a kind is one of
|
|
168
|
-
* fixed words and
|
|
184
|
+
* separator only has to be injective, and it is, because a kind is one of a few
|
|
185
|
+
* fixed words and none contains a `:`. A name that contains one is therefore
|
|
169
186
|
* fine.
|
|
170
187
|
*
|
|
171
188
|
* The obvious separator is a NUL, and it is the wrong one: a source file
|