mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(api-extractor): include entrypoint in links (#10902)
* fix(api-extractor): include entrypoint in links * chore: prettier
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
||||||
// See LICENSE in the project root for license information.
|
// See LICENSE in the project root for license information.
|
||||||
|
|
||||||
|
import { dirname } from 'node:path';
|
||||||
import { Navigation, Meaning } from '@discordjs/api-extractor-model';
|
import { Navigation, Meaning } from '@discordjs/api-extractor-model';
|
||||||
import {
|
import {
|
||||||
DeclarationReference,
|
DeclarationReference,
|
||||||
@@ -348,6 +349,16 @@ export class DeclarationReferenceGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (packageJson?.name) {
|
if (packageJson?.name) {
|
||||||
|
if (packageJson?.exports && !Array.isArray(packageJson.exports) && typeof packageJson.exports !== 'string') {
|
||||||
|
const entryPoint = Object.keys(packageJson.exports).find((path) =>
|
||||||
|
dirname(sourceFile.fileName).endsWith(path.slice(1)),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (entryPoint && packageJson.exports[entryPoint]) {
|
||||||
|
return `${packageJson.name}${entryPoint.slice(1)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return packageJson.name;
|
return packageJson.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import type {
|
|||||||
DocFencedCode,
|
DocFencedCode,
|
||||||
DocComment,
|
DocComment,
|
||||||
} from '@microsoft/tsdoc';
|
} from '@microsoft/tsdoc';
|
||||||
import type { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js';
|
import type { DeclarationReference, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js';
|
||||||
import { BuiltinDocumentationLinks } from './builtinDocumentationLinks.js';
|
import { BuiltinDocumentationLinks } from './builtinDocumentationLinks.js';
|
||||||
import { PACKAGES, fetchVersionDocs, fetchVersions } from './shared.js';
|
import { PACKAGES, fetchVersionDocs, fetchVersions } from './shared.js';
|
||||||
|
|
||||||
@@ -147,6 +147,9 @@ function resolveCanonicalReference(
|
|||||||
containerKey: `|${
|
containerKey: `|${
|
||||||
canonicalReference.symbol.meaning
|
canonicalReference.symbol.meaning
|
||||||
}|${canonicalReference.symbol.componentPath.component.toString()}`,
|
}|${canonicalReference.symbol.componentPath.component.toString()}`,
|
||||||
|
getAssociatedEntryPoint() {
|
||||||
|
return canonicalReference.source as ModuleSource;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line unicorn/better-regex
|
// eslint-disable-next-line unicorn/better-regex
|
||||||
version: apiPackage?.dependencies?.[canonicalReference.source.packageName]?.replace(/[~^]/, ''),
|
version: apiPackage?.dependencies?.[canonicalReference.source.packageName]?.replace(/[~^]/, ''),
|
||||||
@@ -167,6 +170,9 @@ function resolveCanonicalReference(
|
|||||||
members: canonicalReference.memberReferences
|
members: canonicalReference.memberReferences
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.map((member) => ({ kind: member.kind, displayName: member.memberIdentifier!.identifier! })),
|
.map((member) => ({ kind: member.kind, displayName: member.memberIdentifier!.identifier! })),
|
||||||
|
getAssociatedEntryPoint() {
|
||||||
|
return canonicalReference;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line unicorn/better-regex
|
// eslint-disable-next-line unicorn/better-regex
|
||||||
version: apiPackage?.dependencies?.[canonicalReference.packageName ?? '']?.replace(/[~^]/, ''),
|
version: apiPackage?.dependencies?.[canonicalReference.packageName ?? '']?.replace(/[~^]/, ''),
|
||||||
@@ -204,10 +210,14 @@ export function hasEvents(item: ApiItemContainerMixin) {
|
|||||||
return resolveMembers(item, memberPredicate).some(({ item: member }) => member.kind === ApiItemKind.Event);
|
return resolveMembers(item, memberPredicate).some(({ item: member }) => member.kind === ApiItemKind.Event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ApiEntryPointLike {
|
||||||
|
importPath: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface ApiItemLike {
|
interface ApiItemLike {
|
||||||
containerKey?: string;
|
containerKey?: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
getAssociatedEntryPoint?(): ApiEntryPoint | undefined;
|
getAssociatedEntryPoint?(): ApiEntryPointLike | undefined;
|
||||||
kind: string;
|
kind: string;
|
||||||
members?: readonly ApiItemLike[];
|
members?: readonly ApiItemLike[];
|
||||||
parent?: ApiItemLike | undefined;
|
parent?: ApiItemLike | undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user