From 099c6464ed4545e9a8c9a37a39741d95c24d0045 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Tue, 3 May 2022 17:49:29 +0800 Subject: [PATCH] fix(*): make TypeScript realize that each plugin package has a default export --- .../package.json | 2 +- .../src/__tests__/collectRedirects.test.ts | 2 +- .../src/__tests__/options.test.ts | 2 +- .../src/collectRedirects.ts | 5 +- .../src/index.ts | 3 +- .../src/options.ts | 31 ++++++- .../src/plugin-client-redirects.d.ts | 32 ------- .../src/types.ts | 2 +- .../src/blogUtils.ts | 11 +-- .../src/feed.ts | 2 +- .../src/index.ts | 13 +-- .../src/plugin-content-blog.d.ts | 93 +++++++++++++------ .../src/translations.ts | 7 +- .../src/types.ts | 34 +------ .../src/docs.ts | 3 +- .../src/index.ts | 4 +- .../src/plugin-content-docs.d.ts | 16 ++++ .../src/props.ts | 3 +- .../src/translations.ts | 5 +- .../src/types.ts | 13 +-- .../src/index.ts | 8 +- .../src/plugin-content-pages.d.ts | 8 ++ .../src/types.ts | 4 - packages/docusaurus-plugin-debug/src/index.ts | 2 +- .../src/plugin-debug.d.ts | 6 ++ .../package.json | 2 +- .../src/index.ts | 4 +- ...lugin-google-analytics.d.ts => options.ts} | 0 .../package.json | 2 +- .../docusaurus-plugin-google-gtag/src/gtag.ts | 2 +- .../src/index.ts | 4 +- .../{plugin-google-gtag.d.ts => options.ts} | 0 .../docusaurus-plugin-sitemap/package.json | 2 +- .../src/__tests__/options.test.ts | 3 +- .../src/createSitemap.ts | 4 +- .../docusaurus-plugin-sitemap/src/index.ts | 3 +- .../docusaurus-plugin-sitemap/src/options.ts | 15 ++- .../src/plugin-sitemap.d.ts | 22 ----- .../docusaurus-preset-classic/package.json | 2 +- .../docusaurus-preset-classic/src/index.ts | 4 +- .../src/{preset-classic.d.ts => options.ts} | 0 .../src/theme-classic.d.ts | 4 +- 42 files changed, 199 insertions(+), 185 deletions(-) delete mode 100644 packages/docusaurus-plugin-client-redirects/src/plugin-client-redirects.d.ts rename packages/docusaurus-plugin-google-analytics/src/{plugin-google-analytics.d.ts => options.ts} (100%) rename packages/docusaurus-plugin-google-gtag/src/{plugin-google-gtag.d.ts => options.ts} (100%) delete mode 100644 packages/docusaurus-plugin-sitemap/src/plugin-sitemap.d.ts rename packages/docusaurus-preset-classic/src/{preset-classic.d.ts => options.ts} (100%) diff --git a/packages/docusaurus-plugin-client-redirects/package.json b/packages/docusaurus-plugin-client-redirects/package.json index 5cd0e10161688..43565ecb24a72 100644 --- a/packages/docusaurus-plugin-client-redirects/package.json +++ b/packages/docusaurus-plugin-client-redirects/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.18", "description": "Client redirects plugin for Docusaurus.", "main": "lib/index.js", - "types": "src/plugin-client-redirects.d.ts", + "types": "lib/index.d.ts", "scripts": { "build": "tsc", "watch": "tsc --watch" diff --git a/packages/docusaurus-plugin-client-redirects/src/__tests__/collectRedirects.test.ts b/packages/docusaurus-plugin-client-redirects/src/__tests__/collectRedirects.test.ts index 3e7f47e5f853f..266b36911ee37 100644 --- a/packages/docusaurus-plugin-client-redirects/src/__tests__/collectRedirects.test.ts +++ b/packages/docusaurus-plugin-client-redirects/src/__tests__/collectRedirects.test.ts @@ -10,7 +10,7 @@ import collectRedirects from '../collectRedirects'; import {validateOptions} from '../options'; import {removeTrailingSlash} from '@docusaurus/utils'; import {normalizePluginOptions} from '@docusaurus/utils-validation'; -import type {Options} from '@docusaurus/plugin-client-redirects'; +import type {Options} from '../options'; function createTestPluginContext( options?: Options, diff --git a/packages/docusaurus-plugin-client-redirects/src/__tests__/options.test.ts b/packages/docusaurus-plugin-client-redirects/src/__tests__/options.test.ts index 0354dcfe995ae..3243076acba15 100644 --- a/packages/docusaurus-plugin-client-redirects/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-client-redirects/src/__tests__/options.test.ts @@ -7,7 +7,7 @@ import {validateOptions, DEFAULT_OPTIONS} from '../options'; import {normalizePluginOptions} from '@docusaurus/utils-validation'; -import type {Options} from '@docusaurus/plugin-client-redirects'; +import type {Options} from '../options'; function testValidate(options: Options) { return validateOptions({validate: normalizePluginOptions, options}); diff --git a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts index 9fb14e85a239f..8a62cae4f4ab2 100644 --- a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts +++ b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts @@ -6,10 +6,7 @@ */ import _ from 'lodash'; -import type { - PluginOptions, - RedirectOption, -} from '@docusaurus/plugin-client-redirects'; +import type {PluginOptions, RedirectOption} from './options'; import type {PluginContext, RedirectMetadata} from './types'; import { createFromExtensionsRedirects, diff --git a/packages/docusaurus-plugin-client-redirects/src/index.ts b/packages/docusaurus-plugin-client-redirects/src/index.ts index 21ec1195f3739..9bfac10d94987 100644 --- a/packages/docusaurus-plugin-client-redirects/src/index.ts +++ b/packages/docusaurus-plugin-client-redirects/src/index.ts @@ -7,7 +7,7 @@ import type {LoadContext, Plugin} from '@docusaurus/types'; import type {PluginContext, RedirectMetadata} from './types'; -import type {PluginOptions} from '@docusaurus/plugin-client-redirects'; +import type {PluginOptions, Options} from './options'; import collectRedirects from './collectRedirects'; import writeRedirectFiles, { @@ -52,3 +52,4 @@ export default function pluginClientRedirectsPages( } export {validateOptions} from './options'; +export type {PluginOptions, Options}; diff --git a/packages/docusaurus-plugin-client-redirects/src/options.ts b/packages/docusaurus-plugin-client-redirects/src/options.ts index d81b535482b80..34891a1c9b706 100644 --- a/packages/docusaurus-plugin-client-redirects/src/options.ts +++ b/packages/docusaurus-plugin-client-redirects/src/options.ts @@ -5,14 +5,35 @@ * LICENSE file in the root directory of this source tree. */ -import type { - PluginOptions, - Options, - RedirectOption, -} from '@docusaurus/plugin-client-redirects'; import type {OptionValidationContext} from '@docusaurus/types'; import {Joi, PathnameSchema} from '@docusaurus/utils-validation'; +export type RedirectOption = { + to: string; + from: string | string[]; +}; + +export type PluginOptions = { + /** Plugin ID. */ + id: string; + /** The extensions to be removed from the route after redirecting. */ + fromExtensions: string[]; + /** The extensions to be appended to the route after redirecting. */ + toExtensions: string[]; + /** The list of redirect rules, each one with multiple `from`s → one `to`. */ + redirects: RedirectOption[]; + /** + * A callback to create a redirect rule. + * @returns All the paths from which we should redirect to `path` + */ + createRedirects?: ( + /** An existing Docusaurus route path */ + path: string, + ) => string[] | string | null | undefined; +}; + +export type Options = Partial; + export const DEFAULT_OPTIONS: Partial = { fromExtensions: [], toExtensions: [], diff --git a/packages/docusaurus-plugin-client-redirects/src/plugin-client-redirects.d.ts b/packages/docusaurus-plugin-client-redirects/src/plugin-client-redirects.d.ts deleted file mode 100644 index a943eace5e8fb..0000000000000 --- a/packages/docusaurus-plugin-client-redirects/src/plugin-client-redirects.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -export type RedirectOption = { - to: string; - from: string | string[]; -}; - -export type PluginOptions = { - /** Plugin ID. */ - id: string; - /** The extensions to be removed from the route after redirecting. */ - fromExtensions: string[]; - /** The extensions to be appended to the route after redirecting. */ - toExtensions: string[]; - /** The list of redirect rules, each one with multiple `from`s → one `to`. */ - redirects: RedirectOption[]; - /** - * A callback to create a redirect rule. - * @returns All the paths from which we should redirect to `path` - */ - createRedirects?: ( - /** An existing Docusaurus route path */ - path: string, - ) => string[] | string | null | undefined; -}; - -export type Options = Partial; diff --git a/packages/docusaurus-plugin-client-redirects/src/types.ts b/packages/docusaurus-plugin-client-redirects/src/types.ts index ca0f61a6fb017..8ad61ae06c476 100644 --- a/packages/docusaurus-plugin-client-redirects/src/types.ts +++ b/packages/docusaurus-plugin-client-redirects/src/types.ts @@ -6,7 +6,7 @@ */ import type {Props} from '@docusaurus/types'; -import type {PluginOptions} from '@docusaurus/plugin-client-redirects'; +import type {PluginOptions} from './options'; /** * The minimal infos the plugin needs to work diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 6b839cee9d42b..5daf3983e09a6 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -9,13 +9,7 @@ import fs from 'fs-extra'; import path from 'path'; import readingTime from 'reading-time'; import _ from 'lodash'; -import type { - BlogPost, - BlogContentPaths, - BlogMarkdownLoaderOptions, - BlogTags, - BlogPaginated, -} from './types'; +import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types'; import { parseMarkdownString, normalizeUrl, @@ -37,6 +31,9 @@ import logger from '@docusaurus/logger'; import type { PluginOptions, ReadingTimeFunction, + BlogPost, + BlogTags, + BlogPaginated, } from '@docusaurus/plugin-content-blog'; export function truncate(fileString: string, truncateMarker: RegExp): string { diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index af453979243ce..0a465f8582a78 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -6,7 +6,6 @@ */ import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed'; -import type {BlogPost} from './types'; import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; import {load as cheerioLoad} from 'cheerio'; import type {DocusaurusConfig} from '@docusaurus/types'; @@ -16,6 +15,7 @@ import type { FeedType, PluginOptions, Author, + BlogPost, } from '@docusaurus/plugin-content-blog'; import {blogPostContainerID} from '@docusaurus/utils-common'; diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 57fc7840ea039..3b19b9bbab2ef 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -25,14 +25,7 @@ import { } from '@docusaurus/utils'; import {translateContent, getTranslationFiles} from './translations'; -import type { - BlogTag, - BlogTags, - BlogContent, - BlogPaginated, - BlogContentPaths, - BlogMarkdownLoaderOptions, -} from './types'; +import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types'; import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types'; import { generateBlogPosts, @@ -46,6 +39,10 @@ import type { BlogPostFrontMatter, BlogPostMetadata, Assets, + BlogTag, + BlogTags, + BlogContent, + BlogPaginated, } from '@docusaurus/plugin-content-blog'; export default async function pluginContentBlog( diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index e17128655bc4e..d74bba9fc2747 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -8,6 +8,7 @@ declare module '@docusaurus/plugin-content-blog' { import type {MDXOptions} from '@docusaurus/mdx-loader'; import type {FrontMatterTag, Tag} from '@docusaurus/utils'; + import type {Plugin, LoadContext} from '@docusaurus/types'; import type {Overwrite} from 'utility-types'; export type Assets = { @@ -410,6 +411,62 @@ declare module '@docusaurus/plugin-content-blog' { title: string; items: {title: string; permalink: string}[]; }; + + export type BlogContent = { + blogSidebarTitle: string; + blogPosts: BlogPost[]; + blogListPaginated: BlogPaginated[]; + blogTags: BlogTags; + blogTagsListPath: string; + }; + + export type BlogTags = { + [permalink: string]: BlogTag; + }; + + export type BlogTag = Tag & { + /** Blog post permalinks. */ + items: string[]; + pages: BlogPaginated[]; + }; + + export type BlogPost = { + id: string; + metadata: BlogPostMetadata; + content: string; + }; + + export type BlogPaginatedMetadata = { + /** Title of the entire blog. */ + readonly blogTitle: string; + /** Blog description. */ + readonly blogDescription: string; + /** Permalink to the next list page. */ + readonly nextPage?: string; + /** Permalink of the current page. */ + readonly permalink: string; + /** Permalink to the previous list page. */ + readonly previousPage?: string; + /** Index of the current page, 1-based. */ + readonly page: number; + /** Posts displayed on each list page. */ + readonly postsPerPage: number; + /** Total number of posts in the entire blog. */ + readonly totalCount: number; + /** Total number of list pages. */ + readonly totalPages: number; + }; + + export type BlogPaginated = { + metadata: BlogPaginatedMetadata; + /** Blog post permalinks. */ + items: string[]; + }; + + export default function pluginContentBlog( + context: LoadContext, + options: PluginOptions, + ): Promise>; } declare module '@theme/BlogPostPage' { @@ -446,34 +503,16 @@ declare module '@theme/BlogPostPage' { declare module '@theme/BlogListPage' { import type {Content} from '@theme/BlogPostPage'; - import type {BlogSidebar} from '@docusaurus/plugin-content-blog'; - - export type Metadata = { - /** Title of the entire blog. */ - readonly blogTitle: string; - /** Blog description. */ - readonly blogDescription: string; - /** Permalink to the next list page. */ - readonly nextPage?: string; - /** Permalink of the current page. */ - readonly permalink: string; - /** Permalink to the previous list page. */ - readonly previousPage?: string; - /** Index of the current page, 1-based. */ - readonly page: number; - /** Posts displayed on each list page. */ - readonly postsPerPage: number; - /** Total number of posts in the entire blog. */ - readonly totalCount: number; - /** Total number of list pages. */ - readonly totalPages: number; - }; + import type { + BlogSidebar, + BlogPaginatedMetadata, + } from '@docusaurus/plugin-content-blog'; export interface Props { /** Blog sidebar. */ readonly sidebar: BlogSidebar; /** Metadata of the current listing page. */ - readonly metadata: Metadata; + readonly metadata: BlogPaginatedMetadata; /** * Array of blog posts included on this page. Every post's metadata is also * available. @@ -499,9 +538,11 @@ declare module '@theme/BlogTagsListPage' { } declare module '@theme/BlogTagsPostsPage' { - import type {BlogSidebar} from '@docusaurus/plugin-content-blog'; + import type { + BlogSidebar, + BlogPaginatedMetadata, + } from '@docusaurus/plugin-content-blog'; import type {Content} from '@theme/BlogPostPage'; - import type {Metadata} from '@theme/BlogListPage'; import type {TagModule} from '@docusaurus/utils'; export interface Props { @@ -510,7 +551,7 @@ declare module '@theme/BlogTagsPostsPage' { /** Metadata of this tag. */ readonly tag: TagModule; /** Looks exactly the same as the posts list page */ - readonly listMetadata: Metadata; + readonly listMetadata: BlogPaginatedMetadata; /** * Array of blog posts included on this page. Every post's metadata is also * available. diff --git a/packages/docusaurus-plugin-content-blog/src/translations.ts b/packages/docusaurus-plugin-content-blog/src/translations.ts index 28c233dd99c82..9cf763de3b429 100644 --- a/packages/docusaurus-plugin-content-blog/src/translations.ts +++ b/packages/docusaurus-plugin-content-blog/src/translations.ts @@ -5,9 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import type {BlogContent, BlogPaginated} from './types'; import type {TranslationFileContent, TranslationFile} from '@docusaurus/types'; -import type {PluginOptions} from '@docusaurus/plugin-content-blog'; +import type { + PluginOptions, + BlogContent, + BlogPaginated, +} from '@docusaurus/plugin-content-blog'; function translateListPage( blogListPaginated: BlogPaginated[], diff --git a/packages/docusaurus-plugin-content-blog/src/types.ts b/packages/docusaurus-plugin-content-blog/src/types.ts index f40e57e00adfd..9774a412300fc 100644 --- a/packages/docusaurus-plugin-content-blog/src/types.ts +++ b/packages/docusaurus-plugin-content-blog/src/types.ts @@ -5,42 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import type {BrokenMarkdownLink, ContentPaths, Tag} from '@docusaurus/utils'; -import type {BlogPostMetadata} from '@docusaurus/plugin-content-blog'; -import type {Metadata as BlogPaginatedMetadata} from '@theme/BlogListPage'; +import type {BrokenMarkdownLink, ContentPaths} from '@docusaurus/utils'; export type BlogContentPaths = ContentPaths; -export type BlogContent = { - blogSidebarTitle: string; - blogPosts: BlogPost[]; - blogListPaginated: BlogPaginated[]; - blogTags: BlogTags; - blogTagsListPath: string; -}; - -export type BlogTags = { - [permalink: string]: BlogTag; -}; - -export type BlogTag = Tag & { - /** Blog post permalinks. */ - items: string[]; - pages: BlogPaginated[]; -}; - -export type BlogPost = { - id: string; - metadata: BlogPostMetadata; - content: string; -}; - -export type BlogPaginated = { - metadata: BlogPaginatedMetadata; - /** Blog post permalinks. */ - items: string[]; -}; - export type BlogBrokenMarkdownLink = BrokenMarkdownLink; export type BlogMarkdownLoaderOptions = { siteDir: string; diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 1c04edc05efee..7f631f21c7814 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -22,7 +22,7 @@ import { import type {LoadContext} from '@docusaurus/types'; import {getFileLastUpdate} from './lastUpdate'; -import type {DocFile, LoadedVersion} from './types'; +import type {DocFile} from './types'; import getSlug from './slug'; import {CURRENT_VERSION_NAME} from './constants'; import {stripPathNumberPrefixes} from './numberPrefix'; @@ -39,6 +39,7 @@ import type { LastUpdateData, VersionMetadata, DocFrontMatter, + LoadedVersion, } from '@docusaurus/plugin-content-docs'; type LastUpdateOptions = Pick< diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 3c0c0a9531dff..b4c72107f3129 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -26,9 +26,7 @@ import type {DocEnv} from './docs'; import {readVersionDocs, processDocMetadata, addDocNavigation} from './docs'; import {readVersionsMetadata} from './versions'; import type { - LoadedContent, SourceToPermalink, - LoadedVersion, DocFile, DocsMarkdownOption, VersionTag, @@ -53,6 +51,8 @@ import type { DocMetadataBase, VersionMetadata, DocFrontMatter, + LoadedContent, + LoadedVersion, } from '@docusaurus/plugin-content-docs'; import {createSidebarsUtils} from './sidebars/utils'; import _ from 'lodash'; diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 644477d0375b1..412a08cdb08f6 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -14,6 +14,7 @@ declare module '@docusaurus/plugin-content-docs' { TagModule, Tag, } from '@docusaurus/utils'; + import type {Plugin, LoadContext} from '@docusaurus/types'; import type {Required} from 'utility-types'; export type Assets = { @@ -504,6 +505,21 @@ declare module '@docusaurus/plugin-content-docs' { export type PropTagsListPage = { tags: TagsListItem[]; }; + + export type LoadedVersion = VersionMetadata & { + docs: DocMetadata[]; + drafts: DocMetadata[]; + sidebars: import('./sidebars/types').Sidebars; + }; + + export type LoadedContent = { + loadedVersions: LoadedVersion[]; + }; + + export default function pluginContentDocs( + context: LoadContext, + options: PluginOptions, + ): Promise>; } declare module '@theme/DocItem' { diff --git a/packages/docusaurus-plugin-content-docs/src/props.ts b/packages/docusaurus-plugin-content-docs/src/props.ts index 43d3028d455c6..bf4393c631ffc 100644 --- a/packages/docusaurus-plugin-content-docs/src/props.ts +++ b/packages/docusaurus-plugin-content-docs/src/props.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import type {LoadedVersion, VersionTag} from './types'; +import type {VersionTag} from './types'; import type { SidebarItemDoc, SidebarItem, @@ -22,6 +22,7 @@ import type { PropSidebarItemLink, PropVersionDocs, DocMetadata, + LoadedVersion, } from '@docusaurus/plugin-content-docs'; import _ from 'lodash'; import {createDocsByIdIndex} from './docs'; diff --git a/packages/docusaurus-plugin-content-docs/src/translations.ts b/packages/docusaurus-plugin-content-docs/src/translations.ts index 10b058defa571..f5f2f7e719164 100644 --- a/packages/docusaurus-plugin-content-docs/src/translations.ts +++ b/packages/docusaurus-plugin-content-docs/src/translations.ts @@ -5,7 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import type {LoadedVersion, LoadedContent} from './types'; +import type { + LoadedVersion, + LoadedContent, +} from '@docusaurus/plugin-content-docs'; import type { Sidebar, SidebarItemCategory, diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index ee964f533e033..df3579b856d86 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -7,12 +7,11 @@ /// -import type {Sidebars} from './sidebars/types'; import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils'; import type { VersionMetadata, LastUpdateData, - DocMetadata, + LoadedVersion, CategoryGeneratedIndexMetadata, } from '@docusaurus/plugin-content-docs'; import type {SidebarsUtils} from './sidebars/utils'; @@ -37,16 +36,6 @@ export type VersionTags = { [permalink: string]: VersionTag; }; -export type LoadedVersion = VersionMetadata & { - docs: DocMetadata[]; - drafts: DocMetadata[]; - sidebars: Sidebars; -}; - -export type LoadedContent = { - loadedVersions: LoadedVersion[]; -}; - export type FullVersion = LoadedVersion & { sidebarsUtils: SidebarsUtils; categoryGeneratedIndices: CategoryGeneratedIndexMetadata[]; diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index c205743e6a007..5bd819610ba1f 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -25,8 +25,12 @@ import type {LoadContext, Plugin} from '@docusaurus/types'; import admonitions from 'remark-admonitions'; import {validatePageFrontMatter} from './frontMatter'; -import type {LoadedContent, PagesContentPaths} from './types'; -import type {PluginOptions, Metadata} from '@docusaurus/plugin-content-pages'; +import type {PagesContentPaths} from './types'; +import type { + PluginOptions, + Metadata, + LoadedContent, +} from '@docusaurus/plugin-content-pages'; export function getContentPathList(contentPaths: PagesContentPaths): string[] { return [contentPaths.contentPathLocalized, contentPaths.contentPath]; diff --git a/packages/docusaurus-plugin-content-pages/src/plugin-content-pages.d.ts b/packages/docusaurus-plugin-content-pages/src/plugin-content-pages.d.ts index 2f35040cebe5b..dd754b1759400 100644 --- a/packages/docusaurus-plugin-content-pages/src/plugin-content-pages.d.ts +++ b/packages/docusaurus-plugin-content-pages/src/plugin-content-pages.d.ts @@ -7,6 +7,7 @@ declare module '@docusaurus/plugin-content-pages' { import type {MDXOptions} from '@docusaurus/mdx-loader'; + import type {LoadContext, Plugin} from '@docusaurus/types'; export type PluginOptions = MDXOptions & { id?: string; @@ -45,6 +46,13 @@ declare module '@docusaurus/plugin-content-pages' { }; export type Metadata = JSXPageMetadata | MDXPageMetadata; + + export type LoadedContent = Metadata[]; + + export default function pluginContentPages( + context: LoadContext, + options: PluginOptions, + ): Promise>; } declare module '@theme/MDXPage' { diff --git a/packages/docusaurus-plugin-content-pages/src/types.ts b/packages/docusaurus-plugin-content-pages/src/types.ts index e2833c5692f5a..2d11492cb04ef 100644 --- a/packages/docusaurus-plugin-content-pages/src/types.ts +++ b/packages/docusaurus-plugin-content-pages/src/types.ts @@ -5,10 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import type {Metadata} from '@docusaurus/plugin-content-pages'; - -export type LoadedContent = Metadata[]; - export type PagesContentPaths = { contentPath: string; contentPathLocalized: string; diff --git a/packages/docusaurus-plugin-debug/src/index.ts b/packages/docusaurus-plugin-debug/src/index.ts index 01a9e0a4e03f2..62e650824f936 100644 --- a/packages/docusaurus-plugin-debug/src/index.ts +++ b/packages/docusaurus-plugin-debug/src/index.ts @@ -12,7 +12,7 @@ import path from 'path'; export default function pluginDebug({ siteConfig: {baseUrl}, generatedFilesDir, -}: LoadContext): Plugin { +}: LoadContext): Plugin { const pluginDataDirRoot = path.join( generatedFilesDir, 'docusaurus-plugin-debug', diff --git a/packages/docusaurus-plugin-debug/src/plugin-debug.d.ts b/packages/docusaurus-plugin-debug/src/plugin-debug.d.ts index 93b666dd4f316..f66d093a1ba7e 100644 --- a/packages/docusaurus-plugin-debug/src/plugin-debug.d.ts +++ b/packages/docusaurus-plugin-debug/src/plugin-debug.d.ts @@ -7,6 +7,12 @@ /// +declare module '@docusaurus/plugin-debug' { + import type {LoadContext, Plugin} from '@docusaurus/types'; + + export default function pluginDebug(context: LoadContext): Plugin; +} + declare module '@theme/DebugConfig' { export default function DebugMetadata(): JSX.Element; } diff --git a/packages/docusaurus-plugin-google-analytics/package.json b/packages/docusaurus-plugin-google-analytics/package.json index ba4e08a1a4ffd..e094188d43cab 100644 --- a/packages/docusaurus-plugin-google-analytics/package.json +++ b/packages/docusaurus-plugin-google-analytics/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.18", "description": "Global analytics (analytics.js) plugin for Docusaurus.", "main": "lib/index.js", - "types": "src/plugin-google-analytics.d.ts", + "types": "lib/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/docusaurus-plugin-google-analytics/src/index.ts b/packages/docusaurus-plugin-google-analytics/src/index.ts index 0219c748f12c5..6250becb1244b 100644 --- a/packages/docusaurus-plugin-google-analytics/src/index.ts +++ b/packages/docusaurus-plugin-google-analytics/src/index.ts @@ -13,7 +13,7 @@ import type { ThemeConfig, ThemeConfigValidationContext, } from '@docusaurus/types'; -import type {PluginOptions, Options} from '@docusaurus/plugin-google-analytics'; +import type {PluginOptions, Options} from './options'; export default function pluginGoogleAnalytics( context: LoadContext, @@ -87,3 +87,5 @@ export function validateThemeConfig({ } return themeConfig; } + +export type {PluginOptions, Options}; diff --git a/packages/docusaurus-plugin-google-analytics/src/plugin-google-analytics.d.ts b/packages/docusaurus-plugin-google-analytics/src/options.ts similarity index 100% rename from packages/docusaurus-plugin-google-analytics/src/plugin-google-analytics.d.ts rename to packages/docusaurus-plugin-google-analytics/src/options.ts diff --git a/packages/docusaurus-plugin-google-gtag/package.json b/packages/docusaurus-plugin-google-gtag/package.json index 1ddd7df24a514..342888e662349 100644 --- a/packages/docusaurus-plugin-google-gtag/package.json +++ b/packages/docusaurus-plugin-google-gtag/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.18", "description": "Global Site Tag (gtag.js) plugin for Docusaurus.", "main": "lib/index.js", - "types": "src/plugin-google-gtag.d.ts", + "types": "lib/index.d.ts", "scripts": { "build": "tsc", "watch": "tsc --watch" diff --git a/packages/docusaurus-plugin-google-gtag/src/gtag.ts b/packages/docusaurus-plugin-google-gtag/src/gtag.ts index 0beaac7f0a07d..dab90146d1fc4 100644 --- a/packages/docusaurus-plugin-google-gtag/src/gtag.ts +++ b/packages/docusaurus-plugin-google-gtag/src/gtag.ts @@ -6,7 +6,7 @@ */ import globalData from '@generated/globalData'; -import type {PluginOptions} from '@docusaurus/plugin-google-gtag'; +import type {PluginOptions} from './options'; import type {ClientModule} from '@docusaurus/types'; const {trackingID} = globalData['docusaurus-plugin-google-gtag']! diff --git a/packages/docusaurus-plugin-google-gtag/src/index.ts b/packages/docusaurus-plugin-google-gtag/src/index.ts index 66ed0365e0a92..7724c96766832 100644 --- a/packages/docusaurus-plugin-google-gtag/src/index.ts +++ b/packages/docusaurus-plugin-google-gtag/src/index.ts @@ -13,7 +13,7 @@ import type { ThemeConfig, ThemeConfigValidationContext, } from '@docusaurus/types'; -import type {PluginOptions, Options} from '@docusaurus/plugin-google-gtag'; +import type {PluginOptions, Options} from './options'; export default function pluginGoogleGtag( context: LoadContext, @@ -101,3 +101,5 @@ export function validateThemeConfig({ } return themeConfig; } + +export type {PluginOptions, Options}; diff --git a/packages/docusaurus-plugin-google-gtag/src/plugin-google-gtag.d.ts b/packages/docusaurus-plugin-google-gtag/src/options.ts similarity index 100% rename from packages/docusaurus-plugin-google-gtag/src/plugin-google-gtag.d.ts rename to packages/docusaurus-plugin-google-gtag/src/options.ts diff --git a/packages/docusaurus-plugin-sitemap/package.json b/packages/docusaurus-plugin-sitemap/package.json index 769d5d046f756..a3629d6848f37 100644 --- a/packages/docusaurus-plugin-sitemap/package.json +++ b/packages/docusaurus-plugin-sitemap/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.18", "description": "Simple sitemap generation plugin for Docusaurus.", "main": "lib/index.js", - "types": "src/plugin-sitemap.d.ts", + "types": "lib/index.d.ts", "scripts": { "build": "tsc", "watch": "tsc --watch" diff --git a/packages/docusaurus-plugin-sitemap/src/__tests__/options.test.ts b/packages/docusaurus-plugin-sitemap/src/__tests__/options.test.ts index 9e93e57de8ecf..c581cbece0ec1 100644 --- a/packages/docusaurus-plugin-sitemap/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-sitemap/src/__tests__/options.test.ts @@ -5,9 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {validateOptions, DEFAULT_OPTIONS} from '../options'; +import {validateOptions, DEFAULT_OPTIONS, type Options} from '../options'; import {normalizePluginOptions} from '@docusaurus/utils-validation'; -import type {Options} from '@docusaurus/plugin-sitemap'; function testValidate(options: Options) { return validateOptions({validate: normalizePluginOptions, options}); diff --git a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts index fa4aefb75e529..5e1b619d356f1 100644 --- a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts +++ b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts @@ -6,11 +6,11 @@ */ import {SitemapStream, streamToPromise} from 'sitemap'; -import type {PluginOptions} from '@docusaurus/plugin-sitemap'; -import type {DocusaurusConfig} from '@docusaurus/types'; import {applyTrailingSlash} from '@docusaurus/utils-common'; import {createMatcher} from '@docusaurus/utils'; +import type {DocusaurusConfig} from '@docusaurus/types'; import type {HelmetServerState} from 'react-helmet-async'; +import type {PluginOptions} from './options'; import type {ReactElement} from 'react'; export default async function createSitemap( diff --git a/packages/docusaurus-plugin-sitemap/src/index.ts b/packages/docusaurus-plugin-sitemap/src/index.ts index 5f66eeaa3e5a6..3f52b8cf60f0f 100644 --- a/packages/docusaurus-plugin-sitemap/src/index.ts +++ b/packages/docusaurus-plugin-sitemap/src/index.ts @@ -7,8 +7,8 @@ import fs from 'fs-extra'; import path from 'path'; -import type {PluginOptions} from '@docusaurus/plugin-sitemap'; import createSitemap from './createSitemap'; +import type {PluginOptions, Options} from './options'; import type {LoadContext, Plugin} from '@docusaurus/types'; export default function pluginSitemap( @@ -42,3 +42,4 @@ export default function pluginSitemap( } export {validateOptions} from './options'; +export type {PluginOptions, Options}; diff --git a/packages/docusaurus-plugin-sitemap/src/options.ts b/packages/docusaurus-plugin-sitemap/src/options.ts index e5f2053931c00..5a8302424e83d 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -7,9 +7,22 @@ import {Joi} from '@docusaurus/utils-validation'; import {EnumChangefreq} from 'sitemap'; -import type {Options, PluginOptions} from '@docusaurus/plugin-sitemap'; import type {OptionValidationContext} from '@docusaurus/types'; +export type PluginOptions = { + /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */ + changefreq: EnumChangefreq; + /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */ + priority: number; + /** + * A list of glob patterns; matching route paths will be filtered from the + * sitemap. Note that you may need to include the base URL in here. + */ + ignorePatterns: string[]; +}; + +export type Options = Partial; + export const DEFAULT_OPTIONS: PluginOptions = { changefreq: EnumChangefreq.WEEKLY, priority: 0.5, diff --git a/packages/docusaurus-plugin-sitemap/src/plugin-sitemap.d.ts b/packages/docusaurus-plugin-sitemap/src/plugin-sitemap.d.ts deleted file mode 100644 index 6f175bd1f7a16..0000000000000 --- a/packages/docusaurus-plugin-sitemap/src/plugin-sitemap.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import type {EnumChangefreq} from 'sitemap'; - -export type PluginOptions = { - /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */ - changefreq: EnumChangefreq; - /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */ - priority: number; - /** - * A list of glob patterns; matching route paths will be filtered from the - * sitemap. Note that you may need to include the base URL in here. - */ - ignorePatterns: string[]; -}; - -export type Options = Partial; diff --git a/packages/docusaurus-preset-classic/package.json b/packages/docusaurus-preset-classic/package.json index 850c52f9e030c..b727d31e6e3bf 100644 --- a/packages/docusaurus-preset-classic/package.json +++ b/packages/docusaurus-preset-classic/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.18", "description": "Classic preset for Docusaurus.", "main": "lib/index.js", - "types": "src/preset-classic.d.ts", + "types": "lib/index.d.ts", "scripts": { "build": "tsc", "watch": "tsc --watch" diff --git a/packages/docusaurus-preset-classic/src/index.ts b/packages/docusaurus-preset-classic/src/index.ts index e3059a5206659..a695121c9d0fb 100644 --- a/packages/docusaurus-preset-classic/src/index.ts +++ b/packages/docusaurus-preset-classic/src/index.ts @@ -11,7 +11,7 @@ import type { PluginConfig, PluginOptions, } from '@docusaurus/types'; -import type {Options, ThemeConfig} from '@docusaurus/preset-classic'; +import type {Options, ThemeConfig} from './options'; function makePluginConfig( source: string, @@ -93,3 +93,5 @@ export default function preset( return {themes, plugins}; } + +export type {Options, ThemeConfig}; diff --git a/packages/docusaurus-preset-classic/src/preset-classic.d.ts b/packages/docusaurus-preset-classic/src/options.ts similarity index 100% rename from packages/docusaurus-preset-classic/src/preset-classic.d.ts rename to packages/docusaurus-preset-classic/src/options.ts diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index cbbf6bf58d617..8b2958b7c3a8d 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -47,10 +47,10 @@ declare module '@theme/BackToTopButton' { } declare module '@theme/BlogListPaginator' { - import type {Metadata} from '@theme/BlogListPage'; + import type {BlogPaginatedMetadata} from '@docusaurus/plugin-content-blog'; export interface Props { - readonly metadata: Metadata; + readonly metadata: BlogPaginatedMetadata; } export default function BlogListPaginator(props: Props): JSX.Element; }