Skip to content

Commit

Permalink
fix(typedoc-0.14): Improve typedoc 0.14.0 compatibility to account fo…
Browse files Browse the repository at this point in the history
…r api change

This accounts for an API change in DeclarationReflection constructor which is used when creating a parent.child typedoc module
  • Loading branch information
christopherthielen committed Jan 15, 2020
1 parent b983efd commit 68fc6e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
},
"author": "Chris Thielen",
"license": "MIT",
"dependencies": {
"semver": "^7.1.1"
},
"peerDependencies": {
"typedoc": ">=0.7.0 <0.15.0"
},
"devDependencies": {
"@types/handlebars": "^4.0.37",
"@types/semver": "^6.2.0",
"@uirouter/publish-scripts": "^2.3.24",
"husky": "^2.2.0",
"prettier": "^1.13.7",
Expand Down
11 changes: 10 additions & 1 deletion plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { ContainerReflection } from 'typedoc/dist/lib/models/reflections/contain
import { DeclarationReflection } from 'typedoc/dist/lib/models/reflections/declaration';
import { getRawComment } from './getRawComment';

import { satisfies } from 'semver';
const version = require('typedoc/package.json').version;
const useOldDeclarationReflectionConstructor = satisfies(version, '< 0.14.0');

/**
* This plugin allows an ES6 module to specify its TypeDoc name.
* It also allows multiple ES6 modules to be merged together into a single TypeDoc module.
Expand Down Expand Up @@ -109,7 +113,12 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
for (let i = 0; i < nameParts.length - 1; ++i) {
let child: DeclarationReflection = parent.children.filter(ref => ref.name === nameParts[i])[0];
if (!child) {
child = new DeclarationReflection(parent, nameParts[i], ReflectionKind.ExternalModule);
if (useOldDeclarationReflectionConstructor) {
// for typedoc < 0.15.0
child = new (DeclarationReflection as any)(parent, nameParts[i], ReflectionKind.ExternalModule);
} else {
child = new DeclarationReflection(nameParts[i], ReflectionKind.ExternalModule, parent);
}
child.parent = parent;
child.children = [];
context.project.reflections[child.id] = child;
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==

"@types/semver@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.0.tgz#d688d574400d96c5b0114968705366f431831e1a"
integrity sha512-1OzrNb4RuAzIT7wHSsgZRlMBlNsJl+do6UblR7JMW4oB7bbR+uBEYtUh7gEc/jM84GGilh68lSOokyM/zNUlBA==

"@types/shelljs@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.1.tgz#133e874b5fb816a2e1c8647839c82d76760b1191"
Expand Down Expand Up @@ -1716,6 +1721,11 @@ semver-compare@^1.0.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"

semver@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.1.tgz#29104598a197d6cbe4733eeecbe968f7b43a9667"
integrity sha512-WfuG+fl6eh3eZ2qAf6goB7nhiCd7NPXhmyFxigB/TOkQyeLP8w8GsVehvtGNtnNmyboz4TgeK40B1Kbql/8c5A==

set-blocking@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down

0 comments on commit 68fc6e1

Please sign in to comment.