diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 0cdc4a0279b0..d9b5da24f861 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -38,6 +38,7 @@ declare module '@generated/routes' { readonly path: string; readonly component: RouteConfig['component']; readonly exact?: boolean; + readonly routes?: Route[]; }; const routes: Route[]; export default routes; diff --git a/packages/docusaurus-plugin-debug/copyUntypedFiles.js b/packages/docusaurus-plugin-debug/copyUntypedFiles.js new file mode 100644 index 000000000000..e5555c55368f --- /dev/null +++ b/packages/docusaurus-plugin-debug/copyUntypedFiles.js @@ -0,0 +1,20 @@ +/** + * 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. + */ + +const path = require('path'); +const fs = require('fs-extra'); + +/** + * Copy all untyped and static assets files to lib. + */ +const srcDir = path.resolve(__dirname, 'src'); +const libDir = path.resolve(__dirname, 'lib'); +fs.copySync(srcDir, libDir, { + filter(filepath) { + return !/__tests__/.test(filepath) && !/\.tsx?$/.test(filepath); + }, +}); diff --git a/packages/docusaurus-plugin-debug/package.json b/packages/docusaurus-plugin-debug/package.json index 7349206c0e79..0c814c7c0678 100644 --- a/packages/docusaurus-plugin-debug/package.json +++ b/packages/docusaurus-plugin-debug/package.json @@ -3,9 +3,10 @@ "version": "2.0.0-beta.5", "description": "Debug plugin for Docusaurus.", "main": "lib/index.js", + "types": "src/types.d.ts", "scripts": { - "build": "tsc", - "watch": "tsc --watch" + "build": "tsc && node copyUntypedFiles.js", + "watch": "node copyUntypedFiles.js && tsc --watch" }, "publishConfig": { "access": "public" @@ -20,6 +21,7 @@ "@docusaurus/core": "2.0.0-beta.5", "@docusaurus/types": "2.0.0-beta.5", "@docusaurus/utils": "2.0.0-beta.5", + "fs-extra": "^9.1.0", "react-json-view": "^1.21.3", "tslib": "^2.1.0" }, diff --git a/packages/docusaurus-plugin-debug/src/index.ts b/packages/docusaurus-plugin-debug/src/index.ts index bbb09c09e936..fe37ceb9e013 100644 --- a/packages/docusaurus-plugin-debug/src/index.ts +++ b/packages/docusaurus-plugin-debug/src/index.ts @@ -24,7 +24,7 @@ export default function pluginDebug({ name: 'docusaurus-plugin-debug', getThemePath() { - return path.resolve(__dirname, '../src/theme'); + return path.resolve(__dirname, '../lib/theme'); }, async contentLoaded({actions: {createData, addRoute}, allContent}) { diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.tsx similarity index 69% rename from packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.tsx index 83ec1e386f8a..7a233a4e38db 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.tsx @@ -7,17 +7,17 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; -import DebugJsonView from '../DebugJsonView'; +import DebugLayout from '@theme/DebugLayout'; +import DebugJsonView from '@theme/DebugJsonView'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -function DebugMetadata() { +function DebugMetadata(): JSX.Element { const {siteConfig} = useDocusaurusContext(); return (

Site config

- +
); } diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.tsx similarity index 74% rename from packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugContent/index.tsx index e798dd0f7d61..a3a6a53b975f 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.tsx @@ -7,17 +7,30 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; -import DebugJsonView from '../DebugJsonView'; +import DebugLayout from '@theme/DebugLayout'; +import DebugJsonView from '@theme/DebugJsonView'; +import type {Props} from '@theme/DebugContent'; -const PluginInstanceContent = ({pluginId, pluginInstanceContent}) => ( +const PluginInstanceContent = ({ + pluginId, + pluginInstanceContent, +}: { + pluginId: string; + pluginInstanceContent: unknown; +}) => (
{pluginId} - +
); -const PluginContent = ({pluginName, pluginContent}) => { +const PluginContent = ({ + pluginName, + pluginContent, +}: { + pluginName: string; + pluginContent: Record; +}) => { return (

{pluginName}

@@ -41,7 +54,7 @@ const PluginContent = ({pluginName, pluginContent}) => { ); }; -function DebugContent({allContent}) { +function DebugContent({allContent}: Props): JSX.Element { return (

Plugin content

diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.tsx similarity index 68% rename from packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.tsx index 84b4c7599c1f..1f75152b9ee9 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugGlobalData/index.tsx @@ -7,16 +7,16 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; -import DebugJsonView from '../DebugJsonView'; +import DebugLayout from '@theme/DebugLayout'; +import DebugJsonView from '@theme/DebugJsonView'; import useGlobalData from '@docusaurus/useGlobalData'; -function DebugMetadata() { +function DebugMetadata(): JSX.Element { const globalData = useGlobalData(); return (

Global data

- +
); } diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.tsx similarity index 71% rename from packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.tsx index d0a02ffeae63..6e5ef0e0e53f 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.tsx @@ -6,19 +6,20 @@ */ import React from 'react'; - import BrowserOnly from '@docusaurus/BrowserOnly'; +import type {Props} from '@theme/DebugJsonView'; +import type {ReactJsonViewProps} from 'react-json-view'; // avoids "react-json-view" to display "root" -const RootName = false; +const RootName = null; // Seems ReactJson does not work with SSR // https://github.com/mac-s-g/react-json-view/issues/121 -const BrowserOnlyReactJson = (props) => { +const BrowserOnlyReactJson = (props: ReactJsonViewProps) => { return ( {() => { - // eslint-disable-next-line global-require + // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires const ReactJson = require('react-json-view').default; return ; }} @@ -26,10 +27,12 @@ const BrowserOnlyReactJson = (props) => { ); }; -function DebugJsonView({src, collapseDepth}) { +function DebugJsonView({src, collapseDepth}: Props): JSX.Element { return ( 50; }} collapsed={collapseDepth} - groupArraysAfterLength="5" + groupArraysAfterLength={5} enableClipboard={false} displayDataTypes={false} /> diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.tsx similarity index 87% rename from packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.tsx index c075a1fdd627..abdd65a848c4 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.tsx @@ -5,12 +5,12 @@ * 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 Link from '@docusaurus/Link'; import styles from './styles.module.css'; -const DebugNavLink = ({to, children}) => ( +const DebugNavLink = ({to, children}: {to: string; children: ReactNode}) => ( ( ); -function DebugLayout({children}) { +function DebugLayout({children}: {children: ReactNode}): JSX.Element { return ( <> diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.tsx similarity index 90% rename from packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.tsx index 5df4c763fc58..24e49ed027ec 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.tsx @@ -7,11 +7,11 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; +import DebugLayout from '@theme/DebugLayout'; import registry from '@generated/registry'; import styles from './styles.module.css'; -function DebugRegistry() { +function DebugRegistry(): JSX.Element { return (

Registry

diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.tsx similarity index 88% rename from packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.tsx index 8ffa8c0505ea..0c8f37407ab5 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.tsx @@ -7,12 +7,12 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; -import DebugJsonView from '../DebugJsonView'; +import DebugLayout from '@theme/DebugLayout'; +import DebugJsonView from '@theme/DebugJsonView'; import routes from '@generated/routes'; import styles from './styles.module.css'; -function DebugRoutes() { +function DebugRoutes(): JSX.Element { return (

Routes

diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.tsx similarity index 76% rename from packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.js rename to packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.tsx index c78e03a1472e..b72b4484360e 100644 --- a/packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.js +++ b/packages/docusaurus-plugin-debug/src/theme/DebugSiteMetadata/index.tsx @@ -7,11 +7,11 @@ import React from 'react'; -import DebugLayout from '../DebugLayout'; +import DebugLayout from '@theme/DebugLayout'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import styles from './styles.module.css'; -function DebugMetadata() { +function DebugMetadata(): JSX.Element { const {siteMetadata} = useDocusaurusContext(); return ( @@ -28,11 +28,12 @@ function DebugMetadata() { {Object.entries(siteMetadata.pluginVersions).map( ([name, versionInformation]) => (
  • - {versionInformation.version && ( -
    - {versionInformation.version} -
    - )} + {versionInformation.type === 'package' && + versionInformation.version && ( +
    + {versionInformation.version} +
    + )}
    {name}
    Type: {versionInformation.type}
  • diff --git a/packages/docusaurus-plugin-debug/src/types.d.ts b/packages/docusaurus-plugin-debug/src/types.d.ts new file mode 100644 index 000000000000..e21f8108c146 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/types.d.ts @@ -0,0 +1,51 @@ +/** + * 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. + */ + +/// + +declare module '@theme/DebugConfig' { + export default function DebugMetadata(): JSX.Element; +} + +declare module '@theme/DebugContent' { + import type {AllContent} from '@docusaurus/types'; + + export type Props = { + allContent: AllContent; + }; + export default function DebugContent(props: Props): JSX.Element; +} + +declare module '@theme/DebugGlobalData' { + export default function DebugGlobalData(): JSX.Element; +} + +declare module '@theme/DebugJsonView' { + export type Props = { + src: unknown; + collapseDepth?: number; + }; + export default function DebugJsonView(props: Props): JSX.Element; +} + +declare module '@theme/DebugLayout' { + export default function DebugLayout(props: { + children: ReactNode; + }): JSX.Element; +} + +declare module '@theme/DebugRegistry' { + export default function DebugRegistry(): JSX.Element; +} + +declare module '@theme/DebugRoutes' { + export default function DebugRoutes(): JSX.Element; +} + +declare module '@theme/DebugSiteMetadata' { + export default function DebugSiteMetadata(): JSX.Element; +}