Skip to content

Commit

Permalink
fix(*): make TypeScript realize that each plugin package has a defaul…
Browse files Browse the repository at this point in the history
…t export
  • Loading branch information
Josh-Cena committed May 3, 2022
1 parent b49ae67 commit 099c646
Show file tree
Hide file tree
Showing 42 changed files with 199 additions and 185 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-client-redirects/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -52,3 +52,4 @@ export default function pluginClientRedirectsPages(
}

export {validateOptions} from './options';
export type {PluginOptions, Options};
31 changes: 26 additions & 5 deletions packages/docusaurus-plugin-client-redirects/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginOptions>;

export const DEFAULT_OPTIONS: Partial<PluginOptions> = {
fromExtensions: [],
toExtensions: [],
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-client-redirects/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,6 +15,7 @@ import type {
FeedType,
PluginOptions,
Author,
BlogPost,
} from '@docusaurus/plugin-content-blog';
import {blogPostContainerID} from '@docusaurus/utils-common';

Expand Down
13 changes: 5 additions & 8 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -46,6 +39,10 @@ import type {
BlogPostFrontMatter,
BlogPostMetadata,
Assets,
BlogTag,
BlogTags,
BlogContent,
BlogPaginated,
} from '@docusaurus/plugin-content-blog';

export default async function pluginContentBlog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<Plugin<BlogContent>>;
}

declare module '@theme/BlogPostPage' {
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
34 changes: 1 addition & 33 deletions packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlogContentPaths>;
export type BlogMarkdownLoaderOptions = {
siteDir: string;
Expand Down
Loading

0 comments on commit 099c646

Please sign in to comment.