@rspress/plugin-typedoc 1.42.0 → 1.42.1-canary-20240226

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-typedoc",
3
- "version": "1.42.0",
3
+ "version": "1.42.1-canary-20240226",
4
4
  "description": "A plugin for rspress to integrate typedoc",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -19,23 +19,22 @@
19
19
  "module": "./dist/es/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "files": [
22
- "dist",
23
- "src"
22
+ "dist"
24
23
  ],
25
24
  "dependencies": {
26
25
  "typedoc": "0.24.8",
27
26
  "typedoc-plugin-markdown": "3.17.1",
28
- "@rspress/shared": "1.42.0"
27
+ "@rspress/shared": "1.42.1-canary-20240226"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@microsoft/api-extractor": "^7.49.2",
32
- "@modern-js/tsconfig": "2.64.0",
33
- "@rslib/core": "0.4.1",
31
+ "@rslib/core": "0.5.2",
34
32
  "@types/node": "^18.11.17",
35
33
  "@types/react": "^18.3.18",
36
34
  "@types/react-dom": "^18.3.5",
37
35
  "react": "^18.3.1",
38
- "typescript": "^5.5.3"
36
+ "typescript": "^5.5.3",
37
+ "@rspress/config": "1.0.0"
39
38
  },
40
39
  "peerDependencies": {
41
40
  "rspress": "^1.42.0"
@@ -48,7 +47,6 @@
48
47
  "provenance": true,
49
48
  "registry": "https://registry.npmjs.org/"
50
49
  },
51
- "jsnext:source": "./src/index.ts",
52
50
  "scripts": {
53
51
  "build": "rslib build",
54
52
  "dev": "rslib build -w",
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const API_DIR = 'api';
package/src/env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types='@rslib/core/types' />
package/src/index.ts DELETED
@@ -1,103 +0,0 @@
1
- import path from 'node:path';
2
- import type { NavItem, RspressPlugin } from '@rspress/shared';
3
- import { Application, TSConfigReader } from 'typedoc';
4
- import { load } from 'typedoc-plugin-markdown';
5
- import { API_DIR } from './constants';
6
- import { patchGeneratedApiDocs } from './patch';
7
-
8
- export interface PluginTypeDocOptions {
9
- /**
10
- * The entry points of modules.
11
- * @default []
12
- */
13
- entryPoints: string[];
14
- /**
15
- * The output directory.
16
- * @default 'api'
17
- */
18
- outDir?: string;
19
- }
20
-
21
- export function pluginTypeDoc(options: PluginTypeDocOptions): RspressPlugin {
22
- let docRoot: string | undefined;
23
- const { entryPoints = [], outDir = API_DIR } = options;
24
- const apiPageRoute = `/${outDir.replace(/(^\/)|(\/$)/, '')}/`; // e.g: /api/
25
- return {
26
- name: '@rspress/plugin-typedoc',
27
- async addPages() {
28
- return [
29
- {
30
- routePath: apiPageRoute,
31
- filepath: path.join(docRoot!, outDir, 'README.md'),
32
- },
33
- ];
34
- },
35
- async config(config) {
36
- const app = new Application();
37
- docRoot = config.root;
38
- app.options.addReader(new TSConfigReader());
39
- load(app);
40
- app.bootstrap({
41
- name: config.title,
42
- entryPoints,
43
- theme: 'markdown',
44
- disableSources: true,
45
- readme: 'none',
46
- githubPages: false,
47
- requiredToBeDocumented: ['Class', 'Function', 'Interface'],
48
- plugin: ['typedoc-plugin-markdown'],
49
- // @ts-expect-error MarkdownTheme has no export
50
- hideBreadcrumbs: true,
51
- hideMembersSymbol: true,
52
- allReflectionsHaveOwnDocument: true,
53
- });
54
- const project = app.convert();
55
-
56
- if (project) {
57
- // 1. Generate doc/api, doc/api/_meta.json by typedoc
58
- const absoluteApiDir = path.join(docRoot!, outDir);
59
- await app.generateDocs(project, absoluteApiDir);
60
- await patchGeneratedApiDocs(absoluteApiDir);
61
-
62
- // 2. Generate "api" nav bar
63
- config.themeConfig = config.themeConfig || {};
64
- config.themeConfig.nav = config.themeConfig.nav || [];
65
- const { nav } = config.themeConfig;
66
-
67
- // avoid that user config "api" in doc/_meta.json
68
- function isApiAlreadyInNav(navList: NavItem[]) {
69
- return navList.some(item => {
70
- if (
71
- 'link' in item &&
72
- typeof item.link === 'string' &&
73
- item.link.startsWith(
74
- apiPageRoute.slice(0, apiPageRoute.length - 1), // /api
75
- )
76
- ) {
77
- return true;
78
- }
79
- return false;
80
- });
81
- }
82
-
83
- // Note: TypeDoc does not support i18n
84
- if (Array.isArray(nav)) {
85
- if (!isApiAlreadyInNav(nav)) {
86
- nav.push({
87
- text: 'API',
88
- link: apiPageRoute,
89
- });
90
- }
91
- } else if ('default' in nav) {
92
- if (!isApiAlreadyInNav(nav.default)) {
93
- nav.default.push({
94
- text: 'API',
95
- link: apiPageRoute,
96
- });
97
- }
98
- }
99
- }
100
- return config;
101
- },
102
- };
103
- }
package/src/patch.ts DELETED
@@ -1,72 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- async function patchLinks(outputDir: string) {
5
- // Patch links in markdown files
6
- // Scan all the markdown files in the output directory
7
- // replace
8
- // 1. [foo](bar) -> [foo](./bar)
9
- // 2. [foo](./bar) -> [foo](./bar) no change
10
- const normalizeLinksInFile = async (filePath: string) => {
11
- const content = await fs.readFile(filePath, 'utf-8');
12
- // 1. [foo](bar) -> [foo](./bar)
13
- const newContent = content.replace(
14
- /\[([^\]]+)\]\(([^)]+)\)/g,
15
- (_match, p1, p2) => {
16
- // 2. [foo](./bar) -> [foo](./bar) no change
17
- if (['/', '.'].includes(p2[0])) {
18
- return `[${p1}](${p2})`;
19
- }
20
- return `[${p1}](./${p2})`;
21
- },
22
- );
23
- await fs.writeFile(filePath, newContent);
24
- };
25
-
26
- const traverse = async (dir: string) => {
27
- const files = await fs.readdir(dir);
28
- const filePaths = files.map(file => path.join(dir, file));
29
- const stats = await Promise.all(filePaths.map(fp => fs.stat(fp)));
30
-
31
- await Promise.all(
32
- stats.map((stat, index) => {
33
- const file = files[index];
34
- const filePath = filePaths[index];
35
- if (stat.isDirectory()) {
36
- return traverse(filePath);
37
- }
38
- if (stat.isFile() && /\.mdx?/.test(file)) {
39
- return normalizeLinksInFile(filePath);
40
- }
41
- }),
42
- );
43
- };
44
- await traverse(outputDir);
45
- }
46
-
47
- async function generateMetaJson(absoluteApiDir: string) {
48
- const metaJsonPath = path.join(absoluteApiDir, '_meta.json');
49
-
50
- const files = await fs.readdir(absoluteApiDir);
51
- const filePaths = files.map(file => path.join(absoluteApiDir, file));
52
- const stats = await Promise.all(filePaths.map(fp => fs.stat(fp)));
53
- const dirs = stats
54
- .map((stat, index) => (stat.isDirectory() ? files[index] : null))
55
- .filter(Boolean) as string[];
56
-
57
- const meta = dirs.map(dir => ({
58
- type: 'dir',
59
- label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
60
- name: dir,
61
- }));
62
- await fs.writeFile(metaJsonPath, JSON.stringify(['index', ...meta]));
63
- }
64
-
65
- export async function patchGeneratedApiDocs(absoluteApiDir: string) {
66
- await patchLinks(absoluteApiDir);
67
- await fs.rename(
68
- path.join(absoluteApiDir, 'README.md'),
69
- path.join(absoluteApiDir, 'index.md'),
70
- );
71
- await generateMetaJson(absoluteApiDir);
72
- }
package/src/utils.ts DELETED
@@ -1,3 +0,0 @@
1
- export function transformModuleName(name: string) {
2
- return name.replace(/\//g, '_').replace(/-/g, '_');
3
- }