@apify/docusaurus-plugin-typedoc-api 3.0.1 → 4.2.0
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/README.md +27 -5
- package/lib/components/AnchorLink.js +15 -10
- package/lib/components/AnchorLink.js.map +1 -1
- package/lib/components/ApiChangelog.js +9 -11
- package/lib/components/ApiChangelog.js.map +1 -1
- package/lib/components/ApiDataContext.js +2 -2
- package/lib/components/ApiIndex.js +55 -37
- package/lib/components/ApiIndex.js.map +1 -1
- package/lib/components/ApiItem.js +33 -29
- package/lib/components/ApiItem.js.map +1 -1
- package/lib/components/ApiItemLayout.js +49 -27
- package/lib/components/ApiItemLayout.js.map +1 -1
- package/lib/components/ApiPage.js +18 -10
- package/lib/components/ApiPage.js.map +1 -1
- package/lib/components/Breadcrumb.js +27 -14
- package/lib/components/Breadcrumb.js.map +1 -1
- package/lib/components/Comment.js +24 -18
- package/lib/components/Comment.js.map +1 -1
- package/lib/components/CommentBadges.js +8 -11
- package/lib/components/CommentBadges.js.map +1 -1
- package/lib/components/DefaultValue.js +20 -20
- package/lib/components/DefaultValue.js.map +1 -1
- package/lib/components/Flags.js +9 -11
- package/lib/components/Flags.js.map +1 -1
- package/lib/components/Footer.js +11 -12
- package/lib/components/Footer.js.map +1 -1
- package/lib/components/Hierarchy.js +15 -16
- package/lib/components/Hierarchy.js.map +1 -1
- package/lib/components/Icon.js +2 -6
- package/lib/components/Icon.js.map +1 -1
- package/lib/components/Index.js +84 -62
- package/lib/components/Index.js.map +1 -1
- package/lib/components/Markdown.js +80 -66
- package/lib/components/Markdown.js.map +1 -1
- package/lib/components/Member.js +28 -28
- package/lib/components/Member.js.map +1 -1
- package/lib/components/MemberDeclaration.js +51 -42
- package/lib/components/MemberDeclaration.js.map +1 -1
- package/lib/components/MemberGetterSetter.js +50 -40
- package/lib/components/MemberGetterSetter.js.map +1 -1
- package/lib/components/MemberReference.js +27 -16
- package/lib/components/MemberReference.js.map +1 -1
- package/lib/components/MemberSignatureBody.js +57 -45
- package/lib/components/MemberSignatureBody.js.map +1 -1
- package/lib/components/MemberSignatureTitle.js +48 -27
- package/lib/components/MemberSignatureTitle.js.map +1 -1
- package/lib/components/MemberSignatures.js +46 -38
- package/lib/components/MemberSignatures.js.map +1 -1
- package/lib/components/MemberSources.js +18 -15
- package/lib/components/MemberSources.js.map +1 -1
- package/lib/components/Members.js +32 -31
- package/lib/components/Members.js.map +1 -1
- package/lib/components/MembersGroup.js +24 -22
- package/lib/components/MembersGroup.js.map +1 -1
- package/lib/components/Parameter.js +139 -109
- package/lib/components/Parameter.js.map +1 -1
- package/lib/components/Reflection.js +113 -90
- package/lib/components/Reflection.js.map +1 -1
- package/lib/components/SourceLink.js +12 -13
- package/lib/components/SourceLink.js.map +1 -1
- package/lib/components/Type.js +320 -206
- package/lib/components/Type.js.map +1 -1
- package/lib/components/TypeAndParent.js +11 -10
- package/lib/components/TypeAndParent.js.map +1 -1
- package/lib/components/TypeParameters.js +23 -20
- package/lib/components/TypeParameters.js.map +1 -1
- package/lib/components/TypeParametersGeneric.js +17 -16
- package/lib/components/TypeParametersGeneric.js.map +1 -1
- package/lib/components/VersionBanner.js +21 -9
- package/lib/components/VersionBanner.js.map +1 -1
- package/lib/hooks/useBreadcrumbs.js +2 -2
- package/lib/hooks/useGitRefName.js +2 -2
- package/lib/hooks/useMinimalLayout.js +2 -2
- package/lib/hooks/useReflection.js +10 -6
- package/lib/hooks/useReflection.js.map +1 -1
- package/lib/hooks/useReflectionMap.js +2 -2
- package/lib/index.js +62 -25
- package/lib/index.js.map +1 -1
- package/lib/plugin/data.js +61 -18
- package/lib/plugin/data.js.map +1 -1
- package/lib/plugin/version.js +5 -4
- package/lib/plugin/version.js.map +1 -1
- package/lib/utils/helpers.js +8 -0
- package/lib/utils/helpers.js.map +1 -0
- package/lib/utils/hierarchy.js +6 -3
- package/lib/utils/hierarchy.js.map +1 -1
- package/lib/utils/icons.js +2 -5
- package/lib/utils/icons.js.map +1 -1
- package/lib/utils/markdown.js +5 -7
- package/lib/utils/markdown.js.map +1 -1
- package/package.json +17 -14
- package/src/components/AnchorLink.tsx +6 -3
- package/src/components/ApiChangelog.tsx +0 -1
- package/src/components/ApiDataContext.ts +2 -2
- package/src/components/ApiIndex.tsx +1 -1
- package/src/components/ApiItem.tsx +18 -20
- package/src/components/ApiItemLayout.tsx +1 -2
- package/src/components/ApiPage.tsx +18 -13
- package/src/components/Breadcrumb.tsx +2 -3
- package/src/components/Comment.tsx +3 -4
- package/src/components/CommentBadges.tsx +0 -1
- package/src/components/DefaultValue.tsx +0 -1
- package/src/components/Flags.tsx +1 -1
- package/src/components/Footer.tsx +0 -2
- package/src/components/Hierarchy.tsx +0 -1
- package/src/components/Icon.tsx +2 -3
- package/src/components/Index.tsx +14 -19
- package/src/components/Markdown.tsx +54 -25
- package/src/components/Member.tsx +7 -6
- package/src/components/MemberDeclaration.tsx +7 -7
- package/src/components/MemberGetterSetter.tsx +6 -6
- package/src/components/MemberReference.tsx +4 -4
- package/src/components/MemberSignatureBody.tsx +5 -5
- package/src/components/MemberSignatureTitle.tsx +11 -9
- package/src/components/MemberSignatures.tsx +5 -5
- package/src/components/MemberSources.tsx +3 -5
- package/src/components/Members.tsx +3 -4
- package/src/components/MembersGroup.tsx +1 -2
- package/src/components/Parameter.tsx +7 -12
- package/src/components/README.md +1 -1
- package/src/components/Reflection.tsx +7 -10
- package/src/components/SourceLink.tsx +0 -2
- package/src/components/Type.tsx +34 -22
- package/src/components/TypeAndParent.tsx +0 -1
- package/src/components/TypeParameters.tsx +0 -1
- package/src/components/TypeParametersGeneric.tsx +3 -3
- package/src/components/VersionBanner.tsx +1 -1
- package/src/hooks/useReflection.ts +11 -4
- package/src/hooks/useReflectionMap.ts +2 -2
- package/src/index.ts +92 -39
- package/src/plugin/data.ts +123 -54
- package/src/plugin/sidebar.ts +4 -3
- package/src/types.ts +24 -33
- package/src/utils/helpers.ts +4 -0
- package/src/utils/hierarchy.ts +11 -7
- package/src/utils/icons.ts +2 -3
- package/src/utils/markdown.ts +10 -7
- package/src/utils/visibility.ts +4 -4
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Options as MDXLoaderOptions } from '@docusaurus/mdx-loader';
|
|
6
6
|
import type { PropVersionDocs, PropVersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
7
7
|
import { CURRENT_VERSION_NAME } from '@docusaurus/plugin-content-docs/server';
|
|
8
8
|
import type { LoadContext, Plugin, RouteConfig } from '@docusaurus/types';
|
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
PackageEntryConfig,
|
|
23
23
|
PackageReflectionGroup,
|
|
24
24
|
ResolvedPackageConfig,
|
|
25
|
+
TSDDeclarationReflection,
|
|
25
26
|
VersionMetadata,
|
|
26
27
|
} from './types';
|
|
27
28
|
|
|
@@ -51,6 +52,8 @@ const DEFAULT_OPTIONS: Required<DocusaurusPluginTypeDocApiOptions> = {
|
|
|
51
52
|
routeBasePath: 'api',
|
|
52
53
|
tsconfigName: 'tsconfig.json',
|
|
53
54
|
typedocOptions: {},
|
|
55
|
+
remarkPlugins: [],
|
|
56
|
+
rehypePlugins: [],
|
|
54
57
|
versions: {},
|
|
55
58
|
};
|
|
56
59
|
|
|
@@ -96,7 +99,7 @@ export default function typedocApiPlugin(
|
|
|
96
99
|
if (!pkgConfig.entry || typeof pkgConfig.entry === 'string') {
|
|
97
100
|
entries.index = {
|
|
98
101
|
label: 'Index',
|
|
99
|
-
path: pkgConfig.entry
|
|
102
|
+
path: pkgConfig.entry ? String(pkgConfig.entry) : 'src/index.ts',
|
|
100
103
|
};
|
|
101
104
|
} else {
|
|
102
105
|
Object.entries(pkgConfig.entry).forEach(([importPath, entryConfig]) => {
|
|
@@ -105,7 +108,7 @@ export default function typedocApiPlugin(
|
|
|
105
108
|
? {
|
|
106
109
|
label: 'Index',
|
|
107
110
|
path: entryConfig,
|
|
108
|
-
|
|
111
|
+
}
|
|
109
112
|
: entryConfig;
|
|
110
113
|
});
|
|
111
114
|
}
|
|
@@ -116,6 +119,7 @@ export default function typedocApiPlugin(
|
|
|
116
119
|
|
|
117
120
|
return {
|
|
118
121
|
entryPoints: entries,
|
|
122
|
+
packageRoot: path.normalize(path.join(projectRoot, pkgConfig.path || '.')),
|
|
119
123
|
packagePath: pkgConfig.path || '.',
|
|
120
124
|
packageSlug: pkgConfig.slug ?? path.basename(pkgConfig.path),
|
|
121
125
|
// Load later on
|
|
@@ -220,15 +224,34 @@ export default function typedocApiPlugin(
|
|
|
220
224
|
|
|
221
225
|
packages.sort((a, d) => options.sortPackages(a, d));
|
|
222
226
|
|
|
227
|
+
// Generate sidebars (this runs before the main sidebar is loaded)
|
|
228
|
+
const sidebars = extractSidebar(
|
|
229
|
+
packages,
|
|
230
|
+
removeScopes,
|
|
231
|
+
changelogs,
|
|
232
|
+
options.sortSidebar,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
await fs.promises.writeFile(
|
|
236
|
+
path.join(
|
|
237
|
+
context.generatedFilesDir,
|
|
238
|
+
`api-sidebar-${pluginId}-${metadata.versionName}.js`,
|
|
239
|
+
),
|
|
240
|
+
`module.exports = ${JSON.stringify(sidebars, null, 2)};`,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
await fs.promises.writeFile(
|
|
244
|
+
path.join(
|
|
245
|
+
context.generatedFilesDir,
|
|
246
|
+
`api-sidebar-${pluginId}-${metadata.versionName}.d.ts`,
|
|
247
|
+
),
|
|
248
|
+
`import type { SidebarConfig } from '@docusaurus/plugin-content-docs';\nexport = Array<SidebarConfig>;`,
|
|
249
|
+
);
|
|
250
|
+
|
|
223
251
|
return {
|
|
224
252
|
...metadata,
|
|
225
253
|
packages,
|
|
226
|
-
sidebars
|
|
227
|
-
packages,
|
|
228
|
-
removeScopes,
|
|
229
|
-
changelogs,
|
|
230
|
-
options.sortSidebar,
|
|
231
|
-
),
|
|
254
|
+
sidebars,
|
|
232
255
|
};
|
|
233
256
|
}),
|
|
234
257
|
),
|
|
@@ -240,7 +263,6 @@ export default function typedocApiPlugin(
|
|
|
240
263
|
return;
|
|
241
264
|
}
|
|
242
265
|
|
|
243
|
-
const { createData, addRoute } = actions;
|
|
244
266
|
const docs: PropVersionDocs = {};
|
|
245
267
|
|
|
246
268
|
// Create an index of versions for quick lookups.
|
|
@@ -255,14 +277,14 @@ export default function typedocApiPlugin(
|
|
|
255
277
|
}
|
|
256
278
|
});
|
|
257
279
|
|
|
258
|
-
await Promise.all(
|
|
280
|
+
const rootRoutes = await Promise.all(
|
|
259
281
|
content.loadedVersions.map(async (loadedVersion) => {
|
|
260
282
|
const version = loadedVersion.versionName;
|
|
261
283
|
|
|
262
284
|
// Define version metadata for all pages. We need to use the same structure as
|
|
263
285
|
// "docs" so that we can utilize the same React components.
|
|
264
286
|
// https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-plugin-content-docs/src/index.ts#L337
|
|
265
|
-
const versionMetadata = await createData(
|
|
287
|
+
const versionMetadata = await actions.createData(
|
|
266
288
|
`version-${version}.json`,
|
|
267
289
|
JSON.stringify({
|
|
268
290
|
badge: loadedVersion.versionBadge,
|
|
@@ -275,26 +297,28 @@ export default function typedocApiPlugin(
|
|
|
275
297
|
noIndex: false,
|
|
276
298
|
pluginId,
|
|
277
299
|
version: loadedVersion.versionName,
|
|
278
|
-
}
|
|
300
|
+
} satisfies PropVersionMetadata),
|
|
279
301
|
);
|
|
280
302
|
|
|
281
|
-
const packagesData = await createData(
|
|
303
|
+
const packagesData = await actions.createData(
|
|
282
304
|
`packages-${version}.json`,
|
|
283
305
|
JSON.stringify(formatPackagesWithoutHostInfo(loadedVersion.packages)),
|
|
284
306
|
);
|
|
285
307
|
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
308
|
+
const optionsData = await actions.createData(
|
|
309
|
+
'options.json',
|
|
310
|
+
JSON.stringify({
|
|
311
|
+
banner,
|
|
312
|
+
breadcrumbs,
|
|
313
|
+
gitRefName,
|
|
314
|
+
minimal,
|
|
315
|
+
pluginId,
|
|
316
|
+
scopes: removeScopes,
|
|
317
|
+
} satisfies ApiOptions),
|
|
318
|
+
);
|
|
295
319
|
|
|
296
320
|
function createRoute(
|
|
297
|
-
info:
|
|
321
|
+
info: TSDDeclarationReflection,
|
|
298
322
|
modules?: Record<string, string>,
|
|
299
323
|
): RouteConfig {
|
|
300
324
|
return {
|
|
@@ -319,7 +343,7 @@ export default function typedocApiPlugin(
|
|
|
319
343
|
// Map a route for every declaration in the package (the exported APIs)
|
|
320
344
|
const subRoutes = children.map((child) => createRoute(child));
|
|
321
345
|
|
|
322
|
-
// Map a top-level package route, otherwise `
|
|
346
|
+
// Map a top-level package route, otherwise `DocRoot` shows a page not found
|
|
323
347
|
subRoutes.push(
|
|
324
348
|
createRoute(
|
|
325
349
|
entry.reflection,
|
|
@@ -359,20 +383,40 @@ export default function typedocApiPlugin(
|
|
|
359
383
|
});
|
|
360
384
|
}
|
|
361
385
|
|
|
362
|
-
|
|
386
|
+
// Wrap in the `DocVersionRoot` component:
|
|
387
|
+
// https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-content-docs/src/routes.ts#L192
|
|
388
|
+
return {
|
|
363
389
|
path: indexPermalink,
|
|
364
390
|
exact: false,
|
|
365
|
-
component:
|
|
366
|
-
routes
|
|
391
|
+
component: '@theme/DocVersionRoot',
|
|
392
|
+
routes: [
|
|
393
|
+
{
|
|
394
|
+
path: indexPermalink,
|
|
395
|
+
exact: false,
|
|
396
|
+
component: path.join(__dirname, './components/ApiPage.js'),
|
|
397
|
+
routes,
|
|
398
|
+
modules: {
|
|
399
|
+
options: optionsData,
|
|
400
|
+
packages: packagesData,
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
],
|
|
367
404
|
modules: {
|
|
368
|
-
|
|
369
|
-
packages: packagesData,
|
|
370
|
-
versionMetadata,
|
|
405
|
+
version: versionMetadata,
|
|
371
406
|
},
|
|
372
407
|
priority: loadedVersion.routePriority,
|
|
373
|
-
}
|
|
408
|
+
};
|
|
374
409
|
}),
|
|
375
410
|
);
|
|
411
|
+
|
|
412
|
+
// Wrap in the `DocsRoot` component:
|
|
413
|
+
// https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-content-docs/src/routes.ts#L232
|
|
414
|
+
actions.addRoute({
|
|
415
|
+
path: normalizeUrl([context.baseUrl, options.routeBasePath ?? 'api']),
|
|
416
|
+
exact: false,
|
|
417
|
+
component: '@theme/DocsRoot',
|
|
418
|
+
routes: rootRoutes,
|
|
419
|
+
});
|
|
376
420
|
},
|
|
377
421
|
|
|
378
422
|
configureWebpack(config, isServer, utils) {
|
|
@@ -383,10 +427,16 @@ export default function typedocApiPlugin(
|
|
|
383
427
|
// Whitelist the folders that this webpack rule applies to, otherwise we collide with the native
|
|
384
428
|
// docs/blog plugins. We need to include the specific files only, as in polyrepo mode, the `cfg.packagePath`
|
|
385
429
|
// can be project root (where the regular docs are too).
|
|
386
|
-
const include = packageConfigs.flatMap((cfg) =>
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
430
|
+
const include = packageConfigs.flatMap((cfg) => {
|
|
431
|
+
const list: string[] = [];
|
|
432
|
+
if (readmes) {
|
|
433
|
+
list.push(path.join(options.projectRoot, cfg.packagePath, options.readmeName));
|
|
434
|
+
}
|
|
435
|
+
if (changelogs) {
|
|
436
|
+
list.push(path.join(options.projectRoot, cfg.packagePath, options.changelogName));
|
|
437
|
+
}
|
|
438
|
+
return list;
|
|
439
|
+
});
|
|
390
440
|
|
|
391
441
|
return {
|
|
392
442
|
module: {
|
|
@@ -400,12 +450,15 @@ export default function typedocApiPlugin(
|
|
|
400
450
|
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
401
451
|
options: {
|
|
402
452
|
admonitions: true,
|
|
403
|
-
|
|
404
|
-
|
|
453
|
+
remarkPlugins: options.remarkPlugins,
|
|
454
|
+
rehypePlugins: options.rehypePlugins,
|
|
455
|
+
siteDir: context.siteDir,
|
|
456
|
+
staticDirs: [...context.siteConfig.staticDirectories, path.join(context.siteDir, 'static')],
|
|
457
|
+
// Since this isn't a doc/blog page, we can get
|
|
405
458
|
// away with it being a partial!
|
|
406
459
|
isMDXPartial: () => true,
|
|
407
460
|
markdownConfig: context.siteConfig.markdown,
|
|
408
|
-
},
|
|
461
|
+
} satisfies MDXLoaderOptions,
|
|
409
462
|
},
|
|
410
463
|
{
|
|
411
464
|
loader: path.resolve(__dirname, './markdownLoader.js'),
|
package/src/plugin/data.ts
CHANGED
|
@@ -5,10 +5,12 @@ import { JSONOutput, ReflectionKind } from 'typedoc';
|
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
import { normalizeUrl } from '@docusaurus/utils';
|
|
7
7
|
import type {
|
|
8
|
-
DeclarationReflectionMap,
|
|
9
8
|
DocusaurusPluginTypeDocApiOptions,
|
|
9
|
+
PackageEntryConfig,
|
|
10
10
|
PackageReflectionGroup,
|
|
11
11
|
ResolvedPackageConfig,
|
|
12
|
+
TSDDeclarationReflection,
|
|
13
|
+
TSDDeclarationReflectionMap,
|
|
12
14
|
} from '../types';
|
|
13
15
|
import { migrateToVersion0230 } from './structure/0.23';
|
|
14
16
|
import { getKindSlug, getPackageSlug, joinUrl } from './url';
|
|
@@ -52,43 +54,45 @@ export async function generateJson(
|
|
|
52
54
|
return true;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
57
|
+
const tsconfig = path.join(projectRoot, options.tsconfigName ?? 'tsconfig.json');
|
|
58
|
+
|
|
59
|
+
const app = await TypeDoc.Application.bootstrapWithPlugins(
|
|
60
|
+
{
|
|
61
|
+
gitRevision: options.gitRefName,
|
|
62
|
+
includeVersion: true,
|
|
63
|
+
skipErrorChecking: true,
|
|
64
|
+
// stripYamlFrontmatter: true,
|
|
65
|
+
// Only emit when using project references
|
|
66
|
+
emit: shouldEmit(projectRoot, tsconfig),
|
|
67
|
+
// Only document the public API by default
|
|
68
|
+
excludeExternals: true,
|
|
69
|
+
excludeInternal: true,
|
|
70
|
+
excludePrivate: true,
|
|
71
|
+
excludeProtected: true,
|
|
72
|
+
// Enable verbose logging when debugging
|
|
73
|
+
logLevel: options.debug ? 'Verbose' : 'Info',
|
|
74
|
+
inlineTags: [
|
|
75
|
+
'@link',
|
|
76
|
+
'@inheritDoc',
|
|
77
|
+
'@label',
|
|
78
|
+
'@linkcode',
|
|
79
|
+
'@linkplain',
|
|
80
|
+
'@apilink',
|
|
81
|
+
'@doclink',
|
|
82
|
+
] as `@${string}`[],
|
|
83
|
+
...options.typedocOptions,
|
|
84
|
+
// Control how config and packages are detected
|
|
85
|
+
tsconfig,
|
|
86
|
+
entryPoints: entryPoints.map((ep) => path.join(projectRoot, ep)),
|
|
87
|
+
entryPointStrategy: 'expand',
|
|
88
|
+
exclude: options.exclude,
|
|
89
|
+
// We use a fake category title so that we can fallback to the parent group
|
|
90
|
+
defaultCategory: '__CATEGORY__',
|
|
91
|
+
},
|
|
92
|
+
[new TypeDoc.TSConfigReader(), new TypeDoc.TypeDocReader()],
|
|
93
|
+
);
|
|
90
94
|
|
|
91
|
-
const project = app.convert();
|
|
95
|
+
const project = await app.convert();
|
|
92
96
|
|
|
93
97
|
if (project) {
|
|
94
98
|
await app.generateJson(project, outFile);
|
|
@@ -102,9 +106,9 @@ export async function generateJson(
|
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
export function createReflectionMap(
|
|
105
|
-
items:
|
|
106
|
-
):
|
|
107
|
-
const map:
|
|
109
|
+
items: TSDDeclarationReflection[] = [],
|
|
110
|
+
): TSDDeclarationReflectionMap {
|
|
111
|
+
const map: TSDDeclarationReflectionMap = {};
|
|
108
112
|
|
|
109
113
|
items.forEach((item) => {
|
|
110
114
|
map[item.id] = item;
|
|
@@ -139,10 +143,10 @@ export function loadPackageJsonAndDocs(
|
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
export function addMetadataToReflections(
|
|
142
|
-
project: JSONOutput.
|
|
146
|
+
project: JSONOutput.DeclarationReflection,
|
|
143
147
|
packageSlug: string,
|
|
144
148
|
urlPrefix: string,
|
|
145
|
-
):
|
|
149
|
+
): TSDDeclarationReflection {
|
|
146
150
|
const permalink = `/${joinUrl(urlPrefix, packageSlug)}`;
|
|
147
151
|
|
|
148
152
|
if (project.children) {
|
|
@@ -170,13 +174,14 @@ export function addMetadataToReflections(
|
|
|
170
174
|
});
|
|
171
175
|
}
|
|
172
176
|
|
|
177
|
+
// @ts-expect-error Not sure why this fails
|
|
173
178
|
return {
|
|
174
179
|
...project,
|
|
175
180
|
permalink: normalizeUrl([permalink]),
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
183
|
|
|
179
|
-
function mergeReflections(base:
|
|
184
|
+
function mergeReflections(base: TSDDeclarationReflection, next: TSDDeclarationReflection) {
|
|
180
185
|
if (Array.isArray(base.children) && Array.isArray(next.children)) {
|
|
181
186
|
base.children.push(...next.children);
|
|
182
187
|
}
|
|
@@ -198,7 +203,7 @@ function mergeReflections(base: JSONOutput.ProjectReflection, next: JSONOutput.P
|
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
205
|
|
|
201
|
-
function sortReflectionGroups(reflections:
|
|
206
|
+
function sortReflectionGroups(reflections: TSDDeclarationReflection[]) {
|
|
202
207
|
reflections.forEach((reflection) => {
|
|
203
208
|
const map = createReflectionMap(reflection.children);
|
|
204
209
|
const sort = (a: number, b: number) => (map[a].name < map[b].name ? -1 : 1);
|
|
@@ -217,7 +222,7 @@ function sortReflectionGroups(reflections: JSONOutput.ProjectReflection[]) {
|
|
|
217
222
|
});
|
|
218
223
|
}
|
|
219
224
|
|
|
220
|
-
function
|
|
225
|
+
function sourceFileMatchesEntryPoint(
|
|
221
226
|
sourceFile: string,
|
|
222
227
|
entryPoint: string,
|
|
223
228
|
{ deep, single }: { deep: boolean; single: boolean },
|
|
@@ -244,11 +249,51 @@ function matchesEntryPoint(
|
|
|
244
249
|
);
|
|
245
250
|
}
|
|
246
251
|
|
|
252
|
+
function modContainsEntryPoint(
|
|
253
|
+
mod: JSONOutput.DeclarationReflection,
|
|
254
|
+
entry: PackageEntryConfig,
|
|
255
|
+
meta: {
|
|
256
|
+
allSourceFiles: Record<string, boolean>;
|
|
257
|
+
packagePath: string;
|
|
258
|
+
packageRoot: string;
|
|
259
|
+
isSinglePackage: boolean;
|
|
260
|
+
isUsingDeepImports: boolean;
|
|
261
|
+
},
|
|
262
|
+
) {
|
|
263
|
+
const relModSources = mod.sources ?? [];
|
|
264
|
+
const relModSourceFile = relModSources.find((sf) => !!sf.fileName)?.fileName ?? '';
|
|
265
|
+
const relEntryPoint = joinUrl(meta.packagePath, entry.path);
|
|
266
|
+
|
|
267
|
+
// Monorepos of 1 package don't have sources, so use the child sources.
|
|
268
|
+
// They also don't use full paths like "package/src/index.ts" and simply use "index.ts",
|
|
269
|
+
// so account for those entry points also.
|
|
270
|
+
if (!relModSourceFile) {
|
|
271
|
+
const absEntryPoint = path.normalize(path.join(meta.packageRoot, entry.path));
|
|
272
|
+
const relEntryPointName = path.basename(relEntryPoint);
|
|
273
|
+
const entryPointInSourceFiles =
|
|
274
|
+
!!meta.allSourceFiles[absEntryPoint] ||
|
|
275
|
+
!!meta.allSourceFiles[relEntryPoint] ||
|
|
276
|
+
(relEntryPointName.startsWith('index.') && !!meta.allSourceFiles[relEntryPointName]);
|
|
277
|
+
|
|
278
|
+
if (entryPointInSourceFiles) {
|
|
279
|
+
return sourceFileMatchesEntryPoint(relEntryPoint, relEntryPoint, {
|
|
280
|
+
deep: meta.isUsingDeepImports,
|
|
281
|
+
single: meta.isSinglePackage,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return sourceFileMatchesEntryPoint(relModSourceFile, relEntryPoint, {
|
|
287
|
+
deep: meta.isUsingDeepImports,
|
|
288
|
+
single: meta.isSinglePackage,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
247
292
|
function extractReflectionModules(
|
|
248
293
|
project: JSONOutput.ProjectReflection,
|
|
249
294
|
isSinglePackage: boolean,
|
|
250
|
-
): JSONOutput.
|
|
251
|
-
const modules: JSONOutput.
|
|
295
|
+
): JSONOutput.DeclarationReflection[] {
|
|
296
|
+
const modules: JSONOutput.DeclarationReflection[] = [];
|
|
252
297
|
|
|
253
298
|
const inheritChildren = () => {
|
|
254
299
|
project.children?.forEach((child) => {
|
|
@@ -267,7 +312,7 @@ function extractReflectionModules(
|
|
|
267
312
|
// No "module" children:
|
|
268
313
|
// - Polyrepos
|
|
269
314
|
// - Monorepos with 1 package
|
|
270
|
-
modules.push(project);
|
|
315
|
+
modules.push(project as unknown as JSONOutput.DeclarationReflection);
|
|
271
316
|
} else {
|
|
272
317
|
// Has "module" children:
|
|
273
318
|
// - Polyrepos with deep imports
|
|
@@ -285,6 +330,28 @@ function extractReflectionModules(
|
|
|
285
330
|
return modules;
|
|
286
331
|
}
|
|
287
332
|
|
|
333
|
+
function buildSourceFileNameMap(
|
|
334
|
+
project: JSONOutput.ProjectReflection,
|
|
335
|
+
modChildren: JSONOutput.DeclarationReflection[],
|
|
336
|
+
) {
|
|
337
|
+
const map: Record<string, boolean> = {};
|
|
338
|
+
const cwd = process.cwd();
|
|
339
|
+
|
|
340
|
+
Object.values(project.symbolIdMap).forEach((symbol) => {
|
|
341
|
+
// absolute
|
|
342
|
+
map[path.normalize(path.join(cwd, symbol.sourceFileName))] = true;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
modChildren.forEach((child) => {
|
|
346
|
+
child.sources?.forEach((sf) => {
|
|
347
|
+
// relative
|
|
348
|
+
map[sf.fileName] = true;
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
return map;
|
|
353
|
+
}
|
|
354
|
+
|
|
288
355
|
export function flattenAndGroupPackages(
|
|
289
356
|
packageConfigs: ResolvedPackageConfig[],
|
|
290
357
|
project: JSONOutput.ProjectReflection,
|
|
@@ -297,20 +364,22 @@ export function flattenAndGroupPackages(
|
|
|
297
364
|
|
|
298
365
|
// Loop through every TypeDoc module and group based on package and entry point
|
|
299
366
|
const packages: Record<string, PackageReflectionGroup> = {};
|
|
300
|
-
const packagesWithDeepImports:
|
|
367
|
+
const packagesWithDeepImports: TSDDeclarationReflection[] = [];
|
|
301
368
|
|
|
302
369
|
modules.forEach((mod) => {
|
|
303
|
-
const
|
|
370
|
+
const allSourceFiles = buildSourceFileNameMap(project, mod.children ?? []);
|
|
304
371
|
|
|
305
372
|
packageConfigs.some((cfg) =>
|
|
306
373
|
Object.entries(cfg.entryPoints).some(([importPath, entry]) => {
|
|
307
|
-
const relEntryPoint = joinUrl(cfg.packagePath, entry.path);
|
|
308
374
|
const isUsingDeepImports = !entry.path.match(/\.tsx?$/);
|
|
309
375
|
|
|
310
376
|
if (
|
|
311
|
-
!
|
|
312
|
-
|
|
313
|
-
|
|
377
|
+
!modContainsEntryPoint(mod, entry, {
|
|
378
|
+
allSourceFiles,
|
|
379
|
+
isSinglePackage,
|
|
380
|
+
isUsingDeepImports,
|
|
381
|
+
packagePath: cfg.packagePath,
|
|
382
|
+
packageRoot: cfg.packageRoot,
|
|
314
383
|
})
|
|
315
384
|
) {
|
|
316
385
|
return false;
|
package/src/plugin/sidebar.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { JSONOutput } from 'typedoc';
|
|
2
2
|
import { normalizeUrl } from '@docusaurus/utils';
|
|
3
3
|
import type {
|
|
4
|
-
DeclarationReflectionMap,
|
|
5
4
|
DocusaurusPluginTypeDocApiOptions,
|
|
6
5
|
PackageReflectionGroup,
|
|
7
6
|
SidebarItem,
|
|
7
|
+
TSDDeclarationReflection,
|
|
8
|
+
TSDDeclarationReflectionMap,
|
|
8
9
|
} from '../types';
|
|
9
10
|
import { removeScopes } from '../utils/links';
|
|
10
11
|
import { createReflectionMap } from './data';
|
|
11
12
|
|
|
12
13
|
export function groupSidebarItems(
|
|
13
|
-
map:
|
|
14
|
+
map: TSDDeclarationReflectionMap,
|
|
14
15
|
groups: JSONOutput.ReflectionGroup[],
|
|
15
16
|
): SidebarItem[] {
|
|
16
17
|
const items: SidebarItem[] = [];
|
|
@@ -65,7 +66,7 @@ export function groupSidebarItems(
|
|
|
65
66
|
return items;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
export function extractReflectionSidebar(pkg:
|
|
69
|
+
export function extractReflectionSidebar(pkg: TSDDeclarationReflection): SidebarItem[] {
|
|
69
70
|
return pkg.groups ? groupSidebarItems(createReflectionMap(pkg.children), pkg.groups) : [];
|
|
70
71
|
}
|
|
71
72
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JSONOutput, TypeDocOptions } from 'typedoc';
|
|
2
|
+
import type { MDXPlugin } from '@docusaurus/mdx-loader';
|
|
2
3
|
import type {
|
|
3
4
|
PropSidebarItem,
|
|
4
5
|
VersionBanner,
|
|
@@ -28,26 +29,10 @@ export interface DocusaurusPluginTypeDocApiOptions
|
|
|
28
29
|
sortPackages?: (a: PackageReflectionGroup, d: PackageReflectionGroup) => number;
|
|
29
30
|
sortSidebar?: (a: string, d: string) => number;
|
|
30
31
|
tsconfigName?: string;
|
|
31
|
-
typedocOptions?: Partial<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| 'disableSources'
|
|
36
|
-
| 'emit'
|
|
37
|
-
| 'excludeExternals'
|
|
38
|
-
| 'excludeInternal'
|
|
39
|
-
| 'excludeNotDocumented'
|
|
40
|
-
| 'excludePrivate'
|
|
41
|
-
| 'excludeProtected'
|
|
42
|
-
| 'excludeTags'
|
|
43
|
-
| 'externalPattern'
|
|
44
|
-
| 'logger'
|
|
45
|
-
| 'logLevel'
|
|
46
|
-
| 'sort'
|
|
47
|
-
| 'treatWarningsAsErrors'
|
|
48
|
-
| 'validation'
|
|
49
|
-
>
|
|
50
|
-
>;
|
|
32
|
+
typedocOptions?: Partial<TypeDocOptions>;
|
|
33
|
+
|
|
34
|
+
remarkPlugins: MDXPlugin[];
|
|
35
|
+
rehypePlugins: MDXPlugin[];
|
|
51
36
|
|
|
52
37
|
// Versioning, based on Docusaurus
|
|
53
38
|
disableVersioning?: boolean;
|
|
@@ -70,6 +55,7 @@ export interface PackageConfig {
|
|
|
70
55
|
|
|
71
56
|
export interface ResolvedPackageConfig {
|
|
72
57
|
entryPoints: Record<string, PackageEntryConfig>;
|
|
58
|
+
packageRoot: string;
|
|
73
59
|
packagePath: string;
|
|
74
60
|
packageSlug: string;
|
|
75
61
|
packageName: string;
|
|
@@ -123,7 +109,7 @@ export interface TOCItem {
|
|
|
123
109
|
export interface PackageReflectionGroupEntry {
|
|
124
110
|
index: boolean;
|
|
125
111
|
label: string;
|
|
126
|
-
reflection:
|
|
112
|
+
reflection: TSDDeclarationReflection;
|
|
127
113
|
urlSlug: string;
|
|
128
114
|
}
|
|
129
115
|
|
|
@@ -143,20 +129,25 @@ export interface ApiMetadata {
|
|
|
143
129
|
nextId?: number;
|
|
144
130
|
}
|
|
145
131
|
|
|
146
|
-
|
|
132
|
+
// TYPEDOC COMPAT
|
|
133
|
+
|
|
134
|
+
export interface TSDReflection extends Omit<JSONOutput.Reflection, 'signatures'>, ApiMetadata {
|
|
135
|
+
signatures: TSDSignatureReflection[];
|
|
136
|
+
// Added by us for convenience
|
|
137
|
+
parentId?: number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface TSDDeclarationReflection
|
|
141
|
+
extends Omit<JSONOutput.DeclarationReflection, 'children' | 'signatures'>,
|
|
142
|
+
ApiMetadata {
|
|
143
|
+
children?: TSDDeclarationReflection[];
|
|
144
|
+
signatures: TSDSignatureReflection[];
|
|
145
|
+
}
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
interface Reflection extends ApiMetadata {
|
|
150
|
-
// Not typed but used in the templates
|
|
151
|
-
declaration?: DeclarationReflection;
|
|
152
|
-
// Added by us for convenience
|
|
153
|
-
parentId?: number;
|
|
154
|
-
}
|
|
147
|
+
export type TSDDeclarationReflectionMap = Record<number, TSDDeclarationReflection>;
|
|
155
148
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
declaration?: DeclarationReflection;
|
|
159
|
-
}
|
|
149
|
+
export interface TSDSignatureReflection extends JSONOutput.SignatureReflection {
|
|
150
|
+
// declaration: TSDDeclarationReflection;
|
|
160
151
|
}
|
|
161
152
|
|
|
162
153
|
declare global {
|