Skip to content

Commit bc7e8c2

Browse files
committed
Support relative links to package dir
Resolves #2961
1 parent 3da819f commit bc7e8c2

File tree

22 files changed

+154
-104
lines changed

22 files changed

+154
-104
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Changelog
44

55
## Unreleased
66

7+
### Features
8+
9+
- TypeDoc now supports resolving relative paths in links to the package directory as belonging to the project, #2961.
10+
711
### Bug Fixes
812

913
- Attempting to highlight a supported language which is not enabled is now a warning, not an error, #2956.

src/lib/converter/comments/textParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import type { TranslationProxy } from "../../internationalization/index.js";
99
import type { CommentDisplayPart, RelativeLinkDisplayPart } from "../../models/index.js";
10-
import type { FileRegistry } from "../../models/FileRegistry.js";
10+
import type { FileId, FileRegistry } from "../../models/FileRegistry.js";
1111
import { HtmlAttributeParser, ParserState } from "#node-utils";
1212
import { type Token, TokenSyntaxKind } from "./lexer.js";
1313

@@ -28,7 +28,7 @@ interface RelativeLink {
2828
pos: number;
2929
end: number;
3030
/** May be undefined if the registry can't find this file */
31-
target: number | undefined;
31+
target: FileId | undefined;
3232
targetAnchor: string | undefined;
3333
}
3434

src/lib/converter/converter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
322322
this.application.options.getValue("name"),
323323
this.application.files,
324324
);
325+
if (this.owner.options.packageDir) {
326+
project.files.registerReflectionPath(normalizePath(this.owner.options.packageDir), project);
327+
}
328+
325329
const context = new Context(this, programs, project);
326330

327331
this.trigger(Converter.EVENT_BEGIN, context);

src/lib/converter/plugins/PackagePlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ProjectReflection } from "../../models/index.js";
66
import { ApplicationEvents } from "../../application-events.js";
77
import { ConverterEvents } from "../converter-events.js";
88
import type { Converter } from "../converter.js";
9-
import { type GlobString, i18n, MinimalSourceFile, type NormalizedPath } from "#utils";
9+
import { type GlobString, i18n, MinimalSourceFile, type NormalizedPath, NormalizedPathUtils } from "#utils";
1010
import {
1111
discoverPackageJson,
1212
type EntryPointStrategy,
@@ -139,6 +139,10 @@ export class PackagePlugin extends ConverterComponent {
139139
);
140140

141141
project.readme = content;
142+
project.files.registerReflectionPath(this.readmeFile, project);
143+
// In packages mode, this probably won't do anything unless someone uses the readme
144+
// option to select a different file.
145+
project.files.registerReflectionPath(NormalizedPathUtils.dirname(this.readmeFile), project);
142146

143147
// This isn't ideal, but seems better than figuring out the readme
144148
// path over in the include plugin...

src/lib/internationalization/locales/de.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export = localeUtils.buildIncompleteTranslation({
221221
// deserialization
222222
serialized_project_referenced_0_not_part_of_project:
223223
"Serialisiertes Projekt referenziert Reflection {0}, welche kein Teil des Projekts ist",
224-
saved_relative_path_0_resolved_from_1_is_not_a_file:
224+
saved_relative_path_0_resolved_from_1_does_not_exist:
225225
"Serialisiertes Projekt referenziert {0}, was relativ zu {1} nicht existiert",
226226

227227
// options

src/lib/internationalization/locales/en.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export = {
210210
// deserialization
211211
serialized_project_referenced_0_not_part_of_project:
212212
`Serialized project referenced reflection {0}, which was not a part of the project`,
213-
saved_relative_path_0_resolved_from_1_is_not_a_file:
213+
saved_relative_path_0_resolved_from_1_does_not_exist:
214214
`Serialized project referenced {0}, which does not exist relative to {1}`,
215215

216216
// options

src/lib/internationalization/locales/ja.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export = localeUtils.buildIncompleteTranslation({
146146
file_0_not_an_object: "ファイル {0} はオブジェクトではありません",
147147
serialized_project_referenced_0_not_part_of_project:
148148
"シリアル化されたプロジェクトは、プロジェクトの一部ではないリフレクション {0} を参照しました",
149-
// saved_relative_path_0_resolved_from_1_is_not_a_file
149+
// saved_relative_path_0_resolved_from_1_does_not_exist
150150
circular_reference_extends_0: '{0} の "extends" フィールドで循環参照が検出されました',
151151
failed_resolve_0_to_file_in_1: "{0} を {1} 内のファイルに解決できませんでした",
152152
option_0_can_only_be_specified_by_config_file: "'{0}' オプションは設定ファイル経由でのみ指定できます",

src/lib/internationalization/locales/zh.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export = localeUtils.buildIncompleteTranslation({
181181

182182
// deserialization
183183
serialized_project_referenced_0_not_part_of_project: "序列化项目引用了反射 {0},但它不是项目的一部分",
184-
saved_relative_path_0_resolved_from_1_is_not_a_file: "序列化项目引用的 {0} 不存在或无法在 {1} 下找到",
184+
saved_relative_path_0_resolved_from_1_does_not_exist: "序列化项目引用的 {0} 不存在或无法在 {1} 下找到",
185185

186186
// options
187187
circular_reference_extends_0: "{0} 的“extends”字段出现循环引用",

src/lib/models/Comment.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { assertNever, i18n, NonEnumerable, type NormalizedPath, removeIf } from "#utils";
2-
import type { Reflection } from "./Reflection.js";
2+
import type { Reflection, ReflectionId } from "./Reflection.js";
33
import { ReflectionSymbolId } from "./ReflectionSymbolId.js";
44

55
import type { Deserializer, JSONOutput, Serializer } from "#serialization";
6+
import type { FileId } from "./FileRegistry.js";
67

78
/**
89
* Represents a parsed piece of a comment.
@@ -62,7 +63,7 @@ export interface RelativeLinkDisplayPart {
6263
* A link to either some document outside of the project or a reflection.
6364
* This may be `undefined` if the relative path does not exist.
6465
*/
65-
target: number | undefined;
66+
target: FileId | undefined;
6667
/**
6768
* Anchor within the target page, validated after rendering if possible
6869
*/
@@ -238,10 +239,10 @@ export class Comment {
238239
parts: JSONOutput.CommentDisplayPart[],
239240
): CommentDisplayPart[] {
240241
const links: [
241-
number,
242+
ReflectionId,
242243
InlineTagDisplayPart | RelativeLinkDisplayPart,
243244
][] = [];
244-
const files: [number, RelativeLinkDisplayPart][] = [];
245+
const files: [FileId, RelativeLinkDisplayPart][] = [];
245246

246247
const result = parts.map((part): CommentDisplayPart => {
247248
switch (part.kind) {

src/lib/models/DeclarationReflection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ReferenceType, ReflectionType, type SomeType } from "./types.js";
2-
import { type TraverseCallback, TraverseProperty } from "./Reflection.js";
2+
import { type ReflectionId, type TraverseCallback, TraverseProperty } from "./Reflection.js";
33
import { ContainerReflection } from "./ContainerReflection.js";
44
import type { SignatureReflection } from "./SignatureReflection.js";
55
import type { TypeParameterReflection } from "./TypeParameterReflection.js";
@@ -346,7 +346,7 @@ export class DeclarationReflection extends ContainerReflection {
346346
de.defer(() => {
347347
for (const [id, sid] of Object.entries(obj.symbolIdMap || {})) {
348348
const refl = this.project.getReflectionById(
349-
de.oldIdToNewId[+id] ?? -1,
349+
de.oldIdToNewId[+id as ReflectionId] ?? -1,
350350
);
351351
if (refl) {
352352
this.project.registerSymbolId(

0 commit comments

Comments
 (0)