@docusaurus/core 2.0.0-beta.2 → 2.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/docusaurus.mjs +221 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +40 -40
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -13
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +108 -146
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +104 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +109 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +101 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +118 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -134
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +45 -57
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +22 -9
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/docusaurus.js +0 -325
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -40
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadPluginConfigs = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
|
+
const presets_1 = require("./presets");
|
|
14
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
15
|
+
async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
|
|
16
|
+
// plugins: ["./plugin"]
|
|
17
|
+
if (typeof pluginConfig === 'string') {
|
|
18
|
+
const pluginModuleImport = pluginConfig;
|
|
19
|
+
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
20
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
21
|
+
return {
|
|
22
|
+
plugin: pluginModule.default ?? pluginModule,
|
|
23
|
+
options: {},
|
|
24
|
+
pluginModule: {
|
|
25
|
+
path: pluginModuleImport,
|
|
26
|
+
module: pluginModule,
|
|
27
|
+
},
|
|
28
|
+
entryPath: pluginPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// plugins: [() => {...}]
|
|
32
|
+
if (typeof pluginConfig === 'function') {
|
|
33
|
+
return {
|
|
34
|
+
plugin: pluginConfig,
|
|
35
|
+
options: {},
|
|
36
|
+
entryPath: configPath,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// plugins: [
|
|
40
|
+
// ["./plugin",options],
|
|
41
|
+
// ]
|
|
42
|
+
if (typeof pluginConfig[0] === 'string') {
|
|
43
|
+
const pluginModuleImport = pluginConfig[0];
|
|
44
|
+
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
45
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
46
|
+
return {
|
|
47
|
+
plugin: pluginModule.default ?? pluginModule,
|
|
48
|
+
options: pluginConfig[1],
|
|
49
|
+
pluginModule: {
|
|
50
|
+
path: pluginModuleImport,
|
|
51
|
+
module: pluginModule,
|
|
52
|
+
},
|
|
53
|
+
entryPath: pluginPath,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// plugins: [
|
|
57
|
+
// [() => {...}, options],
|
|
58
|
+
// ]
|
|
59
|
+
return {
|
|
60
|
+
plugin: pluginConfig[0],
|
|
61
|
+
options: pluginConfig[1],
|
|
62
|
+
entryPath: configPath,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
|
|
67
|
+
* normalizes the return value. Plugin configs are ordered, mostly for theme
|
|
68
|
+
* alias shadowing. Site themes have the highest priority, and preset plugins
|
|
69
|
+
* are the lowest.
|
|
70
|
+
*/
|
|
71
|
+
async function loadPluginConfigs(context) {
|
|
72
|
+
const preset = await (0, presets_1.loadPresets)(context);
|
|
73
|
+
const { siteConfig, siteConfigPath } = context;
|
|
74
|
+
const pluginRequire = (0, module_1.createRequire)(siteConfigPath);
|
|
75
|
+
function normalizeShorthand(pluginConfig, pluginType) {
|
|
76
|
+
if (typeof pluginConfig === 'string') {
|
|
77
|
+
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, pluginRequire, pluginType);
|
|
78
|
+
}
|
|
79
|
+
else if (Array.isArray(pluginConfig) &&
|
|
80
|
+
typeof pluginConfig[0] === 'string') {
|
|
81
|
+
return [
|
|
82
|
+
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], pluginRequire, pluginType),
|
|
83
|
+
pluginConfig[1] ?? {},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
return pluginConfig;
|
|
87
|
+
}
|
|
88
|
+
preset.plugins = preset.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
89
|
+
preset.themes = preset.themes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
90
|
+
const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
91
|
+
const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
92
|
+
const pluginConfigs = [
|
|
93
|
+
...preset.plugins,
|
|
94
|
+
...preset.themes,
|
|
95
|
+
// Site config should be the highest priority.
|
|
96
|
+
...standalonePlugins,
|
|
97
|
+
...standaloneThemes,
|
|
98
|
+
].filter((x) => Boolean(x));
|
|
99
|
+
return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, context.siteConfigPath, pluginRequire)));
|
|
100
|
+
}
|
|
101
|
+
exports.loadPluginConfigs = loadPluginConfigs;
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { LoadContext,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import type { LoadContext, RouteConfig, GlobalData, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
10
|
+
* `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
|
|
11
|
+
* side-effect-ful (it generates temp files), so is this function. This function
|
|
12
|
+
* would also mutate `context.siteConfig.themeConfig` to translate it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadPlugins(context: LoadContext): Promise<{
|
|
13
15
|
plugins: LoadedPlugin[];
|
|
14
16
|
pluginsRouteConfigs: RouteConfig[];
|
|
15
|
-
globalData:
|
|
16
|
-
themeConfigTranslated: ThemeConfig;
|
|
17
|
+
globalData: GlobalData;
|
|
17
18
|
}>;
|
|
@@ -6,162 +6,101 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.loadPlugins =
|
|
9
|
+
exports.loadPlugins = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const init_1 = require("./init");
|
|
15
|
+
const synthetic_1 = require("./synthetic");
|
|
18
16
|
const translations_1 = require("../translations/translations");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!a.routes && b.routes) {
|
|
28
|
-
return -1;
|
|
29
|
-
}
|
|
30
|
-
// Higher priority get placed first.
|
|
31
|
-
if (a.priority || b.priority) {
|
|
32
|
-
const priorityA = a.priority || 0;
|
|
33
|
-
const priorityB = b.priority || 0;
|
|
34
|
-
const score = priorityB - priorityA;
|
|
35
|
-
if (score !== 0) {
|
|
36
|
-
return score;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return a.path.localeCompare(b.path);
|
|
40
|
-
});
|
|
41
|
-
routeConfigs.forEach((routeConfig) => {
|
|
42
|
-
var _a;
|
|
43
|
-
(_a = routeConfig.routes) === null || _a === void 0 ? void 0 : _a.sort((a, b) => a.path.localeCompare(b.path));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
exports.sortConfig = sortConfig;
|
|
47
|
-
async function loadPlugins({ pluginConfigs, context, }) {
|
|
17
|
+
const routeConfig_1 = require("./routeConfig");
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
20
|
+
* `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
|
|
21
|
+
* side-effect-ful (it generates temp files), so is this function. This function
|
|
22
|
+
* would also mutate `context.siteConfig.themeConfig` to translate it.
|
|
23
|
+
*/
|
|
24
|
+
async function loadPlugins(context) {
|
|
48
25
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
|
49
|
-
const plugins = init_1.
|
|
50
|
-
|
|
51
|
-
context,
|
|
52
|
-
});
|
|
26
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
27
|
+
plugins.push((0, synthetic_1.createBootstrapPlugin)(context), (0, synthetic_1.createMDXFallbackPlugin)(context));
|
|
53
28
|
// 2. Plugin Lifecycle - loadContent.
|
|
54
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
55
|
-
// We could change this in future if there are plugins which
|
|
56
|
-
// run in certain order or depend on others for data.
|
|
29
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
30
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
31
|
+
// need to run in certain order or depend on others for data.
|
|
32
|
+
// This would also translate theme config and content upfront, given the
|
|
33
|
+
// translation files that the plugin declares.
|
|
57
34
|
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
58
|
-
const content =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var _a, _b;
|
|
63
|
-
const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
|
|
64
|
-
content: contentLoadedPlugin.content,
|
|
65
|
-
})))) !== null && _b !== void 0 ? _b : [];
|
|
66
|
-
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
|
|
67
|
-
locale: context.i18n.currentLocale,
|
|
68
|
-
siteDir: context.siteDir,
|
|
35
|
+
const content = await plugin.loadContent?.();
|
|
36
|
+
const rawTranslationFiles = (await plugin.getTranslationFiles?.({ content })) ?? [];
|
|
37
|
+
const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
38
|
+
localizationDir: context.localizationDir,
|
|
69
39
|
translationFile,
|
|
70
|
-
plugin
|
|
40
|
+
plugin,
|
|
71
41
|
})));
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
42
|
+
const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
|
|
43
|
+
const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
|
|
44
|
+
themeConfig: context.siteConfig.themeConfig,
|
|
45
|
+
translationFiles,
|
|
46
|
+
});
|
|
47
|
+
// Side-effect to merge theme config translations. A plugin should only
|
|
48
|
+
// translate its own slice of theme config and should make no assumptions
|
|
49
|
+
// about other plugins' keys, so this is safe to run in parallel.
|
|
50
|
+
Object.assign(context.siteConfig.themeConfig, translatedThemeConfigSlice);
|
|
51
|
+
return { ...plugin, content: translatedContent };
|
|
76
52
|
}));
|
|
77
|
-
const allContent = lodash_1.chain(loadedPlugins)
|
|
53
|
+
const allContent = lodash_1.default.chain(loadedPlugins)
|
|
78
54
|
.groupBy((item) => item.name)
|
|
79
|
-
.mapValues((nameItems) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.value();
|
|
84
|
-
})
|
|
55
|
+
.mapValues((nameItems) => lodash_1.default.chain(nameItems)
|
|
56
|
+
.groupBy((item) => item.options.id)
|
|
57
|
+
.mapValues((idItems) => idItems[0].content)
|
|
58
|
+
.value())
|
|
85
59
|
.value();
|
|
86
60
|
// 3. Plugin Lifecycle - contentLoaded.
|
|
87
61
|
const pluginsRouteConfigs = [];
|
|
88
62
|
const globalData = {};
|
|
89
|
-
await Promise.all(
|
|
90
|
-
var _a, _b, _c;
|
|
63
|
+
await Promise.all(loadedPlugins.map(async ({ content, ...plugin }) => {
|
|
91
64
|
if (!plugin.contentLoaded) {
|
|
92
65
|
return;
|
|
93
66
|
}
|
|
94
|
-
const pluginId =
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
pluginsRouteConfigs.push(finalRouteConfig);
|
|
102
|
-
};
|
|
103
|
-
const createData = async (name, data) => {
|
|
104
|
-
const modulePath = path_1.default.join(dataDir, name);
|
|
105
|
-
await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
|
|
106
|
-
await utils_1.generate(dataDir, name, data);
|
|
107
|
-
return modulePath;
|
|
108
|
-
};
|
|
109
|
-
// the plugins global data are namespaced to avoid data conflicts:
|
|
110
|
-
// - by plugin name
|
|
111
|
-
// - by plugin id (allow using multiple instances of the same plugin)
|
|
112
|
-
const setGlobalData = (data) => {
|
|
113
|
-
var _a;
|
|
114
|
-
globalData[plugin.name] = (_a = globalData[plugin.name]) !== null && _a !== void 0 ? _a : {};
|
|
115
|
-
globalData[plugin.name][pluginId] = data;
|
|
67
|
+
const pluginId = plugin.options.id;
|
|
68
|
+
// Plugins data files are namespaced by pluginName/pluginId
|
|
69
|
+
const dataDir = path_1.default.join(context.generatedFilesDir, plugin.name, pluginId);
|
|
70
|
+
const pluginRouteContextModulePath = path_1.default.join(dataDir, `${(0, utils_1.docuHash)('pluginRouteContextModule')}.json`);
|
|
71
|
+
const pluginRouteContext = {
|
|
72
|
+
name: plugin.name,
|
|
73
|
+
id: pluginId,
|
|
116
74
|
};
|
|
75
|
+
await (0, utils_1.generate)('/', pluginRouteContextModulePath, JSON.stringify(pluginRouteContext, null, 2));
|
|
117
76
|
const actions = {
|
|
118
|
-
addRoute
|
|
119
|
-
|
|
120
|
-
|
|
77
|
+
addRoute(initialRouteConfig) {
|
|
78
|
+
// Trailing slash behavior is handled generically for all plugins
|
|
79
|
+
const finalRouteConfig = (0, routeConfig_1.applyRouteTrailingSlash)(initialRouteConfig, context.siteConfig);
|
|
80
|
+
pluginsRouteConfigs.push({
|
|
81
|
+
...finalRouteConfig,
|
|
82
|
+
context: {
|
|
83
|
+
...(finalRouteConfig.context && { data: finalRouteConfig.context }),
|
|
84
|
+
plugin: pluginRouteContextModulePath,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
async createData(name, data) {
|
|
89
|
+
const modulePath = path_1.default.join(dataDir, name);
|
|
90
|
+
await (0, utils_1.generate)(dataDir, name, data);
|
|
91
|
+
return modulePath;
|
|
92
|
+
},
|
|
93
|
+
setGlobalData(data) {
|
|
94
|
+
var _a;
|
|
95
|
+
globalData[_a = plugin.name] ?? (globalData[_a] = {});
|
|
96
|
+
globalData[plugin.name][pluginId] = data;
|
|
97
|
+
},
|
|
121
98
|
};
|
|
122
|
-
|
|
123
|
-
await plugin.contentLoaded({
|
|
124
|
-
content: translatedContent,
|
|
125
|
-
actions,
|
|
126
|
-
allContent,
|
|
127
|
-
});
|
|
128
|
-
}));
|
|
129
|
-
// 4. Plugin Lifecycle - routesLoaded.
|
|
130
|
-
// Currently plugins run lifecycle methods in parallel and are not order-dependent.
|
|
131
|
-
// We could change this in future if there are plugins which need to
|
|
132
|
-
// run in certain order or depend on others for data.
|
|
133
|
-
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
134
|
-
if (!plugin.routesLoaded) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
// TODO remove this deprecated lifecycle soon
|
|
138
|
-
// deprecated since alpha-60
|
|
139
|
-
// TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918
|
|
140
|
-
console.error(chalk_1.default.red('Plugin routesLoaded lifecycle is deprecated. If you think we should keep this lifecycle, please report here: https://github.com/facebook/docusaurus/issues/3918'));
|
|
141
|
-
return plugin.routesLoaded(pluginsRouteConfigs);
|
|
99
|
+
await plugin.contentLoaded({ content, actions, allContent });
|
|
142
100
|
}));
|
|
143
101
|
// Sort the route config. This ensures that route with nested
|
|
144
102
|
// routes are always placed last.
|
|
145
|
-
sortConfig(pluginsRouteConfigs);
|
|
146
|
-
|
|
147
|
-
function translateThemeConfig(untranslatedThemeConfig) {
|
|
148
|
-
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
149
|
-
var _a;
|
|
150
|
-
const translatedThemeConfigSlice = (_a = plugin.translateThemeConfig) === null || _a === void 0 ? void 0 : _a.call(plugin, {
|
|
151
|
-
themeConfig: currentThemeConfig,
|
|
152
|
-
translationFiles: plugin.translationFiles,
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
...currentThemeConfig,
|
|
156
|
-
...translatedThemeConfigSlice,
|
|
157
|
-
};
|
|
158
|
-
}, untranslatedThemeConfig);
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
plugins: loadedPlugins,
|
|
162
|
-
pluginsRouteConfigs,
|
|
163
|
-
globalData,
|
|
164
|
-
themeConfigTranslated: translateThemeConfig(context.siteConfig.themeConfig),
|
|
165
|
-
};
|
|
103
|
+
(0, routeConfig_1.sortConfig)(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
|
104
|
+
return { plugins: loadedPlugins, pluginsRouteConfigs, globalData };
|
|
166
105
|
}
|
|
167
106
|
exports.loadPlugins = loadPlugins;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { LoadContext,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import type { LoadContext, InitializedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Runs the plugin constructors and returns their return values. It would load
|
|
10
|
+
* plugin configs from `plugins`, `themes`, and `presets`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function initPlugins(context: LoadContext): Promise<InitializedPlugin[]>;
|
|
@@ -6,102 +6,46 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.initPlugins = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const versions_1 = require("../versions");
|
|
14
|
-
const pluginIds_1 = require("./pluginIds");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
14
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof pluginConfig === 'string') {
|
|
20
|
-
const pluginModuleImport = pluginConfig;
|
|
21
|
-
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
22
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
23
|
-
return {
|
|
24
|
-
plugin: (_a = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _a !== void 0 ? _a : pluginModule,
|
|
25
|
-
options: {},
|
|
26
|
-
pluginModule: {
|
|
27
|
-
path: pluginModuleImport,
|
|
28
|
-
module: pluginModule,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// plugins: [function plugin() { }]
|
|
33
|
-
if (typeof pluginConfig === 'function') {
|
|
34
|
-
return {
|
|
35
|
-
plugin: pluginConfig,
|
|
36
|
-
options: {},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(pluginConfig)) {
|
|
40
|
-
// plugins: [
|
|
41
|
-
// ['./plugin',options],
|
|
42
|
-
// ]
|
|
43
|
-
if (typeof pluginConfig[0] === 'string') {
|
|
44
|
-
const pluginModuleImport = pluginConfig[0];
|
|
45
|
-
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
46
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
47
|
-
return {
|
|
48
|
-
plugin: (_b = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _b !== void 0 ? _b : pluginModule,
|
|
49
|
-
options: (_c = pluginConfig[1]) !== null && _c !== void 0 ? _c : {},
|
|
50
|
-
pluginModule: {
|
|
51
|
-
path: pluginModuleImport,
|
|
52
|
-
module: pluginModule,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
// plugins: [
|
|
57
|
-
// [function plugin() { },options],
|
|
58
|
-
// ]
|
|
59
|
-
if (typeof pluginConfig[0] === 'function') {
|
|
60
|
-
return {
|
|
61
|
-
plugin: pluginConfig[0],
|
|
62
|
-
options: (_d = pluginConfig[1]) !== null && _d !== void 0 ? _d : {},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
throw new Error(`Unexpected: can't load plugin for following plugin config.\n${JSON.stringify(pluginConfig)}`);
|
|
67
|
-
}
|
|
15
|
+
const siteMetadata_1 = require("../siteMetadata");
|
|
16
|
+
const pluginIds_1 = require("./pluginIds");
|
|
17
|
+
const configs_1 = require("./configs");
|
|
68
18
|
function getOptionValidationFunction(normalizedPluginConfig) {
|
|
69
|
-
var _a, _b, _c, _d;
|
|
70
19
|
if (normalizedPluginConfig.pluginModule) {
|
|
71
|
-
//
|
|
72
|
-
return (
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
return normalizedPluginConfig.plugin.validateOptions;
|
|
20
|
+
// Support both CommonJS and ES modules
|
|
21
|
+
return (normalizedPluginConfig.pluginModule.module.default?.validateOptions ??
|
|
22
|
+
normalizedPluginConfig.pluginModule.module.validateOptions);
|
|
76
23
|
}
|
|
24
|
+
return normalizedPluginConfig.plugin.validateOptions;
|
|
77
25
|
}
|
|
78
26
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
79
|
-
var _a, _b;
|
|
80
27
|
if (normalizedPluginConfig.pluginModule) {
|
|
81
|
-
//
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
else {
|
|
85
|
-
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
28
|
+
// Support both CommonJS and ES modules
|
|
29
|
+
return (normalizedPluginConfig.pluginModule.module.default?.validateThemeConfig ??
|
|
30
|
+
normalizedPluginConfig.pluginModule.module.validateThemeConfig);
|
|
86
31
|
}
|
|
32
|
+
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
87
33
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
const pluginPath = pluginRequire.resolve(
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return { type: 'local' };
|
|
34
|
+
/**
|
|
35
|
+
* Runs the plugin constructors and returns their return values. It would load
|
|
36
|
+
* plugin configs from `plugins`, `themes`, and `presets`.
|
|
37
|
+
*/
|
|
38
|
+
async function initPlugins(context) {
|
|
39
|
+
// We need to resolve plugins from the perspective of the site config, as if
|
|
40
|
+
// we are using `require.resolve` on those module names.
|
|
41
|
+
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
42
|
+
const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
|
|
43
|
+
async function doGetPluginVersion(normalizedPluginConfig) {
|
|
44
|
+
if (normalizedPluginConfig.pluginModule?.path) {
|
|
45
|
+
const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule.path);
|
|
46
|
+
return (0, siteMetadata_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
104
47
|
}
|
|
48
|
+
return { type: 'local' };
|
|
105
49
|
}
|
|
106
50
|
function doValidateThemeConfig(normalizedPluginConfig) {
|
|
107
51
|
const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
|
|
@@ -111,12 +55,9 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
111
55
|
themeConfig: context.siteConfig.themeConfig,
|
|
112
56
|
});
|
|
113
57
|
}
|
|
114
|
-
|
|
115
|
-
return context.siteConfig.themeConfig;
|
|
116
|
-
}
|
|
58
|
+
return context.siteConfig.themeConfig;
|
|
117
59
|
}
|
|
118
60
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
119
|
-
var _a;
|
|
120
61
|
const validateOptions = getOptionValidationFunction(normalizedPluginConfig);
|
|
121
62
|
if (validateOptions) {
|
|
122
63
|
return validateOptions({
|
|
@@ -124,37 +65,31 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
124
65
|
options: normalizedPluginConfig.options,
|
|
125
66
|
});
|
|
126
67
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
}
|
|
68
|
+
// Important to ensure all plugins have an id
|
|
69
|
+
// as we don't go through the Joi schema that adds it
|
|
70
|
+
return {
|
|
71
|
+
...normalizedPluginConfig.options,
|
|
72
|
+
id: normalizedPluginConfig.options.id ?? utils_1.DEFAULT_PLUGIN_ID,
|
|
73
|
+
};
|
|
135
74
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!pluginConfig) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
|
|
142
|
-
const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
|
|
75
|
+
async function initializePlugin(normalizedPluginConfig) {
|
|
76
|
+
const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
|
|
143
77
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
144
78
|
// Side-effect: merge the normalized theme config in the original one
|
|
145
79
|
context.siteConfig.themeConfig = {
|
|
146
80
|
...context.siteConfig.themeConfig,
|
|
147
81
|
...doValidateThemeConfig(normalizedPluginConfig),
|
|
148
82
|
};
|
|
149
|
-
const pluginInstance = normalizedPluginConfig.plugin(context, pluginOptions);
|
|
83
|
+
const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
|
|
150
84
|
return {
|
|
151
85
|
...pluginInstance,
|
|
152
86
|
options: pluginOptions,
|
|
153
87
|
version: pluginVersion,
|
|
88
|
+
path: path_1.default.dirname(normalizedPluginConfig.entryPath),
|
|
154
89
|
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
pluginIds_1.ensureUniquePluginInstanceIds(plugins);
|
|
90
|
+
}
|
|
91
|
+
const plugins = await Promise.all(pluginConfigs.map(initializePlugin));
|
|
92
|
+
(0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
|
|
158
93
|
return plugins;
|
|
159
94
|
}
|
|
160
|
-
exports.
|
|
95
|
+
exports.initPlugins = initPlugins;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
export declare function getNamePatterns(moduleName: string, moduleType: 'preset' | 'theme' | 'plugin'): string[];
|
|
9
|
+
export declare function resolveModuleName(moduleName: string, moduleRequire: NodeRequire, moduleType: 'preset' | 'theme' | 'plugin'): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.resolveModuleName = exports.getNamePatterns = void 0;
|
|
10
|
+
function getNamePatterns(moduleName, moduleType) {
|
|
11
|
+
if (moduleName.startsWith('@')) {
|
|
12
|
+
// Pure scope: `@scope` => `@scope/docusaurus-plugin`
|
|
13
|
+
if (!moduleName.includes('/')) {
|
|
14
|
+
return [`${moduleName}/docusaurus-${moduleType}`];
|
|
15
|
+
}
|
|
16
|
+
const [scope, packageName] = moduleName.split(/\/(?<rest>.*)/);
|
|
17
|
+
return [
|
|
18
|
+
`${scope}/${packageName}`,
|
|
19
|
+
`${scope}/docusaurus-${moduleType}-${packageName}`,
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
moduleName,
|
|
24
|
+
`@docusaurus/${moduleType}-${moduleName}`,
|
|
25
|
+
`docusaurus-${moduleType}-${moduleName}`,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.getNamePatterns = getNamePatterns;
|
|
29
|
+
function resolveModuleName(moduleName, moduleRequire, moduleType) {
|
|
30
|
+
const modulePatterns = getNamePatterns(moduleName, moduleType);
|
|
31
|
+
const module = modulePatterns.find((m) => {
|
|
32
|
+
try {
|
|
33
|
+
moduleRequire.resolve(m);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (!module) {
|
|
41
|
+
throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
|
|
42
|
+
${modulePatterns.map((m) => `- ${m}`).join('\n')}`);
|
|
43
|
+
}
|
|
44
|
+
return module;
|
|
45
|
+
}
|
|
46
|
+
exports.resolveModuleName = resolveModuleName;
|
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { InitializedPlugin } from '@docusaurus/types';
|
|
7
|
+
import type { InitializedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* It is forbidden to have 2 plugins of the same name sharing the same ID.
|
|
10
|
+
* This is required to support multi-instance plugins without conflict.
|
|
11
|
+
*/
|
|
8
12
|
export declare function ensureUniquePluginInstanceIds(plugins: InitializedPlugin[]): void;
|