mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
fix: cross package links again (#9995)
This commit is contained in:
@@ -46,7 +46,7 @@ import { JsonFile, Path } from '@rushstack/node-core-library';
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import type { AstDeclaration } from '../analyzer/AstDeclaration.js';
|
import type { AstDeclaration } from '../analyzer/AstDeclaration.js';
|
||||||
import type { AstEntity } from '../analyzer/AstEntity.js';
|
import type { AstEntity } from '../analyzer/AstEntity.js';
|
||||||
import type { AstImport } from '../analyzer/AstImport.js';
|
import { AstImport } from '../analyzer/AstImport.js';
|
||||||
import type { AstModule } from '../analyzer/AstModule.js';
|
import type { AstModule } from '../analyzer/AstModule.js';
|
||||||
import { AstNamespaceImport } from '../analyzer/AstNamespaceImport.js';
|
import { AstNamespaceImport } from '../analyzer/AstNamespaceImport.js';
|
||||||
import { AstSymbol } from '../analyzer/AstSymbol.js';
|
import { AstSymbol } from '../analyzer/AstSymbol.js';
|
||||||
@@ -213,6 +213,8 @@ interface IProcessAstEntityContext {
|
|||||||
const linkRegEx =
|
const linkRegEx =
|
||||||
/{@link\s(?:(?<class>\w+)(?:[#.](?<event>event:)?(?<prop>[\w()]+))?|(?<url>https?:\/\/[^\s}]*))(?<name>\s[^}]*)?}/g;
|
/{@link\s(?:(?<class>\w+)(?:[#.](?<event>event:)?(?<prop>[\w()]+))?|(?<url>https?:\/\/[^\s}]*))(?<name>\s[^}]*)?}/g;
|
||||||
|
|
||||||
|
const moduleNameRegEx = /^(?<package>(?:@[\w.-]+\/)?[\w.-]+)(?<path>(?:\/[\w.-]+)+)?$/i;
|
||||||
|
|
||||||
function filePathFromJson(meta: DocgenMetaJson): string {
|
function filePathFromJson(meta: DocgenMetaJson): string {
|
||||||
return `${meta.path.slice('packages/discord.js/'.length)}/${meta.file}`;
|
return `${meta.path.slice('packages/discord.js/'.length)}/${meta.file}`;
|
||||||
}
|
}
|
||||||
@@ -1713,39 +1715,37 @@ export class ApiModelGenerator {
|
|||||||
};
|
};
|
||||||
return mapper
|
return mapper
|
||||||
.flatMap((typ, index) => {
|
.flatMap((typ, index) => {
|
||||||
const result = typ.reduce<IExcerptToken[]>(
|
const result = typ.reduce<IExcerptToken[]>((arr, [type, symbol]) => {
|
||||||
(arr, [type, symbol]) => [
|
const astEntity =
|
||||||
|
(this._collector.entities.find(
|
||||||
|
(entity) => entity.nameForEmit === type && 'astDeclarations' in entity.astEntity,
|
||||||
|
)?.astEntity as AstSymbol | undefined) ??
|
||||||
|
(this._collector.entities.find((entity) => entity.nameForEmit === type && 'astSymbol' in entity.astEntity)
|
||||||
|
?.astEntity as AstImport | undefined);
|
||||||
|
const astSymbol = astEntity instanceof AstImport ? astEntity.astSymbol : astEntity;
|
||||||
|
const match = astEntity instanceof AstImport ? moduleNameRegEx.exec(astEntity.modulePath) : null;
|
||||||
|
const pkg = match?.groups!.package ?? this._apiModel.packages[0]!.name;
|
||||||
|
return [
|
||||||
...arr,
|
...arr,
|
||||||
{
|
{
|
||||||
kind: type?.includes("'") ? ExcerptTokenKind.Content : ExcerptTokenKind.Reference,
|
kind: type?.includes("'") ? ExcerptTokenKind.Content : ExcerptTokenKind.Reference,
|
||||||
text: fixPrimitiveTypes(type ?? 'unknown', symbol),
|
text: fixPrimitiveTypes(type ?? 'unknown', symbol),
|
||||||
canonicalReference: type?.includes("'")
|
canonicalReference: type?.includes("'")
|
||||||
? undefined
|
? undefined
|
||||||
: DeclarationReference.package(this._apiModel.packages[0]!.name)
|
: DeclarationReference.package(pkg)
|
||||||
.addNavigationStep(
|
.addNavigationStep(
|
||||||
Navigation.Members as any,
|
Navigation.Members as any,
|
||||||
DeclarationReference.parseComponent(type ?? 'unknown'),
|
DeclarationReference.parseComponent(type ?? 'unknown'),
|
||||||
)
|
)
|
||||||
.withMeaning(
|
.withMeaning(
|
||||||
lookup[
|
lookup[astSymbol?.astDeclarations[0]?.declaration.kind ?? ts.SyntaxKind.ClassDeclaration] ??
|
||||||
(
|
('class' as any),
|
||||||
(this._collector.entities.find(
|
|
||||||
(entity) => entity.nameForEmit === type && 'astDeclarations' in entity.astEntity,
|
|
||||||
)?.astEntity as AstSymbol | undefined) ??
|
|
||||||
(
|
|
||||||
this._collector.entities.find(
|
|
||||||
(entity) => entity.nameForEmit === type && 'astSymbol' in entity.astEntity,
|
|
||||||
)?.astEntity as AstImport | undefined
|
|
||||||
)?.astSymbol
|
|
||||||
)?.astDeclarations[0]?.declaration.kind ?? ts.SyntaxKind.ClassDeclaration
|
|
||||||
] ?? ('class' as any),
|
|
||||||
)
|
)
|
||||||
.toString(),
|
.toString(),
|
||||||
},
|
},
|
||||||
{ kind: ExcerptTokenKind.Content, text: symbol ?? '' },
|
{ kind: ExcerptTokenKind.Content, text: symbol ?? '' },
|
||||||
],
|
];
|
||||||
[],
|
}, []);
|
||||||
);
|
|
||||||
return index === 0 ? result : [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
|
return index === 0 ? result : [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
|
||||||
})
|
})
|
||||||
.filter((excerpt) => excerpt.text.length);
|
.filter((excerpt) => excerpt.text.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user