@contentful/experience-design-system-extraction 2.26.1
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/LICENSE +21 -0
- package/dist/package.json +59 -0
- package/dist/src/extract/astro.d.ts +5 -0
- package/dist/src/extract/astro.js +289 -0
- package/dist/src/extract/non-authorable-filter.d.ts +16 -0
- package/dist/src/extract/non-authorable-filter.js +60 -0
- package/dist/src/extract/pipeline.d.ts +6 -0
- package/dist/src/extract/pipeline.js +314 -0
- package/dist/src/extract/react.d.ts +2 -0
- package/dist/src/extract/react.js +2310 -0
- package/dist/src/extract/scoring.d.ts +12 -0
- package/dist/src/extract/scoring.js +108 -0
- package/dist/src/extract/slot-allowed-components.d.ts +6 -0
- package/dist/src/extract/slot-allowed-components.js +40 -0
- package/dist/src/extract/slot-detection.d.ts +35 -0
- package/dist/src/extract/slot-detection.js +101 -0
- package/dist/src/extract/source-inspection.d.ts +13 -0
- package/dist/src/extract/source-inspection.js +189 -0
- package/dist/src/extract/stencil.d.ts +2 -0
- package/dist/src/extract/stencil.js +328 -0
- package/dist/src/extract/structural-slot-evidence.d.ts +36 -0
- package/dist/src/extract/structural-slot-evidence.js +121 -0
- package/dist/src/extract/svelte.d.ts +5 -0
- package/dist/src/extract/svelte.js +1357 -0
- package/dist/src/extract/tsx-shared.d.ts +15 -0
- package/dist/src/extract/tsx-shared.js +276 -0
- package/dist/src/extract/validate.d.ts +16 -0
- package/dist/src/extract/validate.js +94 -0
- package/dist/src/extract/vue-tsx.d.ts +2 -0
- package/dist/src/extract/vue-tsx.js +498 -0
- package/dist/src/extract/vue.d.ts +5 -0
- package/dist/src/extract/vue.js +653 -0
- package/dist/src/extract/web-components.d.ts +2 -0
- package/dist/src/extract/web-components.js +876 -0
- package/dist/src/index.d.ts +20 -0
- package/dist/src/index.js +22 -0
- package/dist/src/pre-classify.d.ts +17 -0
- package/dist/src/pre-classify.js +225 -0
- package/dist/src/types.d.ts +91 -0
- package/dist/src/types.js +4 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Contentful GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentful/experience-design-system-extraction",
|
|
3
|
+
"version": "2.26.1",
|
|
4
|
+
"description": "Component extraction engine for the Contentful Experience Design System SDK",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/src/index.js",
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/src/index.d.ts",
|
|
12
|
+
"import": "./dist/src/index.js",
|
|
13
|
+
"node": "./dist/src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://npm.pkg.github.com/"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "nx build experience-design-system-extraction",
|
|
25
|
+
"typecheck": "nx typecheck experience-design-system-extraction",
|
|
26
|
+
"clean": "nx clean experience-design-system-extraction",
|
|
27
|
+
"test": "nx test experience-design-system-extraction",
|
|
28
|
+
"lint": "nx lint experience-design-system-extraction",
|
|
29
|
+
"lint:fix": "nx lint:fix experience-design-system-extraction"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@vue/compiler-sfc": "^3.5.31",
|
|
33
|
+
"svelte": "^5.56.4",
|
|
34
|
+
"ts-morph": "^27.0.2",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@tsconfig/node24": "^24.0.4",
|
|
39
|
+
"@types/node": "^24.0.3",
|
|
40
|
+
"eslint": "^9.39.5",
|
|
41
|
+
"eslint-config-prettier": "^10.1.8",
|
|
42
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
43
|
+
"typescript-eslint": "^8.67.0",
|
|
44
|
+
"vitest": "^4.0.16"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/contentful/experience-design-system-sdk-public.git",
|
|
49
|
+
"directory": "packages/experience-design-system-extraction"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/contentful/experience-design-system-sdk-public#readme",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/contentful/experience-design-system-sdk-public/issues"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=24"
|
|
57
|
+
},
|
|
58
|
+
"module": "./src/index.js"
|
|
59
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { Project, Node } from 'ts-morph';
|
|
5
|
+
function extractAllowedValues(typeText) {
|
|
6
|
+
// Check if the type is a union of string literals like 'a' | 'b' | 'c'
|
|
7
|
+
const parts = typeText.split('|').map((p) => p.trim());
|
|
8
|
+
const literals = parts.filter((p) => /^['"]/.test(p)).map((p) => p.replace(/^['"]|['"]$/g, ''));
|
|
9
|
+
return literals.length >= 2 ? literals.sort() : undefined;
|
|
10
|
+
}
|
|
11
|
+
function usesAstroProps(initializer) {
|
|
12
|
+
if (!initializer)
|
|
13
|
+
return false;
|
|
14
|
+
if (initializer.getText() === 'Astro.props')
|
|
15
|
+
return true;
|
|
16
|
+
let found = false;
|
|
17
|
+
initializer.forEachDescendant((node) => {
|
|
18
|
+
if (found)
|
|
19
|
+
return false;
|
|
20
|
+
if (Node.isPropertyAccessExpression(node) && node.getText() === 'Astro.props') {
|
|
21
|
+
found = true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
});
|
|
26
|
+
return found;
|
|
27
|
+
}
|
|
28
|
+
function extractBindingPropName(element) {
|
|
29
|
+
if (element.getText().startsWith('...'))
|
|
30
|
+
return null;
|
|
31
|
+
return element.getPropertyNameNode()?.getText() ?? element.getNameNode().getText();
|
|
32
|
+
}
|
|
33
|
+
function extractFallbackPropsFromFrontmatter(frontmatter) {
|
|
34
|
+
const project = new Project({
|
|
35
|
+
compilerOptions: {
|
|
36
|
+
strict: false,
|
|
37
|
+
target: 99,
|
|
38
|
+
module: 99,
|
|
39
|
+
allowJs: true,
|
|
40
|
+
},
|
|
41
|
+
useInMemoryFileSystem: true,
|
|
42
|
+
skipAddingFilesFromTsConfig: true,
|
|
43
|
+
});
|
|
44
|
+
const sf = project.createSourceFile('__frontmatter__.ts', frontmatter);
|
|
45
|
+
const props = new Map();
|
|
46
|
+
sf.forEachDescendant((node) => {
|
|
47
|
+
if (!Node.isVariableDeclaration(node))
|
|
48
|
+
return;
|
|
49
|
+
const initializer = node.getInitializer();
|
|
50
|
+
if (!usesAstroProps(initializer))
|
|
51
|
+
return;
|
|
52
|
+
const nameNode = node.getNameNode();
|
|
53
|
+
if (!Node.isObjectBindingPattern(nameNode))
|
|
54
|
+
return;
|
|
55
|
+
for (const element of nameNode.getElements()) {
|
|
56
|
+
const propName = extractBindingPropName(element);
|
|
57
|
+
if (!propName)
|
|
58
|
+
continue;
|
|
59
|
+
props.set(propName, {
|
|
60
|
+
name: propName,
|
|
61
|
+
type: 'any',
|
|
62
|
+
required: !element.getInitializer(),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return [...props.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
67
|
+
}
|
|
68
|
+
function mergeProps(...propGroups) {
|
|
69
|
+
const merged = new Map();
|
|
70
|
+
for (const props of propGroups) {
|
|
71
|
+
for (const prop of props) {
|
|
72
|
+
const existing = merged.get(prop.name);
|
|
73
|
+
merged.set(prop.name, existing
|
|
74
|
+
? {
|
|
75
|
+
...existing,
|
|
76
|
+
...prop,
|
|
77
|
+
required: existing.required && prop.required,
|
|
78
|
+
}
|
|
79
|
+
: prop);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [...merged.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
83
|
+
}
|
|
84
|
+
function extractPropsFromFrontmatter(frontmatter) {
|
|
85
|
+
const project = new Project({
|
|
86
|
+
compilerOptions: {
|
|
87
|
+
strict: false,
|
|
88
|
+
target: 99, // ESNext
|
|
89
|
+
module: 99, // ESNext
|
|
90
|
+
allowJs: true,
|
|
91
|
+
},
|
|
92
|
+
useInMemoryFileSystem: true,
|
|
93
|
+
skipAddingFilesFromTsConfig: true,
|
|
94
|
+
});
|
|
95
|
+
const sf = project.createSourceFile('__frontmatter__.ts', frontmatter);
|
|
96
|
+
const props = [];
|
|
97
|
+
// Find `interface Props` or `type Props = ...`
|
|
98
|
+
const propsInterface = sf.getInterface('Props');
|
|
99
|
+
const propsTypeAlias = sf.getTypeAlias('Props');
|
|
100
|
+
if (propsInterface) {
|
|
101
|
+
for (const member of propsInterface.getProperties()) {
|
|
102
|
+
const name = member.getName();
|
|
103
|
+
const typeText = member.getTypeNode()?.getText() ?? 'any';
|
|
104
|
+
const required = !member.hasQuestionToken();
|
|
105
|
+
const allowedValues = extractAllowedValues(typeText);
|
|
106
|
+
props.push({
|
|
107
|
+
name,
|
|
108
|
+
type: typeText,
|
|
109
|
+
required,
|
|
110
|
+
...(allowedValues && { allowedValues }),
|
|
111
|
+
sourceStartLine: member.getStartLineNumber(),
|
|
112
|
+
sourceEndLine: member.getEndLineNumber(),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (propsTypeAlias) {
|
|
117
|
+
const type = propsTypeAlias.getType();
|
|
118
|
+
for (const property of type.getProperties()) {
|
|
119
|
+
const name = property.getName();
|
|
120
|
+
const decl = property.getValueDeclaration() ?? property.getDeclarations()[0];
|
|
121
|
+
if (!decl)
|
|
122
|
+
continue;
|
|
123
|
+
const propType = property.getTypeAtLocation(decl);
|
|
124
|
+
const typeText = propType.getText(decl);
|
|
125
|
+
const required = !property.isOptional();
|
|
126
|
+
const allowedValues = extractAllowedValues(typeText);
|
|
127
|
+
props.push({
|
|
128
|
+
name,
|
|
129
|
+
type: typeText,
|
|
130
|
+
required,
|
|
131
|
+
...(allowedValues && { allowedValues }),
|
|
132
|
+
...(typeof decl.getStartLineNumber === 'function'
|
|
133
|
+
? {
|
|
134
|
+
sourceStartLine: decl.getStartLineNumber(),
|
|
135
|
+
sourceEndLine: decl.getEndLineNumber(),
|
|
136
|
+
}
|
|
137
|
+
: {}),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return props.sort((a, b) => a.name.localeCompare(b.name));
|
|
142
|
+
}
|
|
143
|
+
function extractDefaultsFromFrontmatter(frontmatter) {
|
|
144
|
+
const defaults = new Map();
|
|
145
|
+
const project = new Project({
|
|
146
|
+
compilerOptions: {
|
|
147
|
+
strict: false,
|
|
148
|
+
target: 99,
|
|
149
|
+
module: 99,
|
|
150
|
+
allowJs: true,
|
|
151
|
+
},
|
|
152
|
+
useInMemoryFileSystem: true,
|
|
153
|
+
skipAddingFilesFromTsConfig: true,
|
|
154
|
+
});
|
|
155
|
+
const sf = project.createSourceFile('__frontmatter__.ts', frontmatter);
|
|
156
|
+
sf.forEachDescendant((node) => {
|
|
157
|
+
if (!Node.isVariableDeclaration(node))
|
|
158
|
+
return;
|
|
159
|
+
const initializer = node.getInitializer();
|
|
160
|
+
if (!initializer)
|
|
161
|
+
return;
|
|
162
|
+
if (!usesAstroProps(initializer))
|
|
163
|
+
return;
|
|
164
|
+
const nameNode = node.getNameNode();
|
|
165
|
+
if (!Node.isObjectBindingPattern(nameNode))
|
|
166
|
+
return;
|
|
167
|
+
for (const element of nameNode.getElements()) {
|
|
168
|
+
const propName = extractBindingPropName(element);
|
|
169
|
+
if (!propName)
|
|
170
|
+
continue;
|
|
171
|
+
const elementInitializer = element.getInitializer();
|
|
172
|
+
if (!elementInitializer)
|
|
173
|
+
continue;
|
|
174
|
+
const value = elementInitializer.getText().replace(/^['"]|['"]$/g, '');
|
|
175
|
+
defaults.set(propName, value);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return defaults;
|
|
179
|
+
}
|
|
180
|
+
function extractSlotsFromTemplate(template) {
|
|
181
|
+
const slots = [];
|
|
182
|
+
const seen = new Set();
|
|
183
|
+
const slotRegex = /<slot(?:\s+name=["']([^"']+)["'])?\s*\/?>/g;
|
|
184
|
+
let match;
|
|
185
|
+
while ((match = slotRegex.exec(template)) !== null) {
|
|
186
|
+
const slotName = match[1] ?? 'default';
|
|
187
|
+
if (!seen.has(slotName)) {
|
|
188
|
+
seen.add(slotName);
|
|
189
|
+
slots.push({ name: slotName, isDefault: slotName === 'default' });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return slots;
|
|
193
|
+
}
|
|
194
|
+
function extractSlotsFromFrontmatter(frontmatter) {
|
|
195
|
+
const slots = [];
|
|
196
|
+
const seen = new Set();
|
|
197
|
+
const slotRenderRegex = /Astro\.slots\.render\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
198
|
+
let match;
|
|
199
|
+
while ((match = slotRenderRegex.exec(frontmatter)) !== null) {
|
|
200
|
+
const slotName = match[1];
|
|
201
|
+
if (!seen.has(slotName)) {
|
|
202
|
+
seen.add(slotName);
|
|
203
|
+
slots.push({ name: slotName, isDefault: slotName === 'default' });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return slots;
|
|
207
|
+
}
|
|
208
|
+
function mergeSlots(...slotGroups) {
|
|
209
|
+
const merged = [];
|
|
210
|
+
const seen = new Set();
|
|
211
|
+
for (const slots of slotGroups) {
|
|
212
|
+
for (const slot of slots) {
|
|
213
|
+
if (seen.has(slot.name))
|
|
214
|
+
continue;
|
|
215
|
+
seen.add(slot.name);
|
|
216
|
+
merged.push(slot);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return merged;
|
|
220
|
+
}
|
|
221
|
+
function extractFromAstroFile(filePath, source) {
|
|
222
|
+
const name = basename(filePath, '.astro');
|
|
223
|
+
// Split on `---` fences: frontmatter is between first and second `---`
|
|
224
|
+
// If there is no `---`, the entire file is a template-only component
|
|
225
|
+
const fenceIndex = source.startsWith('---') ? 0 : -1;
|
|
226
|
+
let frontmatter = '';
|
|
227
|
+
let template = source;
|
|
228
|
+
if (fenceIndex !== -1) {
|
|
229
|
+
const endFenceIndex = source.indexOf('---', fenceIndex + 3);
|
|
230
|
+
if (endFenceIndex !== -1) {
|
|
231
|
+
frontmatter = source.slice(fenceIndex + 3, endFenceIndex);
|
|
232
|
+
template = source.slice(endFenceIndex + 3);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const props = frontmatter
|
|
236
|
+
? mergeProps(extractFallbackPropsFromFrontmatter(frontmatter), extractPropsFromFrontmatter(frontmatter))
|
|
237
|
+
: [];
|
|
238
|
+
const defaults = frontmatter ? extractDefaultsFromFrontmatter(frontmatter) : new Map();
|
|
239
|
+
const propsWithDefaults = props.map((p) => {
|
|
240
|
+
const defaultValue = defaults.get(p.name);
|
|
241
|
+
return defaultValue ? { ...p, defaultValue } : p;
|
|
242
|
+
});
|
|
243
|
+
const slots = mergeSlots(extractSlotsFromTemplate(template), extractSlotsFromFrontmatter(frontmatter));
|
|
244
|
+
return {
|
|
245
|
+
name,
|
|
246
|
+
source: filePath,
|
|
247
|
+
sourcePath: filePath,
|
|
248
|
+
framework: 'astro',
|
|
249
|
+
props: propsWithDefaults,
|
|
250
|
+
slots,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const ASTRO_EXTRACT_CONCURRENCY = Number(process.env['EDS_EXTRACT_CONCURRENCY'] ?? 0) || os.cpus().length;
|
|
254
|
+
export async function extractAstroComponents(filePaths, onProgress) {
|
|
255
|
+
const astroFiles = filePaths.filter((f) => f.endsWith('.astro'));
|
|
256
|
+
if (astroFiles.length === 0) {
|
|
257
|
+
return { components: [], warnings: [] };
|
|
258
|
+
}
|
|
259
|
+
const warnings = [];
|
|
260
|
+
const components = [];
|
|
261
|
+
let filesProcessed = 0;
|
|
262
|
+
let componentsFound = 0;
|
|
263
|
+
const queue = [...astroFiles];
|
|
264
|
+
async function worker() {
|
|
265
|
+
while (queue.length > 0) {
|
|
266
|
+
const filePath = queue.shift();
|
|
267
|
+
if (!filePath)
|
|
268
|
+
break;
|
|
269
|
+
try {
|
|
270
|
+
const source = await readFile(filePath, 'utf-8');
|
|
271
|
+
const component = extractFromAstroFile(filePath, source);
|
|
272
|
+
if (component) {
|
|
273
|
+
components.push(component);
|
|
274
|
+
componentsFound++;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
warnings.push(`Failed to extract from ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
279
|
+
}
|
|
280
|
+
filesProcessed++;
|
|
281
|
+
onProgress?.({ filesProcessed, componentsFound });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
await Promise.all(Array.from({ length: Math.min(ASTRO_EXTRACT_CONCURRENCY, astroFiles.length) }, worker));
|
|
285
|
+
return {
|
|
286
|
+
components: components.sort((a, b) => a.name.localeCompare(b.name)),
|
|
287
|
+
warnings,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RawComponentDefinition } from '../types.js';
|
|
2
|
+
export interface NonAuthorableResult {
|
|
3
|
+
skip: boolean;
|
|
4
|
+
reason?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Decides whether a component is non-authorable infrastructure (Context.Provider,
|
|
8
|
+
* analytics shim, layout-only utility, etc.) and should be filtered out of the
|
|
9
|
+
* analyze TUI before authoring-token generation.
|
|
10
|
+
*
|
|
11
|
+
* Uses prop-shape signals only — no component-name or source-path patterns.
|
|
12
|
+
* A design system can live anywhere under any naming convention; relying on
|
|
13
|
+
* suffixes like `*Provider` or paths like `src/lib/` would silently fail in
|
|
14
|
+
* other repos.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNonAuthorableComponent(component: RawComponentDefinition): NonAuthorableResult;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const HANDLER_TYPE_PATTERN = /=>|EventHandler|Dispatch<|SetStateAction/;
|
|
2
|
+
const REF_TYPE_PATTERN = /Ref<|RefObject<|MutableRefObject/;
|
|
3
|
+
function isHandlerOrRefProp(prop) {
|
|
4
|
+
if (HANDLER_TYPE_PATTERN.test(prop.type))
|
|
5
|
+
return true;
|
|
6
|
+
if (REF_TYPE_PATTERN.test(prop.type))
|
|
7
|
+
return true;
|
|
8
|
+
if (/^on[A-Z]/.test(prop.name) || /^set[A-Z]/.test(prop.name))
|
|
9
|
+
return true;
|
|
10
|
+
if (prop.name === 'ref' || prop.name === 'innerRef')
|
|
11
|
+
return true;
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Decides whether a component is non-authorable infrastructure (Context.Provider,
|
|
16
|
+
* analytics shim, layout-only utility, etc.) and should be filtered out of the
|
|
17
|
+
* analyze TUI before authoring-token generation.
|
|
18
|
+
*
|
|
19
|
+
* Uses prop-shape signals only — no component-name or source-path patterns.
|
|
20
|
+
* A design system can live anywhere under any naming convention; relying on
|
|
21
|
+
* suffixes like `*Provider` or paths like `src/lib/` would silently fail in
|
|
22
|
+
* other repos.
|
|
23
|
+
*/
|
|
24
|
+
export function isNonAuthorableComponent(component) {
|
|
25
|
+
const { props, slots, usesCreateContext } = component;
|
|
26
|
+
// R1: zero props AND zero slots — nothing for an editor to author.
|
|
27
|
+
// Catches analytics scripts, GTM tags, layout fixers, security tokens, etc.
|
|
28
|
+
if (props.length === 0 && slots.length === 0) {
|
|
29
|
+
return { skip: true, reason: 'component has no props and no slots' };
|
|
30
|
+
}
|
|
31
|
+
// R2: createContext source + prop literally named `value` — canonical
|
|
32
|
+
// `<Context.Provider value={...}>` call site.
|
|
33
|
+
if (usesCreateContext && props.some((p) => p.name === 'value')) {
|
|
34
|
+
return {
|
|
35
|
+
skip: true,
|
|
36
|
+
reason: 'source uses createContext and component exposes a Context.Provider value prop',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// R3: createContext source + zero props — Provider wrapper that hard-codes
|
|
40
|
+
// the context value internally (e.g. FontProvider, BottomSheetProvider).
|
|
41
|
+
if (usesCreateContext && props.length === 0) {
|
|
42
|
+
return { skip: true, reason: 'source uses createContext and component has no props' };
|
|
43
|
+
}
|
|
44
|
+
// R4: createContext source + exactly one non-handler prop — Provider that
|
|
45
|
+
// takes the context value as its sole data prop, named after the data
|
|
46
|
+
// (e.g. `LocaleProvider({ locale })`, `NavigationProvider({ navItems })`).
|
|
47
|
+
if (usesCreateContext && props.length === 1 && !isHandlerOrRefProp(props[0])) {
|
|
48
|
+
return {
|
|
49
|
+
skip: true,
|
|
50
|
+
reason: 'source uses createContext and component has a single non-handler prop',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// R5: every prop is a handler/ref — pure data plumbing, no authoring surface.
|
|
54
|
+
// Catches components like `OsanoCookiePlaceholder({ onBannerLoaded })` or
|
|
55
|
+
// `FeedbackCard({ setShowModal })`.
|
|
56
|
+
if (props.length > 0 && props.every(isHandlerOrRefProp)) {
|
|
57
|
+
return { skip: true, reason: 'every prop is a handler or ref' };
|
|
58
|
+
}
|
|
59
|
+
return { skip: false };
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ComponentExtractionResult, ExtractorOptions } from '../types.js';
|
|
2
|
+
export type ExtractProgress = {
|
|
3
|
+
filesProcessed: number;
|
|
4
|
+
componentsFound: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function extractComponents(filePaths: string[], onProgress?: (progress: ExtractProgress) => void, opts?: ExtractorOptions): Promise<ComponentExtractionResult>;
|