@contentful/experience-design-system-extraction 2.34.5-dev-build-d08439d.0 → 2.34.5-dev-build-5e798cb1.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/dist/package.json +1 -1
- package/dist/src/extract/astro.js +2 -3
- package/dist/src/extract/react.js +22 -3
- package/dist/src/extract/structural-slot-evidence.d.ts +27 -0
- package/dist/src/extract/structural-slot-evidence.js +157 -0
- package/dist/src/extract/svelte.js +2 -3
- package/dist/src/extract/vue.js +2 -3
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experience-design-system-extraction",
|
|
3
|
-
"version": "2.34.5-dev-build-
|
|
3
|
+
"version": "2.34.5-dev-build-5e798cb1.0",
|
|
4
4
|
"description": "Component extraction engine for the Contentful Experience Design System SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { basename } from 'node:path';
|
|
2
1
|
import os from 'node:os';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
3
|
import { Project, Node } from 'ts-morph';
|
|
4
4
|
import { createSortedExtractionResult, runFileExtractionWorkers } from './file-extraction-workers.js';
|
|
5
5
|
import { resolveTypeProperty } from './resolve-type-property.js';
|
|
@@ -217,10 +217,9 @@ function extractFromAstroFile(filePath, source) {
|
|
|
217
217
|
slots,
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
-
const ASTRO_EXTRACT_CONCURRENCY = Number(process.env['EDS_EXTRACT_CONCURRENCY'] ?? 0) || os.cpus().length;
|
|
221
220
|
export async function extractAstroComponents(filePaths, onProgress) {
|
|
222
221
|
const astroFiles = filePaths.filter((f) => f.endsWith('.astro'));
|
|
223
|
-
const { items: components, warnings } = await runFileExtractionWorkers(astroFiles,
|
|
222
|
+
const { items: components, warnings } = await runFileExtractionWorkers(astroFiles, os.cpus().length, async (filePath, source) => ({
|
|
224
223
|
item: extractFromAstroFile(filePath, source),
|
|
225
224
|
}), (filePath, error) => `Failed to extract from ${filePath}: ${error instanceof Error ? error.message : String(error)}`, onProgress);
|
|
226
225
|
return createSortedExtractionResult(components, warnings);
|
|
@@ -3,7 +3,7 @@ import { extractAllowedValues, getNodeDefinitions, getTypeReferenceName, getType
|
|
|
3
3
|
import { shouldBeSlot } from './slot-detection.js';
|
|
4
4
|
import { extractAllowedComponentsFromTypeText, extractAllowedComponentsFromJsdoc } from './slot-allowed-components.js';
|
|
5
5
|
import { getSourceLineMetadata } from './source-line-metadata.js';
|
|
6
|
-
import { collectTypePredicateComponentReferences, collectRuntimeTypeCheckComponentReferences, collectRenderedComponentReferences, } from './structural-slot-evidence.js';
|
|
6
|
+
import { collectTypePredicateComponentReferences, collectRuntimeTypeCheckComponentReferences, collectRenderedComponentReferences, collectArrayMapRenderComponentReferences, } from './structural-slot-evidence.js';
|
|
7
7
|
const REACT_ELEMENT_GENERIC_TEST = /(?:React\.)?ReactElement\s*<\s*[A-Za-z_$][\w$.]*/;
|
|
8
8
|
function isReactElementGenericSlotType(typeText) {
|
|
9
9
|
return REACT_ELEMENT_GENERIC_TEST.test(typeText);
|
|
@@ -1705,13 +1705,32 @@ export async function extractReactComponents(filePaths) {
|
|
|
1705
1705
|
for (const c of components) {
|
|
1706
1706
|
const fromFile = structuralNamesForFile(c.source);
|
|
1707
1707
|
const fromRender = c._funcNode ? collectRenderedComponentReferences(c._funcNode, componentNames, c.name) : [];
|
|
1708
|
-
const
|
|
1708
|
+
const propTypesByName = new Map(c.props.map((p) => [p.name, p.type]));
|
|
1709
|
+
const fromArrayMap = c._funcNode
|
|
1710
|
+
? collectArrayMapRenderComponentReferences(c._funcNode, componentNames, c.name, propTypesByName)
|
|
1711
|
+
: [];
|
|
1712
|
+
const structural = new Set([...fromFile, ...fromRender, ...fromArrayMap]);
|
|
1709
1713
|
if (structural.size === 0)
|
|
1710
1714
|
continue;
|
|
1715
|
+
// Signal D — array-map render — is the only signal that can imply an
|
|
1716
|
+
// authorable compositional slot the parent didn't declare. When it fires
|
|
1717
|
+
// and the parent has no declared slots at all, synthesise a default
|
|
1718
|
+
// `children` slot so the evidence has somewhere to land. Signals A/B/C
|
|
1719
|
+
// still only decorate existing slots to keep the current provenance
|
|
1720
|
+
// guarantees intact.
|
|
1721
|
+
const synthesisedSlot = fromArrayMap.length > 0 && c.slots.length === 0 ? { name: 'children', isDefault: true } : undefined;
|
|
1722
|
+
if (synthesisedSlot) {
|
|
1723
|
+
c.slots.push(synthesisedSlot);
|
|
1724
|
+
}
|
|
1711
1725
|
for (const slot of c.slots) {
|
|
1712
1726
|
if (slot.allowedComponents && slot.allowedComponents.length > 0)
|
|
1713
1727
|
continue;
|
|
1714
|
-
|
|
1728
|
+
// Synthesised slots carry ONLY Signal D's mapped children — the strict
|
|
1729
|
+
// signal is what earned the slot; unioning in Signal C's render-body
|
|
1730
|
+
// hits would smuggle private structural pieces (icons, headings) into
|
|
1731
|
+
// an authorable slot the caller can't actually compose against.
|
|
1732
|
+
// Declared slots keep the existing union so A/B/C still enrich them.
|
|
1733
|
+
slot.structuralAllowedComponents = slot === synthesisedSlot ? [...fromArrayMap].sort() : [...structural].sort();
|
|
1715
1734
|
}
|
|
1716
1735
|
}
|
|
1717
1736
|
for (const c of components) {
|
|
@@ -33,4 +33,31 @@ export declare function collectRuntimeTypeCheckComponentReferences(sourceFile: S
|
|
|
33
33
|
* caller-supplied content — the weakest-trust signal, kept last in the rank.
|
|
34
34
|
*/
|
|
35
35
|
export declare function collectRenderedComponentReferences(funcNode: FunctionLike, componentNames: ReadonlySet<string>, ownComponentName: string): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Signal D — data-array render: the component's render body maps an array-
|
|
38
|
+
* typed prop to a known child component (e.g. `{items.map(x => <ItemRow
|
|
39
|
+
* .../>)}` inside a parent whose `items` prop is a plain data array).
|
|
40
|
+
*
|
|
41
|
+
* Fires only when ALL strict-gating conditions hold, to keep false positives
|
|
42
|
+
* off in the common case where mapping over data doesn't imply an authorable
|
|
43
|
+
* compositional slot. Conditions are listed in check order (cheap fails
|
|
44
|
+
* first) so the loop-body labels line up 1-to-1 with this list:
|
|
45
|
+
*
|
|
46
|
+
* 1. The `.map` callee is an identifier that matches a declared prop on
|
|
47
|
+
* the parent (`propNames`).
|
|
48
|
+
* 2. The prop's declared type text is a plain data array — not
|
|
49
|
+
* `ReactNode[]` / `ReactElement<...>[]` / `React.ReactNode[]`, etc.
|
|
50
|
+
* (those cases are already covered by the typed-slot pass, so firing
|
|
51
|
+
* this signal for them would double-count.)
|
|
52
|
+
* 3. The callback returns a JSX element whose tag is an identifier
|
|
53
|
+
* resolving to a known component (`componentNames`).
|
|
54
|
+
* 4. That child component is NOT rendered anywhere else in the parent's
|
|
55
|
+
* body — the map is the only render site.
|
|
56
|
+
*
|
|
57
|
+
* When all four hold, the mapped child is a strong candidate for a
|
|
58
|
+
* synthesised default slot on the parent — the extractor treats it that way
|
|
59
|
+
* only when there's no other slot to hang the evidence on (see the caller in
|
|
60
|
+
* react.ts).
|
|
61
|
+
*/
|
|
62
|
+
export declare function collectArrayMapRenderComponentReferences(funcNode: FunctionLike, componentNames: ReadonlySet<string>, ownComponentName: string, propTypesByName: ReadonlyMap<string, string>): string[];
|
|
36
63
|
export {};
|
|
@@ -119,3 +119,160 @@ export function collectRenderedComponentReferences(funcNode, componentNames, own
|
|
|
119
119
|
}
|
|
120
120
|
return [...found].sort();
|
|
121
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Signal D — data-array render: the component's render body maps an array-
|
|
124
|
+
* typed prop to a known child component (e.g. `{items.map(x => <ItemRow
|
|
125
|
+
* .../>)}` inside a parent whose `items` prop is a plain data array).
|
|
126
|
+
*
|
|
127
|
+
* Fires only when ALL strict-gating conditions hold, to keep false positives
|
|
128
|
+
* off in the common case where mapping over data doesn't imply an authorable
|
|
129
|
+
* compositional slot. Conditions are listed in check order (cheap fails
|
|
130
|
+
* first) so the loop-body labels line up 1-to-1 with this list:
|
|
131
|
+
*
|
|
132
|
+
* 1. The `.map` callee is an identifier that matches a declared prop on
|
|
133
|
+
* the parent (`propNames`).
|
|
134
|
+
* 2. The prop's declared type text is a plain data array — not
|
|
135
|
+
* `ReactNode[]` / `ReactElement<...>[]` / `React.ReactNode[]`, etc.
|
|
136
|
+
* (those cases are already covered by the typed-slot pass, so firing
|
|
137
|
+
* this signal for them would double-count.)
|
|
138
|
+
* 3. The callback returns a JSX element whose tag is an identifier
|
|
139
|
+
* resolving to a known component (`componentNames`).
|
|
140
|
+
* 4. That child component is NOT rendered anywhere else in the parent's
|
|
141
|
+
* body — the map is the only render site.
|
|
142
|
+
*
|
|
143
|
+
* When all four hold, the mapped child is a strong candidate for a
|
|
144
|
+
* synthesised default slot on the parent — the extractor treats it that way
|
|
145
|
+
* only when there's no other slot to hang the evidence on (see the caller in
|
|
146
|
+
* react.ts).
|
|
147
|
+
*/
|
|
148
|
+
export function collectArrayMapRenderComponentReferences(funcNode, componentNames, ownComponentName, propTypesByName) {
|
|
149
|
+
const found = new Set();
|
|
150
|
+
const propNames = new Set(propTypesByName.keys());
|
|
151
|
+
const renderCountByComponent = new Map();
|
|
152
|
+
const bumpRenderCount = (name) => {
|
|
153
|
+
renderCountByComponent.set(name, (renderCountByComponent.get(name) ?? 0) + 1);
|
|
154
|
+
};
|
|
155
|
+
for (const jsxElement of [
|
|
156
|
+
...funcNode.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement),
|
|
157
|
+
...funcNode.getDescendantsOfKind(SyntaxKind.JsxOpeningElement),
|
|
158
|
+
]) {
|
|
159
|
+
const tagName = jsxElement.getTagNameNode().getText();
|
|
160
|
+
if (isIntrinsicJsxElement(tagName))
|
|
161
|
+
continue;
|
|
162
|
+
if (tagName === ownComponentName)
|
|
163
|
+
continue;
|
|
164
|
+
if (!componentNames.has(tagName))
|
|
165
|
+
continue;
|
|
166
|
+
bumpRenderCount(tagName);
|
|
167
|
+
}
|
|
168
|
+
for (const callExpr of funcNode.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
169
|
+
const callee = callExpr.getExpression();
|
|
170
|
+
if (!Node.isPropertyAccessExpression(callee))
|
|
171
|
+
continue;
|
|
172
|
+
if (callee.getName() !== 'map')
|
|
173
|
+
continue;
|
|
174
|
+
// Condition 1: callee's receiver must be a bare prop identifier.
|
|
175
|
+
const receiver = callee.getExpression();
|
|
176
|
+
if (!Node.isIdentifier(receiver))
|
|
177
|
+
continue;
|
|
178
|
+
const propName = receiver.getText();
|
|
179
|
+
if (!propNames.has(propName))
|
|
180
|
+
continue;
|
|
181
|
+
// Condition 2: prop's declared type must be a plain data array — reject
|
|
182
|
+
// ReactNode / ReactElement / JSX.Element unions so we don't overlap with
|
|
183
|
+
// the typed-slot pass.
|
|
184
|
+
const propTypeText = propTypesByName.get(propName) ?? '';
|
|
185
|
+
if (isJsxCarryingTypeText(propTypeText))
|
|
186
|
+
continue;
|
|
187
|
+
// Condition 3: callback must be a function expression whose return is a
|
|
188
|
+
// JSX element resolving to a known component.
|
|
189
|
+
const [callbackArg] = callExpr.getArguments();
|
|
190
|
+
if (!callbackArg)
|
|
191
|
+
continue;
|
|
192
|
+
if (!Node.isArrowFunction(callbackArg) && !Node.isFunctionExpression(callbackArg))
|
|
193
|
+
continue;
|
|
194
|
+
const returnedJsxTag = getReturnedJsxTagName(callbackArg);
|
|
195
|
+
if (!returnedJsxTag)
|
|
196
|
+
continue;
|
|
197
|
+
if (returnedJsxTag === ownComponentName)
|
|
198
|
+
continue;
|
|
199
|
+
if (!componentNames.has(returnedJsxTag))
|
|
200
|
+
continue;
|
|
201
|
+
// Condition 4: the child must ONLY be rendered inside this map. Any
|
|
202
|
+
// additional render site elsewhere in the parent means it's a private
|
|
203
|
+
// implementation detail, not a composable slot child.
|
|
204
|
+
const totalRenders = renderCountByComponent.get(returnedJsxTag) ?? 0;
|
|
205
|
+
if (totalRenders !== 1)
|
|
206
|
+
continue;
|
|
207
|
+
found.add(returnedJsxTag);
|
|
208
|
+
}
|
|
209
|
+
return [...found].sort();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns the tag identifier of the JSX element the callback returns, or
|
|
213
|
+
* `undefined` if the callback doesn't return exactly one identifier-tagged
|
|
214
|
+
* JSX element. Accepts both arrow-with-expression bodies and function bodies
|
|
215
|
+
* with a single return statement. Fragment wrappers with a single JSX child
|
|
216
|
+
* are unwrapped.
|
|
217
|
+
*/
|
|
218
|
+
function getReturnedJsxTagName(callback) {
|
|
219
|
+
const body = callback.getBody();
|
|
220
|
+
const jsxNode = unwrapReturnedJsx(body);
|
|
221
|
+
if (!jsxNode)
|
|
222
|
+
return undefined;
|
|
223
|
+
if (Node.isJsxSelfClosingElement(jsxNode) || Node.isJsxOpeningElement(jsxNode)) {
|
|
224
|
+
return jsxNode.getTagNameNode().getText();
|
|
225
|
+
}
|
|
226
|
+
if (Node.isJsxElement(jsxNode)) {
|
|
227
|
+
return jsxNode.getOpeningElement().getTagNameNode().getText();
|
|
228
|
+
}
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
function unwrapReturnedJsx(bodyOrExpr) {
|
|
232
|
+
// Arrow with expression body: `(x) => <Foo/>` or `(x) => <><Foo/></>`
|
|
233
|
+
if (Node.isJsxElement(bodyOrExpr) ||
|
|
234
|
+
Node.isJsxSelfClosingElement(bodyOrExpr) ||
|
|
235
|
+
Node.isJsxOpeningElement(bodyOrExpr)) {
|
|
236
|
+
return bodyOrExpr;
|
|
237
|
+
}
|
|
238
|
+
if (Node.isJsxFragment(bodyOrExpr)) {
|
|
239
|
+
return unwrapSingleJsxChildOfFragment(bodyOrExpr);
|
|
240
|
+
}
|
|
241
|
+
if (Node.isParenthesizedExpression(bodyOrExpr)) {
|
|
242
|
+
return unwrapReturnedJsx(bodyOrExpr.getExpression());
|
|
243
|
+
}
|
|
244
|
+
// Block body: look for a single `return <Foo/>;` at the top level.
|
|
245
|
+
if (Node.isBlock(bodyOrExpr)) {
|
|
246
|
+
const returns = bodyOrExpr.getStatements().filter(Node.isReturnStatement);
|
|
247
|
+
if (returns.length !== 1)
|
|
248
|
+
return undefined;
|
|
249
|
+
const expr = returns[0].getExpression();
|
|
250
|
+
if (!expr)
|
|
251
|
+
return undefined;
|
|
252
|
+
return unwrapReturnedJsx(expr);
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
function unwrapSingleJsxChildOfFragment(fragment) {
|
|
257
|
+
if (!Node.isJsxFragment(fragment))
|
|
258
|
+
return undefined;
|
|
259
|
+
const jsxChildren = fragment
|
|
260
|
+
.getJsxChildren()
|
|
261
|
+
.filter((child) => Node.isJsxElement(child) || Node.isJsxSelfClosingElement(child));
|
|
262
|
+
if (jsxChildren.length !== 1)
|
|
263
|
+
return undefined;
|
|
264
|
+
return jsxChildren[0];
|
|
265
|
+
}
|
|
266
|
+
const JSX_CARRYING_TYPE_TOKENS = ['ReactNode', 'ReactElement', 'JSX.Element'];
|
|
267
|
+
/**
|
|
268
|
+
* True if the type text refers to a React-JSX-carrying type. Used to reject
|
|
269
|
+
* `items: ReactNode[]`-style props from the array-map signal so we don't
|
|
270
|
+
* overlap with the typed-slot pass, which already handles those.
|
|
271
|
+
*/
|
|
272
|
+
function isJsxCarryingTypeText(typeText) {
|
|
273
|
+
for (const token of JSX_CARRYING_TYPE_TOKENS) {
|
|
274
|
+
if (typeText.includes(token))
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import { basename, dirname, resolve, join } from 'node:path';
|
|
2
3
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
4
|
import { createRequire } from 'node:module';
|
|
4
|
-
import os from 'node:os';
|
|
5
5
|
import { parse as parseSvelte } from 'svelte/compiler';
|
|
6
6
|
import { Project, Node, ScriptTarget, ModuleKind, ts } from 'ts-morph';
|
|
7
7
|
import { computeExtractionScore, deriveNeedsReview } from './scoring.js';
|
|
8
8
|
import { extractAllowedComponentsFromTypeText } from './slot-allowed-components.js';
|
|
9
9
|
import { runFileExtractionWorkers } from './file-extraction-workers.js';
|
|
10
10
|
import { resolveLocalModule } from './resolve-local-module.js';
|
|
11
|
-
const SVELTE_EXTRACT_CONCURRENCY = Number(process.env['EDS_EXTRACT_CONCURRENCY'] ?? 0) || os.cpus().length;
|
|
12
11
|
export async function extractSvelteComponents(filePaths, onProgress, opts) {
|
|
13
12
|
const svelteFiles = filePaths.filter((f) => f.endsWith('.svelte'));
|
|
14
13
|
const retryContexts = new Map();
|
|
15
|
-
const { items: components, warnings } = await runFileExtractionWorkers(svelteFiles,
|
|
14
|
+
const { items: components, warnings } = await runFileExtractionWorkers(svelteFiles, os.cpus().length, async (filePath, source) => {
|
|
16
15
|
const { component, warnings: fileWarnings, retryContext } = await extractFromSvelteFile(filePath, source);
|
|
17
16
|
return { item: component, warnings: fileWarnings, metadata: retryContext };
|
|
18
17
|
}, (filePath, error) => `${getSvelteComponentName(filePath)}: failed to extract from ${filePath} — ${error instanceof Error ? error.message : String(error)}`, onProgress, (filePath, outcome) => {
|
package/dist/src/extract/vue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import { basename, dirname, resolve, join } from 'node:path';
|
|
2
3
|
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
5
|
import { parse as parseSFC } from '@vue/compiler-sfc';
|
|
6
6
|
import { Project, Node } from 'ts-morph';
|
|
7
7
|
import { createSortedExtractionResult, runFileExtractionWorkers } from './file-extraction-workers.js';
|
|
@@ -20,10 +20,9 @@ const VUE_TYPE_MAP = {
|
|
|
20
20
|
Date: 'Date',
|
|
21
21
|
Symbol: 'symbol',
|
|
22
22
|
};
|
|
23
|
-
const VUE_EXTRACT_CONCURRENCY = Number(process.env['EDS_EXTRACT_CONCURRENCY'] ?? 0) || os.cpus().length;
|
|
24
23
|
export async function extractVueComponents(filePaths, onProgress) {
|
|
25
24
|
const vueFiles = filePaths.filter((f) => f.endsWith('.vue'));
|
|
26
|
-
const { items: components, warnings } = await runFileExtractionWorkers(vueFiles,
|
|
25
|
+
const { items: components, warnings } = await runFileExtractionWorkers(vueFiles, os.cpus().length, async (filePath, source) => {
|
|
27
26
|
const { component, warnings: fileWarnings } = await extractFromVueSFC(filePath, source);
|
|
28
27
|
return { item: component, warnings: fileWarnings };
|
|
29
28
|
}, (filePath, error) => `Failed to extract from ${filePath}: ${error instanceof Error ? error.message : String(error)}`, onProgress);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experience-design-system-extraction",
|
|
3
|
-
"version": "2.34.5-dev-build-
|
|
3
|
+
"version": "2.34.5-dev-build-5e798cb1.0",
|
|
4
4
|
"description": "Component extraction engine for the Contentful Experience Design System SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|