diff --git a/src/merger/project_merger.ts b/src/merger/project_merger.ts index 0cbf5cc..aad672e 100644 --- a/src/merger/project_merger.ts +++ b/src/merger/project_merger.ts @@ -3,6 +3,7 @@ import { DeclarationReflection, DocumentReflection, ProjectReflection, Reflectio import { addDeclarationReflectionToTarget, addDocumentReflectionToTarget, + getModules as getModulesFrom, removeDeclarationReflectionFromModule, removeDocumentReflectionFromModule, } from "../utils"; @@ -26,18 +27,22 @@ export class ProjectMerger { * Performs the merging routine. */ public execute(): void { - const modules = (this.project.children ?? []).filter((c) => c.kindOf(ReflectionKind.Module)); + // In monorepo project each project is also a module => Recursively collect all modules + const allModules = getModulesFrom(this.project); - if (modules.length > 0) { + if (allModules.length > 0) { this.clearProject(); - for (const mod of modules) { + for (const module of allModules) { // Here we create a copy because the next loop modifies the collection - const reflections = [...(mod.childrenIncludingDocuments ?? [])]; + const reflections = [...(module.childrenIncludingDocuments ?? [])]; for (const ref of reflections) { - // Drop aliases (= ReflectionKind.Reference) - if (ref instanceof DeclarationReflection && !ref.kindOf(ReflectionKind.Reference)) { + // Drop aliases (= ReflectionKind.Reference) and modules + if ( + ref instanceof DeclarationReflection && + !ref.kindOf([ReflectionKind.Reference, ReflectionKind.Module]) + ) { this.moveDeclarationReflectionToProject(ref); } else if (ref instanceof DocumentReflection) { this.moveDocumentReflectionFromToProject(ref); diff --git a/src/utils.ts b/src/utils.ts index 237446c..8378ba3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { Context, DeclarationReflection, DocumentReflection, ProjectReflection } from "typedoc"; +import { Context, DeclarationReflection, DocumentReflection, ProjectReflection, ReflectionKind } from "typedoc"; import * as ts from "typescript"; /** @@ -124,3 +124,19 @@ export function removeDocumentReflectionFromModule(ref: DocumentReflection): voi module.childrenIncludingDocuments?.splice(indexInChildrenIncludingDocuments, 1); } } + +/** + * Returns the modules within the given module parent. Searches recursively. + * @param moduleParent The element in which to search for modules. + * @returns The modules within the given module parent. + */ +export function getModules(moduleParent: ProjectReflection | DeclarationReflection): DeclarationReflection[] { + const modules = (moduleParent.children ?? []).filter((c) => c.kindOf(ReflectionKind.Module)); + + for (const mod of modules) { + const subModules = getModules(mod); + modules.push(...subModules); + } + + return modules; +}