Skip to content

Commit f3068c0

Browse files
authored
improved stability when parsing barrel files
1 parent 20d5d5a commit f3068c0

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tsharp/ng-component-hierarchy-visualizer",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "generate mermaid representations of your angular component hierarchy",
55
"keywords": [
66
"angular",

scripts/component.helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const handleLoadChildren = (route) => {
9494
} else {
9595
// Check if routes are configured directly (convention: .+\/.+routing.*|.+routes)
9696
const moduleImportMatch = routesFileContent.match(/(import|export)\s+\{?[^}]+\}?\s+from\s+'(.+\/.*routing.*|.+routes)'/);
97-
const originalModulePath = moduleImportMatch[2];
97+
const originalModulePath = moduleImportMatch?.[2] ?? routesFileContent.match(/(import|export)\s+\{?[^}]+\}?\s+from\s+'(.+\/.*)'/)[2];
9898
const resolvedModulePath = replacePath(originalModulePath);
9999

100100
const moduleFilePath = originalModulePath === resolvedModulePath

scripts/route.helper.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ export const extractRoutesFromTS = (routesString, rootName = ROOT_COMPONENT) =>
115115
}
116116

117117
try {
118-
const resolvedRoutes = extractRoutes(routesArrayNodes, rootName)
119-
if (resolvedRoutes.length === 1) {
120-
return resolvedRoutes[0];
121-
}
122-
118+
const resolvedRoutes = extractRoutes(routesArrayNodes, rootName);
123119
return resolvedRoutes;
124120
} catch (error) {
125121
console.error('Error extracting route configuration:', error);

scripts/template.helper.js

Lines changed: 1 addition & 1 deletion
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')?.[0]
3939
?.value.elements);
4040

4141
// ToDo: add tests for this

0 commit comments

Comments
 (0)