Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions e2e/fixtures/plugin-typedoc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ test.describe('plugin-typedoc single entry', async () => {
[
'@rspress-fixture/rspress-plugin-typedoc-single',
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Function: createMiddleware()',
'Function: mergeMiddlewares()',
'Types',
'Type alias: Middleware',
'Type Alias: Middleware()',
].join(','),
);
});
Expand Down Expand Up @@ -68,21 +68,21 @@ test.describe('plugin-typedoc multi entries', async () => {
[
'@rspress-fixture/rspress-plugin-typedoc-multi',
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Function: getRspressUrl',
'Function: createMiddleware()',
'Function: mergeMiddlewares()',
'Function: getRspressUrl()',
'Modules',
'Module: middleware',
'Module: raw-link',
'Types',
'Type alias: Middleware',
'Type Alias: Middleware()',
].join(','),
);
});

test('Should render raw link correctly', async ({ page }) => {
await page.goto(
`http://localhost:${appPort}/api/functions/raw_link.getRspressUrl.html`,
`http://localhost:${appPort}/api/functions/raw-link.getRspressUrl.html`,
{
waitUntil: 'networkidle',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-typedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"typedoc": "0.24.8",
"typedoc-plugin-markdown": "3.17.1"
"typedoc": "0.28.14",
"typedoc-plugin-markdown": "4.9.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.55.0",
Expand Down
33 changes: 17 additions & 16 deletions packages/plugin-typedoc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import type { RspressPlugin } from '@rspress/core';
import { Application, TSConfigReader } from 'typedoc';
import { load } from 'typedoc-plugin-markdown';
import { Application } from 'typedoc';
import { load as loadPluginMarkdown } from 'typedoc-plugin-markdown';
import { API_DIR } from './constants';
import { patchGeneratedApiDocs } from './patch';

Expand All @@ -19,35 +19,36 @@ export interface PluginTypeDocOptions {
}

export function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {
let docRoot: string | undefined;
const { entryPoints = [], outDir = API_DIR } = options;
return {
name: '@rspress/plugin-typedoc',
async config(config) {
const app = new Application();
docRoot = config.root;
app.options.addReader(new TSConfigReader());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TSConfigReader is now included by default when using the bootstrapWithPlugins method.

load(app);
app.bootstrap({
const app = await Application.bootstrapWithPlugins({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the constructor of the Application class has been made private, initialization is now done using the bootstrapWithPlugins method instead.

name: config.title,
entryPoints,
theme: 'markdown',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme option is no longer needed; instead, it is now specified via the writeOutput method.

disableSources: true,
router: 'kind',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the default output directory structure has changed, I added an option so that it can generate the same structure as before.

readme: 'none',
githubPages: false,
requiredToBeDocumented: ['Class', 'Function', 'Interface'],
plugin: ['typedoc-plugin-markdown'],
// @ts-expect-error - FIXME: current version of MarkdownTheme has no export, bump related package versions
// @ts-expect-error - Typedoc does not export a type for this options
plugin: [loadPluginMarkdown],
entryFileName: 'index',
hidePageHeader: true,
hideBreadcrumbs: true,
hideMembersSymbol: true,
allReflectionsHaveOwnDocument: true,
Comment on lines -42 to -43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options have been removed and are no longer available.

pageTitleTemplates: {
module: '{kind}: {name}', // e.g. "Module: MyModule"
},
});
const project = app.convert();

const project = await app.convert();
if (project) {
// 1. Generate doc/api, doc/api/_meta.json by typedoc
const absoluteApiDir = path.join(docRoot!, outDir);
await app.generateDocs(project, absoluteApiDir);
const absoluteApiDir = path.join(config.root!, outDir);
await app.outputs.writeOutput(
{ name: 'markdown', path: absoluteApiDir },
project,
);
Comment on lines -50 to +51
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the generateDocs method was changed to output HTML files, I updated the code to use the writeOutput method instead.

await patchGeneratedApiDocs(absoluteApiDir);
}
return config;
Expand Down
4 changes: 0 additions & 4 deletions packages/plugin-typedoc/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,5 @@ async function generateMetaJson(absoluteApiDir: string) {

export async function patchGeneratedApiDocs(absoluteApiDir: string) {
await patchLinks(absoluteApiDir);
await fs.rename(
path.join(absoluteApiDir, 'README.md'),
path.join(absoluteApiDir, 'index.md'),
);
Comment on lines -73 to -76
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to use the entryFileName option instead.

await generateMetaJson(absoluteApiDir);
}
3 changes: 0 additions & 3 deletions packages/plugin-typedoc/src/utils.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it was not being used.

This file was deleted.

Loading
Loading