diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b50a19..156c71b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [4.0.0] - 2022-07-03 +### Breaking Changes +- Support changed to TypeDoc versions 0.23.x due to a breaking change in TypeDoc's API. +### Added +- Option `mergeModulesMergeMode` now has a new value `module-category` to merge modules with the same name but only + if they are within the same category. +### Fixed +- Renaming of default exports now also works for: enums, object literals, type literals and type aliases. + ## [3.1.0] - 2021-12-08 ### Added - When merging modules by name you can use the comment tag `@mergeTarget` to define the module into which the other @@ -42,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 First release -[unreleased]: https://github.com/krisztianb/typedoc-plugin-merge-modules/compare/v3.1.0...HEAD +[unreleased]: https://github.com/krisztianb/typedoc-plugin-merge-modules/compare/v4.0.0...HEAD +[4.0.0]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v4.0.0 [3.1.0]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v3.1.0 [3.0.2]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v3.0.2 [3.0.1]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v3.0.1 diff --git a/README.md b/README.md index ed3838b..48c4f3f 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,9 @@ The following options are added to TypeDoc when the plugin is installed: | Name & Format | Description | Default | | ------------- | ----------- | ------- | | **mergeModulesRenameDefaults** `` | Defines if the plugin should rename default exports to their original name. | `true` | -| **mergeModulesMergeMode** `<"project"\|"module"\|"off">` | Defines if the plugin should merge all modules into the project or if it should merge modules based on their name or module annotation. You can use the value `"off"` to disable the plugin. | `"project"` | +| **mergeModulesMergeMode** `<"project"\|"module"\|"module-category"\|"off">` | Defines how the plugin should merge modules:

| `"project"` | -When using `mergeModulesMergeMode: module` in combination with [module comments](https://typedoc.org/guides/doccomments/#files) you should add the tag `@mergeTarget` to the comment of the module whose comment should be used in the merge result. +When you set `mergeModulesMergeMode` to `"module"` OR `"module-category"` in combination with [module comments](https://typedoc.org/tags/module/) you should add the tag `@mergeTarget` to the comment of the module whose comment should be used in the merge result. ## Bugs diff --git a/package-lock.json b/package-lock.json index 161d315..4c23443 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "typedoc-plugin-merge-modules", - "version": "3.1.0", + "version": "4.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -189,14 +189,14 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.1.tgz", - "integrity": "sha512-Ffa9FZqZUVJKwCL8PMHTJCkO7IKA3/x0mYy5qcqcwcmjPdpJ1FnWdZQAqKGJolZ1ymLxygcdrNR9yzNIh/bZtQ==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.3.tgz", + "integrity": "sha512-QEgE1uahnDbWEkZlidq7uKB630ny1NN8KbLPmznX+8hYsYpoV1/quG1Nzvs141FVuumuS7O0EpqYw3RB4AVzRg==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.30.1", - "@typescript-eslint/type-utils": "5.30.1", - "@typescript-eslint/utils": "5.30.1", + "@typescript-eslint/scope-manager": "5.30.3", + "@typescript-eslint/type-utils": "5.30.3", + "@typescript-eslint/utils": "5.30.3", "debug": "^4.3.4", "functional-red-black-tree": "^1.0.1", "ignore": "^5.2.0", @@ -206,52 +206,52 @@ } }, "@typescript-eslint/parser": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.30.1.tgz", - "integrity": "sha512-mRcFvIWhIx4QpMVu7JLPm3qDwY8qhRVRKzbgaUKToI5qVEWqUWu+6I1ZY//xymDMN3QKBOIWSvxcgng1lyu8jw==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.30.3.tgz", + "integrity": "sha512-ddwGEPC3E49DduAUC8UThQafHRE5uc1NE8jdOgl+w8/NrYF50MJQNeD3u4JZrqAXdY9rJz0CdQ9HpNME20CzkA==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.30.1", - "@typescript-eslint/types": "5.30.1", - "@typescript-eslint/typescript-estree": "5.30.1", + "@typescript-eslint/scope-manager": "5.30.3", + "@typescript-eslint/types": "5.30.3", + "@typescript-eslint/typescript-estree": "5.30.3", "debug": "^4.3.4" } }, "@typescript-eslint/scope-manager": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.30.1.tgz", - "integrity": "sha512-L57F9W0Zr9mF8UyHQweSbfo7Jac7KfkLl+CcYr4VP+d44KBHflTpyvwLwv1A/Ff1hxqKWHYHsc5TcjHB+ZIZtg==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.30.3.tgz", + "integrity": "sha512-yVJIIUXeo/vv6Alj6lKBvsqnRs5hcxUpN3Dg3aD9Zv6r7p6Nn106jJcr5rnpRHAReEb/aMI2RWrt3JmL17eCVA==", "dev": true, "requires": { - "@typescript-eslint/types": "5.30.1", - "@typescript-eslint/visitor-keys": "5.30.1" + "@typescript-eslint/types": "5.30.3", + "@typescript-eslint/visitor-keys": "5.30.3" } }, "@typescript-eslint/type-utils": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.30.1.tgz", - "integrity": "sha512-N8ZYmXzFXvnSbD4v4mwDNxkfjp5qVu3PfP4uW9bAfsJHhL/05YBL8chs0oP7+UGIdcJBPwzB6s1EyUbRfjxZAQ==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.30.3.tgz", + "integrity": "sha512-IIzakE7OXOqdwPaXhRiPnaZ8OuJJYBLufOffd9fqzkI4IMFIYq8KC7bghdnF7QUJTirURRErQFrJ/w5UpwIqaw==", "dev": true, "requires": { - "@typescript-eslint/utils": "5.30.1", + "@typescript-eslint/utils": "5.30.3", "debug": "^4.3.4", "tsutils": "^3.21.0" } }, "@typescript-eslint/types": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.30.1.tgz", - "integrity": "sha512-YL6O8aH4Iw8PPewfX0PGap5exJ96hFi/n+zOIjb08ba9gghXFlpChzCxvZbEXc0V0dQYjuxRThcOxHkGmqiHAw==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.30.3.tgz", + "integrity": "sha512-vshU3pjSTgBPNgfd55JLYngHkXuwQP68fxYFUAg1Uq+JrR3xG/XjvL9Dmv28CpOERtqwkaR4QQ3mD0NLZcE2Xw==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.1.tgz", - "integrity": "sha512-8pxRQco97J+rYsjN6P0+e+rmPOHyRx0xrOZ21Z3zMG+CfX0bo7ieh8Z+bvXn4N3zoNRc37VyD2zvzX3YTebXGw==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.3.tgz", + "integrity": "sha512-jqVh5N9AJx6+7yRgoA+ZelAFrHezgI9pzI9giv7s84DDOmtpFwTgURcpICDHyz9x6vAeOu91iACZ4dBTVfzIyA==", "dev": true, "requires": { - "@typescript-eslint/types": "5.30.1", - "@typescript-eslint/visitor-keys": "5.30.1", + "@typescript-eslint/types": "5.30.3", + "@typescript-eslint/visitor-keys": "5.30.3", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -260,26 +260,26 @@ } }, "@typescript-eslint/utils": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.30.1.tgz", - "integrity": "sha512-0kR4AKO9iT1qKEqxqIfqOubJouRdUkpdLi4iWOu/cG2m0BpcYBpRNXETSpugpycta76CC/7hHrzieyq/qrU+5Q==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.30.3.tgz", + "integrity": "sha512-OEaBXGxxdIy35H+jyXfYAMQ66KMJczK9hEhL3gR6IRbWe5PyK+bPDC9zbQNVII6rNFTfF/Mse0z21NlEU+vOMw==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.30.1", - "@typescript-eslint/types": "5.30.1", - "@typescript-eslint/typescript-estree": "5.30.1", + "@typescript-eslint/scope-manager": "5.30.3", + "@typescript-eslint/types": "5.30.3", + "@typescript-eslint/typescript-estree": "5.30.3", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" } }, "@typescript-eslint/visitor-keys": { - "version": "5.30.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.1.tgz", - "integrity": "sha512-Ag9rdIwoMUqX8euF/BoQzC57eUmcqNfWPVBnGTJKAHu8oMGXGH75q4HyXjHD1JBnyKBqBpS97tqbcjxleqLMLw==", + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.3.tgz", + "integrity": "sha512-ep2xtHOhnSRt6fDP9DSSxrA/FqZhdMF7/Y9fYsxrKss2uWJMbzJyBJ/We1fKc786BJ10pHwrzUlhvpz8i7XzBg==", "dev": true, "requires": { - "@typescript-eslint/types": "5.30.1", + "@typescript-eslint/types": "5.30.3", "eslint-visitor-keys": "^3.3.0" } }, @@ -491,9 +491,9 @@ "dev": true }, "eslint": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.18.0.tgz", - "integrity": "sha512-As1EfFMVk7Xc6/CvhssHUjsAQSkpfXvUGMFC3ce8JDe6WvqCgRrLOBQbVpsBFr1X1V+RACOadnzVvcUS5ni2bA==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.19.0.tgz", + "integrity": "sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw==", "dev": true, "requires": { "@eslint/eslintrc": "^1.3.0", @@ -1064,9 +1064,9 @@ "dev": true }, "marked": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/marked/-/marked-3.0.8.tgz", - "integrity": "sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==", + "version": "4.0.17", + "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.17.tgz", + "integrity": "sha512-Wfk0ATOK5iPxM4ptrORkFemqroz0ZDxp5MWfYA7H/F+wO17NRWV5Ypxi6p3g2Xmw2bKeiYOl6oVnLHKxBA0VhA==", "dev": true }, "merge2": { @@ -1392,9 +1392,9 @@ "dev": true }, "shiki": { - "version": "0.9.14", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.9.14.tgz", - "integrity": "sha512-uLHjjyJdNsMzF9GOF8vlOuZ8BwigiYPraMN5yjC826k8K7Xu90JQcC5GUNrzRibLgT2EOk9597I1IX+jRdA8nw==", + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.10.1.tgz", + "integrity": "sha512-VsY7QJVzU51j5o1+DguUd+6vmCmZ5v/6gYu4vyYAhzjuNQU6P/vmSy4uQaOhvje031qQMiW0d2BwgMH52vqMng==", "dev": true, "requires": { "jsonc-parser": "^3.0.0", @@ -1525,30 +1525,33 @@ "dev": true }, "typedoc": { - "version": "0.22.10", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.22.10.tgz", - "integrity": "sha512-hQYZ4WtoMZ61wDC6w10kxA42+jclWngdmztNZsDvIz7BMJg7F2xnT+uYsUa7OluyKossdFj9E9Ye4QOZKTy8SA==", + "version": "0.23.5", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.23.5.tgz", + "integrity": "sha512-5ydWUOe4E9Z3a/r33cC5X5CJPLnFDKIondHYtdnEnO0sa/s8f+Nrfe+LBGOk/UTkV2IPYyL1Gm1PtUKIihklyw==", "dev": true, "requires": { - "glob": "^7.2.0", "lunr": "^2.3.9", - "marked": "^3.0.8", - "minimatch": "^3.0.4", - "shiki": "^0.9.12" + "marked": "^4.0.16", + "minimatch": "^5.1.0", + "shiki": "^0.10.1" }, "dependencies": { - "glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", + "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", "dev": true, "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "brace-expansion": "^2.0.1" } } } @@ -1585,9 +1588,9 @@ } }, "vscode-oniguruma": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.6.1.tgz", - "integrity": "sha512-vc4WhSIaVpgJ0jJIejjYxPvURJavX6QG41vu0mGhqywMkQqulezEqEQ3cO3gc8GvcOpX6ycmKGqRoROEMBNXTQ==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.6.2.tgz", + "integrity": "sha512-KH8+KKov5eS/9WhofZR8M8dMHWN2gTxjMsG4jd04YhpbPR91fUj7rYQ2/XjeHCJWbg7X++ApRIU9NUwM2vTvLA==", "dev": true }, "vscode-textmate": { diff --git a/package.json b/package.json index 187b784..e2564d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typedoc-plugin-merge-modules", - "version": "3.1.0", + "version": "4.0.0", "description": "Plugin for TypeDoc that merges the content of modules.", "author": { "name": "KrisztiƔn Balla", @@ -12,19 +12,19 @@ ], "devDependencies": { "@types/node": "14.18.0", - "@typescript-eslint/eslint-plugin": "5.30.1", - "@typescript-eslint/parser": "5.30.1", - "eslint": "8.18.0", + "@typescript-eslint/eslint-plugin": "5.30.3", + "@typescript-eslint/parser": "5.30.3", + "eslint": "8.19.0", "eslint-plugin-jsdoc": "39.3.3", "eslint-plugin-ordered-imports": "0.6.0", "eslint-plugin-unicorn": "43.0.0", "prettier": "2.7.1", "rimraf": "3.0.2", - "typedoc": "0.22.10", + "typedoc": "0.23.5", "typescript": "4.7.4" }, "peerDependencies": { - "typedoc": "0.21.x || 0.22.x" + "typedoc": "0.23.x" }, "repository": { "type": "git", diff --git a/src/merger/module_bundle.ts b/src/merger/module_bundle.ts index 005ec1b..485baac 100644 --- a/src/merger/module_bundle.ts +++ b/src/merger/module_bundle.ts @@ -5,15 +5,12 @@ import { removeTagFromCommentsOf } from "./utils"; * Name of the comment tag that can be used to mark a module as the target module within the bundle. * The target module is the one into which all the modules of the bundle are merged. */ -const targetModuleCommentTagName = "mergeTarget"; +const targetModuleCommentTag = "@mergeTarget"; /** * Class representing a group of modules. */ export class ModuleBundle { - /** The name of the module bundle. */ - private readonly name: string; - /** The project in which all modules are in. */ private readonly project: ProjectReflection; @@ -22,11 +19,9 @@ export class ModuleBundle { /** * Creates a new module bundle instance. - * @param name The name of the module bundle. * @param project The project in which all modules are in. */ - public constructor(name: string, project: ProjectReflection) { - this.name = name; + public constructor(project: ProjectReflection) { this.project = project; } @@ -49,7 +44,7 @@ export class ModuleBundle { // get target module const targetModule = this.getTargetModule(); - removeTagFromCommentsOf(targetModule, targetModuleCommentTagName); + removeTagFromCommentsOf(targetModule, targetModuleCommentTag); // set target module for all children childrenOfAllModules.forEach((child) => (child.parent = targetModule)); @@ -72,9 +67,7 @@ export class ModuleBundle { // 1. search for the first module which is marked with a specific tag const firstModuleWithTargetTag = this.modules.find( (module) => - module.comment?.tags.findIndex( - (tag) => tag.tagName.toLowerCase() === targetModuleCommentTagName.toLowerCase(), - ) !== -1, + module.comment && module.comment.blockTags.findIndex((ct) => ct.tag === targetModuleCommentTag) !== -1, ); if (firstModuleWithTargetTag) { @@ -82,7 +75,7 @@ export class ModuleBundle { } // 2. search for the first module with a comment - const firstModuleWithComment = this.modules.find((module) => module.comment?.shortText); + const firstModuleWithComment = this.modules.find((module) => (module.comment?.summary.length ?? 0) > 0); if (firstModuleWithComment) { return firstModuleWithComment; diff --git a/src/merger/module_category_merger.ts b/src/merger/module_category_merger.ts new file mode 100644 index 0000000..3ea3893 --- /dev/null +++ b/src/merger/module_category_merger.ts @@ -0,0 +1,19 @@ +import { DeclarationReflection } from "typedoc"; +import { ModuleMerger } from "./module_merger"; + +/** + * Merger that merges the content of modules based on their JSDoc module annotation and category. + */ +export class ModuleCategoryMerger extends ModuleMerger { + /** + * Creates an identifier for the module's bundle. + * @param module The module for which the identifier is generated. + * @returns The identifier for the module's bundle. + */ + // eslint-disable-next-line class-methods-use-this + protected override createModuleBundleId(module: DeclarationReflection): string { + const categoryTags = module.comment?.blockTags.filter((ct) => ct.tag === "@category") ?? []; + const categoryTagTexts = categoryTags.map((ct) => ct.content.map((c) => c.text).join()).sort(); + return module.name + "_[[[CATEGORIES:]]]_" + categoryTagTexts.join("_[[[|]]]_"); + } +} diff --git a/src/merger/module_merger.ts b/src/merger/module_merger.ts index 32e2b68..b63577f 100644 --- a/src/merger/module_merger.ts +++ b/src/merger/module_merger.ts @@ -1,4 +1,4 @@ -import { ProjectReflection, ReflectionKind } from "typedoc"; +import { DeclarationReflection, ProjectReflection, ReflectionKind } from "typedoc"; import { ModuleBundle } from "./module_bundle"; /** @@ -6,7 +6,7 @@ import { ModuleBundle } from "./module_bundle"; */ export class ModuleMerger { /** The project whose modules are merged. */ - private readonly project: ProjectReflection; + protected readonly project: ProjectReflection; /** * Creates a new merger instance. @@ -24,20 +24,32 @@ export class ModuleMerger { moduleBundles.forEach((bundle) => bundle.merge()); } + /** + * Creates an identifier for the module's bundle. + * @param module The module for which the identifier is generated. + * @returns The identifier for the module's bundle. + */ + // eslint-disable-next-line class-methods-use-this + protected createModuleBundleId(module: DeclarationReflection): string { + return module.name; + } + /** * Creates an object describing which modules of the project should be merged. * @returns The collection of module bundles. */ - private createModuleBundles(): ModuleBundle[] { + protected createModuleBundles(): ModuleBundle[] { const modules = (this.project.children ?? []).filter((c) => c.kindOf(ReflectionKind.Module)); const moduleBundleMap = new Map(); for (const module of modules) { - if (!moduleBundleMap.has(module.name)) { - moduleBundleMap.set(module.name, new ModuleBundle(module.name, this.project)); + const bundleId = this.createModuleBundleId(module); + + if (!moduleBundleMap.has(bundleId)) { + moduleBundleMap.set(bundleId, new ModuleBundle(this.project)); } - moduleBundleMap.get(module.name)?.add(module); + moduleBundleMap.get(bundleId)?.add(module); } return [...moduleBundleMap.values()]; diff --git a/src/merger/utils.ts b/src/merger/utils.ts index c761b8c..13670f7 100644 --- a/src/merger/utils.ts +++ b/src/merger/utils.ts @@ -6,11 +6,9 @@ import { DeclarationReflection } from "typedoc"; * @param tagToRemove Name of the tag to be removed. */ export function removeTagFromCommentsOf(reflection: DeclarationReflection, tagToRemove: string): void { - tagToRemove = tagToRemove.toLowerCase(); - - const tagIndex = reflection.comment?.tags.findIndex((tag) => tag.tagName.toLowerCase() === tagToRemove) ?? -1; + const tagIndex = reflection.comment?.blockTags.findIndex((ct) => ct.tag === tagToRemove) ?? -1; if (tagIndex !== -1) { - reflection.comment?.tags.splice(tagIndex, 1); + reflection.comment?.blockTags.splice(tagIndex, 1); } } diff --git a/src/plugin.ts b/src/plugin.ts index 7984ca4..665f95c 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,5 +1,5 @@ -import { Application, Context, Converter, ProjectReflection, Reflection } from "typedoc"; -import * as ts from "typescript"; +import { Application, Context, Converter, DeclarationReflection, ProjectReflection, ReflectionKind } from "typedoc"; +import { ModuleCategoryMerger } from "./merger/module_category_merger"; import { ModuleMerger } from "./merger/module_merger"; import { ProjectMerger } from "./merger/project_merger"; import { PluginOptions } from "./plugin_options"; @@ -39,9 +39,8 @@ export class Plugin { */ private subscribeToApplicationEvents(typedoc: Readonly): void { typedoc.converter.on(Converter.EVENT_BEGIN, (c: Readonly) => this.onConverterBegin(c)); - typedoc.converter.on( - Converter.EVENT_CREATE_DECLARATION, - (c: Readonly, r: Reflection, n?: Readonly) => this.onConverterCreateDeclaration(c, r, n), + typedoc.converter.on(Converter.EVENT_CREATE_DECLARATION, (c: Readonly, r: DeclarationReflection) => + this.onConverterCreateDeclaration(c, r), ); typedoc.converter.on(Converter.EVENT_RESOLVE_BEGIN, (c: Readonly) => this.onConverterResolveBegin(c)); } @@ -56,27 +55,28 @@ export class Plugin { /** * Triggered when the converter has created a declaration reflection. - * @param _context Describes the current state the converter is in. + * @param context Describes the current state the converter is in. * @param reflection The reflection that has been created. - * @param node The triggering TypeScript node if available. */ - public onConverterCreateDeclaration( - _context: Readonly, - reflection: Reflection, - node?: Readonly, - ): void { + public onConverterCreateDeclaration(context: Readonly, reflection: DeclarationReflection): void { if ( this.isEnabled && this.options.renameDefaults && reflection.name === "default" && - node && - (ts.isVariableDeclaration(node) || - ts.isFunctionDeclaration(node) || - ts.isClassDeclaration(node) || - ts.isInterfaceDeclaration(node)) && - node.name + reflection.kindOf( + ReflectionKind.ClassOrInterface | + ReflectionKind.Enum | + ReflectionKind.Function | + ReflectionKind.ObjectLiteral | + ReflectionKind.TypeAlias | + ReflectionKind.TypeLiteral | + ReflectionKind.Variable, + ) ) { - reflection.name = node.name.getText(); + const originalName = context.project.getSymbolFromReflection(reflection)?.name; + if (originalName) { + reflection.name = originalName; + } } } @@ -100,6 +100,8 @@ export class Plugin { return new ProjectMerger(project); } else if (this.options.mode === "module") { return new ModuleMerger(project); + } else if (this.options.mode === "module-category") { + return new ModuleCategoryMerger(project); } return undefined; diff --git a/src/plugin_options.ts b/src/plugin_options.ts index 1311a1d..1e046db 100644 --- a/src/plugin_options.ts +++ b/src/plugin_options.ts @@ -1,7 +1,7 @@ import { Application, ParameterType } from "typedoc"; /** Type for the plugin's mode. */ -type Mode = "project" | "module" | "off"; +type Mode = "project" | "module" | "module-category" | "off"; /** * Extend typedoc's options with the plugin's option using declaration merging. @@ -58,6 +58,7 @@ export class PluginOptions { map: new Map([ ["project", "project"], ["module", "module"], + ["module-category", "module-category"], ["off", "off"], ]), name: "mergeModulesMergeMode",