diff --git a/CHANGELOG.md b/CHANGELOG.md index f0edc1aa2..f835e5d19 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index 1d18365c8..e02a639ae 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -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"; @@ -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; diff --git a/src/lib/converter/utils/nodes.ts b/src/lib/converter/utils/nodes.ts index 4825ca9d4..c0cff59dd 100644 --- a/src/lib/converter/utils/nodes.ts +++ b/src/lib/converter/utils/nodes.ts @@ -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( diff --git a/src/lib/utils/entry-point.ts b/src/lib/utils/entry-point.ts index b571bcb77..cfe49bcbb 100644 --- a/src/lib/utils/entry-point.ts +++ b/src/lib/utils/entry-point.ts @@ -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. @@ -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. @@ -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 ); diff --git a/src/lib/utils/package-manifest.ts b/src/lib/utils/package-manifest.ts index a47f55e4b..ed57cabc1 100644 --- a/src/lib/utils/package-manifest.ts +++ b/src/lib/utils/package-manifest.ts @@ -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"; @@ -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 diff --git a/src/lib/utils/paths.ts b/src/lib/utils/paths.ts index fd6c244d6..24c4d0557 100644 --- a/src/lib/utils/paths.ts +++ b/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"; @@ -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:\//, ""), { @@ -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)); }