From 2347564b31ed4f5cfbd98a29daaf942969f5d337 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 13:41:35 +0800 Subject: [PATCH 01/10] refactor: mark a few client-side packages as side-effect-free --- packages/docusaurus-plugin-content-docs/package.json | 1 + packages/docusaurus-theme-common/package.json | 1 + packages/docusaurus-theme-live-codeblock/package.json | 1 + packages/docusaurus-theme-search-algolia/package.json | 1 + packages/docusaurus-utils-common/package.json | 1 + 5 files changed, 5 insertions(+) diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index c080891df07f..74c02f89345b 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -3,6 +3,7 @@ "version": "2.0.0-beta.18", "description": "Docs plugin for Docusaurus.", "main": "lib/index.js", + "sideEffects": false, "exports": { "./client": "./lib/client/index.js", "./server": "./lib/server-export.js", diff --git a/packages/docusaurus-theme-common/package.json b/packages/docusaurus-theme-common/package.json index 9c77f8eb95b9..98ee259caf2b 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -4,6 +4,7 @@ "description": "Common code for Docusaurus themes.", "main": "./lib/index.js", "types": "./lib/index.d.ts", + "sideEffects": false, "scripts": { "build": "node copyUntypedFiles.mjs && tsc", "watch": "node copyUntypedFiles.mjs && tsc --watch" diff --git a/packages/docusaurus-theme-live-codeblock/package.json b/packages/docusaurus-theme-live-codeblock/package.json index ffdcbb6ca6b0..b4745279e115 100644 --- a/packages/docusaurus-theme-live-codeblock/package.json +++ b/packages/docusaurus-theme-live-codeblock/package.json @@ -4,6 +4,7 @@ "description": "Docusaurus live code block component.", "main": "lib/index.js", "types": "src/theme-live-codeblock.d.ts", + "sideEffects": false, "publishConfig": { "access": "public" }, diff --git a/packages/docusaurus-theme-search-algolia/package.json b/packages/docusaurus-theme-search-algolia/package.json index e2cd35f6bdf6..1265927d34ad 100644 --- a/packages/docusaurus-theme-search-algolia/package.json +++ b/packages/docusaurus-theme-search-algolia/package.json @@ -3,6 +3,7 @@ "version": "2.0.0-beta.18", "description": "Algolia search component for Docusaurus.", "main": "lib/index.js", + "sideEffects": false, "exports": { "./client": "./lib/client/index.js", ".": "./lib/index.js" diff --git a/packages/docusaurus-utils-common/package.json b/packages/docusaurus-utils-common/package.json index ee7156d5b08b..a544907d5ea0 100644 --- a/packages/docusaurus-utils-common/package.json +++ b/packages/docusaurus-utils-common/package.json @@ -4,6 +4,7 @@ "description": "Common (Node/Browser) utility functions for Docusaurus packages.", "main": "./lib/index.js", "types": "./lib/index.d.ts", + "sideEffects": false, "scripts": { "build": "tsc", "watch": "tsc --watch" From 913713cd7c2bb8b63448ae99adc3a9624f19402d Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 14:10:18 +0800 Subject: [PATCH 02/10] fix --- packages/docusaurus-theme-classic/package.json | 4 ++++ packages/docusaurus-theme-common/package.json | 4 +++- packages/docusaurus-theme-live-codeblock/package.json | 4 +++- packages/docusaurus-theme-search-algolia/package.json | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 9536af7b3b17..d7b224d29350 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -4,6 +4,10 @@ "description": "Classic theme for Docusaurus", "main": "lib/index.js", "types": "src/theme-classic.d.ts", + "sideEffects": [ + "*.css", + "lib/prism-include-languages.js" + ], "publishConfig": { "access": "public" }, diff --git a/packages/docusaurus-theme-common/package.json b/packages/docusaurus-theme-common/package.json index 98ee259caf2b..7fbcbe0234fc 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -4,7 +4,9 @@ "description": "Common code for Docusaurus themes.", "main": "./lib/index.js", "types": "./lib/index.d.ts", - "sideEffects": false, + "sideEffects": [ + "*.css" + ], "scripts": { "build": "node copyUntypedFiles.mjs && tsc", "watch": "node copyUntypedFiles.mjs && tsc --watch" diff --git a/packages/docusaurus-theme-live-codeblock/package.json b/packages/docusaurus-theme-live-codeblock/package.json index b4745279e115..160769446785 100644 --- a/packages/docusaurus-theme-live-codeblock/package.json +++ b/packages/docusaurus-theme-live-codeblock/package.json @@ -4,7 +4,9 @@ "description": "Docusaurus live code block component.", "main": "lib/index.js", "types": "src/theme-live-codeblock.d.ts", - "sideEffects": false, + "sideEffects": [ + "*.css" + ], "publishConfig": { "access": "public" }, diff --git a/packages/docusaurus-theme-search-algolia/package.json b/packages/docusaurus-theme-search-algolia/package.json index 1265927d34ad..7637c85dcde1 100644 --- a/packages/docusaurus-theme-search-algolia/package.json +++ b/packages/docusaurus-theme-search-algolia/package.json @@ -3,7 +3,9 @@ "version": "2.0.0-beta.18", "description": "Algolia search component for Docusaurus.", "main": "lib/index.js", - "sideEffects": false, + "sideEffects": [ + "*.css" + ], "exports": { "./client": "./lib/client/index.js", ".": "./lib/index.js" From 1e34d722eb1662e2d4146fb3f2f8ade8bfc2d723 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 14:22:35 +0800 Subject: [PATCH 03/10] fix again --- packages/docusaurus-theme-common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-common/package.json b/packages/docusaurus-theme-common/package.json index 7fbcbe0234fc..19104c04fa8e 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -5,7 +5,7 @@ "main": "./lib/index.js", "types": "./lib/index.d.ts", "sideEffects": [ - "*.css" + "lib/components/Details/*" ], "scripts": { "build": "node copyUntypedFiles.mjs && tsc", From aa3a6713eb26c877e76aa82bf28089e47c6ab93b Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 14:36:48 +0800 Subject: [PATCH 04/10] fix... --- packages/docusaurus-theme-classic/src/theme/Details/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 724863d73088..563343ba6316 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -9,6 +9,8 @@ import React from 'react'; import clsx from 'clsx'; import {Details as DetailsGeneric} from '@docusaurus/theme-common'; 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 From b0dec03771aab93a31052e428531e5c4639fc0b9 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 14:43:42 +0800 Subject: [PATCH 05/10] revert sideeffect --- packages/docusaurus-theme-classic/package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index d7b224d29350..9536af7b3b17 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -4,10 +4,6 @@ "description": "Classic theme for Docusaurus", "main": "lib/index.js", "types": "src/theme-classic.d.ts", - "sideEffects": [ - "*.css", - "lib/prism-include-languages.js" - ], "publishConfig": { "access": "public" }, From 5954f0b58858c331f3d0ff55163ddeecb047a4ab Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 14:45:07 +0800 Subject: [PATCH 06/10] revert --- packages/docusaurus-theme-classic/src/theme/Details/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 563343ba6316..724863d73088 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -9,8 +9,6 @@ import React from 'react'; import clsx from 'clsx'; import {Details as DetailsGeneric} from '@docusaurus/theme-common'; 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 From 306f5a89316d11a7bd6e838cb2d4951cea87a09f Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 16:22:13 +0800 Subject: [PATCH 07/10] fix again... --- packages/docusaurus-theme-classic/src/theme/Details/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 724863d73088..563343ba6316 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -9,6 +9,8 @@ import React from 'react'; import clsx from 'clsx'; import {Details as DetailsGeneric} from '@docusaurus/theme-common'; 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 From 06e43aa7e79efe11d932af77ea6b021c72700fbd Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 1 Apr 2022 16:31:54 +0800 Subject: [PATCH 08/10] properly fix --- packages/docusaurus-theme-classic/src/theme/Details/index.tsx | 2 -- packages/docusaurus-theme-common/package.json | 3 ++- packages/docusaurus-theme-live-codeblock/package.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 563343ba6316..724863d73088 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -9,8 +9,6 @@ import React from 'react'; import clsx from 'clsx'; import {Details as DetailsGeneric} from '@docusaurus/theme-common'; 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/package.json b/packages/docusaurus-theme-common/package.json index 19104c04fa8e..c961cf0f32e0 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -5,7 +5,8 @@ "main": "./lib/index.js", "types": "./lib/index.d.ts", "sideEffects": [ - "lib/components/Details/*" + "lib/components/Details/*", + "lib/index.js" ], "scripts": { "build": "node copyUntypedFiles.mjs && tsc", diff --git a/packages/docusaurus-theme-live-codeblock/package.json b/packages/docusaurus-theme-live-codeblock/package.json index 160769446785..04f9125977a9 100644 --- a/packages/docusaurus-theme-live-codeblock/package.json +++ b/packages/docusaurus-theme-live-codeblock/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "types": "src/theme-live-codeblock.d.ts", "sideEffects": [ - "*.css" + "lib/theme/Playground/*" ], "publishConfig": { "access": "public" From 4f6fd78db855b64d07d2edacf8b3f6e5ce5d1fcb Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sat, 2 Apr 2022 08:52:42 +0800 Subject: [PATCH 09/10] fix --- packages/docusaurus-theme-classic/src/theme/Details/index.tsx | 2 ++ packages/docusaurus-theme-common/package.json | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx index 724863d73088..563343ba6316 100644 --- a/packages/docusaurus-theme-classic/src/theme/Details/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Details/index.tsx @@ -9,6 +9,8 @@ import React from 'react'; import clsx from 'clsx'; import {Details as DetailsGeneric} from '@docusaurus/theme-common'; 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/package.json b/packages/docusaurus-theme-common/package.json index c961cf0f32e0..19104c04fa8e 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -5,8 +5,7 @@ "main": "./lib/index.js", "types": "./lib/index.d.ts", "sideEffects": [ - "lib/components/Details/*", - "lib/index.js" + "lib/components/Details/*" ], "scripts": { "build": "node copyUntypedFiles.mjs && tsc", From 621000af5a7bd32b9d84f85ffb87488752c8bc1c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 8 Apr 2022 22:21:09 +0800 Subject: [PATCH 10/10] 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"] }