From 653b2814f8c0dd8cc09d580f3c1aa19994be6b71 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Mon, 4 Sep 2023 11:54:40 -0600 Subject: [PATCH] Respect --exclude when expanding globs in entry points Resolves #2376 --- CHANGELOG.md | 1 + src/lib/utils/entry-point.ts | 49 ++++++++++++++++++++++++++++-------- src/lib/utils/jsx.ts | 2 +- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3162b08b3..0678e9aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Improved support for optional names within JSDoc types, #2384. - Fixed duplicate rendering of reflection flags on signature parameters, #2385. - TypeDoc now handles the `intrinsic` keyword if TS intrinsic types are included in documentation. +- `--exclude` is now respected when expanding globs in entry points, #2376. ### Thanks! diff --git a/src/lib/utils/entry-point.ts b/src/lib/utils/entry-point.ts index a3f550def..df77ea8bd 100644 --- a/src/lib/utils/entry-point.ts +++ b/src/lib/utils/entry-point.ts @@ -57,6 +57,7 @@ export function getEntryPoints( } const entryPoints = options.getValue("entryPoints"); + const exclude = options.getValue("exclude"); // May be set explicitly to be an empty array to only include a readme for a package // See #2264 @@ -70,7 +71,7 @@ export function getEntryPoints( case EntryPointStrategy.Resolve: result = getEntryPointsForPaths( logger, - expandGlobs(entryPoints, logger), + expandGlobs(entryPoints, exclude, logger), options, ); break; @@ -78,7 +79,7 @@ export function getEntryPoints( case EntryPointStrategy.Expand: result = getExpandedEntryPointsForPaths( logger, - expandGlobs(entryPoints, logger), + expandGlobs(entryPoints, exclude, logger), options, ); break; @@ -108,17 +109,23 @@ export function getWatchEntryPoints( let result: DocumentationEntryPoint[] | undefined; const entryPoints = options.getValue("entryPoints"); - switch (options.getValue("entryPointStrategy")) { + const exclude = options.getValue("exclude"); + const strategy = options.getValue("entryPointStrategy"); + + switch (strategy) { case EntryPointStrategy.Resolve: - result = getEntryPointsForPaths(logger, entryPoints, options, [ - program, - ]); + result = getEntryPointsForPaths( + logger, + expandGlobs(entryPoints, exclude, logger), + options, + [program], + ); break; case EntryPointStrategy.Expand: result = getExpandedEntryPointsForPaths( logger, - entryPoints, + expandGlobs(entryPoints, exclude, logger), options, [program], ); @@ -129,6 +136,15 @@ export function getWatchEntryPoints( "Watch mode does not support 'packages' style entry points.", ); break; + + case EntryPointStrategy.Merge: + logger.error( + "Watch mode does not support 'merge' style entry points.", + ); + break; + + default: + assertNever(strategy); } if (result && result.length === 0) { @@ -228,7 +244,9 @@ export function getExpandedEntryPointsForPaths( ); } -function expandGlobs(inputFiles: string[], logger: Logger) { +function expandGlobs(inputFiles: string[], exclude: string[], logger: Logger) { + const excludePatterns = createMinimatch(exclude); + const base = deriveRootDir(inputFiles); const result = inputFiles.flatMap((entry) => { const result = glob(entry, base, { @@ -236,22 +254,33 @@ function expandGlobs(inputFiles: string[], logger: Logger) { followSymlinks: true, }); + const filtered = result.filter( + (file) => file === entry || !matchesAny(excludePatterns, file), + ); + if (result.length === 0) { logger.warn( `The entrypoint glob ${nicePath( entry, )} did not match any files.`, ); + } else if (filtered.length === 0) { + logger.warn( + `The entrypoint glob ${nicePath( + entry, + )} did not match any files after applying exclude patterns.`, + ); } else { logger.verbose( - `Expanded ${nicePath(entry)} to:\n\t${result + `Expanded ${nicePath(entry)} to:\n\t${filtered .map(nicePath) .join("\n\t")}`, ); } - return result; + return filtered; }); + return result; } diff --git a/src/lib/utils/jsx.ts b/src/lib/utils/jsx.ts index 861a59d59..ffe06102e 100644 --- a/src/lib/utils/jsx.ts +++ b/src/lib/utils/jsx.ts @@ -108,7 +108,7 @@ export function setRenderSettings(options: { pretty: boolean }) { export const renderElement = function renderElement( element: JsxElement | null | undefined, ): string { - if (!element) { + if (!element || typeof element === "boolean") { return ""; }