Skip to content

Commit f66dbd5

Browse files
committed
Add support for filtering packages with --exclude
Resolves #1959
1 parent 04da924 commit f66dbd5

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- TypeDoc no longer ignores project references if `--entryPointStrategy Packages` is set, #1976.
66

7+
### Features
8+
9+
- The `--exclude` option will now be respected by `--entryPointStrategy Packages` and can be used to exclude package directories, #1959.
10+
711
## v0.23.3 (2022-07-01)
812

913
### Bug Fixes

src/lib/utils/entry-point.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,16 @@ function getEntryPointsForPackages(
308308
options: Options
309309
): DocumentationEntryPoint[] | undefined {
310310
const results: DocumentationEntryPoint[] = [];
311+
const exclude = createMinimatch(options.getValue("exclude"));
311312

312313
// packages arguments are workspace tree roots, or glob patterns
313314
// This expands them to leave only leaf packages
314-
const expandedPackages = expandPackages(logger, ".", packageGlobPaths);
315+
const expandedPackages = expandPackages(
316+
logger,
317+
".",
318+
packageGlobPaths,
319+
exclude
320+
);
315321
for (const packagePath of expandedPackages) {
316322
const packageJsonPath = resolve(packagePath, "package.json");
317323
const packageJson = loadPackageManifest(logger, packageJsonPath);

src/lib/utils/package-manifest.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { existsSync } from "fs";
55

66
import { readFile, glob } from "./fs";
77
import type { Logger } from "./loggers";
8+
import type { IMinimatch } from "minimatch";
9+
import { matchesAny } from "./paths";
810

911
/**
1012
* Helper for the TS type system to understand hasOwnProperty
@@ -71,7 +73,8 @@ function getPackagePaths(
7173
export function expandPackages(
7274
logger: Logger,
7375
packageJsonDir: string,
74-
workspaces: string[]
76+
workspaces: string[],
77+
exclude: IMinimatch[]
7578
): string[] {
7679
// Technically npm and Yarn workspaces don't support recursive nesting,
7780
// however we support the passing of paths to either packages or
@@ -84,6 +87,10 @@ export function expandPackages(
8487
resolve(packageJsonDir)
8588
);
8689
return globbedPackageJsonPaths.flatMap((packageJsonPath) => {
90+
if (matchesAny(exclude, dirname(packageJsonPath))) {
91+
return [];
92+
}
93+
8794
const packageJson = loadPackageManifest(logger, packageJsonPath);
8895
if (packageJson === undefined) {
8996
logger.error(`Failed to load ${packageJsonPath}`);
@@ -98,7 +105,8 @@ export function expandPackages(
98105
return expandPackages(
99106
logger,
100107
dirname(packageJsonPath),
101-
packagePaths
108+
packagePaths,
109+
exclude
102110
);
103111
});
104112
});

src/test/packages.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
import { tempdirProject } from "@typestrong/fs-fixture-builder";
1111
import { TestLogger } from "./TestLogger";
12+
import { createMinimatch } from "../lib/utils/paths";
1213

1314
describe("Packages support", () => {
1415
let project: ReturnType<typeof tempdirProject>;
@@ -73,9 +74,25 @@ describe("Packages support", () => {
7374
});
7475
project.addJsonFile("packages/foo/tsconfig.json", childTsconfig);
7576

77+
// Ign, ignored package
78+
project.addFile("packages/ign/dist/index.js", "module.exports = 123");
79+
project.addFile("packages/ign/index.ts", "export function ign() {}");
80+
project.addJsonFile("packages/ign/package.json", {
81+
name: "typedoc-multi-package-ign",
82+
version: "1.0.0",
83+
main: "dist/index",
84+
typedocMain: "index.ts",
85+
});
86+
project.addJsonFile("packages/ign/tsconfig.json", childTsconfig);
87+
7688
project.write();
7789
const logger = new TestLogger();
78-
const packages = expandPackages(logger, project.cwd, [project.cwd]);
90+
const packages = expandPackages(
91+
logger,
92+
project.cwd,
93+
[project.cwd],
94+
createMinimatch(["**/ign"])
95+
);
7996

8097
equal(
8198
packages,
@@ -134,7 +151,7 @@ describe("Packages support", () => {
134151
project.write();
135152

136153
const logger = new TestLogger();
137-
const packages = expandPackages(logger, project.cwd, [project.cwd]);
154+
const packages = expandPackages(logger, project.cwd, [project.cwd], []);
138155

139156
logger.expectNoOtherMessages();
140157
equal(packages, [normalizePath(project.cwd)]);
@@ -169,7 +186,7 @@ describe("Packages support", () => {
169186
project.write();
170187

171188
const logger = new TestLogger();
172-
const packages = expandPackages(logger, project.cwd, [project.cwd]);
189+
const packages = expandPackages(logger, project.cwd, [project.cwd], []);
173190

174191
logger.expectNoOtherMessages();
175192
equal(packages, [normalizePath(project.cwd)]);

0 commit comments

Comments
 (0)