Skip to content

Commit 1e96a2d

Browse files
committed
Improve error messaging for missing entry points
Resolves #2242
1 parent 4970a4b commit 1e96a2d

File tree

6 files changed

+112
-31
lines changed

6 files changed

+112
-31
lines changed

CHANGELOG.md

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

3+
### Features
4+
5+
- Improved error messaging if a provided entry point could not be converted into a documented module reflection, #2242.
6+
- API: Added support for `g`, `circle`, `ellipse`, `polygon`, and `polyline` svg elements, #2259.
7+
8+
### Bug Fixes
9+
10+
- Fixed an infinite loop if more than one entry point was provided, and all entry points were the same.
11+
12+
### Thanks!
13+
14+
- @FlippieCoetser
15+
316
## v0.24.5 (2023-04-22)
417

518
### Features

src/lib/application.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import { Converter } from "./converter/index";
55
import { Renderer } from "./output/renderer";
66
import { Deserializer, JSONOutput, Serializer } from "./serialization";
77
import type { ProjectReflection } from "./models/index";
8-
import {
9-
Logger,
10-
ConsoleLogger,
11-
loadPlugins,
12-
writeFile,
13-
normalizePath,
14-
} from "./utils/index";
8+
import { Logger, ConsoleLogger, loadPlugins, writeFile } from "./utils/index";
159

1610
import {
1711
AbstractComponent,
@@ -591,17 +585,25 @@ export class Application extends ChildableComponent<
591585
const start = Date.now();
592586

593587
const rootDir = deriveRootDir(this.entryPoints);
594-
this.logger.verbose(
595-
`Derived root dir is ${rootDir}, will expand ${this.entryPoints
596-
.map(normalizePath)
597-
.join(", ")}`
598-
);
599-
const entryPoints = this.entryPoints.flatMap((entry) =>
600-
glob(entry, rootDir)
601-
);
602-
this.logger.verbose(
603-
`Merging entry points:\n\t${entryPoints.map(nicePath).join("\n\t")}`
604-
);
588+
const entryPoints = this.entryPoints.flatMap((entry) => {
589+
const result = glob(entry, rootDir);
590+
591+
if (result.length === 0) {
592+
this.logger.warn(
593+
`The entrypoint glob ${nicePath(
594+
entry
595+
)} did not match any files.`
596+
);
597+
} else {
598+
this.logger.verbose(
599+
`Expanded ${nicePath(entry)} to:\n\t${result
600+
.map(nicePath)
601+
.join("\n\t")}`
602+
);
603+
}
604+
605+
return result;
606+
});
605607

606608
if (entryPoints.length < 1) {
607609
this.logger.error("No entry points provided to merge.");

src/lib/utils/entry-point.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { createMinimatch, matchesAny, nicePath, normalizePath } from "./paths";
1313
import type { Logger } from "./loggers";
1414
import type { Options } from "./options";
15-
import { deriveRootDir, glob } from "./fs";
15+
import { deriveRootDir, glob, isDir } from "./fs";
1616
import { assertNever } from "./general";
1717

1818
/**
@@ -64,21 +64,26 @@ export function getEntryPoints(
6464
): DocumentationEntryPoint[] | undefined {
6565
const entryPoints = options.getValue("entryPoints");
6666

67+
if (entryPoints.length === 0) {
68+
logger.error("No entry points were provided.");
69+
return;
70+
}
71+
6772
let result: DocumentationEntryPoint[] | undefined;
6873
const strategy = options.getValue("entryPointStrategy");
6974
switch (strategy) {
7075
case EntryPointStrategy.Resolve:
7176
result = getEntryPointsForPaths(
7277
logger,
73-
expandGlobs(entryPoints),
78+
expandGlobs(entryPoints, logger),
7479
options
7580
);
7681
break;
7782

7883
case EntryPointStrategy.Expand:
7984
result = getExpandedEntryPointsForPaths(
8085
logger,
81-
expandGlobs(entryPoints),
86+
expandGlobs(entryPoints, logger),
8287
options
8388
);
8489
break;
@@ -101,9 +106,7 @@ export function getEntryPoints(
101106
}
102107

103108
if (result && result.length === 0) {
104-
logger.error(
105-
"Unable to find any entry points. Make sure TypeDoc can find your tsconfig"
106-
);
109+
logger.error("Unable to find any entry points. See previous warnings.");
107110
return;
108111
}
109112

@@ -210,10 +213,14 @@ function getEntryPointsForPaths(
210213
}
211214
}
212215
}
216+
217+
const suggestion = isDir(fileOrDir)
218+
? " If you wanted to include files inside this directory, set --entryPointStrategy to expand or specify a glob."
219+
: "";
213220
logger.warn(
214221
`The entry point ${nicePath(
215222
fileOrDir
216-
)} does not exist or is not included in the program for your provided tsconfig.`
223+
)} is not included in the program for your provided tsconfig.${suggestion}`
217224
);
218225
}
219226

@@ -234,11 +241,30 @@ export function getExpandedEntryPointsForPaths(
234241
);
235242
}
236243

237-
function expandGlobs(inputFiles: string[]) {
244+
function expandGlobs(inputFiles: string[], logger: Logger) {
238245
const base = deriveRootDir(inputFiles);
239-
const result = inputFiles.flatMap((entry) =>
240-
glob(entry, base, { includeDirectories: true, followSymlinks: true })
241-
);
246+
const result = inputFiles.flatMap((entry) => {
247+
const result = glob(entry, base, {
248+
includeDirectories: true,
249+
followSymlinks: true,
250+
});
251+
252+
if (result.length === 0) {
253+
logger.warn(
254+
`The entrypoint glob ${nicePath(
255+
entry
256+
)} did not match any files.`
257+
);
258+
} else {
259+
logger.verbose(
260+
`Expanded ${nicePath(entry)} to:\n\t${result
261+
.map(nicePath)
262+
.join("\n\t")}`
263+
);
264+
}
265+
266+
return result;
267+
});
242268
return result;
243269
}
244270

src/lib/utils/fs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export function getCommonDirectory(files: readonly string[]): string {
5757

5858
let i = 0;
5959

60-
while (new Set(roots.map((part) => part[i])).size === 1) {
60+
while (
61+
i < roots[0].length &&
62+
new Set(roots.map((part) => part[i])).size === 1
63+
) {
6164
i++;
6265
}
6366

src/lib/utils/package-manifest.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ export function expandPackages(
132132
resolve(packageJsonDir, workspace, "package.json"),
133133
resolve(packageJsonDir)
134134
);
135+
136+
if (globbedPackageJsonPaths.length === 0) {
137+
logger.warn(
138+
`The entrypoint glob ${nicePath(
139+
workspace
140+
)} did not match any directories containing package.json.`
141+
);
142+
} else {
143+
logger.verbose(
144+
`Expanded ${nicePath(
145+
workspace
146+
)} to:\n\t${globbedPackageJsonPaths.map(nicePath).join("\n\t")}`
147+
);
148+
}
149+
135150
return globbedPackageJsonPaths.flatMap((packageJsonPath) => {
136151
if (matchesAny(exclude, dirname(packageJsonPath))) {
137152
return [];

src/test/utils/fs.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createServer } from "net";
33
import { Project, tempdirProject } from "@typestrong/fs-fixture-builder";
44
import { AssertionError, deepStrictEqual as equal } from "assert";
55
import { basename, dirname, resolve, normalize } from "path";
6-
import { glob } from "../../lib/utils/fs";
6+
import { getCommonDirectory, glob } from "../../lib/utils/fs";
77

88
describe("fs.ts", () => {
99
let fix: Project;
@@ -15,6 +15,28 @@ describe("fs.ts", () => {
1515
fix.rm();
1616
});
1717

18+
describe("getCommonDirectory", () => {
19+
it("Returns the empty string if no files are provided", () => {
20+
equal(getCommonDirectory([]), "");
21+
});
22+
23+
it("Returns the dirname if only one file is provided", () => {
24+
equal(getCommonDirectory(["a/b/c.ts"]), "a/b");
25+
});
26+
27+
it("Handles duplicates paths appropriately", () => {
28+
const p = "a/b/c";
29+
equal(getCommonDirectory([p, p]), p);
30+
});
31+
32+
it("Gets the path common to all files", () => {
33+
equal(
34+
getCommonDirectory(["/a/b/c", "/a/b/c/d/e", "/a/b/d"]),
35+
"/a/b"
36+
);
37+
});
38+
});
39+
1840
describe("glob", () => {
1941
it("handles root match", () => {
2042
fix.write();

0 commit comments

Comments
 (0)