Skip to content

fix: generateSplitDocumentation for external docs on main #10827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api-extractor/extends/tsdoc-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

"@betaDocumentation": true,
"@internalRemarks": true,
"@mixes": true,
"@preapproved": true
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jsdoc/valid-types */
import { ApplicationCommandType, type RESTPostAPIChatInputApplicationCommandsJSONBody } from 'discord-api-types/v10';
import { Mixin } from 'ts-mixer';
import { validate } from '../../../util/validation.js';
Expand All @@ -10,10 +11,10 @@ import { SharedChatInputCommandSubcommands } from './mixins/SharedSubcommands.js
/**
* A builder that creates API-compatible JSON data for chat input commands.
*
* @mixes CommandBuilder<RESTPostAPIChatInputApplicationCommandsJSONBody>
* @mixes SharedChatInputCommandOptions
* @mixes SharedNameAndDescription
* @mixes SharedChatInputCommandSubcommands
* @mixes {@link CommandBuilder}\<{@link discord-api-types/v10#(RESTPostAPIChatInputApplicationCommandsJSONBody:interface)}\>
* @mixes {@link SharedChatInputCommandOptions}
* @mixes {@link SharedNameAndDescription}
* @mixes {@link SharedChatInputCommandSubcommands}
*/
export class ChatInputCommandBuilder extends Mixin(
CommandBuilder<RESTPostAPIChatInputApplicationCommandsJSONBody>,
Expand Down
7 changes: 1 addition & 6 deletions packages/builders/tsdoc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"tagDefinitions": [
{
"tagName": "@mixes",
"syntaxKind": "block"
}
]
"extends": ["@discordjs/api-extractor/extends/tsdoc-base.json"]
}
1 change: 1 addition & 0 deletions packages/discord.js/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bundledPackages": [
"discord-api-types",
"@discordjs/builders",
"@discordjs/collection",
"@discordjs/formatters",
"@discordjs/rest",
"@discordjs/util",
Expand Down
25 changes: 21 additions & 4 deletions packages/scripts/src/generateSplitDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,15 @@ function itemTsDoc(item: DocNode, apiItem: ApiItem) {
const comment = node as DocComment;

const exampleBlocks = comment.customBlocks.filter(
(block) => block.blockTag.tagName.toUpperCase() === StandardTags.example.tagNameWithUpperCase,
(block) => block.blockTag.tagNameWithUpperCase === StandardTags.example.tagNameWithUpperCase,
);

const defaultValueBlock = comment.customBlocks.find(
(block) => block.blockTag.tagName.toUpperCase() === StandardTags.defaultValue.tagNameWithUpperCase,
(block) => block.blockTag.tagNameWithUpperCase === StandardTags.defaultValue.tagNameWithUpperCase,
);

const mixesBlocks = comment.customBlocks.filter((block) => block.blockTag.tagNameWithUpperCase === '@MIXES');

return {
kind: DocNodeKind.Comment,
deprecatedBlock: comment.deprecatedBlock
Expand Down Expand Up @@ -497,6 +499,9 @@ function itemTsDoc(item: DocNode, apiItem: ApiItem) {
seeBlocks: comment.seeBlocks
.flatMap((block) => createNode(block.content).flat(1))
.filter((val: any) => val.kind !== DocNodeKind.SoftBreak),
mixesBlocks: mixesBlocks
.flatMap((block) => createNode(block.content).flat(1))
.filter((val: any) => val.kind !== DocNodeKind.SoftBreak),
};
}

Expand All @@ -522,8 +527,7 @@ function itemInfo(item: ApiDeclaredItem) {
const isAbstract = ApiAbstractMixin.isBaseClassOf(item) && item.isAbstract;
const isOptional = ApiOptionalMixin.isBaseClassOf(item) && item.isOptional;
const isDeprecated = Boolean(item.tsdocComment?.deprecatedBlock);
const isExternal = Boolean(item.sourceLocation.fileUrl?.includes('node_modules'));

const isExternal = Boolean(sourceLine === undefined);
const hasSummary = Boolean(item.tsdocComment?.summarySection);

return {
Expand Down Expand Up @@ -587,6 +591,19 @@ function resolveFileUrl(item: ApiDeclaredItem) {
sourceURL: href,
};
}
} else if (fileUrl?.includes('/dist/') && fileUrl.includes('/main/packages/')) {
const [, pkg] = fileUrl.split('/main/packages/');
const pkgName = pkg!.split('/')[0];
const version = 'main';

// https://github.com/discordjs/discord.js/tree/main/packages/builders/dist/index.d.ts
let currentItem = item;
while (currentItem.parent && currentItem.parent.kind !== ApiItemKind.EntryPoint)
currentItem = currentItem.parent as ApiDeclaredItem;

return {
sourceURL: `/docs/packages/${pkgName}/${version}/${currentItem.displayName}:${currentItem.kind}`,
};
}

return {
Expand Down