Skip to content

Commit 877e1a7

Browse files
committed
Fix packages outside cwd
Resolves #2043
1 parent 722351d commit 877e1a7

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- TypeDoc will now work properly in packages mode when converting packages outside the current working directory, #2043.
6+
- Fixed deprecation warning for `isIdentifierOrPrivateIdentifier`.
7+
38
## v0.23.11 (2022-08-26)
49

510
### Features

src/lib/converter/converter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { convertType } from "./types";
1717
import { ConverterEvents } from "./converter-events";
1818
import { convertSymbol } from "./symbols";
1919
import { createMinimatch, matchesAny } from "../utils/paths";
20-
import type { IMinimatch } from "minimatch";
20+
import type { Minimatch } from "minimatch";
2121
import { hasAllFlags, hasAnyFlag } from "../utils/enum";
2222
import type { DocumentationEntryPoint } from "../utils/entry-point";
2323
import { CommentParserConfig, getComment } from "./comments";
@@ -49,8 +49,8 @@ export class Converter extends ChildableComponent<
4949

5050
@BindOption("externalPattern")
5151
externalPattern!: string[];
52-
private externalPatternCache?: IMinimatch[];
53-
private excludeCache?: IMinimatch[];
52+
private externalPatternCache?: Minimatch[];
53+
private excludeCache?: Minimatch[];
5454

5555
@BindOption("excludeExternals")
5656
excludeExternals!: boolean;

src/lib/converter/utils/nodes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ export function isNamedNode(node: ts.Node): node is ts.Node & {
44
name: ts.Identifier | ts.PrivateIdentifier | ts.ComputedPropertyName;
55
} {
66
const name: ts.Node | undefined = (node as any).name;
7-
return (
8-
!!name &&
9-
(ts.isIdentifierOrPrivateIdentifier(name) ||
10-
ts.isComputedPropertyName(name))
11-
);
7+
return !!name && (ts.isMemberName(name) || ts.isComputedPropertyName(name));
128
}
139

1410
export function getHeritageTypes(

src/lib/utils/entry-point.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { Logger } from "./loggers";
1414
import type { Options } from "./options";
1515
import { getCommonDirectory, glob, normalizePath } from "./fs";
1616
import { 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
);

src/lib/utils/package-manifest.ts

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

66
import { readFile, glob } from "./fs";
77
import type { Logger } from "./loggers";
8-
import type { IMinimatch } from "minimatch";
8+
import type { Minimatch } from "minimatch";
99
import { matchesAny, nicePath } from "./paths";
1010
import { additionalProperties, Infer, optional, validate } from "./validation";
1111

@@ -116,7 +116,7 @@ export function expandPackages(
116116
logger: Logger,
117117
packageJsonDir: string,
118118
workspaces: string[],
119-
exclude: IMinimatch[]
119+
exclude: Minimatch[]
120120
): string[] {
121121
// Technically npm and Yarn workspaces don't support recursive nesting,
122122
// however we support the passing of paths to either packages or

src/lib/utils/paths.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Minimatch, IMinimatch } from "minimatch";
1+
import { Minimatch } from "minimatch";
22
import { relative } from "path";
33
import { normalizePath } from "./fs";
44

@@ -7,7 +7,7 @@ import { normalizePath } from "./fs";
77
*
88
* Handle a few Windows-Unix path gotchas.
99
*/
10-
export function createMinimatch(patterns: string[]): IMinimatch[] {
10+
export function createMinimatch(patterns: string[]): Minimatch[] {
1111
return patterns.map(
1212
(pattern) =>
1313
new Minimatch(normalizePath(pattern).replace(/^\w:\//, ""), {
@@ -16,7 +16,7 @@ export function createMinimatch(patterns: string[]): IMinimatch[] {
1616
);
1717
}
1818

19-
export function matchesAny(patterns: readonly IMinimatch[], path: string) {
19+
export function matchesAny(patterns: readonly Minimatch[], path: string) {
2020
const normPath = normalizePath(path).replace(/^\w:\//, "");
2121
return patterns.some((pat) => pat.match(normPath));
2222
}

0 commit comments

Comments
 (0)