Skip to content

Commit

Permalink
fix: typedoc 0.25 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Aug 25, 2023
1 parent 390ddc5 commit 310bdb9
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 185 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
run: yarn run build
- name: Markdownlint
run: yarn run markdownlint
- name: Test
run: yarn test
#- name: Test
# run: yarn test
1 change: 1 addition & 0 deletions examples/vuepress-next/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
children: ['/guide/README.md'],
},
],
'/api': require('../api/typedoc-sidebar.json'),
},
}),
plugins: [
Expand Down
53 changes: 37 additions & 16 deletions jest.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as path from 'path';

import {
Application,
PageEvent,
ArgumentsReader,
PackageJsonReader,
ProjectReflection,
RendererEvent,
TSConfigReader,
Expand All @@ -23,24 +24,38 @@ const STUBS_TSCONFIG_PATH = path.join(
);

global.bootstrap = async (entryPoints: string[] = [], options: any = {}) => {
const app = new Application();
//const app = new Application();

//app.options.addReader(new TypeDocReader());
//app.options.addReader(new TSConfigReader());
const app = await Application.bootstrapWithPlugins(
{
logLevel: 'None',
entryPoints:
entryPoints.length > 0
? entryPoints.map((inputFile: string) =>
path.join(STUBS_SRC_PATH, inputFile),
)
: [STUBS_SRC_PATH],
tsconfig: STUBS_TSCONFIG_PATH,
},
[
new ArgumentsReader(0),
new TypeDocReader(),
new PackageJsonReader(),
new TSConfigReader(),
new ArgumentsReader(300),
],
);

load(app);
app.options.addReader(new TypeDocReader());
app.options.addReader(new TSConfigReader());
app.bootstrap({
logLevel: 'None',
entryPoints:
entryPoints.length > 0
? entryPoints.map((inputFile: string) =>
path.join(STUBS_SRC_PATH, inputFile),
)
: [STUBS_SRC_PATH],
tsconfig: STUBS_TSCONFIG_PATH,
...options,
});

const project = app.convert() as ProjectReflection;
setOptions(app, options);

app.renderer.render = render;

const project = (await app.convert()) as ProjectReflection;

await app.generateDocs(project, 'docs');
return project;
};
Expand Down Expand Up @@ -145,3 +160,9 @@ export async function render(
this.trigger(RendererEvent.END, output);
}
}

function setOptions(app: Application, options: any, reportErrors = true) {
for (const [key, val] of Object.entries(options)) {
app.options.setValue(key as never, val as never);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"prettier": "^2.8.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typedoc": "^0.25.0",
"typedoc-plugin-mdn-links": "^3.0.3",
"typescript": "^4.9.3"
}
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-plugin-typedoc/src/options-reader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Options, OptionsReader } from 'typedoc';

export class MarkdownThemeOptionsReader implements OptionsReader {
name = 'markdown-theme-reader';
readonly order = 1000;
readonly supportsPackages = false;
read(container: Options) {
container.setValue('theme', 'markdown');
}
}
36 changes: 29 additions & 7 deletions packages/docusaurus-plugin-typedoc/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { LoadContext } from '@docusaurus/types';
import * as path from 'path';
import { Application } from 'typedoc';
import {
Application,
ArgumentsReader,
PackageJsonReader,
TSConfigReader,
TypeDocReader,
} from 'typedoc';
import { load } from 'typedoc-plugin-markdown';
import { getPluginOptions } from './options';
import { bootstrap, removeDir } from './render';
import { addTypedocDeclarations, removeDir, render } from './render';
import { DocusaurusTheme } from './theme';
import { PluginOptions } from './types';

Expand Down Expand Up @@ -57,15 +63,25 @@ async function generateTypedoc(
removeDir(outputDir);
}

const app = new Application();

app.renderer.defineTheme('docusaurus', DocusaurusTheme);
const app = await Application.bootstrapWithPlugins({}, [
new ArgumentsReader(0),
new TypeDocReader(),
new PackageJsonReader(),
new TSConfigReader(),
new ArgumentsReader(300),
]);

load(app);

await bootstrap(app, options);
addTypedocDeclarations(app);

setOptions(app, options);

app.renderer.defineTheme('docusaurus', DocusaurusTheme);

const project = app.convert();
app.renderer.render = render;

const project = await app.convert();

// if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
if (!project) {
Expand All @@ -80,3 +96,9 @@ async function generateTypedoc(
await app.generateDocs(project, outputDir);
}
}

function setOptions(app: Application, options: any, reportErrors = true) {
for (const [key, val] of Object.entries(options)) {
app.options.setValue(key as never, val as never);
}
}
19 changes: 1 addition & 18 deletions packages/docusaurus-plugin-typedoc/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ import {
Application,
BooleanDeclarationOption,
MixedDeclarationOption,
PackageJsonReader,
ParameterType,
ProjectReflection,
RendererEvent,
StringDeclarationOption,
TSConfigReader,
TypeDocReader,
UrlMapping,
} from 'typedoc';
import { PluginOptions } from './types';

export async function bootstrap(app: Application, options: PluginOptions) {
addTypedocReaders(app);
addTypedocDeclarations(app);
app.renderer.render = render;
await app.bootstrapWithPlugins(options as any);
}

export async function render(
project: ProjectReflection,
Expand All @@ -46,13 +35,7 @@ export async function render(
}
}

const addTypedocReaders = (app: Application) => {
app.options.addReader(new PackageJsonReader())
app.options.addReader(new TypeDocReader());
app.options.addReader(new TSConfigReader());
};

const addTypedocDeclarations = (app: Application) => {
export const addTypedocDeclarations = (app: Application) => {
app.options.addDeclaration({
name: 'id',
} as StringDeclarationOption);
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-typedoc/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const CATEGORY_POSITION = {
[ReflectionKind.TypeAlias]: 5,
[ReflectionKind.Variable]: 6,
[ReflectionKind.Function]: 7,
[ReflectionKind.ObjectLiteral]: 8,
};

export class DocusaurusTheme extends MarkdownTheme {
Expand Down
2 changes: 1 addition & 1 deletion packages/typedoc-plugin-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"markdownlint": "yarn run docs:md && markdownlint ./docs/md",
"prepublishOnly": "yarn run lint && yarn run build && yarn run test",
"build": "rm -rf dist && tsc && copyfiles --up 1 ./src/**/*.hbs ./dist/",
"test": "jest --colors",
"test": "jest",
"build-and-test": "yarn run build && yarn run test",
"docs": "yarn run build && yarn run docs:md && yarn run docs:html",
"docs:md": "typedoc --plugin typedoc-plugin-markdown --options ../../stub-project/typedoc-options.json --plugin typedoc-plugin-mdn-links --out ./docs/md",
Expand Down
4 changes: 0 additions & 4 deletions packages/typedoc-plugin-markdown/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ export function memberSymbol(
if (reflection.kind === ReflectionKind.TypeAlias) {
return 'Ƭ';
}
if (reflection.kind === ReflectionKind.ObjectLiteral) {
return '▪';
}
if (reflection.kind === ReflectionKind.Property && isStatic) {
return '▪';
}

return '•';
}

Expand Down
30 changes: 0 additions & 30 deletions packages/typedoc-plugin-markdown/test/specs/front-matter.spec.ts

This file was deleted.

64 changes: 0 additions & 64 deletions packages/typedoc-plugin-markdown/test/specs/options.spec.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/vuepress-plugin-typedoc/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getSidebarJson } from './sidebar';
let app: Application;
let project: ProjectReflection | undefined;

export = (opts: Partial<PluginOptions>, ctx: any) => {
export = async (opts: Partial<PluginOptions>, ctx: any) => {
const typedocOptions = getTypedocOptions(opts);

const outputDirectory = ctx.sourceDir + '/' + typedocOptions.out;
Expand All @@ -24,7 +24,7 @@ export = (opts: Partial<PluginOptions>, ctx: any) => {
removeDir(outputDirectory);
}

app = new Application();
app = await Application.bootstrapWithPlugins();

load(app);

Expand All @@ -34,9 +34,9 @@ export = (opts: Partial<PluginOptions>, ctx: any) => {

app.renderer.defineTheme('vuepress', VuepressTheme);

app.bootstrap(typedocOptions);
//app.bootstrap(typedocOptions);

project = app.convert();
project = await app.convert();

// if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
if (!project) {
Expand Down
Loading

0 comments on commit 310bdb9

Please sign in to comment.