@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -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 +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- 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 +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- 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/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- 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 +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- 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 +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- 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/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- 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 +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -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 +3 -2
- package/lib/webpack/utils.d.ts +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- 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/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- 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
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.normalizePluginConfigs = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
11
|
+
const module_1 = require("module");
|
|
11
12
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
|
-
const
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
14
|
const versions_1 = require("../versions");
|
|
14
15
|
const pluginIds_1 = require("./pluginIds");
|
|
15
16
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
17
|
-
var _a, _b, _c, _d;
|
|
17
|
+
async function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
18
18
|
// plugins: ['./plugin']
|
|
19
19
|
if (typeof pluginConfig === 'string') {
|
|
20
20
|
const pluginModuleImport = pluginConfig;
|
|
21
21
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
22
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
22
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
23
23
|
return {
|
|
24
|
-
plugin:
|
|
24
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
25
25
|
options: {},
|
|
26
26
|
pluginModule: {
|
|
27
27
|
path: pluginModuleImport,
|
|
@@ -43,10 +43,10 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
43
43
|
if (typeof pluginConfig[0] === 'string') {
|
|
44
44
|
const pluginModuleImport = pluginConfig[0];
|
|
45
45
|
const pluginPath = pluginRequire.resolve(pluginModuleImport);
|
|
46
|
-
const pluginModule = import_fresh_1.default(pluginPath);
|
|
46
|
+
const pluginModule = (0, import_fresh_1.default)(pluginPath);
|
|
47
47
|
return {
|
|
48
|
-
plugin:
|
|
49
|
-
options:
|
|
48
|
+
plugin: pluginModule?.default ?? pluginModule,
|
|
49
|
+
options: pluginConfig[1] ?? {},
|
|
50
50
|
pluginModule: {
|
|
51
51
|
path: pluginModuleImport,
|
|
52
52
|
module: pluginModule,
|
|
@@ -59,49 +59,44 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
|
|
|
59
59
|
if (typeof pluginConfig[0] === 'function') {
|
|
60
60
|
return {
|
|
61
61
|
plugin: pluginConfig[0],
|
|
62
|
-
options:
|
|
62
|
+
options: pluginConfig[1] ?? {},
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
throw new Error(`Unexpected: can't load plugin for following plugin config.\n${JSON.stringify(pluginConfig)}`);
|
|
67
67
|
}
|
|
68
|
+
async function normalizePluginConfigs(pluginConfigs, pluginRequire) {
|
|
69
|
+
return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, pluginRequire)));
|
|
70
|
+
}
|
|
71
|
+
exports.normalizePluginConfigs = normalizePluginConfigs;
|
|
68
72
|
function getOptionValidationFunction(normalizedPluginConfig) {
|
|
69
|
-
var _a, _b, _c, _d;
|
|
70
73
|
if (normalizedPluginConfig.pluginModule) {
|
|
71
74
|
// support both commonjs and ES modules
|
|
72
|
-
return (
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
return normalizedPluginConfig.plugin.validateOptions;
|
|
75
|
+
return (normalizedPluginConfig.pluginModule.module?.default?.validateOptions ??
|
|
76
|
+
normalizedPluginConfig.pluginModule.module?.validateOptions);
|
|
76
77
|
}
|
|
78
|
+
return normalizedPluginConfig.plugin.validateOptions;
|
|
77
79
|
}
|
|
78
80
|
function getThemeValidationFunction(normalizedPluginConfig) {
|
|
79
|
-
var _a, _b;
|
|
80
81
|
if (normalizedPluginConfig.pluginModule) {
|
|
81
82
|
// support both commonjs and ES modules
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
else {
|
|
85
|
-
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
83
|
+
return (normalizedPluginConfig.pluginModule.module.default?.validateThemeConfig ??
|
|
84
|
+
normalizedPluginConfig.pluginModule.module.validateThemeConfig);
|
|
86
85
|
}
|
|
86
|
+
return normalizedPluginConfig.plugin.validateThemeConfig;
|
|
87
87
|
}
|
|
88
|
-
function initPlugins({ pluginConfigs, context, }) {
|
|
89
|
-
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
90
|
-
// declares the dependency on these plugins.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const pluginRequire = createRequire(context.siteConfigPath);
|
|
95
|
-
function doGetPluginVersion(normalizedPluginConfig) {
|
|
96
|
-
var _a, _b;
|
|
88
|
+
async function initPlugins({ pluginConfigs, context, }) {
|
|
89
|
+
// We need to resolve plugins from the perspective of the siteDir, since the
|
|
90
|
+
// siteDir's package.json declares the dependency on these plugins.
|
|
91
|
+
const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
92
|
+
const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, pluginRequire);
|
|
93
|
+
async function doGetPluginVersion(normalizedPluginConfig) {
|
|
97
94
|
// get plugin version
|
|
98
|
-
if (
|
|
99
|
-
const pluginPath = pluginRequire.resolve(
|
|
100
|
-
return versions_1.getPluginVersion(pluginPath, context.siteDir);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return { type: 'local' };
|
|
95
|
+
if (normalizedPluginConfig.pluginModule?.path) {
|
|
96
|
+
const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
|
|
97
|
+
return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
|
|
104
98
|
}
|
|
99
|
+
return { type: 'local' };
|
|
105
100
|
}
|
|
106
101
|
function doValidateThemeConfig(normalizedPluginConfig) {
|
|
107
102
|
const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
|
|
@@ -111,12 +106,9 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
111
106
|
themeConfig: context.siteConfig.themeConfig,
|
|
112
107
|
});
|
|
113
108
|
}
|
|
114
|
-
|
|
115
|
-
return context.siteConfig.themeConfig;
|
|
116
|
-
}
|
|
109
|
+
return context.siteConfig.themeConfig;
|
|
117
110
|
}
|
|
118
111
|
function doValidatePluginOptions(normalizedPluginConfig) {
|
|
119
|
-
var _a;
|
|
120
112
|
const validateOptions = getOptionValidationFunction(normalizedPluginConfig);
|
|
121
113
|
if (validateOptions) {
|
|
122
114
|
return validateOptions({
|
|
@@ -124,37 +116,35 @@ function initPlugins({ pluginConfigs, context, }) {
|
|
|
124
116
|
options: normalizedPluginConfig.options,
|
|
125
117
|
});
|
|
126
118
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
}
|
|
119
|
+
// Important to ensure all plugins have an id
|
|
120
|
+
// as we don't go through the Joi schema that adds it
|
|
121
|
+
return {
|
|
122
|
+
...normalizedPluginConfig.options,
|
|
123
|
+
id: normalizedPluginConfig.options.id ?? utils_1.DEFAULT_PLUGIN_ID,
|
|
124
|
+
};
|
|
135
125
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!pluginConfig) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
|
|
142
|
-
const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
|
|
126
|
+
async function initializePlugin(normalizedPluginConfig) {
|
|
127
|
+
const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
|
|
143
128
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
|
144
129
|
// Side-effect: merge the normalized theme config in the original one
|
|
145
130
|
context.siteConfig.themeConfig = {
|
|
146
131
|
...context.siteConfig.themeConfig,
|
|
147
132
|
...doValidateThemeConfig(normalizedPluginConfig),
|
|
148
133
|
};
|
|
149
|
-
const pluginInstance = normalizedPluginConfig.plugin(context, pluginOptions);
|
|
134
|
+
const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
|
|
150
135
|
return {
|
|
151
136
|
...pluginInstance,
|
|
152
137
|
options: pluginOptions,
|
|
153
138
|
version: pluginVersion,
|
|
154
139
|
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
140
|
+
}
|
|
141
|
+
const plugins = (await Promise.all(pluginConfigsNormalized.map((pluginConfig) => {
|
|
142
|
+
if (!pluginConfig) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return initializePlugin(pluginConfig);
|
|
146
|
+
}))).filter((item) => Boolean(item));
|
|
147
|
+
(0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
|
|
158
148
|
return plugins;
|
|
159
149
|
}
|
|
160
150
|
exports.default = initPlugins;
|
|
@@ -4,5 +4,5 @@
|
|
|
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 { InitializedPlugin } from '@docusaurus/types';
|
|
7
|
+
import type { InitializedPlugin } from '@docusaurus/types';
|
|
8
8
|
export declare function ensureUniquePluginInstanceIds(plugins: InitializedPlugin[]): void;
|
|
@@ -7,17 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
// It is forbidden to have 2 plugins of the same name sharing the same id
|
|
13
14
|
// this is required to support multi-instance plugins without conflict
|
|
14
15
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName = lodash_1.groupBy(plugins, (p) => p.name);
|
|
16
|
+
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
16
17
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById = lodash_1.groupBy(pluginInstances, (p) =>
|
|
18
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => p.options.id ?? utils_1.DEFAULT_PLUGIN_ID);
|
|
18
19
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
20
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
|
-
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with
|
|
21
|
+
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
22
|
+
? `\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).`
|
|
23
|
+
: ''}`);
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
26
|
});
|
|
@@ -4,8 +4,8 @@
|
|
|
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 { LoadContext, PluginConfig } from '@docusaurus/types';
|
|
8
|
-
export default function loadPresets(context: LoadContext): {
|
|
7
|
+
import type { LoadContext, PluginConfig } from '@docusaurus/types';
|
|
8
|
+
export default function loadPresets(context: LoadContext): Promise<{
|
|
9
9
|
plugins: PluginConfig[];
|
|
10
10
|
themes: PluginConfig[];
|
|
11
|
-
}
|
|
11
|
+
}>;
|
|
@@ -7,16 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const module_1 =
|
|
10
|
+
const module_1 = require("module");
|
|
11
11
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const pluginRequire = createRequire(context.siteConfigPath);
|
|
19
|
-
const presets = (context.siteConfig || {}).presets || [];
|
|
12
|
+
const moduleShorthand_1 = require("../moduleShorthand");
|
|
13
|
+
async function loadPresets(context) {
|
|
14
|
+
// We need to resolve presets from the perspective of the siteDir, since the
|
|
15
|
+
// siteDir's package.json declares the dependency on these presets.
|
|
16
|
+
const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
17
|
+
const presets = context.siteConfig.presets || [];
|
|
20
18
|
const unflatPlugins = [];
|
|
21
19
|
const unflatThemes = [];
|
|
22
20
|
presets.forEach((presetItem) => {
|
|
@@ -31,8 +29,9 @@ function loadPresets(context) {
|
|
|
31
29
|
else {
|
|
32
30
|
throw new Error('Invalid presets format detected in config.');
|
|
33
31
|
}
|
|
34
|
-
const
|
|
35
|
-
const
|
|
32
|
+
const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
|
|
33
|
+
const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
|
|
34
|
+
const preset = (presetModule.default ?? presetModule)(context, presetOptions);
|
|
36
35
|
if (preset.plugins) {
|
|
37
36
|
unflatPlugins.push(preset.plugins);
|
|
38
37
|
}
|
|
@@ -41,8 +40,8 @@ function loadPresets(context) {
|
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
return {
|
|
44
|
-
plugins:
|
|
45
|
-
themes:
|
|
43
|
+
plugins: unflatPlugins.flat().filter(Boolean),
|
|
44
|
+
themes: unflatThemes.flat().filter(Boolean),
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
47
|
exports.default = loadPresets;
|
package/lib/server/routes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { ChunkRegistry, RouteConfig, ChunkNames } from '@docusaurus/types';
|
|
7
|
+
import type { ChunkRegistry, RouteConfig, ChunkNames } from '@docusaurus/types';
|
|
8
8
|
declare type LoadedRoutes = {
|
|
9
9
|
registry: {
|
|
10
10
|
[chunkName: string]: ChunkRegistry;
|
package/lib/server/routes.js
CHANGED
|
@@ -7,20 +7,34 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const utils_1 = require("@docusaurus/utils");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const querystring_1 = require("querystring");
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
${
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
:
|
|
23
|
-
|
|
11
|
+
function indent(str) {
|
|
12
|
+
const spaces = ' ';
|
|
13
|
+
return `${spaces}${str.replace(/\n/g, `\n${spaces}`)}`;
|
|
14
|
+
}
|
|
15
|
+
const createRouteCodeString = ({ routePath, routeHash, exact, subroutesCodeStrings, props, }) => {
|
|
16
|
+
const parts = [
|
|
17
|
+
`path: '${routePath}'`,
|
|
18
|
+
`component: ComponentCreator('${routePath}','${routeHash}')`,
|
|
19
|
+
];
|
|
20
|
+
if (exact) {
|
|
21
|
+
parts.push(`exact: true`);
|
|
22
|
+
}
|
|
23
|
+
if (subroutesCodeStrings) {
|
|
24
|
+
parts.push(`routes: [
|
|
25
|
+
${indent((0, utils_1.removeSuffix)(subroutesCodeStrings.join(',\n'), ',\n'))}
|
|
26
|
+
]`);
|
|
27
|
+
}
|
|
28
|
+
Object.entries(props).forEach(([propName, propValue]) => {
|
|
29
|
+
// Figure out how to "unquote" JS attributes that don't need to be quoted
|
|
30
|
+
// Is this lib reliable? https://github.com/armanozak/should-quote
|
|
31
|
+
const shouldQuote = true; // TODO
|
|
32
|
+
const key = shouldQuote ? `'${propName}'` : propName;
|
|
33
|
+
parts.push(`${key}: ${JSON.stringify(propValue)}`);
|
|
34
|
+
});
|
|
35
|
+
return `{
|
|
36
|
+
${indent(parts.join(',\n'))}
|
|
37
|
+
}`;
|
|
24
38
|
};
|
|
25
39
|
const NotFoundRouteCode = `{
|
|
26
40
|
path: '*',
|
|
@@ -31,10 +45,13 @@ const RoutesImportsCode = [
|
|
|
31
45
|
`import ComponentCreator from '@docusaurus/ComponentCreator';`,
|
|
32
46
|
].join('\n');
|
|
33
47
|
function isModule(value) {
|
|
34
|
-
if (
|
|
48
|
+
if (typeof value === 'string') {
|
|
35
49
|
return true;
|
|
36
50
|
}
|
|
37
|
-
if (
|
|
51
|
+
if (typeof value === 'object' &&
|
|
52
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
53
|
+
value?.__import &&
|
|
54
|
+
value?.path) {
|
|
38
55
|
return true;
|
|
39
56
|
}
|
|
40
57
|
return false;
|
|
@@ -43,29 +60,31 @@ function getModulePath(target) {
|
|
|
43
60
|
if (typeof target === 'string') {
|
|
44
61
|
return target;
|
|
45
62
|
}
|
|
46
|
-
const queryStr = target.query ? `?${querystring_1.stringify(target.query)}` : '';
|
|
63
|
+
const queryStr = target.query ? `?${(0, querystring_1.stringify)(target.query)}` : '';
|
|
47
64
|
return `${target.path}${queryStr}`;
|
|
48
65
|
}
|
|
49
66
|
async function loadRoutes(pluginsRouteConfigs, baseUrl) {
|
|
50
67
|
const registry = {};
|
|
51
|
-
const routesPaths = [utils_1.normalizeUrl([baseUrl, '404.html'])];
|
|
68
|
+
const routesPaths = [(0, utils_1.normalizeUrl)([baseUrl, '404.html'])];
|
|
52
69
|
const routesChunkNames = {};
|
|
53
70
|
// This is the higher level overview of route code generation.
|
|
54
71
|
function generateRouteCode(routeConfig) {
|
|
55
|
-
const { path: routePath, component, modules = {}, routes: subroutes, exact, } = routeConfig;
|
|
56
|
-
if (
|
|
57
|
-
throw new Error(`Invalid route config: path must be a string and component is required
|
|
72
|
+
const { path: routePath, component, modules = {}, routes: subroutes, exact, priority, ...props } = routeConfig;
|
|
73
|
+
if (typeof routePath !== 'string' || !component) {
|
|
74
|
+
throw new Error(`Invalid route config: path must be a string and component is required.
|
|
75
|
+
${JSON.stringify(routeConfig)}`);
|
|
58
76
|
}
|
|
59
77
|
// Collect all page paths for injecting it later in the plugin lifecycle
|
|
60
78
|
// This is useful for plugins like sitemaps, redirects etc...
|
|
61
|
-
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
79
|
+
// If a route has subroutes, it is not necessarily a valid page path (more
|
|
80
|
+
// likely to be a wrapper)
|
|
62
81
|
if (!subroutes) {
|
|
63
82
|
routesPaths.push(routePath);
|
|
64
83
|
}
|
|
65
84
|
// We hash the route to generate the key, because 2 routes can conflict with
|
|
66
85
|
// each others if they have the same path, ex: parent=/docs, child=/docs
|
|
67
86
|
// see https://github.com/facebook/docusaurus/issues/2917
|
|
68
|
-
const routeHash = utils_1.simpleHash(JSON.stringify(routeConfig), 3);
|
|
87
|
+
const routeHash = (0, utils_1.simpleHash)(JSON.stringify(routeConfig), 3);
|
|
69
88
|
const chunkNamesKey = `${routePath}-${routeHash}`;
|
|
70
89
|
routesChunkNames[chunkNamesKey] = {
|
|
71
90
|
...genRouteChunkNames(registry, { component }, 'component', component),
|
|
@@ -75,15 +94,18 @@ async function loadRoutes(pluginsRouteConfigs, baseUrl) {
|
|
|
75
94
|
routePath: routeConfig.path.replace(/'/g, "\\'"),
|
|
76
95
|
routeHash,
|
|
77
96
|
exact,
|
|
78
|
-
subroutesCodeStrings: subroutes
|
|
97
|
+
subroutesCodeStrings: subroutes?.map(generateRouteCode),
|
|
98
|
+
props,
|
|
79
99
|
});
|
|
80
100
|
}
|
|
81
101
|
const routesConfig = `
|
|
82
102
|
${RoutesImportsCode}
|
|
103
|
+
|
|
83
104
|
export default [
|
|
84
|
-
${pluginsRouteConfigs.map(generateRouteCode).join(',\n')}
|
|
85
|
-
${NotFoundRouteCode}
|
|
86
|
-
]
|
|
105
|
+
${indent(`${pluginsRouteConfigs.map(generateRouteCode).join(',\n')},`)}
|
|
106
|
+
${indent(NotFoundRouteCode)}
|
|
107
|
+
];
|
|
108
|
+
`;
|
|
87
109
|
return {
|
|
88
110
|
registry,
|
|
89
111
|
routesConfig,
|
|
@@ -103,9 +125,8 @@ registry, value, prefix, name) {
|
|
|
103
125
|
}
|
|
104
126
|
if (isModule(value)) {
|
|
105
127
|
const modulePath = getModulePath(value);
|
|
106
|
-
const chunkName = utils_1.genChunkName(modulePath, prefix, name);
|
|
107
|
-
|
|
108
|
-
const loader = `() => import(/* webpackChunkName: '${chunkName}' */ ${JSON.stringify(modulePath)})`;
|
|
128
|
+
const chunkName = (0, utils_1.genChunkName)(modulePath, prefix, name);
|
|
129
|
+
const loader = `() => import(/* webpackChunkName: '${chunkName}' */ '${(0, utils_1.escapePath)(modulePath)}')`;
|
|
109
130
|
registry[chunkName] = {
|
|
110
131
|
loader,
|
|
111
132
|
modulePath,
|
|
@@ -4,5 +4,6 @@
|
|
|
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 { ThemeAliases } from '@docusaurus/types';
|
|
8
|
-
export
|
|
7
|
+
import type { ThemeAliases } from '@docusaurus/types';
|
|
8
|
+
export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
|
|
9
|
+
export default function themeAlias(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
|
|
@@ -6,35 +6,43 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sortAliases = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
// Order of Webpack aliases is important because one alias can shadow another
|
|
16
|
+
// This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
|
|
17
|
+
// See https://github.com/facebook/docusaurus/pull/3922
|
|
18
|
+
// See https://github.com/facebook/docusaurus/issues/5382
|
|
19
|
+
function sortAliases(aliases) {
|
|
20
|
+
// Alphabetical order by default
|
|
21
|
+
const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
|
|
22
|
+
// @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
|
|
23
|
+
entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
|
|
24
|
+
return Object.fromEntries(entries);
|
|
25
|
+
}
|
|
26
|
+
exports.sortAliases = sortAliases;
|
|
27
|
+
async function themeAlias(themePath, addOriginalAlias) {
|
|
28
|
+
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
18
29
|
return {};
|
|
19
30
|
}
|
|
20
|
-
const themeComponentFiles =
|
|
31
|
+
const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
|
|
21
32
|
cwd: themePath,
|
|
22
33
|
});
|
|
23
|
-
// See https://github.com/facebook/docusaurus/pull/3922
|
|
24
|
-
// ensure @theme/NavbarItem alias is created after @theme/NavbarItem/LocaleDropdown
|
|
25
|
-
const sortedThemeComponentFiles = lodash_1.sortBy(themeComponentFiles, (file) => file.endsWith('/index.js'));
|
|
26
34
|
const aliases = {};
|
|
27
|
-
|
|
35
|
+
themeComponentFiles.forEach((relativeSource) => {
|
|
28
36
|
const filePath = path_1.default.join(themePath, relativeSource);
|
|
29
|
-
const fileName = utils_1.fileToPath(relativeSource);
|
|
30
|
-
const aliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme', fileName]).replace(/\/$/, ''));
|
|
37
|
+
const fileName = (0, utils_1.fileToPath)(relativeSource);
|
|
38
|
+
const aliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme', fileName]).replace(/\/$/, ''));
|
|
31
39
|
aliases[aliasName] = filePath;
|
|
32
40
|
if (addOriginalAlias) {
|
|
33
41
|
// For swizzled components to access the original.
|
|
34
|
-
const originalAliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme-original', fileName]).replace(/\/$/, ''));
|
|
42
|
+
const originalAliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme-original', fileName]).replace(/\/$/, ''));
|
|
35
43
|
aliases[originalAliasName] = filePath;
|
|
36
44
|
}
|
|
37
45
|
});
|
|
38
|
-
return aliases;
|
|
46
|
+
return sortAliases(aliases);
|
|
39
47
|
}
|
|
40
48
|
exports.default = themeAlias;
|
|
@@ -4,9 +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 { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
-
export declare function loadThemeAliases(themePaths: string[], userThemePaths
|
|
7
|
+
import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
|
|
9
9
|
export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
|
|
10
10
|
siteDir: string;
|
|
11
11
|
plugins: LoadedPlugin[];
|
|
12
|
-
}): ThemeAliases
|
|
12
|
+
}): Promise<ThemeAliases>;
|
|
@@ -9,39 +9,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.loadPluginsThemeAliases = exports.loadThemeAliases = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const
|
|
13
|
-
const alias_1 = tslib_1.
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const alias_1 = tslib_1.__importStar(require("./alias"));
|
|
14
14
|
const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const userThemeAliases = alias_1.default(themePath, false);
|
|
35
|
-
aliases
|
|
36
|
-
}
|
|
37
|
-
return aliases;
|
|
15
|
+
async function loadThemeAliases(themePaths, userThemePaths) {
|
|
16
|
+
const aliases = {};
|
|
17
|
+
for (const themePath of themePaths) {
|
|
18
|
+
const themeAliases = await (0, alias_1.default)(themePath, true);
|
|
19
|
+
Object.keys(themeAliases).forEach((aliasKey) => {
|
|
20
|
+
// If this alias shadows a previous one, use @theme-init to preserve the
|
|
21
|
+
// initial one. @theme-init is only applied once: to the initial theme
|
|
22
|
+
// that provided this component
|
|
23
|
+
if (aliasKey in aliases) {
|
|
24
|
+
const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
|
|
25
|
+
const initAlias = `@theme-init/${componentName}`;
|
|
26
|
+
if (!(initAlias in aliases)) {
|
|
27
|
+
aliases[initAlias] = aliases[aliasKey];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
aliases[aliasKey] = themeAliases[aliasKey];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
for (const themePath of userThemePaths) {
|
|
34
|
+
const userThemeAliases = await (0, alias_1.default)(themePath, false);
|
|
35
|
+
Object.assign(aliases, userThemeAliases);
|
|
36
|
+
}
|
|
37
|
+
return (0, alias_1.sortAliases)(aliases);
|
|
38
38
|
}
|
|
39
39
|
exports.loadThemeAliases = loadThemeAliases;
|
|
40
40
|
function loadPluginsThemeAliases({ siteDir, plugins, }) {
|
|
41
41
|
const pluginThemes = plugins
|
|
42
42
|
.map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
|
|
43
43
|
.filter((x) => Boolean(x));
|
|
44
|
-
const userTheme = path_1.default.resolve(siteDir,
|
|
44
|
+
const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
|
|
45
45
|
return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
|
|
46
46
|
}
|
|
47
47
|
exports.loadPluginsThemeAliases = loadPluginsThemeAliases;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
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 { TranslationFileContent, TranslationFile, TranslationMessage, InitializedPlugin } from '@docusaurus/types';
|
|
2
8
|
export declare type WriteTranslationsOptions = {
|
|
3
9
|
override?: boolean;
|
|
4
10
|
messagePrefix?: string;
|