From 01adf25b0f978585b84736d62fb5fb41dcdcd302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 14 May 2021 15:36:55 +0200 Subject: [PATCH] chore(v2): TypeScript, use isolatedModules (#4790) * Use isolatedModules * better solution for useDocs? * fix blog-only mode * fix bad useDocs import --- admin/verdaccio.yaml | 3 ++ .../src/theme/hooks/useDocs.ts | 9 ++++-- .../src/theme/hooks/useDocs.ts | 28 +++---------------- packages/docusaurus-theme-common/src/index.ts | 5 ++-- tsconfig.json | 1 + 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/admin/verdaccio.yaml b/admin/verdaccio.yaml index a2d9e4e223..1e8c71c5a8 100644 --- a/admin/verdaccio.yaml +++ b/admin/verdaccio.yaml @@ -30,3 +30,6 @@ packages: # Log settings logs: - {type: stdout, format: pretty, level: http} + +# Fix 413 errors in e2e CI +max_body_size: 1000mb diff --git a/packages/docusaurus-plugin-content-docs/src/theme/hooks/useDocs.ts b/packages/docusaurus-plugin-content-docs/src/theme/hooks/useDocs.ts index 9c9e2b7884..46bfb46b41 100644 --- a/packages/docusaurus-plugin-content-docs/src/theme/hooks/useDocs.ts +++ b/packages/docusaurus-plugin-content-docs/src/theme/hooks/useDocs.ts @@ -6,8 +6,8 @@ */ import {useLocation} from '@docusaurus/router'; -import { - useAllPluginInstancesData, +import useGlobalData, { + // useAllPluginInstancesData, usePluginData, } from '@docusaurus/useGlobalData'; @@ -24,8 +24,11 @@ import { GetActivePluginOptions, } from '../../client/docsClientUtils'; +// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme +// We need a fail-safe fallback when the docs plugin is not in use export const useAllDocsData = (): Record => - useAllPluginInstancesData('docusaurus-plugin-content-docs'); + // useAllPluginInstancesData('docusaurus-plugin-content-docs'); + useGlobalData()['docusaurus-plugin-content-docs'] ?? {}; export const useDocsData = (pluginId: string | undefined): GlobalPluginData => usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData; diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useDocs.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useDocs.ts index 985ab8a040..a89ebfe8f3 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useDocs.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useDocs.ts @@ -5,27 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -// See https://github.com/facebook/docusaurus/issues/3360 -// TODO find a better solution, this shouldn't be needed - -// TODO this is not ideal and produce a warning! -// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437 -// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924 -try { - // eslint-disable-next-line global-require - module.exports = require('@theme-init/hooks/useDocs'); -} catch (e) { - // In case the docs plugin is not available, might be useful to stub some methods here - // https://github.com/facebook/docusaurus/issues/3947 - const Empty = {}; - module.exports = { - useAllDocsData: () => Empty, - useActivePluginAndVersion: () => undefined, - }; -} - -/* -throw new Error( - "The docs plugin is not used, so you can't require the useDocs hooks. ", -); - */ +// Re-expose useDocs +// Ensure it's always statically available even if user is not using the docs plugin +// Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360 +export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs'; diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index 6d5243f3ef..99278499ca 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -5,8 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -export { - useThemeConfig, +export {useThemeConfig} from './utils/useThemeConfig'; + +export type { ThemeConfig, Navbar, NavbarItem, diff --git a/tsconfig.json b/tsconfig.json index dd7ea79295..61e2b2df31 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,7 @@ "moduleResolution": "node", "allowSyntheticDefaultImports": true, "esModuleInterop": true, + "isolatedModules": true, /* Advanced Options */ "resolveJsonModule": true,