From d9eed7ca7556a50de79b3ca2e4e8f15be73dfe14 Mon Sep 17 00:00:00 2001 From: slorber Date: Thu, 6 Aug 2020 20:39:04 +0200 Subject: [PATCH] improve debug plugin: - add multiple debug pages + debug layout - ability to debug plugin contentLoaded data --- .../src/normalizePluginOptions.ts | 3 + .../src/types.ts | 1 + .../src/index.ts | 9 +-- packages/docusaurus-plugin-debug/src/index.ts | 66 +++++++++++++++-- .../src/theme/Debug/index.js | 70 ------------------- .../src/theme/DebugConfig/index.js | 23 ++++++ .../{Debug => DebugConfig}/styles.module.css | 10 --- .../src/theme/DebugContent/index.js | 16 +++++ .../src/theme/DebugContent/styles.module.css | 7 ++ .../src/theme/DebugLayout/index.js | 39 +++++++++++ .../src/theme/DebugLayout/styles.module.css | 6 ++ .../src/theme/DebugMetadata/index.js | 40 +++++++++++ .../src/theme/DebugMetadata/styles.module.css | 7 ++ .../src/theme/DebugRegistry/index.js | 30 ++++++++ .../src/theme/DebugRegistry/styles.module.css | 7 ++ .../src/theme/DebugRoutes/index.js | 29 ++++++++ .../src/theme/DebugRoutes/styles.module.css | 7 ++ .../docusaurus-preset-classic/src/index.js | 5 +- .../theme/{Layout => DebugLayout}/index.js | 0 packages/docusaurus-types/src/index.d.ts | 12 +++- .../docusaurus/src/server/plugins/index.ts | 31 +++++--- .../docusaurus/src/server/plugins/init.ts | 9 ++- tsconfig.json | 4 +- website/docusaurus.config.js | 1 + 24 files changed, 325 insertions(+), 107 deletions(-) delete mode 100644 packages/docusaurus-plugin-debug/src/theme/Debug/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js rename packages/docusaurus-plugin-debug/src/theme/{Debug => DebugConfig}/styles.module.css (60%) create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugContent/styles.module.css create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugLayout/styles.module.css create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugMetadata/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugMetadata/styles.module.css create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugRegistry/styles.module.css create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js create mode 100644 packages/docusaurus-plugin-debug/src/theme/DebugRoutes/styles.module.css rename packages/docusaurus-theme-bootstrap/src/theme/{Layout => DebugLayout}/index.js (100%) diff --git a/packages/docusaurus-plugin-client-redirects/src/normalizePluginOptions.ts b/packages/docusaurus-plugin-client-redirects/src/normalizePluginOptions.ts index b5e07f662305..b05bee9f10ae 100644 --- a/packages/docusaurus-plugin-client-redirects/src/normalizePluginOptions.ts +++ b/packages/docusaurus-plugin-client-redirects/src/normalizePluginOptions.ts @@ -8,8 +8,10 @@ import {PluginOptions, RedirectOption, UserPluginOptions} from './types'; import * as Joi from '@hapi/joi'; import {PathnameValidator} from './redirectValidation'; +import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants'; export const DefaultPluginOptions: PluginOptions = { + id: DEFAULT_PLUGIN_ID, // TODO temporary fromExtensions: [], toExtensions: [], redirects: [], @@ -26,6 +28,7 @@ const RedirectPluginOptionValidation = Joi.object({ const isString = Joi.string().required().not(null); const UserOptionsSchema = Joi.object({ + id: Joi.string().optional(), // TODO remove once validation migrated to new system fromExtensions: Joi.array().items(isString), toExtensions: Joi.array().items(isString), redirects: Joi.array().items(RedirectPluginOptionValidation), diff --git a/packages/docusaurus-plugin-client-redirects/src/types.ts b/packages/docusaurus-plugin-client-redirects/src/types.ts index 15c0987e0dd0..32ccdfd66d21 100644 --- a/packages/docusaurus-plugin-client-redirects/src/types.ts +++ b/packages/docusaurus-plugin-client-redirects/src/types.ts @@ -8,6 +8,7 @@ import {Props} from '@docusaurus/types'; export type PluginOptions = { + id: string; fromExtensions: string[]; toExtensions: string[]; redirects: RedirectOption[]; diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index c77f082a7b9d..8a4573f596c6 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -28,7 +28,6 @@ import { import {PluginOptionSchema} from './pluginOptionSchema'; import { LoadContext, - PluginContentLoadedActions, ConfigureWebpackUtils, Props, Plugin, @@ -195,13 +194,7 @@ export default function pluginContentBlog( }; }, - async contentLoaded({ - content: blogContents, - actions, - }: { - content: BlogContent; - actions: PluginContentLoadedActions; - }) { + async contentLoaded({content: blogContents, actions}) { if (!blogContents) { return; } diff --git a/packages/docusaurus-plugin-debug/src/index.ts b/packages/docusaurus-plugin-debug/src/index.ts index 8eadee856646..1ca9d6f0e1af 100644 --- a/packages/docusaurus-plugin-debug/src/index.ts +++ b/packages/docusaurus-plugin-debug/src/index.ts @@ -6,13 +6,20 @@ */ import {LoadContext, Plugin} from '@docusaurus/types'; -import {normalizeUrl} from '@docusaurus/utils'; - +import {docuHash, normalizeUrl} from '@docusaurus/utils'; import path from 'path'; export default function pluginContentPages({ siteConfig: {baseUrl}, + generatedFilesDir, }: LoadContext): Plugin { + const pluginDataDirRoot = path.join( + generatedFilesDir, + 'docusaurus-plugin-debug', + ); + const aliasedSource = (source: string) => + `~debug/${path.relative(pluginDataDirRoot, source)}`; + return { name: 'docusaurus-plugin-debug', @@ -20,12 +27,63 @@ export default function pluginContentPages({ return path.resolve(__dirname, '../src/theme'); }, - contentLoaded({actions: {addRoute}}) { + async contentLoaded({actions: {createData, addRoute}, allContent}) { + const allContentPath = await createData( + // Note that this created data path must be in sync with + // metadataPath provided to mdx-loader. + `${docuHash('docusaurus-debug-allContent')}.json`, + JSON.stringify(allContent, null, 2), + ); + + // Home is config (duplicate for now) addRoute({ path: normalizeUrl([baseUrl, '__docusaurus/debug']), - component: '@theme/Debug', + component: '@theme/DebugConfig', + exact: true, + }); + + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug/config']), + component: '@theme/DebugConfig', exact: true, }); + + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug/metadata']), + component: '@theme/DebugMetadata', + exact: true, + }); + + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug/registry']), + component: '@theme/DebugRegistry', + exact: true, + }); + + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug/routes']), + component: '@theme/DebugRoutes', + exact: true, + }); + + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug/content']), + component: '@theme/DebugContent', + exact: true, + modules: { + allContent: aliasedSource(allContentPath), + }, + }); + }, + + configureWebpack() { + return { + resolve: { + alias: { + '~debug': pluginDataDirRoot, + }, + }, + }; }, }; } diff --git a/packages/docusaurus-plugin-debug/src/theme/Debug/index.js b/packages/docusaurus-plugin-debug/src/theme/Debug/index.js deleted file mode 100644 index 49a3a9f4519c..000000000000 --- a/packages/docusaurus-plugin-debug/src/theme/Debug/index.js +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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. - */ - -import React from 'react'; -import Layout from '@theme/Layout'; - -import registry from '@generated/registry'; -import routes from '@generated/routes'; - -import styles from './styles.module.css'; -import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; - -function Debug() { - const {siteMetadata} = useDocusaurusContext(); - return ( - -
-
-

Site Metadata

-
Docusaurus Version: {siteMetadata.docusaurusVersion}
-
- Site Version: {siteMetadata.siteVersion || 'No version specified'} -
-

Plugins and themes:

-
    - {Object.entries(siteMetadata.pluginVersions).map( - ([name, versionInformation]) => ( -
  • -
    Name: {name}
    -
    Type: {versionInformation.type}
    - {versionInformation.version && ( -
    Version: {versionInformation.version}
    - )} -
  • - ), - )} -
-
-
-

Registry

-
    - {Object.values(registry).map(([, aliasedPath, resolved]) => ( -
  • -
    Aliased Path: {aliasedPath}
    -
    Resolved Path: {resolved}
    -
  • - ))} -
-
-
-

Routes

-
    - {routes.map(({path, exact}) => ( -
  • -
    Route: {path}
    -
    Is exact: {String(Boolean(exact))}
    -
  • - ))} -
-
-
-
- ); -} - -export default Debug; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js new file mode 100644 index 000000000000..99a4191bc8ea --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.js @@ -0,0 +1,23 @@ +/** + * 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. + */ + +import React from 'react'; + +import DebugLayout from '../DebugLayout'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; + +function DebugMetadata() { + const {siteConfig} = useDocusaurusContext(); + return ( + +

Site config

+
{JSON.stringify(siteConfig, null, 2)}
+
+ ); +} + +export default DebugMetadata; diff --git a/packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/styles.module.css similarity index 60% rename from packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css rename to packages/docusaurus-plugin-debug/src/theme/DebugConfig/styles.module.css index 8dee72f3c8ac..99ba01cb7753 100644 --- a/packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css +++ b/packages/docusaurus-plugin-debug/src/theme/DebugConfig/styles.module.css @@ -5,13 +5,3 @@ * LICENSE file in the root directory of this source tree. */ -.Container { - display: flex; - flex-wrap: wrap; - justify-content: center; - margin: 1em; -} - -.Section { - width: 500px; -} diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js new file mode 100644 index 000000000000..e61581f3ebcf --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js @@ -0,0 +1,16 @@ +/** + * 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. + */ + +import React from 'react'; + +import DebugLayout from '../DebugLayout'; + +function DebugContent({allContent}) { + return {JSON.stringify(allContent, null, 2)}; +} + +export default DebugContent; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugContent/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugContent/styles.module.css new file mode 100644 index 000000000000..99ba01cb7753 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugContent/styles.module.css @@ -0,0 +1,7 @@ +/** + * 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. + */ + diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js new file mode 100644 index 000000000000..02c2eb7f869b --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js @@ -0,0 +1,39 @@ +/** + * 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. + */ + +import React from 'react'; +import Link from '@docusaurus/Link'; +// import styles from './styles.module.css'; + +const DebugNavLink = ({to, children}) => ( + + {children} + +); + +function DebugLayout({children}) { + return ( +
+ +
{children}
+
+ ); +} + +export default DebugLayout; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugLayout/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/styles.module.css new file mode 100644 index 000000000000..b5c0e33b4a5b --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugLayout/styles.module.css @@ -0,0 +1,6 @@ +/** + * 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. + */ diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/index.js new file mode 100644 index 000000000000..9cb98a2e1e73 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/index.js @@ -0,0 +1,40 @@ +/** + * 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. + */ + +import React from 'react'; + +import DebugLayout from '../DebugLayout'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; + +function DebugMetadata() { + const {siteMetadata} = useDocusaurusContext(); + return ( + +

Site Metadata

+
Docusaurus Version: {siteMetadata.docusaurusVersion}
+
+ Site Version: {siteMetadata.siteVersion || 'No version specified'} +
+

Plugins and themes:

+
    + {Object.entries(siteMetadata.pluginVersions).map( + ([name, versionInformation]) => ( +
  • +
    Name: {name}
    +
    Type: {versionInformation.type}
    + {versionInformation.version && ( +
    Version: {versionInformation.version}
    + )} +
  • + ), + )} +
+
+ ); +} + +export default DebugMetadata; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/styles.module.css new file mode 100644 index 000000000000..99ba01cb7753 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugMetadata/styles.module.css @@ -0,0 +1,7 @@ +/** + * 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. + */ + diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js new file mode 100644 index 000000000000..f10a53a8a6f2 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/index.js @@ -0,0 +1,30 @@ +/** + * 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. + */ + +import React from 'react'; + +import DebugLayout from '../DebugLayout'; +import registry from '@generated/registry'; + +function DebugRegistry() { + return ( + + {' '} +

Registry

+
    + {Object.values(registry).map(([, aliasedPath, resolved]) => ( +
  • +
    Aliased Path: {aliasedPath}
    +
    Resolved Path: {resolved}
    +
  • + ))} +
+
+ ); +} + +export default DebugRegistry; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/styles.module.css new file mode 100644 index 000000000000..99ba01cb7753 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRegistry/styles.module.css @@ -0,0 +1,7 @@ +/** + * 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. + */ + diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js new file mode 100644 index 000000000000..5eedd036f41a --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js @@ -0,0 +1,29 @@ +/** + * 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. + */ + +import React from 'react'; + +import DebugLayout from '../DebugLayout'; +import routes from '@generated/routes'; + +function DebugRoutes() { + return ( + +

Routes

+
    + {routes.map(({path, exact}) => ( +
  • +
    Route: {path}
    +
    Is exact: {String(Boolean(exact))}
    +
  • + ))} +
+
+ ); +} + +export default DebugRoutes; diff --git a/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/styles.module.css new file mode 100644 index 000000000000..99ba01cb7753 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/DebugRoutes/styles.module.css @@ -0,0 +1,7 @@ +/** + * 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. + */ + diff --git a/packages/docusaurus-preset-classic/src/index.js b/packages/docusaurus-preset-classic/src/index.js index 894fe315c251..47f65208f1d3 100644 --- a/packages/docusaurus-preset-classic/src/index.js +++ b/packages/docusaurus-preset-classic/src/index.js @@ -11,6 +11,9 @@ module.exports = function preset(context, opts = {}) { const {algolia, googleAnalytics, gtag} = themeConfig; const isProd = process.env.NODE_ENV === 'production'; + const debug = + typeof opts.debug !== 'undefined' ? Boolean(opts.debug) : !isProd; + return { themes: [ [require.resolve('@docusaurus/theme-classic'), opts.theme], @@ -24,7 +27,7 @@ module.exports = function preset(context, opts = {}) { isProd && googleAnalytics && require.resolve('@docusaurus/plugin-google-analytics'), - !isProd && require.resolve('@docusaurus/plugin-debug'), + debug && require.resolve('@docusaurus/plugin-debug'), isProd && gtag && require.resolve('@docusaurus/plugin-google-gtag'), isProd && [require.resolve('@docusaurus/plugin-sitemap'), opts.sitemap], ], diff --git a/packages/docusaurus-theme-bootstrap/src/theme/Layout/index.js b/packages/docusaurus-theme-bootstrap/src/theme/DebugLayout/index.js similarity index 100% rename from packages/docusaurus-theme-bootstrap/src/theme/Layout/index.js rename to packages/docusaurus-theme-bootstrap/src/theme/DebugLayout/index.js diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 14ee8dd2b987..d2b0bf4c6192 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -126,8 +126,15 @@ export interface PluginContentLoadedActions { setGlobalData(data: T): void; } +export type AllContent = Record< + string, // plugin name + Record< + string, // plugin id + unknown // plugin data + > +>; + export interface Plugin { - id?: string; name: string; loadContent?(): Promise; validateOptions?(): ValidationResult; @@ -136,7 +143,8 @@ export interface Plugin { content, actions, }: { - content: T; + content: T; // the content loaded by this plugin instance + allContent: AllContent; // content loaded by ALL the plugins actions: PluginContentLoadedActions; }): void; routesLoaded?(routes: RouteConfig[]): void; // TODO remove soon, deprecated (alpha-60) diff --git a/packages/docusaurus/src/server/plugins/index.ts b/packages/docusaurus/src/server/plugins/index.ts index 619afeed6ad5..8d3306e3a194 100644 --- a/packages/docusaurus/src/server/plugins/index.ts +++ b/packages/docusaurus/src/server/plugins/index.ts @@ -9,6 +9,7 @@ import {generate} from '@docusaurus/utils'; import fs from 'fs-extra'; import path from 'path'; import { + AllContent, LoadContext, PluginConfig, PluginContentLoadedActions, @@ -17,6 +18,7 @@ import { import initPlugins, {InitPlugin} from './init'; import chalk from 'chalk'; import {DEFAULT_PLUGIN_ID} from '../../constants'; +import {chain} from 'lodash'; export function sortConfig(routeConfigs: RouteConfig[]): void { // Sort the route config. This ensures that route with nested @@ -68,23 +70,31 @@ export async function loadPlugins({ // Currently plugins run lifecycle methods in parallel and are not order-dependent. // We could change this in future if there are plugins which need to // run in certain order or depend on others for data. - const pluginsLoadedContent = await Promise.all( + type ContentLoadedPlugin = {plugin: InitPlugin; content: unknown}; + const contentLoadedPlugins: ContentLoadedPlugin[] = await Promise.all( plugins.map(async (plugin) => { - if (!plugin.loadContent) { - return null; - } - - return plugin.loadContent(); + const content = plugin.loadContent ? await plugin.loadContent() : null; + return {plugin, content}; }), ); + const allContent: AllContent = chain(contentLoadedPlugins) + .groupBy((item) => item.plugin.name) + .mapValues((nameItems) => { + return chain(nameItems) + .groupBy((item) => item.plugin.options.id ?? DEFAULT_PLUGIN_ID) + .mapValues((idItems) => idItems[0].content) + .value(); + }) + .value(); + // 3. Plugin Lifecycle - contentLoaded. const pluginsRouteConfigs: RouteConfig[] = []; const globalData = {}; await Promise.all( - plugins.map(async (plugin, index) => { + contentLoadedPlugins.map(async ({plugin, content}) => { if (!plugin.contentLoaded) { return; } @@ -100,11 +110,11 @@ export async function loadPlugins({ const createData: PluginContentLoadedActions['createData'] = async ( name, - content, + data, ) => { const modulePath = path.join(dataDir, name); await fs.ensureDir(path.dirname(modulePath)); - await generate(dataDir, name, content); + await generate(dataDir, name, data); return modulePath; }; @@ -125,8 +135,9 @@ export async function loadPlugins({ }; await plugin.contentLoaded({ - content: pluginsLoadedContent[index], + content, actions, + allContent, }); }), ); diff --git a/packages/docusaurus/src/server/plugins/init.ts b/packages/docusaurus/src/server/plugins/init.ts index 09f0e08ef5ef..d7e9de0e4205 100644 --- a/packages/docusaurus/src/server/plugins/init.ts +++ b/packages/docusaurus/src/server/plugins/init.ts @@ -15,7 +15,7 @@ import { PluginConfig, DocusaurusPluginVersionInformation, } from '@docusaurus/types'; -import {CONFIG_FILE_NAME} from '../../constants'; +import {CONFIG_FILE_NAME, DEFAULT_PLUGIN_ID} from '../../constants'; import {getPluginVersion} from '../versions'; import {ensureUniquePluginInstanceIds} from './pluginIds'; import { @@ -79,6 +79,13 @@ export default function initPlugins({ options: pluginOptions, }); pluginOptions = normalizedOptions; + } else { + // Important to ensure all plugins have an id + // as we don't go through the Joi schema that adds it + pluginOptions = { + ...pluginOptions, + id: pluginOptions.id ?? DEFAULT_PLUGIN_ID, + }; } // support both commonjs and ES modules diff --git a/tsconfig.json b/tsconfig.json index e0b11fc6d794..179d7409ff6c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,10 +17,12 @@ /* Additional Checks */ "noUnusedLocals": true, - "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + /* Disabled on purpose (handled by ESLint, should not block compilation) */ + "noUnusedParameters": false, + /* Module Resolution Options */ "moduleResolution": "node", "allowSyntheticDefaultImports": true, diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 191b1cec4364..16f2fa31004c 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -156,6 +156,7 @@ module.exports = { [ '@docusaurus/preset-classic', { + debug: true, // force debug plugin usage docs: { // routeBasePath: '/', path: 'docs',