Skip to content

Commit 8605fc8

Browse files
authored
fix(api-extractor): include entrypoint in links (#10902)
* fix(api-extractor): include entrypoint in links * chore: prettier
1 parent 33d8619 commit 8605fc8

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/api-extractor/src/generators/DeclarationReferenceGenerator.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { dirname } from 'node:path';
45
import { Navigation, Meaning } from '@discordjs/api-extractor-model';
56
import {
67
DeclarationReference,
@@ -348,6 +349,16 @@ export class DeclarationReferenceGenerator {
348349
);
349350

350351
if (packageJson?.name) {
352+
if (packageJson?.exports && !Array.isArray(packageJson.exports) && typeof packageJson.exports !== 'string') {
353+
const entryPoint = Object.keys(packageJson.exports).find((path) =>
354+
dirname(sourceFile.fileName).endsWith(path.slice(1)),
355+
);
356+
357+
if (entryPoint && packageJson.exports[entryPoint]) {
358+
return `${packageJson.name}${entryPoint.slice(1)}`;
359+
}
360+
}
361+
351362
return packageJson.name;
352363
}
353364

packages/scripts/src/generateSplitDocumentation.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import type {
4646
DocFencedCode,
4747
DocComment,
4848
} from '@microsoft/tsdoc';
49-
import type { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js';
49+
import type { DeclarationReference, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js';
5050
import { BuiltinDocumentationLinks } from './builtinDocumentationLinks.js';
5151
import { PACKAGES, fetchVersionDocs, fetchVersions } from './shared.js';
5252

@@ -147,6 +147,9 @@ function resolveCanonicalReference(
147147
containerKey: `|${
148148
canonicalReference.symbol.meaning
149149
}|${canonicalReference.symbol.componentPath.component.toString()}`,
150+
getAssociatedEntryPoint() {
151+
return canonicalReference.source as ModuleSource;
152+
},
150153
},
151154
// eslint-disable-next-line unicorn/better-regex
152155
version: apiPackage?.dependencies?.[canonicalReference.source.packageName]?.replace(/[~^]/, ''),
@@ -167,6 +170,9 @@ function resolveCanonicalReference(
167170
members: canonicalReference.memberReferences
168171
.slice(1)
169172
.map((member) => ({ kind: member.kind, displayName: member.memberIdentifier!.identifier! })),
173+
getAssociatedEntryPoint() {
174+
return canonicalReference;
175+
},
170176
},
171177
// eslint-disable-next-line unicorn/better-regex
172178
version: apiPackage?.dependencies?.[canonicalReference.packageName ?? '']?.replace(/[~^]/, ''),
@@ -204,10 +210,14 @@ export function hasEvents(item: ApiItemContainerMixin) {
204210
return resolveMembers(item, memberPredicate).some(({ item: member }) => member.kind === ApiItemKind.Event);
205211
}
206212

213+
interface ApiEntryPointLike {
214+
importPath: string | undefined;
215+
}
216+
207217
interface ApiItemLike {
208218
containerKey?: string;
209219
displayName: string;
210-
getAssociatedEntryPoint?(): ApiEntryPoint | undefined;
220+
getAssociatedEntryPoint?(): ApiEntryPointLike | undefined;
211221
kind: string;
212222
members?: readonly ApiItemLike[];
213223
parent?: ApiItemLike | undefined;

0 commit comments

Comments
 (0)