@docusaurus/core 2.0.0-beta.ff31de0ff → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/docusaurus.mjs +221 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +44 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +8 -15
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +109 -136
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +102 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +40 -20
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +111 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +48 -28
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +5 -3
- package/lib/server/configValidation.js +105 -44
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -6
- package/lib/server/index.js +86 -173
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +10 -10
- package/lib/server/plugins/index.js +76 -128
- package/lib/server/plugins/init.d.ts +6 -9
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +6 -2
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +16 -22
- package/lib/server/translations/translations.js +41 -73
- package/lib/server/translations/translationsExtractor.d.ts +10 -5
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +56 -58
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +34 -18
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +23 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +16 -31
- package/lib/webpack/utils.js +63 -183
- package/package.json +83 -77
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5682
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -4127
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -39
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -39
- package/lib/server/themes/index.d.ts +0 -8
- package/lib/server/themes/index.js +0 -35
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.resolveModuleName = exports.getNamePatterns = void 0;
|
|
10
|
+
function getNamePatterns(moduleName, moduleType) {
|
|
11
|
+
if (moduleName.startsWith('@')) {
|
|
12
|
+
// Pure scope: `@scope` => `@scope/docusaurus-plugin`
|
|
13
|
+
if (!moduleName.includes('/')) {
|
|
14
|
+
return [`${moduleName}/docusaurus-${moduleType}`];
|
|
15
|
+
}
|
|
16
|
+
const [scope, packageName] = moduleName.split(/\/(?<rest>.*)/);
|
|
17
|
+
return [
|
|
18
|
+
`${scope}/${packageName}`,
|
|
19
|
+
`${scope}/docusaurus-${moduleType}-${packageName}`,
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
moduleName,
|
|
24
|
+
`@docusaurus/${moduleType}-${moduleName}`,
|
|
25
|
+
`docusaurus-${moduleType}-${moduleName}`,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.getNamePatterns = getNamePatterns;
|
|
29
|
+
function resolveModuleName(moduleName, moduleRequire, moduleType) {
|
|
30
|
+
const modulePatterns = getNamePatterns(moduleName, moduleType);
|
|
31
|
+
const module = modulePatterns.find((m) => {
|
|
32
|
+
try {
|
|
33
|
+
moduleRequire.resolve(m);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (!module) {
|
|
41
|
+
throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
|
|
42
|
+
${modulePatterns.map((m) => `- ${m}`).join('\n')}`);
|
|
43
|
+
}
|
|
44
|
+
return module;
|
|
45
|
+
}
|
|
46
|
+
exports.resolveModuleName = resolveModuleName;
|
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import type { InitializedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* It is forbidden to have 2 plugins of the same name sharing the same ID.
|
|
10
|
+
* This is required to support multi-instance plugins without conflict.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureUniquePluginInstanceIds(plugins: InitializedPlugin[]): void;
|
|
@@ -7,17 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
/**
|
|
14
|
+
* It is forbidden to have 2 plugins of the same name sharing the same ID.
|
|
15
|
+
* This is required to support multi-instance plugins without conflict.
|
|
16
|
+
*/
|
|
14
17
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName = lodash_1.groupBy(plugins, (p) => p.name);
|
|
18
|
+
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
16
19
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById = lodash_1.groupBy(pluginInstances, (p) =>
|
|
20
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => p.options.id ?? utils_1.DEFAULT_PLUGIN_ID);
|
|
18
21
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
22
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
|
-
throw new Error(`Plugin ${pluginName} is used ${pluginInstancesWithId.length} times with
|
|
23
|
+
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
|
|
24
|
+
? `\n\nThe plugin ID is "${utils_1.DEFAULT_PLUGIN_ID}" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances).`
|
|
25
|
+
: ''}`);
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
28
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoadContext, DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Calls preset functions, aggregates each of their return values, and returns
|
|
10
|
+
* the plugin and theme configs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadPresets(context: LoadContext): Promise<Pick<DocusaurusConfig, 'plugins' | 'themes'>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadPresets = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
14
|
+
/**
|
|
15
|
+
* Calls preset functions, aggregates each of their return values, and returns
|
|
16
|
+
* the plugin and theme configs.
|
|
17
|
+
*/
|
|
18
|
+
async function loadPresets(context) {
|
|
19
|
+
// We need to resolve plugins from the perspective of the site config, as if
|
|
20
|
+
// we are using `require.resolve` on those module names.
|
|
21
|
+
const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
22
|
+
const { presets } = context.siteConfig;
|
|
23
|
+
const plugins = [];
|
|
24
|
+
const themes = [];
|
|
25
|
+
presets.forEach((presetItem) => {
|
|
26
|
+
let presetModuleImport;
|
|
27
|
+
let presetOptions = {};
|
|
28
|
+
if (!presetItem) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (typeof presetItem === 'string') {
|
|
32
|
+
presetModuleImport = presetItem;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
[presetModuleImport, presetOptions] = presetItem;
|
|
36
|
+
}
|
|
37
|
+
const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
|
|
38
|
+
const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
|
|
39
|
+
const preset = (presetModule.default ?? presetModule)(context, presetOptions);
|
|
40
|
+
if (preset.plugins) {
|
|
41
|
+
plugins.push(...preset.plugins);
|
|
42
|
+
}
|
|
43
|
+
if (preset.themes) {
|
|
44
|
+
themes.push(...preset.themes);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return { plugins, themes };
|
|
48
|
+
}
|
|
49
|
+
exports.loadPresets = loadPresets;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
|
|
8
|
+
import type { RouteConfig } from '@docusaurus/types';
|
|
9
|
+
/** Recursively applies trailing slash config to all nested routes. */
|
|
10
|
+
export declare function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
|
|
11
|
+
export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sortConfig = exports.applyRouteTrailingSlash = void 0;
|
|
10
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
|
+
/** Recursively applies trailing slash config to all nested routes. */
|
|
12
|
+
function applyRouteTrailingSlash(route, params) {
|
|
13
|
+
return {
|
|
14
|
+
...route,
|
|
15
|
+
path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
|
|
16
|
+
...(route.routes && {
|
|
17
|
+
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.applyRouteTrailingSlash = applyRouteTrailingSlash;
|
|
22
|
+
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
23
|
+
// Sort the route config. This ensures that route with nested
|
|
24
|
+
// routes is always placed last.
|
|
25
|
+
routeConfigs.sort((a, b) => {
|
|
26
|
+
// Root route should get placed last.
|
|
27
|
+
if (a.path === baseUrl && b.path !== baseUrl) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (a.path !== baseUrl && b.path === baseUrl) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
if (a.routes && !b.routes) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
if (!a.routes && b.routes) {
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
// Higher priority get placed first.
|
|
40
|
+
if (a.priority || b.priority) {
|
|
41
|
+
const priorityA = a.priority ?? 0;
|
|
42
|
+
const priorityB = b.priority ?? 0;
|
|
43
|
+
const score = priorityB - priorityA;
|
|
44
|
+
if (score !== 0) {
|
|
45
|
+
return score;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return a.path.localeCompare(b.path);
|
|
49
|
+
});
|
|
50
|
+
routeConfigs.forEach((routeConfig) => {
|
|
51
|
+
routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.sortConfig = sortConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoadedPlugin, LoadContext } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Make a synthetic plugin to:
|
|
10
|
+
* - Inject site client modules
|
|
11
|
+
* - Inject scripts/stylesheets
|
|
12
|
+
*/
|
|
13
|
+
export declare function createBootstrapPlugin({ siteDir, siteConfig, }: LoadContext): LoadedPlugin;
|
|
14
|
+
/**
|
|
15
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
16
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
17
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
18
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
19
|
+
*/
|
|
20
|
+
export declare function createMDXFallbackPlugin({ siteDir, siteConfig, }: LoadContext): LoadedPlugin;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createMDXFallbackPlugin = exports.createBootstrapPlugin = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
/**
|
|
13
|
+
* Make a synthetic plugin to:
|
|
14
|
+
* - Inject site client modules
|
|
15
|
+
* - Inject scripts/stylesheets
|
|
16
|
+
*/
|
|
17
|
+
function createBootstrapPlugin({ siteDir, siteConfig, }) {
|
|
18
|
+
const { stylesheets, scripts, clientModules: siteConfigClientModules, } = siteConfig;
|
|
19
|
+
return {
|
|
20
|
+
name: 'docusaurus-bootstrap-plugin',
|
|
21
|
+
content: null,
|
|
22
|
+
options: {
|
|
23
|
+
id: 'default',
|
|
24
|
+
},
|
|
25
|
+
version: { type: 'synthetic' },
|
|
26
|
+
path: siteDir,
|
|
27
|
+
getClientModules() {
|
|
28
|
+
return siteConfigClientModules;
|
|
29
|
+
},
|
|
30
|
+
injectHtmlTags: () => {
|
|
31
|
+
const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
|
|
32
|
+
? `<link rel="stylesheet" href="${source}">`
|
|
33
|
+
: {
|
|
34
|
+
tagName: 'link',
|
|
35
|
+
attributes: {
|
|
36
|
+
rel: 'stylesheet',
|
|
37
|
+
...source,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const scriptsTags = scripts.map((source) => typeof source === 'string'
|
|
41
|
+
? `<script src="${source}"></script>`
|
|
42
|
+
: {
|
|
43
|
+
tagName: 'script',
|
|
44
|
+
attributes: {
|
|
45
|
+
...source,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.createBootstrapPlugin = createBootstrapPlugin;
|
|
55
|
+
/**
|
|
56
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
57
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
58
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
59
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
60
|
+
*/
|
|
61
|
+
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
62
|
+
return {
|
|
63
|
+
name: 'docusaurus-mdx-fallback-plugin',
|
|
64
|
+
content: null,
|
|
65
|
+
options: {
|
|
66
|
+
id: 'default',
|
|
67
|
+
},
|
|
68
|
+
version: { type: 'synthetic' },
|
|
69
|
+
// Synthetic, the path doesn't matter much
|
|
70
|
+
path: '.',
|
|
71
|
+
configureWebpack(config, isServer, { getJSLoader }) {
|
|
72
|
+
// We need the mdx fallback loader to exclude files that were already
|
|
73
|
+
// processed by content plugins mdx loaders. This works, but a bit
|
|
74
|
+
// hacky... Not sure there's a way to handle that differently in webpack
|
|
75
|
+
function getMDXFallbackExcludedPaths() {
|
|
76
|
+
const rules = config.module?.rules;
|
|
77
|
+
return rules.flatMap((rule) => {
|
|
78
|
+
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
79
|
+
return isMDXRule ? rule.include : [];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const mdxLoaderOptions = {
|
|
83
|
+
admonitions: true,
|
|
84
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
85
|
+
siteDir,
|
|
86
|
+
// External MDX files are always meant to be imported as partials
|
|
87
|
+
isMDXPartial: () => true,
|
|
88
|
+
// External MDX files might have front matter, just disable the warning
|
|
89
|
+
isMDXPartialFrontMatterWarningDisabled: true,
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
module: {
|
|
93
|
+
rules: [
|
|
94
|
+
{
|
|
95
|
+
test: /\.mdx?$/i,
|
|
96
|
+
exclude: getMDXFallbackExcludedPaths(),
|
|
97
|
+
use: [
|
|
98
|
+
getJSLoader({ isServer }),
|
|
99
|
+
{
|
|
100
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
101
|
+
options: mdxLoaderOptions,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
exports.createMDXFallbackPlugin = createMDXFallbackPlugin;
|
package/lib/server/routes.d.ts
CHANGED
|
@@ -4,16 +4,48 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import type { RouteConfig, RouteChunkNames, ReportingSeverity } from '@docusaurus/types';
|
|
8
8
|
declare type LoadedRoutes = {
|
|
9
|
-
|
|
10
|
-
[chunkName: string]: ChunkRegistry;
|
|
11
|
-
};
|
|
9
|
+
/** Serialized routes config that can be directly emitted into temp file. */
|
|
12
10
|
routesConfig: string;
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/** @see {ChunkNames} */
|
|
12
|
+
routesChunkNames: RouteChunkNames;
|
|
13
|
+
/**
|
|
14
|
+
* A map from chunk name to module paths. Module paths would have backslash
|
|
15
|
+
* escaped already, so they can be directly printed.
|
|
16
|
+
*/
|
|
17
|
+
registry: {
|
|
18
|
+
[chunkName: string]: string;
|
|
15
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Collect all page paths for injecting it later in the plugin lifecycle.
|
|
22
|
+
* This is useful for plugins like sitemaps, redirects etc... Only collects
|
|
23
|
+
* "actual" pages, i.e. those without subroutes, because if a route has
|
|
24
|
+
* subroutes, it is probably a wrapper.
|
|
25
|
+
*/
|
|
16
26
|
routesPaths: string[];
|
|
17
27
|
};
|
|
18
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Generates a unique chunk name that can be used in the chunk registry.
|
|
30
|
+
*
|
|
31
|
+
* @param modulePath A path to generate chunk name from. The actual value has no
|
|
32
|
+
* semantic significance.
|
|
33
|
+
* @param prefix A prefix to append to the chunk name, to avoid name clash.
|
|
34
|
+
* @param preferredName Chunk names default to `modulePath`, and this can supply
|
|
35
|
+
* a more human-readable name.
|
|
36
|
+
* @param shortId When `true`, the chunk name would only be a hash without any
|
|
37
|
+
* other characters. Useful for bundle size. Defaults to `true` in production.
|
|
38
|
+
*/
|
|
39
|
+
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
40
|
+
export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
|
|
41
|
+
/**
|
|
42
|
+
* Routes are prepared into three temp files:
|
|
43
|
+
*
|
|
44
|
+
* - `routesConfig`, the route config passed to react-router. This file is kept
|
|
45
|
+
* minimal, because it can't be code-splitted.
|
|
46
|
+
* - `routesChunkNames`, a mapping from route paths (hashed) to code-splitted
|
|
47
|
+
* chunk names.
|
|
48
|
+
* - `registry`, a mapping from chunk names to options for react-loadable.
|
|
49
|
+
*/
|
|
50
|
+
export declare function loadRoutes(routeConfigs: RouteConfig[], baseUrl: string, onDuplicateRoutes: ReportingSeverity): LoadedRoutes;
|
|
19
51
|
export {};
|