@@ -6,6 +6,7 @@ import ts from 'typescript';
6
6
import { normalizeUrl } from '@docusaurus/utils' ;
7
7
import type {
8
8
DocusaurusPluginTypeDocApiOptions ,
9
+ PackageEntryConfig ,
9
10
PackageReflectionGroup ,
10
11
ResolvedPackageConfig ,
11
12
TSDDeclarationReflection ,
@@ -221,7 +222,7 @@ function sortReflectionGroups(reflections: TSDDeclarationReflection[]) {
221
222
} ) ;
222
223
}
223
224
224
- function matchesEntryPoint (
225
+ function sourceFileMatchesEntryPoint (
225
226
sourceFile : string ,
226
227
entryPoint : string ,
227
228
{ deep, single } : { deep : boolean ; single : boolean } ,
@@ -248,6 +249,43 @@ function matchesEntryPoint(
248
249
) ;
249
250
}
250
251
252
+ function modContainsEntryPoint (
253
+ mod : JSONOutput . DeclarationReflection ,
254
+ entry : PackageEntryConfig ,
255
+ meta : {
256
+ allSourceFiles : Record < string , boolean > ;
257
+ packagePath : string ;
258
+ isSinglePackage : boolean ;
259
+ isUsingDeepImports : boolean ;
260
+ } ,
261
+ ) {
262
+ const relModSources = mod . sources ?? [ ] ;
263
+ const relModSourceFile = relModSources . find ( ( sf ) => ! ! sf . fileName ) ?. fileName ?? '' ;
264
+ const relEntryPoint = joinUrl ( meta . packagePath , entry . path ) ;
265
+
266
+ // Monorepos of 1 package don't have sources, so use the child sources.
267
+ // They also don't use full paths like "package/src/index.ts" and simply use "index.ts",
268
+ // so account for those entry points also.
269
+ if ( ! relModSourceFile ) {
270
+ const relEntryPointName = path . basename ( relEntryPoint ) ;
271
+ const relEntryPointInSourceFiles =
272
+ ! ! meta . allSourceFiles [ relEntryPoint ] ||
273
+ ( relEntryPointName . startsWith ( 'index.' ) && ! ! meta . allSourceFiles [ relEntryPointName ] ) ;
274
+
275
+ if ( relEntryPointInSourceFiles ) {
276
+ return sourceFileMatchesEntryPoint ( relEntryPoint , relEntryPoint , {
277
+ deep : meta . isUsingDeepImports ,
278
+ single : meta . isSinglePackage ,
279
+ } ) ;
280
+ }
281
+ }
282
+
283
+ return sourceFileMatchesEntryPoint ( relModSourceFile , relEntryPoint , {
284
+ deep : meta . isUsingDeepImports ,
285
+ single : meta . isSinglePackage ,
286
+ } ) ;
287
+ }
288
+
251
289
function extractReflectionModules (
252
290
project : JSONOutput . ProjectReflection ,
253
291
isSinglePackage : boolean ,
@@ -289,6 +327,18 @@ function extractReflectionModules(
289
327
return modules ;
290
328
}
291
329
330
+ function buildSourceFileNameMap ( modChildren : JSONOutput . DeclarationReflection [ ] ) {
331
+ const map : Record < string , boolean > = { } ;
332
+
333
+ modChildren . forEach ( ( child ) => {
334
+ child . sources ?. forEach ( ( sf ) => {
335
+ map [ sf . fileName ] = true ;
336
+ } ) ;
337
+ } ) ;
338
+
339
+ return map ;
340
+ }
341
+
292
342
export function flattenAndGroupPackages (
293
343
packageConfigs : ResolvedPackageConfig [ ] ,
294
344
project : JSONOutput . ProjectReflection ,
@@ -304,19 +354,18 @@ export function flattenAndGroupPackages(
304
354
const packagesWithDeepImports : TSDDeclarationReflection [ ] = [ ] ;
305
355
306
356
modules . forEach ( ( mod ) => {
307
- // Monorepos of 1 package don't have sources, so use the child sources
308
- const relSources = mod . sources ?? mod . children ?. [ 0 ] . sources ?? [ ] ;
309
- const relSourceFile = relSources . find ( ( sf ) => ! ! sf . fileName ) ?. fileName ?? '' ;
357
+ const allSourceFiles = buildSourceFileNameMap ( mod . children ?? [ ] ) ;
310
358
311
359
packageConfigs . some ( ( cfg ) =>
312
360
Object . entries ( cfg . entryPoints ) . some ( ( [ importPath , entry ] ) => {
313
- const relEntryPoint = joinUrl ( cfg . packagePath , entry . path ) ;
314
361
const isUsingDeepImports = ! entry . path . match ( / \. t s x ? $ / ) ;
315
362
316
363
if (
317
- ! matchesEntryPoint ( relSourceFile , relEntryPoint , {
318
- deep : isUsingDeepImports ,
319
- single : isSinglePackage ,
364
+ ! modContainsEntryPoint ( mod , entry , {
365
+ allSourceFiles,
366
+ isSinglePackage,
367
+ isUsingDeepImports,
368
+ packagePath : cfg . packagePath ,
320
369
} )
321
370
) {
322
371
return false ;
0 commit comments