Skip to content

Commit

Permalink
Respect --exclude when expanding globs in entry points
Browse files Browse the repository at this point in the history
Resolves #2376
  • Loading branch information
Gerrit0 committed Sep 4, 2023
1 parent a6823cf commit 653b281
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
49 changes: 39 additions & 10 deletions src/lib/utils/entry-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,15 +71,15 @@ export function getEntryPoints(
case EntryPointStrategy.Resolve:
result = getEntryPointsForPaths(
logger,
expandGlobs(entryPoints, logger),
expandGlobs(entryPoints, exclude, logger),
options,
);
break;

case EntryPointStrategy.Expand:
result = getExpandedEntryPointsForPaths(
logger,
expandGlobs(entryPoints, logger),
expandGlobs(entryPoints, exclude, logger),
options,
);
break;
Expand Down Expand Up @@ -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],
);
Expand All @@ -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) {
Expand Down Expand Up @@ -228,30 +244,43 @@ 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, {
includeDirectories: true,
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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}

Expand Down

0 comments on commit 653b281

Please sign in to comment.