@docusaurus/core 0.0.0-4798 → 0.0.0-4799

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.
Files changed (54) hide show
  1. package/lib/commands/build.d.ts +1 -1
  2. package/lib/commands/build.js +2 -1
  3. package/lib/commands/clear.d.ts +1 -1
  4. package/lib/commands/clear.js +2 -1
  5. package/lib/commands/deploy.d.ts +1 -1
  6. package/lib/commands/deploy.js +4 -3
  7. package/lib/commands/external.d.ts +1 -1
  8. package/lib/commands/external.js +4 -5
  9. package/lib/commands/serve.d.ts +1 -1
  10. package/lib/commands/serve.js +4 -3
  11. package/lib/commands/start.d.ts +1 -1
  12. package/lib/commands/start.js +2 -1
  13. package/lib/commands/swizzle/context.js +4 -7
  14. package/lib/commands/swizzle/index.d.ts +1 -1
  15. package/lib/commands/swizzle/index.js +2 -1
  16. package/lib/commands/writeHeadingIds.d.ts +1 -1
  17. package/lib/commands/writeHeadingIds.js +4 -7
  18. package/lib/commands/writeTranslations.d.ts +1 -1
  19. package/lib/commands/writeTranslations.js +4 -7
  20. package/lib/index.d.ts +9 -10
  21. package/lib/index.js +18 -19
  22. package/lib/server/{client-modules/index.d.ts → clientModules.d.ts} +1 -1
  23. package/lib/server/{client-modules/index.js → clientModules.js} +2 -1
  24. package/lib/server/config.d.ts +1 -1
  25. package/lib/server/config.js +2 -1
  26. package/lib/server/{html-tags/index.d.ts → htmlTags.d.ts} +0 -0
  27. package/lib/server/htmlTags.js +58 -0
  28. package/lib/server/i18n.d.ts +0 -8
  29. package/lib/server/i18n.js +1 -18
  30. package/lib/server/index.d.ts +1 -2
  31. package/lib/server/index.js +15 -173
  32. package/lib/server/{html-tags/htmlTags.d.ts → plugins/configs.d.ts} +2 -1
  33. package/lib/server/plugins/configs.js +42 -0
  34. package/lib/server/plugins/index.d.ts +2 -6
  35. package/lib/server/plugins/index.js +9 -43
  36. package/lib/server/plugins/init.d.ts +1 -4
  37. package/lib/server/plugins/init.js +7 -5
  38. package/lib/server/{presets/index.d.ts → plugins/presets.d.ts} +1 -1
  39. package/lib/server/{presets/index.js → plugins/presets.js} +2 -1
  40. package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +2 -1
  41. package/lib/server/plugins/routeConfig.js +53 -0
  42. package/lib/server/plugins/synthetic.d.ts +20 -0
  43. package/lib/server/plugins/synthetic.js +112 -0
  44. package/lib/server/routes.d.ts +1 -1
  45. package/lib/server/routes.js +2 -1
  46. package/lib/server/{versions/index.d.ts → siteMetadata.d.ts} +5 -2
  47. package/lib/server/{versions/index.js → siteMetadata.js} +34 -2
  48. package/lib/server/themes/alias.d.ts +1 -1
  49. package/lib/server/themes/alias.js +2 -2
  50. package/lib/server/themes/index.js +3 -3
  51. package/package.json +10 -10
  52. package/lib/server/html-tags/htmlTags.js +0 -38
  53. package/lib/server/html-tags/index.js +0 -42
  54. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
@@ -6,29 +6,24 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.load = exports.loadPluginConfigs = exports.loadContext = exports.loadSiteConfig = void 0;
9
+ exports.load = exports.loadContext = exports.loadSiteConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
13
  const path_1 = tslib_1.__importDefault(require("path"));
13
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
14
  const ssr_html_template_1 = tslib_1.__importDefault(require("../webpack/templates/ssr.html.template"));
15
- const client_modules_1 = tslib_1.__importDefault(require("./client-modules"));
16
- const config_1 = tslib_1.__importDefault(require("./config"));
15
+ const clientModules_1 = require("./clientModules");
16
+ const config_1 = require("./config");
17
17
  const plugins_1 = require("./plugins");
18
- const presets_1 = tslib_1.__importDefault(require("./presets"));
19
- const routes_1 = tslib_1.__importDefault(require("./routes"));
20
- const html_tags_1 = require("./html-tags");
21
- const versions_1 = require("./versions");
18
+ const routes_1 = require("./routes");
19
+ const htmlTags_1 = require("./htmlTags");
20
+ const siteMetadata_1 = require("./siteMetadata");
22
21
  const duplicateRoutes_1 = require("./duplicateRoutes");
23
22
  const i18n_1 = require("./i18n");
24
23
  const translations_1 = require("./translations/translations");
25
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
26
- const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
27
- const module_1 = require("module");
28
- const moduleShorthand_1 = require("./moduleShorthand");
29
24
  async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
30
25
  const siteConfigPath = path_1.default.resolve(siteDir, customConfigFilePath ?? utils_1.DEFAULT_CONFIG_FILE_NAME);
31
- const siteConfig = await (0, config_1.default)(siteConfigPath);
26
+ const siteConfig = await (0, config_1.loadConfig)(siteConfigPath);
32
27
  return { siteConfig, siteConfigPath };
33
28
  }
34
29
  exports.loadSiteConfig = loadSiteConfig;
@@ -42,13 +37,13 @@ async function loadContext(siteDir, options = {}) {
42
37
  const { ssrTemplate } = initialSiteConfig;
43
38
  const baseOutDir = path_1.default.resolve(siteDir, customOutDir ?? utils_1.DEFAULT_BUILD_DIR_NAME);
44
39
  const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
45
- const baseUrl = (0, i18n_1.localizePath)({
40
+ const baseUrl = (0, utils_1.localizePath)({
46
41
  path: initialSiteConfig.baseUrl,
47
42
  i18n,
48
43
  options,
49
44
  pathType: 'url',
50
45
  });
51
- const outDir = (0, i18n_1.localizePath)({
46
+ const outDir = (0, utils_1.localizePath)({
52
47
  path: baseOutDir,
53
48
  i18n,
54
49
  options,
@@ -74,136 +69,12 @@ async function loadContext(siteDir, options = {}) {
74
69
  };
75
70
  }
76
71
  exports.loadContext = loadContext;
77
- async function loadPluginConfigs(context) {
78
- let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
79
- const { siteConfig, siteConfigPath } = context;
80
- const require = (0, module_1.createRequire)(siteConfigPath);
81
- function normalizeShorthand(pluginConfig, pluginType) {
82
- if (typeof pluginConfig === 'string') {
83
- return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
84
- }
85
- else if (Array.isArray(pluginConfig) &&
86
- typeof pluginConfig[0] === 'string') {
87
- return [
88
- (0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
89
- pluginConfig[1] ?? {},
90
- ];
91
- }
92
- return pluginConfig;
93
- }
94
- presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
95
- presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
96
- const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
97
- const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
98
- return [
99
- ...presetPlugins,
100
- ...presetThemes,
101
- // Site config should be the highest priority.
102
- ...standalonePlugins,
103
- ...standaloneThemes,
104
- ];
105
- }
106
- exports.loadPluginConfigs = loadPluginConfigs;
107
- // Make a fake plugin to:
108
- // - Resolve aliased theme components
109
- // - Inject scripts/stylesheets
110
- function createBootstrapPlugin({ siteDir, siteConfig, }) {
111
- const { stylesheets, scripts, clientModules: siteConfigClientModules, } = siteConfig;
112
- return {
113
- name: 'docusaurus-bootstrap-plugin',
114
- content: null,
115
- options: {
116
- id: 'default',
117
- },
118
- version: { type: 'synthetic' },
119
- path: siteDir,
120
- getClientModules() {
121
- return siteConfigClientModules;
122
- },
123
- injectHtmlTags: () => {
124
- const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
125
- ? `<link rel="stylesheet" href="${source}">`
126
- : {
127
- tagName: 'link',
128
- attributes: {
129
- rel: 'stylesheet',
130
- ...source,
131
- },
132
- });
133
- const scriptsTags = scripts.map((source) => typeof source === 'string'
134
- ? `<script src="${source}"></script>`
135
- : {
136
- tagName: 'script',
137
- attributes: {
138
- ...source,
139
- },
140
- });
141
- return {
142
- headTags: [...stylesheetsTags, ...scriptsTags],
143
- };
144
- },
145
- };
146
- }
147
- /**
148
- * Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
149
- * folders. Adds a "fallback" mdx loader for mdx files that are not processed by
150
- * content plugins. This allows to do things such as importing repo/README.md as
151
- * a partial from another doc. Not ideal solution, but good enough for now
152
- */
153
- function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
154
- return {
155
- name: 'docusaurus-mdx-fallback-plugin',
156
- content: null,
157
- options: {
158
- id: 'default',
159
- },
160
- version: { type: 'synthetic' },
161
- // Synthetic, the path doesn't matter much
162
- path: '.',
163
- configureWebpack(config, isServer, { getJSLoader }) {
164
- // We need the mdx fallback loader to exclude files that were already
165
- // processed by content plugins mdx loaders. This works, but a bit
166
- // hacky... Not sure there's a way to handle that differently in webpack
167
- function getMDXFallbackExcludedPaths() {
168
- const rules = config?.module?.rules;
169
- return rules.flatMap((rule) => {
170
- const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
171
- return isMDXRule ? rule.include : [];
172
- });
173
- }
174
- return {
175
- module: {
176
- rules: [
177
- {
178
- test: /\.mdx?$/i,
179
- exclude: getMDXFallbackExcludedPaths(),
180
- use: [
181
- getJSLoader({ isServer }),
182
- {
183
- loader: require.resolve('@docusaurus/mdx-loader'),
184
- options: {
185
- staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
186
- siteDir,
187
- isMDXPartial: () => true,
188
- isMDXPartialFrontMatterWarningDisabled: true,
189
- remarkPlugins: [remark_admonitions_1.default],
190
- },
191
- },
192
- ],
193
- },
194
- ],
195
- },
196
- };
197
- },
198
- };
199
- }
200
72
  async function load(siteDir, options = {}) {
201
73
  // Context.
202
74
  const context = await loadContext(siteDir, options);
203
75
  const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
204
76
  // Plugins.
205
- const pluginConfigs = await loadPluginConfigs(context);
206
- const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
77
+ const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)(context);
207
78
  // Side-effect to replace the untranslated themeConfig by the translated one
208
79
  context.siteConfig.themeConfig = themeConfigTranslated;
209
80
  (0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
@@ -222,9 +93,8 @@ next build. You can clear all build artifacts (including this folder) with the
222
93
  */
223
94
  export default ${JSON.stringify(siteConfig, null, 2)};
224
95
  `);
225
- plugins.push(createBootstrapPlugin({ siteDir, siteConfig }), createMDXFallbackPlugin({ siteDir, siteConfig }));
226
96
  // Load client modules.
227
- const clientModules = (0, client_modules_1.default)(plugins);
97
+ const clientModules = (0, clientModules_1.loadClientModules)(plugins);
228
98
  const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
229
99
  ${clientModules
230
100
  // import() is async so we use require() because client modules can have
@@ -234,9 +104,9 @@ ${clientModules
234
104
  ];
235
105
  `);
236
106
  // Load extra head & body html tags.
237
- const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
107
+ const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
238
108
  // Routing.
239
- const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
109
+ const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl);
240
110
  const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
241
111
  ${Object.entries(registry)
242
112
  .sort((a, b) => a[0].localeCompare(b[0]))
@@ -253,17 +123,7 @@ ${Object.entries(registry)
253
123
  };
254
124
  const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
255
125
  // Version metadata.
256
- const siteMetadata = {
257
- docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
258
- siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
259
- pluginVersions: {},
260
- };
261
- plugins
262
- .filter(({ version: { type } }) => type !== 'synthetic')
263
- .forEach(({ name, version }) => {
264
- siteMetadata.pluginVersions[name] = version;
265
- });
266
- checkDocusaurusPackagesVersion(siteMetadata);
126
+ const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
267
127
  const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
268
128
  await Promise.all([
269
129
  genWarning,
@@ -298,21 +158,3 @@ ${Object.entries(registry)
298
158
  return props;
299
159
  }
300
160
  exports.load = load;
301
- // We want all @docusaurus/* packages to have the exact same version!
302
- // See https://github.com/facebook/docusaurus/issues/3371
303
- // See https://github.com/facebook/docusaurus/pull/3386
304
- function checkDocusaurusPackagesVersion(siteMetadata) {
305
- const { docusaurusVersion } = siteMetadata;
306
- Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
307
- if (versionInfo.type === 'package' &&
308
- versionInfo.name?.startsWith('@docusaurus/') &&
309
- versionInfo.version &&
310
- versionInfo.version !== docusaurusVersion) {
311
- // should we throw instead?
312
- // It still could work with different versions
313
- logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
314
- All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
315
- Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
316
- }
317
- });
318
- }
@@ -4,4 +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
- export default function htmlTagObjectToString(tagDefinition: unknown): string;
7
+ import type { LoadContext, PluginConfig } from '@docusaurus/types';
8
+ export declare function loadPluginConfigs(context: LoadContext): Promise<PluginConfig[]>;
@@ -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.loadPluginConfigs = void 0;
10
+ const module_1 = require("module");
11
+ const presets_1 = require("./presets");
12
+ const moduleShorthand_1 = require("../moduleShorthand");
13
+ async function loadPluginConfigs(context) {
14
+ const preset = await (0, presets_1.loadPresets)(context);
15
+ const { siteConfig, siteConfigPath } = context;
16
+ const require = (0, module_1.createRequire)(siteConfigPath);
17
+ function normalizeShorthand(pluginConfig, pluginType) {
18
+ if (typeof pluginConfig === 'string') {
19
+ return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
20
+ }
21
+ else if (Array.isArray(pluginConfig) &&
22
+ typeof pluginConfig[0] === 'string') {
23
+ return [
24
+ (0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
25
+ pluginConfig[1] ?? {},
26
+ ];
27
+ }
28
+ return pluginConfig;
29
+ }
30
+ preset.plugins = preset.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
31
+ preset.themes = preset.themes.map((theme) => normalizeShorthand(theme, 'theme'));
32
+ const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
33
+ const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
34
+ return [
35
+ ...preset.plugins,
36
+ ...preset.themes,
37
+ // Site config should be the highest priority.
38
+ ...standalonePlugins,
39
+ ...standaloneThemes,
40
+ ];
41
+ }
42
+ exports.loadPluginConfigs = loadPluginConfigs;
@@ -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 type { LoadContext, PluginConfig, RouteConfig, GlobalData, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
- export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
9
- export declare function loadPlugins({ pluginConfigs, context, }: {
10
- pluginConfigs: PluginConfig[];
11
- context: LoadContext;
12
- }): Promise<{
7
+ import type { LoadContext, RouteConfig, GlobalData, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
+ export declare function loadPlugins(context: LoadContext): Promise<{
13
9
  plugins: LoadedPlugin[];
14
10
  pluginsRouteConfigs: RouteConfig[];
15
11
  globalData: GlobalData;
@@ -6,55 +6,21 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadPlugins = exports.sortConfig = void 0;
9
+ exports.loadPlugins = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const path_1 = tslib_1.__importDefault(require("path"));
14
- const init_1 = tslib_1.__importDefault(require("./init"));
14
+ const init_1 = require("./init");
15
+ const synthetic_1 = require("./synthetic");
15
16
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
17
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
17
18
  const translations_1 = require("../translations/translations");
18
- const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
19
- function sortConfig(routeConfigs, baseUrl = '/') {
20
- // Sort the route config. This ensures that route with nested
21
- // routes is always placed last.
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
- }
30
- if (a.routes && !b.routes) {
31
- return 1;
32
- }
33
- if (!a.routes && b.routes) {
34
- return -1;
35
- }
36
- // Higher priority get placed first.
37
- if (a.priority || b.priority) {
38
- const priorityA = a.priority || 0;
39
- const priorityB = b.priority || 0;
40
- const score = priorityB - priorityA;
41
- if (score !== 0) {
42
- return score;
43
- }
44
- }
45
- return a.path.localeCompare(b.path);
46
- });
47
- routeConfigs.forEach((routeConfig) => {
48
- routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
49
- });
50
- }
51
- exports.sortConfig = sortConfig;
52
- async function loadPlugins({ pluginConfigs, context, }) {
19
+ const routeConfig_1 = require("./routeConfig");
20
+ async function loadPlugins(context) {
53
21
  // 1. Plugin Lifecycle - Initialization/Constructor.
54
- const plugins = await (0, init_1.default)({
55
- pluginConfigs,
56
- context,
57
- });
22
+ const plugins = await (0, init_1.initPlugins)(context);
23
+ plugins.push((0, synthetic_1.createBootstrapPlugin)(context), (0, synthetic_1.createMDXFallbackPlugin)(context));
58
24
  // 2. Plugin Lifecycle - loadContent.
59
25
  // Currently plugins run lifecycle methods in parallel and are not
60
26
  // order-dependent. We could change this in future if there are plugins which
@@ -111,7 +77,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
111
77
  const pluginRouteContextModulePath = await createData(`${(0, utils_1.docuHash)('pluginRouteContextModule')}.json`, JSON.stringify(pluginRouteContext, null, 2));
112
78
  const addRoute = (initialRouteConfig) => {
113
79
  // Trailing slash behavior is handled in a generic way for all plugins
114
- const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
80
+ const finalRouteConfig = (0, routeConfig_1.applyRouteTrailingSlash)(initialRouteConfig, {
115
81
  trailingSlash: context.siteConfig.trailingSlash,
116
82
  baseUrl: context.siteConfig.baseUrl,
117
83
  });
@@ -158,7 +124,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
158
124
  }));
159
125
  // Sort the route config. This ensures that route with nested
160
126
  // routes are always placed last.
161
- sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
127
+ (0, routeConfig_1.sortConfig)(pluginsRouteConfigs, context.siteConfig.baseUrl);
162
128
  // Apply each plugin one after the other to translate the theme config
163
129
  function translateThemeConfig(untranslatedThemeConfig) {
164
130
  return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
@@ -19,7 +19,4 @@ export declare type NormalizedPluginConfig = {
19
19
  entryPath: string;
20
20
  };
21
21
  export declare function normalizePluginConfigs(pluginConfigs: PluginConfig[], configPath: string): Promise<NormalizedPluginConfig[]>;
22
- export default function initPlugins({ pluginConfigs, context, }: {
23
- pluginConfigs: PluginConfig[];
24
- context: LoadContext;
25
- }): Promise<InitializedPlugin[]>;
22
+ export declare function initPlugins(context: LoadContext): Promise<InitializedPlugin[]>;
@@ -6,15 +6,16 @@
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
+ exports.initPlugins = exports.normalizePluginConfigs = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const module_1 = require("module");
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
- const versions_1 = require("../versions");
15
+ const siteMetadata_1 = require("../siteMetadata");
16
16
  const pluginIds_1 = require("./pluginIds");
17
17
  const utils_validation_1 = require("@docusaurus/utils-validation");
18
+ const configs_1 = require("./configs");
18
19
  async function normalizePluginConfig(pluginConfig, configPath) {
19
20
  const pluginRequire = (0, module_1.createRequire)(configPath);
20
21
  // plugins: ['./plugin']
@@ -86,16 +87,17 @@ function getThemeValidationFunction(normalizedPluginConfig) {
86
87
  }
87
88
  return normalizedPluginConfig.plugin.validateThemeConfig;
88
89
  }
89
- async function initPlugins({ pluginConfigs, context, }) {
90
+ async function initPlugins(context) {
90
91
  // We need to resolve plugins from the perspective of the siteDir, since the
91
92
  // siteDir's package.json declares the dependency on these plugins.
92
93
  const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
94
+ const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
93
95
  const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, context.siteConfigPath);
94
96
  async function doGetPluginVersion(normalizedPluginConfig) {
95
97
  // get plugin version
96
98
  if (normalizedPluginConfig.pluginModule?.path) {
97
99
  const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
98
- return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
100
+ return (0, siteMetadata_1.getPluginVersion)(pluginPath, context.siteDir);
99
101
  }
100
102
  return { type: 'local' };
101
103
  }
@@ -144,4 +146,4 @@ async function initPlugins({ pluginConfigs, context, }) {
144
146
  (0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
145
147
  return plugins;
146
148
  }
147
- exports.default = initPlugins;
149
+ exports.initPlugins = initPlugins;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { LoadContext, PluginConfig } from '@docusaurus/types';
8
- export default function loadPresets(context: LoadContext): Promise<{
8
+ export declare function loadPresets(context: LoadContext): Promise<{
9
9
  plugins: PluginConfig[];
10
10
  themes: PluginConfig[];
11
11
  }>;
@@ -6,6 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.loadPresets = void 0;
9
10
  const tslib_1 = require("tslib");
10
11
  const module_1 = require("module");
11
12
  const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
@@ -38,4 +39,4 @@ async function loadPresets(context) {
38
39
  });
39
40
  return { plugins, themes };
40
41
  }
41
- exports.default = loadPresets;
42
+ exports.loadPresets = loadPresets;
@@ -6,4 +6,5 @@
6
6
  */
7
7
  import type { RouteConfig } from '@docusaurus/types';
8
8
  import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
9
- export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
9
+ export declare function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
10
+ export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
@@ -0,0 +1,53 @@
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
+ function applyRouteTrailingSlash(route, params) {
12
+ return {
13
+ ...route,
14
+ path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
15
+ ...(route.routes && {
16
+ routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
17
+ }),
18
+ };
19
+ }
20
+ exports.applyRouteTrailingSlash = applyRouteTrailingSlash;
21
+ function sortConfig(routeConfigs, baseUrl = '/') {
22
+ // Sort the route config. This ensures that route with nested
23
+ // routes is always placed last.
24
+ routeConfigs.sort((a, b) => {
25
+ // Root route should get placed last.
26
+ if (a.path === baseUrl && b.path !== baseUrl) {
27
+ return 1;
28
+ }
29
+ if (a.path !== baseUrl && b.path === baseUrl) {
30
+ return -1;
31
+ }
32
+ if (a.routes && !b.routes) {
33
+ return 1;
34
+ }
35
+ if (!a.routes && b.routes) {
36
+ return -1;
37
+ }
38
+ // Higher priority get placed first.
39
+ if (a.priority || b.priority) {
40
+ const priorityA = a.priority || 0;
41
+ const priorityB = b.priority || 0;
42
+ const score = priorityB - priorityA;
43
+ if (score !== 0) {
44
+ return score;
45
+ }
46
+ }
47
+ return a.path.localeCompare(b.path);
48
+ });
49
+ routeConfigs.forEach((routeConfig) => {
50
+ routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
51
+ });
52
+ }
53
+ 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;