@@ -14,6 +14,7 @@ import type { Logger } from "./loggers";
1414import type { Options } from "./options" ;
1515import { getCommonDirectory , glob , normalizePath } from "./fs" ;
1616import { validate } from "./validation" ;
17+ import { filterMap } from "./array" ;
1718
1819/**
1920 * Defines how entry points are interpreted.
@@ -300,6 +301,17 @@ function expandInputFiles(
300301 return files ;
301302}
302303
304+ function deriveRootDir ( packageGlobPaths : string [ ] ) : string {
305+ const globs = createMinimatch ( packageGlobPaths ) ;
306+ const rootPaths = globs . flatMap ( ( glob ) =>
307+ filterMap ( glob . set , ( set ) => {
308+ const stop = set . findIndex ( ( part ) => typeof part !== "string" ) ;
309+ return stop === - 1 ? set . join ( "/" ) : set . slice ( 0 , stop ) . join ( "/" ) ;
310+ } )
311+ ) ;
312+ return getCommonDirectory ( rootPaths ) ;
313+ }
314+
303315/**
304316 * Expand the provided packages configuration paths, determining the entry points
305317 * and creating the ts.Programs for any which are found.
@@ -314,12 +326,13 @@ function getEntryPointsForPackages(
314326) : DocumentationEntryPoint [ ] | undefined {
315327 const results : DocumentationEntryPoint [ ] = [ ] ;
316328 const exclude = createMinimatch ( options . getValue ( "exclude" ) ) ;
329+ const rootDir = deriveRootDir ( packageGlobPaths ) ;
317330
318331 // packages arguments are workspace tree roots, or glob patterns
319332 // This expands them to leave only leaf packages
320333 const expandedPackages = expandPackages (
321334 logger ,
322- "." ,
335+ rootDir ,
323336 packageGlobPaths ,
324337 exclude
325338 ) ;
0 commit comments