Skip to content

Commit 14e226b

Browse files
authored
fix(website): remove several obsolete special handling of dtypes (#10898)
* fix(website): remove several obsolete special handling of dtypes * fix: reduce hardcoded places * chore: api-extractor.json setting mainEntryPointName
1 parent aa533ef commit 14e226b

File tree

12 files changed

+49
-94
lines changed

12 files changed

+49
-94
lines changed

apps/website/src/components/EntrypointSelect.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@ export function EntryPointSelect({
1717
const { entryPoints: parsedEntrypoints } = parseDocsPathParams(params.item as string[] | undefined);
1818

1919
return (
20-
<Select
21-
aria-label="Select an entrypoint"
22-
defaultSelectedKey={parsedEntrypoints.length ? parsedEntrypoints.join('/') : 'global'}
23-
>
20+
<Select aria-label="Select an entrypoint" defaultSelectedKey={parsedEntrypoints.join('/')}>
2421
<SelectTrigger className="bg-[#f3f3f4] dark:bg-[#121214]" />
2522
<SelectList classNames={{ popover: 'bg-[#f3f3f4] dark:bg-[#28282d]' }} items={entryPoints}>
2623
{(item) => (
2724
<SelectOption
2825
className="dark:pressed:bg-[#313135] bg-[#f3f3f4] dark:bg-[#28282d] dark:hover:bg-[#313135]"
2926
href={`/docs/packages/${params.packageName}/${params.version}/${item.entryPoint}`}
30-
id={item.entryPoint || 'global'}
31-
key={item.entryPoint || 'global'}
27+
id={item.entryPoint}
28+
key={item.entryPoint}
3229
onHoverStart={() =>
3330
router.prefetch(`/docs/packages/${params.packageName}/${params.version}/${item.entryPoint}`)
3431
}
35-
textValue={item.entryPoint || 'global'}
32+
textValue={item.entryPoint}
3633
>
37-
{item.entryPoint || 'global'}
34+
{item.entryPoint}
3835
</SelectOption>
3936
)}
4037
</SelectList>

apps/website/src/middleware.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import Cloudflare from 'cloudflare';
22
import { NextResponse, type NextRequest } from 'next/server';
3-
import { PACKAGES } from './util/constants';
3+
import { DEFAULT_ENTRY_POINT, PACKAGES, PACKAGES_WITH_ENTRY_POINTS } from './util/constants';
44
import { ENV } from './util/env';
55

66
const client = new Cloudflare({
77
apiToken: process.env.CF_D1_DOCS_API_KEY,
88
});
99

1010
async function fetchLatestVersion(packageName: string): Promise<string> {
11+
const hasEntryPoints = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
1112
if (ENV.IS_LOCAL_DEV) {
13+
if (hasEntryPoints) {
14+
return ['main', ...DEFAULT_ENTRY_POINT].join('/');
15+
}
16+
1217
return 'main';
1318
}
1419

@@ -19,7 +24,7 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
1924
params: [packageName],
2025
});
2126

22-
return (result[0]?.results as { version: string }[] | undefined)?.[0]?.version ?? 'main';
27+
return `${(result[0]?.results as { version: string }[] | undefined)?.[0]?.version ?? 'main'}${hasEntryPoints ? ['', ...DEFAULT_ENTRY_POINT].join('/') : ''}`;
2328
} catch {
2429
return '';
2530
}

apps/website/src/util/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ export const PACKAGES = [
1616

1717
export const PACKAGES_WITH_ENTRY_POINTS = ['discord-api-types'];
1818

19+
export const DEFAULT_ENTRY_POINT = ['v10'];
20+
1921
export const DESCRIPTION =
2022
"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.";

apps/website/src/util/parseDocsPathParams.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DEFAULT_ENTRY_POINT } from './constants';
2+
13
export function parseDocsPathParams(item: string[] | undefined): {
24
entryPoints: string[];
35
foundItem: string | undefined;
@@ -10,7 +12,7 @@ export function parseDocsPathParams(item: string[] | undefined): {
1012
const hasTypeMarker = lastElement?.includes('%3A');
1113

1214
return {
13-
entryPoints: hasTypeMarker ? item.slice(0, -1) : item,
15+
entryPoints: hasTypeMarker ? item.slice(0, -1) : lastElement?.length === 0 ? DEFAULT_ENTRY_POINT : item,
1416
foundItem: hasTypeMarker ? lastElement : undefined,
1517
};
1618
}

packages/api-extractor-model/src/model/ApiEntryPoint.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ import { ApiPackage } from './ApiPackage.js';
1515
export interface IApiEntryPointOptions extends IApiItemContainerMixinOptions, IApiNameMixinOptions {}
1616

1717
/**
18-
* Represents the entry point for an NPM package.
18+
* Represents an entry point for an NPM package.
1919
*
2020
* @remarks
2121
*
2222
* This is part of the {@link ApiModel} hierarchy of classes, which are serializable representations of
2323
* API declarations.
2424
*
25-
* `ApiEntryPoint` represents the entry point to an NPM package. API Extractor does not currently support
26-
* analysis of multiple entry points, but the `ApiEntryPoint` object is included to support a future feature.
27-
* In the current implementation, `ApiEntryPoint.importPath` is always the empty string.
25+
* `ApiEntryPoint` represents an entry point to an NPM package.
2826
*
2927
* For example, suppose the package.json file looks like this:
3028
*
@@ -37,7 +35,7 @@ export interface IApiEntryPointOptions extends IApiItemContainerMixinOptions, IA
3735
* }
3836
* ```
3937
*
40-
* In this example, the `ApiEntryPoint` would represent the TypeScript module for `./lib/index.js`.
38+
* In this example, the main `ApiEntryPoint` would represent the TypeScript module for `./lib/index.js`.
4139
* @public
4240
*/
4341
export class ApiEntryPoint extends ApiItemContainerMixin(ApiNameMixin(ApiItem)) {
@@ -62,12 +60,7 @@ export class ApiEntryPoint extends ApiItemContainerMixin(ApiNameMixin(ApiItem))
6260

6361
/**
6462
* The module path for this entry point, relative to the parent `ApiPackage`. In the current implementation,
65-
* this is always the empty string, indicating the default entry point.
66-
*
67-
* @remarks
68-
*
69-
* API Extractor does not currently support analysis of multiple entry points. If that feature is implemented
70-
* in the future, then the `ApiEntryPoint.importPath` will be used to distinguish different entry points,
63+
* this is used to distinguish different entry points,
7164
* for example: `controls/Button` in `import { Button } from "example-package/controls/Button";`.
7265
*
7366
* The `ApiEntryPoint.name` property stores the same value as `ApiEntryPoint.importPath`.

packages/api-extractor/src/api/ExtractorConfig.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ interface IExtractorConfigParameters {
209209
docModelIncludeForgottenExports: boolean;
210210
enumMemberOrder: EnumMemberOrder;
211211
mainEntryPointFilePath: string;
212+
mainEntryPointName: string;
212213
messages: IExtractorMessagesConfig;
213214
newlineKind: NewlineKind;
214215
omitTrimmingComments: boolean;
@@ -474,6 +475,7 @@ export class ExtractorConfig {
474475
projectFolder,
475476
packageJson,
476477
packageFolder,
478+
mainEntryPointName,
477479
mainEntryPointFilePath,
478480
additionalEntryPoints,
479481
bundledPackages,
@@ -509,7 +511,7 @@ export class ExtractorConfig {
509511
this.packageJson = packageJson;
510512
this.packageFolder = packageFolder;
511513
this.mainEntryPointFilePath = {
512-
modulePath: '',
514+
modulePath: mainEntryPointName,
513515
filePath: mainEntryPointFilePath,
514516
};
515517
this.additionalEntryPoints = additionalEntryPoints;
@@ -1003,6 +1005,8 @@ export class ExtractorConfig {
10031005
tokenContext,
10041006
);
10051007

1008+
const mainEntryPointName = configObject.mainEntryPointName ?? '';
1009+
10061010
if (!ExtractorConfig.hasDtsFileExtension(mainEntryPointFilePath)) {
10071011
throw new Error('The "mainEntryPointFilePath" value is not a declaration file: ' + mainEntryPointFilePath);
10081012
}
@@ -1289,6 +1293,7 @@ export class ExtractorConfig {
12891293
packageJson,
12901294
packageFolder,
12911295
mainEntryPointFilePath,
1296+
mainEntryPointName,
12921297
additionalEntryPoints,
12931298
bundledPackages,
12941299
tsconfigFilePath,

packages/api-extractor/src/api/IConfigFile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ export interface IConfigFile {
491491
*/
492492
mainEntryPointFilePath: string;
493493

494+
/**
495+
* Specifies the import path of the entrypoint used as the starting point for analysis.
496+
*/
497+
mainEntryPointName: string;
498+
494499
/**
495500
* {@inheritDoc IExtractorMessagesConfig}
496501
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export class ApiModelGenerator {
291291
docComment: packageDocComment,
292292
tsdocConfiguration: this._collector.extractorConfig.tsdocConfiguration,
293293
projectFolderUrl: this._collector.extractorConfig.projectFolderUrl,
294+
preserveMemberOrder: true,
294295
});
295296
this._apiModel.addMember(apiPackage);
296297

packages/api-extractor/src/schemas/api-extractor-defaults.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// ("mainEntryPointFilePath" is required)
55

6+
"mainEntryPointName": "",
7+
68
"bundledPackages": [],
79

810
"newlineKind": "crlf",

packages/api-extractor/src/schemas/api-extractor-template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
*/
4848
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
4949

50+
/**
51+
* Specifies the import path of the entrypoint used as the starting point for analysis.
52+
*/
53+
// "mainEntryPointName": "",
54+
5055
/**
5156
* A list of NPM package names whose exports should be treated as part of this package.
5257
*

0 commit comments

Comments
 (0)