@docusaurus/core 2.0.0-beta.16 → 2.0.0-beta.17
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/lib/babel/preset.js +2 -2
- package/lib/choosePort.js +4 -4
- package/lib/client/client-lifecycles-dispatcher.js +3 -3
- package/lib/client/docusaurus.js +2 -5
- package/lib/client/exports/ErrorBoundary.js +4 -5
- package/lib/client/exports/Interpolate.js +2 -2
- package/lib/client/exports/Link.js +2 -3
- package/lib/client/exports/Translate.js +1 -2
- package/lib/commands/build.js +12 -14
- package/lib/commands/clear.js +3 -3
- package/lib/commands/commandUtils.js +1 -1
- package/lib/commands/deploy.js +6 -6
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +7 -8
- package/lib/commands/start.js +13 -14
- package/lib/commands/swizzle/actions.js +4 -4
- package/lib/commands/swizzle/common.js +8 -9
- package/lib/commands/swizzle/components.js +7 -10
- package/lib/commands/swizzle/config.js +7 -4
- package/lib/commands/swizzle/context.js +1 -1
- package/lib/commands/swizzle/index.js +1 -1
- package/lib/commands/swizzle/prompts.js +2 -2
- package/lib/commands/swizzle/tables.js +3 -3
- package/lib/commands/swizzle/themes.js +6 -8
- package/lib/commands/writeHeadingIds.js +5 -5
- package/lib/commands/writeTranslations.js +4 -6
- package/lib/index.js +9 -9
- package/lib/server/brokenLinks.js +26 -12
- package/lib/server/client-modules/index.js +1 -1
- package/lib/server/config.js +2 -2
- package/lib/server/html-tags/htmlTags.js +3 -3
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.js +7 -6
- package/lib/server/index.js +16 -20
- package/lib/server/plugins/index.js +14 -19
- package/lib/server/plugins/init.js +12 -15
- package/lib/server/plugins/pluginIds.js +2 -2
- package/lib/server/presets/index.js +2 -3
- package/lib/server/routes.js +3 -5
- package/lib/server/themes/alias.js +3 -3
- package/lib/server/themes/index.js +2 -2
- package/lib/server/translations/translations.js +15 -22
- package/lib/server/translations/translationsExtractor.js +13 -15
- package/lib/server/utils.js +1 -1
- package/lib/server/versions/index.js +2 -2
- package/lib/webpack/base.js +4 -5
- package/lib/webpack/client.js +6 -7
- package/lib/webpack/plugins/CleanWebpackPlugin.js +1 -1
- package/lib/webpack/plugins/LogPlugin.js +2 -2
- package/lib/webpack/plugins/WaitPlugin.js +3 -3
- package/lib/webpack/server.js +5 -5
- package/lib/webpack/utils.js +16 -19
- package/package.json +11 -11
- package/lib/server/loadSetup.d.ts +0 -8
- package/lib/server/loadSetup.js +0 -25
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const path_1 =
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
11
|
const server_1 = require("../server");
|
|
12
|
-
const init_1 =
|
|
12
|
+
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
13
13
|
const translations_1 = require("../server/translations/translations");
|
|
14
14
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
15
15
|
const utils_1 = require("../webpack/utils");
|
|
@@ -30,9 +30,8 @@ async function getExtraSourceCodeFilePaths() {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }) {
|
|
33
|
-
var _a;
|
|
34
33
|
if (plugin.getTranslationFiles) {
|
|
35
|
-
const content = await
|
|
34
|
+
const content = await plugin.loadContent?.();
|
|
36
35
|
const translationFiles = await plugin.getTranslationFiles({
|
|
37
36
|
content,
|
|
38
37
|
});
|
|
@@ -48,7 +47,6 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
async function writeTranslations(siteDir, options) {
|
|
51
|
-
var _a;
|
|
52
50
|
const context = await (0, server_1.loadContext)(siteDir, {
|
|
53
51
|
customConfigFilePath: options.config,
|
|
54
52
|
locale: options.locale,
|
|
@@ -58,7 +56,7 @@ async function writeTranslations(siteDir, options) {
|
|
|
58
56
|
pluginConfigs,
|
|
59
57
|
context,
|
|
60
58
|
});
|
|
61
|
-
const locale =
|
|
59
|
+
const locale = options.locale ?? context.i18n.defaultLocale;
|
|
62
60
|
if (!context.i18n.locales.includes(locale)) {
|
|
63
61
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
64
62
|
Available locales are: ${context.i18n.locales.join(',')}.`);
|
package/lib/index.js
CHANGED
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const build_1 =
|
|
11
|
+
const build_1 = tslib_1.__importDefault(require("./commands/build"));
|
|
12
12
|
exports.build = build_1.default;
|
|
13
|
-
const clear_1 =
|
|
13
|
+
const clear_1 = tslib_1.__importDefault(require("./commands/clear"));
|
|
14
14
|
exports.clear = clear_1.default;
|
|
15
|
-
const deploy_1 =
|
|
15
|
+
const deploy_1 = tslib_1.__importDefault(require("./commands/deploy"));
|
|
16
16
|
exports.deploy = deploy_1.default;
|
|
17
|
-
const external_1 =
|
|
17
|
+
const external_1 = tslib_1.__importDefault(require("./commands/external"));
|
|
18
18
|
exports.externalCommand = external_1.default;
|
|
19
|
-
const serve_1 =
|
|
19
|
+
const serve_1 = tslib_1.__importDefault(require("./commands/serve"));
|
|
20
20
|
exports.serve = serve_1.default;
|
|
21
|
-
const start_1 =
|
|
21
|
+
const start_1 = tslib_1.__importDefault(require("./commands/start"));
|
|
22
22
|
exports.start = start_1.default;
|
|
23
|
-
const swizzle_1 =
|
|
23
|
+
const swizzle_1 = tslib_1.__importDefault(require("./commands/swizzle"));
|
|
24
24
|
exports.swizzle = swizzle_1.default;
|
|
25
|
-
const writeHeadingIds_1 =
|
|
25
|
+
const writeHeadingIds_1 = tslib_1.__importDefault(require("./commands/writeHeadingIds"));
|
|
26
26
|
exports.writeHeadingIds = writeHeadingIds_1.default;
|
|
27
|
-
const writeTranslations_1 =
|
|
27
|
+
const writeTranslations_1 = tslib_1.__importDefault(require("./commands/writeTranslations"));
|
|
28
28
|
exports.writeTranslations = writeTranslations_1.default;
|
|
@@ -9,12 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenLinksErrorMessage = exports.getAllBrokenLinks = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const react_router_config_1 = require("react-router-config");
|
|
12
|
-
const fs_extra_1 =
|
|
13
|
-
const lodash_1 =
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const utils_2 = require("./utils");
|
|
16
|
-
const path_1 =
|
|
17
|
-
const combine_promises_1 =
|
|
16
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
18
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
18
19
|
function toReactRouterRoutes(routes) {
|
|
19
20
|
// @ts-expect-error: types incompatible???
|
|
20
21
|
return routes;
|
|
@@ -66,7 +67,9 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
66
67
|
return `${brokenLink.link}${showResolvedLink ? ` (resolved as: ${brokenLink.resolvedLink})` : ''}`;
|
|
67
68
|
}
|
|
68
69
|
function pageBrokenLinksMessage(pagePath, brokenLinks) {
|
|
69
|
-
return
|
|
70
|
+
return `
|
|
71
|
+
- On source page path = ${pagePath}:
|
|
72
|
+
-> linking to ${brokenLinks
|
|
70
73
|
.map(brokenLinkMessage)
|
|
71
74
|
.join('\n -> linking to ')}`;
|
|
72
75
|
}
|
|
@@ -85,13 +88,24 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
85
88
|
if (frequentLinks.length === 0) {
|
|
86
89
|
return '';
|
|
87
90
|
}
|
|
88
|
-
return
|
|
91
|
+
return logger_1.default.interpolate `
|
|
92
|
+
|
|
93
|
+
It looks like some of the broken links we found appear in many pages of your site.
|
|
94
|
+
Maybe those broken links appear on all pages through your site layout?
|
|
95
|
+
We recommend that you check your theme configuration for such links (particularly, theme navbar and footer).
|
|
96
|
+
Frequent broken links are linking to:${frequentLinks}
|
|
97
|
+
`;
|
|
89
98
|
}
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
return `Docusaurus found broken links!
|
|
100
|
+
|
|
101
|
+
Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
|
|
102
|
+
Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}
|
|
103
|
+
|
|
104
|
+
Exhaustive list of all broken links found:
|
|
105
|
+
${Object.entries(allBrokenLinks)
|
|
106
|
+
.map(([pagePath, brokenLinks]) => pageBrokenLinksMessage(pagePath, brokenLinks))
|
|
107
|
+
.join('\n')}
|
|
108
|
+
`;
|
|
95
109
|
}
|
|
96
110
|
exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
|
|
97
111
|
async function isExistingFile(filePath) {
|
|
@@ -107,7 +121,7 @@ async function isExistingFile(filePath) {
|
|
|
107
121
|
async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
|
|
108
122
|
async function linkFileExists(link) {
|
|
109
123
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
|
110
|
-
const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
|
|
124
|
+
const baseFilePath = onlyPathname((0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/'));
|
|
111
125
|
// -> /outDir/javadoc
|
|
112
126
|
// -> /outDir/javadoc.html
|
|
113
127
|
// -> /outDir/javadoc/index.html
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
function loadClientModules(plugins) {
|
|
10
|
-
return plugins.flatMap((plugin) =>
|
|
10
|
+
return plugins.flatMap((plugin) => plugin.getClientModules?.() ?? []);
|
|
11
11
|
}
|
|
12
12
|
exports.default = loadClientModules;
|
package/lib/server/config.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_extra_1 =
|
|
11
|
-
const import_fresh_1 =
|
|
10
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
12
|
const configValidation_1 = require("./configValidation");
|
|
13
13
|
async function loadConfig(configPath) {
|
|
14
14
|
if (!(await fs_extra_1.default.pathExists(configPath))) {
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const html_tags_1 =
|
|
11
|
-
const void_1 =
|
|
12
|
-
const escape_html_1 =
|
|
10
|
+
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
11
|
+
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
12
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
13
13
|
function assertIsHtmlTagObject(val) {
|
|
14
14
|
if (typeof val !== 'object' || !val) {
|
|
15
15
|
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.loadHtmlTags = exports.createHtmlTagsString = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const htmlTags_1 =
|
|
11
|
+
const htmlTags_1 = tslib_1.__importDefault(require("./htmlTags"));
|
|
12
12
|
function toString(val) {
|
|
13
13
|
return typeof val === 'string' ? val : (0, htmlTags_1.default)(val);
|
|
14
14
|
}
|
package/lib/server/i18n.js
CHANGED
|
@@ -8,12 +8,15 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.localizePath = exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const rtl_detect_1 = require("rtl-detect");
|
|
14
|
-
const logger_1 =
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
15
|
function getDefaultLocaleLabel(locale) {
|
|
16
16
|
const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
|
|
17
|
+
if (!languageName) {
|
|
18
|
+
return locale;
|
|
19
|
+
}
|
|
17
20
|
return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
|
|
18
21
|
}
|
|
19
22
|
function getDefaultLocaleConfig(locale) {
|
|
@@ -25,9 +28,8 @@ function getDefaultLocaleConfig(locale) {
|
|
|
25
28
|
}
|
|
26
29
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
27
30
|
async function loadI18n(config, options = {}) {
|
|
28
|
-
var _a;
|
|
29
31
|
const { i18n: i18nConfig } = config;
|
|
30
|
-
const currentLocale =
|
|
32
|
+
const currentLocale = options.locale ?? i18nConfig.defaultLocale;
|
|
31
33
|
if (!i18nConfig.locales.includes(currentLocale)) {
|
|
32
34
|
logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
|
|
33
35
|
Note: Docusaurus only support running one locale at a time.`;
|
|
@@ -51,10 +53,9 @@ Note: Docusaurus only support running one locale at a time.`;
|
|
|
51
53
|
}
|
|
52
54
|
exports.loadI18n = loadI18n;
|
|
53
55
|
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
54
|
-
var _a;
|
|
55
56
|
const shouldLocalizePath =
|
|
56
57
|
// By default, we don't localize the path of defaultLocale
|
|
57
|
-
|
|
58
|
+
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
58
59
|
if (!shouldLocalizePath) {
|
|
59
60
|
return originalPath;
|
|
60
61
|
}
|
package/lib/server/index.js
CHANGED
|
@@ -9,25 +9,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.load = exports.loadPluginConfigs = exports.loadContext = exports.loadSiteConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const path_1 =
|
|
13
|
-
const logger_1 =
|
|
14
|
-
const ssr_html_template_1 =
|
|
15
|
-
const client_modules_1 =
|
|
16
|
-
const config_1 =
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const ssr_html_template_1 = tslib_1.__importDefault(require("../webpack/templates/ssr.html.template"));
|
|
15
|
+
const client_modules_1 = tslib_1.__importDefault(require("./client-modules"));
|
|
16
|
+
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
17
17
|
const plugins_1 = require("./plugins");
|
|
18
|
-
const presets_1 =
|
|
19
|
-
const routes_1 =
|
|
18
|
+
const presets_1 = tslib_1.__importDefault(require("./presets"));
|
|
19
|
+
const routes_1 = tslib_1.__importDefault(require("./routes"));
|
|
20
20
|
const html_tags_1 = require("./html-tags");
|
|
21
21
|
const versions_1 = require("./versions");
|
|
22
22
|
const duplicateRoutes_1 = require("./duplicateRoutes");
|
|
23
23
|
const i18n_1 = require("./i18n");
|
|
24
24
|
const translations_1 = require("./translations/translations");
|
|
25
|
-
const lodash_1 =
|
|
26
|
-
const remark_admonitions_1 =
|
|
25
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
26
|
+
const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
|
|
27
27
|
const module_1 = require("module");
|
|
28
28
|
const moduleShorthand_1 = require("./moduleShorthand");
|
|
29
29
|
async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
30
|
-
const siteConfigPathUnresolved = customConfigFilePath
|
|
30
|
+
const siteConfigPathUnresolved = customConfigFilePath ?? utils_1.DEFAULT_CONFIG_FILE_NAME;
|
|
31
31
|
const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
|
|
32
32
|
? siteConfigPathUnresolved
|
|
33
33
|
: path_1.default.resolve(siteDir, siteConfigPathUnresolved);
|
|
@@ -36,7 +36,6 @@ async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
|
36
36
|
}
|
|
37
37
|
exports.loadSiteConfig = loadSiteConfig;
|
|
38
38
|
async function loadContext(siteDir, options = {}) {
|
|
39
|
-
var _a;
|
|
40
39
|
const { customOutDir, locale, customConfigFilePath } = options;
|
|
41
40
|
const generatedFilesDir = path_1.default.isAbsolute(utils_1.GENERATED_FILES_DIR_NAME)
|
|
42
41
|
? utils_1.GENERATED_FILES_DIR_NAME
|
|
@@ -63,10 +62,10 @@ async function loadContext(siteDir, options = {}) {
|
|
|
63
62
|
pathType: 'fs',
|
|
64
63
|
});
|
|
65
64
|
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
66
|
-
const codeTranslationFileContent = (
|
|
65
|
+
const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({
|
|
67
66
|
siteDir,
|
|
68
67
|
locale: i18n.currentLocale,
|
|
69
|
-
}))
|
|
68
|
+
})) ?? {};
|
|
70
69
|
// We only need key->message for code translations
|
|
71
70
|
const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
72
71
|
return {
|
|
@@ -77,7 +76,7 @@ async function loadContext(siteDir, options = {}) {
|
|
|
77
76
|
outDir,
|
|
78
77
|
baseUrl,
|
|
79
78
|
i18n,
|
|
80
|
-
ssrTemplate: ssrTemplate
|
|
79
|
+
ssrTemplate: ssrTemplate ?? ssr_html_template_1.default,
|
|
81
80
|
codeTranslations,
|
|
82
81
|
};
|
|
83
82
|
}
|
|
@@ -87,7 +86,6 @@ async function loadPluginConfigs(context) {
|
|
|
87
86
|
const { siteConfig, siteConfigPath } = context;
|
|
88
87
|
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
89
88
|
function normalizeShorthand(pluginConfig, pluginType) {
|
|
90
|
-
var _a;
|
|
91
89
|
if (typeof pluginConfig === 'string') {
|
|
92
90
|
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
|
|
93
91
|
}
|
|
@@ -95,7 +93,7 @@ async function loadPluginConfigs(context) {
|
|
|
95
93
|
typeof pluginConfig[0] === 'string') {
|
|
96
94
|
return [
|
|
97
95
|
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
|
|
98
|
-
|
|
96
|
+
pluginConfig[1] ?? {},
|
|
99
97
|
];
|
|
100
98
|
}
|
|
101
99
|
return pluginConfig;
|
|
@@ -167,8 +165,7 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
167
165
|
// processed by content plugins mdx loaders. This works, but a bit
|
|
168
166
|
// hacky... Not sure there's a way to handle that differently in webpack
|
|
169
167
|
function getMDXFallbackExcludedPaths() {
|
|
170
|
-
|
|
171
|
-
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
168
|
+
const rules = config?.module?.rules;
|
|
172
169
|
return rules.flatMap((rule) => {
|
|
173
170
|
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
174
171
|
return isMDXRule ? rule.include : [];
|
|
@@ -302,9 +299,8 @@ exports.load = load;
|
|
|
302
299
|
function checkDocusaurusPackagesVersion(siteMetadata) {
|
|
303
300
|
const { docusaurusVersion } = siteMetadata;
|
|
304
301
|
Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
|
|
305
|
-
var _a;
|
|
306
302
|
if (versionInfo.type === 'package' &&
|
|
307
|
-
|
|
303
|
+
versionInfo.name?.startsWith('@docusaurus/') &&
|
|
308
304
|
versionInfo.version &&
|
|
309
305
|
versionInfo.version !== docusaurusVersion) {
|
|
310
306
|
// should we throw instead?
|
|
@@ -9,13 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.loadPlugins = exports.sortConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const fs_extra_1 =
|
|
13
|
-
const path_1 =
|
|
14
|
-
const init_1 =
|
|
15
|
-
const logger_1 =
|
|
16
|
-
const lodash_1 =
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const init_1 = tslib_1.__importDefault(require("./init"));
|
|
15
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
16
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
17
17
|
const translations_1 = require("../translations/translations");
|
|
18
|
-
const applyRouteTrailingSlash_1 =
|
|
18
|
+
const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
|
|
19
19
|
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
20
20
|
// Sort the route config. This ensures that route with nested
|
|
21
21
|
// routes is always placed last.
|
|
@@ -45,8 +45,7 @@ function sortConfig(routeConfigs, baseUrl = '/') {
|
|
|
45
45
|
return a.path.localeCompare(b.path);
|
|
46
46
|
});
|
|
47
47
|
routeConfigs.forEach((routeConfig) => {
|
|
48
|
-
|
|
49
|
-
(_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));
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
exports.sortConfig = sortConfig;
|
|
@@ -65,10 +64,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
65
64
|
return { ...plugin, content };
|
|
66
65
|
}));
|
|
67
66
|
const contentLoadedTranslatedPlugins = await Promise.all(loadedPlugins.map(async (contentLoadedPlugin) => {
|
|
68
|
-
|
|
69
|
-
const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
|
|
67
|
+
const translationFiles = (await contentLoadedPlugin?.getTranslationFiles?.({
|
|
70
68
|
content: contentLoadedPlugin.content,
|
|
71
|
-
}))
|
|
69
|
+
})) ?? [];
|
|
72
70
|
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
73
71
|
locale: context.i18n.currentLocale,
|
|
74
72
|
siteDir: context.siteDir,
|
|
@@ -83,7 +81,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
83
81
|
const allContent = lodash_1.default.chain(loadedPlugins)
|
|
84
82
|
.groupBy((item) => item.name)
|
|
85
83
|
.mapValues((nameItems) => lodash_1.default.chain(nameItems)
|
|
86
|
-
.groupBy((item) =>
|
|
84
|
+
.groupBy((item) => item.options.id ?? utils_1.DEFAULT_PLUGIN_ID)
|
|
87
85
|
.mapValues((idItems) => idItems[0].content)
|
|
88
86
|
.value())
|
|
89
87
|
.value();
|
|
@@ -91,11 +89,10 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
91
89
|
const pluginsRouteConfigs = [];
|
|
92
90
|
const globalData = {};
|
|
93
91
|
await Promise.all(contentLoadedTranslatedPlugins.map(async ({ content, translationFiles, ...plugin }) => {
|
|
94
|
-
var _a, _b, _c;
|
|
95
92
|
if (!plugin.contentLoaded) {
|
|
96
93
|
return;
|
|
97
94
|
}
|
|
98
|
-
const pluginId =
|
|
95
|
+
const pluginId = plugin.options.id ?? utils_1.DEFAULT_PLUGIN_ID;
|
|
99
96
|
// plugins data files are namespaced by pluginName/pluginId
|
|
100
97
|
const dataDirRoot = path_1.default.join(context.generatedFilesDir, plugin.name);
|
|
101
98
|
const dataDir = path_1.default.join(dataDirRoot, pluginId);
|
|
@@ -117,8 +114,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
117
114
|
// - by plugin name
|
|
118
115
|
// - by plugin id (allow using multiple instances of the same plugin)
|
|
119
116
|
const setGlobalData = (data) => {
|
|
120
|
-
|
|
121
|
-
globalData[plugin.name] = (_a = globalData[plugin.name]) !== null && _a !== void 0 ? _a : {};
|
|
117
|
+
globalData[plugin.name] = globalData[plugin.name] ?? {};
|
|
122
118
|
globalData[plugin.name][pluginId] = data;
|
|
123
119
|
};
|
|
124
120
|
const actions = {
|
|
@@ -126,7 +122,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
126
122
|
createData,
|
|
127
123
|
setGlobalData,
|
|
128
124
|
};
|
|
129
|
-
const translatedContent =
|
|
125
|
+
const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
|
|
130
126
|
await plugin.contentLoaded({
|
|
131
127
|
content: translatedContent,
|
|
132
128
|
actions,
|
|
@@ -153,8 +149,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
153
149
|
// Apply each plugin one after the other to translate the theme config
|
|
154
150
|
function translateThemeConfig(untranslatedThemeConfig) {
|
|
155
151
|
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
156
|
-
|
|
157
|
-
const translatedThemeConfigSlice = (_a = plugin.translateThemeConfig) === null || _a === void 0 ? void 0 : _a.call(plugin, {
|
|
152
|
+
const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
|
|
158
153
|
themeConfig: currentThemeConfig,
|
|
159
154
|
translationFiles: plugin.translationFiles,
|
|
160
155
|
});
|
|
@@ -9,20 +9,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.normalizePluginConfigs = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const module_1 = require("module");
|
|
12
|
-
const import_fresh_1 =
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
14
|
const versions_1 = require("../versions");
|
|
15
15
|
const pluginIds_1 = require("./pluginIds");
|
|
16
16
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
17
17
|
async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
18
|
-
var _a, _b, _c, _d;
|
|
19
18
|
// plugins: ['./plugin']
|
|
20
19
|
if (typeof pluginConfig === 'string') {
|
|
21
20
|
const pluginModuleImport = pluginConfig;
|
|
22
21
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
23
22
|
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
24
23
|
return {
|
|
25
|
-
plugin:
|
|
24
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
26
25
|
options: {},
|
|
27
26
|
pluginModule: {
|
|
28
27
|
path: pluginModuleImport,
|
|
@@ -46,8 +45,8 @@ async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
46
45
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
47
46
|
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
48
47
|
return {
|
|
49
|
-
plugin:
|
|
50
|
-
options:
|
|
48
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
49
|
+
options: pluginConfig[1] ?? {},
|
|
51
50
|
pluginModule: {
|
|
52
51
|
path: pluginModuleImport,
|
|
53
52
|
module: pluginModule,
|
|
@@ -60,7 +59,7 @@ async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
60
59
|
if (typeof pluginConfig[0] === 'function') {
|
|
61
60
|
return {
|
|
62
61
|
plugin: pluginConfig[0],
|
|
63
|
-
options:
|
|
62
|
+
options: pluginConfig[1] ?? {},
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -71,18 +70,18 @@ async function normalizePluginConfigs(pluginConfigs, pluginRequire) {
|
|
|
71
70
|
}
|
|
72
71
|
exports.normalizePluginConfigs = normalizePluginConfigs;
|
|
73
72
|
function getOptionValidationFunction(normalizedPluginConfig) {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
75
73
|
if (normalizedPluginConfig.pluginModule) {
|
|
76
74
|
// support both commonjs and ES modules
|
|
77
|
-
return (
|
|
75
|
+
return (normalizedPluginConfig.pluginModule.module?.default?.validateOptions ??
|
|
76
|
+
normalizedPluginConfig.pluginModule.module?.validateOptions);
|
|
78
77
|
}
|
|
79
78
|
return normalizedPluginConfig.plugin.validateOptions;
|
|
80
79
|
}
|
|
81
80
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
82
|
-
var _a, _b;
|
|
83
81
|
if (normalizedPluginConfig.pluginModule) {
|
|
84
82
|
// support both commonjs and ES modules
|
|
85
|
-
return (
|
|
83
|
+
return (normalizedPluginConfig.pluginModule.module.default?.validateThemeConfig ??
|
|
84
|
+
normalizedPluginConfig.pluginModule.module.validateThemeConfig);
|
|
86
85
|
}
|
|
87
86
|
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
88
87
|
}
|
|
@@ -92,10 +91,9 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
92
91
|
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
93
92
|
const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, pluginRequire);
|
|
94
93
|
async function doGetPluginVersion(normalizedPluginConfig) {
|
|
95
|
-
var _a, _b;
|
|
96
94
|
// get plugin version
|
|
97
|
-
if (
|
|
98
|
-
const pluginPath = pluginRequire.resolve(
|
|
95
|
+
if (normalizedPluginConfig.pluginModule?.path) {
|
|
96
|
+
const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
|
|
99
97
|
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
100
98
|
}
|
|
101
99
|
return { type: 'local' };
|
|
@@ -111,7 +109,6 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
111
109
|
return context.siteConfig.themeConfig;
|
|
112
110
|
}
|
|
113
111
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
114
|
-
var _a;
|
|
115
112
|
const validateOptions = getOptionValidationFunction(normalizedPluginConfig);
|
|
116
113
|
if (validateOptions) {
|
|
117
114
|
return validateOptions({
|
|
@@ -123,7 +120,7 @@ async function initPlugins({ pluginConfigs, context, }) {
|
|
|
123
120
|
// as we don't go through the Joi schema that adds it
|
|
124
121
|
return {
|
|
125
122
|
...normalizedPluginConfig.options,
|
|
126
|
-
id:
|
|
123
|
+
id: normalizedPluginConfig.options.id ?? utils_1.DEFAULT_PLUGIN_ID,
|
|
127
124
|
};
|
|
128
125
|
}
|
|
129
126
|
async function initializePlugin(normalizedPluginConfig) {
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
// It is forbidden to have 2 plugins of the same name sharing the same id
|
|
14
14
|
// this is required to support multi-instance plugins without conflict
|
|
15
15
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
16
16
|
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
17
17
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
18
|
-
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) =>
|
|
18
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => p.options.id ?? utils_1.DEFAULT_PLUGIN_ID);
|
|
19
19
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
20
20
|
if (pluginInstancesWithId.length !== 1) {
|
|
21
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
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const module_1 = require("module");
|
|
11
|
-
const import_fresh_1 =
|
|
11
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
12
|
const moduleShorthand_1 = require("../moduleShorthand");
|
|
13
13
|
async function loadPresets(context) {
|
|
14
14
|
// We need to resolve presets from the perspective of the siteDir, since the
|
|
@@ -18,7 +18,6 @@ async function loadPresets(context) {
|
|
|
18
18
|
const unflatPlugins = [];
|
|
19
19
|
const unflatThemes = [];
|
|
20
20
|
presets.forEach((presetItem) => {
|
|
21
|
-
var _a;
|
|
22
21
|
let presetModuleImport;
|
|
23
22
|
let presetOptions = {};
|
|
24
23
|
if (typeof presetItem === 'string') {
|
|
@@ -32,7 +31,7 @@ async function loadPresets(context) {
|
|
|
32
31
|
}
|
|
33
32
|
const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
|
|
34
33
|
const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
|
|
35
|
-
const preset = (
|
|
34
|
+
const preset = (presetModule.default ?? presetModule)(context, presetOptions);
|
|
36
35
|
if (preset.plugins) {
|
|
37
36
|
unflatPlugins.push(preset.plugins);
|
|
38
37
|
}
|
package/lib/server/routes.js
CHANGED
|
@@ -45,15 +45,13 @@ const RoutesImportsCode = [
|
|
|
45
45
|
`import ComponentCreator from '@docusaurus/ComponentCreator';`,
|
|
46
46
|
].join('\n');
|
|
47
47
|
function isModule(value) {
|
|
48
|
-
var _a, _b;
|
|
49
48
|
if (typeof value === 'string') {
|
|
50
49
|
return true;
|
|
51
50
|
}
|
|
52
51
|
if (typeof value === 'object' &&
|
|
53
|
-
(
|
|
54
52
|
// eslint-disable-next-line no-underscore-dangle
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
value?.__import &&
|
|
54
|
+
value?.path) {
|
|
57
55
|
return true;
|
|
58
56
|
}
|
|
59
57
|
return false;
|
|
@@ -96,7 +94,7 @@ ${JSON.stringify(routeConfig)}`);
|
|
|
96
94
|
routePath: routeConfig.path.replace(/'/g, "\\'"),
|
|
97
95
|
routeHash,
|
|
98
96
|
exact,
|
|
99
|
-
subroutesCodeStrings: subroutes
|
|
97
|
+
subroutesCodeStrings: subroutes?.map(generateRouteCode),
|
|
100
98
|
props,
|
|
101
99
|
});
|
|
102
100
|
}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.sortAliases = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 =
|
|
12
|
-
const path_1 =
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const lodash_1 =
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
15
|
// Order of Webpack aliases is important because one alias can shadow another
|
|
16
16
|
// This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
|
|
17
17
|
// See https://github.com/facebook/docusaurus/pull/3922
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.loadPluginsThemeAliases = exports.loadThemeAliases = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
const alias_1 =
|
|
13
|
+
const alias_1 = tslib_1.__importStar(require("./alias"));
|
|
14
14
|
const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
|
|
15
15
|
async function loadThemeAliases(themePaths, userThemePaths) {
|
|
16
16
|
const aliases = {};
|