@docusaurus/core 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.js +125 -0
- package/bin/docusaurus.js +36 -105
- package/lib/.tsbuildinfo +1 -1
- package/lib/babel/preset.d.ts +6 -0
- package/lib/babel/preset.js +3 -3
- package/lib/choosePort.js +12 -13
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/.tsbuildinfo +1 -1
- package/lib/client/App.js +12 -22
- package/lib/client/LinksCollector.d.ts +2 -2
- package/lib/client/LinksCollector.js +4 -8
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
- package/lib/client/client-lifecycles-dispatcher.js +0 -2
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +11 -19
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Interpolate.js +12 -15
- package/lib/client/exports/Link.js +11 -11
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +13 -9
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +21 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/useBaseUrl.js +2 -4
- package/lib/client/exports/useDocusaurusContext.js +2 -7
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
- package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
- package/lib/client/flat.d.ts +2 -1
- package/lib/client/flat.js +7 -9
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +15 -31
- package/lib/client/theme-fallback/Error/index.js +47 -0
- package/lib/client/theme-fallback/Layout/index.js +1 -1
- package/lib/client/theme-fallback/Loading/index.js +2 -2
- package/lib/client/theme-fallback/Root/index.js +1 -3
- package/lib/commands/build.js +37 -40
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +9 -9
- package/lib/commands/commandUtils.d.ts +6 -0
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +3 -0
- package/lib/commands/deploy.js +98 -53
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +13 -13
- package/lib/commands/start.js +83 -73
- package/lib/commands/swizzle.js +49 -49
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +32 -32
- package/lib/commands/writeTranslations.js +31 -11
- package/lib/server/brokenLinks.js +13 -17
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +12 -7
- package/lib/server/duplicateRoutes.js +8 -2
- package/lib/server/html-tags/htmlTags.js +5 -6
- package/lib/server/html-tags/index.d.ts +2 -2
- package/lib/server/html-tags/index.js +3 -3
- package/lib/server/i18n.js +16 -13
- package/lib/server/index.js +129 -71
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +42 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -1
- package/lib/server/plugins/applyRouteTrailingSlash.js +3 -3
- package/lib/server/plugins/index.d.ts +3 -4
- package/lib/server/plugins/index.js +44 -33
- package/lib/server/plugins/init.d.ts +2 -6
- package/lib/server/plugins/init.js +9 -12
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/presets/index.js +12 -12
- package/lib/server/routes.js +41 -23
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -12
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +32 -21
- package/lib/server/translations/translations.d.ts +10 -5
- package/lib/server/translations/translations.js +15 -17
- package/lib/server/translations/translationsExtractor.d.ts +8 -3
- package/lib/server/translations/translationsExtractor.js +65 -56
- package/lib/server/utils.d.ts +8 -2
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__tests/index.test.js +5 -5
- package/lib/server/versions/index.js +6 -6
- package/lib/webpack/base.js +29 -21
- package/lib/webpack/client.js +8 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
- package/lib/webpack/plugins/LogPlugin.js +5 -6
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.js +13 -9
- package/lib/webpack/utils.d.ts +2 -23
- package/lib/webpack/utils.js +29 -127
- package/package.json +56 -51
- package/tsconfig.client.json +1 -2
- package/tsconfig.json +5 -4
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
package/lib/server/index.js
CHANGED
|
@@ -9,37 +9,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.load = exports.loadPluginConfigs = exports.loadContext = exports.loadSiteConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const path_1 = tslib_1.__importStar(require("path"));
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
|
-
const ssr_html_template_1 = tslib_1.__importDefault(require("../client/templates/ssr.html.template"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
12
|
+
const path_1 = (0, tslib_1.__importStar)(require("path"));
|
|
13
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
14
|
+
const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
|
|
15
|
+
const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
|
|
16
|
+
const config_1 = (0, tslib_1.__importDefault)(require("./config"));
|
|
18
17
|
const plugins_1 = require("./plugins");
|
|
19
|
-
const presets_1 = tslib_1.__importDefault(require("./presets"));
|
|
20
|
-
const routes_1 = tslib_1.__importDefault(require("./routes"));
|
|
21
|
-
const themes_1 = tslib_1.__importDefault(require("./themes"));
|
|
18
|
+
const presets_1 = (0, tslib_1.__importDefault)(require("./presets"));
|
|
19
|
+
const routes_1 = (0, tslib_1.__importDefault)(require("./routes"));
|
|
22
20
|
const html_tags_1 = require("./html-tags");
|
|
23
21
|
const versions_1 = require("./versions");
|
|
24
22
|
const duplicateRoutes_1 = require("./duplicateRoutes");
|
|
25
23
|
const i18n_1 = require("./i18n");
|
|
26
24
|
const translations_1 = require("./translations/translations");
|
|
27
25
|
const lodash_1 = require("lodash");
|
|
26
|
+
const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
|
|
27
|
+
const module_1 = require("module");
|
|
28
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
28
29
|
async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
29
|
-
const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath :
|
|
30
|
+
const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : utils_1.DEFAULT_CONFIG_FILE_NAME;
|
|
30
31
|
const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
|
|
31
32
|
? siteConfigPathUnresolved
|
|
32
33
|
: path_1.default.resolve(siteDir, siteConfigPathUnresolved);
|
|
33
|
-
const siteConfig = await config_1.default(siteConfigPath);
|
|
34
|
+
const siteConfig = await (0, config_1.default)(siteConfigPath);
|
|
34
35
|
return { siteConfig, siteConfigPath };
|
|
35
36
|
}
|
|
36
37
|
exports.loadSiteConfig = loadSiteConfig;
|
|
37
38
|
async function loadContext(siteDir, options = {}) {
|
|
38
39
|
var _a;
|
|
39
40
|
const { customOutDir, locale, customConfigFilePath } = options;
|
|
40
|
-
const generatedFilesDir = path_1.default.isAbsolute(
|
|
41
|
-
?
|
|
42
|
-
: path_1.default.resolve(siteDir,
|
|
41
|
+
const generatedFilesDir = path_1.default.isAbsolute(utils_1.GENERATED_FILES_DIR_NAME)
|
|
42
|
+
? utils_1.GENERATED_FILES_DIR_NAME
|
|
43
|
+
: path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
|
|
43
44
|
const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
|
|
44
45
|
siteDir,
|
|
45
46
|
customConfigFilePath,
|
|
@@ -47,27 +48,27 @@ async function loadContext(siteDir, options = {}) {
|
|
|
47
48
|
const { ssrTemplate } = initialSiteConfig;
|
|
48
49
|
const baseOutDir = customOutDir
|
|
49
50
|
? path_1.default.resolve(customOutDir)
|
|
50
|
-
: path_1.default.resolve(siteDir,
|
|
51
|
-
const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
|
|
52
|
-
const baseUrl = i18n_1.localizePath({
|
|
51
|
+
: path_1.default.resolve(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME);
|
|
52
|
+
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
53
|
+
const baseUrl = (0, i18n_1.localizePath)({
|
|
53
54
|
path: initialSiteConfig.baseUrl,
|
|
54
55
|
i18n,
|
|
55
56
|
options,
|
|
56
57
|
pathType: 'url',
|
|
57
58
|
});
|
|
58
|
-
const outDir = i18n_1.localizePath({
|
|
59
|
+
const outDir = (0, i18n_1.localizePath)({
|
|
59
60
|
path: baseOutDir,
|
|
60
61
|
i18n,
|
|
61
62
|
options,
|
|
62
63
|
pathType: 'fs',
|
|
63
64
|
});
|
|
64
65
|
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
65
|
-
const codeTranslationFileContent = (_a = (await translations_1.readCodeTranslationFileContent({
|
|
66
|
+
const codeTranslationFileContent = (_a = (await (0, translations_1.readCodeTranslationFileContent)({
|
|
66
67
|
siteDir,
|
|
67
68
|
locale: i18n.currentLocale,
|
|
68
69
|
}))) !== null && _a !== void 0 ? _a : {};
|
|
69
70
|
// We only need key->message for code translations
|
|
70
|
-
const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
71
|
+
const codeTranslations = (0, lodash_1.mapValues)(codeTranslationFileContent, (value) => value.message);
|
|
71
72
|
return {
|
|
72
73
|
siteDir,
|
|
73
74
|
generatedFilesDir,
|
|
@@ -82,56 +83,49 @@ async function loadContext(siteDir, options = {}) {
|
|
|
82
83
|
}
|
|
83
84
|
exports.loadContext = loadContext;
|
|
84
85
|
function loadPluginConfigs(context) {
|
|
85
|
-
|
|
86
|
-
const { siteConfig } = context;
|
|
86
|
+
let { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
|
|
87
|
+
const { siteConfig, siteConfigPath } = context;
|
|
88
|
+
const require = (0, module_1.createRequire)(siteConfigPath);
|
|
89
|
+
function normalizeShorthand(pluginConfig, pluginType) {
|
|
90
|
+
var _a;
|
|
91
|
+
if (typeof pluginConfig === 'string') {
|
|
92
|
+
return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
|
|
93
|
+
}
|
|
94
|
+
else if (Array.isArray(pluginConfig) &&
|
|
95
|
+
typeof pluginConfig[0] === 'string') {
|
|
96
|
+
return [
|
|
97
|
+
(0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
|
|
98
|
+
(_a = pluginConfig[1]) !== null && _a !== void 0 ? _a : {},
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
return pluginConfig;
|
|
102
|
+
}
|
|
103
|
+
presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
104
|
+
presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
|
|
105
|
+
const standalonePlugins = (siteConfig.plugins || []).map((plugin) => normalizeShorthand(plugin, 'plugin'));
|
|
106
|
+
const standaloneThemes = (siteConfig.themes || []).map((theme) => normalizeShorthand(theme, 'theme'));
|
|
87
107
|
return [
|
|
88
108
|
...presetPlugins,
|
|
89
109
|
...presetThemes,
|
|
90
110
|
// Site config should be the highest priority.
|
|
91
|
-
...
|
|
92
|
-
...
|
|
111
|
+
...standalonePlugins,
|
|
112
|
+
...standaloneThemes,
|
|
93
113
|
];
|
|
94
114
|
}
|
|
95
115
|
exports.loadPluginConfigs = loadPluginConfigs;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Plugins.
|
|
101
|
-
const pluginConfigs = loadPluginConfigs(context);
|
|
102
|
-
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
|
|
103
|
-
pluginConfigs,
|
|
104
|
-
context,
|
|
105
|
-
});
|
|
106
|
-
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
107
|
-
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
108
|
-
duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
|
|
109
|
-
// Site config must be generated after plugins
|
|
110
|
-
// We want the generated config to have been normalized by the plugins!
|
|
111
|
-
const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
|
|
112
|
-
// Themes.
|
|
113
|
-
const fallbackTheme = path_1.default.resolve(__dirname, '../client/theme-fallback');
|
|
114
|
-
const pluginThemes = plugins
|
|
115
|
-
.map((plugin) => plugin.getThemePath && plugin.getThemePath())
|
|
116
|
-
.filter((x) => Boolean(x));
|
|
117
|
-
const userTheme = path_1.default.resolve(siteDir, constants_1.THEME_PATH);
|
|
118
|
-
const alias = themes_1.default([fallbackTheme, ...pluginThemes], [userTheme]);
|
|
119
|
-
// Make a fake plugin to:
|
|
120
|
-
// - Resolve aliased theme components
|
|
121
|
-
// - Inject scripts/stylesheets
|
|
116
|
+
// Make a fake plugin to:
|
|
117
|
+
// - Resolve aliased theme components
|
|
118
|
+
// - Inject scripts/stylesheets
|
|
119
|
+
function createBootstrapPlugin({ siteConfig, }) {
|
|
122
120
|
const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
|
|
123
|
-
|
|
121
|
+
return {
|
|
124
122
|
name: 'docusaurus-bootstrap-plugin',
|
|
123
|
+
content: null,
|
|
125
124
|
options: {},
|
|
126
125
|
version: { type: 'synthetic' },
|
|
127
126
|
getClientModules() {
|
|
128
127
|
return siteConfigClientModules;
|
|
129
128
|
},
|
|
130
|
-
configureWebpack: () => ({
|
|
131
|
-
resolve: {
|
|
132
|
-
alias,
|
|
133
|
-
},
|
|
134
|
-
}),
|
|
135
129
|
injectHtmlTags: () => {
|
|
136
130
|
const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
|
|
137
131
|
? `<link rel="stylesheet" href="${source}">`
|
|
@@ -154,39 +148,103 @@ async function load(siteDir, options = {}) {
|
|
|
154
148
|
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
155
149
|
};
|
|
156
150
|
},
|
|
157
|
-
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Configurer Webpack fallback mdx loader for md/mdx files out of content-plugin folders
|
|
154
|
+
// Adds a "fallback" mdx loader for mdx files that are not processed by content plugins
|
|
155
|
+
// This allows to do things such as importing repo/README.md as a partial from another doc
|
|
156
|
+
// Not ideal solution though, but good enough for now
|
|
157
|
+
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
158
|
+
return {
|
|
159
|
+
name: 'docusaurus-mdx-fallback-plugin',
|
|
160
|
+
content: null,
|
|
161
|
+
options: {},
|
|
162
|
+
version: { type: 'synthetic' },
|
|
163
|
+
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
+
// We need the mdx fallback loader to exclude files that were already processed by content plugins mdx loaders
|
|
165
|
+
// This works, but a bit hacky...
|
|
166
|
+
// Not sure there's a way to handle that differently in webpack :s
|
|
167
|
+
function getMDXFallbackExcludedPaths() {
|
|
168
|
+
var _a;
|
|
169
|
+
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
170
|
+
return rules.flatMap((rule) => {
|
|
171
|
+
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
172
|
+
return isMDXRule ? rule.include : [];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
module: {
|
|
177
|
+
rules: [
|
|
178
|
+
{
|
|
179
|
+
test: /(\.mdx?)$/,
|
|
180
|
+
exclude: getMDXFallbackExcludedPaths(),
|
|
181
|
+
use: [
|
|
182
|
+
getJSLoader({ isServer }),
|
|
183
|
+
{
|
|
184
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
185
|
+
options: {
|
|
186
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
187
|
+
siteDir,
|
|
188
|
+
isMDXPartial: (_filename) => true,
|
|
189
|
+
isMDXPartialFrontMatterWarningDisabled: true,
|
|
190
|
+
remarkPlugins: [remark_admonitions_1.default],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async function load(siteDir, options = {}) {
|
|
202
|
+
// Context.
|
|
203
|
+
const context = await loadContext(siteDir, options);
|
|
204
|
+
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
|
|
205
|
+
// Plugins.
|
|
206
|
+
const pluginConfigs = loadPluginConfigs(context);
|
|
207
|
+
const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
|
|
208
|
+
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
209
|
+
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
210
|
+
(0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
|
|
211
|
+
// Site config must be generated after plugins
|
|
212
|
+
// We want the generated config to have been normalized by the plugins!
|
|
213
|
+
const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
|
|
214
|
+
plugins.push(createBootstrapPlugin({ siteConfig }));
|
|
215
|
+
plugins.push(createMDXFallbackPlugin({ siteDir, siteConfig }));
|
|
158
216
|
// Load client modules.
|
|
159
|
-
const clientModules = client_modules_1.default(plugins);
|
|
160
|
-
const genClientModules = utils_1.generate(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
|
|
217
|
+
const clientModules = (0, client_modules_1.default)(plugins);
|
|
218
|
+
const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
|
|
161
219
|
// import() is async so we use require() because client modules can have
|
|
162
220
|
// CSS and the order matters for loading CSS.
|
|
163
221
|
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
164
222
|
.map((module) => ` require(${JSON.stringify(module)}),`)
|
|
165
223
|
.join('\n')}\n];\n`);
|
|
166
224
|
// Load extra head & body html tags.
|
|
167
|
-
const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
|
|
225
|
+
const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
|
|
168
226
|
// Routing.
|
|
169
|
-
const { registry, routesChunkNames, routesConfig, routesPaths
|
|
170
|
-
const genRegistry = utils_1.generate(generatedFilesDir, 'registry.js', `export default {
|
|
227
|
+
const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
|
|
228
|
+
const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
|
|
171
229
|
${Object.keys(registry)
|
|
172
230
|
.sort()
|
|
173
231
|
.map((key) =>
|
|
174
232
|
// We need to JSON.stringify so that if its on windows, backslash are escaped.
|
|
175
233
|
` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
|
|
176
234
|
.join('\n')}};\n`);
|
|
177
|
-
const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
178
|
-
const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
|
|
179
|
-
const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
180
|
-
const genI18n = utils_1.generate(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
235
|
+
const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
236
|
+
const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
|
|
237
|
+
const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
238
|
+
const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
181
239
|
const codeTranslationsWithFallbacks = {
|
|
182
|
-
...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
|
|
240
|
+
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
183
241
|
...codeTranslations,
|
|
184
242
|
};
|
|
185
|
-
const genCodeTranslations = utils_1.generate(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
243
|
+
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
|
|
186
244
|
// Version metadata.
|
|
187
245
|
const siteMetadata = {
|
|
188
|
-
docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
|
|
189
|
-
siteVersion: versions_1.getPackageJsonVersion(path_1.join(siteDir, 'package.json')),
|
|
246
|
+
docusaurusVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(__dirname, '../../package.json')),
|
|
247
|
+
siteVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(siteDir, 'package.json')),
|
|
190
248
|
pluginVersions: {},
|
|
191
249
|
};
|
|
192
250
|
plugins
|
|
@@ -195,7 +253,7 @@ ${Object.keys(registry)
|
|
|
195
253
|
siteMetadata.pluginVersions[name] = version;
|
|
196
254
|
});
|
|
197
255
|
checkDocusaurusPackagesVersion(siteMetadata);
|
|
198
|
-
const genSiteMetadata = utils_1.generate(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
256
|
+
const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
199
257
|
await Promise.all([
|
|
200
258
|
genClientModules,
|
|
201
259
|
genSiteConfig,
|
package/lib/server/loadSetup.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
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
|
const loadSetup = async (name) => {
|
|
@@ -16,10 +16,10 @@ const loadSetup = async (name) => {
|
|
|
16
16
|
const customSite = path_1.default.join(fixtures, 'custom-site');
|
|
17
17
|
switch (name) {
|
|
18
18
|
case 'custom':
|
|
19
|
-
return index_1.load(customSite);
|
|
19
|
+
return (0, index_1.load)(customSite);
|
|
20
20
|
case 'simple':
|
|
21
21
|
default:
|
|
22
|
-
return index_1.load(simpleSite);
|
|
22
|
+
return (0, index_1.load)(simpleSite);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
exports.default = loadSetup;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
8
|
+
export declare function getNamePatterns(moduleName: string, moduleType: 'preset' | 'theme' | 'plugin'): string[];
|
|
9
|
+
export declare function resolveModuleName(moduleName: string, moduleRequire: NodeRequire, moduleType: 'preset' | 'theme' | 'plugin'): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
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(/\/(.*)/);
|
|
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
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
32
|
+
for (const module of modulePatterns) {
|
|
33
|
+
try {
|
|
34
|
+
moduleRequire.resolve(module);
|
|
35
|
+
return module;
|
|
36
|
+
}
|
|
37
|
+
catch (e) { }
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
|
|
40
|
+
${modulePatterns.map((module) => `- ${module}`).join('\n')}`);
|
|
41
|
+
}
|
|
42
|
+
exports.resolveModuleName = resolveModuleName;
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { RouteConfig } from '@docusaurus/types';
|
|
8
|
-
|
|
8
|
+
import { ApplyTrailingSlashParams } from '@docusaurus/utils-common';
|
|
9
|
+
export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
10
|
-
function applyRouteTrailingSlash(route,
|
|
10
|
+
function applyRouteTrailingSlash(route, params) {
|
|
11
11
|
return {
|
|
12
12
|
...route,
|
|
13
|
-
path: utils_common_1.applyTrailingSlash(route.path,
|
|
13
|
+
path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
|
|
14
14
|
...(route.routes && {
|
|
15
|
-
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute,
|
|
15
|
+
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
|
|
16
16
|
}),
|
|
17
17
|
};
|
|
18
18
|
}
|
|
@@ -4,14 +4,13 @@
|
|
|
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, RouteConfig, ThemeConfig } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
export declare function sortConfig(routeConfigs: RouteConfig[]): void;
|
|
7
|
+
import { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
|
|
10
9
|
export declare function loadPlugins({ pluginConfigs, context, }: {
|
|
11
10
|
pluginConfigs: PluginConfig[];
|
|
12
11
|
context: LoadContext;
|
|
13
12
|
}): Promise<{
|
|
14
|
-
plugins:
|
|
13
|
+
plugins: LoadedPlugin[];
|
|
15
14
|
pluginsRouteConfigs: RouteConfig[];
|
|
16
15
|
globalData: unknown;
|
|
17
16
|
themeConfigTranslated: ThemeConfig;
|
|
@@ -9,18 +9,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.loadPlugins = exports.sortConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const init_1 = tslib_1.__importDefault(require("./init"));
|
|
15
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
16
|
-
const constants_1 = require("../../constants");
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
const init_1 = (0, tslib_1.__importDefault)(require("./init"));
|
|
15
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
17
16
|
const lodash_1 = require("lodash");
|
|
18
17
|
const translations_1 = require("../translations/translations");
|
|
19
|
-
const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
|
|
20
|
-
function sortConfig(routeConfigs) {
|
|
18
|
+
const applyRouteTrailingSlash_1 = (0, tslib_1.__importDefault)(require("./applyRouteTrailingSlash"));
|
|
19
|
+
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
21
20
|
// Sort the route config. This ensures that route with nested
|
|
22
21
|
// routes is always placed last.
|
|
23
22
|
routeConfigs.sort((a, b) => {
|
|
23
|
+
// Root route should get placed last.
|
|
24
|
+
if (a.path === baseUrl && b.path !== baseUrl) {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
if (a.path !== baseUrl && b.path === baseUrl) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
24
30
|
if (a.routes && !b.routes) {
|
|
25
31
|
return 1;
|
|
26
32
|
}
|
|
@@ -46,60 +52,65 @@ function sortConfig(routeConfigs) {
|
|
|
46
52
|
exports.sortConfig = sortConfig;
|
|
47
53
|
async function loadPlugins({ pluginConfigs, context, }) {
|
|
48
54
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
|
49
|
-
const plugins = init_1.default({
|
|
55
|
+
const plugins = (0, init_1.default)({
|
|
50
56
|
pluginConfigs,
|
|
51
57
|
context,
|
|
52
58
|
});
|
|
53
|
-
|
|
59
|
+
// 2. Plugin Lifecycle - loadContent.
|
|
60
|
+
// Currently plugins run lifecycle methods in parallel and are not order-dependent.
|
|
61
|
+
// We could change this in future if there are plugins which need to
|
|
62
|
+
// run in certain order or depend on others for data.
|
|
63
|
+
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
54
64
|
const content = plugin.loadContent ? await plugin.loadContent() : null;
|
|
55
|
-
return { plugin, content };
|
|
65
|
+
return { ...plugin, content };
|
|
56
66
|
}));
|
|
57
|
-
const contentLoadedTranslatedPlugins = await Promise.all(
|
|
58
|
-
var _a, _b
|
|
59
|
-
const translationFiles = (
|
|
67
|
+
const contentLoadedTranslatedPlugins = await Promise.all(loadedPlugins.map(async (contentLoadedPlugin) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
|
|
60
70
|
content: contentLoadedPlugin.content,
|
|
61
|
-
})))) !== null &&
|
|
62
|
-
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
|
|
71
|
+
})))) !== null && _b !== void 0 ? _b : [];
|
|
72
|
+
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
63
73
|
locale: context.i18n.currentLocale,
|
|
64
74
|
siteDir: context.siteDir,
|
|
65
75
|
translationFile,
|
|
66
|
-
plugin: contentLoadedPlugin
|
|
76
|
+
plugin: contentLoadedPlugin,
|
|
67
77
|
})));
|
|
68
78
|
return {
|
|
69
79
|
...contentLoadedPlugin,
|
|
70
80
|
translationFiles: localizedTranslationFiles,
|
|
71
81
|
};
|
|
72
82
|
}));
|
|
73
|
-
const allContent = lodash_1.chain(
|
|
74
|
-
.groupBy((item) => item.
|
|
75
|
-
.mapValues((nameItems) =>
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.value();
|
|
80
|
-
})
|
|
83
|
+
const allContent = (0, lodash_1.chain)(loadedPlugins)
|
|
84
|
+
.groupBy((item) => item.name)
|
|
85
|
+
.mapValues((nameItems) => (0, lodash_1.chain)(nameItems)
|
|
86
|
+
.groupBy((item) => { var _a; return (_a = item.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; })
|
|
87
|
+
.mapValues((idItems) => idItems[0].content)
|
|
88
|
+
.value())
|
|
81
89
|
.value();
|
|
82
90
|
// 3. Plugin Lifecycle - contentLoaded.
|
|
83
91
|
const pluginsRouteConfigs = [];
|
|
84
92
|
const globalData = {};
|
|
85
|
-
await Promise.all(contentLoadedTranslatedPlugins.map(async ({
|
|
93
|
+
await Promise.all(contentLoadedTranslatedPlugins.map(async ({ content, translationFiles, ...plugin }) => {
|
|
86
94
|
var _a, _b, _c;
|
|
87
95
|
if (!plugin.contentLoaded) {
|
|
88
96
|
return;
|
|
89
97
|
}
|
|
90
|
-
const pluginId = (_a = plugin.options.id) !== null && _a !== void 0 ? _a :
|
|
98
|
+
const pluginId = (_a = plugin.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID;
|
|
91
99
|
// plugins data files are namespaced by pluginName/pluginId
|
|
92
100
|
const dataDirRoot = path_1.default.join(context.generatedFilesDir, plugin.name);
|
|
93
101
|
const dataDir = path_1.default.join(dataDirRoot, pluginId);
|
|
94
102
|
const addRoute = (initialRouteConfig) => {
|
|
95
103
|
// Trailing slash behavior is handled in a generic way for all plugins
|
|
96
|
-
const finalRouteConfig = applyRouteTrailingSlash_1.default(initialRouteConfig,
|
|
104
|
+
const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
|
|
105
|
+
trailingSlash: context.siteConfig.trailingSlash,
|
|
106
|
+
baseUrl: context.siteConfig.baseUrl,
|
|
107
|
+
});
|
|
97
108
|
pluginsRouteConfigs.push(finalRouteConfig);
|
|
98
109
|
};
|
|
99
110
|
const createData = async (name, data) => {
|
|
100
111
|
const modulePath = path_1.default.join(dataDir, name);
|
|
101
112
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
|
|
102
|
-
await utils_1.generate(dataDir, name, data);
|
|
113
|
+
await (0, utils_1.generate)(dataDir, name, data);
|
|
103
114
|
return modulePath;
|
|
104
115
|
};
|
|
105
116
|
// the plugins global data are namespaced to avoid data conflicts:
|
|
@@ -126,7 +137,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
126
137
|
// Currently plugins run lifecycle methods in parallel and are not order-dependent.
|
|
127
138
|
// We could change this in future if there are plugins which need to
|
|
128
139
|
// run in certain order or depend on others for data.
|
|
129
|
-
await Promise.all(contentLoadedTranslatedPlugins.map(async (
|
|
140
|
+
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
130
141
|
if (!plugin.routesLoaded) {
|
|
131
142
|
return null;
|
|
132
143
|
}
|
|
@@ -138,14 +149,14 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
138
149
|
}));
|
|
139
150
|
// Sort the route config. This ensures that route with nested
|
|
140
151
|
// routes are always placed last.
|
|
141
|
-
sortConfig(pluginsRouteConfigs);
|
|
152
|
+
sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
|
142
153
|
// Apply each plugin one after the other to translate the theme config
|
|
143
154
|
function translateThemeConfig(untranslatedThemeConfig) {
|
|
144
|
-
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig,
|
|
155
|
+
return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
145
156
|
var _a;
|
|
146
157
|
const translatedThemeConfigSlice = (_a = plugin.translateThemeConfig) === null || _a === void 0 ? void 0 : _a.call(plugin, {
|
|
147
158
|
themeConfig: currentThemeConfig,
|
|
148
|
-
translationFiles,
|
|
159
|
+
translationFiles: plugin.translationFiles,
|
|
149
160
|
});
|
|
150
161
|
return {
|
|
151
162
|
...currentThemeConfig,
|
|
@@ -154,7 +165,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
154
165
|
}, untranslatedThemeConfig);
|
|
155
166
|
}
|
|
156
167
|
return {
|
|
157
|
-
plugins,
|
|
168
|
+
plugins: loadedPlugins,
|
|
158
169
|
pluginsRouteConfigs,
|
|
159
170
|
globalData,
|
|
160
171
|
themeConfigTranslated: translateThemeConfig(context.siteConfig.themeConfig),
|
|
@@ -4,12 +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 {
|
|
8
|
-
export declare type InitPlugin = Plugin<unknown> & {
|
|
9
|
-
readonly options: PluginOptions;
|
|
10
|
-
readonly version: DocusaurusPluginVersionInformation;
|
|
11
|
-
};
|
|
7
|
+
import { LoadContext, PluginConfig, InitializedPlugin } from '@docusaurus/types';
|
|
12
8
|
export default function initPlugins({ pluginConfigs, context, }: {
|
|
13
9
|
pluginConfigs: PluginConfig[];
|
|
14
10
|
context: LoadContext;
|
|
15
|
-
}):
|
|
11
|
+
}): InitializedPlugin[];
|