@docusaurus/core 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/bin/docusaurus.mjs +13 -12
  2. package/lib/babel/preset.js +1 -1
  3. package/lib/client/App.d.ts +0 -2
  4. package/lib/client/BaseUrlIssueBanner/index.d.ts +0 -1
  5. package/lib/client/BrokenLinksContext.d.ts +0 -1
  6. package/lib/client/SiteMetadataDefaults.d.ts +0 -1
  7. package/lib/client/exports/BrowserOnly.d.ts +0 -2
  8. package/lib/client/exports/ErrorBoundary.d.ts +0 -1
  9. package/lib/client/exports/Head.d.ts +0 -2
  10. package/lib/client/exports/Interpolate.d.ts +0 -1
  11. package/lib/client/exports/Link.d.ts +0 -1
  12. package/lib/client/exports/Link.js +15 -4
  13. package/lib/client/exports/Translate.d.ts +0 -2
  14. package/lib/client/exports/useBaseUrl.d.ts +0 -1
  15. package/lib/client/exports/useBrokenLinks.d.ts +0 -1
  16. package/lib/client/hasHydratedDataAttribute.d.ts +0 -1
  17. package/lib/client/theme-fallback/Error/index.d.ts +0 -2
  18. package/lib/client/theme-fallback/Layout/index.d.ts +0 -2
  19. package/lib/client/theme-fallback/Loading/index.d.ts +0 -1
  20. package/lib/client/theme-fallback/NotFound/index.d.ts +0 -1
  21. package/lib/client/theme-fallback/Root/index.d.ts +0 -2
  22. package/lib/client/theme-fallback/SiteMetadata/index.d.ts +0 -1
  23. package/lib/commands/build.js +1 -2
  24. package/lib/commands/clear.js +1 -2
  25. package/lib/commands/deploy.js +1 -2
  26. package/lib/commands/external.js +1 -2
  27. package/lib/commands/serve.js +2 -3
  28. package/lib/commands/start/start.js +1 -2
  29. package/lib/commands/start/utils.js +2 -3
  30. package/lib/commands/start/watcher.js +5 -6
  31. package/lib/commands/start/webpack.js +1 -2
  32. package/lib/commands/swizzle/actions.js +4 -4
  33. package/lib/commands/swizzle/common.js +7 -7
  34. package/lib/commands/swizzle/components.js +5 -6
  35. package/lib/commands/swizzle/config.js +2 -3
  36. package/lib/commands/swizzle/context.js +19 -8
  37. package/lib/commands/swizzle/index.js +1 -2
  38. package/lib/commands/swizzle/prompts.js +4 -5
  39. package/lib/commands/swizzle/tables.js +2 -3
  40. package/lib/commands/swizzle/themes.js +5 -6
  41. package/lib/commands/writeHeadingIds.js +1 -2
  42. package/lib/commands/writeTranslations.js +1 -2
  43. package/lib/server/brokenLinks.js +1 -2
  44. package/lib/server/clientModules.js +1 -2
  45. package/lib/server/codegen/codegen.js +1 -2
  46. package/lib/server/codegen/codegenRoutes.js +4 -5
  47. package/lib/server/config.js +1 -2
  48. package/lib/server/configValidation.js +2 -2
  49. package/lib/server/getHostPort.js +1 -2
  50. package/lib/server/htmlTags.js +1 -2
  51. package/lib/server/i18n.js +2 -3
  52. package/lib/server/plugins/actions.js +1 -2
  53. package/lib/server/plugins/configs.js +1 -2
  54. package/lib/server/plugins/init.d.ts +11 -0
  55. package/lib/server/plugins/init.js +42 -7
  56. package/lib/server/plugins/moduleShorthand.d.ts +0 -1
  57. package/lib/server/plugins/moduleShorthand.js +2 -3
  58. package/lib/server/plugins/pluginIds.js +1 -2
  59. package/lib/server/plugins/plugins.js +2 -3
  60. package/lib/server/plugins/pluginsUtils.js +7 -8
  61. package/lib/server/plugins/presets.js +1 -2
  62. package/lib/server/plugins/routeConfig.js +2 -3
  63. package/lib/server/plugins/synthetic.js +2 -3
  64. package/lib/server/routes.js +2 -3
  65. package/lib/server/site.js +4 -5
  66. package/lib/server/siteMetadata.js +3 -4
  67. package/lib/server/storage.js +1 -2
  68. package/lib/server/translations/translations.js +9 -10
  69. package/lib/server/translations/translationsExtractor.js +4 -5
  70. package/lib/server/utils.js +1 -2
  71. package/lib/ssg.d.ts +0 -1
  72. package/lib/ssg.js +3 -4
  73. package/lib/templates/templates.js +3 -4
  74. package/lib/webpack/aliases/index.js +4 -5
  75. package/lib/webpack/base.js +3 -3
  76. package/lib/webpack/client.js +3 -4
  77. package/lib/webpack/configure.js +3 -4
  78. package/lib/webpack/minification.js +1 -2
  79. package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.js +1 -2
  80. package/lib/webpack/server.js +1 -1
  81. package/lib/webpack/utils.d.ts +1 -2
  82. package/lib/webpack/utils.js +8 -8
  83. package/package.json +10 -10
@@ -6,19 +6,30 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.initSwizzleContext = void 0;
9
+ exports.initSwizzleContext = initSwizzleContext;
10
10
  const site_1 = require("../../server/site");
11
11
  const init_1 = require("../../server/plugins/init");
12
12
  const configs_1 = require("../../server/plugins/configs");
13
+ async function getSwizzlePlugins(context) {
14
+ const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
15
+ const pluginConfigInitResults = await (0, init_1.initPluginsConfigs)(context, pluginConfigs);
16
+ return pluginConfigInitResults.flatMap((initResult) => {
17
+ // Ignore self-disabling plugins returning null
18
+ if (initResult.plugin === null) {
19
+ return [];
20
+ }
21
+ return [
22
+ // TODO this is a bit confusing, need refactor
23
+ {
24
+ plugin: initResult.config,
25
+ instance: initResult.plugin,
26
+ },
27
+ ];
28
+ });
29
+ }
13
30
  async function initSwizzleContext(siteDir, options) {
14
31
  const context = await (0, site_1.loadContext)({ siteDir, config: options.config });
15
- const plugins = await (0, init_1.initPlugins)(context);
16
- const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
17
32
  return {
18
- plugins: plugins.map((plugin, pluginIndex) => ({
19
- plugin: pluginConfigs[pluginIndex],
20
- instance: plugin,
21
- })),
33
+ plugins: await getSwizzlePlugins(context),
22
34
  };
23
35
  }
24
- exports.initSwizzleContext = initSwizzleContext;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.swizzle = void 0;
9
+ exports.swizzle = swizzle;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -145,4 +145,3 @@ Ejected name=${componentName} from name=${themeName} to path=${result.createdFil
145
145
  await executeAction();
146
146
  return process.exit(0);
147
147
  }
148
- exports.swizzle = swizzle;
@@ -6,7 +6,10 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.askSwizzleAction = exports.askSwizzleDangerousComponent = exports.askComponentName = exports.askThemeName = void 0;
9
+ exports.askThemeName = askThemeName;
10
+ exports.askComponentName = askComponentName;
11
+ exports.askSwizzleDangerousComponent = askSwizzleDangerousComponent;
12
+ exports.askSwizzleAction = askSwizzleAction;
10
13
  const tslib_1 = require("tslib");
11
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
15
  const prompts_1 = tslib_1.__importDefault(require("prompts"));
@@ -26,7 +29,6 @@ async function askThemeName(themeNames) {
26
29
  }
27
30
  return themeName;
28
31
  }
29
- exports.askThemeName = askThemeName;
30
32
  async function askComponentName(themeComponents) {
31
33
  function formatComponentName(componentName) {
32
34
  const anySafe = themeComponents.hasAnySafeAction(componentName);
@@ -64,7 +66,6 @@ ${common_1.PartiallySafeHint} = not safe for all swizzle actions
64
66
  }
65
67
  return componentName;
66
68
  }
67
- exports.askComponentName = askComponentName;
68
69
  async function askSwizzleDangerousComponent() {
69
70
  const { switchToDanger } = (await (0, prompts_1.default)({
70
71
  type: 'select',
@@ -84,7 +85,6 @@ async function askSwizzleDangerousComponent() {
84
85
  }
85
86
  return !!switchToDanger;
86
87
  }
87
- exports.askSwizzleDangerousComponent = askSwizzleDangerousComponent;
88
88
  async function askSwizzleAction(componentConfig) {
89
89
  const { action } = (await (0, prompts_1.default)({
90
90
  type: 'select',
@@ -107,4 +107,3 @@ async function askSwizzleAction(componentConfig) {
107
107
  }
108
108
  return action;
109
109
  }
110
- exports.askSwizzleAction = askSwizzleAction;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.themeComponentsTable = exports.helpTables = void 0;
9
+ exports.helpTables = helpTables;
10
+ exports.themeComponentsTable = themeComponentsTable;
10
11
  const tslib_1 = require("tslib");
11
12
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
13
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -89,7 +90,6 @@ ${statusTable()}
89
90
 
90
91
  ${logger_1.default.bold('Swizzle guide')}: https://docusaurus.io/docs/swizzling`;
91
92
  }
92
- exports.helpTables = helpTables;
93
93
  function themeComponentsTable(themeComponents) {
94
94
  const table = new cli_table3_1.default({
95
95
  head: [
@@ -110,4 +110,3 @@ function themeComponentsTable(themeComponents) {
110
110
  ${table.toString()}
111
111
  `;
112
112
  }
113
- exports.themeComponentsTable = themeComponentsTable;
@@ -6,7 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getThemePath = exports.getThemeName = exports.getThemeNames = exports.getPluginByThemeName = exports.pluginToThemeName = void 0;
9
+ exports.pluginToThemeName = pluginToThemeName;
10
+ exports.getPluginByThemeName = getPluginByThemeName;
11
+ exports.getThemeNames = getThemeNames;
12
+ exports.getThemeName = getThemeName;
13
+ exports.getThemePath = getThemePath;
10
14
  const tslib_1 = require("tslib");
11
15
  const path_1 = tslib_1.__importDefault(require("path"));
12
16
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
@@ -20,7 +24,6 @@ function pluginToThemeName(plugin) {
20
24
  }
21
25
  return undefined;
22
26
  }
23
- exports.pluginToThemeName = pluginToThemeName;
24
27
  function getPluginByThemeName(plugins, themeName) {
25
28
  const plugin = plugins.find((p) => pluginToThemeName(p) === themeName);
26
29
  if (!plugin) {
@@ -28,7 +31,6 @@ function getPluginByThemeName(plugins, themeName) {
28
31
  }
29
32
  return plugin;
30
33
  }
31
- exports.getPluginByThemeName = getPluginByThemeName;
32
34
  function getThemeNames(plugins) {
33
35
  const themeNames = lodash_1.default.uniq(
34
36
  // The fact that getThemePath is attached to the plugin instance makes
@@ -46,7 +48,6 @@ function getThemeNames(plugins) {
46
48
  (t) => t.includes('@docusaurus'),
47
49
  ], ['desc', 'desc', 'desc']);
48
50
  }
49
- exports.getThemeNames = getThemeNames;
50
51
  // Returns a valid value if recovering is possible
51
52
  function handleInvalidThemeName({ themeNameParam, themeNames, }) {
52
53
  // Trying to recover invalid value
@@ -84,7 +85,6 @@ async function getThemeName({ themeNameParam, themeNames, list, }) {
84
85
  ? validateThemeName({ themeNameParam, themeNames })
85
86
  : (0, prompts_1.askThemeName)(themeNames);
86
87
  }
87
- exports.getThemeName = getThemeName;
88
88
  function getThemePath({ plugins, themeName, typescript, }) {
89
89
  const pluginInstance = getPluginByThemeName(plugins, themeName);
90
90
  const themePath = typescript
@@ -103,4 +103,3 @@ function getThemePath({ plugins, themeName, typescript, }) {
103
103
  }
104
104
  return themePath;
105
105
  }
106
- exports.getThemePath = getThemePath;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.writeHeadingIds = void 0;
9
+ exports.writeHeadingIds = writeHeadingIds;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -48,4 +48,3 @@ async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
48
48
  logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.`;
49
49
  }
50
50
  }
51
- exports.writeHeadingIds = writeHeadingIds;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.writeTranslations = void 0;
9
+ exports.writeTranslations = writeTranslations;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -82,4 +82,3 @@ Available locales are: ${context.i18n.locales.join(',')}.`);
82
82
  await writePluginTranslationFiles({ localizationDir, plugin, options });
83
83
  }));
84
84
  }
85
- exports.writeTranslations = writeTranslations;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.handleBrokenLinks = void 0;
9
+ exports.handleBrokenLinks = handleBrokenLinks;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -281,4 +281,3 @@ async function handleBrokenLinks({ collectedLinks, onBrokenLinks, onBrokenAnchor
281
281
  });
282
282
  reportBrokenLinks({ brokenLinks, onBrokenLinks, onBrokenAnchors });
283
283
  }
284
- exports.handleBrokenLinks = handleBrokenLinks;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getAllClientModules = void 0;
9
+ exports.getAllClientModules = getAllClientModules;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  /**
@@ -17,4 +17,3 @@ function getAllClientModules(plugins) {
17
17
  return plugins.flatMap((plugin) => plugin.getClientModules?.().map((p) => path_1.default.resolve(plugin.path, p)) ??
18
18
  []);
19
19
  }
20
- exports.getAllClientModules = getAllClientModules;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.generateSiteFiles = void 0;
9
+ exports.generateSiteFiles = generateSiteFiles;
10
10
  const utils_1 = require("@docusaurus/utils");
11
11
  const codegenRoutes_1 = require("./codegenRoutes");
12
12
  function genWarning({ generatedFilesDir }) {
@@ -66,4 +66,3 @@ async function generateSiteFiles(params) {
66
66
  genCodeTranslations(params),
67
67
  ]);
68
68
  }
69
- exports.generateSiteFiles = generateSiteFiles;
@@ -6,7 +6,10 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.generateRouteFiles = exports.generateRoutePropFilename = exports.generateRoutesCode = exports.genChunkName = void 0;
9
+ exports.genChunkName = genChunkName;
10
+ exports.generateRoutesCode = generateRoutesCode;
11
+ exports.generateRoutePropFilename = generateRoutePropFilename;
12
+ exports.generateRouteFiles = generateRouteFiles;
10
13
  const tslib_1 = require("tslib");
11
14
  const querystring_1 = tslib_1.__importDefault(require("querystring"));
12
15
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -53,7 +56,6 @@ function genChunkName(modulePath, prefix, preferredName, shortId = process.env.N
53
56
  }
54
57
  return chunkName;
55
58
  }
56
- exports.genChunkName = genChunkName;
57
59
  /**
58
60
  * Takes a piece of route config, and serializes it into raw JS code. The shape
59
61
  * is the same as react-router's `RouteConfig`. Formatting is similar to
@@ -169,7 +171,6 @@ ${indent(routeConfigSerialized)},
169
171
  `;
170
172
  return res;
171
173
  }
172
- exports.generateRoutesCode = generateRoutesCode;
173
174
  const genRegistry = ({ generatedFilesDir, registry, }) => (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
174
175
  ${Object.entries(registry)
175
176
  .sort((a, b) => a[0].localeCompare(b[0]))
@@ -193,7 +194,6 @@ function generateRoutePropFilename(route) {
193
194
  // same component.
194
195
  { hashExtra: route.component })}.json`;
195
196
  }
196
- exports.generateRoutePropFilename = generateRoutePropFilename;
197
197
  async function generateRoutePropModule({ generatedFilesDir, route, plugin, }) {
198
198
  ensureNoPropsConflict(route);
199
199
  const moduleContent = JSON.stringify(route.props);
@@ -270,4 +270,3 @@ async function generateRouteFiles({ generatedFilesDir, routes: initialRoutes, })
270
270
  genRoutes({ generatedFilesDir, routesConfig }),
271
271
  ]);
272
272
  }
273
- exports.generateRouteFiles = generateRouteFiles;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadSiteConfig = void 0;
9
+ exports.loadSiteConfig = loadSiteConfig;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
@@ -39,4 +39,3 @@ async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
39
39
  const siteConfig = (0, configValidation_1.validateConfig)(loadedConfig, path_1.default.relative(siteDir, siteConfigPath));
40
40
  return { siteConfig, siteConfigPath };
41
41
  }
42
- exports.loadSiteConfig = loadSiteConfig;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
9
+ exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
+ exports.validateConfig = validateConfig;
10
11
  const utils_1 = require("@docusaurus/utils");
11
12
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
13
  const utils_common_1 = require("@docusaurus/utils-common");
@@ -301,4 +302,3 @@ function validateConfig(config, siteConfigPath) {
301
302
  return value;
302
303
  }
303
304
  }
304
- exports.validateConfig = validateConfig;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getHostPort = void 0;
9
+ exports.getHostPort = getHostPort;
10
10
  const tslib_1 = require("tslib");
11
11
  const child_process_1 = require("child_process");
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -79,4 +79,3 @@ async function getHostPort(options) {
79
79
  const port = await choosePort(host, basePort);
80
80
  return { host, port };
81
81
  }
82
- exports.getHostPort = getHostPort;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadHtmlTags = void 0;
9
+ exports.loadHtmlTags = loadHtmlTags;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
@@ -68,4 +68,3 @@ function loadHtmlTags({ plugins, router, }) {
68
68
  .join('\n')
69
69
  .trim())));
70
70
  }
71
- exports.loadHtmlTags = loadHtmlTags;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
9
+ exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
10
+ exports.loadI18n = loadI18n;
10
11
  const tslib_1 = require("tslib");
11
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
13
  const rtl_detect_1 = require("rtl-detect");
@@ -71,7 +72,6 @@ function getDefaultLocaleConfig(locale) {
71
72
  throw new Error(`Docusaurus couldn't get default locale config for ${locale}`, { cause: e });
72
73
  }
73
74
  }
74
- exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
75
75
  async function loadI18n(config, options) {
76
76
  const { i18n: i18nConfig } = config;
77
77
  const currentLocale = options.locale ?? i18nConfig.defaultLocale;
@@ -97,4 +97,3 @@ Note: Docusaurus only support running one locale at a time.`;
97
97
  localeConfigs,
98
98
  };
99
99
  }
100
- exports.loadI18n = loadI18n;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createPluginActionsUtils = void 0;
9
+ exports.createPluginActionsUtils = createPluginActionsUtils;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
@@ -67,4 +67,3 @@ async function createPluginActionsUtils({ plugin, generatedFilesDir, baseUrl, tr
67
67
  getActions: () => actions,
68
68
  };
69
69
  }
70
- exports.createPluginActionsUtils = createPluginActionsUtils;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadPluginConfigs = void 0;
9
+ exports.loadPluginConfigs = loadPluginConfigs;
10
10
  const module_1 = require("module");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const presets_1 = require("./presets");
@@ -97,4 +97,3 @@ async function loadPluginConfigs(context) {
97
97
  ].filter((x) => Boolean(x));
98
98
  return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, context.siteConfigPath, pluginRequire)));
99
99
  }
100
- exports.loadPluginConfigs = loadPluginConfigs;
@@ -4,9 +4,20 @@
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 NormalizedPluginConfig } from './configs';
7
8
  import type { LoadContext, InitializedPlugin } from '@docusaurus/types';
9
+ type PluginConfigInitResult = {
10
+ config: NormalizedPluginConfig;
11
+ plugin: InitializedPlugin | null;
12
+ };
8
13
  /**
9
14
  * Runs the plugin constructors and returns their return values. It would load
10
15
  * plugin configs from `plugins`, `themes`, and `presets`.
11
16
  */
17
+ export declare function initPluginsConfigs(context: LoadContext, pluginConfigs: NormalizedPluginConfig[]): Promise<PluginConfigInitResult[]>;
18
+ /**
19
+ * Runs the plugin constructors and returns their return values
20
+ * for all the site context plugins that do not return null to self-disable.
21
+ */
12
22
  export declare function initPlugins(context: LoadContext): Promise<InitializedPlugin[]>;
23
+ export {};
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.initPlugins = void 0;
9
+ exports.initPluginsConfigs = initPluginsConfigs;
10
+ exports.initPlugins = initPlugins;
10
11
  const tslib_1 = require("tslib");
11
12
  const module_1 = require("module");
12
13
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -31,15 +32,20 @@ function getThemeValidationFunction(normalizedPluginConfig) {
31
32
  }
32
33
  return normalizedPluginConfig.plugin.validateThemeConfig;
33
34
  }
35
+ // This filters self-disabling plugins and returns only the initialized ones
36
+ function onlyInitializedPlugins(initPluginsConfigsResults) {
37
+ return initPluginsConfigsResults
38
+ .map((results) => results.plugin)
39
+ .filter((p) => p !== null);
40
+ }
34
41
  /**
35
42
  * Runs the plugin constructors and returns their return values. It would load
36
43
  * plugin configs from `plugins`, `themes`, and `presets`.
37
44
  */
38
- async function initPlugins(context) {
45
+ async function initPluginsConfigs(context, pluginConfigs) {
39
46
  // We need to resolve plugins from the perspective of the site config, as if
40
47
  // we are using `require.resolve` on those module names.
41
48
  const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
42
- const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
43
49
  async function doLoadPluginVersion(normalizedPluginConfig) {
44
50
  if (normalizedPluginConfig.pluginModule?.path) {
45
51
  const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule.path);
@@ -76,20 +82,49 @@ async function initPlugins(context) {
76
82
  const pluginVersion = await doLoadPluginVersion(normalizedPluginConfig);
77
83
  const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
78
84
  // Side-effect: merge the normalized theme config in the original one
85
+ // Note: it's important to do this before calling the plugin constructor
86
+ // Example: the theme classic plugin will read siteConfig.themeConfig
79
87
  context.siteConfig.themeConfig = {
80
88
  ...context.siteConfig.themeConfig,
81
89
  ...doValidateThemeConfig(normalizedPluginConfig),
82
90
  };
83
91
  const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
84
- return {
92
+ // Returning null has been explicitly allowed
93
+ // It's a way for plugins to self-disable depending on context
94
+ // See https://github.com/facebook/docusaurus/pull/10286
95
+ if (pluginInstance === null) {
96
+ return { config: normalizedPluginConfig, plugin: null };
97
+ }
98
+ if (pluginInstance === undefined) {
99
+ throw new Error(`A Docusaurus plugin returned 'undefined', which is forbidden.
100
+ A plugin is expected to return an object having at least a 'name' property.
101
+ If you want a plugin to self-disable depending on context/options, you can explicitly return 'null' instead of 'undefined'`);
102
+ }
103
+ if (!pluginInstance?.name) {
104
+ throw new Error(`A Docusaurus plugin is missing a 'name' property.
105
+ Note that even inline/anonymous plugin functions require a 'name' property.`);
106
+ }
107
+ const plugin = {
85
108
  ...pluginInstance,
86
109
  options: pluginOptions,
87
110
  version: pluginVersion,
88
111
  path: path_1.default.dirname(normalizedPluginConfig.entryPath),
89
112
  };
113
+ return {
114
+ config: normalizedPluginConfig,
115
+ plugin,
116
+ };
90
117
  }
91
- const plugins = await Promise.all(pluginConfigs.map(initializePlugin));
92
- (0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
118
+ const plugins = (await Promise.all(pluginConfigs.map(initializePlugin))).filter((p) => p !== null);
119
+ (0, pluginIds_1.ensureUniquePluginInstanceIds)(onlyInitializedPlugins(plugins));
93
120
  return plugins;
94
121
  }
95
- exports.initPlugins = initPlugins;
122
+ /**
123
+ * Runs the plugin constructors and returns their return values
124
+ * for all the site context plugins that do not return null to self-disable.
125
+ */
126
+ async function initPlugins(context) {
127
+ const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
128
+ const initPluginsConfigsResults = await initPluginsConfigs(context, pluginConfigs);
129
+ return onlyInitializedPlugins(initPluginsConfigsResults);
130
+ }
@@ -4,6 +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
- /// <reference types="node" />
8
7
  export declare function getNamePatterns(moduleName: string, moduleType: 'preset' | 'theme' | 'plugin'): string[];
9
8
  export declare function resolveModuleName(moduleName: string, moduleRequire: NodeRequire, moduleType: 'preset' | 'theme' | 'plugin'): string;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.resolveModuleName = exports.getNamePatterns = void 0;
9
+ exports.getNamePatterns = getNamePatterns;
10
+ exports.resolveModuleName = resolveModuleName;
10
11
  function getNamePatterns(moduleName, moduleType) {
11
12
  if (moduleName.startsWith('@')) {
12
13
  // Pure scope: `@scope` => `@scope/docusaurus-plugin`
@@ -25,7 +26,6 @@ function getNamePatterns(moduleName, moduleType) {
25
26
  `docusaurus-${moduleType}-${moduleName}`,
26
27
  ];
27
28
  }
28
- exports.getNamePatterns = getNamePatterns;
29
29
  function resolveModuleName(moduleName, moduleRequire, moduleType) {
30
30
  const modulePatterns = getNamePatterns(moduleName, moduleType);
31
31
  const module = modulePatterns.find((m) => {
@@ -43,4 +43,3 @@ ${modulePatterns.map((m) => `- ${m}`).join('\n')}`);
43
43
  }
44
44
  return module;
45
45
  }
46
- exports.resolveModuleName = resolveModuleName;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ensureUniquePluginInstanceIds = void 0;
9
+ exports.ensureUniquePluginInstanceIds = ensureUniquePluginInstanceIds;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const utils_1 = require("@docusaurus/utils");
@@ -27,4 +27,3 @@ function ensureUniquePluginInstanceIds(plugins) {
27
27
  });
28
28
  });
29
29
  }
30
- exports.ensureUniquePluginInstanceIds = ensureUniquePluginInstanceIds;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.reloadPlugin = exports.loadPlugins = void 0;
9
+ exports.loadPlugins = loadPlugins;
10
+ exports.reloadPlugin = reloadPlugin;
10
11
  const init_1 = require("./init");
11
12
  const synthetic_1 = require("./synthetic");
12
13
  const translations_1 = require("../translations/translations");
@@ -152,7 +153,6 @@ async function loadPlugins(context) {
152
153
  return { plugins, routes, globalData };
153
154
  });
154
155
  }
155
- exports.loadPlugins = loadPlugins;
156
156
  async function reloadPlugin({ pluginIdentifier, plugins: previousPlugins, context, }) {
157
157
  return utils_1.PerfLogger.async(`Reload plugin ${(0, pluginsUtils_1.formatPluginName)(pluginIdentifier)}`, async () => {
158
158
  const previousPlugin = (0, pluginsUtils_1.getPluginByIdentifier)({
@@ -184,4 +184,3 @@ async function reloadPlugin({ pluginIdentifier, plugins: previousPlugins, contex
184
184
  return { plugins, routes, globalData };
185
185
  });
186
186
  }
187
- exports.reloadPlugin = reloadPlugin;
@@ -6,7 +6,13 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.formatPluginName = exports.mergeGlobalData = exports.aggregateGlobalData = exports.aggregateRoutes = exports.toPluginRoute = exports.aggregateAllContent = exports.getPluginByIdentifier = void 0;
9
+ exports.getPluginByIdentifier = getPluginByIdentifier;
10
+ exports.aggregateAllContent = aggregateAllContent;
11
+ exports.toPluginRoute = toPluginRoute;
12
+ exports.aggregateRoutes = aggregateRoutes;
13
+ exports.aggregateGlobalData = aggregateGlobalData;
14
+ exports.mergeGlobalData = mergeGlobalData;
15
+ exports.formatPluginName = formatPluginName;
10
16
  const tslib_1 = require("tslib");
11
17
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
18
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -17,7 +23,6 @@ function getPluginByIdentifier({ plugins, pluginIdentifier, }) {
17
23
  }
18
24
  return plugin;
19
25
  }
20
- exports.getPluginByIdentifier = getPluginByIdentifier;
21
26
  function aggregateAllContent(loadedPlugins) {
22
27
  return lodash_1.default.chain(loadedPlugins)
23
28
  .groupBy((item) => item.name)
@@ -27,15 +32,12 @@ function aggregateAllContent(loadedPlugins) {
27
32
  .value())
28
33
  .value();
29
34
  }
30
- exports.aggregateAllContent = aggregateAllContent;
31
35
  function toPluginRoute({ plugin, route, }) {
32
36
  return { plugin: { name: plugin.name, id: plugin.options.id }, ...route };
33
37
  }
34
- exports.toPluginRoute = toPluginRoute;
35
38
  function aggregateRoutes(loadedPlugins) {
36
39
  return loadedPlugins.flatMap((plugin) => plugin.routes.map((route) => toPluginRoute({ plugin, route })));
37
40
  }
38
- exports.aggregateRoutes = aggregateRoutes;
39
41
  function aggregateGlobalData(loadedPlugins) {
40
42
  const globalData = {};
41
43
  loadedPlugins.forEach((plugin) => {
@@ -47,7 +49,6 @@ function aggregateGlobalData(loadedPlugins) {
47
49
  });
48
50
  return globalData;
49
51
  }
50
- exports.aggregateGlobalData = aggregateGlobalData;
51
52
  function mergeGlobalData(...globalDataList) {
52
53
  const result = {};
53
54
  const allPluginIdentifiers = globalDataList.flatMap((gd) => Object.keys(gd).flatMap((name) => Object.keys(gd[name]).map((id) => ({ name, id }))));
@@ -61,7 +62,6 @@ function mergeGlobalData(...globalDataList) {
61
62
  });
62
63
  return result;
63
64
  }
64
- exports.mergeGlobalData = mergeGlobalData;
65
65
  // This is primarily useful for colored logging purpose
66
66
  // Do not rely on this for logic
67
67
  function formatPluginName(plugin) {
@@ -76,4 +76,3 @@ function formatPluginName(plugin) {
76
76
  const formattedId = logger_1.default.subdue(id);
77
77
  return `${formattedName}@${formattedId}`;
78
78
  }
79
- exports.formatPluginName = formatPluginName;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadPresets = void 0;
9
+ exports.loadPresets = loadPresets;
10
10
  const module_1 = require("module");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const moduleShorthand_1 = require("./moduleShorthand");
@@ -39,4 +39,3 @@ async function loadPresets(context) {
39
39
  const themes = loadedPresets.flatMap((preset) => preset.themes ?? []);
40
40
  return { plugins, themes };
41
41
  }
42
- exports.loadPresets = loadPresets;