@docusaurus/core 2.0.0-beta.12faed89d → 2.0.0-beta.13
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.js +33 -8
- package/bin/docusaurus.js +36 -40
- package/lib/.tsbuildinfo +1 -1
- package/lib/babel/preset.d.ts +6 -0
- package/lib/babel/preset.js +3 -3
- package/lib/choosePort.js +12 -13
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/.tsbuildinfo +1 -1
- package/lib/client/App.js +12 -22
- package/lib/client/LinksCollector.d.ts +2 -2
- package/lib/client/LinksCollector.js +4 -8
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
- package/lib/client/client-lifecycles-dispatcher.js +0 -2
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +11 -19
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Interpolate.js +12 -15
- package/lib/client/exports/Link.js +9 -9
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +13 -9
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +21 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/useBaseUrl.js +2 -4
- package/lib/client/exports/useDocusaurusContext.js +2 -7
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
- package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
- package/lib/client/flat.d.ts +2 -1
- package/lib/client/flat.js +7 -9
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +15 -31
- package/lib/client/theme-fallback/Error/index.js +47 -0
- package/lib/client/theme-fallback/Layout/index.js +1 -1
- package/lib/client/theme-fallback/Loading/index.js +2 -2
- package/lib/client/theme-fallback/Root/index.js +1 -3
- package/lib/commands/build.js +34 -37
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +9 -9
- package/lib/commands/commandUtils.d.ts +6 -0
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +3 -0
- package/lib/commands/deploy.js +90 -53
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +13 -13
- package/lib/commands/start.js +82 -72
- package/lib/commands/swizzle.js +34 -34
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +32 -32
- package/lib/commands/writeTranslations.js +31 -11
- package/lib/server/brokenLinks.js +13 -17
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +11 -6
- package/lib/server/duplicateRoutes.js +8 -2
- package/lib/server/html-tags/htmlTags.js +5 -6
- package/lib/server/html-tags/index.js +2 -2
- package/lib/server/i18n.js +16 -13
- package/lib/server/index.js +128 -58
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +42 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +1 -1
- package/lib/server/plugins/index.js +24 -20
- package/lib/server/plugins/init.js +9 -12
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/presets/index.js +12 -12
- package/lib/server/routes.js +9 -11
- package/lib/server/themes/alias.d.ts +1 -0
- package/lib/server/themes/alias.js +21 -12
- package/lib/server/themes/index.d.ts +1 -1
- package/lib/server/themes/index.js +22 -23
- package/lib/server/translations/translations.d.ts +6 -0
- package/lib/server/translations/translations.js +15 -17
- package/lib/server/translations/translationsExtractor.d.ts +7 -1
- package/lib/server/translations/translationsExtractor.js +65 -56
- package/lib/server/utils.d.ts +8 -2
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__tests/index.test.js +5 -5
- package/lib/server/versions/index.js +6 -6
- package/lib/webpack/base.js +14 -16
- package/lib/webpack/client.js +8 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
- package/lib/webpack/plugins/LogPlugin.js +5 -6
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.js +9 -9
- package/lib/webpack/utils.d.ts +0 -22
- package/lib/webpack/utils.js +26 -125
- package/package.json +55 -50
- package/tsconfig.client.json +1 -2
- package/tsconfig.json +5 -4
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- 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
|
@@ -1,11 +1,31 @@
|
|
|
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
9
|
const tslib_1 = require("tslib");
|
|
10
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
4
11
|
const server_1 = require("../server");
|
|
5
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
12
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
6
13
|
const translations_1 = require("../server/translations/translations");
|
|
7
14
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
8
15
|
const utils_1 = require("../webpack/utils");
|
|
16
|
+
// This is a hack, so that @docusaurus/theme-common translations are extracted!
|
|
17
|
+
// A theme doesn't have a way to express that one of its dependency (like @docusaurus/theme-common) also has translations to extract
|
|
18
|
+
// Instead of introducing a new lifecycle (like plugin.getThemeTranslationPaths() ?)
|
|
19
|
+
// We just make an exception and assume that Docusaurus user is using an official theme
|
|
20
|
+
async function getExtraSourceCodeFilePaths() {
|
|
21
|
+
try {
|
|
22
|
+
const themeCommonSourceDir = path_1.default.dirname(require.resolve('@docusaurus/theme-common/lib'));
|
|
23
|
+
return (0, translationsExtractor_1.globSourceCodeFilePaths)([themeCommonSourceDir]);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
27
|
+
}
|
|
28
|
+
}
|
|
9
29
|
async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }) {
|
|
10
30
|
var _a;
|
|
11
31
|
if (plugin.getTranslationFiles) {
|
|
@@ -14,7 +34,7 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
14
34
|
content,
|
|
15
35
|
});
|
|
16
36
|
await Promise.all(translationFiles.map(async (translationFile) => {
|
|
17
|
-
await translations_1.writePluginTranslations({
|
|
37
|
+
await (0, translations_1.writePluginTranslations)({
|
|
18
38
|
siteDir,
|
|
19
39
|
plugin,
|
|
20
40
|
translationFile,
|
|
@@ -26,12 +46,12 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
26
46
|
}
|
|
27
47
|
async function writeTranslations(siteDir, options) {
|
|
28
48
|
var _a;
|
|
29
|
-
const context = await server_1.loadContext(siteDir, {
|
|
49
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
30
50
|
customConfigFilePath: options.config,
|
|
31
51
|
locale: options.locale,
|
|
32
52
|
});
|
|
33
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
34
|
-
const plugins = init_1.default({
|
|
53
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
54
|
+
const plugins = (0, init_1.default)({
|
|
35
55
|
pluginConfigs,
|
|
36
56
|
context,
|
|
37
57
|
});
|
|
@@ -40,17 +60,17 @@ async function writeTranslations(siteDir, options) {
|
|
|
40
60
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
41
61
|
Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
42
62
|
}
|
|
43
|
-
const babelOptions = utils_1.getBabelOptions({
|
|
63
|
+
const babelOptions = (0, utils_1.getBabelOptions)({
|
|
44
64
|
isServer: true,
|
|
45
|
-
babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
|
|
65
|
+
babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
46
66
|
});
|
|
47
|
-
const extractedCodeTranslations = await translationsExtractor_1.extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions);
|
|
48
|
-
const defaultCodeMessages = await translations_1.getPluginsDefaultCodeTranslationMessages(plugins);
|
|
49
|
-
const codeTranslations = translations_1.applyDefaultCodeTranslations({
|
|
67
|
+
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
|
|
68
|
+
const defaultCodeMessages = await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins);
|
|
69
|
+
const codeTranslations = (0, translations_1.applyDefaultCodeTranslations)({
|
|
50
70
|
extractedCodeTranslations,
|
|
51
71
|
defaultCodeMessages,
|
|
52
72
|
});
|
|
53
|
-
await translations_1.writeCodeTranslations({ siteDir, locale }, codeTranslations, options);
|
|
73
|
+
await (0, translations_1.writeCodeTranslations)({ siteDir, locale }, codeTranslations, options);
|
|
54
74
|
await Promise.all(plugins.map(async (plugin) => {
|
|
55
75
|
await writePluginTranslationFiles({ siteDir, plugin, locale, options });
|
|
56
76
|
}));
|
|
@@ -9,12 +9,12 @@ 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 resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
13
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathname"));
|
|
13
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
const utils_2 = require("./utils");
|
|
17
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
18
18
|
function toReactRouterRoutes(routes) {
|
|
19
19
|
// @ts-expect-error: types incompatible???
|
|
20
20
|
return routes;
|
|
@@ -29,12 +29,12 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
29
29
|
// we must resolve the links before using matchRoutes
|
|
30
30
|
// resolvePathname is used internally by ReactRouter
|
|
31
31
|
function resolveLink(link) {
|
|
32
|
-
const resolvedLink = resolve_pathname_1.default(onlyPathname(link), pagePath);
|
|
32
|
+
const resolvedLink = (0, resolve_pathname_1.default)(onlyPathname(link), pagePath);
|
|
33
33
|
return { link, resolvedLink };
|
|
34
34
|
}
|
|
35
35
|
function isBrokenLink(link) {
|
|
36
36
|
const matchedRoutes = [link, decodeURI(link)]
|
|
37
|
-
.map((l) => react_router_config_1.matchRoutes(toReactRouterRoutes(routes), l))
|
|
37
|
+
.map((l) => (0, react_router_config_1.matchRoutes)(toReactRouterRoutes(routes), l))
|
|
38
38
|
.reduce((prev, cur) => prev.concat(cur));
|
|
39
39
|
return matchedRoutes.length === 0;
|
|
40
40
|
}
|
|
@@ -46,15 +46,13 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
46
46
|
// We also need to remove the match all 404 route
|
|
47
47
|
function filterIntermediateRoutes(routesInput) {
|
|
48
48
|
const routesWithout404 = routesInput.filter((route) => route.path !== '*');
|
|
49
|
-
return utils_2.getAllFinalRoutes(routesWithout404);
|
|
49
|
+
return (0, utils_2.getAllFinalRoutes)(routesWithout404);
|
|
50
50
|
}
|
|
51
51
|
function getAllBrokenLinks({ allCollectedLinks, routes, }) {
|
|
52
52
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
|
53
|
-
const allBrokenLinks = lodash_1.mapValues(allCollectedLinks, (pageLinks, pagePath) => {
|
|
54
|
-
return getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes });
|
|
55
|
-
});
|
|
53
|
+
const allBrokenLinks = (0, lodash_1.mapValues)(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
|
|
56
54
|
// remove pages without any broken link
|
|
57
|
-
return lodash_1.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
55
|
+
return (0, lodash_1.pickBy)(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
58
56
|
}
|
|
59
57
|
exports.getAllBrokenLinks = getAllBrokenLinks;
|
|
60
58
|
function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
@@ -74,8 +72,8 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
74
72
|
// Add an additional message in such case to help user figure this out.
|
|
75
73
|
// see https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
|
|
76
74
|
function getLayoutBrokenLinksHelpMessage() {
|
|
77
|
-
const flatList =
|
|
78
|
-
const countedBrokenLinks = lodash_1.countBy(flatList, (item) => item.brokenLink.link);
|
|
75
|
+
const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
|
|
76
|
+
const countedBrokenLinks = (0, lodash_1.countBy)(flatList, (item) => item.brokenLink.link);
|
|
79
77
|
const FrequencyThreshold = 5; // Is this a good value?
|
|
80
78
|
const frequentLinks = Object.entries(countedBrokenLinks)
|
|
81
79
|
.filter(([, count]) => count >= FrequencyThreshold)
|
|
@@ -106,7 +104,7 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
|
|
|
106
104
|
// not easy to make this async :'(
|
|
107
105
|
function linkFileExists(link) {
|
|
108
106
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
|
109
|
-
const baseFilePath = utils_1.removeSuffix(`${outDir}/${utils_1.removePrefix(link, baseUrl)}`, '/');
|
|
107
|
+
const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
|
|
110
108
|
// -> /outDir/javadoc
|
|
111
109
|
// -> /outDir/javadoc.html
|
|
112
110
|
// -> /outDir/javadoc/index.html
|
|
@@ -117,9 +115,7 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
|
|
|
117
115
|
}
|
|
118
116
|
return filePathsToTry.some(isExistingFile);
|
|
119
117
|
}
|
|
120
|
-
return lodash_1.mapValues(allCollectedLinks, (links) =>
|
|
121
|
-
return links.filter((link) => !linkFileExists(link));
|
|
122
|
-
});
|
|
118
|
+
return (0, lodash_1.mapValues)(allCollectedLinks, (links) => links.filter((link) => !linkFileExists(link)));
|
|
123
119
|
}
|
|
124
120
|
exports.filterExistingFileLinks = filterExistingFileLinks;
|
|
125
121
|
async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
|
|
@@ -139,7 +135,7 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
|
|
|
139
135
|
});
|
|
140
136
|
const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
|
|
141
137
|
if (errorMessage) {
|
|
142
|
-
utils_1.reportMessage(errorMessage, onBrokenLinks);
|
|
138
|
+
(0, utils_1.reportMessage)(errorMessage, onBrokenLinks);
|
|
143
139
|
}
|
|
144
140
|
}
|
|
145
141
|
exports.handleBrokenLinks = handleBrokenLinks;
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
function loadClientModules(plugins) {
|
|
10
|
-
return []
|
|
11
|
-
.map((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; })
|
|
12
|
-
.filter(Boolean));
|
|
10
|
+
return plugins.flatMap((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; });
|
|
13
11
|
}
|
|
14
12
|
exports.default = loadClientModules;
|
package/lib/server/config.js
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
-
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
10
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
11
|
+
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
12
12
|
const configValidation_1 = require("./configValidation");
|
|
13
13
|
function loadConfig(configPath) {
|
|
14
14
|
if (!fs_extra_1.default.existsSync(configPath)) {
|
|
15
15
|
throw new Error(`Config file at "${configPath}" not found.`);
|
|
16
16
|
}
|
|
17
|
-
const loadedConfig = import_fresh_1.default(configPath);
|
|
18
|
-
return configValidation_1.validateConfig(loadedConfig);
|
|
17
|
+
const loadedConfig = (0, import_fresh_1.default)(configPath);
|
|
18
|
+
return (0, configValidation_1.validateConfig)(loadedConfig);
|
|
19
19
|
}
|
|
20
20
|
exports.default = loadConfig;
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
import { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
|
|
8
8
|
import { Joi } from '@docusaurus/utils-validation';
|
|
9
9
|
export declare const DEFAULT_I18N_CONFIG: I18nConfig;
|
|
10
|
-
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner'>;
|
|
10
|
+
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner' | 'staticDirectories'>;
|
|
11
11
|
export declare const ConfigSchema: Joi.ObjectSchema<any>;
|
|
12
12
|
export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
|
|
10
|
-
const
|
|
10
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
12
|
const DEFAULT_I18N_LOCALE = 'en';
|
|
13
13
|
exports.DEFAULT_I18N_CONFIG = {
|
|
@@ -28,6 +28,7 @@ exports.DEFAULT_CONFIG = {
|
|
|
28
28
|
titleDelimiter: '|',
|
|
29
29
|
noIndex: false,
|
|
30
30
|
baseUrlIssueBanner: true,
|
|
31
|
+
staticDirectories: [utils_1.STATIC_DIR_NAME],
|
|
31
32
|
};
|
|
32
33
|
const PluginSchema = utils_validation_1.Joi.alternatives()
|
|
33
34
|
.try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array().ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required()), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
|
|
@@ -68,7 +69,7 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
|
68
69
|
})
|
|
69
70
|
.optional()
|
|
70
71
|
.default(exports.DEFAULT_I18N_CONFIG);
|
|
71
|
-
const SiteUrlSchema = utils_validation_1.URISchema.required().custom(
|
|
72
|
+
const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, helpers) => {
|
|
72
73
|
try {
|
|
73
74
|
const { pathname } = new URL(value);
|
|
74
75
|
if (pathname !== '/') {
|
|
@@ -84,7 +85,7 @@ const SiteUrlSchema = utils_validation_1.URISchema.required().custom(function (v
|
|
|
84
85
|
exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
85
86
|
baseUrl: utils_validation_1.Joi.string()
|
|
86
87
|
.required()
|
|
87
|
-
.regex(
|
|
88
|
+
.regex(/\/$/m)
|
|
88
89
|
.message('{{#label}} must be a string with a trailing slash.'),
|
|
89
90
|
baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
|
|
90
91
|
favicon: utils_validation_1.Joi.string().optional(),
|
|
@@ -102,7 +103,11 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
102
103
|
.equal('ignore', 'log', 'warn', 'error', 'throw')
|
|
103
104
|
.default(exports.DEFAULT_CONFIG.onDuplicateRoutes),
|
|
104
105
|
organizationName: utils_validation_1.Joi.string().allow(''),
|
|
106
|
+
staticDirectories: utils_validation_1.Joi.array()
|
|
107
|
+
.items(utils_validation_1.Joi.string())
|
|
108
|
+
.default(exports.DEFAULT_CONFIG.staticDirectories),
|
|
105
109
|
projectName: utils_validation_1.Joi.string().allow(''),
|
|
110
|
+
deploymentBranch: utils_validation_1.Joi.string().optional(),
|
|
106
111
|
customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
|
|
107
112
|
githubHost: utils_validation_1.Joi.string(),
|
|
108
113
|
plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
|
|
@@ -138,9 +143,9 @@ function validateConfig(config) {
|
|
|
138
143
|
const { error, warning, value } = exports.ConfigSchema.validate(config, {
|
|
139
144
|
abortEarly: false,
|
|
140
145
|
});
|
|
141
|
-
utils_validation_1.printWarning(warning);
|
|
146
|
+
(0, utils_validation_1.printWarning)(warning);
|
|
142
147
|
if (error) {
|
|
143
|
-
utils_validation_1.logValidationBugReportHint();
|
|
148
|
+
(0, utils_validation_1.logValidationBugReportHint)();
|
|
144
149
|
if (utils_validation_1.isValidationDisabledEscapeHatch) {
|
|
145
150
|
console.error(error);
|
|
146
151
|
return config;
|
|
@@ -155,7 +160,7 @@ function validateConfig(config) {
|
|
|
155
160
|
? `${accumulatedErr}${err.message}\n`
|
|
156
161
|
: accumulatedErr, '');
|
|
157
162
|
formattedError = unknownFields
|
|
158
|
-
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${
|
|
163
|
+
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/docusaurus.config.js/#customfields`
|
|
159
164
|
: formattedError;
|
|
160
165
|
throw new Error(formattedError);
|
|
161
166
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
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
9
|
exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getAllDuplicateRoutes = void 0;
|
|
4
10
|
const utils_1 = require("@docusaurus/utils");
|
|
5
11
|
const utils_2 = require("./utils");
|
|
6
12
|
function getAllDuplicateRoutes(pluginsRouteConfigs) {
|
|
7
|
-
const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
13
|
+
const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
8
14
|
const seenRoutes = {};
|
|
9
15
|
return allRoutes.filter((route) => {
|
|
10
16
|
if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
|
|
@@ -32,7 +38,7 @@ function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
|
|
|
32
38
|
const message = getDuplicateRoutesMessage(duplicatePaths);
|
|
33
39
|
if (message) {
|
|
34
40
|
const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
|
|
35
|
-
utils_1.reportMessage(finalMessage, onDuplicateRoutes);
|
|
41
|
+
(0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
exports.handleDuplicateRoutes = handleDuplicateRoutes;
|
|
@@ -8,14 +8,13 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
12
|
-
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
13
|
-
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
11
|
+
const html_tags_1 = (0, tslib_1.__importDefault)(require("html-tags"));
|
|
12
|
+
const void_1 = (0, tslib_1.__importDefault)(require("html-tags/void"));
|
|
13
|
+
const escape_html_1 = (0, tslib_1.__importDefault)(require("escape-html"));
|
|
14
14
|
function assertIsHtmlTagObject(val) {
|
|
15
|
-
if (!lodash_1.isPlainObject(val)) {
|
|
15
|
+
if (!(0, lodash_1.isPlainObject)(val)) {
|
|
16
16
|
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
17
17
|
}
|
|
18
|
-
// @ts-expect-error: If tagName doesn't exist, it will throw.
|
|
19
18
|
if (typeof val.tagName !== 'string') {
|
|
20
19
|
throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
|
|
21
20
|
}
|
|
@@ -33,7 +32,7 @@ function htmlTagObjectToString(tagDefinition) {
|
|
|
33
32
|
if (tagAttributes[attributeName] === true) {
|
|
34
33
|
return attributeName;
|
|
35
34
|
}
|
|
36
|
-
return `${attributeName}="${escape_html_1.default(tagAttributes[attributeName])}"`;
|
|
35
|
+
return `${attributeName}="${(0, escape_html_1.default)(tagAttributes[attributeName])}"`;
|
|
37
36
|
});
|
|
38
37
|
return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${(!isVoidTag && tagDefinition.innerHTML) || ''}${isVoidTag ? '' : `</${tagDefinition.tagName}>`}`;
|
|
39
38
|
}
|
|
@@ -8,9 +8,9 @@
|
|
|
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 = tslib_1.__importDefault(require("./htmlTags"));
|
|
11
|
+
const htmlTags_1 = (0, tslib_1.__importDefault)(require("./htmlTags"));
|
|
12
12
|
function toString(val) {
|
|
13
|
-
return typeof val === 'string' ? val : htmlTags_1.default(val);
|
|
13
|
+
return typeof val === 'string' ? val : (0, htmlTags_1.default)(val);
|
|
14
14
|
}
|
|
15
15
|
function createHtmlTagsString(tags) {
|
|
16
16
|
return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
|
package/lib/server/i18n.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
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
9
|
exports.localizePath = exports.loadI18n = exports.shouldWarnAboutNodeVersion = exports.getDefaultLocaleConfig = void 0;
|
|
4
10
|
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
6
12
|
const utils_1 = require("@docusaurus/utils");
|
|
7
13
|
const rtl_detect_1 = require("rtl-detect");
|
|
8
|
-
const
|
|
9
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
10
15
|
function getDefaultLocaleLabel(locale) {
|
|
11
16
|
// Intl.DisplayNames is ES2021 - Node14+
|
|
12
17
|
// https://v8.dev/features/intl-displaynames
|
|
13
|
-
// @ts-expect-error: wait for TS support of ES2021 feature
|
|
14
18
|
if (typeof Intl.DisplayNames !== 'undefined') {
|
|
15
|
-
|
|
16
|
-
return
|
|
19
|
+
const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
|
|
20
|
+
return (languageName.charAt(0).toLocaleUpperCase(locale) +
|
|
21
|
+
languageName.substring(1));
|
|
17
22
|
}
|
|
18
23
|
return locale;
|
|
19
24
|
}
|
|
20
25
|
function getDefaultLocaleConfig(locale) {
|
|
21
26
|
return {
|
|
22
27
|
label: getDefaultLocaleLabel(locale),
|
|
23
|
-
direction: rtl_detect_1.getLangDir(locale),
|
|
28
|
+
direction: (0, rtl_detect_1.getLangDir)(locale),
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
31
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
@@ -41,8 +46,8 @@ Note: Docusaurus only support running one locale at a time.`));
|
|
|
41
46
|
const locales = i18nConfig.locales.includes(currentLocale)
|
|
42
47
|
? i18nConfig.locales
|
|
43
48
|
: i18nConfig.locales.concat(currentLocale);
|
|
44
|
-
if (shouldWarnAboutNodeVersion(
|
|
45
|
-
console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use Node.js 14 or later (instead of ${
|
|
49
|
+
if (shouldWarnAboutNodeVersion(utils_1.NODE_MAJOR_VERSION, locales)) {
|
|
50
|
+
console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use Node.js 14 or later (instead of ${utils_1.NODE_MAJOR_VERSION}).`));
|
|
46
51
|
}
|
|
47
52
|
function getLocaleConfig(locale) {
|
|
48
53
|
return {
|
|
@@ -50,9 +55,7 @@ Note: Docusaurus only support running one locale at a time.`));
|
|
|
50
55
|
...i18nConfig.localeConfigs[locale],
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
|
-
const localeConfigs = locales.reduce((acc, locale) => {
|
|
54
|
-
return { ...acc, [locale]: getLocaleConfig(locale) };
|
|
55
|
-
}, {});
|
|
58
|
+
const localeConfigs = locales.reduce((acc, locale) => ({ ...acc, [locale]: getLocaleConfig(locale) }), {});
|
|
56
59
|
return {
|
|
57
60
|
defaultLocale: i18nConfig.defaultLocale,
|
|
58
61
|
locales,
|
|
@@ -73,7 +76,7 @@ function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
|
73
76
|
}
|
|
74
77
|
// Url paths
|
|
75
78
|
else if (pathType === 'url') {
|
|
76
|
-
return utils_1.normalizeUrl([originalPath, '/', i18n.currentLocale, '/']);
|
|
79
|
+
return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
|
|
77
80
|
}
|
|
78
81
|
// should never happen
|
|
79
82
|
else {
|