feat(api-extractor): support multiple entrypoints (#10829)

* feat(api-extractor): support multiple entrypoints

* chore: initial support in generateSplitDocumentation

* chore: bring in line with upstream

* refactor: multiple entrypoints in scripts

* fix: split docs

* feat: website

* fix: docs failing on next

* fix: don't include dtypes for now

* refactor: don't fetch entrypoint if there is none

---------

Co-authored-by: iCrawl <buechler.noel@outlook.com>
This commit is contained in:
Qjuh
2025-05-12 23:48:41 +02:00
committed by GitHub
parent 4f5e5c7c14
commit b3db92edfb
93 changed files with 2330 additions and 1956 deletions

View File

@@ -11,7 +11,10 @@ export const PACKAGES = [
{ name: 'util' },
{ name: 'voice' },
{ name: 'ws' },
// { name: 'discord-api-types' },
];
export const PACKAGES_WITH_ENTRY_POINTS = ['discord-api-types'];
export const DESCRIPTION =
"discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.";

View File

@@ -0,0 +1,34 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
// import { sql } from '@vercel/postgres';
import { ENV } from './env';
export async function fetchEntryPoints(packageName: string, version: string) {
if (ENV.IS_LOCAL_DEV) {
const fileContent = await readFile(
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.entrypoints.api.json`),
'utf8',
);
return JSON.parse(fileContent);
}
// try {
// const { rows } = await sql<{
// entryPoint: string;
// }>`select entryPoint from documentation where name = ${packageName} and version = ${version} order by
// case
// when version = 'main' then 0
// else 1
// end,
// case
// when version = 'main' then null
// else string_to_array(version, '.')::int[]
// end desc;
// `;
// return rows;
// } catch {
return [];
// }
}

View File

@@ -3,21 +3,24 @@ import { join } from 'node:path';
import { ENV } from './env';
export async function fetchNode({
entryPoint,
item,
packageName,
version,
}: {
readonly entryPoint?: string | undefined;
readonly item: any;
readonly packageName: string;
readonly version: string;
}) {
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
const normalizedEntryPoint = entryPoint ? `${entryPoint}.` : '';
const normalizeItem = item.replaceAll(':', '.').toLowerCase();
if (ENV.IS_LOCAL_DEV) {
const fileContent = await readFile(
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
),
'utf8',
);
@@ -27,7 +30,7 @@ export async function fetchNode({
const isMain = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
{ next: { revalidate: isMain ? 0 : 604_800 } },
);

View File

@@ -3,15 +3,22 @@ import { join } from 'node:path';
import { ENV } from './env';
export async function fetchSitemap({
entryPoint,
packageName,
version,
}: {
readonly entryPoint?: string | undefined;
readonly packageName: string;
readonly version: string;
}) {
const normalizedEntryPoint = entryPoint ? `${entryPoint}.` : '';
if (ENV.IS_LOCAL_DEV) {
const fileContent = await readFile(
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizedEntryPoint}sitemap.api.json`,
),
'utf8',
);
@@ -20,7 +27,7 @@ export async function fetchSitemap({
const isMain = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizedEntryPoint}sitemap.api.json`,
{
next: { revalidate: isMain ? 0 : 604_800 },
},

View File

@@ -0,0 +1,16 @@
export function parseDocsPathParams(item: string[] | undefined): {
entryPoints: string[];
foundItem: string | undefined;
} {
if (!item?.length) {
return { entryPoints: [], foundItem: undefined };
}
const lastElement = item.at(-1);
const hasTypeMarker = lastElement?.includes('%3A');
return {
entryPoints: hasTypeMarker ? item.slice(0, -1) : item,
foundItem: hasTypeMarker ? lastElement : undefined,
};
}