@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +29 -38
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +19 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +5 -9
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  16. package/lib/client/client-lifecycles-dispatcher.js +6 -10
  17. package/lib/client/clientEntry.js +11 -5
  18. package/lib/client/docusaurus.d.ts +6 -0
  19. package/lib/client/docusaurus.js +16 -25
  20. package/lib/client/exports/BrowserOnly.d.ts +2 -3
  21. package/lib/client/exports/BrowserOnly.js +13 -7
  22. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  23. package/lib/client/exports/ComponentCreator.js +7 -6
  24. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  25. package/lib/client/exports/ErrorBoundary.js +35 -0
  26. package/lib/client/exports/Head.d.ts +2 -3
  27. package/lib/client/exports/Head.js +3 -4
  28. package/lib/client/exports/Interpolate.d.ts +1 -1
  29. package/lib/client/exports/Interpolate.js +16 -22
  30. package/lib/client/exports/Link.d.ts +11 -5
  31. package/lib/client/exports/Link.js +24 -19
  32. package/lib/client/exports/Translate.d.ts +3 -3
  33. package/lib/client/exports/Translate.js +14 -10
  34. package/lib/client/exports/browserContext.d.ts +11 -0
  35. package/lib/client/exports/browserContext.js +22 -0
  36. package/lib/client/exports/constants.js +1 -11
  37. package/lib/client/exports/docusaurusContext.d.ts +12 -0
  38. package/lib/client/exports/docusaurusContext.js +25 -0
  39. package/lib/client/exports/isInternalUrl.js +1 -1
  40. package/lib/client/exports/renderRoutes.d.ts +1 -2
  41. package/lib/client/exports/renderRoutes.js +1 -2
  42. package/lib/client/exports/router.d.ts +1 -1
  43. package/lib/client/exports/router.js +1 -1
  44. package/lib/client/exports/useBaseUrl.js +3 -5
  45. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  46. package/lib/client/exports/useDocusaurusContext.js +3 -9
  47. package/lib/client/exports/useGlobalData.js +1 -5
  48. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  49. package/lib/client/exports/useIsBrowser.js +11 -0
  50. package/lib/client/flat.d.ts +2 -2
  51. package/lib/client/flat.js +8 -11
  52. package/lib/client/normalizeLocation.d.ts +2 -5
  53. package/lib/client/normalizeLocation.js +1 -2
  54. package/lib/client/nprogress.css +2 -2
  55. package/lib/client/prefetch.d.ts +1 -2
  56. package/lib/client/prefetch.js +1 -3
  57. package/lib/client/preload.d.ts +3 -2
  58. package/lib/client/preload.js +2 -1
  59. package/lib/client/serverEntry.d.ts +10 -0
  60. package/lib/client/serverEntry.js +90 -142
  61. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  62. package/lib/client/theme-fallback/Error/index.js +39 -0
  63. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  64. package/lib/client/theme-fallback/Layout/index.js +10 -19
  65. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  66. package/lib/client/theme-fallback/Loading/index.js +47 -115
  67. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  68. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  69. package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
  70. package/lib/client/theme-fallback/Root/index.js +2 -7
  71. package/lib/commands/build.d.ts +1 -1
  72. package/lib/commands/build.js +50 -54
  73. package/lib/commands/clear.d.ts +6 -0
  74. package/lib/commands/clear.js +30 -19
  75. package/lib/commands/commandUtils.d.ts +7 -1
  76. package/lib/commands/commandUtils.js +6 -6
  77. package/lib/commands/deploy.d.ts +4 -1
  78. package/lib/commands/deploy.js +102 -66
  79. package/lib/commands/external.d.ts +2 -2
  80. package/lib/commands/external.js +3 -3
  81. package/lib/commands/serve.d.ts +1 -1
  82. package/lib/commands/serve.js +13 -19
  83. package/lib/commands/start.d.ts +1 -1
  84. package/lib/commands/start.js +93 -83
  85. package/lib/commands/swizzle/actions.d.ts +23 -0
  86. package/lib/commands/swizzle/actions.js +102 -0
  87. package/lib/commands/swizzle/common.d.ts +33 -0
  88. package/lib/commands/swizzle/common.js +56 -0
  89. package/lib/commands/swizzle/components.d.ts +29 -0
  90. package/lib/commands/swizzle/components.js +162 -0
  91. package/lib/commands/swizzle/config.d.ts +10 -0
  92. package/lib/commands/swizzle/config.js +80 -0
  93. package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
  94. package/lib/commands/swizzle/context.js +30 -0
  95. package/lib/commands/swizzle/index.d.ts +8 -0
  96. package/lib/commands/swizzle/index.js +115 -0
  97. package/lib/commands/swizzle/prompts.d.ts +12 -0
  98. package/lib/commands/swizzle/prompts.js +110 -0
  99. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  100. package/lib/commands/swizzle/tables.js +116 -0
  101. package/lib/commands/swizzle/themes.d.ts +20 -0
  102. package/lib/commands/swizzle/themes.js +103 -0
  103. package/lib/commands/writeHeadingIds.d.ts +9 -6
  104. package/lib/commands/writeHeadingIds.js +41 -43
  105. package/lib/commands/writeTranslations.d.ts +2 -2
  106. package/lib/commands/writeTranslations.js +35 -14
  107. package/lib/index.d.ts +10 -9
  108. package/lib/index.js +20 -19
  109. package/lib/server/brokenLinks.d.ts +1 -1
  110. package/lib/server/brokenLinks.js +57 -38
  111. package/lib/server/client-modules/index.d.ts +1 -1
  112. package/lib/server/client-modules/index.js +1 -3
  113. package/lib/server/config.d.ts +2 -2
  114. package/lib/server/config.js +7 -4
  115. package/lib/server/configValidation.d.ts +2 -2
  116. package/lib/server/configValidation.js +43 -28
  117. package/lib/server/duplicateRoutes.d.ts +1 -1
  118. package/lib/server/duplicateRoutes.js +10 -6
  119. package/lib/server/html-tags/htmlTags.js +2 -4
  120. package/lib/server/html-tags/index.d.ts +1 -1
  121. package/lib/server/html-tags/index.js +1 -1
  122. package/lib/server/i18n.d.ts +1 -2
  123. package/lib/server/i18n.js +32 -46
  124. package/lib/server/index.d.ts +2 -2
  125. package/lib/server/index.js +147 -68
  126. package/lib/server/moduleShorthand.d.ts +9 -0
  127. package/lib/server/moduleShorthand.js +46 -0
  128. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  129. package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
  130. package/lib/server/plugins/index.d.ts +2 -2
  131. package/lib/server/plugins/index.js +34 -35
  132. package/lib/server/plugins/init.d.ts +12 -2
  133. package/lib/server/plugins/init.js +48 -58
  134. package/lib/server/plugins/pluginIds.d.ts +1 -1
  135. package/lib/server/plugins/pluginIds.js +8 -5
  136. package/lib/server/presets/index.d.ts +3 -3
  137. package/lib/server/presets/index.js +12 -13
  138. package/lib/server/routes.d.ts +1 -1
  139. package/lib/server/routes.js +50 -29
  140. package/lib/server/themes/alias.d.ts +3 -2
  141. package/lib/server/themes/alias.js +22 -14
  142. package/lib/server/themes/index.d.ts +3 -3
  143. package/lib/server/themes/index.js +26 -26
  144. package/lib/server/translations/translations.d.ts +7 -1
  145. package/lib/server/translations/translations.js +30 -45
  146. package/lib/server/translations/translationsExtractor.d.ts +9 -3
  147. package/lib/server/translations/translationsExtractor.js +159 -120
  148. package/lib/server/utils.d.ts +9 -3
  149. package/lib/server/utils.js +7 -9
  150. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  151. package/lib/server/versions/index.d.ts +3 -4
  152. package/lib/server/versions/index.js +22 -21
  153. package/lib/webpack/base.d.ts +4 -4
  154. package/lib/webpack/base.js +38 -33
  155. package/lib/webpack/client.d.ts +3 -3
  156. package/lib/webpack/client.js +12 -19
  157. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  158. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  159. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  160. package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
  161. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  162. package/lib/webpack/plugins/LogPlugin.js +4 -5
  163. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  164. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  165. package/lib/webpack/server.d.ts +3 -3
  166. package/lib/webpack/server.js +9 -8
  167. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  168. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  169. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  170. package/lib/webpack/utils.d.ts +7 -29
  171. package/lib/webpack/utils.js +54 -171
  172. package/package.json +74 -69
  173. package/lib/.tsbuildinfo +0 -1
  174. package/lib/client/.tsbuildinfo +0 -1
  175. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  176. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  177. package/lib/commands/swizzle.d.ts +0 -9
  178. package/lib/commands/swizzle.js +0 -245
  179. package/lib/constants.d.ts +0 -18
  180. package/lib/constants.js +0 -23
  181. package/lib/server/loadSetup.js +0 -25
  182. package/lib/server/versions/__tests/index.test.js +0 -25
  183. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  184. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  185. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  186. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  187. package/lib/webpack/sharedModuleAliases.js +0 -18
  188. package/tsconfig.client.json +0 -13
  189. package/tsconfig.json +0 -13
@@ -9,10 +9,9 @@ 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 constants_1 = require("../constants");
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const ssr_html_template_1 = tslib_1.__importDefault(require("../webpack/templates/ssr.html.template"));
16
15
  const client_modules_1 = tslib_1.__importDefault(require("./client-modules"));
17
16
  const config_1 = tslib_1.__importDefault(require("./config"));
18
17
  const plugins_1 = require("./plugins");
@@ -23,22 +22,24 @@ const versions_1 = require("./versions");
23
22
  const duplicateRoutes_1 = require("./duplicateRoutes");
24
23
  const i18n_1 = require("./i18n");
25
24
  const translations_1 = require("./translations/translations");
26
- const lodash_1 = require("lodash");
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");
27
29
  async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
28
- const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : constants_1.DEFAULT_CONFIG_FILE_NAME;
30
+ const siteConfigPathUnresolved = customConfigFilePath ?? utils_1.DEFAULT_CONFIG_FILE_NAME;
29
31
  const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
30
32
  ? siteConfigPathUnresolved
31
33
  : path_1.default.resolve(siteDir, siteConfigPathUnresolved);
32
- const siteConfig = await config_1.default(siteConfigPath);
34
+ const siteConfig = await (0, config_1.default)(siteConfigPath);
33
35
  return { siteConfig, siteConfigPath };
34
36
  }
35
37
  exports.loadSiteConfig = loadSiteConfig;
36
38
  async function loadContext(siteDir, options = {}) {
37
- var _a;
38
39
  const { customOutDir, locale, customConfigFilePath } = options;
39
- const generatedFilesDir = path_1.default.isAbsolute(constants_1.GENERATED_FILES_DIR_NAME)
40
- ? constants_1.GENERATED_FILES_DIR_NAME
41
- : path_1.default.resolve(siteDir, constants_1.GENERATED_FILES_DIR_NAME);
40
+ const generatedFilesDir = path_1.default.isAbsolute(utils_1.GENERATED_FILES_DIR_NAME)
41
+ ? utils_1.GENERATED_FILES_DIR_NAME
42
+ : path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
42
43
  const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
43
44
  siteDir,
44
45
  customConfigFilePath,
@@ -46,27 +47,27 @@ async function loadContext(siteDir, options = {}) {
46
47
  const { ssrTemplate } = initialSiteConfig;
47
48
  const baseOutDir = customOutDir
48
49
  ? path_1.default.resolve(customOutDir)
49
- : path_1.default.resolve(siteDir, constants_1.DEFAULT_BUILD_DIR_NAME);
50
- const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
51
- const baseUrl = i18n_1.localizePath({
50
+ : path_1.default.resolve(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME);
51
+ const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
52
+ const baseUrl = (0, i18n_1.localizePath)({
52
53
  path: initialSiteConfig.baseUrl,
53
54
  i18n,
54
55
  options,
55
56
  pathType: 'url',
56
57
  });
57
- const outDir = i18n_1.localizePath({
58
+ const outDir = (0, i18n_1.localizePath)({
58
59
  path: baseOutDir,
59
60
  i18n,
60
61
  options,
61
62
  pathType: 'fs',
62
63
  });
63
64
  const siteConfig = { ...initialSiteConfig, baseUrl };
64
- const codeTranslationFileContent = (_a = (await translations_1.readCodeTranslationFileContent({
65
+ const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({
65
66
  siteDir,
66
67
  locale: i18n.currentLocale,
67
- }))) !== null && _a !== void 0 ? _a : {};
68
+ })) ?? {};
68
69
  // We only need key->message for code translations
69
- const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
70
+ const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
70
71
  return {
71
72
  siteDir,
72
73
  generatedFilesDir,
@@ -75,44 +76,47 @@ async function loadContext(siteDir, options = {}) {
75
76
  outDir,
76
77
  baseUrl,
77
78
  i18n,
78
- ssrTemplate,
79
+ ssrTemplate: ssrTemplate ?? ssr_html_template_1.default,
79
80
  codeTranslations,
80
81
  };
81
82
  }
82
83
  exports.loadContext = loadContext;
83
- function loadPluginConfigs(context) {
84
- const { plugins: presetPlugins, themes: presetThemes } = presets_1.default(context);
85
- const { siteConfig } = context;
84
+ async function loadPluginConfigs(context) {
85
+ let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
86
+ const { siteConfig, siteConfigPath } = context;
87
+ const require = (0, module_1.createRequire)(siteConfigPath);
88
+ function normalizeShorthand(pluginConfig, pluginType) {
89
+ if (typeof pluginConfig === 'string') {
90
+ return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
91
+ }
92
+ else if (Array.isArray(pluginConfig) &&
93
+ typeof pluginConfig[0] === 'string') {
94
+ return [
95
+ (0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
96
+ pluginConfig[1] ?? {},
97
+ ];
98
+ }
99
+ return pluginConfig;
100
+ }
101
+ presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
102
+ presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
103
+ const standalonePlugins = (siteConfig.plugins || []).map((plugin) => normalizeShorthand(plugin, 'plugin'));
104
+ const standaloneThemes = (siteConfig.themes || []).map((theme) => normalizeShorthand(theme, 'theme'));
86
105
  return [
87
106
  ...presetPlugins,
88
107
  ...presetThemes,
89
108
  // Site config should be the highest priority.
90
- ...(siteConfig.plugins || []),
91
- ...(siteConfig.themes || []),
109
+ ...standalonePlugins,
110
+ ...standaloneThemes,
92
111
  ];
93
112
  }
94
113
  exports.loadPluginConfigs = loadPluginConfigs;
95
- async function load(siteDir, options = {}) {
96
- // Context.
97
- const context = await loadContext(siteDir, options);
98
- const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
99
- // Plugins.
100
- const pluginConfigs = loadPluginConfigs(context);
101
- const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
102
- pluginConfigs,
103
- context,
104
- });
105
- // Side-effect to replace the untranslated themeConfig by the translated one
106
- context.siteConfig.themeConfig = themeConfigTranslated;
107
- duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
108
- // Site config must be generated after plugins
109
- // We want the generated config to have been normalized by the plugins!
110
- const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
111
- // Make a fake plugin to:
112
- // - Resolve aliased theme components
113
- // - Inject scripts/stylesheets
114
+ // Make a fake plugin to:
115
+ // - Resolve aliased theme components
116
+ // - Inject scripts/stylesheets
117
+ function createBootstrapPlugin({ siteConfig, }) {
114
118
  const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
115
- plugins.push({
119
+ return {
116
120
  name: 'docusaurus-bootstrap-plugin',
117
121
  content: null,
118
122
  options: {},
@@ -142,39 +146,111 @@ async function load(siteDir, options = {}) {
142
146
  headTags: [...stylesheetsTags, ...scriptsTags],
143
147
  };
144
148
  },
145
- });
149
+ };
150
+ }
151
+ /**
152
+ * Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
153
+ * folders. Adds a "fallback" mdx loader for mdx files that are not processed by
154
+ * content plugins. This allows to do things such as importing repo/README.md as
155
+ * a partial from another doc. Not ideal solution, but good enough for now
156
+ */
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
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: (_filename) => true,
188
+ isMDXPartialFrontMatterWarningDisabled: true,
189
+ remarkPlugins: [remark_admonitions_1.default],
190
+ },
191
+ },
192
+ ],
193
+ },
194
+ ],
195
+ },
196
+ };
197
+ },
198
+ };
199
+ }
200
+ async function load(siteDir, options = {}) {
201
+ // Context.
202
+ const context = await loadContext(siteDir, options);
203
+ const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
204
+ // Plugins.
205
+ const pluginConfigs = await loadPluginConfigs(context);
206
+ const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
207
+ // Side-effect to replace the untranslated themeConfig by the translated one
208
+ context.siteConfig.themeConfig = themeConfigTranslated;
209
+ (0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
210
+ const genWarning = (0, utils_1.generate)(generatedFilesDir, 'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
211
+ DO NOT hand-modify files in this folder because they will be overwritten in the
212
+ next build. You can clear all build artifacts (including this folder) with the
213
+ \`docusaurus clear\` command.
214
+ `);
215
+ // Site config must be generated after plugins
216
+ // We want the generated config to have been normalized by the plugins!
217
+ const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `/*
218
+ AUTOGENERATED - DON'T EDIT
219
+ Your edits in this file will be overwritten in the next build!
220
+ Modify the docusaurus.config.js file at your site's root instead.
221
+ */
222
+ export default ${JSON.stringify(siteConfig, null, 2)};`);
223
+ plugins.push(createBootstrapPlugin({ siteConfig }));
224
+ plugins.push(createMDXFallbackPlugin({ siteDir, siteConfig }));
146
225
  // Load client modules.
147
- const clientModules = client_modules_1.default(plugins);
148
- const genClientModules = utils_1.generate(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
226
+ const clientModules = (0, client_modules_1.default)(plugins);
227
+ const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
149
228
  // import() is async so we use require() because client modules can have
150
229
  // CSS and the order matters for loading CSS.
151
- // We need to JSON.stringify so that if its on windows, backslash are escaped.
152
- .map((module) => ` require(${JSON.stringify(module)}),`)
230
+ .map((module) => ` require('${(0, utils_1.escapePath)(module)}'),`)
153
231
  .join('\n')}\n];\n`);
154
232
  // Load extra head & body html tags.
155
- const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
233
+ const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
156
234
  // Routing.
157
- const { registry, routesChunkNames, routesConfig, routesPaths, } = await routes_1.default(pluginsRouteConfigs, baseUrl);
158
- const genRegistry = utils_1.generate(generatedFilesDir, 'registry.js', `export default {
235
+ const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
236
+ const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
159
237
  ${Object.keys(registry)
160
238
  .sort()
161
- .map((key) =>
162
- // We need to JSON.stringify so that if its on windows, backslash are escaped.
163
- ` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
239
+ .map((key) => ` '${key}': [${registry[key].loader}, '${(0, utils_1.escapePath)(registry[key].modulePath)}', require.resolveWeak('${(0, utils_1.escapePath)(registry[key].modulePath)}')],`)
164
240
  .join('\n')}};\n`);
165
- const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
166
- const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
167
- const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
168
- const genI18n = utils_1.generate(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
241
+ const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
242
+ const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
243
+ const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
244
+ const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
169
245
  const codeTranslationsWithFallbacks = {
170
- ...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
246
+ ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
171
247
  ...codeTranslations,
172
248
  };
173
- const genCodeTranslations = utils_1.generate(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
249
+ const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
174
250
  // Version metadata.
175
251
  const siteMetadata = {
176
- docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
177
- siteVersion: versions_1.getPackageJsonVersion(path_1.join(siteDir, 'package.json')),
252
+ docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
253
+ siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
178
254
  pluginVersions: {},
179
255
  };
180
256
  plugins
@@ -183,8 +259,9 @@ ${Object.keys(registry)
183
259
  siteMetadata.pluginVersions[name] = version;
184
260
  });
185
261
  checkDocusaurusPackagesVersion(siteMetadata);
186
- const genSiteMetadata = utils_1.generate(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
262
+ const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
187
263
  await Promise.all([
264
+ genWarning,
188
265
  genClientModules,
189
266
  genSiteConfig,
190
267
  genRegistry,
@@ -210,7 +287,7 @@ ${Object.keys(registry)
210
287
  headTags,
211
288
  preBodyTags,
212
289
  postBodyTags,
213
- ssrTemplate: ssrTemplate || ssr_html_template_1.default,
290
+ ssrTemplate,
214
291
  codeTranslations,
215
292
  };
216
293
  return props;
@@ -222,13 +299,15 @@ exports.load = load;
222
299
  function checkDocusaurusPackagesVersion(siteMetadata) {
223
300
  const { docusaurusVersion } = siteMetadata;
224
301
  Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
225
- var _a;
226
302
  if (versionInfo.type === 'package' &&
227
- ((_a = versionInfo.name) === null || _a === void 0 ? void 0 : _a.startsWith('@docusaurus/')) &&
303
+ versionInfo.name?.startsWith('@docusaurus/') &&
304
+ versionInfo.version &&
228
305
  versionInfo.version !== docusaurusVersion) {
229
306
  // should we throw instead?
230
307
  // It still could work with different versions
231
- console.warn(chalk_1.default.red(`Invalid ${plugin} version ${versionInfo.version}.\nAll official @docusaurus/* packages should have the exact same version as @docusaurus/core (${docusaurusVersion}).\nMaybe you want to check, or regenerate your yarn.lock or package-lock.json file?`));
308
+ logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
309
+ All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
310
+ Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
232
311
  }
233
312
  });
234
313
  }
@@ -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,46 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveModuleName = exports.getNamePatterns = void 0;
10
+ function getNamePatterns(moduleName, moduleType) {
11
+ if (moduleName.startsWith('@')) {
12
+ // Pure scope: `@scope` => `@scope/docusaurus-plugin`
13
+ if (!moduleName.includes('/')) {
14
+ return [`${moduleName}/docusaurus-${moduleType}`];
15
+ }
16
+ const [scope, packageName] = moduleName.split(/\/(?<rest>.*)/);
17
+ return [
18
+ `${scope}/${packageName}`,
19
+ `${scope}/docusaurus-${moduleType}-${packageName}`,
20
+ ];
21
+ }
22
+ return [
23
+ moduleName,
24
+ `@docusaurus/${moduleType}-${moduleName}`,
25
+ `docusaurus-${moduleType}-${moduleName}`,
26
+ ];
27
+ }
28
+ exports.getNamePatterns = getNamePatterns;
29
+ function resolveModuleName(moduleName, moduleRequire, moduleType) {
30
+ const modulePatterns = getNamePatterns(moduleName, moduleType);
31
+ const module = modulePatterns.find((m) => {
32
+ try {
33
+ moduleRequire.resolve(m);
34
+ return true;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ });
40
+ if (!module) {
41
+ throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
42
+ ${modulePatterns.map((m) => `- ${m}`).join('\n')}`);
43
+ }
44
+ return module;
45
+ }
46
+ exports.resolveModuleName = resolveModuleName;
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { RouteConfig } from '@docusaurus/types';
8
- import { ApplyTrailingSlashParams } from '@docusaurus/utils-common';
7
+ import type { RouteConfig } from '@docusaurus/types';
8
+ import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
9
9
  export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
@@ -10,7 +10,7 @@ const utils_common_1 = require("@docusaurus/utils-common");
10
10
  function applyRouteTrailingSlash(route, params) {
11
11
  return {
12
12
  ...route,
13
- path: utils_common_1.applyTrailingSlash(route.path, params),
13
+ path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
14
14
  ...(route.routes && {
15
15
  routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
16
16
  }),
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
- export declare function sortConfig(routeConfigs: RouteConfig[]): void;
7
+ import type { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
+ export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
9
9
  export declare function loadPlugins({ pluginConfigs, context, }: {
10
10
  pluginConfigs: PluginConfig[];
11
11
  context: LoadContext;
@@ -12,15 +12,21 @@ 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
14
  const init_1 = tslib_1.__importDefault(require("./init"));
15
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
16
- const constants_1 = require("../../constants");
17
- const lodash_1 = require("lodash");
15
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
18
17
  const translations_1 = require("../translations/translations");
19
18
  const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
20
- function sortConfig(routeConfigs) {
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
  }
@@ -39,31 +45,29 @@ function sortConfig(routeConfigs) {
39
45
  return a.path.localeCompare(b.path);
40
46
  });
41
47
  routeConfigs.forEach((routeConfig) => {
42
- var _a;
43
- (_a = routeConfig.routes) === null || _a === void 0 ? void 0 : _a.sort((a, b) => a.path.localeCompare(b.path));
48
+ routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
44
49
  });
45
50
  }
46
51
  exports.sortConfig = sortConfig;
47
52
  async function loadPlugins({ pluginConfigs, context, }) {
48
53
  // 1. Plugin Lifecycle - Initialization/Constructor.
49
- const plugins = init_1.default({
54
+ const plugins = await (0, init_1.default)({
50
55
  pluginConfigs,
51
56
  context,
52
57
  });
53
58
  // 2. Plugin Lifecycle - loadContent.
54
- // Currently plugins run lifecycle methods in parallel and are not order-dependent.
55
- // We could change this in future if there are plugins which need to
56
- // run in certain order or depend on others for data.
59
+ // Currently plugins run lifecycle methods in parallel and are not
60
+ // order-dependent. We could change this in future if there are plugins which
61
+ // need to run in certain order or depend on others for data.
57
62
  const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
58
63
  const content = plugin.loadContent ? await plugin.loadContent() : null;
59
64
  return { ...plugin, content };
60
65
  }));
61
66
  const contentLoadedTranslatedPlugins = await Promise.all(loadedPlugins.map(async (contentLoadedPlugin) => {
62
- var _a, _b;
63
- const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
67
+ const translationFiles = (await contentLoadedPlugin?.getTranslationFiles?.({
64
68
  content: contentLoadedPlugin.content,
65
- })))) !== null && _b !== void 0 ? _b : [];
66
- const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
69
+ })) ?? [];
70
+ const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
67
71
  locale: context.i18n.currentLocale,
68
72
  siteDir: context.siteDir,
69
73
  translationFile,
@@ -74,30 +78,27 @@ async function loadPlugins({ pluginConfigs, context, }) {
74
78
  translationFiles: localizedTranslationFiles,
75
79
  };
76
80
  }));
77
- const allContent = lodash_1.chain(loadedPlugins)
81
+ const allContent = lodash_1.default.chain(loadedPlugins)
78
82
  .groupBy((item) => item.name)
79
- .mapValues((nameItems) => {
80
- return lodash_1.chain(nameItems)
81
- .groupBy((item) => { var _a; return (_a = item.options.id) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PLUGIN_ID; })
82
- .mapValues((idItems) => idItems[0].content)
83
- .value();
84
- })
83
+ .mapValues((nameItems) => lodash_1.default.chain(nameItems)
84
+ .groupBy((item) => item.options.id ?? utils_1.DEFAULT_PLUGIN_ID)
85
+ .mapValues((idItems) => idItems[0].content)
86
+ .value())
85
87
  .value();
86
88
  // 3. Plugin Lifecycle - contentLoaded.
87
89
  const pluginsRouteConfigs = [];
88
90
  const globalData = {};
89
91
  await Promise.all(contentLoadedTranslatedPlugins.map(async ({ content, translationFiles, ...plugin }) => {
90
- var _a, _b, _c;
91
92
  if (!plugin.contentLoaded) {
92
93
  return;
93
94
  }
94
- const pluginId = (_a = plugin.options.id) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PLUGIN_ID;
95
+ const pluginId = plugin.options.id ?? utils_1.DEFAULT_PLUGIN_ID;
95
96
  // plugins data files are namespaced by pluginName/pluginId
96
97
  const dataDirRoot = path_1.default.join(context.generatedFilesDir, plugin.name);
97
98
  const dataDir = path_1.default.join(dataDirRoot, pluginId);
98
99
  const addRoute = (initialRouteConfig) => {
99
100
  // Trailing slash behavior is handled in a generic way for all plugins
100
- const finalRouteConfig = applyRouteTrailingSlash_1.default(initialRouteConfig, {
101
+ const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
101
102
  trailingSlash: context.siteConfig.trailingSlash,
102
103
  baseUrl: context.siteConfig.baseUrl,
103
104
  });
@@ -106,15 +107,14 @@ async function loadPlugins({ pluginConfigs, context, }) {
106
107
  const createData = async (name, data) => {
107
108
  const modulePath = path_1.default.join(dataDir, name);
108
109
  await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
109
- await utils_1.generate(dataDir, name, data);
110
+ await (0, utils_1.generate)(dataDir, name, data);
110
111
  return modulePath;
111
112
  };
112
113
  // the plugins global data are namespaced to avoid data conflicts:
113
114
  // - by plugin name
114
115
  // - by plugin id (allow using multiple instances of the same plugin)
115
116
  const setGlobalData = (data) => {
116
- var _a;
117
- globalData[plugin.name] = (_a = globalData[plugin.name]) !== null && _a !== void 0 ? _a : {};
117
+ globalData[plugin.name] = globalData[plugin.name] ?? {};
118
118
  globalData[plugin.name][pluginId] = data;
119
119
  };
120
120
  const actions = {
@@ -122,7 +122,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
122
122
  createData,
123
123
  setGlobalData,
124
124
  };
125
- const translatedContent = (_c = (_b = plugin.translateContent) === null || _b === void 0 ? void 0 : _b.call(plugin, { content, translationFiles })) !== null && _c !== void 0 ? _c : content;
125
+ const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
126
126
  await plugin.contentLoaded({
127
127
  content: translatedContent,
128
128
  actions,
@@ -130,9 +130,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
130
130
  });
131
131
  }));
132
132
  // 4. Plugin Lifecycle - routesLoaded.
133
- // Currently plugins run lifecycle methods in parallel and are not order-dependent.
134
- // We could change this in future if there are plugins which need to
135
- // run in certain order or depend on others for data.
133
+ // Currently plugins run lifecycle methods in parallel and are not
134
+ // order-dependent. We could change this in future if there are plugins which
135
+ // need to run in certain order or depend on others for data.
136
136
  await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
137
137
  if (!plugin.routesLoaded) {
138
138
  return null;
@@ -140,17 +140,16 @@ async function loadPlugins({ pluginConfigs, context, }) {
140
140
  // TODO remove this deprecated lifecycle soon
141
141
  // deprecated since alpha-60
142
142
  // TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918
143
- console.error(chalk_1.default.red('Plugin routesLoaded lifecycle is deprecated. If you think we should keep this lifecycle, please report here: https://github.com/facebook/docusaurus/issues/3918'));
143
+ logger_1.default.error `Plugin code=${'routesLoaded'} lifecycle is deprecated. If you think we should keep this lifecycle, please report here: path=${'https://github.com/facebook/docusaurus/issues/3918'}`;
144
144
  return plugin.routesLoaded(pluginsRouteConfigs);
145
145
  }));
146
146
  // Sort the route config. This ensures that route with nested
147
147
  // routes are always placed last.
148
- sortConfig(pluginsRouteConfigs);
148
+ sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
149
149
  // Apply each plugin one after the other to translate the theme config
150
150
  function translateThemeConfig(untranslatedThemeConfig) {
151
151
  return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
152
- var _a;
153
- const translatedThemeConfigSlice = (_a = plugin.translateThemeConfig) === null || _a === void 0 ? void 0 : _a.call(plugin, {
152
+ const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
154
153
  themeConfig: currentThemeConfig,
155
154
  translationFiles: plugin.translationFiles,
156
155
  });
@@ -4,8 +4,18 @@
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, InitializedPlugin } from '@docusaurus/types';
7
+ /// <reference types="node" />
8
+ import type { ImportedPluginModule, LoadContext, PluginModule, PluginConfig, PluginOptions, InitializedPlugin } from '@docusaurus/types';
9
+ export declare type NormalizedPluginConfig = {
10
+ plugin: PluginModule;
11
+ options: PluginOptions;
12
+ pluginModule?: {
13
+ path: string;
14
+ module: ImportedPluginModule;
15
+ };
16
+ };
17
+ export declare function normalizePluginConfigs(pluginConfigs: PluginConfig[], pluginRequire: NodeRequire): Promise<NormalizedPluginConfig[]>;
8
18
  export default function initPlugins({ pluginConfigs, context, }: {
9
19
  pluginConfigs: PluginConfig[];
10
20
  context: LoadContext;
11
- }): InitializedPlugin[];
21
+ }): Promise<InitializedPlugin[]>;