@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.
Files changed (138) hide show
  1. package/README.md +27 -5
  2. package/lib/components/AnchorLink.js +15 -10
  3. package/lib/components/AnchorLink.js.map +1 -1
  4. package/lib/components/ApiChangelog.js +9 -11
  5. package/lib/components/ApiChangelog.js.map +1 -1
  6. package/lib/components/ApiDataContext.js +2 -2
  7. package/lib/components/ApiIndex.js +55 -37
  8. package/lib/components/ApiIndex.js.map +1 -1
  9. package/lib/components/ApiItem.js +33 -29
  10. package/lib/components/ApiItem.js.map +1 -1
  11. package/lib/components/ApiItemLayout.js +49 -27
  12. package/lib/components/ApiItemLayout.js.map +1 -1
  13. package/lib/components/ApiPage.js +18 -10
  14. package/lib/components/ApiPage.js.map +1 -1
  15. package/lib/components/Breadcrumb.js +27 -14
  16. package/lib/components/Breadcrumb.js.map +1 -1
  17. package/lib/components/Comment.js +24 -18
  18. package/lib/components/Comment.js.map +1 -1
  19. package/lib/components/CommentBadges.js +8 -11
  20. package/lib/components/CommentBadges.js.map +1 -1
  21. package/lib/components/DefaultValue.js +20 -20
  22. package/lib/components/DefaultValue.js.map +1 -1
  23. package/lib/components/Flags.js +9 -11
  24. package/lib/components/Flags.js.map +1 -1
  25. package/lib/components/Footer.js +11 -12
  26. package/lib/components/Footer.js.map +1 -1
  27. package/lib/components/Hierarchy.js +15 -16
  28. package/lib/components/Hierarchy.js.map +1 -1
  29. package/lib/components/Icon.js +2 -6
  30. package/lib/components/Icon.js.map +1 -1
  31. package/lib/components/Index.js +84 -62
  32. package/lib/components/Index.js.map +1 -1
  33. package/lib/components/Markdown.js +80 -66
  34. package/lib/components/Markdown.js.map +1 -1
  35. package/lib/components/Member.js +28 -28
  36. package/lib/components/Member.js.map +1 -1
  37. package/lib/components/MemberDeclaration.js +51 -42
  38. package/lib/components/MemberDeclaration.js.map +1 -1
  39. package/lib/components/MemberGetterSetter.js +50 -40
  40. package/lib/components/MemberGetterSetter.js.map +1 -1
  41. package/lib/components/MemberReference.js +27 -16
  42. package/lib/components/MemberReference.js.map +1 -1
  43. package/lib/components/MemberSignatureBody.js +57 -45
  44. package/lib/components/MemberSignatureBody.js.map +1 -1
  45. package/lib/components/MemberSignatureTitle.js +48 -27
  46. package/lib/components/MemberSignatureTitle.js.map +1 -1
  47. package/lib/components/MemberSignatures.js +46 -38
  48. package/lib/components/MemberSignatures.js.map +1 -1
  49. package/lib/components/MemberSources.js +18 -15
  50. package/lib/components/MemberSources.js.map +1 -1
  51. package/lib/components/Members.js +32 -31
  52. package/lib/components/Members.js.map +1 -1
  53. package/lib/components/MembersGroup.js +24 -22
  54. package/lib/components/MembersGroup.js.map +1 -1
  55. package/lib/components/Parameter.js +139 -109
  56. package/lib/components/Parameter.js.map +1 -1
  57. package/lib/components/Reflection.js +113 -90
  58. package/lib/components/Reflection.js.map +1 -1
  59. package/lib/components/SourceLink.js +12 -13
  60. package/lib/components/SourceLink.js.map +1 -1
  61. package/lib/components/Type.js +320 -206
  62. package/lib/components/Type.js.map +1 -1
  63. package/lib/components/TypeAndParent.js +11 -10
  64. package/lib/components/TypeAndParent.js.map +1 -1
  65. package/lib/components/TypeParameters.js +23 -20
  66. package/lib/components/TypeParameters.js.map +1 -1
  67. package/lib/components/TypeParametersGeneric.js +17 -16
  68. package/lib/components/TypeParametersGeneric.js.map +1 -1
  69. package/lib/components/VersionBanner.js +21 -9
  70. package/lib/components/VersionBanner.js.map +1 -1
  71. package/lib/hooks/useBreadcrumbs.js +2 -2
  72. package/lib/hooks/useGitRefName.js +2 -2
  73. package/lib/hooks/useMinimalLayout.js +2 -2
  74. package/lib/hooks/useReflection.js +10 -6
  75. package/lib/hooks/useReflection.js.map +1 -1
  76. package/lib/hooks/useReflectionMap.js +2 -2
  77. package/lib/index.js +62 -25
  78. package/lib/index.js.map +1 -1
  79. package/lib/plugin/data.js +61 -18
  80. package/lib/plugin/data.js.map +1 -1
  81. package/lib/plugin/version.js +5 -4
  82. package/lib/plugin/version.js.map +1 -1
  83. package/lib/utils/helpers.js +8 -0
  84. package/lib/utils/helpers.js.map +1 -0
  85. package/lib/utils/hierarchy.js +6 -3
  86. package/lib/utils/hierarchy.js.map +1 -1
  87. package/lib/utils/icons.js +2 -5
  88. package/lib/utils/icons.js.map +1 -1
  89. package/lib/utils/markdown.js +5 -7
  90. package/lib/utils/markdown.js.map +1 -1
  91. package/package.json +17 -14
  92. package/src/components/AnchorLink.tsx +6 -3
  93. package/src/components/ApiChangelog.tsx +0 -1
  94. package/src/components/ApiDataContext.ts +2 -2
  95. package/src/components/ApiIndex.tsx +1 -1
  96. package/src/components/ApiItem.tsx +18 -20
  97. package/src/components/ApiItemLayout.tsx +1 -2
  98. package/src/components/ApiPage.tsx +18 -13
  99. package/src/components/Breadcrumb.tsx +2 -3
  100. package/src/components/Comment.tsx +3 -4
  101. package/src/components/CommentBadges.tsx +0 -1
  102. package/src/components/DefaultValue.tsx +0 -1
  103. package/src/components/Flags.tsx +1 -1
  104. package/src/components/Footer.tsx +0 -2
  105. package/src/components/Hierarchy.tsx +0 -1
  106. package/src/components/Icon.tsx +2 -3
  107. package/src/components/Index.tsx +14 -19
  108. package/src/components/Markdown.tsx +54 -25
  109. package/src/components/Member.tsx +7 -6
  110. package/src/components/MemberDeclaration.tsx +7 -7
  111. package/src/components/MemberGetterSetter.tsx +6 -6
  112. package/src/components/MemberReference.tsx +4 -4
  113. package/src/components/MemberSignatureBody.tsx +5 -5
  114. package/src/components/MemberSignatureTitle.tsx +11 -9
  115. package/src/components/MemberSignatures.tsx +5 -5
  116. package/src/components/MemberSources.tsx +3 -5
  117. package/src/components/Members.tsx +3 -4
  118. package/src/components/MembersGroup.tsx +1 -2
  119. package/src/components/Parameter.tsx +7 -12
  120. package/src/components/README.md +1 -1
  121. package/src/components/Reflection.tsx +7 -10
  122. package/src/components/SourceLink.tsx +0 -2
  123. package/src/components/Type.tsx +34 -22
  124. package/src/components/TypeAndParent.tsx +0 -1
  125. package/src/components/TypeParameters.tsx +0 -1
  126. package/src/components/TypeParametersGeneric.tsx +3 -3
  127. package/src/components/VersionBanner.tsx +1 -1
  128. package/src/hooks/useReflection.ts +11 -4
  129. package/src/hooks/useReflectionMap.ts +2 -2
  130. package/src/index.ts +92 -39
  131. package/src/plugin/data.ts +123 -54
  132. package/src/plugin/sidebar.ts +4 -3
  133. package/src/types.ts +24 -33
  134. package/src/utils/helpers.ts +4 -0
  135. package/src/utils/hierarchy.ts +11 -7
  136. package/src/utils/icons.ts +2 -3
  137. package/src/utils/markdown.ts +10 -7
  138. 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 { JSONOutput } from 'typedoc';
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 ?? 'src/index.ts',
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: await extractSidebar(
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
- } as PropVersionMetadata),
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 optionsContextData: ApiOptions = {
287
- banner,
288
- breadcrumbs,
289
- gitRefName,
290
- minimal,
291
- pluginId,
292
- scopes: removeScopes,
293
- };
294
- const optionsData = await createData('options.json', JSON.stringify(optionsContextData));
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: JSONOutput.Reflection,
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 `DocPage` shows a page not found
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
- addRoute({
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: path.join(__dirname, './components/ApiPage.js'),
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
- options: optionsData,
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
- path.join(options.projectRoot, cfg.packagePath, options.readmeName),
388
- path.join(options.projectRoot, cfg.packagePath, options.changelogName),
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
- staticDir: path.join(context.siteDir, 'static'),
404
- // Since this isnt a doc/blog page, we can get
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'),
@@ -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 app = new TypeDoc.Application();
56
- const tsconfig = path.join(projectRoot, options.tsconfigName!);
57
-
58
- app.options.addReader(new TypeDoc.TSConfigReader());
59
- app.options.addReader(new TypeDoc.TypeDocReader());
60
-
61
- app.bootstrap({
62
- skipErrorChecking: true,
63
- // Only emit when using project references
64
- emit: shouldEmit(projectRoot, tsconfig),
65
- // Only document the public API by default
66
- excludeExternals: true,
67
- excludeInternal: true,
68
- excludePrivate: true,
69
- excludeProtected: true,
70
- // Enable verbose logging when debugging
71
- logLevel: options.debug ? 'Verbose' : 'Info',
72
- inlineTags: [
73
- '@link',
74
- '@inheritDoc',
75
- '@label',
76
- '@linkcode',
77
- '@linkplain',
78
- '@apilink',
79
- '@doclink',
80
- ] as `@${string}`[],
81
- ...options.typedocOptions,
82
- // Control how config and packages are detected
83
- tsconfig,
84
- entryPoints: entryPoints.map((ep) => path.join(projectRoot, ep)),
85
- entryPointStrategy: 'expand',
86
- exclude: options.exclude,
87
- // We use a fake category title so that we can fallback to the parent group
88
- defaultCategory: 'CATEGORY',
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: JSONOutput.DeclarationReflection[] = [],
106
- ): DeclarationReflectionMap {
107
- const map: DeclarationReflectionMap = {};
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.ProjectReflection,
146
+ project: JSONOutput.DeclarationReflection,
143
147
  packageSlug: string,
144
148
  urlPrefix: string,
145
- ): JSONOutput.ProjectReflection {
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: JSONOutput.ProjectReflection, next: JSONOutput.ProjectReflection) {
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: JSONOutput.ProjectReflection[]) {
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 matchesEntryPoint(
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.ProjectReflection[] {
251
- const modules: JSONOutput.ProjectReflection[] = [];
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: JSONOutput.ProjectReflection[] = [];
367
+ const packagesWithDeepImports: TSDDeclarationReflection[] = [];
301
368
 
302
369
  modules.forEach((mod) => {
303
- const relSourceFile = mod.sources?.[0]?.fileName ?? '';
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
- !matchesEntryPoint(relSourceFile, relEntryPoint, {
312
- deep: isUsingDeepImports,
313
- single: isSinglePackage,
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;
@@ -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: DeclarationReflectionMap,
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: JSONOutput.ProjectReflection): SidebarItem[] {
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
- Pick<
33
- TypeDocOptions,
34
- | 'commentStyle'
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: JSONOutput.ProjectReflection;
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
- export type DeclarationReflectionMap = Record<number, JSONOutput.DeclarationReflection>;
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
- declare module 'typedoc/dist/lib/serialization/schema' {
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
- interface Type {
157
- // Not typed but used in the templates
158
- declaration?: DeclarationReflection;
159
- }
149
+ export interface TSDSignatureReflection extends JSONOutput.SignatureReflection {
150
+ // declaration: TSDDeclarationReflection;
160
151
  }
161
152
 
162
153
  declare global {
@@ -0,0 +1,4 @@
1
+ export function escapeMdx(value: string | null): string | null {
2
+ // New values are unicode!
3
+ return value?.replace('<', '<').replace('>', '>') ?? null;
4
+ }