@contentful/experience-design-system-extraction 2.34.5-dev-build-a95aeeba.0 → 2.34.5-dev-build-f8f0b1fa.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
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-f8f0b1fa.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
1
|
import { Node, SyntaxKind, } from 'ts-morph';
|
|
2
|
-
import { extractAllowedValues, getNodeDefinitions, getTypeReferenceName, getTypeTargetDeclarations,
|
|
2
|
+
import { extractAllowedValues, getNodeDefinitions, getTypeReferenceName, getTypeTargetDeclarations, getValueTargetDeclarations, getJsxTagNameNode, extractTsxComponents, getRenderableExports, isIntrinsicJsxElement, } from './tsx-shared.js';
|
|
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';
|
|
@@ -1626,18 +1626,13 @@ function hasImplementationChildrenHint(funcNode, param) {
|
|
|
1626
1626
|
.some((attr) => isComponentSpreadAttribute(attr, new Set([paramName])));
|
|
1627
1627
|
}
|
|
1628
1628
|
export async function extractReactComponents(filePaths) {
|
|
1629
|
-
const exclusions = []
|
|
1630
|
-
const extractionContext = extractTsxComponents(filePaths, /\.[jt]sx$/, (sourceFile) => {
|
|
1629
|
+
const { components, warnings, exclusions, project } = extractTsxComponents(filePaths, /\.[jt]sx$/, (sourceFile, exclusions) => {
|
|
1631
1630
|
if (isStencilFile(sourceFile))
|
|
1632
1631
|
return [];
|
|
1633
1632
|
const fileExports = [...sourceFile.getExportedDeclarations().keys()];
|
|
1634
1633
|
const isNext = isNextJsComponent(sourceFile.getFilePath(), fileExports);
|
|
1635
1634
|
return extractFromSourceFile(sourceFile, isNext, exclusions);
|
|
1636
1635
|
});
|
|
1637
|
-
if (!extractionContext) {
|
|
1638
|
-
return { components: [], warnings: [] };
|
|
1639
|
-
}
|
|
1640
|
-
const { project, components, warnings } = extractionContext;
|
|
1641
1636
|
const propsToComponent = new Map();
|
|
1642
1637
|
const componentNames = new Set();
|
|
1643
1638
|
for (const c of components) {
|
|
@@ -1679,7 +1674,7 @@ export async function extractReactComponents(filePaths) {
|
|
|
1679
1674
|
const cached = structuralByFile.get(filePath);
|
|
1680
1675
|
if (cached)
|
|
1681
1676
|
return cached;
|
|
1682
|
-
const sourceFile = project
|
|
1677
|
+
const sourceFile = project?.getSourceFile(filePath);
|
|
1683
1678
|
if (!sourceFile)
|
|
1684
1679
|
return [];
|
|
1685
1680
|
const ctx = { propsToComponent, componentNames };
|
|
@@ -1758,22 +1753,11 @@ export async function extractReactComponents(filePaths) {
|
|
|
1758
1753
|
}
|
|
1759
1754
|
function extractFromSourceFile(sourceFile, isNext, exclusions) {
|
|
1760
1755
|
const components = [];
|
|
1761
|
-
const exported = sourceFile.getExportedDeclarations();
|
|
1762
1756
|
const usesCreateContext = sourceFileUsesCreateContext(sourceFile);
|
|
1763
|
-
for (const
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
if (isCompositionHookName(name)) {
|
|
1768
|
-
exclusions.push({
|
|
1769
|
-
itemType: 'component',
|
|
1770
|
-
name,
|
|
1771
|
-
source: sourceFile.getFilePath(),
|
|
1772
|
-
reason: 'React hook names are not renderable components',
|
|
1773
|
-
stage: 'component-filter',
|
|
1774
|
-
});
|
|
1775
|
-
continue;
|
|
1776
|
-
}
|
|
1757
|
+
for (const { name, declarations } of getRenderableExports(sourceFile, exclusions, {
|
|
1758
|
+
allowVariableDeclaration: true,
|
|
1759
|
+
hookReason: 'React hook names are not renderable components',
|
|
1760
|
+
})) {
|
|
1777
1761
|
const funcNode = resolveBestFunctionNode(declarations);
|
|
1778
1762
|
if (!funcNode)
|
|
1779
1763
|
continue;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { Node, Project, type SourceFile, type Type } from 'ts-morph';
|
|
2
|
+
import type { ExtractionExclusion } from '../types.js';
|
|
2
3
|
export declare function getTsxExtractionContext(filePaths: string[], componentFilePattern: RegExp): {
|
|
3
4
|
componentFiles: string[];
|
|
4
5
|
project: Project;
|
|
5
6
|
} | undefined;
|
|
6
|
-
export declare function extractTsxComponents<T>(filePaths: string[], componentFilePattern: RegExp,
|
|
7
|
-
componentFiles: string[];
|
|
8
|
-
project: Project;
|
|
7
|
+
export declare function extractTsxComponents<T>(filePaths: string[], componentFilePattern: RegExp, extract: (sourceFile: SourceFile, exclusions: ExtractionExclusion[]) => T[]): {
|
|
9
8
|
components: T[];
|
|
10
9
|
warnings: string[];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, allowVariableDeclaration?: boolean): string | undefined;
|
|
15
|
-
export declare function isCompositionHookName(name: string): boolean;
|
|
10
|
+
exclusions: ExtractionExclusion[];
|
|
11
|
+
project?: Project;
|
|
12
|
+
};
|
|
16
13
|
export declare function resolveDefaultExportName(declarations: Node[], exported: {
|
|
17
14
|
has(name: string): boolean;
|
|
18
15
|
}, allowVariableDeclaration?: boolean): string | undefined;
|
|
16
|
+
export declare function getRenderableExports(sourceFile: SourceFile, exclusions: ExtractionExclusion[], options: {
|
|
17
|
+
allowVariableDeclaration?: boolean;
|
|
18
|
+
hookReason: string;
|
|
19
|
+
}): Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
declarations: Node[];
|
|
22
|
+
}>;
|
|
19
23
|
export declare function kebabToPascal(input: string): string;
|
|
20
24
|
export declare function extractAllowedValues(type: Type): string[] | undefined;
|
|
21
25
|
/**
|
|
@@ -35,31 +35,27 @@ export function getTsxExtractionContext(filePaths, componentFilePattern) {
|
|
|
35
35
|
project: createTsxProject(getTsxProjectFiles(filePaths)),
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
export function extractTsxComponents(filePaths, componentFilePattern,
|
|
38
|
+
export function extractTsxComponents(filePaths, componentFilePattern, extract) {
|
|
39
39
|
const extractionContext = getTsxExtractionContext(filePaths, componentFilePattern);
|
|
40
|
-
if (!extractionContext)
|
|
41
|
-
return
|
|
42
|
-
|
|
40
|
+
if (!extractionContext) {
|
|
41
|
+
return { components: [], warnings: [], exclusions: [] };
|
|
42
|
+
}
|
|
43
|
+
const { componentFiles, project } = extractionContext;
|
|
43
44
|
const components = [];
|
|
44
|
-
|
|
45
|
+
const warnings = [];
|
|
46
|
+
const exclusions = [];
|
|
47
|
+
for (const filePath of componentFiles) {
|
|
45
48
|
try {
|
|
46
|
-
const sourceFile =
|
|
49
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
47
50
|
if (!sourceFile)
|
|
48
51
|
continue;
|
|
49
|
-
components.push(...
|
|
52
|
+
components.push(...extract(sourceFile, exclusions));
|
|
50
53
|
}
|
|
51
54
|
catch (e) {
|
|
52
55
|
warnings.push(`Failed to extract from ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
return {
|
|
56
|
-
}
|
|
57
|
-
export function resolveComponentExportName(exportKey, declarations, exported, allowVariableDeclaration = false) {
|
|
58
|
-
const name = exportKey === 'default' ? resolveDefaultExportName(declarations, exported, allowVariableDeclaration) : exportKey;
|
|
59
|
-
return name && /^[A-Z]/.test(name) ? name : undefined;
|
|
60
|
-
}
|
|
61
|
-
export function isCompositionHookName(name) {
|
|
62
|
-
return name.startsWith('use');
|
|
58
|
+
return { components, warnings, exclusions, project };
|
|
63
59
|
}
|
|
64
60
|
export function resolveDefaultExportName(declarations, exported, allowVariableDeclaration = false) {
|
|
65
61
|
const declaration = declarations[0];
|
|
@@ -72,6 +68,29 @@ export function resolveDefaultExportName(declarations, exported, allowVariableDe
|
|
|
72
68
|
return undefined;
|
|
73
69
|
return name;
|
|
74
70
|
}
|
|
71
|
+
export function getRenderableExports(sourceFile, exclusions, options) {
|
|
72
|
+
const renderable = [];
|
|
73
|
+
const exported = sourceFile.getExportedDeclarations();
|
|
74
|
+
for (const [exportKey, declarations] of exported) {
|
|
75
|
+
const name = exportKey === 'default'
|
|
76
|
+
? resolveDefaultExportName(declarations, exported, options.allowVariableDeclaration)
|
|
77
|
+
: exportKey;
|
|
78
|
+
if (!name || !/^[A-Z]/.test(name))
|
|
79
|
+
continue;
|
|
80
|
+
if (name.startsWith('use')) {
|
|
81
|
+
exclusions.push({
|
|
82
|
+
itemType: 'component',
|
|
83
|
+
name,
|
|
84
|
+
source: sourceFile.getFilePath(),
|
|
85
|
+
reason: options.hookReason,
|
|
86
|
+
stage: 'component-filter',
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
renderable.push({ name, declarations });
|
|
91
|
+
}
|
|
92
|
+
return renderable;
|
|
93
|
+
}
|
|
75
94
|
export function kebabToPascal(input) {
|
|
76
95
|
return input
|
|
77
96
|
.split('-')
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
|
-
import { extractAllowedValues, extractTsxComponents, getTypeReferenceName, getTypeTargetDeclarations, getValueTargetDeclarations,
|
|
2
|
+
import { extractAllowedValues, extractTsxComponents, getTypeReferenceName, getTypeTargetDeclarations, getValueTargetDeclarations, getRenderableExports, } from './tsx-shared.js';
|
|
3
3
|
export async function extractVueTsxComponents(filePaths) {
|
|
4
|
-
const exclusions =
|
|
5
|
-
const extractionContext = extractTsxComponents(filePaths, /\.tsx$/, (sourceFile) => extractFromSourceFile(sourceFile, exclusions));
|
|
6
|
-
if (!extractionContext) {
|
|
7
|
-
return { components: [], warnings: [] };
|
|
8
|
-
}
|
|
9
|
-
const { components, warnings } = extractionContext;
|
|
4
|
+
const { components, warnings, exclusions } = extractTsxComponents(filePaths, /\.tsx$/, extractFromSourceFile);
|
|
10
5
|
return {
|
|
11
6
|
components: components.sort((a, b) => a.name.localeCompare(b.name)),
|
|
12
7
|
warnings,
|
|
@@ -15,21 +10,9 @@ export async function extractVueTsxComponents(filePaths) {
|
|
|
15
10
|
}
|
|
16
11
|
function extractFromSourceFile(sourceFile, exclusions) {
|
|
17
12
|
const components = [];
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!name)
|
|
22
|
-
continue;
|
|
23
|
-
if (isCompositionHookName(name)) {
|
|
24
|
-
exclusions.push({
|
|
25
|
-
itemType: 'component',
|
|
26
|
-
name,
|
|
27
|
-
source: sourceFile.getFilePath(),
|
|
28
|
-
reason: 'Vue composition hook names are not renderable components',
|
|
29
|
-
stage: 'component-filter',
|
|
30
|
-
});
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
13
|
+
for (const { name, declarations } of getRenderableExports(sourceFile, exclusions, {
|
|
14
|
+
hookReason: 'Vue composition hook names are not renderable components',
|
|
15
|
+
})) {
|
|
33
16
|
const component = extractVueTsxComponent(declarations, name, sourceFile);
|
|
34
17
|
if (component) {
|
|
35
18
|
components.push(component);
|
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-f8f0b1fa.0",
|
|
4
4
|
"description": "Component extraction engine for the Contentful Experience Design System SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|