Skip to content

Commit 33c6517

Browse files
committed
fix: extract jsdoc information from astro files
1 parent 990c79c commit 33c6517

9 files changed

Lines changed: 186 additions & 43 deletions

File tree

docs/architecture/README.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/architecture/aac-ir.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/architecture/default_container__basic_astro.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/architecture/default_container__generators.md

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extractors/builtin/basic-astro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default async function basicAstroExtractor(
175175
const ir = mapToIR(extractions, packages, systemInfo);
176176

177177
log.info(
178-
`Extracted ${ir.components.length} components, ${ir.code.length} code elements, ${ir.componentRelationships.length} relationships`,
178+
`Extracted ${ir.components.length} components, ${ir.actors.length} actors, ${ir.code.length} code elements, ${ir.componentRelationships.length} relationships`,
179179
);
180180

181181
return ir;

src/extractors/builtin/basic-astro/component-detector.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ function extractJSDocBlocks(source: string): JSDocBlock[] {
4848
*/
4949
function parseJSDocBlock(comment: string): JSDocBlock | null {
5050
// Remove /** and */ and leading * from each line
51+
// Handle both Unix (\n) and Windows (\r\n) line endings
5152
const cleaned = comment
5253
.replace(/^\/\*\*/, '')
5354
.replace(/\*\/$/, '')
55+
.replace(/\r\n/g, '\n') // Normalize Windows line endings to Unix
5456
.split('\n')
5557
.map((line) => line.replace(/^\s*\*\s?/, ''))
5658
.join('\n')
@@ -91,6 +93,7 @@ function parseJSDocBlock(comment: string): JSDocBlock | null {
9193
* If no tags found, infers component from directory structure:
9294
* - Files in subdirectories use the immediate parent folder name
9395
* - Files in root directory use ROOT_COMPONENT_MARKER
96+
* - Uses any JSDoc description found in the frontmatter
9497
*/
9598
export function extractFileComponent(
9699
frontmatter: string,
@@ -121,8 +124,21 @@ export function extractFileComponent(
121124
}
122125
}
123126

124-
// If no JSDoc tags found, infer from file path
125-
return inferComponentFromPath(filePath);
127+
// If no explicit component tag found, infer from file path
128+
// But still use any JSDoc description found in the frontmatter
129+
const inferredComponent = inferComponentFromPath(filePath);
130+
131+
// Look for any JSDoc block with a description (even without @component tag)
132+
for (const block of jsDocBlocks) {
133+
if (block.description && block.description.trim()) {
134+
return {
135+
...inferredComponent,
136+
description: block.description.trim(),
137+
};
138+
}
139+
}
140+
141+
return inferredComponent;
126142
}
127143

128144
/**

src/extractors/builtin/basic-astro/file-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ export async function parseFiles(filePaths: string[]): Promise<FileExtraction[]>
115115
/**
116116
* Extract frontmatter content from Astro file
117117
* Frontmatter is the TypeScript/JavaScript code between --- markers at the top of the file
118+
* Handles both Unix (\n) and Windows (\r\n) line endings
118119
*/
119120
function extractFrontmatter(content: string): string {
120-
const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/);
121+
const frontmatterMatch = content.match(/^---\s*\r?\n([\s\S]*?)\r?\n---/);
121122
return frontmatterMatch ? frontmatterMatch[1] : '';
122123
}
123124

0 commit comments

Comments
 (0)