Skip to content

Commit 196c78d

Browse files
committed
add support for hostDirectives
1 parent 3300aae commit 196c78d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

scripts/template.helper.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const loadDependencies = (c, withNestedDependencies, recursionDepth) => {
3535
const importNodes = parse(fileContent, { range: true }).body
3636
.filter(n => (n.type === 'ExportDefaultDeclaration' || n.type === 'ExportNamedDeclaration') && n.declaration?.decorators)?.flatMap(n => n
3737
.declaration.decorators.filter(d => d.expression.callee?.name === 'Component')?.[0]
38-
?.expression.arguments[0].properties.filter(n => n.key.name === 'imports')?.[0]
38+
?.expression.arguments[0].properties.filter(n => n.key.name === 'imports' || n.key.name === 'hostDirectives')?.[0]
3939
?.value.elements);
4040

4141
// ToDo: add tests for this
@@ -45,16 +45,29 @@ const loadDependencies = (c, withNestedDependencies, recursionDepth) => {
4545
return [c, ...components];
4646
}
4747

48-
const identifierNodes = importNodes.filter(n => n?.type === 'Identifier');
48+
// Extract both direct identifiers and hostDirective property expressions
49+
const identifierNodes = importNodes.filter(n =>
50+
n?.type === 'Identifier' ||
51+
(n?.type === 'ObjectExpression' && n.properties.some(p => p.key.name === 'directive'))
52+
);
4953

5054
if (identifierNodes?.length) {
5155
try {
52-
const importsContent = identifierNodes.map(e => e.name);
56+
// Extract component names from both regular imports and hostDirectives
57+
const importsContent = identifierNodes.map(e => {
58+
if (e.type === 'Identifier') {
59+
return e.name;
60+
} else if (e.type === 'ObjectExpression') {
61+
const directiveProp = e.properties.find(p => p.key.name === 'directive');
62+
return directiveProp?.value?.name;
63+
}
64+
return null;
65+
}).filter(Boolean);
5366

5467
importsContent.forEach(componentName => {
5568
const comp = handleComponent(componentName, fileContent, c.componentName, path.relative(cwd, p));
5669
if (comp) {
57-
components.push(comp)
70+
components.push(comp);
5871
}
5972
});
6073

0 commit comments

Comments
 (0)