From 638a0663acfce56d2c2ecd80a93a73abf6403c38 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 26 Apr 2020 23:09:07 -0400 Subject: [PATCH 1/8] feat(v2): Support swizzling TypeScript components --- .eslintignore | 1 + .gitignore | 1 + .../docusaurus-theme-classic/babel.config.js | 10 ++++++++ .../docusaurus-theme-classic/package.json | 9 ++++++++ .../docusaurus-theme-classic/src/index.js | 4 ++++ .../AnnouncementBar/{index.js => index.tsx} | 4 ++-- .../BlogListPage/{index.js => index.tsx} | 2 +- .../BlogListPaginator/{index.js => index.tsx} | 2 +- .../BlogPostItem/{index.js => index.tsx} | 2 +- .../BlogPostPage/{index.js => index.tsx} | 2 +- .../BlogPostPaginator/{index.js => index.tsx} | 2 +- .../BlogTagsListPage/{index.js => index.tsx} | 4 ++-- .../BlogTagsPostsPage/{index.js => index.tsx} | 4 ++-- .../theme/CodeBlock/{index.js => index.tsx} | 16 +++++++++---- .../src/theme/DocItem/{index.js => index.tsx} | 4 ++-- .../src/theme/DocPage/{index.js => index.tsx} | 2 +- .../DocPaginator/{index.js => index.tsx} | 2 +- .../theme/DocSidebar/{index.js => index.tsx} | 2 +- .../src/theme/Footer/{index.js => index.tsx} | 2 +- .../src/theme/Heading/{index.js => index.tsx} | 6 ++--- .../src/theme/Layout/{index.js => index.tsx} | 0 .../MDXComponents/{index.js => index.tsx} | 0 .../src/theme/Navbar/{index.js => index.tsx} | 2 +- .../src/theme/{NotFound.js => NotFound.tsx} | 0 .../src/theme/{SearchBar.js => SearchBar.tsx} | 0 .../src/theme/TabItem/{index.js => index.tsx} | 4 ++-- .../src/theme/Tabs/{index.js => index.tsx} | 20 ++++++++++++---- .../{ThemeContext.js => ThemeContext.ts} | 0 .../ThemeProvider/{index.js => index.tsx} | 4 ++-- .../src/theme/Toggle/{index.js => index.tsx} | 0 ...esContext.js => UserPreferencesContext.ts} | 0 .../{index.js => index.tsx} | 4 ++-- ...nouncementBar.js => useAnnouncementBar.ts} | 9 +++++--- ...HideableNavbar.js => useHideableNavbar.ts} | 2 +- ...{useLocationHash.js => useLocationHash.ts} | 6 +++-- ...LockBodyScroll.js => useLockBodyScroll.ts} | 2 +- .../theme/hooks/{useLogo.js => useLogo.ts} | 11 +++++++-- .../{usePrismTheme.js => usePrismTheme.ts} | 2 +- ...ScrollPosition.js => useScrollPosition.ts} | 10 ++++++-- ...{useTOCHighlight.js => useTOCHighlight.ts} | 15 ++++++++---- ...TabGroupChoice.js => useTabGroupChoice.ts} | 13 +++++++---- .../theme/hooks/{useTheme.js => useTheme.ts} | 7 +++++- ...{useThemeContext.js => useThemeContext.ts} | 6 ++++- ...ontext.js => useUserPreferencesContext.ts} | 7 +++++- .../{useWindowSize.js => useWindowSize.ts} | 6 ++--- ...anguages.js => prism-include-languages.ts} | 2 +- .../docusaurus-theme-classic/src/types.d.ts | 9 ++++++++ .../docusaurus-theme-classic/tsconfig.json | 13 +++++++++++ packages/docusaurus-types/src/index.d.ts | 1 + packages/docusaurus-utils/src/index.ts | 2 +- packages/docusaurus/bin/docusaurus.js | 13 +++++++++-- packages/docusaurus/src/commands/swizzle.ts | 19 +++++++++++---- yarn.lock | 23 ++++++++++++++++++- 53 files changed, 220 insertions(+), 73 deletions(-) create mode 100644 packages/docusaurus-theme-classic/babel.config.js rename packages/docusaurus-theme-classic/src/theme/AnnouncementBar/{index.js => index.tsx} (92%) rename packages/docusaurus-theme-classic/src/theme/BlogListPage/{index.js => index.tsx} (96%) rename packages/docusaurus-theme-classic/src/theme/BlogListPaginator/{index.js => index.tsx} (95%) rename packages/docusaurus-theme-classic/src/theme/BlogPostItem/{index.js => index.tsx} (98%) rename packages/docusaurus-theme-classic/src/theme/BlogPostPage/{index.js => index.tsx} (98%) rename packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/{index.js => index.tsx} (96%) rename packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/{index.js => index.tsx} (93%) rename packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/{index.js => index.tsx} (93%) rename packages/docusaurus-theme-classic/src/theme/CodeBlock/{index.js => index.tsx} (96%) rename packages/docusaurus-theme-classic/src/theme/DocItem/{index.js => index.tsx} (98%) rename packages/docusaurus-theme-classic/src/theme/DocPage/{index.js => index.tsx} (98%) rename packages/docusaurus-theme-classic/src/theme/DocPaginator/{index.js => index.tsx} (96%) rename packages/docusaurus-theme-classic/src/theme/DocSidebar/{index.js => index.tsx} (99%) rename packages/docusaurus-theme-classic/src/theme/Footer/{index.js => index.tsx} (98%) rename packages/docusaurus-theme-classic/src/theme/Heading/{index.js => index.tsx} (92%) rename packages/docusaurus-theme-classic/src/theme/Layout/{index.js => index.tsx} (100%) rename packages/docusaurus-theme-classic/src/theme/MDXComponents/{index.js => index.tsx} (100%) rename packages/docusaurus-theme-classic/src/theme/Navbar/{index.js => index.tsx} (99%) rename packages/docusaurus-theme-classic/src/theme/{NotFound.js => NotFound.tsx} (100%) rename packages/docusaurus-theme-classic/src/theme/{SearchBar.js => SearchBar.tsx} (100%) rename packages/docusaurus-theme-classic/src/theme/TabItem/{index.js => index.tsx} (69%) rename packages/docusaurus-theme-classic/src/theme/Tabs/{index.js => index.tsx} (85%) rename packages/docusaurus-theme-classic/src/theme/{ThemeContext.js => ThemeContext.ts} (100%) rename packages/docusaurus-theme-classic/src/theme/ThemeProvider/{index.js => index.tsx} (83%) rename packages/docusaurus-theme-classic/src/theme/Toggle/{index.js => index.tsx} (100%) rename packages/docusaurus-theme-classic/src/theme/{UserPreferencesContext.js => UserPreferencesContext.ts} (100%) rename packages/docusaurus-theme-classic/src/theme/UserPreferencesProvider/{index.js => index.tsx} (87%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useAnnouncementBar.js => useAnnouncementBar.ts} (83%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useHideableNavbar.js => useHideableNavbar.ts} (97%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useLocationHash.js => useLocationHash.ts} (76%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useLockBodyScroll.js => useLockBodyScroll.ts} (88%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useLogo.js => useLogo.ts} (82%) rename packages/docusaurus-theme-classic/src/theme/hooks/{usePrismTheme.js => usePrismTheme.ts} (93%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useScrollPosition.js => useScrollPosition.ts} (76%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useTOCHighlight.js => useTOCHighlight.ts} (83%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useTabGroupChoice.js => useTabGroupChoice.ts} (75%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useTheme.js => useTheme.ts} (91%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useThemeContext.js => useThemeContext.ts} (74%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useUserPreferencesContext.js => useUserPreferencesContext.ts} (61%) rename packages/docusaurus-theme-classic/src/theme/hooks/{useWindowSize.js => useWindowSize.ts} (90%) rename packages/docusaurus-theme-classic/src/theme/{prism-include-languages.js => prism-include-languages.ts} (93%) create mode 100644 packages/docusaurus-theme-classic/src/types.d.ts create mode 100644 packages/docusaurus-theme-classic/tsconfig.json diff --git a/.eslintignore b/.eslintignore index 6e940531fa67..b9cb4992d8e7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -22,6 +22,7 @@ packages/docusaurus-plugin-debug/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js +packages/docusaurus-theme-classic/lib/ packages/docusaurus-1.x/.eslintrc.js packages/docusaurus-init/templates/facebook/.eslintrc.js diff --git a/.gitignore b/.gitignore index 5fe68e835d72..1dba5a650855 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ packages/docusaurus-plugin-content-pages/lib/ packages/docusaurus-plugin-debug/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ +packages/docusaurus-theme-classic/lib/ diff --git a/packages/docusaurus-theme-classic/babel.config.js b/packages/docusaurus-theme-classic/babel.config.js new file mode 100644 index 000000000000..a6b570f38777 --- /dev/null +++ b/packages/docusaurus-theme-classic/babel.config.js @@ -0,0 +1,10 @@ +/** + * 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. + */ + +module.exports = { + presets: [['@babel/preset-typescript', {isTSX: true, allExtensions: true}]], +}; diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index adc547a420bd..9233ae67416c 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -7,6 +7,11 @@ "access": "public" }, "license": "MIT", + "scripts": { + "tsc": "yarn babel && yarn prettier", + "babel": "babel src -d lib --extensions \".tsx,.ts\" --copy-files", + "prettier": "prettier --config ../../.prettierrc --write \"**/*.{js,ts}\"" + }, "dependencies": { "@mdx-js/mdx": "^1.5.8", "@mdx-js/react": "^1.5.8", @@ -20,6 +25,10 @@ "react-router-dom": "^5.1.2", "react-toggle": "^4.1.1" }, + "devDependencies": { + "@babel/cli": "^7.8.4", + "@docusaurus/module-type-aliases": "^2.0.0-alpha.58" + }, "peerDependencies": { "@docusaurus/core": "^2.0.0", "react": "^16.8.4", diff --git a/packages/docusaurus-theme-classic/src/index.js b/packages/docusaurus-theme-classic/src/index.js index cbe3e4c91410..58bb3ee111e3 100644 --- a/packages/docusaurus-theme-classic/src/index.js +++ b/packages/docusaurus-theme-classic/src/index.js @@ -60,6 +60,10 @@ module.exports = function (context, options) { name: 'docusaurus-theme-classic', getThemePath() { + return path.join(__dirname, '..', 'lib', 'theme'); + }, + + getTypeScriptThemePath() { return path.resolve(__dirname, './theme'); }, diff --git a/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.js b/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx similarity index 92% rename from packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.js rename to packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx index 031d9cc01ba4..761123214871 100644 --- a/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.js +++ b/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx @@ -11,9 +11,9 @@ import useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext'; import styles from './styles.module.css'; -function AnnouncementBar() { +function AnnouncementBar(): JSX.Element | null { const { - siteConfig: {themeConfig: {announcementBar = {}}} = {}, + siteConfig: {themeConfig: {announcementBar = {}} = {}} = {}, } = useDocusaurusContext(); const {content, backgroundColor, textColor} = announcementBar; const { diff --git a/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.js b/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx similarity index 96% rename from packages/docusaurus-theme-classic/src/theme/BlogListPage/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx index 6426bc8874bf..75d12e459a4d 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx @@ -12,7 +12,7 @@ import Layout from '@theme/Layout'; import BlogPostItem from '@theme/BlogPostItem'; import BlogListPaginator from '@theme/BlogListPaginator'; -function BlogListPage(props) { +function BlogListPage(props): JSX.Element { const {metadata, items} = props; const { siteConfig: {title: siteTitle}, diff --git a/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.js b/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx similarity index 95% rename from packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx index a14ca3cf6a7b..8593728803a8 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import Link from '@docusaurus/Link'; -function BlogListPaginator(props) { +function BlogListPaginator(props): JSX.Element { const {metadata} = props; const {previousPage, nextPage} = metadata; diff --git a/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js b/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.tsx similarity index 98% rename from packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.tsx index 892dac2a713d..9f2ad1e01547 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogPostItem/index.tsx @@ -31,7 +31,7 @@ const MONTHS = [ 'December', ]; -function BlogPostItem(props) { +function BlogPostItem(props): JSX.Element { const { children, frontMatter, diff --git a/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.js b/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx similarity index 98% rename from packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx index 7881bba0850b..c17a41d809b3 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx @@ -11,7 +11,7 @@ import Layout from '@theme/Layout'; import BlogPostItem from '@theme/BlogPostItem'; import BlogPostPaginator from '@theme/BlogPostPaginator'; -function BlogPostPage(props) { +function BlogPostPage(props): JSX.Element { const {content: BlogPostContents} = props; const {frontMatter, metadata} = BlogPostContents; const {title, description, nextItem, prevItem, editUrl} = metadata; diff --git a/packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.js b/packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.tsx similarity index 96% rename from packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.tsx index 6dacef1c8ea9..1028cc588abb 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogPostPaginator/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import Link from '@docusaurus/Link'; -function BlogPostPaginator(props) { +function BlogPostPaginator(props): JSX.Element { const {nextItem, prevItem} = props; return ( diff --git a/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.js b/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx similarity index 93% rename from packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx index ba490ac9da7f..b3ce4c53279c 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx @@ -15,10 +15,10 @@ function getCategoryOfTag(tag) { return tag[0].toUpperCase(); } -function BlogTagsListPage(props) { +function BlogTagsListPage(props): JSX.Element { const {tags} = props; - const tagCategories = {}; + const tagCategories: {[category: string]: string[]} = {}; Object.keys(tags).forEach((tag) => { const category = getCategoryOfTag(tag); tagCategories[category] = tagCategories[category] || []; diff --git a/packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.js b/packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.tsx similarity index 93% rename from packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.js rename to packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.tsx index 41d10517f8e7..e3da4fb4b399 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.js +++ b/packages/docusaurus-theme-classic/src/theme/BlogTagsPostsPage/index.tsx @@ -11,11 +11,11 @@ import Layout from '@theme/Layout'; import BlogPostItem from '@theme/BlogPostItem'; import Link from '@docusaurus/Link'; -function pluralize(count, word) { +function pluralize(count: number, word: string) { return count > 1 ? `${word}s` : word; } -function BlogTagsPostPage(props) { +function BlogTagsPostPage(props): JSX.Element { const {metadata, items} = props; const {allTagsPath, name: tagName, count} = metadata; diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.js b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx similarity index 96% rename from packages/docusaurus-theme-classic/src/theme/CodeBlock/index.js rename to packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx index 38b5e12615d4..d0f2540e8394 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.js +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx @@ -87,7 +87,15 @@ const highlightDirectiveRegex = (lang) => { }; const codeBlockTitleRegex = /title=".*"/; -export default ({children, className: languageClassName, metastring}) => { +export default ({ + children, + className: languageClassName, + metastring, +}: { + children: string; + className: string; + metastring: string; +}): JSX.Element => { const { siteConfig: { themeConfig: {prism = {}}, @@ -108,7 +116,7 @@ export default ({children, className: languageClassName, metastring}) => { }, []); const button = useRef(null); - let highlightLines = []; + let highlightLines: number[] = []; let codeBlockTitle = ''; const prismTheme = usePrismTheme(); @@ -188,7 +196,7 @@ export default ({children, className: languageClassName, metastring}) => { return ( @@ -211,7 +219,7 @@ export default ({children, className: languageClassName, metastring}) => { {showCopied ? 'Copied' : 'Copy'}
diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx similarity index 98% rename from packages/docusaurus-theme-classic/src/theme/DocItem/index.js rename to packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx index 95259336fa06..93e996c9def7 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx @@ -33,7 +33,7 @@ function DocTOC({headings}) { } /* eslint-disable jsx-a11y/control-has-associated-label */ -function Headings({headings, isChild}) { +function Headings({headings, isChild}: {headings; isChild?: boolean}) { if (!headings.length) { return null; } @@ -58,7 +58,7 @@ function Headings({headings, isChild}) { ); } -function DocItem(props) { +function DocItem(props): JSX.Element { const {siteConfig = {}} = useDocusaurusContext(); const {url: siteUrl, title: siteTitle} = siteConfig; const {content: DocContent} = props; diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/index.js b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx similarity index 98% rename from packages/docusaurus-theme-classic/src/theme/DocPage/index.js rename to packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx index adee2291b84c..95c74c2b4bec 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx @@ -18,7 +18,7 @@ import {matchPath} from '@docusaurus/router'; import styles from './styles.module.css'; -function DocPage(props) { +function DocPage(props): JSX.Element { const {route: baseRoute, docsMetadata, location} = props; // case-sensitive route such as it is defined in the sidebar const currentRoute = diff --git a/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.js b/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx similarity index 96% rename from packages/docusaurus-theme-classic/src/theme/DocPaginator/index.js rename to packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx index b771f38175d6..aea9a81d4b5f 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import Link from '@docusaurus/Link'; -function DocPaginator(props) { +function DocPaginator(props): JSX.Element { const {metadata} = props; return ( diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx similarity index 99% rename from packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js rename to packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx index 38504c8ab32d..1207e5b921bb 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx @@ -163,7 +163,7 @@ function DocSidebarItem(props) { } } -function DocSidebar(props) { +function DocSidebar(props): JSX.Element | null { const [showResponsiveSidebar, setShowResponsiveSidebar] = useState(false); const { siteConfig: { diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/index.js b/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx similarity index 98% rename from packages/docusaurus-theme-classic/src/theme/Footer/index.js rename to packages/docusaurus-theme-classic/src/theme/Footer/index.tsx index a60e0c707246..a942520f1b9f 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx @@ -39,7 +39,7 @@ const FooterLogo = ({url, alt}) => ( {alt} ); -function Footer() { +function Footer(): JSX.Element | null { const context = useDocusaurusContext(); const {siteConfig = {}} = context; const {themeConfig = {}} = siteConfig; diff --git a/packages/docusaurus-theme-classic/src/theme/Heading/index.js b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx similarity index 92% rename from packages/docusaurus-theme-classic/src/theme/Heading/index.js rename to packages/docusaurus-theme-classic/src/theme/Heading/index.tsx index e649f680bd77..de76331ee56a 100644 --- a/packages/docusaurus-theme-classic/src/theme/Heading/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx @@ -14,7 +14,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import './styles.css'; import styles from './styles.module.css'; -const Heading = (Tag) => +const Heading = (Tag): ((props) => JSX.Element) => function TargetComponent({id, ...props}) { const { siteConfig: { @@ -30,7 +30,7 @@ const Heading = (Tag) =>
tags. links = document.getElementsByClassName(linkClassName); while (index < links.length && !itemHighlighted) { const link = links[index]; diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.js b/packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.ts similarity index 75% rename from packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.js rename to packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.ts index 2a2a98e8bfce..3c7bac9f137e 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.ts @@ -9,8 +9,13 @@ import {useState, useCallback, useEffect} from 'react'; const TAB_CHOICE_PREFIX = 'docusaurus.tab.'; -const useTabGroupChoice = () => { - const [tabGroupChoices, setChoices] = useState({}); +const useTabGroupChoice = (): { + tabGroupChoices: {readonly [groupId: string]: string}; + setTabGroupChoices: (groupId: string, newChoice: string) => void; +} => { + const [tabGroupChoices, setChoices] = useState<{ + readonly [groupId: string]: string; + }>({}); const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => { try { localStorage.setItem(`${TAB_CHOICE_PREFIX}${groupId}`, newChoice); @@ -23,7 +28,7 @@ const useTabGroupChoice = () => { try { const localStorageChoices = {}; for (let i = 0; i < localStorage.length; i += 1) { - const storageKey = localStorage.key(i); + const storageKey = localStorage.key(i) as string; if (storageKey.startsWith(TAB_CHOICE_PREFIX)) { const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length); localStorageChoices[groupId] = localStorage.getItem(storageKey); @@ -37,7 +42,7 @@ const useTabGroupChoice = () => { return { tabGroupChoices, - setTabGroupChoices: (groupId, newChoice) => { + setTabGroupChoices: (groupId: string, newChoice: string) => { setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice})); setChoiceSyncWithLocalStorage(groupId, newChoice); }, diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.js b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts similarity index 91% rename from packages/docusaurus-theme-classic/src/theme/hooks/useTheme.js rename to packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts index a0bd4e6d046a..99d7366fac05 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts @@ -14,7 +14,11 @@ const themes = { dark: 'dark', }; -const useTheme = () => { +const useTheme = (): { + isDarkTheme: boolean; + setLightTheme: () => void; + setDarkTheme: () => void; +} => { const { siteConfig: {themeConfig: {disableDarkMode}} = {}, } = useDocusaurusContext(); @@ -43,6 +47,7 @@ const useTheme = () => { }, []); useEffect(() => { + // @ts-expect-error: safe to set null as attribute document.documentElement.setAttribute('data-theme', theme); }, [theme]); diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js b/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.ts similarity index 74% rename from packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js rename to packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.ts index a71392756fa0..677bb51adb74 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.ts @@ -9,7 +9,11 @@ import {useContext} from 'react'; import ThemeContext from '@theme/ThemeContext'; -function useThemeContext() { +function useThemeContext(): { + isDarkTheme: boolean; + setLightTheme: () => void; + setDarkTheme: () => void; +} { return useContext(ThemeContext); } diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js b/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.ts similarity index 61% rename from packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js rename to packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.ts index d35259677322..3437255ee520 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.ts @@ -9,7 +9,12 @@ import {useContext} from 'react'; import UserPreferencesContext from '@theme/UserPreferencesContext'; -function useUserPreferencesContext() { +function useUserPreferencesContext(): { + tabGroupChoices: {readonly [groupId: string]: string}; + setTabGroupChoices: (groupId: string, newChoice: string) => void; + isAnnouncementBarClosed: boolean; + closeAnnouncementBar: () => void; +} { return useContext(UserPreferencesContext); } diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.js b/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts similarity index 90% rename from packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.js rename to packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts index 255dbfe5422b..36ede5cb7458 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts @@ -12,9 +12,9 @@ const desktopThresholdWidth = 996; const windowSizes = { desktop: 'desktop', mobile: 'mobile', -}; +} as const; -function useWindowSize() { +function useWindowSize(): 'desktop' | 'mobile' | undefined { const isClient = typeof window !== 'undefined'; function getSize() { @@ -30,7 +30,7 @@ function useWindowSize() { useEffect(() => { if (!isClient) { - return false; + return undefined; } function handleResize() { diff --git a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.js b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts similarity index 93% rename from packages/docusaurus-theme-classic/src/theme/prism-include-languages.js rename to packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts index bf0947ea86dd..693f775d0ceb 100644 --- a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.js +++ b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts @@ -8,7 +8,7 @@ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; import siteConfig from '@generated/docusaurus.config'; -const prismIncludeLanguages = (Prism) => { +const prismIncludeLanguages = (Prism): void => { if (ExecutionEnvironment.canUseDOM) { const { themeConfig: {prism: {additionalLanguages = []} = {}}, diff --git a/packages/docusaurus-theme-classic/src/types.d.ts b/packages/docusaurus-theme-classic/src/types.d.ts new file mode 100644 index 000000000000..684e0064fbf9 --- /dev/null +++ b/packages/docusaurus-theme-classic/src/types.d.ts @@ -0,0 +1,9 @@ +/** + * 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. + */ + +// eslint-disable-next-line spaced-comment +/// diff --git a/packages/docusaurus-theme-classic/tsconfig.json b/packages/docusaurus-theme-classic/tsconfig.json new file mode 100644 index 000000000000..d2a4d72b2c83 --- /dev/null +++ b/packages/docusaurus-theme-classic/tsconfig.json @@ -0,0 +1,13 @@ +{ + // This file is not used in compilation. It is here just for a nice editor experience. + "extends": "../../tsconfig.json", + "compilerOptions": { + "lib": ["DOM"], + "module": "esnext", + "noEmit": true, + "noImplicitAny": false, + "jsx": "react", + "baseUrl": "src" + }, + "include": ["src/"] +} diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index b9d29faad264..b7ec621cfa7d 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -118,6 +118,7 @@ export interface Plugin { utils: ConfigureWebpackUtils, ): Configuration; getThemePath?(): string; + getTypeScriptThemePath?(): string; getPathsToWatch?(): string[]; getClientModules?(): string[]; extendCli?(cli: Command): void; diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 14df6168903a..542b05ba2450 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -60,7 +60,7 @@ export function objectWithKeySorted(obj: {[index: string]: any}) { } const indexRE = /(^|.*\/)index\.(md|js|jsx|ts|tsx)$/i; -const extRE = /\.(md|js|tsx)$/; +const extRE = /\.(md|js|ts|tsx)$/; /** * Convert filepath to url path. diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index 97068cfd00ff..6bba9d1e6a9e 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -60,8 +60,17 @@ cli cli .command('swizzle [componentName] [siteDir]') .description('Copy the theme files into website folder for customization.') - .action((themeName, componentName, siteDir = '.') => { - wrapCommand(swizzle)(path.resolve(siteDir), themeName, componentName); + .option( + '--typescript', + 'Copy TypeScript theme files when possible (default: false)', + ) + .action((themeName, componentName, siteDir = '.', {typescript}) => { + wrapCommand(swizzle)( + path.resolve(siteDir), + themeName, + componentName, + typescript, + ); }); cli diff --git a/packages/docusaurus/src/commands/swizzle.ts b/packages/docusaurus/src/commands/swizzle.ts index c57a59f22caa..b9b52936a794 100644 --- a/packages/docusaurus/src/commands/swizzle.ts +++ b/packages/docusaurus/src/commands/swizzle.ts @@ -18,13 +18,16 @@ export default async function swizzle( siteDir: string, themeName: string, componentName?: string, + typescript?: boolean, ): Promise { const plugin = importFresh(themeName) as ( context: LoadContext, ) => Plugin; const context = loadContext(siteDir); const pluginInstance = plugin(context); - let fromPath = pluginInstance.getThemePath?.(); + let fromPath = typescript + ? (pluginInstance.getTypeScriptThemePath ?? pluginInstance.getThemePath)?.() + : pluginInstance.getThemePath?.(); if (fromPath) { let toPath = path.resolve(siteDir, THEME_PATH); @@ -32,10 +35,16 @@ export default async function swizzle( fromPath = path.join(fromPath, componentName); toPath = path.join(toPath, componentName); - // Handle single JavaScript file only. - // E.g: if does not exist, we try to swizzle .js instead - if (!fs.existsSync(fromPath) && fs.existsSync(`${fromPath}.js`)) { - [fromPath, toPath] = [`${fromPath}.js`, `${toPath}.js`]; + // Handle single TypeScript/JavaScript file only. + // E.g: if does not exist, we try to swizzle .(ts|tsx|js) instead + if (!fs.existsSync(fromPath)) { + if (fs.existsSync(`${fromPath}.ts`)) { + [fromPath, toPath] = [`${fromPath}.ts`, `${toPath}.ts`]; + } else if (fs.existsSync(`${fromPath}.tsx`)) { + [fromPath, toPath] = [`${fromPath}.tsx`, `${toPath}.tsx`]; + } else if (fs.existsSync(`${fromPath}.js`)) { + [fromPath, toPath] = [`${fromPath}.js`, `${toPath}.js`]; + } } } await fs.copy(fromPath, toPath); diff --git a/yarn.lock b/yarn.lock index 5b7b61839ca0..e1054101f4b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,22 @@ # yarn lockfile v1 +"@babel/cli@^7.8.4": + version "7.8.4" + resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.8.4.tgz#505fb053721a98777b2b175323ea4f090b7d3c1c" + integrity sha512-XXLgAm6LBbaNxaGhMAznXXaxtCWfuv6PIDJ9Alsy9JYTOh+j2jJz+L/162kkfU1j/pTSxK1xGmlwI4pdIMkoag== + dependencies: + commander "^4.0.1" + convert-source-map "^1.1.0" + fs-readdir-recursive "^1.1.0" + glob "^7.0.0" + lodash "^4.17.13" + make-dir "^2.1.0" + slash "^2.0.0" + source-map "^0.5.0" + optionalDependencies: + chokidar "^2.1.8" + "@babel/code-frame@7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" @@ -5762,7 +5778,7 @@ conventional-recommended-bump@^5.0.0: meow "^4.0.0" q "^1.5.1" -convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0: +convert-source-map@^1.1.0, convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442" integrity sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA== @@ -8256,6 +8272,11 @@ fs-minipass@^2.0.0: dependencies: minipass "^3.0.0" +fs-readdir-recursive@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" + integrity sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA== + fs-write-stream-atomic@^1.0.8: version "1.0.10" resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9" From fb5fe86ca6c10e70610407ad077c8f5d2693edfe Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 22 Jun 2020 22:26:06 -0400 Subject: [PATCH 2/8] Add tsc --noEmit to tsc script in theme-classic Now everything can pass the type checker! (although still a lot of any) --- package.json | 1 + .../src/index.d.ts | 5 +---- .../docusaurus-theme-classic/package.json | 2 +- .../src/theme/BlogListPage/index.tsx | 7 +++++- .../src/theme/BlogTagsListPage/index.tsx | 6 +++-- .../src/theme/CodeBlock/index.tsx | 14 +++++++++--- .../src/theme/DocPaginator/index.tsx | 8 ++++++- .../src/theme/DocSidebar/index.tsx | 2 +- .../src/theme/Heading/index.tsx | 4 ++-- .../src/theme/Layout/index.tsx | 15 +++++++++++-- .../src/theme/MDXComponents/index.tsx | 16 +++++++++----- .../src/theme/Navbar/index.tsx | 22 +++++++++++++++---- .../src/theme/NotFound.tsx | 2 +- .../src/theme/ThemeProvider/index.tsx | 4 ++-- .../src/theme/Toggle/index.tsx | 4 ++-- .../src/theme/hooks/useAnnouncementBar.ts | 4 +++- .../src/theme/hooks/useLogo.ts | 2 +- .../src/theme/hooks/useTOCHighlight.ts | 4 +++- .../src/theme/hooks/useTheme.ts | 2 +- .../src/theme/prism-include-languages.ts | 7 +++--- tsconfig.json | 2 +- yarn.lock | 5 +++++ 22 files changed, 99 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index f02cff5be3c5..92f85b3309da 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@types/lodash.pick": "^4.4.6", "@types/lodash.pickby": "^4.6.6", "@types/node": "^13.11.0", + "@types/prismjs": "^1.16.1", "@types/react": "^16.9.38", "@types/react-dev-utils": "^9.0.1", "@types/react-helmet": "^6.0.0", diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 0ce9464b708a..4eb1bc075396 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -37,10 +37,7 @@ declare module '@generated/routesChunkNames' { export default routesChunkNames; } -declare module '@theme/*' { - const component: any; - export default component; -} +declare module '@theme/*'; declare module '@docusaurus/*'; diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 9233ae67416c..8b377d118548 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -8,7 +8,7 @@ }, "license": "MIT", "scripts": { - "tsc": "yarn babel && yarn prettier", + "tsc": "tsc --noEmit && yarn babel && yarn prettier", "babel": "babel src -d lib --extensions \".tsx,.ts\" --copy-files", "prettier": "prettier --config ../../.prettierrc --write \"**/*.{js,ts}\"" }, diff --git a/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx index 75d12e459a4d..81de70722e1a 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx @@ -12,7 +12,12 @@ import Layout from '@theme/Layout'; import BlogPostItem from '@theme/BlogPostItem'; import BlogListPaginator from '@theme/BlogListPaginator'; -function BlogListPage(props): JSX.Element { +type Props = { + metadata: {permalink: string; title: string}; + items: {content}[]; +}; + +function BlogListPage(props: Props): JSX.Element { const {metadata, items} = props; const { siteConfig: {title: siteTitle}, diff --git a/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx index b3ce4c53279c..ace1226d74b8 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogTagsListPage/index.tsx @@ -10,12 +10,14 @@ import React from 'react'; import Layout from '@theme/Layout'; import Link from '@docusaurus/Link'; -function getCategoryOfTag(tag) { +function getCategoryOfTag(tag: string) { // tag's category should be customizable return tag[0].toUpperCase(); } -function BlogTagsListPage(props): JSX.Element { +type Tag = {permalink: string; name: string; count: number}; + +function BlogTagsListPage(props: {tags: Record}): JSX.Element { const {tags} = props; const tagCategories: {[category: string]: string[]} = {}; diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx index d0f2540e8394..df897c5522d6 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx @@ -122,15 +122,19 @@ export default ({ const prismTheme = usePrismTheme(); if (metastring && highlightLinesRangeRegex.test(metastring)) { - const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1]; + // Tested above + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const highlightLinesRange = metastring.match(highlightLinesRangeRegex)![1]; highlightLines = rangeParser .parse(highlightLinesRange) .filter((n) => n > 0); } if (metastring && codeBlockTitleRegex.test(metastring)) { + // Tested above + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion codeBlockTitle = metastring - .match(codeBlockTitleRegex)[0] + .match(codeBlockTitleRegex)![0] .split('title=')[1] .replace(/"+/g, ''); } @@ -159,7 +163,10 @@ export default ({ if (match !== null) { const directive = match .slice(1) - .reduce((final, item) => final || item, undefined); + .reduce( + (final: string | undefined, item) => final || item, + undefined, + ); switch (directive) { case 'highlight-next-line': range += `${lineNumber},`; @@ -199,6 +206,7 @@ export default ({ key={String(mounted)} theme={prismTheme} code={code} + // @ts-expect-error: prism-react-renderer doesn't export Language type language={language}> {({className, style, tokens, getLineProps, getTokenProps}) => ( <> diff --git a/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx index aea9a81d4b5f..3d0f917f8f56 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPaginator/index.tsx @@ -8,7 +8,13 @@ import React from 'react'; import Link from '@docusaurus/Link'; -function DocPaginator(props): JSX.Element { +type PageInfo = {permalink: string; title: string}; + +type Props = { + metadata: {previous: PageInfo; next: PageInfo}; +}; + +function DocPaginator(props: Props): JSX.Element { const {metadata} = props; return ( diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx index 1207e5b921bb..558658649363 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx @@ -167,7 +167,7 @@ function DocSidebar(props): JSX.Element | null { const [showResponsiveSidebar, setShowResponsiveSidebar] = useState(false); const { siteConfig: { - themeConfig: {navbar: {title, hideOnScroll = false} = {}}, + themeConfig: {navbar: {title = '', hideOnScroll = false} = {}} = {}, } = {}, isClient, } = useDocusaurusContext(); diff --git a/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx index de76331ee56a..1e114dfd9017 100644 --- a/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx @@ -7,14 +7,14 @@ /* eslint-disable jsx-a11y/anchor-has-content, jsx-a11y/anchor-is-valid */ -import React from 'react'; +import React, {ComponentType} from 'react'; import clsx from 'clsx'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import './styles.css'; import styles from './styles.module.css'; -const Heading = (Tag): ((props) => JSX.Element) => +const Heading = (Tag: ComponentType): ((props) => JSX.Element) => function TargetComponent({id, ...props}) { const { siteConfig: { diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx index 090e1a27952a..b5ea1d72ba26 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React from 'react'; +import React, {ReactNode} from 'react'; import Head from '@docusaurus/Head'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; @@ -18,7 +18,18 @@ import Footer from '@theme/Footer'; import './styles.css'; -function Layout(props) { +type Props = { + children: ReactNode; + title?: string; + noFooter?: boolean; + description?: string; + image?: string; + keywords?: string[]; + permalink?: string; + version?: string; +}; + +function Layout(props: Props): JSX.Element { const {siteConfig = {}} = useDocusaurusContext(); const { favicon, diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx index 15945e73fe73..799e08671e60 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx @@ -5,7 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import React from 'react'; +import React, { + HTMLAttributes, + AnchorHTMLAttributes, + ComponentProps, +} from 'react'; import Link from '@docusaurus/Link'; import CodeBlock from '@theme/CodeBlock'; import Heading from '@theme/Heading'; @@ -13,7 +17,7 @@ import Heading from '@theme/Heading'; import styles from './styles.module.css'; export default { - code: (props) => { + code: (props: ComponentProps): JSX.Element => { const {children} = props; if (typeof children === 'string') { if (!children.includes('\n')) { @@ -23,14 +27,16 @@ export default { } return children; }, - a: (props) => { - if (/\.[^./]+$/.test(props.href)) { + a: (props: AnchorHTMLAttributes): JSX.Element => { + if (/\.[^./]+$/.test(props.href || '')) { // eslint-disable-next-line jsx-a11y/anchor-has-content return ; } return ; }, - pre: (props) =>
, + pre: (props: HTMLAttributes): JSX.Element => ( +
+ ), h1: Heading('h1'), h2: Heading('h2'), h3: Heading('h3'), diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx index ef181dcf9f43..1ada1e03d1df 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx @@ -5,7 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import React, {useCallback, useState, useEffect} from 'react'; +import React, { + useCallback, + useState, + useEffect, + AnchorHTMLAttributes, +} from 'react'; import clsx from 'clsx'; import Link from '@docusaurus/Link'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; @@ -33,7 +38,15 @@ function NavLink({ activeClassName = 'navbar__link--active', prependBaseUrlToHref, ...props -}) { +}: { + activeBasePath?: string; + activeBaseRegex?: string; + to?: string; + href?: string; + label?: string; + activeClassName?: string; + prependBaseUrlToHref?: string; +} & AnchorHTMLAttributes) { const toUrl = useBaseUrl(to); const activeBaseUrl = useBaseUrl(activeBasePath); const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true}); @@ -96,7 +109,8 @@ function NavItem({ onClick={(e) => e.preventDefault()} onKeyDown={(e) => { if (e.key === 'Enter') { - e.target.parentNode.classList.toggle('dropdown--show'); + ((e.target as HTMLElement) + .parentNode as HTMLElement).classList.toggle('dropdown--show'); } }}> {props.label} @@ -175,7 +189,7 @@ function Navbar(): JSX.Element { const { siteConfig: { themeConfig: { - navbar: {title, links = [], hideOnScroll = false} = {}, + navbar: {title = '', links = [], hideOnScroll = false} = {}, disableDarkMode = false, }, }, diff --git a/packages/docusaurus-theme-classic/src/theme/NotFound.tsx b/packages/docusaurus-theme-classic/src/theme/NotFound.tsx index 955f51e2b4f7..c06fd3e53d60 100644 --- a/packages/docusaurus-theme-classic/src/theme/NotFound.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NotFound.tsx @@ -8,7 +8,7 @@ import React from 'react'; import Layout from '@theme/Layout'; -function NotFound() { +function NotFound(): JSX.Element { return (
diff --git a/packages/docusaurus-theme-classic/src/theme/ThemeProvider/index.tsx b/packages/docusaurus-theme-classic/src/theme/ThemeProvider/index.tsx index e1dd0572d665..be26e0d16551 100644 --- a/packages/docusaurus-theme-classic/src/theme/ThemeProvider/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/ThemeProvider/index.tsx @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import React, { ReactNode } from 'react'; +import React, {ReactNode} from 'react'; import useTheme from '@theme/hooks/useTheme'; import ThemeContext from '@theme/ThemeContext'; -function ThemeProvider(props: { readonly children: ReactNode }) { +function ThemeProvider(props: {readonly children: ReactNode}): JSX.Element { const {isDarkTheme, setLightTheme, setDarkTheme} = useTheme(); return ( diff --git a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx index cdb0956abf5f..a73e95e05551 100644 --- a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React from 'react'; +import React, {ComponentProps} from 'react'; import Toggle from 'react-toggle'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; @@ -16,7 +16,7 @@ import styles from './styles.module.css'; const Moon = () => ; const Sun = () => ; -export default function (props) { +export default function (props: ComponentProps): JSX.Element { const {isClient} = useDocusaurusContext(); return ( void; } => { const { - siteConfig: {themeConfig: {announcementBar: {id} = {}}} = {}, + siteConfig: { + themeConfig: {announcementBar: {id = 'annoucement-bar'} = {}} = {}, + } = {}, } = useDocusaurusContext(); const [isClosed, setClosed] = useState(true); const handleClose = () => { diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useLogo.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useLogo.ts index 917bd3105a17..4631f8aec329 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useLogo.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useLogo.ts @@ -19,7 +19,7 @@ const useLogo = (): { logoAlt: string; } => { const { - siteConfig: {themeConfig: {navbar: {logo = {}} = {}}} = {}, + siteConfig: {themeConfig: {navbar: {logo = {}} = {}} = {}} = {}, } = useDocusaurusContext(); const {isDarkTheme} = useThemeContext(); const logoLink = useBaseUrl(logo.href || '/'); diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useTOCHighlight.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useTOCHighlight.ts index 5051940259cb..16cb1fe573d6 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useTOCHighlight.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useTOCHighlight.ts @@ -12,7 +12,9 @@ function useTOCHighlight( linkActiveClassName: string, topOffset: number, ): void { - const [lastActiveLink, setLastActiveLink] = useState(undefined); + const [lastActiveLink, setLastActiveLink] = useState( + undefined!, + ); useEffect(() => { let headersAnchors: HTMLCollectionOf; diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts index 99d7366fac05..6cd399b3211b 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts @@ -20,7 +20,7 @@ const useTheme = (): { setDarkTheme: () => void; } => { const { - siteConfig: {themeConfig: {disableDarkMode}} = {}, + siteConfig: {themeConfig: {disableDarkMode = false} = {}} = {}, } = useDocusaurusContext(); const [theme, setTheme] = useState( typeof document !== 'undefined' diff --git a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts index 693f775d0ceb..e1c813139818 100644 --- a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts +++ b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts @@ -7,16 +7,17 @@ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; import siteConfig from '@generated/docusaurus.config'; +import type * as PrismNamespace from 'prismjs'; -const prismIncludeLanguages = (Prism): void => { +const prismIncludeLanguages = (PrismObject: typeof PrismNamespace): void => { if (ExecutionEnvironment.canUseDOM) { const { themeConfig: {prism: {additionalLanguages = []} = {}}, } = siteConfig; - window.Prism = Prism; + window.Prism = PrismObject; - additionalLanguages.forEach((lang) => { + additionalLanguages.forEach((lang: string) => { require(`prismjs/components/prism-${lang}`); // eslint-disable-line }); diff --git a/tsconfig.json b/tsconfig.json index bf338b3df6bf..e0b11fc6d794 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es2017", "module": "commonjs", - "lib": ["es2017","es2019.array"], + "lib": ["es2017","es2019.array", "DOM"], "declaration": true, "declarationMap": true, diff --git a/yarn.lock b/yarn.lock index e1054101f4b6..cd4ec0e96cfe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3022,6 +3022,11 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.19.1.tgz#33509849f8e679e4add158959fdb086440e9553f" integrity sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ== +"@types/prismjs@^1.16.1": + version "1.16.1" + resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.16.1.tgz#50b82947207847db6abcbcd14caa89e3b897c259" + integrity sha512-RNgcK3FEc1GpeOkamGDq42EYkb6yZW5OWQwTS56NJIB8WL0QGISQglA7En7NUx9RGP8AC52DOe+squqbAckXlA== + "@types/prop-types@*": version "15.7.3" resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" From 9950f600771fcb2942a39be30582e744c1715376 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Jun 2020 18:58:49 -0400 Subject: [PATCH 3/8] Add tsconfig and types.d.ts to website Improve developer experience. As an example, I converted NotFound to tsx --- packages/docusaurus-theme-classic/tsconfig.json | 1 - website/src/theme/{NotFound.js => NotFound.tsx} | 2 +- website/src/types.d.ts | 9 +++++++++ website/tsconfig.json | 13 +++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) rename website/src/theme/{NotFound.js => NotFound.tsx} (92%) create mode 100644 website/src/types.d.ts create mode 100644 website/tsconfig.json diff --git a/packages/docusaurus-theme-classic/tsconfig.json b/packages/docusaurus-theme-classic/tsconfig.json index d2a4d72b2c83..a27160e60158 100644 --- a/packages/docusaurus-theme-classic/tsconfig.json +++ b/packages/docusaurus-theme-classic/tsconfig.json @@ -1,5 +1,4 @@ { - // This file is not used in compilation. It is here just for a nice editor experience. "extends": "../../tsconfig.json", "compilerOptions": { "lib": ["DOM"], diff --git a/website/src/theme/NotFound.js b/website/src/theme/NotFound.tsx similarity index 92% rename from website/src/theme/NotFound.js rename to website/src/theme/NotFound.tsx index 3d7c2b5ddda0..2dcfdcb2c57f 100644 --- a/website/src/theme/NotFound.js +++ b/website/src/theme/NotFound.tsx @@ -9,7 +9,7 @@ import React from 'react'; import Layout from '@theme/Layout'; import Feedback from '../pages/feedback'; -function NotFound({location}) { +function NotFound({location}: {location: {pathname: string}}): JSX.Element { if (/^\/feedback/.test(location.pathname)) { return ; } diff --git a/website/src/types.d.ts b/website/src/types.d.ts new file mode 100644 index 000000000000..684e0064fbf9 --- /dev/null +++ b/website/src/types.d.ts @@ -0,0 +1,9 @@ +/** + * 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. + */ + +// eslint-disable-next-line spaced-comment +/// diff --git a/website/tsconfig.json b/website/tsconfig.json new file mode 100644 index 000000000000..0f11fe0d4ae2 --- /dev/null +++ b/website/tsconfig.json @@ -0,0 +1,13 @@ +{ + // This file is not used in compilation. It is here just for a nice editor experience. + "extends": "../tsconfig.json", + "compilerOptions": { + "lib": ["DOM"], + "module": "esnext", + "noEmit": true, + "noImplicitAny": false, + "jsx": "react", + "baseUrl": "src" + }, + "include": ["src/"] +} From 52a5aa0499f517f0799fcb9a53949de7a1841f01 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Jun 2020 19:04:43 -0400 Subject: [PATCH 4/8] Apply type annotation suggestions --- .../src/theme/MDXComponents/index.tsx | 10 +++------- .../src/theme/Navbar/index.tsx | 9 ++------- .../docusaurus-theme-classic/src/theme/Tabs/index.tsx | 6 +++--- .../src/theme/hooks/useWindowSize.ts | 4 +++- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx index 799e08671e60..1083e690806a 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx @@ -5,11 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { - HTMLAttributes, - AnchorHTMLAttributes, - ComponentProps, -} from 'react'; +import React, {ComponentProps} from 'react'; import Link from '@docusaurus/Link'; import CodeBlock from '@theme/CodeBlock'; import Heading from '@theme/Heading'; @@ -27,14 +23,14 @@ export default { } return children; }, - a: (props: AnchorHTMLAttributes): JSX.Element => { + a: (props: ComponentProps<'a'>): JSX.Element => { if (/\.[^./]+$/.test(props.href || '')) { // eslint-disable-next-line jsx-a11y/anchor-has-content return ; } return ; }, - pre: (props: HTMLAttributes): JSX.Element => ( + pre: (props: ComponentProps<'div'>): JSX.Element => (
), h1: Heading('h1'), diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx index 1ada1e03d1df..798a4139f08a 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/index.tsx @@ -5,12 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { - useCallback, - useState, - useEffect, - AnchorHTMLAttributes, -} from 'react'; +import React, {useCallback, useState, useEffect, ComponentProps} from 'react'; import clsx from 'clsx'; import Link from '@docusaurus/Link'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; @@ -46,7 +41,7 @@ function NavLink({ label?: string; activeClassName?: string; prependBaseUrlToHref?: string; -} & AnchorHTMLAttributes) { +} & ComponentProps<'a'>) { const toUrl = useBaseUrl(to); const activeBaseUrl = useBaseUrl(activeBasePath); const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true}); diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx index 2aac0c7b6d3e..f714a15ff1ef 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, {useState, Children, ReactNode} from 'react'; +import React, {useState, Children, ReactElement} from 'react'; import useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext'; import clsx from 'clsx'; @@ -19,7 +19,7 @@ const keys = { type Props = { block?: boolean; - children: ReactNode; + children: ReactElement<{value: string}>[]; defaultValue?: string; values: {value: string; label: string}[]; groupId?: string; @@ -112,7 +112,7 @@ function Tabs(props: Props): JSX.Element { { Children.toArray(children).filter( (child) => - (child as React.Component<{value: string}>).props.value === + (child as ReactElement<{value: string}>).props.value === selectedValue, )[0] } diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts index 36ede5cb7458..7ec2e32818a6 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useWindowSize.ts @@ -14,7 +14,9 @@ const windowSizes = { mobile: 'mobile', } as const; -function useWindowSize(): 'desktop' | 'mobile' | undefined { +type WindowSize = keyof typeof windowSizes; + +function useWindowSize(): WindowSize | undefined { const isClient = typeof window !== 'undefined'; function getSize() { From 5bfd883b2c726cc4cf1f49096cf941d2d59cf31a Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Jun 2020 19:11:32 -0400 Subject: [PATCH 5/8] Do not fallback to `getThemePath` if getTypeScriptThemePath is undefined --- packages/docusaurus/src/commands/swizzle.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/src/commands/swizzle.ts b/packages/docusaurus/src/commands/swizzle.ts index b9b52936a794..f133ab547a00 100644 --- a/packages/docusaurus/src/commands/swizzle.ts +++ b/packages/docusaurus/src/commands/swizzle.ts @@ -26,7 +26,7 @@ export default async function swizzle( const context = loadContext(siteDir); const pluginInstance = plugin(context); let fromPath = typescript - ? (pluginInstance.getTypeScriptThemePath ?? pluginInstance.getThemePath)?.() + ? pluginInstance.getTypeScriptThemePath?.() : pluginInstance.getThemePath?.(); if (fromPath) { @@ -57,5 +57,13 @@ export default async function swizzle( console.log( `\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`, ); + } else if (typescript) { + console.warn( + chalk.yellow( + `${themeName} does not provide TypeScript theme code via getTypeScriptThemePath().`, + ), + ); + } else { + console.warn(chalk.yellow(`${themeName} does not provide any theme code.`)); } } From 676e43f179d301b280a1e5521f89c50900fbdc61 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Jun 2020 19:22:51 -0400 Subject: [PATCH 6/8] Fix tsc --- packages/docusaurus-theme-classic/src/theme/ThemeContext.ts | 2 +- .../src/theme/UserPreferencesContext.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/ThemeContext.ts b/packages/docusaurus-theme-classic/src/theme/ThemeContext.ts index e78020cad7fb..ad265a49e499 100644 --- a/packages/docusaurus-theme-classic/src/theme/ThemeContext.ts +++ b/packages/docusaurus-theme-classic/src/theme/ThemeContext.ts @@ -7,6 +7,6 @@ import React from 'react'; -const ThemeContext = React.createContext(); +const ThemeContext = React.createContext(undefined); export default ThemeContext; diff --git a/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.ts b/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.ts index 81f3675386b9..c9c8252f5dc3 100644 --- a/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.ts +++ b/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.ts @@ -7,6 +7,6 @@ import {createContext} from 'react'; -const UserPreferencesContext = createContext(); +const UserPreferencesContext = createContext(undefined); export default UserPreferencesContext; From 3042ceb115baa09b0da7276c6d45ba120dc93ca4 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 Jun 2020 19:23:40 -0400 Subject: [PATCH 7/8] Add module declaration for @theme-original/* --- packages/docusaurus-module-type-aliases/src/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 4eb1bc075396..ae41e1d54c3e 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -39,6 +39,8 @@ declare module '@generated/routesChunkNames' { declare module '@theme/*'; +declare module '@theme-original/*'; + declare module '@docusaurus/*'; declare module '*.module.css' { From d6c3a19e7f363d4dd9c09c9c1ec7a8a657a179cd Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 Jun 2020 21:46:12 -0400 Subject: [PATCH 8/8] Move babel cli to root package.json --- package.json | 1 + packages/docusaurus-theme-classic/package.json | 1 - yarn.lock | 10 +++++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 92f85b3309da..7f694d8c5680 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ }, "devDependencies": { "@babel/core": "^7.9.0", + "@babel/cli": "^7.9.0", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3", "@babel/plugin-proposal-optional-chaining": "^7.9.0", "@babel/preset-typescript": "^7.9.0", diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 8b377d118548..f544452cf025 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -26,7 +26,6 @@ "react-toggle": "^4.1.1" }, "devDependencies": { - "@babel/cli": "^7.8.4", "@docusaurus/module-type-aliases": "^2.0.0-alpha.58" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index 0a9696122423..bd46cdc5f529 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@babel/cli@^7.8.4": - version "7.8.4" - resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.8.4.tgz#505fb053721a98777b2b175323ea4f090b7d3c1c" - integrity sha512-XXLgAm6LBbaNxaGhMAznXXaxtCWfuv6PIDJ9Alsy9JYTOh+j2jJz+L/162kkfU1j/pTSxK1xGmlwI4pdIMkoag== +"@babel/cli@^7.9.0": + version "7.10.3" + resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.10.3.tgz#4ea83bd997d2a41c78d07263ada3ec466fb3764b" + integrity sha512-lWB3yH5/fWY8pi2Kj5/fA+17guJ9feSBw5DNjTju3/nRi9sXnl1JPh7aKQOSvdNbiDbkzzoGYtsr46M8dGmXDQ== dependencies: commander "^4.0.1" convert-source-map "^1.1.0" @@ -2855,7 +2855,7 @@ version "17.1.2" resolved "https://registry.yarnpkg.com/@types/hapi__joi/-/hapi__joi-17.1.2.tgz#f547d45b5d33677d1807ec217aeee832dc7e6334" integrity sha512-2S6+hBISRQ5Ca6/9zfQi7zPueWMGyZxox6xicqJuW1/aC/6ambLyh+gDqY5fi8JBuHmGKMHldSfEpIXJtTmGKQ== - + "@types/history@*": version "4.7.6" resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.6.tgz#ed8fc802c45b8e8f54419c2d054e55c9ea344356"