Skip to content

Commit

Permalink
Fix packages outside cwd
Browse files Browse the repository at this point in the history
Resolves #2043
  • Loading branch information
Gerrit0 committed Aug 28, 2022
1 parent 722351d commit 877e1a7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Unreleased

### Bug Fixes

- TypeDoc will now work properly in packages mode when converting packages outside the current working directory, #2043.
- Fixed deprecation warning for `isIdentifierOrPrivateIdentifier`.

## v0.23.11 (2022-08-26)

### Features
Expand Down
6 changes: 3 additions & 3 deletions src/lib/converter/converter.ts
Expand Up @@ -17,7 +17,7 @@ import { convertType } from "./types";
import { ConverterEvents } from "./converter-events";
import { convertSymbol } from "./symbols";
import { createMinimatch, matchesAny } from "../utils/paths";
import type { IMinimatch } from "minimatch";
import type { Minimatch } from "minimatch";
import { hasAllFlags, hasAnyFlag } from "../utils/enum";
import type { DocumentationEntryPoint } from "../utils/entry-point";
import { CommentParserConfig, getComment } from "./comments";
Expand Down Expand Up @@ -49,8 +49,8 @@ export class Converter extends ChildableComponent<

@BindOption("externalPattern")
externalPattern!: string[];
private externalPatternCache?: IMinimatch[];
private excludeCache?: IMinimatch[];
private externalPatternCache?: Minimatch[];
private excludeCache?: Minimatch[];

@BindOption("excludeExternals")
excludeExternals!: boolean;
Expand Down
6 changes: 1 addition & 5 deletions src/lib/converter/utils/nodes.ts
Expand Up @@ -4,11 +4,7 @@ export function isNamedNode(node: ts.Node): node is ts.Node & {
name: ts.Identifier | ts.PrivateIdentifier | ts.ComputedPropertyName;
} {
const name: ts.Node | undefined = (node as any).name;
return (
!!name &&
(ts.isIdentifierOrPrivateIdentifier(name) ||
ts.isComputedPropertyName(name))
);
return !!name && (ts.isMemberName(name) || ts.isComputedPropertyName(name));
}

export function getHeritageTypes(
Expand Down
15 changes: 14 additions & 1 deletion src/lib/utils/entry-point.ts
Expand Up @@ -14,6 +14,7 @@ import type { Logger } from "./loggers";
import type { Options } from "./options";
import { getCommonDirectory, glob, normalizePath } from "./fs";
import { validate } from "./validation";
import { filterMap } from "./array";

/**
* Defines how entry points are interpreted.
Expand Down Expand Up @@ -300,6 +301,17 @@ function expandInputFiles(
return files;
}

function deriveRootDir(packageGlobPaths: string[]): string {
const globs = createMinimatch(packageGlobPaths);
const rootPaths = globs.flatMap((glob) =>
filterMap(glob.set, (set) => {
const stop = set.findIndex((part) => typeof part !== "string");
return stop === -1 ? set.join("/") : set.slice(0, stop).join("/");
})
);
return getCommonDirectory(rootPaths);
}

/**
* Expand the provided packages configuration paths, determining the entry points
* and creating the ts.Programs for any which are found.
Expand All @@ -314,12 +326,13 @@ function getEntryPointsForPackages(
): DocumentationEntryPoint[] | undefined {
const results: DocumentationEntryPoint[] = [];
const exclude = createMinimatch(options.getValue("exclude"));
const rootDir = deriveRootDir(packageGlobPaths);

// packages arguments are workspace tree roots, or glob patterns
// This expands them to leave only leaf packages
const expandedPackages = expandPackages(
logger,
".",
rootDir,
packageGlobPaths,
exclude
);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/package-manifest.ts
Expand Up @@ -5,7 +5,7 @@ import { existsSync } from "fs";

import { readFile, glob } from "./fs";
import type { Logger } from "./loggers";
import type { IMinimatch } from "minimatch";
import type { Minimatch } from "minimatch";
import { matchesAny, nicePath } from "./paths";
import { additionalProperties, Infer, optional, validate } from "./validation";

Expand Down Expand Up @@ -116,7 +116,7 @@ export function expandPackages(
logger: Logger,
packageJsonDir: string,
workspaces: string[],
exclude: IMinimatch[]
exclude: Minimatch[]
): string[] {
// Technically npm and Yarn workspaces don't support recursive nesting,
// however we support the passing of paths to either packages or
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utils/paths.ts
@@ -1,4 +1,4 @@
import { Minimatch, IMinimatch } from "minimatch";
import { Minimatch } from "minimatch";
import { relative } from "path";
import { normalizePath } from "./fs";

Expand All @@ -7,7 +7,7 @@ import { normalizePath } from "./fs";
*
* Handle a few Windows-Unix path gotchas.
*/
export function createMinimatch(patterns: string[]): IMinimatch[] {
export function createMinimatch(patterns: string[]): Minimatch[] {
return patterns.map(
(pattern) =>
new Minimatch(normalizePath(pattern).replace(/^\w:\//, ""), {
Expand All @@ -16,7 +16,7 @@ export function createMinimatch(patterns: string[]): IMinimatch[] {
);
}

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

0 comments on commit 877e1a7

Please sign in to comment.