Skip to content

Commit 26df2ac

Browse files
committed
Support readme only packages
Resolves #2264
1 parent eb18150 commit 26df2ac

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Features
4+
5+
- TypeDoc will now allow conversion without any entry points to support "readme only" packages, #2264.
6+
37
### Bug Fixes
48

59
- Category children are now sorted according to the `sort` option, #2272.

Diff for: src/lib/application.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ export class Application extends ChildableComponent<
516516
}
517517

518518
private _convertPackages(): ProjectReflection | undefined {
519+
if (!this.options.isSet("entryPoints")) {
520+
this.logger.error(
521+
"No entry points provided to packages mode, documentation cannot be generated."
522+
);
523+
return;
524+
}
525+
519526
const packageDirs = getPackageDirectories(
520527
this.logger,
521528
this.options,
@@ -535,7 +542,7 @@ export class Application extends ChildableComponent<
535542
// Generate a json file for each package
536543
for (const dir of packageDirs) {
537544
this.logger.info(`Converting project at ${nicePath(dir)}`);
538-
const opts = origOptions.copyForPackage();
545+
const opts = origOptions.copyForPackage(dir);
539546
// Invalid links should only be reported after everything has been merged.
540547
opts.setValue("validation", { invalidLink: false });
541548
opts.read(this.logger, dir);
@@ -584,6 +591,11 @@ export class Application extends ChildableComponent<
584591
private _merge(): ProjectReflection | undefined {
585592
const start = Date.now();
586593

594+
if (!this.options.isSet("entryPoints")) {
595+
this.logger.error("No entry points provided to merge.");
596+
return;
597+
}
598+
587599
const rootDir = deriveRootDir(this.entryPoints);
588600
const entryPoints = this.entryPoints.flatMap((entry) => {
589601
const result = glob(entry, rootDir);
@@ -605,11 +617,6 @@ export class Application extends ChildableComponent<
605617
return result;
606618
});
607619

608-
if (entryPoints.length < 1) {
609-
this.logger.error("No entry points provided to merge.");
610-
return;
611-
}
612-
613620
const jsonProjects = entryPoints.map((path) => {
614621
try {
615622
return JSON.parse(readFile(path));

Diff for: src/lib/converter/plugins/PackagePlugin.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export class PackagePlugin extends ConverterComponent {
8181
? this.entryPoints.map((d) => join(d, "package.json"))
8282
: this.entryPoints;
8383

84-
const dirName = Path.resolve(deriveRootDir(entryFiles));
84+
const dirName =
85+
this.application.options.packageDir ??
86+
Path.resolve(deriveRootDir(entryFiles));
8587

8688
this.application.logger.verbose(
8789
`Begin readme.md/package.json search at ${nicePath(dirName)}`

Diff for: src/lib/output/themes/default/partials/index.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { classNames, renderName } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
3-
import { JSX, Raw } from "../../../../utils";
4-
import { ContainerReflection, DeclarationReflection, ReflectionCategory, ReflectionKind } from "../../../../models";
3+
import { JSX } from "../../../../utils";
4+
import type { ContainerReflection, ReflectionCategory } from "../../../../models";
55

66
function renderCategory(
77
{ urlTo, icons, getReflectionClasses }: DefaultThemeRenderContext,
@@ -72,15 +72,6 @@ export function index(context: DefaultThemeRenderContext, props: ContainerReflec
7272

7373
return (
7474
<>
75-
{props instanceof DeclarationReflection &&
76-
props.kind === ReflectionKind.Module &&
77-
props.readme?.length !== 0 && (
78-
<section class="tsd-panel-group">
79-
<section class="tsd-panel tsd-typography">
80-
<Raw html={context.markdown(props.readme || [])} />
81-
</section>
82-
</section>
83-
)}
8475
<section class="tsd-panel-group tsd-index-group">
8576
<section class="tsd-panel tsd-index-panel">{content}</section>
8677
</section>

Diff for: src/lib/output/themes/default/templates/reflection.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { classNames, hasTypeParameters } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import type { PageEvent } from "../../../events";
44
import { ContainerReflection, DeclarationReflection, ReflectionKind, ReflectionType } from "../../../../models";
5-
import { JSX } from "../../../../utils";
5+
import { JSX, Raw } from "../../../../utils";
66

77
export function reflectionTemplate(context: DefaultThemeRenderContext, props: PageEvent<ContainerReflection>) {
88
if (
@@ -18,6 +18,14 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
1818
<section class="tsd-panel tsd-comment">{context.comment(props.model)}</section>
1919
)}
2020

21+
{props.model instanceof DeclarationReflection &&
22+
props.model.kind === ReflectionKind.Module &&
23+
props.model.readme?.length && (
24+
<section class="tsd-panel tsd-typography">
25+
<Raw html={context.markdown(props.model.readme)} />
26+
</section>
27+
)}
28+
2129
{hasTypeParameters(props.model) && <> {context.typeParameters(props.model.typeParameters)} </>}
2230
{props.model instanceof DeclarationReflection && (
2331
<>

Diff for: src/lib/utils/entry-point.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ export function getEntryPoints(
6262
logger: Logger,
6363
options: Options
6464
): DocumentationEntryPoint[] | undefined {
65+
if (!options.isSet("entryPoints")) {
66+
logger.warn(
67+
"No entry points were provided, this is likely a misconfiguration."
68+
);
69+
return [];
70+
}
71+
6572
const entryPoints = options.getValue("entryPoints");
6673

74+
// May be set explicitly to be an empty array to only include a readme for a package
75+
// See #2264
6776
if (entryPoints.length === 0) {
68-
logger.error("No entry points were provided.");
69-
return;
77+
return [];
7078
}
7179

7280
let result: DocumentationEntryPoint[] | undefined;
@@ -181,7 +189,7 @@ function getEntryPointsForPaths(
181189
inputFiles: string[],
182190
options: Options,
183191
programs = getEntryPrograms(logger, options)
184-
): DocumentationEntryPoint[] | undefined {
192+
): DocumentationEntryPoint[] {
185193
const baseDir = options.getValue("basePath") || deriveRootDir(inputFiles);
186194
const entryPoints: DocumentationEntryPoint[] = [];
187195

@@ -232,7 +240,7 @@ export function getExpandedEntryPointsForPaths(
232240
inputFiles: string[],
233241
options: Options,
234242
programs = getEntryPrograms(logger, options)
235-
): DocumentationEntryPoint[] | undefined {
243+
): DocumentationEntryPoint[] {
236244
return getEntryPointsForPaths(
237245
logger,
238246
expandInputFiles(logger, inputFiles, options),

Diff for: src/lib/utils/options/options.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export class Options {
9595
private _projectReferences: readonly ts.ProjectReference[] = [];
9696
private _logger: Logger;
9797

98+
/**
99+
* In packages mode, the directory of the package being converted.
100+
*/
101+
packageDir?: string;
102+
98103
constructor(logger: Logger) {
99104
this._logger = logger;
100105
addTypeDocOptions(this);
@@ -103,8 +108,9 @@ export class Options {
103108
/**
104109
* Clones the options, intended for use in packages mode.
105110
*/
106-
copyForPackage(): Options {
111+
copyForPackage(packageDir: string): Options {
107112
const options = new Options(this._logger);
113+
options.packageDir = packageDir;
108114

109115
options._readers = this._readers.filter(
110116
(reader) => reader.supportsPackages

0 commit comments

Comments
 (0)