Skip to content

Commit

Permalink
build: package api-extractor and -model (#9920)
Browse files Browse the repository at this point in the history
* fix(ExceptText): don't display import("d..-types/v10"). in return type

* Squashed 'packages/api-extractor-model/' content from commit 39ecb196c

git-subtree-dir: packages/api-extractor-model
git-subtree-split: 39ecb196ca210bdf84ba6c9cadb1bb93571849d7

* Squashed 'packages/api-extractor/' content from commit 341ad6c51

git-subtree-dir: packages/api-extractor
git-subtree-split: 341ad6c51b01656d4f73b74ad4bdb3095f9262c4

* feat(api-extractor): add api-extractor and -model

* fix: package.json docs script

* fix(SourcLink): use <> instead of function syntax

* fix: make packages private

* fix: rest params showing in docs, added labels

* fix: missed two files

* fix: cpy-cli & pnpm-lock

* fix: increase icon size

* fix: icon size again
  • Loading branch information
Qjuh authored Nov 7, 2023
1 parent 95c0b1a commit 5c0fad3
Show file tree
Hide file tree
Showing 251 changed files with 36,017 additions and 296 deletions.
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ apps:guide:
apps:website:
- apps/website/*
- apps/website/**/*
packages:api-extractor:
- packages/api-extractor/*
- packages/api-extractor/**/*
packages:api-extractor-model:
- packages/api-extractor-model/*
- packages/api-extractor-model/**/*
packages:brokers:
- packages/brokers/*
- packages/brokers/**/*
Expand Down
4 changes: 4 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
color: e4e669
- name: need repro
color: c66037
- name: packages:api-extractor
color: fbca04
- name: packages:api-extractor-model
color: fbca04
- name: packages:brokers
color: fbca04
- name: packages:builders
Expand Down
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ resolution-mode=highest
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*@rushstack/node-core-library*
public-hoist-pattern[]=*@microsoft/api-extractor-model*
public-hoist-pattern[]=*jju*
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
/**
* (REQUIRED) Whether to generate the .d.ts rollup file.
*/
"enabled": true,
"enabled": false,

/**
* Specifies the output path for a .d.ts rollup file to be generated without any trimming.
Expand Down
2 changes: 1 addition & 1 deletion apps/website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default withBundleAnalyzer({
reactStrictMode: true,
experimental: {
typedRoutes: true,
serverComponentsExternalPackages: ['@rushstack/node-core-library', '@microsoft/api-extractor-model', 'jju'],
serverComponentsExternalPackages: ['@rushstack/node-core-library', '@discordjs/api-extractor-model', 'jju'],
},
images: {
dangerouslyAllowSVG: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@discordjs/api-extractor-utils": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@discordjs/ui": "workspace:^",
"@microsoft/api-extractor-model": "^7.28.2",
"@discordjs/api-extractor-model": "workspace:^",
"@microsoft/tsdoc": "^0.14.2",
"@microsoft/tsdoc-config": "0.16.2",
"@planetscale/database": "^1.11.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/app/api/dynamic-open-graph.png/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-unknown-property */

import type { ApiItemKind } from '@microsoft/api-extractor-model';
import type { ApiItemKind } from '@discordjs/api-extractor-model';
import { ImageResponse } from '@vercel/og';
import type { NextRequest } from 'next/server';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { tryResolveSummaryText } from '@discordjs/scripts';
import type {
ApiClass,
ApiDeclaredItem,
Expand All @@ -13,8 +12,9 @@ import type {
ApiTypeAlias,
ApiVariable,
ApiFunction,
} from '@microsoft/api-extractor-model';
import { ApiItemKind, ApiModel } from '@microsoft/api-extractor-model';
} from '@discordjs/api-extractor-model';
import { ApiItemKind, ApiModel } from '@discordjs/api-extractor-model';
import { tryResolveSummaryText } from '@discordjs/scripts';
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { fetchModelJSON } from '~/app/docAPI';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApiFunction, ApiItem } from '@microsoft/api-extractor-model';
import { ApiModel } from '@microsoft/api-extractor-model';
import type { ApiFunction, ApiItem } from '@discordjs/api-extractor-model';
import { ApiModel } from '@discordjs/api-extractor-model';
import dynamic from 'next/dynamic';
import { notFound } from 'next/navigation';
import type { PropsWithChildren } from 'react';
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/Badges.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApiDocumentedItem } from '@microsoft/api-extractor-model';
import { ApiAbstractMixin, ApiProtectedMixin, ApiReadonlyMixin, ApiStaticMixin } from '@microsoft/api-extractor-model';
import type { ApiDocumentedItem } from '@discordjs/api-extractor-model';
import { ApiAbstractMixin, ApiProtectedMixin, ApiReadonlyMixin, ApiStaticMixin } from '@discordjs/api-extractor-model';
import type { PropsWithChildren } from 'react';

export enum BadgeColor {
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/CmdK.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import type { ApiItemKind } from '@microsoft/api-extractor-model';
import type { ApiItemKind } from '@discordjs/api-extractor-model';
import { VscArrowRight } from '@react-icons/all-files/vsc/VscArrowRight';
import { VscSymbolClass } from '@react-icons/all-files/vsc/VscSymbolClass';
import { VscSymbolEnum } from '@react-icons/all-files/vsc/VscSymbolEnum';
Expand Down
24 changes: 18 additions & 6 deletions apps/website/src/components/CodeHeading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import { Anchor } from './Anchor';
import { SourceLink } from './documentation/SourceLink';

export interface CodeListingProps {
/**
Expand All @@ -14,15 +15,26 @@ export interface CodeListingProps {
* The href of this heading.
*/
readonly href?: string | undefined;
/**
* The line in the source code where this part is declared
*/
readonly sourceLine?: number | undefined;
/**
* The URL of the source code of this code part
*/
readonly sourceURL?: string | undefined;
}

export function CodeHeading({ href, className, children }: CodeListingProps) {
export function CodeHeading({ href, className, children, sourceURL, sourceLine }: CodeListingProps) {
return (
<div
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
>
{href ? <Anchor href={href} /> : null}
{children}
<div className="flex flex-row place-items-center justify-between gap-1">
<div
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
>
{href ? <Anchor href={href} /> : null}
{children}
</div>
{sourceURL ? <SourceLink className="text-2xl" sourceLine={sourceLine} sourceURL={sourceURL} /> : null}
</div>
);
}
6 changes: 3 additions & 3 deletions apps/website/src/components/ExcerptText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApiModel, Excerpt } from '@microsoft/api-extractor-model';
import { ExcerptTokenKind } from '@microsoft/api-extractor-model';
import type { ApiModel, Excerpt } from '@discordjs/api-extractor-model';
import { ExcerptTokenKind } from '@discordjs/api-extractor-model';
import { DISCORD_API_TYPES_DOCS_URL } from '~/util/constants';
import { ItemLink } from './ItemLink';
import { resolveItemURI } from './documentation/util';
Expand Down Expand Up @@ -60,7 +60,7 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
);
}

return token.text;
return token.text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
})}
</span>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/InheritanceText.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDeclaredItem } from '@microsoft/api-extractor-model';
import type { ApiDeclaredItem } from '@discordjs/api-extractor-model';
import { ItemLink } from './ItemLink';
import { resolveItemURI } from './documentation/util';

Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/ParameterTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDocumentedItem, ApiParameterListMixin } from '@microsoft/api-extractor-model';
import type { ApiDocumentedItem, ApiParameterListMixin } from '@discordjs/api-extractor-model';
import { useMemo } from 'react';
import { resolveParameters } from '~/util/model';
import { ExcerptText } from './ExcerptText';
Expand All @@ -16,7 +16,7 @@ export function ParameterTable({ item }: { readonly item: ApiDocumentedItem & Ap
const rows = useMemo(
() =>
params.map((param) => ({
Name: param.name,
Name: param.isRest ? `...${param.name}` : param.name,
Type: <ExcerptText excerpt={param.parameterTypeExcerpt} model={item.getAssociatedModel()!} />,
Optional: param.isOptional ? 'Yes' : 'No',
Description: param.description ? <TSDoc item={item} tsdoc={param.description} /> : 'None',
Expand Down
8 changes: 6 additions & 2 deletions apps/website/src/components/Property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ApiItemContainerMixin,
ApiProperty,
ApiPropertySignature,
} from '@microsoft/api-extractor-model';
} from '@discordjs/api-extractor-model';
import type { PropsWithChildren } from 'react';
import { Badges } from './Badges';
import { CodeHeading } from './CodeHeading';
Expand All @@ -25,7 +25,11 @@ export function Property({
<div className="flex flex-col scroll-mt-30 gap-4" id={item.displayName}>
<div className="flex flex-col gap-2 md:-ml-9">
<Badges item={item} />
<CodeHeading href={`#${item.displayName}`}>
<CodeHeading
href={`#${item.displayName}`}
sourceURL={item.sourceLocation.fileUrl}
sourceLine={item.sourceLocation.fileLine}
>
{`${item.displayName}${item.isOptional ? '?' : ''}`}
<span>:</span>
{item.propertyTypeExcerpt.text ? (
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/PropertyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
ApiItemContainerMixin,
ApiProperty,
ApiPropertySignature,
} from '@microsoft/api-extractor-model';
import { ApiItemKind } from '@microsoft/api-extractor-model';
} from '@discordjs/api-extractor-model';
import { ApiItemKind } from '@discordjs/api-extractor-model';
import { Fragment, useMemo } from 'react';
import { resolveMembers } from '~/util/members';
import { Property } from './Property';
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import type { ApiItemKind } from '@microsoft/api-extractor-model';
import type { ApiItemKind } from '@discordjs/api-extractor-model';
import { VscSymbolClass } from '@react-icons/all-files/vsc/VscSymbolClass';
import { VscSymbolEnum } from '@react-icons/all-files/vsc/VscSymbolEnum';
import { VscSymbolInterface } from '@react-icons/all-files/vsc/VscSymbolInterface';
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/SignatureText.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiModel, Excerpt } from '@microsoft/api-extractor-model';
import type { ApiModel, Excerpt } from '@discordjs/api-extractor-model';
import { ExcerptText } from './ExcerptText';

export function SignatureText({ excerpt, model }: { readonly excerpt: Excerpt; readonly model: ApiModel }) {
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/TypeParamTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiTypeParameterListMixin } from '@microsoft/api-extractor-model';
import type { ApiTypeParameterListMixin } from '@discordjs/api-extractor-model';
import { useMemo } from 'react';
import { ExcerptText } from './ExcerptText';
import { Table } from './Table';
Expand Down
18 changes: 10 additions & 8 deletions apps/website/src/components/documentation/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApiItemKind } from '@microsoft/api-extractor-model';
import { VscFileCode } from '@react-icons/all-files/vsc/VscFileCode';
import { ApiItemKind } from '@discordjs/api-extractor-model';
import { VscSymbolClass } from '@react-icons/all-files/vsc/VscSymbolClass';
import { VscSymbolEnum } from '@react-icons/all-files/vsc/VscSymbolEnum';
import { VscSymbolInterface } from '@react-icons/all-files/vsc/VscSymbolInterface';
import { VscSymbolMethod } from '@react-icons/all-files/vsc/VscSymbolMethod';
import { VscSymbolVariable } from '@react-icons/all-files/vsc/VscSymbolVariable';
import type { PropsWithChildren } from 'react';
import { SourceLink } from './SourceLink';

function generateIcon(kind: ApiItemKind) {
switch (kind) {
Expand All @@ -30,19 +30,21 @@ export function Header({
kind,
name,
sourceURL,
}: PropsWithChildren<{ readonly kind: ApiItemKind; readonly name: string; readonly sourceURL?: string | undefined }>) {
sourceLine,
}: PropsWithChildren<{
readonly kind: ApiItemKind;
readonly name: string;
readonly sourceLine?: number | undefined;
readonly sourceURL?: string | undefined;
}>) {
return (
<div className="flex flex-col">
<h2 className="flex flex-row place-items-center justify-between gap-2 break-all text-2xl font-bold">
<span className="row flex flex place-items-center gap-2">
<span>{generateIcon(kind)}</span>
{name}
</span>
{sourceURL ? (
<a className="text-blurple" href={sourceURL} rel="external noopener noreferrer" target="_blank">
<VscFileCode />
</a>
) : null}
{sourceURL ? <SourceLink sourceLine={sourceLine} sourceURL={sourceURL} /> : null}
</h2>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/documentation/HierarchyText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApiClass, ApiInterface, Excerpt } from '@microsoft/api-extractor-model';
import { ApiItemKind } from '@microsoft/api-extractor-model';
import type { ApiClass, ApiInterface, Excerpt } from '@discordjs/api-extractor-model';
import { ApiItemKind } from '@discordjs/api-extractor-model';
import { ExcerptText } from '../ExcerptText';

export function HierarchyText({
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/documentation/Members.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDeclaredItem, ApiItemContainerMixin } from '@microsoft/api-extractor-model';
import type { ApiDeclaredItem, ApiItemContainerMixin } from '@discordjs/api-extractor-model';
import { MethodsSection } from './section/MethodsSection';
import { PropertiesSection } from './section/PropertiesSection';
import { hasProperties, hasMethods } from './util';
Expand Down
9 changes: 7 additions & 2 deletions apps/website/src/components/documentation/ObjectHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDeclaredItem } from '@microsoft/api-extractor-model';
import type { ApiDeclaredItem } from '@discordjs/api-extractor-model';
import { SyntaxHighlighter } from '../SyntaxHighlighter';
import { Header } from './Header';
import { SummarySection } from './section/SummarySection';
Expand All @@ -10,7 +10,12 @@ export interface ObjectHeaderProps {
export function ObjectHeader({ item }: ObjectHeaderProps) {
return (
<>
<Header kind={item.kind} name={item.displayName} sourceURL={item.sourceLocation.fileUrl} />
<Header
kind={item.kind}
name={item.displayName}
sourceURL={item.sourceLocation.fileUrl}
sourceLine={item.sourceLocation.fileLine}
/>
{/* @ts-expect-error async component */}
<SyntaxHighlighter code={item.excerpt.text} />
<SummarySection item={item} />
Expand Down
22 changes: 22 additions & 0 deletions apps/website/src/components/documentation/SourceLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { VscFileCode } from '@react-icons/all-files/vsc/VscFileCode';

export function SourceLink({
className,
sourceURL,
sourceLine,
}: {
readonly className?: string | undefined;
readonly sourceLine?: number | undefined;
readonly sourceURL?: string | undefined;
}) {
return (
<a
className={` text-blurple ${className}`}
href={sourceLine ? `${sourceURL}#L${sourceLine}` : sourceURL}
rel="external noopener noreferrer"
target="_blank"
>
<VscFileCode />
</a>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiConstructor } from '@microsoft/api-extractor-model';
import type { ApiConstructor } from '@discordjs/api-extractor-model';
import { VscSymbolMethod } from '@react-icons/all-files/vsc/VscSymbolMethod';
import { CodeHeading } from '~/components/CodeHeading';
import { ParameterTable } from '../../ParameterTable';
Expand All @@ -10,7 +10,10 @@ export function ConstructorSection({ item }: { readonly item: ApiConstructor })
return (
<DocumentationSection icon={<VscSymbolMethod size={20} />} padded title="Constructor">
<div className="flex flex-col gap-2">
<CodeHeading>{`constructor(${parametersString(item)})`}</CodeHeading>
<CodeHeading
sourceURL={item.sourceLocation.fileUrl}
sourceLine={item.sourceLocation.fileLine}
>{`constructor(${parametersString(item)})`}</CodeHeading>
{item.tsdocComment ? <TSDoc item={item} tsdoc={item.tsdocComment} /> : null}
<ParameterTable item={item} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
ApiItemContainerMixin,
ApiMethod,
ApiMethodSignature,
} from '@microsoft/api-extractor-model';
import { ApiItemKind } from '@microsoft/api-extractor-model';
} from '@discordjs/api-extractor-model';
import { ApiItemKind } from '@discordjs/api-extractor-model';
import { VscSymbolMethod } from '@react-icons/all-files/vsc/VscSymbolMethod';
import { useMemo, Fragment } from 'react';
import { resolveMembers } from '~/util/members';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDocumentedItem, ApiParameterListMixin } from '@microsoft/api-extractor-model';
import type { ApiDocumentedItem, ApiParameterListMixin } from '@discordjs/api-extractor-model';
import { VscSymbolParameter } from '@react-icons/all-files/vsc/VscSymbolParameter';
import { ParameterTable } from '../../ParameterTable';
import { DocumentationSection } from './DocumentationSection';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiItemContainerMixin } from '@microsoft/api-extractor-model';
import type { ApiItemContainerMixin } from '@discordjs/api-extractor-model';
import { VscSymbolProperty } from '@react-icons/all-files/vsc/VscSymbolProperty';
import { PropertyList } from '../../PropertyList';
import { DocumentationSection } from './DocumentationSection';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiDeclaredItem } from '@microsoft/api-extractor-model';
import type { ApiDeclaredItem } from '@discordjs/api-extractor-model';
import { VscListSelection } from '@react-icons/all-files/vsc/VscListSelection';
import { TSDoc } from '../tsdoc/TSDoc';
import { DocumentationSection } from './DocumentationSection';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiTypeParameterListMixin } from '@microsoft/api-extractor-model';
import type { ApiTypeParameterListMixin } from '@discordjs/api-extractor-model';
import { VscSymbolParameter } from '@react-icons/all-files/vsc/VscSymbolParameter';
import { TypeParamTable } from '../../TypeParamTable';
import { DocumentationSection } from './DocumentationSection';
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/documentation/tsdoc/TSDoc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApiItem } from '@microsoft/api-extractor-model';
import type { ApiItem } from '@discordjs/api-extractor-model';
import type { DocComment, DocFencedCode, DocLinkTag, DocNode, DocNodeContainer, DocPlainText } from '@microsoft/tsdoc';
import { DocNodeKind, StandardTags } from '@microsoft/tsdoc';
import type { Route } from 'next';
Expand Down
Loading

1 comment on commit 5c0fad3

@vercel
Copy link

@vercel vercel bot commented on 5c0fad3 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.