@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18
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/bin/beforeCli.mjs +133 -0
- package/bin/docusaurus.mjs +279 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +31 -43
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +23 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +7 -11
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/browserContext.d.ts +11 -0
- package/lib/client/browserContext.js +22 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +13 -7
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +40 -19
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -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 -26
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +31 -20
- 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 +8 -5
- 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 +4 -8
- 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/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +4 -2
- package/lib/client/flat.js +9 -13
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +2 -7
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +4 -6
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +5 -10
- 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 +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +43 -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 +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +17 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +1 -1
- package/lib/commands/deploy.js +83 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +4 -8
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +25 -12
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +96 -87
- 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 +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +28 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -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 +19 -76
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +37 -17
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +64 -52
- package/lib/server/client-modules/index.d.ts +2 -2
- package/lib/server/client-modules/index.js +4 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +8 -5
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +93 -37
- package/lib/server/duplicateRoutes.d.ts +1 -3
- package/lib/server/duplicateRoutes.js +17 -13
- package/lib/server/html-tags/htmlTags.js +7 -8
- package/lib/server/html-tags/index.d.ts +2 -3
- package/lib/server/html-tags/index.js +3 -4
- package/lib/server/i18n.d.ts +2 -3
- package/lib/server/i18n.js +27 -48
- package/lib/server/index.d.ts +9 -2
- package/lib/server/index.js +175 -96
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
- package/lib/server/plugins/index.d.ts +4 -5
- package/lib/server/plugins/index.js +69 -45
- package/lib/server/plugins/init.d.ts +15 -5
- package/lib/server/plugins/init.js +68 -81
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +16 -23
- package/lib/server/routes.d.ts +3 -5
- package/lib/server/routes.js +68 -36
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -13
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +36 -24
- package/lib/server/translations/translations.d.ts +21 -17
- package/lib/server/translations/translations.js +33 -54
- package/lib/server/translations/translationsExtractor.d.ts +12 -5
- package/lib/server/translations/translationsExtractor.js +159 -121
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -24
- package/lib/webpack/base.d.ts +6 -4
- package/lib/webpack/base.js +51 -36
- 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 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +14 -7
- 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 +5 -4
- package/lib/webpack/utils.d.ts +15 -30
- package/lib/webpack/utils.js +57 -175
- package/package.json +77 -70
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5732
- package/lib/client/.tsbuildinfo +0 -4171
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- 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/loadSetup.js +0 -25
- 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/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.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -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;
|
|
@@ -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
|
+
import type { RouteConfig } from '@docusaurus/types';
|
|
8
|
+
import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
|
|
9
|
+
export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
10
|
+
function applyRouteTrailingSlash(route, params) {
|
|
11
|
+
return {
|
|
12
|
+
...route,
|
|
13
|
+
path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
|
|
14
|
+
...(route.routes && {
|
|
15
|
+
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.default = applyRouteTrailingSlash;
|
|
@@ -4,15 +4,14 @@
|
|
|
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, PluginConfig, RouteConfig, ThemeConfig } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
export declare function sortConfig(routeConfigs: RouteConfig[]): void;
|
|
7
|
+
import type { LoadContext, PluginConfig, RouteConfig, GlobalData, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
|
|
10
9
|
export declare function loadPlugins({ pluginConfigs, context, }: {
|
|
11
10
|
pluginConfigs: PluginConfig[];
|
|
12
11
|
context: LoadContext;
|
|
13
12
|
}): Promise<{
|
|
14
|
-
plugins:
|
|
13
|
+
plugins: LoadedPlugin[];
|
|
15
14
|
pluginsRouteConfigs: RouteConfig[];
|
|
16
|
-
globalData:
|
|
15
|
+
globalData: GlobalData;
|
|
17
16
|
themeConfigTranslated: ThemeConfig;
|
|
18
17
|
}>;
|
|
@@ -12,14 +12,21 @@ const utils_1 = require("@docusaurus/utils");
|
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const init_1 = tslib_1.__importDefault(require("./init"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const lodash_1 = require("lodash");
|
|
15
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
16
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
18
17
|
const translations_1 = require("../translations/translations");
|
|
19
|
-
|
|
18
|
+
const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
|
|
19
|
+
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
20
20
|
// Sort the route config. This ensures that route with nested
|
|
21
21
|
// routes is always placed last.
|
|
22
22
|
routeConfigs.sort((a, b) => {
|
|
23
|
+
// Root route should get placed last.
|
|
24
|
+
if (a.path === baseUrl && b.path !== baseUrl) {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
if (a.path !== baseUrl && b.path === baseUrl) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
23
30
|
if (a.routes && !b.routes) {
|
|
24
31
|
return 1;
|
|
25
32
|
}
|
|
@@ -38,71 +45,89 @@ function sortConfig(routeConfigs) {
|
|
|
38
45
|
return a.path.localeCompare(b.path);
|
|
39
46
|
});
|
|
40
47
|
routeConfigs.forEach((routeConfig) => {
|
|
41
|
-
|
|
42
|
-
(_a = routeConfig.routes) === null || _a === void 0 ? void 0 : _a.sort((a, b) => a.path.localeCompare(b.path));
|
|
48
|
+
routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
exports.sortConfig = sortConfig;
|
|
46
52
|
async function loadPlugins({ pluginConfigs, context, }) {
|
|
47
53
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
|
48
|
-
const plugins = init_1.default({
|
|
54
|
+
const plugins = await (0, init_1.default)({
|
|
49
55
|
pluginConfigs,
|
|
50
56
|
context,
|
|
51
57
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
// 2. Plugin Lifecycle - loadContent.
|
|
59
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
60
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
61
|
+
// need to run in certain order or depend on others for data.
|
|
62
|
+
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
63
|
+
const content = await plugin.loadContent?.();
|
|
64
|
+
return { ...plugin, content };
|
|
55
65
|
}));
|
|
56
|
-
const contentLoadedTranslatedPlugins = await Promise.all(
|
|
57
|
-
|
|
58
|
-
const translationFiles = (_c = (await ((_b = (_a = contentLoadedPlugin.plugin) === null || _a === void 0 ? void 0 : _a.getTranslationFiles) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
66
|
+
const contentLoadedTranslatedPlugins = await Promise.all(loadedPlugins.map(async (contentLoadedPlugin) => {
|
|
67
|
+
const translationFiles = (await contentLoadedPlugin?.getTranslationFiles?.({
|
|
59
68
|
content: contentLoadedPlugin.content,
|
|
60
|
-
}))
|
|
61
|
-
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
|
|
69
|
+
})) ?? [];
|
|
70
|
+
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
62
71
|
locale: context.i18n.currentLocale,
|
|
63
72
|
siteDir: context.siteDir,
|
|
64
73
|
translationFile,
|
|
65
|
-
plugin: contentLoadedPlugin
|
|
74
|
+
plugin: contentLoadedPlugin,
|
|
66
75
|
})));
|
|
67
76
|
return {
|
|
68
77
|
...contentLoadedPlugin,
|
|
69
78
|
translationFiles: localizedTranslationFiles,
|
|
70
79
|
};
|
|
71
80
|
}));
|
|
72
|
-
const allContent = lodash_1.chain(
|
|
73
|
-
.groupBy((item) => item.
|
|
74
|
-
.mapValues((nameItems) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.value();
|
|
79
|
-
})
|
|
81
|
+
const allContent = lodash_1.default.chain(loadedPlugins)
|
|
82
|
+
.groupBy((item) => item.name)
|
|
83
|
+
.mapValues((nameItems) => lodash_1.default.chain(nameItems)
|
|
84
|
+
.groupBy((item) => item.options.id)
|
|
85
|
+
.mapValues((idItems) => idItems[0].content)
|
|
86
|
+
.value())
|
|
80
87
|
.value();
|
|
81
88
|
// 3. Plugin Lifecycle - contentLoaded.
|
|
82
89
|
const pluginsRouteConfigs = [];
|
|
83
90
|
const globalData = {};
|
|
84
|
-
await Promise.all(contentLoadedTranslatedPlugins.map(async ({
|
|
85
|
-
var _a, _b, _c;
|
|
91
|
+
await Promise.all(contentLoadedTranslatedPlugins.map(async ({ content, translationFiles, ...plugin }) => {
|
|
86
92
|
if (!plugin.contentLoaded) {
|
|
87
93
|
return;
|
|
88
94
|
}
|
|
89
|
-
const pluginId =
|
|
95
|
+
const pluginId = plugin.options.id;
|
|
90
96
|
// plugins data files are namespaced by pluginName/pluginId
|
|
91
97
|
const dataDirRoot = path_1.default.join(context.generatedFilesDir, plugin.name);
|
|
92
98
|
const dataDir = path_1.default.join(dataDirRoot, pluginId);
|
|
93
|
-
const addRoute = (config) => pluginsRouteConfigs.push(config);
|
|
94
99
|
const createData = async (name, data) => {
|
|
95
100
|
const modulePath = path_1.default.join(dataDir, name);
|
|
96
101
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
|
|
97
|
-
await utils_1.generate(dataDir, name, data);
|
|
102
|
+
await (0, utils_1.generate)(dataDir, name, data);
|
|
98
103
|
return modulePath;
|
|
99
104
|
};
|
|
105
|
+
// TODO this would be better to do all that in the codegen phase
|
|
106
|
+
// TODO handle context for nested routes
|
|
107
|
+
const pluginRouteContext = {
|
|
108
|
+
plugin: { name: plugin.name, id: pluginId },
|
|
109
|
+
data: undefined, // TODO allow plugins to provide context data
|
|
110
|
+
};
|
|
111
|
+
const pluginRouteContextModulePath = await createData(`${(0, utils_1.docuHash)('pluginRouteContextModule')}.json`, JSON.stringify(pluginRouteContext, null, 2));
|
|
112
|
+
const addRoute = (initialRouteConfig) => {
|
|
113
|
+
// Trailing slash behavior is handled in a generic way for all plugins
|
|
114
|
+
const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
|
|
115
|
+
trailingSlash: context.siteConfig.trailingSlash,
|
|
116
|
+
baseUrl: context.siteConfig.baseUrl,
|
|
117
|
+
});
|
|
118
|
+
pluginsRouteConfigs.push({
|
|
119
|
+
...finalRouteConfig,
|
|
120
|
+
modules: {
|
|
121
|
+
...finalRouteConfig.modules,
|
|
122
|
+
__routeContextModule: pluginRouteContextModulePath,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
};
|
|
100
126
|
// the plugins global data are namespaced to avoid data conflicts:
|
|
101
127
|
// - by plugin name
|
|
102
128
|
// - by plugin id (allow using multiple instances of the same plugin)
|
|
103
129
|
const setGlobalData = (data) => {
|
|
104
|
-
|
|
105
|
-
globalData[plugin.name] = (_a = globalData[plugin.name]) !== null && _a !== void 0 ? _a : {};
|
|
130
|
+
globalData[plugin.name] = globalData[plugin.name] ?? {};
|
|
106
131
|
globalData[plugin.name][pluginId] = data;
|
|
107
132
|
};
|
|
108
133
|
const actions = {
|
|
@@ -110,7 +135,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
110
135
|
createData,
|
|
111
136
|
setGlobalData,
|
|
112
137
|
};
|
|
113
|
-
const translatedContent =
|
|
138
|
+
const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
|
|
114
139
|
await plugin.contentLoaded({
|
|
115
140
|
content: translatedContent,
|
|
116
141
|
actions,
|
|
@@ -118,29 +143,28 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
118
143
|
});
|
|
119
144
|
}));
|
|
120
145
|
// 4. Plugin Lifecycle - routesLoaded.
|
|
121
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
122
|
-
// We could change this in future if there are plugins which
|
|
123
|
-
// run in certain order or depend on others for data.
|
|
124
|
-
await Promise.all(contentLoadedTranslatedPlugins.map(async (
|
|
146
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
147
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
148
|
+
// need to run in certain order or depend on others for data.
|
|
149
|
+
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
125
150
|
if (!plugin.routesLoaded) {
|
|
126
|
-
return
|
|
151
|
+
return;
|
|
127
152
|
}
|
|
128
153
|
// TODO remove this deprecated lifecycle soon
|
|
129
154
|
// deprecated since alpha-60
|
|
130
155
|
// TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
logger_1.default.error `Plugin code=${'routesLoaded'} lifecycle is deprecated. If you think we should keep this lifecycle, please report here: path=${'https://github.com/facebook/docusaurus/issues/3918'}`;
|
|
157
|
+
await plugin.routesLoaded(pluginsRouteConfigs);
|
|
133
158
|
}));
|
|
134
159
|
// Sort the route config. This ensures that route with nested
|
|
135
160
|
// routes are always placed last.
|
|
136
|
-
sortConfig(pluginsRouteConfigs);
|
|
161
|
+
sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
|
137
162
|
// Apply each plugin one after the other to translate the theme config
|
|
138
163
|
function translateThemeConfig(untranslatedThemeConfig) {
|
|
139
|
-
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig,
|
|
140
|
-
|
|
141
|
-
const translatedThemeConfigSlice = (_a = plugin.translateThemeConfig) === null || _a === void 0 ? void 0 : _a.call(plugin, {
|
|
164
|
+
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
165
|
+
const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
|
|
142
166
|
themeConfig: currentThemeConfig,
|
|
143
|
-
translationFiles,
|
|
167
|
+
translationFiles: plugin.translationFiles,
|
|
144
168
|
});
|
|
145
169
|
return {
|
|
146
170
|
...currentThemeConfig,
|
|
@@ -149,7 +173,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
149
173
|
}, untranslatedThemeConfig);
|
|
150
174
|
}
|
|
151
175
|
return {
|
|
152
|
-
plugins,
|
|
176
|
+
plugins: loadedPlugins,
|
|
153
177
|
pluginsRouteConfigs,
|
|
154
178
|
globalData,
|
|
155
179
|
themeConfigTranslated: translateThemeConfig(context.siteConfig.themeConfig),
|
|
@@ -4,12 +4,22 @@
|
|
|
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 {
|
|
8
|
-
export declare type
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import type { ImportedPluginModule, LoadContext, PluginModule, PluginConfig, PluginOptions, InitializedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare type NormalizedPluginConfig = {
|
|
9
|
+
plugin: PluginModule;
|
|
10
|
+
options: PluginOptions;
|
|
11
|
+
pluginModule?: {
|
|
12
|
+
path: string;
|
|
13
|
+
module: ImportedPluginModule;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Different from pluginModule.path, this one is always an absolute path used
|
|
17
|
+
* to resolve relative paths returned from lifecycles
|
|
18
|
+
*/
|
|
19
|
+
entryPath: string;
|
|
11
20
|
};
|
|
21
|
+
export declare function normalizePluginConfigs(pluginConfigs: PluginConfig[], configPath: string): Promise<NormalizedPluginConfig[]>;
|
|
12
22
|
export default function initPlugins({ pluginConfigs, context, }: {
|
|
13
23
|
pluginConfigs: PluginConfig[];
|
|
14
24
|
context: LoadContext;
|
|
15
|
-
}):
|
|
25
|
+
}): Promise<InitializedPlugin[]>;
|
|
@@ -6,27 +6,30 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.normalizePluginConfigs = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
13
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
|
-
const
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
15
|
const versions_1 = require("../versions");
|
|
14
16
|
const pluginIds_1 = require("./pluginIds");
|
|
15
17
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
function normalizePluginConfig(pluginConfig,
|
|
17
|
-
|
|
18
|
+
async function normalizePluginConfig(pluginConfig, configPath) {
|
|
19
|
+
const pluginRequire = (0, module_1.createRequire)(configPath);
|
|
18
20
|
// plugins: ['./plugin']
|
|
19
21
|
if (typeof pluginConfig === 'string') {
|
|
20
22
|
const pluginModuleImport = pluginConfig;
|
|
21
23
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
22
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
24
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
23
25
|
return {
|
|
24
|
-
plugin:
|
|
26
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
25
27
|
options: {},
|
|
26
28
|
pluginModule: {
|
|
27
29
|
path: pluginModuleImport,
|
|
28
30
|
module: pluginModule,
|
|
29
31
|
},
|
|
32
|
+
entryPath: pluginPath,
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
// plugins: [function plugin() { }]
|
|
@@ -34,74 +37,67 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
34
37
|
return {
|
|
35
38
|
plugin: pluginConfig,
|
|
36
39
|
options: {},
|
|
40
|
+
entryPath: configPath,
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
}
|
|
43
|
+
// plugins: [
|
|
44
|
+
// ['./plugin',options],
|
|
45
|
+
// ]
|
|
46
|
+
if (typeof pluginConfig[0] === 'string') {
|
|
47
|
+
const pluginModuleImport = pluginConfig[0];
|
|
48
|
+
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
49
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
50
|
+
return {
|
|
51
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
52
|
+
options: pluginConfig[1],
|
|
53
|
+
pluginModule: {
|
|
54
|
+
path: pluginModuleImport,
|
|
55
|
+
module: pluginModule,
|
|
56
|
+
},
|
|
57
|
+
entryPath: pluginPath,
|
|
58
|
+
};
|
|
65
59
|
}
|
|
66
|
-
|
|
60
|
+
// plugins: [
|
|
61
|
+
// [function plugin() { },options],
|
|
62
|
+
// ]
|
|
63
|
+
return {
|
|
64
|
+
plugin: pluginConfig[0],
|
|
65
|
+
options: pluginConfig[1],
|
|
66
|
+
entryPath: configPath,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async function normalizePluginConfigs(pluginConfigs, configPath) {
|
|
70
|
+
return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, configPath)));
|
|
67
71
|
}
|
|
72
|
+
exports.normalizePluginConfigs = normalizePluginConfigs;
|
|
68
73
|
function getOptionValidationFunction(normalizedPluginConfig) {
|
|
69
|
-
var _a, _b, _c, _d;
|
|
70
74
|
if (normalizedPluginConfig.pluginModule) {
|
|
71
75
|
// support both commonjs and ES modules
|
|
72
|
-
return (
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
return normalizedPluginConfig.plugin.validateOptions;
|
|
76
|
+
return (normalizedPluginConfig.pluginModule.module?.default?.validateOptions ??
|
|
77
|
+
normalizedPluginConfig.pluginModule.module?.validateOptions);
|
|
76
78
|
}
|
|
79
|
+
return normalizedPluginConfig.plugin.validateOptions;
|
|
77
80
|
}
|
|
78
81
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
79
|
-
var _a, _b;
|
|
80
82
|
if (normalizedPluginConfig.pluginModule) {
|
|
81
83
|
// support both commonjs and ES modules
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
else {
|
|
85
|
-
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
84
|
+
return (normalizedPluginConfig.pluginModule.module.default?.validateThemeConfig ??
|
|
85
|
+
normalizedPluginConfig.pluginModule.module.validateThemeConfig);
|
|
86
86
|
}
|
|
87
|
+
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
87
88
|
}
|
|
88
|
-
function initPlugins({ pluginConfigs, context, }) {
|
|
89
|
-
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
90
|
-
// declares the dependency on these plugins.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const pluginRequire = createRequire(context.siteConfigPath);
|
|
95
|
-
function doGetPluginVersion(normalizedPluginConfig) {
|
|
96
|
-
var _a, _b;
|
|
89
|
+
async function initPlugins({ pluginConfigs, context, }) {
|
|
90
|
+
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
91
|
+
// siteDir's package.json declares the dependency on these plugins.
|
|
92
|
+
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
93
|
+
const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, context.siteConfigPath);
|
|
94
|
+
async function doGetPluginVersion(normalizedPluginConfig) {
|
|
97
95
|
// get plugin version
|
|
98
|
-
if (
|
|
99
|
-
const pluginPath = pluginRequire.resolve(
|
|
100
|
-
return versions_1.getPluginVersion(pluginPath, context.siteDir);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return { type: 'local' };
|
|
96
|
+
if (normalizedPluginConfig.pluginModule?.path) {
|
|
97
|
+
const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
|
|
98
|
+
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
104
99
|
}
|
|
100
|
+
return { type: 'local' };
|
|
105
101
|
}
|
|
106
102
|
function doValidateThemeConfig(normalizedPluginConfig) {
|
|
107
103
|
const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
|
|
@@ -111,12 +107,9 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
111
107
|
themeConfig: context.siteConfig.themeConfig,
|
|
112
108
|
});
|
|
113
109
|
}
|
|
114
|
-
|
|
115
|
-
return context.siteConfig.themeConfig;
|
|
116
|
-
}
|
|
110
|
+
return context.siteConfig.themeConfig;
|
|
117
111
|
}
|
|
118
112
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
119
|
-
var _a;
|
|
120
113
|
const validateOptions = getOptionValidationFunction(normalizedPluginConfig);
|
|
121
114
|
if (validateOptions) {
|
|
122
115
|
return validateOptions({
|
|
@@ -124,37 +117,31 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
124
117
|
options: normalizedPluginConfig.options,
|
|
125
118
|
});
|
|
126
119
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
}
|
|
120
|
+
// Important to ensure all plugins have an id
|
|
121
|
+
// as we don't go through the Joi schema that adds it
|
|
122
|
+
return {
|
|
123
|
+
...normalizedPluginConfig.options,
|
|
124
|
+
id: normalizedPluginConfig.options.id ?? utils_1.DEFAULT_PLUGIN_ID,
|
|
125
|
+
};
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!pluginConfig) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
|
|
142
|
-
const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
|
|
127
|
+
async function initializePlugin(normalizedPluginConfig) {
|
|
128
|
+
const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
|
|
143
129
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
144
130
|
// Side-effect: merge the normalized theme config in the original one
|
|
145
131
|
context.siteConfig.themeConfig = {
|
|
146
132
|
...context.siteConfig.themeConfig,
|
|
147
133
|
...doValidateThemeConfig(normalizedPluginConfig),
|
|
148
134
|
};
|
|
149
|
-
const pluginInstance = normalizedPluginConfig.plugin(context, pluginOptions);
|
|
135
|
+
const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
|
|
150
136
|
return {
|
|
151
137
|
...pluginInstance,
|
|
152
138
|
options: pluginOptions,
|
|
153
139
|
version: pluginVersion,
|
|
140
|
+
path: path_1.default.dirname(normalizedPluginConfig.entryPath),
|
|
154
141
|
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
pluginIds_1.ensureUniquePluginInstanceIds(plugins);
|
|
142
|
+
}
|
|
143
|
+
const plugins = await Promise.all(pluginConfigsNormalized.map(initializePlugin));
|
|
144
|
+
(0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
|
|
158
145
|
return plugins;
|
|
159
146
|
}
|
|
160
147
|
exports.default = initPlugins;
|
|
@@ -4,5 +4,5 @@
|
|
|
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 {
|
|
8
|
-
export declare function ensureUniquePluginInstanceIds(plugins:
|
|
7
|
+
import type { InitializedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare function ensureUniquePluginInstanceIds(plugins: InitializedPlugin[]): void;
|
|
@@ -7,17 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
// It is forbidden to have 2 plugins of the same name sharing the same id
|
|
13
14
|
// this is required to support multi-instance plugins without conflict
|
|
14
15
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName = lodash_1.groupBy(plugins, (p) => p.name);
|
|
16
|
+
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
16
17
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById = lodash_1.groupBy(pluginInstances, (p) =>
|
|
18
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => p.options.id ?? utils_1.DEFAULT_PLUGIN_ID);
|
|
18
19
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
20
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
|
-
throw new Error(`Plugin ${pluginName} is used ${pluginInstancesWithId.length} times with
|
|
21
|
+
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
22
|
+
? `\n\nThe plugin ID is "${utils_1.DEFAULT_PLUGIN_ID}" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances).`
|
|
23
|
+
: ''}`);
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
26
|
});
|
|
@@ -4,8 +4,8 @@
|
|
|
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, PluginConfig } from '@docusaurus/types';
|
|
8
|
-
export default function loadPresets(context: LoadContext): {
|
|
7
|
+
import type { LoadContext, PluginConfig } from '@docusaurus/types';
|
|
8
|
+
export default function loadPresets(context: LoadContext): Promise<{
|
|
9
9
|
plugins: PluginConfig[];
|
|
10
10
|
themes: PluginConfig[];
|
|
11
|
-
}
|
|
11
|
+
}>;
|