From 0f233f51ed76fb33e3ee27b572a3c932e0abddcb Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sun, 17 Apr 2022 23:19:47 +0800 Subject: [PATCH] fix: fix a lot of declaration semantic errors --- packages/docusaurus-mdx-loader/src/deps.d.ts | 8 +- .../src/feed.ts | 82 +++++++++---------- .../src/deps.d.ts | 3 +- .../docusaurus-plugin-pwa/src/plugin-pwa.d.ts | 2 +- .../src/types.d.ts | 3 +- packages/docusaurus/src/commands/build.ts | 2 +- packages/docusaurus/src/commands/deploy.ts | 2 +- packages/docusaurus/src/deps.d.ts | 25 +++--- 8 files changed, 64 insertions(+), 63 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/deps.d.ts b/packages/docusaurus-mdx-loader/src/deps.d.ts index 510bfc74e092..d27fd5334b9e 100644 --- a/packages/docusaurus-mdx-loader/src/deps.d.ts +++ b/packages/docusaurus-mdx-loader/src/deps.d.ts @@ -8,14 +8,14 @@ // TODO Types provided by MDX 2.0 https://github.com/mdx-js/mdx/blob/main/packages/mdx/types/index.d.ts declare module '@mdx-js/mdx' { import type {Processor} from 'unified'; - import type {RemarkOrRehypePlugin} from '@docusaurus/mdx-loader'; + import type {MDXPlugin} from '@docusaurus/mdx-loader'; export type Options = { filepath?: string; skipExport?: boolean; wrapExport?: string; - remarkPlugins?: RemarkOrRehypePlugin[]; - rehypePlugins?: RemarkOrRehypePlugin[]; + remarkPlugins?: MDXPlugin[]; + rehypePlugins?: MDXPlugin[]; }; export function sync(content: string, options?: Options): string; @@ -23,6 +23,6 @@ declare module '@mdx-js/mdx' { export function createCompiler(options?: Options): Processor; export default function mdx( content: string, - options?: mdx.Options, + options?: Options, ): Promise; } diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index fa546fbf0f18..af453979243c 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -7,11 +7,7 @@ import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed'; import type {BlogPost} from './types'; -import { - normalizeUrl, - mapAsyncSequential, - readOutputHTMLFile, -} from '@docusaurus/utils'; +import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; import {load as cheerioLoad} from 'cheerio'; import type {DocusaurusConfig} from '@docusaurus/types'; import path from 'path'; @@ -61,46 +57,48 @@ async function generateBlogFeed({ return {name: author.name, link: author.url, email: author.email}; } - await mapAsyncSequential(blogPosts, async (post) => { - const { - id, - metadata: { + await Promise.all( + blogPosts.map(async (post) => { + const { + id, + metadata: { + title: metadataTitle, + permalink, + date, + description, + authors, + tags, + }, + } = post; + + const content = await readOutputHTMLFile( + permalink.replace(siteConfig.baseUrl, ''), + outDir, + siteConfig.trailingSlash, + ); + const $ = cheerioLoad(content); + + const feedItem: FeedItem = { title: metadataTitle, - permalink, + id, + link: normalizeUrl([siteUrl, permalink]), date, description, - authors, - tags, - }, - } = post; - - const content = await readOutputHTMLFile( - permalink.replace(siteConfig.baseUrl, ''), - outDir, - siteConfig.trailingSlash, - ); - const $ = cheerioLoad(content); - - const feedItem: FeedItem = { - title: metadataTitle, - id, - link: normalizeUrl([siteUrl, permalink]), - date, - description, - // Atom feed demands the "term", while other feeds use "name" - category: tags.map((tag) => ({name: tag.label, term: tag.label})), - content: $(`#${blogPostContainerID}`).html()!, - }; - - // json1() method takes the first item of authors array - // it causes an error when authors array is empty - const feedItemAuthors = authors.map(toFeedAuthor); - if (feedItemAuthors.length > 0) { - feedItem.author = feedItemAuthors; - } - - feed.addItem(feedItem); - }); + // Atom feed demands the "term", while other feeds use "name" + category: tags.map((tag) => ({name: tag.label, term: tag.label})), + content: $(`#${blogPostContainerID}`).html()!, + }; + + // json1() method takes the first item of authors array + // it causes an error when authors array is empty + const feedItemAuthors = authors.map(toFeedAuthor); + if (feedItemAuthors.length > 0) { + feedItem.author = feedItemAuthors; + } + + return feedItem; + }), + ).then((items) => items.forEach(feed.addItem)); return feed; } diff --git a/packages/docusaurus-plugin-ideal-image/src/deps.d.ts b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts index 839a35fac984..f5a6da75b378 100644 --- a/packages/docusaurus-plugin-ideal-image/src/deps.d.ts +++ b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts @@ -42,7 +42,8 @@ declare module '@endiliey/react-ideal-image' { type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript'; - export interface ImageProps extends ComponentProps<'img'> { + export interface ImageProps + extends Omit, 'srcSet' | 'placeholder'> { /** * This function decides what icon to show based on the current state of the * component. diff --git a/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts b/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts index 51cdf63f2c7a..9633e9e4e43a 100644 --- a/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts +++ b/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts @@ -66,7 +66,7 @@ declare module '@docusaurus/plugin-pwa' { tagName: string; href?: string; content?: string; - [attributeName: string]: string | boolean; + [attributeName: string]: string | boolean | undefined; }[]; /** * Useful for additional Workbox rules. You can do whatever a service worker diff --git a/packages/docusaurus-theme-live-codeblock/src/types.d.ts b/packages/docusaurus-theme-live-codeblock/src/types.d.ts index 9ae9bb21cef3..47200c50ab58 100644 --- a/packages/docusaurus-theme-live-codeblock/src/types.d.ts +++ b/packages/docusaurus-theme-live-codeblock/src/types.d.ts @@ -9,7 +9,8 @@ /// declare module '@theme-init/CodeBlock' { - import type CodeBlock, {Props as BaseProps} from '@theme/CodeBlock'; + import type CodeBlock from '@theme/CodeBlock'; + import type {Props as BaseProps} from '@theme/CodeBlock'; export interface Props extends BaseProps { live?: boolean; diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index 98f7d2bf85fc..8c211c225fba 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -145,7 +145,7 @@ async function buildLocale({ new ReactLoadableSSRAddon({ filename: clientManifestPath, }), - ].filter(Boolean), + ].filter((x: T | undefined | false): x is T => Boolean(x)), }, ); diff --git a/packages/docusaurus/src/commands/deploy.ts b/packages/docusaurus/src/commands/deploy.ts index a632fe245be8..2382c696a889 100644 --- a/packages/docusaurus/src/commands/deploy.ts +++ b/packages/docusaurus/src/commands/deploy.ts @@ -236,7 +236,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`); if (!cliOptions.skipBuild) { // Build site, then push to deploymentBranch branch of specified repo. try { - await runDeploy(await build(siteDir, cliOptions, false)); + await build(siteDir, cliOptions, false).then(runDeploy); } catch (err) { logger.error('Deployment of the build output failed.'); throw err; diff --git a/packages/docusaurus/src/deps.d.ts b/packages/docusaurus/src/deps.d.ts index fe48ab85493b..c2dc3ccd1fd4 100644 --- a/packages/docusaurus/src/deps.d.ts +++ b/packages/docusaurus/src/deps.d.ts @@ -8,6 +8,8 @@ declare module 'remark-admonitions'; declare module 'react-loadable-ssr-addon-v5-slorber' { + import type {WebpackPluginInstance, Compiler} from 'webpack'; + type Asset = { file: string; hash: string; @@ -26,15 +28,14 @@ declare module 'react-loadable-ssr-addon-v5-slorber' { modulesToBeLoaded: string[], ): {js: Asset[]; css: Asset[]}; - type ReactLoadableSSRAddon = { - new (props: {filename: string}); - }; - - const plugin: ReactLoadableSSRAddon; - export default plugin; + export default class ReactLoadableSSRAddon implements WebpackPluginInstance { + constructor(props: {filename: string}); + apply(compiler: Compiler): void; + } } declare module '@slorber/static-site-generator-webpack-plugin' { + import type {WebpackPluginInstance, Compiler} from 'webpack'; import type {HelmetServerState} from 'react-helmet-async'; export type Locals = { @@ -53,18 +54,18 @@ declare module '@slorber/static-site-generator-webpack-plugin' { noIndex: boolean; }; - type StaticSiteGeneratorPlugin = { - new (props: { + export default class StaticSiteGeneratorPlugin + implements WebpackPluginInstance + { + constructor(props: { entry: string; locals: Locals; paths: string[]; preferFoldersOutput?: boolean; globals: {[key: string]: unknown}; }); - }; - - const plugin: StaticSiteGeneratorPlugin; - export default plugin; + apply(compiler: Compiler): void; + } } declare module 'webpack/lib/HotModuleReplacementPlugin' {