Skip to content
Draft
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
20 changes: 7 additions & 13 deletions e2e/fixtures/plugin-typedoc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ test.describe('plugin-typedoc single entry', async () => {
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Types',
'Type alias: Middleware',
'Type-aliases',
'Type Alias: Middleware()',
].join(','),
);
});
Expand Down Expand Up @@ -63,26 +63,20 @@ test.describe('plugin-typedoc multi entries', async () => {
await expect(navItems).toHaveCount(2);

const sidebarTexts = await getSidebarTexts(page);
expect(sidebarTexts.length).toBe(10);
expect(sidebarTexts.length).toBe(7);
expect(sidebarTexts.join(',')).toEqual(
[
'@rspress-fixture/rspress-plugin-typedoc-multi',
'Functions',
'Function: createMiddleware',
'Function: mergeMiddlewares',
'Function: getRspressUrl',
'Modules',
'Module: middleware',
'Module: raw-link',
'Types',
'Type alias: Middleware',
'Index',
'Middleware',
'Raw-link',
].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/raw-link/functions/getRspressUrl.html`,
{
waitUntil: 'networkidle',
},
Expand Down
12 changes: 0 additions & 12 deletions e2e/fixtures/plugin-typedoc/multi/doc/_nav.json

This file was deleted.

1 change: 0 additions & 1 deletion e2e/fixtures/plugin-typedoc/multi/doc/guide.mdx

This file was deleted.

1 change: 0 additions & 1 deletion e2e/fixtures/plugin-typedoc/multi/doc/index.mdx

This file was deleted.

12 changes: 0 additions & 12 deletions e2e/fixtures/plugin-typedoc/single/doc/_nav.json

This file was deleted.

1 change: 0 additions & 1 deletion e2e/fixtures/plugin-typedoc/single/doc/guide.mdx

This file was deleted.

1 change: 0 additions & 1 deletion e2e/fixtures/plugin-typedoc/single/doc/index.mdx

This file was deleted.

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.53.3",
Expand Down
38 changes: 20 additions & 18 deletions packages/plugin-typedoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,32 @@ export function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {
return {
name: '@rspress/plugin-typedoc',
async config(config) {
const app = new Application();
docRoot = config.root;
app.options.addReader(new TSConfigReader());
const app = await Application.bootstrap(
{
name: config.title,
entryPoints,
disableSources: true,
readme: 'none',
githubPages: false,
requiredToBeDocumented: ['Class', 'Function', 'Interface'],
},
[new TSConfigReader()],
);
// Load the markdown plugin manually
load(app);
app.bootstrap({
name: config.title,
entryPoints,
theme: 'markdown',
disableSources: true,
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
hideBreadcrumbs: true,
hideMembersSymbol: true,
allReflectionsHaveOwnDocument: true,
});
const project = app.convert();
// Set plugin-specific options after loading the plugin
app.options.setValue('hideBreadcrumbs', true);
app.options.setValue('fileExtension', '.md');
app.options.setValue('entryFileName', 'index');
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);
// Set the markdown output directory and generate outputs
app.options.setValue('markdown', absoluteApiDir);
await app.generateOutputs(project);
await patchGeneratedApiDocs(absoluteApiDir);
}
return config;
Expand Down
15 changes: 11 additions & 4 deletions packages/plugin-typedoc/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ 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'),
);
// In newer versions of typedoc-plugin-markdown with entryFileName='index',
// index.md is generated directly. Only rename if README.md exists.
const readmePath = path.join(absoluteApiDir, 'README.md');
const indexPath = path.join(absoluteApiDir, 'index.md');
try {
await fs.access(readmePath);
// README.md exists, rename it to index.md
await fs.rename(readmePath, indexPath);
} catch {
// README.md doesn't exist, index.md should already exist
}
await generateMetaJson(absoluteApiDir);
}
Loading
Loading