From 621000af5a7bd32b9d84f85ffb87488752c8bc1c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 8 Apr 2022 22:21:09 +0800 Subject: [PATCH] properly fix --- .../src/theme-classic.d.ts | 2 +- .../src/theme/Details/index.tsx | 4 +--- packages/docusaurus-theme-common/Details.d.ts | 14 ++++++++++++++ packages/docusaurus-theme-common/package.json | 7 ++++++- packages/docusaurus-theme-common/src/index.ts | 2 -- packages/docusaurus-theme-common/tsconfig.json | 3 ++- 6 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 packages/docusaurus-theme-common/Details.d.ts diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index 9f3c48ed3da0..997c9db361ee 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -857,7 +857,7 @@ declare module '@theme/ThemedImage' { } declare module '@theme/Details' { - import {Details, type DetailsProps} from '@docusaurus/theme-common'; + import {Details, type DetailsProps} from '@docusaurus/theme-common/Details'; export interface Props extends DetailsProps {} export default Details; diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 563343ba6316..188729351494 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -7,10 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import {Details as DetailsGeneric} from '@docusaurus/theme-common'; +import {Details as DetailsGeneric} from '@docusaurus/theme-common/Details'; import type {Props} from '@theme/Details'; -// Ensure that the default details style is properly overridden -import '@docusaurus/theme-common/lib/components/Details/styles.module.css'; import styles from './styles.module.css'; // Should we have a custom details/summary comp in Infima instead of reusing diff --git a/packages/docusaurus-theme-common/Details.d.ts b/packages/docusaurus-theme-common/Details.d.ts new file mode 100644 index 000000000000..61dab97e7363 --- /dev/null +++ b/packages/docusaurus-theme-common/Details.d.ts @@ -0,0 +1,14 @@ +/** + * 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. + */ + +// `Details` is a separate export entry because of side-effects messing with CSS +// insertion order. See https://github.com/facebook/docusaurus/pull/7085. +// However, because TS doesn't recognize `exports` (also a problem in +// `content-docs`), we have to manually create a stub. + +// eslint-disable-next-line import/named +export {Details, type DetailsProps} from './lib/components/Details'; diff --git a/packages/docusaurus-theme-common/package.json b/packages/docusaurus-theme-common/package.json index 19104c04fa8e..23e0625a1e31 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -5,8 +5,13 @@ "main": "./lib/index.js", "types": "./lib/index.d.ts", "sideEffects": [ - "lib/components/Details/*" + "lib/components/Details/*", + "*.css" ], + "exports": { + ".": "./lib/index.js", + "./Details": "./lib/components/Details/index.js" + }, "scripts": { "build": "node copyUntypedFiles.mjs && tsc", "watch": "node copyUntypedFiles.mjs && tsc --watch" diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index 77afa2fdfd21..3cb282b77614 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -63,8 +63,6 @@ export {useLocationChange} from './utils/useLocationChange'; export {useCollapsible, Collapsible} from './components/Collapsible'; -export {Details, type DetailsProps} from './components/Details'; - export { useDocsPreferredVersion, useDocsPreferredVersionByPluginId, diff --git a/packages/docusaurus-theme-common/tsconfig.json b/packages/docusaurus-theme-common/tsconfig.json index 074e3894b4d0..20c3d66f6411 100644 --- a/packages/docusaurus-theme-common/tsconfig.json +++ b/packages/docusaurus-theme-common/tsconfig.json @@ -8,5 +8,6 @@ "declarationMap": true, "rootDir": "src", "outDir": "lib" - } + }, + "include": ["src"] }