@docusaurus/core 2.0.0-beta.15 → 2.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +62 -40
- package/lib/babel/preset.d.ts +1 -2
- package/lib/babel/preset.js +5 -4
- package/lib/choosePort.js +22 -30
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +13 -8
- package/lib/client/LinksCollector.js +1 -1
- package/lib/client/PendingNavigation.d.ts +4 -4
- package/lib/client/PendingNavigation.js +4 -6
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +5 -7
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.js +6 -4
- package/lib/client/exports/BrowserOnly.d.ts +1 -2
- package/lib/client/exports/BrowserOnly.js +2 -3
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +1 -2
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.js +9 -12
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +13 -7
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +3 -2
- package/lib/client/exports/docusaurusContext.js +1 -1
- 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/useDocusaurusContext.d.ts +1 -2
- package/lib/client/exports/useDocusaurusContext.js +1 -2
- package/lib/client/flat.d.ts +1 -2
- package/lib/client/flat.js +1 -2
- package/lib/client/normalizeLocation.d.ts +2 -3
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -2
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +23 -19
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +21 -29
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +46 -114
- package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -5
- package/lib/commands/build.js +33 -34
- package/lib/commands/clear.js +23 -11
- package/lib/commands/deploy.js +12 -11
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +3 -2
- package/lib/commands/start.js +4 -4
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +13 -14
- package/lib/commands/writeTranslations.js +10 -7
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.js +30 -20
- package/lib/server/config.js +1 -1
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +32 -23
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/html-tags/htmlTags.js +1 -2
- package/lib/server/i18n.d.ts +0 -1
- package/lib/server/i18n.js +16 -26
- package/lib/server/index.d.ts +1 -1
- package/lib/server/index.js +17 -15
- package/lib/server/loadSetup.d.ts +1 -2
- package/lib/server/loadSetup.js +2 -2
- package/lib/server/moduleShorthand.js +1 -1
- package/lib/server/plugins/index.js +9 -9
- package/lib/server/plugins/init.d.ts +11 -1
- package/lib/server/plugins/init.js +23 -28
- package/lib/server/plugins/pluginIds.js +4 -3
- package/lib/server/presets/index.d.ts +2 -2
- package/lib/server/presets/index.js +3 -3
- package/lib/server/routes.js +13 -7
- package/lib/server/themes/alias.d.ts +1 -1
- package/lib/server/themes/alias.js +5 -6
- package/lib/server/themes/index.d.ts +2 -2
- package/lib/server/themes/index.js +10 -9
- package/lib/server/translations/translations.js +10 -11
- package/lib/server/translations/translationsExtractor.js +20 -19
- package/lib/server/versions/index.d.ts +2 -3
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +2 -2
- package/lib/webpack/base.js +30 -22
- package/lib/webpack/client.d.ts +1 -1
- package/lib/webpack/client.js +7 -4
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
- package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
- package/lib/webpack/server.d.ts +1 -1
- package/lib/webpack/server.js +6 -5
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +17 -37
- package/package.json +56 -56
- package/bin/beforeCli.js +0 -124
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -236
- package/lib/server/versions/__tests/index.test.js +0 -26
package/lib/index.js
CHANGED
|
@@ -6,22 +6,23 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./commands/build"));
|
|
12
|
+
exports.build = build_1.default;
|
|
13
|
+
const clear_1 = (0, tslib_1.__importDefault)(require("./commands/clear"));
|
|
14
|
+
exports.clear = clear_1.default;
|
|
15
|
+
const deploy_1 = (0, tslib_1.__importDefault)(require("./commands/deploy"));
|
|
16
|
+
exports.deploy = deploy_1.default;
|
|
17
|
+
const external_1 = (0, tslib_1.__importDefault)(require("./commands/external"));
|
|
18
|
+
exports.externalCommand = external_1.default;
|
|
19
|
+
const serve_1 = (0, tslib_1.__importDefault)(require("./commands/serve"));
|
|
20
|
+
exports.serve = serve_1.default;
|
|
21
|
+
const start_1 = (0, tslib_1.__importDefault)(require("./commands/start"));
|
|
22
|
+
exports.start = start_1.default;
|
|
23
|
+
const swizzle_1 = (0, tslib_1.__importDefault)(require("./commands/swizzle"));
|
|
24
|
+
exports.swizzle = swizzle_1.default;
|
|
25
|
+
const writeHeadingIds_1 = (0, tslib_1.__importDefault)(require("./commands/writeHeadingIds"));
|
|
26
|
+
exports.writeHeadingIds = writeHeadingIds_1.default;
|
|
27
|
+
const writeTranslations_1 = (0, tslib_1.__importDefault)(require("./commands/writeTranslations"));
|
|
28
|
+
exports.writeTranslations = writeTranslations_1.default;
|
|
@@ -10,10 +10,11 @@ exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenL
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const react_router_config_1 = require("react-router-config");
|
|
12
12
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const utils_2 = require("./utils");
|
|
16
16
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
17
|
+
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
17
18
|
function toReactRouterRoutes(routes) {
|
|
18
19
|
// @ts-expect-error: types incompatible???
|
|
19
20
|
return routes;
|
|
@@ -39,19 +40,21 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
39
40
|
}
|
|
40
41
|
return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The route defs can be recursive, and have a parent match-all route. We don't
|
|
45
|
+
* want to match broken links like /docs/brokenLink against /docs/*. For this
|
|
46
|
+
* reason, we only consider the "final routes", that do not have subroutes.
|
|
47
|
+
* We also need to remove the match all 404 route
|
|
48
|
+
*/
|
|
46
49
|
function filterIntermediateRoutes(routesInput) {
|
|
47
50
|
const routesWithout404 = routesInput.filter((route) => route.path !== '*');
|
|
48
51
|
return (0, utils_2.getAllFinalRoutes)(routesWithout404);
|
|
49
52
|
}
|
|
50
53
|
function getAllBrokenLinks({ allCollectedLinks, routes, }) {
|
|
51
54
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
|
52
|
-
const allBrokenLinks =
|
|
55
|
+
const allBrokenLinks = lodash_1.default.mapValues(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
|
|
53
56
|
// remove pages without any broken link
|
|
54
|
-
return
|
|
57
|
+
return lodash_1.default.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
55
58
|
}
|
|
56
59
|
exports.getAllBrokenLinks = getAllBrokenLinks;
|
|
57
60
|
function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
@@ -67,12 +70,14 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
67
70
|
.map(brokenLinkMessage)
|
|
68
71
|
.join('\n -> linking to ')}`;
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
/**
|
|
74
|
+
* If there's a broken link appearing very often, it is probably a broken link
|
|
75
|
+
* on the layout. Add an additional message in such case to help user figure
|
|
76
|
+
* this out. See https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
|
|
77
|
+
*/
|
|
73
78
|
function getLayoutBrokenLinksHelpMessage() {
|
|
74
79
|
const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
|
|
75
|
-
const countedBrokenLinks =
|
|
80
|
+
const countedBrokenLinks = lodash_1.default.countBy(flatList, (item) => item.brokenLink.link);
|
|
76
81
|
const FrequencyThreshold = 5; // Is this a good value?
|
|
77
82
|
const frequentLinks = Object.entries(countedBrokenLinks)
|
|
78
83
|
.filter(([, count]) => count >= FrequencyThreshold)
|
|
@@ -89,19 +94,18 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
89
94
|
`);
|
|
90
95
|
}
|
|
91
96
|
exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
|
|
92
|
-
function isExistingFile(filePath) {
|
|
97
|
+
async function isExistingFile(filePath) {
|
|
93
98
|
try {
|
|
94
|
-
return fs_extra_1.default.
|
|
99
|
+
return (await fs_extra_1.default.stat(filePath)).isFile();
|
|
95
100
|
}
|
|
96
|
-
catch
|
|
101
|
+
catch {
|
|
97
102
|
return false;
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
// If a file actually exist on the file system, we know the link is valid
|
|
101
106
|
// even if docusaurus does not know about this file, so we don't report it
|
|
102
107
|
async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
|
|
103
|
-
|
|
104
|
-
function linkFileExists(link) {
|
|
108
|
+
async function linkFileExists(link) {
|
|
105
109
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
|
106
110
|
const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
|
|
107
111
|
// -> /outDir/javadoc
|
|
@@ -112,17 +116,23 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
|
|
|
112
116
|
filePathsToTry.push(`${baseFilePath}.html`);
|
|
113
117
|
filePathsToTry.push(path_1.default.join(baseFilePath, 'index.html'));
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
for (const file of filePathsToTry) {
|
|
120
|
+
if (await isExistingFile(file)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
116
125
|
}
|
|
117
|
-
return (0, lodash_1.mapValues
|
|
126
|
+
return (0, combine_promises_1.default)(lodash_1.default.mapValues(allCollectedLinks, async (links) => (await Promise.all(links.map(async (link) => ((await linkFileExists(link)) ? '' : link)))).filter(Boolean)));
|
|
118
127
|
}
|
|
119
128
|
exports.filterExistingFileLinks = filterExistingFileLinks;
|
|
120
129
|
async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
|
|
121
130
|
if (onBrokenLinks === 'ignore') {
|
|
122
131
|
return;
|
|
123
132
|
}
|
|
124
|
-
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
125
|
-
//
|
|
133
|
+
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
134
|
+
// file system. It is not a broken link, it may simply be a link to an
|
|
135
|
+
// existing static file...
|
|
126
136
|
const allCollectedLinksFiltered = await filterExistingFileLinks({
|
|
127
137
|
allCollectedLinks,
|
|
128
138
|
baseUrl,
|
package/lib/server/config.js
CHANGED
|
@@ -11,7 +11,7 @@ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
|
11
11
|
const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
|
|
12
12
|
const configValidation_1 = require("./configValidation");
|
|
13
13
|
async function loadConfig(configPath) {
|
|
14
|
-
if (!fs_extra_1.default.
|
|
14
|
+
if (!(await fs_extra_1.default.pathExists(configPath))) {
|
|
15
15
|
throw new Error(`Config file at "${configPath}" not found.`);
|
|
16
16
|
}
|
|
17
17
|
const importedConfig = (0, import_fresh_1.default)(configPath);
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
import type { 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' | 'staticDirectories'>;
|
|
10
|
+
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories'>;
|
|
11
11
|
export declare const ConfigSchema: Joi.ObjectSchema<any>;
|
|
12
12
|
export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
|
|
@@ -7,8 +7,6 @@
|
|
|
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 tslib_1 = require("tslib");
|
|
11
|
-
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
10
|
const utils_1 = require("@docusaurus/utils");
|
|
13
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
14
12
|
const DEFAULT_I18N_LOCALE = 'en';
|
|
@@ -29,18 +27,30 @@ exports.DEFAULT_CONFIG = {
|
|
|
29
27
|
themeConfig: {},
|
|
30
28
|
titleDelimiter: '|',
|
|
31
29
|
noIndex: false,
|
|
30
|
+
tagline: '',
|
|
32
31
|
baseUrlIssueBanner: true,
|
|
33
32
|
staticDirectories: [utils_1.STATIC_DIR_NAME],
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
error
|
|
43
|
-
|
|
34
|
+
function createPluginSchema(theme = false) {
|
|
35
|
+
return (utils_validation_1.Joi.alternatives()
|
|
36
|
+
.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()
|
|
37
|
+
.ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
|
|
38
|
+
.length(2), utils_validation_1.Joi.bool().equal(false))
|
|
39
|
+
// @ts-expect-error: bad lib def, doesn't recognize an array of reports
|
|
40
|
+
.error((errors) => {
|
|
41
|
+
errors.forEach((error) => {
|
|
42
|
+
const validConfigExample = theme
|
|
43
|
+
? `Example valid theme config:
|
|
44
|
+
{
|
|
45
|
+
themes: [
|
|
46
|
+
["@docusaurus/theme-classic",options],
|
|
47
|
+
"./myTheme",
|
|
48
|
+
["./myTheme",{someOption: 42}],
|
|
49
|
+
function myTheme() { },
|
|
50
|
+
[function myTheme() { },options]
|
|
51
|
+
],
|
|
52
|
+
};`
|
|
53
|
+
: `Example valid plugin config:
|
|
44
54
|
{
|
|
45
55
|
plugins: [
|
|
46
56
|
["@docusaurus/plugin-content-docs",options],
|
|
@@ -49,12 +59,16 @@ Example valid plugin config:
|
|
|
49
59
|
function myPlugin() { },
|
|
50
60
|
[function myPlugin() { },options]
|
|
51
61
|
],
|
|
52
|
-
}
|
|
62
|
+
};`;
|
|
63
|
+
error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
|
|
64
|
+
${validConfigExample}
|
|
53
65
|
`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
|
|
66
|
+
});
|
|
67
|
+
return errors;
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
const PluginSchema = createPluginSchema(false);
|
|
71
|
+
const ThemeSchema = createPluginSchema(true);
|
|
58
72
|
const PresetSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required()).length(2));
|
|
59
73
|
const LocaleConfigSchema = utils_validation_1.Joi.object({
|
|
60
74
|
label: utils_validation_1.Joi.string(),
|
|
@@ -79,7 +93,7 @@ const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, hel
|
|
|
79
93
|
});
|
|
80
94
|
}
|
|
81
95
|
}
|
|
82
|
-
catch
|
|
96
|
+
catch { }
|
|
83
97
|
return value;
|
|
84
98
|
}, 'siteUrlCustomValidation');
|
|
85
99
|
// TODO move to @docusaurus/utils-validation
|
|
@@ -128,7 +142,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
128
142
|
type: utils_validation_1.Joi.string(),
|
|
129
143
|
}).unknown()),
|
|
130
144
|
clientModules: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
|
|
131
|
-
tagline: utils_validation_1.Joi.string().allow(''),
|
|
145
|
+
tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
|
|
132
146
|
titleDelimiter: utils_validation_1.Joi.string().default('|'),
|
|
133
147
|
noIndex: utils_validation_1.Joi.bool().default(false),
|
|
134
148
|
webpack: utils_validation_1.Joi.object({
|
|
@@ -146,11 +160,6 @@ function validateConfig(config) {
|
|
|
146
160
|
});
|
|
147
161
|
(0, utils_validation_1.printWarning)(warning);
|
|
148
162
|
if (error) {
|
|
149
|
-
(0, utils_validation_1.logValidationBugReportHint)();
|
|
150
|
-
if (utils_validation_1.isValidationDisabledEscapeHatch) {
|
|
151
|
-
logger_1.default.error(error.message);
|
|
152
|
-
return config;
|
|
153
|
-
}
|
|
154
163
|
const unknownFields = error.details.reduce((formattedError, err) => {
|
|
155
164
|
if (err.type === 'object.unknown') {
|
|
156
165
|
return `${formattedError}"${err.path}",`;
|
|
@@ -16,10 +16,8 @@ function getAllDuplicateRoutes(pluginsRouteConfigs) {
|
|
|
16
16
|
if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
19
|
+
seenRoutes[route] = true;
|
|
20
|
+
return false;
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
23
|
exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
|
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const html_tags_1 = (0, tslib_1.__importDefault)(require("html-tags"));
|
|
12
11
|
const void_1 = (0, tslib_1.__importDefault)(require("html-tags/void"));
|
|
13
12
|
const escape_html_1 = (0, tslib_1.__importDefault)(require("escape-html"));
|
|
14
13
|
function assertIsHtmlTagObject(val) {
|
|
15
|
-
if (
|
|
14
|
+
if (typeof val !== 'object' || !val) {
|
|
16
15
|
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
17
16
|
}
|
|
18
17
|
if (typeof val.tagName !== 'string') {
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
8
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
9
|
-
export declare function shouldWarnAboutNodeVersion(version: number, locales: string[]): boolean;
|
|
10
9
|
export declare function loadI18n(config: DocusaurusConfig, options?: {
|
|
11
10
|
locale?: string;
|
|
12
11
|
}): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.localizePath = exports.loadI18n = exports.
|
|
9
|
+
exports.localizePath = exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -24,12 +24,6 @@ function getDefaultLocaleConfig(locale) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
27
|
-
function shouldWarnAboutNodeVersion(version, locales) {
|
|
28
|
-
const isOnlyEnglish = locales.length === 1 && locales.includes('en');
|
|
29
|
-
const isOlderNodeVersion = version < 14;
|
|
30
|
-
return isOlderNodeVersion && !isOnlyEnglish;
|
|
31
|
-
}
|
|
32
|
-
exports.shouldWarnAboutNodeVersion = shouldWarnAboutNodeVersion;
|
|
33
27
|
async function loadI18n(config, options = {}) {
|
|
34
28
|
var _a;
|
|
35
29
|
const { i18n: i18nConfig } = config;
|
|
@@ -57,26 +51,22 @@ Note: Docusaurus only support running one locale at a time.`;
|
|
|
57
51
|
}
|
|
58
52
|
exports.loadI18n = loadI18n;
|
|
59
53
|
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (shouldLocalizePath) {
|
|
65
|
-
// FS paths need special care, for Windows support
|
|
66
|
-
if (pathType === 'fs') {
|
|
67
|
-
return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
|
|
68
|
-
}
|
|
69
|
-
// Url paths
|
|
70
|
-
else if (pathType === 'url') {
|
|
71
|
-
return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
|
|
72
|
-
}
|
|
73
|
-
// should never happen
|
|
74
|
-
else {
|
|
75
|
-
throw new Error(`Unhandled path type "${pathType}".`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
54
|
+
var _a;
|
|
55
|
+
const shouldLocalizePath =
|
|
56
|
+
// By default, we don't localize the path of defaultLocale
|
|
57
|
+
(_a = options.localizePath) !== null && _a !== void 0 ? _a : i18n.currentLocale !== i18n.defaultLocale;
|
|
58
|
+
if (!shouldLocalizePath) {
|
|
79
59
|
return originalPath;
|
|
80
60
|
}
|
|
61
|
+
// FS paths need special care, for Windows support
|
|
62
|
+
if (pathType === 'fs') {
|
|
63
|
+
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
64
|
+
}
|
|
65
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
66
|
+
if (pathType === 'url') {
|
|
67
|
+
return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
68
|
+
}
|
|
69
|
+
// should never happen
|
|
70
|
+
throw new Error(`Unhandled path type "${pathType}".`);
|
|
81
71
|
}
|
|
82
72
|
exports.localizePath = localizePath;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ export declare function loadSiteConfig({ siteDir, customConfigFilePath, }: {
|
|
|
19
19
|
siteConfigPath: string;
|
|
20
20
|
}>;
|
|
21
21
|
export declare function loadContext(siteDir: string, options?: LoadContextOptions): Promise<LoadContext>;
|
|
22
|
-
export declare function loadPluginConfigs(context: LoadContext): PluginConfig[]
|
|
22
|
+
export declare function loadPluginConfigs(context: LoadContext): Promise<PluginConfig[]>;
|
|
23
23
|
export declare function load(siteDir: string, options?: LoadContextOptions): Promise<Props>;
|
package/lib/server/index.js
CHANGED
|
@@ -22,7 +22,7 @@ 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 = require("lodash");
|
|
25
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
26
26
|
const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
|
|
27
27
|
const module_1 = require("module");
|
|
28
28
|
const moduleShorthand_1 = require("./moduleShorthand");
|
|
@@ -68,7 +68,7 @@ async function loadContext(siteDir, options = {}) {
|
|
|
68
68
|
locale: i18n.currentLocale,
|
|
69
69
|
}))) !== null && _a !== void 0 ? _a : {};
|
|
70
70
|
// We only need key->message for code translations
|
|
71
|
-
const codeTranslations =
|
|
71
|
+
const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
72
72
|
return {
|
|
73
73
|
siteDir,
|
|
74
74
|
generatedFilesDir,
|
|
@@ -82,8 +82,8 @@ async function loadContext(siteDir, options = {}) {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
exports.loadContext = loadContext;
|
|
85
|
-
function loadPluginConfigs(context) {
|
|
86
|
-
let { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
|
|
85
|
+
async function loadPluginConfigs(context) {
|
|
86
|
+
let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
|
|
87
87
|
const { siteConfig, siteConfigPath } = context;
|
|
88
88
|
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
89
89
|
function normalizeShorthand(pluginConfig, pluginType) {
|
|
@@ -150,10 +150,12 @@ function createBootstrapPlugin({ siteConfig, }) {
|
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
155
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
156
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
157
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
158
|
+
*/
|
|
157
159
|
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
158
160
|
return {
|
|
159
161
|
name: 'docusaurus-mdx-fallback-plugin',
|
|
@@ -161,9 +163,9 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
161
163
|
options: {},
|
|
162
164
|
version: { type: 'synthetic' },
|
|
163
165
|
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
-
// We need the mdx fallback loader to exclude files that were already
|
|
165
|
-
// This works, but a bit
|
|
166
|
-
// Not sure there's a way to handle that differently in webpack
|
|
166
|
+
// We need the mdx fallback loader to exclude files that were already
|
|
167
|
+
// processed by content plugins mdx loaders. This works, but a bit
|
|
168
|
+
// hacky... Not sure there's a way to handle that differently in webpack
|
|
167
169
|
function getMDXFallbackExcludedPaths() {
|
|
168
170
|
var _a;
|
|
169
171
|
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
@@ -176,7 +178,7 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
176
178
|
module: {
|
|
177
179
|
rules: [
|
|
178
180
|
{
|
|
179
|
-
test:
|
|
181
|
+
test: /\.mdx?$/i,
|
|
180
182
|
exclude: getMDXFallbackExcludedPaths(),
|
|
181
183
|
use: [
|
|
182
184
|
getJSLoader({ isServer }),
|
|
@@ -203,7 +205,7 @@ async function load(siteDir, options = {}) {
|
|
|
203
205
|
const context = await loadContext(siteDir, options);
|
|
204
206
|
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
|
|
205
207
|
// Plugins.
|
|
206
|
-
const pluginConfigs = loadPluginConfigs(context);
|
|
208
|
+
const pluginConfigs = await loadPluginConfigs(context);
|
|
207
209
|
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
|
|
208
210
|
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
209
211
|
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
@@ -250,8 +252,8 @@ ${Object.keys(registry)
|
|
|
250
252
|
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
251
253
|
// Version metadata.
|
|
252
254
|
const siteMetadata = {
|
|
253
|
-
docusaurusVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json')),
|
|
254
|
-
siteVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
|
|
255
|
+
docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
|
|
256
|
+
siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
|
|
255
257
|
pluginVersions: {},
|
|
256
258
|
};
|
|
257
259
|
plugins
|
package/lib/server/loadSetup.js
CHANGED
|
@@ -10,7 +10,7 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
11
11
|
const index_1 = require("./index");
|
|
12
12
|
// Helper methods to setup dummy/fake projects.
|
|
13
|
-
|
|
13
|
+
async function loadSetup(name) {
|
|
14
14
|
const fixtures = path_1.default.join(__dirname, '__tests__', '__fixtures__');
|
|
15
15
|
const simpleSite = path_1.default.join(fixtures, 'simple-site');
|
|
16
16
|
const customSite = path_1.default.join(fixtures, 'custom-site');
|
|
@@ -21,5 +21,5 @@ const loadSetup = async (name) => {
|
|
|
21
21
|
default:
|
|
22
22
|
return (0, index_1.load)(simpleSite);
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
exports.default = loadSetup;
|
|
@@ -13,7 +13,7 @@ function getNamePatterns(moduleName, moduleType) {
|
|
|
13
13
|
if (!moduleName.includes('/')) {
|
|
14
14
|
return [`${moduleName}/docusaurus-${moduleType}`];
|
|
15
15
|
}
|
|
16
|
-
const [scope, packageName] = moduleName.split(/\/(
|
|
16
|
+
const [scope, packageName] = moduleName.split(/\/(?<rest>.*)/);
|
|
17
17
|
return [
|
|
18
18
|
`${scope}/${packageName}`,
|
|
19
19
|
`${scope}/docusaurus-${moduleType}-${packageName}`,
|
|
@@ -13,7 +13,7 @@ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
|
13
13
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
14
|
const init_1 = (0, tslib_1.__importDefault)(require("./init"));
|
|
15
15
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
16
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
17
17
|
const translations_1 = require("../translations/translations");
|
|
18
18
|
const applyRouteTrailingSlash_1 = (0, tslib_1.__importDefault)(require("./applyRouteTrailingSlash"));
|
|
19
19
|
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
@@ -57,9 +57,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
57
57
|
context,
|
|
58
58
|
});
|
|
59
59
|
// 2. Plugin Lifecycle - loadContent.
|
|
60
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
-
// We could change this in future if there are plugins which
|
|
62
|
-
// run in certain order or depend on others for data.
|
|
60
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
62
|
+
// need to run in certain order or depend on others for data.
|
|
63
63
|
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
64
64
|
const content = plugin.loadContent ? await plugin.loadContent() : null;
|
|
65
65
|
return { ...plugin, content };
|
|
@@ -80,9 +80,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
80
80
|
translationFiles: localizedTranslationFiles,
|
|
81
81
|
};
|
|
82
82
|
}));
|
|
83
|
-
const allContent =
|
|
83
|
+
const allContent = lodash_1.default.chain(loadedPlugins)
|
|
84
84
|
.groupBy((item) => item.name)
|
|
85
|
-
.mapValues((nameItems) =>
|
|
85
|
+
.mapValues((nameItems) => lodash_1.default.chain(nameItems)
|
|
86
86
|
.groupBy((item) => { var _a; return (_a = item.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; })
|
|
87
87
|
.mapValues((idItems) => idItems[0].content)
|
|
88
88
|
.value())
|
|
@@ -134,9 +134,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
134
134
|
});
|
|
135
135
|
}));
|
|
136
136
|
// 4. Plugin Lifecycle - routesLoaded.
|
|
137
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
-
// We could change this in future if there are plugins which
|
|
139
|
-
// run in certain order or depend on others for data.
|
|
137
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
139
|
+
// need to run in certain order or depend on others for data.
|
|
140
140
|
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
141
141
|
if (!plugin.routesLoaded) {
|
|
142
142
|
return null;
|
|
@@ -4,7 +4,17 @@
|
|
|
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
|
-
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import type { ImportedPluginModule, LoadContext, PluginModule, PluginConfig, PluginOptions, InitializedPlugin } from '@docusaurus/types';
|
|
9
|
+
export declare type NormalizedPluginConfig = {
|
|
10
|
+
plugin: PluginModule;
|
|
11
|
+
options: PluginOptions;
|
|
12
|
+
pluginModule?: {
|
|
13
|
+
path: string;
|
|
14
|
+
module: ImportedPluginModule;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare function normalizePluginConfigs(pluginConfigs: PluginConfig[], pluginRequire: NodeRequire): Promise<NormalizedPluginConfig[]>;
|
|
8
18
|
export default function initPlugins({ pluginConfigs, context, }: {
|
|
9
19
|
pluginConfigs: PluginConfig[];
|
|
10
20
|
context: LoadContext;
|