@docusaurus/core 2.0.0-beta.fc64c12e4 → 2.0.0
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.js → docusaurus.mjs} +81 -118
- 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/ExecutionEnvironment.js +7 -8
- 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 +18 -51
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +38 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +11 -10
- 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/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- 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/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- 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 +94 -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 +107 -102
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -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 +119 -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 -137
- 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 +166 -99
- 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 +7 -1
- package/lib/server/utils.js +7 -8
- 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 +30 -29
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +21 -12
- 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/beforeCli.js +0 -103
- 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 -9
- 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 -39
- 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,12 @@
|
|
|
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 { Props, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Runs the `injectHtmlTags` lifecycle, and aggregates all plugins' tags into
|
|
10
|
+
* directly render-able HTML markup.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadHtmlTags(plugins: LoadedPlugin[]): Pick<Props, 'headTags' | 'preBodyTags' | 'postBodyTags'>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.loadHtmlTags = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
13
|
+
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
14
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
15
|
+
function assertIsHtmlTagObject(val) {
|
|
16
|
+
if (typeof val !== 'object' || !val) {
|
|
17
|
+
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
18
|
+
}
|
|
19
|
+
if (typeof val.tagName !== 'string') {
|
|
20
|
+
throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
|
|
21
|
+
}
|
|
22
|
+
if (!html_tags_1.default.includes(val.tagName)) {
|
|
23
|
+
throw new Error(`Error loading ${JSON.stringify(val)}, "${val.tagName}" is not a valid HTML tag.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function htmlTagObjectToString(tag) {
|
|
27
|
+
assertIsHtmlTagObject(tag);
|
|
28
|
+
const isVoidTag = void_1.default.includes(tag.tagName);
|
|
29
|
+
const tagAttributes = tag.attributes ?? {};
|
|
30
|
+
const attributes = Object.keys(tagAttributes)
|
|
31
|
+
.map((attr) => {
|
|
32
|
+
const value = tagAttributes[attr];
|
|
33
|
+
if (typeof value === 'boolean') {
|
|
34
|
+
return value ? attr : undefined;
|
|
35
|
+
}
|
|
36
|
+
return `${attr}="${(0, escape_html_1.default)(value)}"`;
|
|
37
|
+
})
|
|
38
|
+
.filter((str) => Boolean(str));
|
|
39
|
+
const openingTag = `<${[tag.tagName].concat(attributes).join(' ')}>`;
|
|
40
|
+
const innerHTML = (!isVoidTag && tag.innerHTML) || '';
|
|
41
|
+
const closingTag = isVoidTag ? '' : `</${tag.tagName}>`;
|
|
42
|
+
return openingTag + innerHTML + closingTag;
|
|
43
|
+
}
|
|
44
|
+
function createHtmlTagsString(tags) {
|
|
45
|
+
return (Array.isArray(tags) ? tags : [tags])
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.map((val) => (typeof val === 'string' ? val : htmlTagObjectToString(val)))
|
|
48
|
+
.join('\n');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the `injectHtmlTags` lifecycle, and aggregates all plugins' tags into
|
|
52
|
+
* directly render-able HTML markup.
|
|
53
|
+
*/
|
|
54
|
+
function loadHtmlTags(plugins) {
|
|
55
|
+
const pluginHtmlTags = plugins.map((plugin) => plugin.injectHtmlTags?.({ content: plugin.content }) ?? {});
|
|
56
|
+
const tagTypes = ['headTags', 'preBodyTags', 'postBodyTags'];
|
|
57
|
+
return Object.fromEntries(lodash_1.default.zip(tagTypes, tagTypes.map((type) => pluginHtmlTags
|
|
58
|
+
.map((tags) => createHtmlTagsString(tags[type]))
|
|
59
|
+
.join('\n')
|
|
60
|
+
.trim())));
|
|
61
|
+
}
|
|
62
|
+
exports.loadHtmlTags = loadHtmlTags;
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -4,17 +4,7 @@
|
|
|
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 { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
7
|
+
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
|
+
import type { LoadContextOptions } from './index';
|
|
8
9
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function loadI18n(config: DocusaurusConfig, options?: {
|
|
11
|
-
locale?: string;
|
|
12
|
-
}): Promise<I18n>;
|
|
13
|
-
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
14
|
-
pathType: 'fs' | 'url';
|
|
15
|
-
path: string;
|
|
16
|
-
i18n: I18n;
|
|
17
|
-
options?: {
|
|
18
|
-
localizePath?: boolean;
|
|
19
|
-
};
|
|
20
|
-
}): string;
|
|
10
|
+
export declare function loadI18n(config: DocusaurusConfig, options: Pick<LoadContextOptions, 'locale'>): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -1,87 +1,53 @@
|
|
|
1
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
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
9
|
+
exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
4
10
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const utils_1 = require("@docusaurus/utils");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
7
12
|
const rtl_detect_1 = require("rtl-detect");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
13
|
function getDefaultLocaleLabel(locale) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// @ts-expect-error: wait for TS support of ES2021 feature
|
|
14
|
-
if (typeof Intl.DisplayNames !== 'undefined') {
|
|
15
|
-
// @ts-expect-error: wait for TS support of ES2021 feature
|
|
16
|
-
return new Intl.DisplayNames([locale], { type: 'language' }).of(locale);
|
|
17
|
-
}
|
|
18
|
-
return locale;
|
|
14
|
+
const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
|
|
15
|
+
return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
|
|
19
16
|
}
|
|
20
17
|
function getDefaultLocaleConfig(locale) {
|
|
21
18
|
return {
|
|
22
19
|
label: getDefaultLocaleLabel(locale),
|
|
23
|
-
direction: rtl_detect_1.getLangDir(locale),
|
|
20
|
+
direction: (0, rtl_detect_1.getLangDir)(locale),
|
|
21
|
+
htmlLang: locale,
|
|
22
|
+
// If the locale name includes -u-ca-xxx the calendar will be defined
|
|
23
|
+
calendar: new Intl.Locale(locale).calendar ?? 'gregory',
|
|
24
|
+
path: locale,
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
27
|
-
function
|
|
28
|
-
const isOnlyEnglish = locales.length === 1 && locales.includes('en');
|
|
29
|
-
const isOlderNodeVersion = version < 14;
|
|
30
|
-
return isOlderNodeVersion && !isOnlyEnglish;
|
|
31
|
-
}
|
|
32
|
-
exports.shouldWarnAboutNodeVersion = shouldWarnAboutNodeVersion;
|
|
33
|
-
async function loadI18n(config, options = {}) {
|
|
34
|
-
var _a;
|
|
28
|
+
async function loadI18n(config, options) {
|
|
35
29
|
const { i18n: i18nConfig } = config;
|
|
36
|
-
const currentLocale =
|
|
30
|
+
const currentLocale = options.locale ?? i18nConfig.defaultLocale;
|
|
37
31
|
if (!i18nConfig.locales.includes(currentLocale)) {
|
|
38
|
-
|
|
39
|
-
Note: Docusaurus only support running one locale at a time
|
|
32
|
+
logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
|
|
33
|
+
Note: Docusaurus only support running one locale at a time.`;
|
|
40
34
|
}
|
|
41
35
|
const locales = i18nConfig.locales.includes(currentLocale)
|
|
42
36
|
? i18nConfig.locales
|
|
43
37
|
: i18nConfig.locales.concat(currentLocale);
|
|
44
|
-
if (shouldWarnAboutNodeVersion(constants_1.NODE_MAJOR_VERSION, locales)) {
|
|
45
|
-
console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use Node.js 14 or later (instead of ${constants_1.NODE_MAJOR_VERSION}).`));
|
|
46
|
-
}
|
|
47
38
|
function getLocaleConfig(locale) {
|
|
48
39
|
return {
|
|
49
40
|
...getDefaultLocaleConfig(locale),
|
|
50
41
|
...i18nConfig.localeConfigs[locale],
|
|
51
42
|
};
|
|
52
43
|
}
|
|
53
|
-
const localeConfigs = locales.
|
|
54
|
-
return { ...acc, [locale]: getLocaleConfig(locale) };
|
|
55
|
-
}, {});
|
|
44
|
+
const localeConfigs = Object.fromEntries(locales.map((locale) => [locale, getLocaleConfig(locale)]));
|
|
56
45
|
return {
|
|
57
46
|
defaultLocale: i18nConfig.defaultLocale,
|
|
58
47
|
locales,
|
|
48
|
+
path: i18nConfig.path,
|
|
59
49
|
currentLocale,
|
|
60
50
|
localeConfigs,
|
|
61
51
|
};
|
|
62
52
|
}
|
|
63
53
|
exports.loadI18n = loadI18n;
|
|
64
|
-
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
65
|
-
const shouldLocalizePath = typeof options.localizePath === 'undefined'
|
|
66
|
-
? // By default, we don't localize the path of defaultLocale
|
|
67
|
-
i18n.currentLocale !== i18n.defaultLocale
|
|
68
|
-
: options.localizePath;
|
|
69
|
-
if (shouldLocalizePath) {
|
|
70
|
-
// FS paths need special care, for Windows support
|
|
71
|
-
if (pathType === 'fs') {
|
|
72
|
-
return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
|
|
73
|
-
}
|
|
74
|
-
// Url paths
|
|
75
|
-
else if (pathType === 'url') {
|
|
76
|
-
return utils_1.normalizeUrl([originalPath, '/', i18n.currentLocale, '/']);
|
|
77
|
-
}
|
|
78
|
-
// should never happen
|
|
79
|
-
else {
|
|
80
|
-
throw new Error(`Unhandled path type "${pathType}".`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return originalPath;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.localizePath = localizePath;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -4,20 +4,35 @@
|
|
|
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 {
|
|
7
|
+
import type { LoadContext, Props } from '@docusaurus/types';
|
|
8
8
|
export declare type LoadContextOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Usually the CWD; can be overridden with command argument. */
|
|
10
|
+
siteDir: string;
|
|
11
|
+
/** Custom output directory. Can be customized with `--out-dir` option */
|
|
12
|
+
outDir?: string;
|
|
13
|
+
/** Custom config path. Can be customized with `--config` option */
|
|
14
|
+
config?: string;
|
|
15
|
+
/** Default is `i18n.defaultLocale` */
|
|
11
16
|
locale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `true` means the paths will have the locale prepended; `false` means they
|
|
19
|
+
* won't (useful for `yarn build -l zh-Hans` where the output should be
|
|
20
|
+
* emitted into `build/` instead of `build/zh-Hans/`); `undefined` is like the
|
|
21
|
+
* "smart" option where only non-default locale paths are localized
|
|
22
|
+
*/
|
|
12
23
|
localizePath?: boolean;
|
|
13
24
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loading context is the very first step in site building. Its options are
|
|
27
|
+
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
28
|
+
* context (which includes code translations). The `LoadContext` will be passed
|
|
29
|
+
* to plugin constructors.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadContext(options: LoadContextOptions): Promise<LoadContext>;
|
|
32
|
+
/**
|
|
33
|
+
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
34
|
+
* code translations, config file, plugin modules... Plugins then use their
|
|
35
|
+
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
36
|
+
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
37
|
+
*/
|
|
38
|
+
export declare function load(options: LoadContextOptions): Promise<Props>;
|
package/lib/server/index.js
CHANGED
|
@@ -6,185 +6,120 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.load = exports.
|
|
9
|
+
exports.load = exports.loadContext = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
11
13
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const ssr_html_template_1 = tslib_1.__importDefault(require("../client/templates/ssr.html.template"));
|
|
15
|
-
const constants_1 = require("../constants");
|
|
16
|
-
const client_modules_1 = tslib_1.__importDefault(require("./client-modules"));
|
|
17
|
-
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
const clientModules_1 = require("./clientModules");
|
|
18
16
|
const plugins_1 = require("./plugins");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const versions_1 = require("./versions");
|
|
23
|
-
const duplicateRoutes_1 = require("./duplicateRoutes");
|
|
17
|
+
const routes_1 = require("./routes");
|
|
18
|
+
const htmlTags_1 = require("./htmlTags");
|
|
19
|
+
const siteMetadata_1 = require("./siteMetadata");
|
|
24
20
|
const i18n_1 = require("./i18n");
|
|
25
21
|
const translations_1 = require("./translations/translations");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
async function loadContext(siteDir, options = {}) {
|
|
37
|
-
var _a;
|
|
38
|
-
const { customOutDir, locale, customConfigFilePath } = options;
|
|
39
|
-
const generatedFilesDir = path_1.default.isAbsolute(constants_1.GENERATED_FILES_DIR_NAME)
|
|
40
|
-
? constants_1.GENERATED_FILES_DIR_NAME
|
|
41
|
-
: path_1.default.resolve(siteDir, constants_1.GENERATED_FILES_DIR_NAME);
|
|
42
|
-
const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
|
|
22
|
+
/**
|
|
23
|
+
* Loading context is the very first step in site building. Its options are
|
|
24
|
+
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
25
|
+
* context (which includes code translations). The `LoadContext` will be passed
|
|
26
|
+
* to plugin constructors.
|
|
27
|
+
*/
|
|
28
|
+
async function loadContext(options) {
|
|
29
|
+
const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, } = options;
|
|
30
|
+
const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
|
|
31
|
+
const { siteConfig: initialSiteConfig, siteConfigPath } = await (0, config_1.loadSiteConfig)({
|
|
43
32
|
siteDir,
|
|
44
33
|
customConfigFilePath,
|
|
45
34
|
});
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
? path_1.default.resolve(customOutDir)
|
|
49
|
-
: path_1.default.resolve(siteDir, constants_1.DEFAULT_BUILD_DIR_NAME);
|
|
50
|
-
const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
|
|
51
|
-
const baseUrl = i18n_1.localizePath({
|
|
35
|
+
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
36
|
+
const baseUrl = (0, utils_1.localizePath)({
|
|
52
37
|
path: initialSiteConfig.baseUrl,
|
|
53
38
|
i18n,
|
|
54
39
|
options,
|
|
55
40
|
pathType: 'url',
|
|
56
41
|
});
|
|
57
|
-
const outDir =
|
|
58
|
-
path: baseOutDir,
|
|
42
|
+
const outDir = (0, utils_1.localizePath)({
|
|
43
|
+
path: path_1.default.resolve(siteDir, baseOutDir),
|
|
59
44
|
i18n,
|
|
60
45
|
options,
|
|
61
46
|
pathType: 'fs',
|
|
62
47
|
});
|
|
63
48
|
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
locale: i18n.currentLocale,
|
|
67
|
-
}))) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[i18n.currentLocale].path);
|
|
50
|
+
const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({ localizationDir })) ?? {};
|
|
68
51
|
// We only need key->message for code translations
|
|
69
|
-
const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
52
|
+
const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
70
53
|
return {
|
|
71
54
|
siteDir,
|
|
72
55
|
generatedFilesDir,
|
|
56
|
+
localizationDir,
|
|
73
57
|
siteConfig,
|
|
74
58
|
siteConfigPath,
|
|
75
59
|
outDir,
|
|
76
60
|
baseUrl,
|
|
77
61
|
i18n,
|
|
78
|
-
ssrTemplate,
|
|
79
62
|
codeTranslations,
|
|
80
63
|
};
|
|
81
64
|
}
|
|
82
65
|
exports.loadContext = loadContext;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const pluginConfigs = loadPluginConfigs(context);
|
|
101
|
-
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
|
|
102
|
-
pluginConfigs,
|
|
103
|
-
context,
|
|
104
|
-
});
|
|
105
|
-
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
106
|
-
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
107
|
-
duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
|
|
108
|
-
// Site config must be generated after plugins
|
|
109
|
-
// We want the generated config to have been normalized by the plugins!
|
|
110
|
-
const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
|
|
111
|
-
// Make a fake plugin to:
|
|
112
|
-
// - Resolve aliased theme components
|
|
113
|
-
// - Inject scripts/stylesheets
|
|
114
|
-
const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
|
|
115
|
-
plugins.push({
|
|
116
|
-
name: 'docusaurus-bootstrap-plugin',
|
|
117
|
-
content: null,
|
|
118
|
-
options: {},
|
|
119
|
-
version: { type: 'synthetic' },
|
|
120
|
-
getClientModules() {
|
|
121
|
-
return siteConfigClientModules;
|
|
122
|
-
},
|
|
123
|
-
injectHtmlTags: () => {
|
|
124
|
-
const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
|
|
125
|
-
? `<link rel="stylesheet" href="${source}">`
|
|
126
|
-
: {
|
|
127
|
-
tagName: 'link',
|
|
128
|
-
attributes: {
|
|
129
|
-
rel: 'stylesheet',
|
|
130
|
-
...source,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
const scriptsTags = scripts.map((source) => typeof source === 'string'
|
|
134
|
-
? `<script src="${source}"></script>`
|
|
135
|
-
: {
|
|
136
|
-
tagName: 'script',
|
|
137
|
-
attributes: {
|
|
138
|
-
...source,
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
// Load client modules.
|
|
147
|
-
const clientModules = client_modules_1.default(plugins);
|
|
148
|
-
const genClientModules = utils_1.generate(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
|
|
149
|
-
// import() is async so we use require() because client modules can have
|
|
150
|
-
// CSS and the order matters for loading CSS.
|
|
151
|
-
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
152
|
-
.map((module) => ` require(${JSON.stringify(module)}),`)
|
|
153
|
-
.join('\n')}\n];\n`);
|
|
154
|
-
// Load extra head & body html tags.
|
|
155
|
-
const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
|
|
156
|
-
// Routing.
|
|
157
|
-
const { registry, routesChunkNames, routesConfig, routesPaths, } = await routes_1.default(pluginsRouteConfigs, baseUrl);
|
|
158
|
-
const genRegistry = utils_1.generate(generatedFilesDir, 'registry.js', `export default {
|
|
159
|
-
${Object.keys(registry)
|
|
160
|
-
.sort()
|
|
161
|
-
.map((key) =>
|
|
162
|
-
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
163
|
-
` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
|
|
164
|
-
.join('\n')}};\n`);
|
|
165
|
-
const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
166
|
-
const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
|
|
167
|
-
const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
168
|
-
const genI18n = utils_1.generate(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
169
|
-
const codeTranslationsWithFallbacks = {
|
|
170
|
-
...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
|
|
171
|
-
...codeTranslations,
|
|
172
|
-
};
|
|
173
|
-
const genCodeTranslations = utils_1.generate(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
174
|
-
// Version metadata.
|
|
175
|
-
const siteMetadata = {
|
|
176
|
-
docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
|
|
177
|
-
siteVersion: versions_1.getPackageJsonVersion(path_1.join(siteDir, 'package.json')),
|
|
178
|
-
pluginVersions: {},
|
|
66
|
+
/**
|
|
67
|
+
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
68
|
+
* code translations, config file, plugin modules... Plugins then use their
|
|
69
|
+
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
70
|
+
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
71
|
+
*/
|
|
72
|
+
async function load(options) {
|
|
73
|
+
const { siteDir } = options;
|
|
74
|
+
const context = await loadContext(options);
|
|
75
|
+
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
|
|
76
|
+
const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
|
|
77
|
+
const clientModules = (0, clientModules_1.loadClientModules)(plugins);
|
|
78
|
+
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
|
|
79
|
+
const { registry, routesChunkNames, routesConfig, routesPaths } = (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
|
|
80
|
+
const codeTranslations = {
|
|
81
|
+
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
82
|
+
...siteCodeTranslations,
|
|
179
83
|
};
|
|
180
|
-
plugins
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
84
|
+
const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
|
|
85
|
+
// === Side-effects part ===
|
|
86
|
+
const genWarning = (0, utils_1.generate)(generatedFilesDir,
|
|
87
|
+
// cSpell:ignore DONT
|
|
88
|
+
'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
|
|
89
|
+
|
|
90
|
+
DO NOT hand-modify files in this folder because they will be overwritten in the
|
|
91
|
+
next build. You can clear all build artifacts (including this folder) with the
|
|
92
|
+
\`docusaurus clear\` command.
|
|
93
|
+
`);
|
|
94
|
+
const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, `${utils_1.DEFAULT_CONFIG_FILE_NAME}.mjs`, `/*
|
|
95
|
+
* AUTOGENERATED - DON'T EDIT
|
|
96
|
+
* Your edits in this file will be overwritten in the next build!
|
|
97
|
+
* Modify the docusaurus.config.js file at your site's root instead.
|
|
98
|
+
*/
|
|
99
|
+
export default ${JSON.stringify(siteConfig, null, 2)};
|
|
100
|
+
`);
|
|
101
|
+
const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
|
|
102
|
+
${clientModules
|
|
103
|
+
// Use `require()` because `import()` is async but client modules can have CSS
|
|
104
|
+
// and the order matters for loading CSS.
|
|
105
|
+
.map((clientModule) => ` require('${(0, utils_1.escapePath)(clientModule)}'),`)
|
|
106
|
+
.join('\n')}
|
|
107
|
+
];
|
|
108
|
+
`);
|
|
109
|
+
const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
|
|
110
|
+
${Object.entries(registry)
|
|
111
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
112
|
+
.map(([chunkName, modulePath]) => ` '${chunkName}': [() => import(/* webpackChunkName: '${chunkName}' */ '${modulePath}'), '${modulePath}', require.resolveWeak('${modulePath}')],`)
|
|
113
|
+
.join('\n')}};
|
|
114
|
+
`);
|
|
115
|
+
const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
116
|
+
const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
|
|
117
|
+
const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
118
|
+
const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
119
|
+
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslations, null, 2));
|
|
120
|
+
const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
187
121
|
await Promise.all([
|
|
122
|
+
genWarning,
|
|
188
123
|
genClientModules,
|
|
189
124
|
genSiteConfig,
|
|
190
125
|
genRegistry,
|
|
@@ -195,7 +130,7 @@ ${Object.keys(registry)
|
|
|
195
130
|
genI18n,
|
|
196
131
|
genCodeTranslations,
|
|
197
132
|
]);
|
|
198
|
-
|
|
133
|
+
return {
|
|
199
134
|
siteConfig,
|
|
200
135
|
siteConfigPath,
|
|
201
136
|
siteMetadata,
|
|
@@ -203,6 +138,7 @@ ${Object.keys(registry)
|
|
|
203
138
|
outDir,
|
|
204
139
|
baseUrl,
|
|
205
140
|
i18n,
|
|
141
|
+
localizationDir,
|
|
206
142
|
generatedFilesDir,
|
|
207
143
|
routes: pluginsRouteConfigs,
|
|
208
144
|
routesPaths,
|
|
@@ -210,25 +146,7 @@ ${Object.keys(registry)
|
|
|
210
146
|
headTags,
|
|
211
147
|
preBodyTags,
|
|
212
148
|
postBodyTags,
|
|
213
|
-
ssrTemplate: ssrTemplate || ssr_html_template_1.default,
|
|
214
149
|
codeTranslations,
|
|
215
150
|
};
|
|
216
|
-
return props;
|
|
217
151
|
}
|
|
218
152
|
exports.load = load;
|
|
219
|
-
// We want all @docusaurus/* packages to have the exact same version!
|
|
220
|
-
// See https://github.com/facebook/docusaurus/issues/3371
|
|
221
|
-
// See https://github.com/facebook/docusaurus/pull/3386
|
|
222
|
-
function checkDocusaurusPackagesVersion(siteMetadata) {
|
|
223
|
-
const { docusaurusVersion } = siteMetadata;
|
|
224
|
-
Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
|
|
225
|
-
var _a;
|
|
226
|
-
if (versionInfo.type === 'package' &&
|
|
227
|
-
((_a = versionInfo.name) === null || _a === void 0 ? void 0 : _a.startsWith('@docusaurus/')) &&
|
|
228
|
-
versionInfo.version !== docusaurusVersion) {
|
|
229
|
-
// should we throw instead?
|
|
230
|
-
// It still could work with different versions
|
|
231
|
-
console.warn(chalk_1.default.red(`Invalid ${plugin} version ${versionInfo.version}.\nAll official @docusaurus/* packages should have the exact same version as @docusaurus/core (${docusaurusVersion}).\nMaybe you want to check, or regenerate your yarn.lock or package-lock.json file?`));
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { LoadContext, PluginModule, PluginOptions } from '@docusaurus/types';
|
|
8
|
+
declare type ImportedPluginModule = PluginModule & {
|
|
9
|
+
default?: PluginModule;
|
|
10
|
+
};
|
|
11
|
+
export declare type NormalizedPluginConfig = {
|
|
12
|
+
/**
|
|
13
|
+
* The default export of the plugin module, or alternatively, what's provided
|
|
14
|
+
* in the config file as inline plugins. Note that if a file is like:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* export default plugin() {...}
|
|
18
|
+
* export validateOptions() {...}
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Then the static methods may not exist here. `pluginModule.module` will
|
|
22
|
+
* always take priority.
|
|
23
|
+
*/
|
|
24
|
+
plugin: PluginModule;
|
|
25
|
+
/** Options as they are provided in the config, not validated yet. */
|
|
26
|
+
options: PluginOptions;
|
|
27
|
+
/** Only available when a string is provided in config. */
|
|
28
|
+
pluginModule?: {
|
|
29
|
+
/**
|
|
30
|
+
* Raw module name as provided in the config. Shorthands have been resolved,
|
|
31
|
+
* so at least it's directly `require.resolve`able.
|
|
32
|
+
*/
|
|
33
|
+
path: string;
|
|
34
|
+
/** Whatever gets imported with `require`. */
|
|
35
|
+
module: ImportedPluginModule;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Different from `pluginModule.path`, this one is always an absolute path,
|
|
39
|
+
* used to resolve relative paths returned from lifecycles. If it's an inline
|
|
40
|
+
* plugin, it will be path to the config file.
|
|
41
|
+
*/
|
|
42
|
+
entryPath: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
|
|
46
|
+
* normalizes the return value. Plugin configs are ordered, mostly for theme
|
|
47
|
+
* alias shadowing. Site themes have the highest priority, and preset plugins
|
|
48
|
+
* are the lowest.
|
|
49
|
+
*/
|
|
50
|
+
export declare function loadPluginConfigs(context: LoadContext): Promise<NormalizedPluginConfig[]>;
|
|
51
|
+
export {};
|