@docusaurus/core 2.0.0-beta.16 → 2.0.0-beta.19

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 (171) hide show
  1. package/bin/beforeCli.mjs +14 -12
  2. package/bin/docusaurus.mjs +41 -93
  3. package/lib/babel/preset.js +2 -2
  4. package/lib/client/.eslintrc.js +2 -3
  5. package/lib/client/App.d.ts +1 -1
  6. package/lib/client/App.js +15 -7
  7. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
  8. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
  9. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  10. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  11. package/lib/client/ClientLifecyclesDispatcher.js +34 -0
  12. package/lib/client/LinksCollector.d.ts +1 -1
  13. package/lib/client/LinksCollector.js +4 -5
  14. package/lib/client/PendingNavigation.d.ts +8 -17
  15. package/lib/client/PendingNavigation.js +39 -70
  16. package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
  17. package/lib/client/SiteMetadataDefaults.js +19 -0
  18. package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
  19. package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
  20. package/lib/client/clientEntry.js +3 -4
  21. package/lib/client/docusaurus.d.ts +5 -5
  22. package/lib/client/docusaurus.js +26 -33
  23. package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
  24. package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
  25. package/lib/client/exports/BrowserOnly.d.ts +3 -4
  26. package/lib/client/exports/BrowserOnly.js +2 -2
  27. package/lib/client/exports/ComponentCreator.js +65 -40
  28. package/lib/client/exports/ErrorBoundary.d.ts +2 -2
  29. package/lib/client/exports/ErrorBoundary.js +4 -5
  30. package/lib/client/exports/Interpolate.d.ts +1 -1
  31. package/lib/client/exports/Interpolate.js +18 -41
  32. package/lib/client/exports/Link.d.ts +3 -15
  33. package/lib/client/exports/Link.js +24 -30
  34. package/lib/client/exports/Translate.d.ts +2 -2
  35. package/lib/client/exports/Translate.js +3 -3
  36. package/lib/client/exports/useBaseUrl.js +8 -9
  37. package/lib/client/exports/useDocusaurusContext.js +1 -1
  38. package/lib/client/exports/useGlobalData.d.ts +4 -3
  39. package/lib/client/exports/useGlobalData.js +5 -5
  40. package/lib/client/exports/useIsBrowser.js +1 -1
  41. package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
  42. package/lib/client/exports/useRouteContext.js +15 -0
  43. package/lib/client/flat.d.ts +12 -2
  44. package/lib/client/flat.js +12 -5
  45. package/lib/client/normalizeLocation.js +13 -8
  46. package/lib/client/prefetch.js +10 -28
  47. package/lib/client/preload.d.ts +1 -3
  48. package/lib/client/preload.js +5 -11
  49. package/lib/client/routeContext.d.ts +13 -0
  50. package/lib/client/routeContext.js +31 -0
  51. package/lib/client/serverEntry.js +19 -18
  52. package/lib/client/theme-fallback/Error/index.js +7 -1
  53. package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
  54. package/lib/client/theme-fallback/Layout/index.js +2 -17
  55. package/lib/client/theme-fallback/Loading/index.js +2 -0
  56. package/lib/client/theme-fallback/NotFound/index.js +13 -5
  57. package/lib/client/theme-fallback/Root/index.d.ts +4 -4
  58. package/lib/client/theme-fallback/Root/index.js +2 -1
  59. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  60. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  61. package/lib/commands/build.d.ts +6 -2
  62. package/lib/commands/build.js +48 -30
  63. package/lib/commands/clear.d.ts +1 -1
  64. package/lib/commands/clear.js +6 -5
  65. package/lib/commands/deploy.d.ts +5 -5
  66. package/lib/commands/deploy.js +21 -45
  67. package/lib/commands/external.d.ts +1 -1
  68. package/lib/commands/external.js +6 -11
  69. package/lib/commands/serve.d.ts +7 -2
  70. package/lib/commands/serve.js +18 -19
  71. package/lib/commands/start.d.ts +8 -2
  72. package/lib/commands/start.js +33 -30
  73. package/lib/commands/swizzle/actions.d.ts +2 -2
  74. package/lib/commands/swizzle/actions.js +10 -10
  75. package/lib/commands/swizzle/common.d.ts +3 -3
  76. package/lib/commands/swizzle/common.js +8 -9
  77. package/lib/commands/swizzle/components.js +48 -13
  78. package/lib/commands/swizzle/config.js +21 -15
  79. package/lib/commands/swizzle/context.js +6 -12
  80. package/lib/commands/swizzle/index.d.ts +2 -2
  81. package/lib/commands/swizzle/index.js +5 -4
  82. package/lib/commands/swizzle/prompts.js +2 -2
  83. package/lib/commands/swizzle/tables.js +10 -13
  84. package/lib/commands/swizzle/themes.js +9 -8
  85. package/lib/commands/writeHeadingIds.d.ts +2 -9
  86. package/lib/commands/writeHeadingIds.js +11 -69
  87. package/lib/commands/writeTranslations.d.ts +3 -4
  88. package/lib/commands/writeTranslations.js +10 -14
  89. package/lib/index.d.ts +9 -10
  90. package/lib/index.js +18 -19
  91. package/lib/server/brokenLinks.d.ts +3 -16
  92. package/lib/server/brokenLinks.js +37 -31
  93. package/lib/server/clientModules.d.ts +12 -0
  94. package/lib/server/clientModules.js +20 -0
  95. package/lib/server/config.d.ts +5 -2
  96. package/lib/server/config.js +14 -9
  97. package/lib/server/configValidation.d.ts +1 -1
  98. package/lib/server/configValidation.js +39 -13
  99. package/lib/server/getHostPort.d.ts +14 -0
  100. package/lib/{choosePort.js → server/getHostPort.js} +24 -41
  101. package/lib/server/htmlTags.d.ts +12 -0
  102. package/lib/server/htmlTags.js +62 -0
  103. package/lib/server/i18n.d.ts +2 -11
  104. package/lib/server/i18n.js +7 -28
  105. package/lib/server/index.d.ts +28 -13
  106. package/lib/server/index.js +62 -229
  107. package/lib/server/plugins/configs.d.ts +51 -0
  108. package/lib/server/plugins/configs.js +101 -0
  109. package/lib/server/plugins/index.d.ts +9 -8
  110. package/lib/server/plugins/index.js +65 -132
  111. package/lib/server/plugins/init.d.ts +6 -15
  112. package/lib/server/plugins/init.js +25 -83
  113. package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
  114. package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
  115. package/lib/server/plugins/pluginIds.d.ts +4 -0
  116. package/lib/server/plugins/pluginIds.js +6 -4
  117. package/lib/server/plugins/presets.d.ts +12 -0
  118. package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
  119. package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
  120. package/lib/server/plugins/routeConfig.js +54 -0
  121. package/lib/server/plugins/synthetic.d.ts +20 -0
  122. package/lib/server/plugins/synthetic.js +112 -0
  123. package/lib/server/routes.d.ts +39 -7
  124. package/lib/server/routes.js +169 -102
  125. package/lib/server/siteMetadata.d.ts +12 -0
  126. package/lib/server/siteMetadata.js +81 -0
  127. package/lib/server/translations/translations.d.ts +5 -14
  128. package/lib/server/translations/translations.js +23 -39
  129. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  130. package/lib/server/translations/translationsExtractor.js +16 -19
  131. package/lib/server/utils.js +1 -1
  132. package/lib/webpack/aliases/index.d.ts +34 -0
  133. package/lib/webpack/aliases/index.js +106 -0
  134. package/lib/webpack/base.d.ts +0 -1
  135. package/lib/webpack/base.js +12 -30
  136. package/lib/webpack/client.js +7 -8
  137. package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
  138. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
  139. package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
  140. package/lib/webpack/plugins/LogPlugin.js +2 -2
  141. package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
  142. package/lib/webpack/plugins/WaitPlugin.js +3 -3
  143. package/lib/webpack/server.d.ts +2 -2
  144. package/lib/webpack/server.js +10 -8
  145. package/lib/webpack/utils.d.ts +9 -3
  146. package/lib/webpack/utils.js +20 -25
  147. package/package.json +38 -41
  148. package/lib/choosePort.d.ts +0 -11
  149. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
  150. package/lib/client/client-lifecycles-dispatcher.js +0 -23
  151. package/lib/client/nprogress.css +0 -36
  152. package/lib/commands/commandUtils.d.ts +0 -9
  153. package/lib/commands/commandUtils.js +0 -21
  154. package/lib/server/client-modules/index.js +0 -12
  155. package/lib/server/duplicateRoutes.d.ts +0 -10
  156. package/lib/server/duplicateRoutes.js +0 -42
  157. package/lib/server/html-tags/htmlTags.js +0 -38
  158. package/lib/server/html-tags/index.d.ts +0 -9
  159. package/lib/server/html-tags/index.js +0 -43
  160. package/lib/server/loadSetup.js +0 -25
  161. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  162. package/lib/server/presets/index.d.ts +0 -11
  163. package/lib/server/themes/alias.d.ts +0 -9
  164. package/lib/server/themes/alias.js +0 -48
  165. package/lib/server/themes/index.d.ts +0 -12
  166. package/lib/server/themes/index.js +0 -47
  167. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  168. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  169. package/lib/server/versions/__fixtures__/package.json +0 -3
  170. package/lib/server/versions/index.d.ts +0 -9
  171. package/lib/server/versions/index.js +0 -51
@@ -6,67 +6,50 @@
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 = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
- const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../webpack/templates/ssr.html.template"));
15
- const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
16
- const config_1 = (0, tslib_1.__importDefault)(require("./config"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const path_1 = tslib_1.__importDefault(require("path"));
14
+ const config_1 = require("./config");
15
+ const clientModules_1 = require("./clientModules");
17
16
  const plugins_1 = require("./plugins");
18
- const presets_1 = (0, tslib_1.__importDefault)(require("./presets"));
19
- const routes_1 = (0, tslib_1.__importDefault)(require("./routes"));
20
- const html_tags_1 = require("./html-tags");
21
- const versions_1 = require("./versions");
22
- const duplicateRoutes_1 = require("./duplicateRoutes");
17
+ const routes_1 = require("./routes");
18
+ const htmlTags_1 = require("./htmlTags");
19
+ const siteMetadata_1 = require("./siteMetadata");
23
20
  const i18n_1 = require("./i18n");
24
21
  const translations_1 = require("./translations/translations");
25
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
26
- const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
27
- const module_1 = require("module");
28
- const moduleShorthand_1 = require("./moduleShorthand");
29
- async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
30
- const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : utils_1.DEFAULT_CONFIG_FILE_NAME;
31
- const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
32
- ? siteConfigPathUnresolved
33
- : path_1.default.resolve(siteDir, siteConfigPathUnresolved);
34
- const siteConfig = await (0, config_1.default)(siteConfigPath);
35
- return { siteConfig, siteConfigPath };
36
- }
37
- exports.loadSiteConfig = loadSiteConfig;
38
- async function loadContext(siteDir, options = {}) {
39
- var _a;
40
- const { customOutDir, locale, customConfigFilePath } = options;
41
- const generatedFilesDir = path_1.default.isAbsolute(utils_1.GENERATED_FILES_DIR_NAME)
42
- ? utils_1.GENERATED_FILES_DIR_NAME
43
- : path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
44
- const { siteConfig: initialSiteConfig, siteConfigPath } = await loadSiteConfig({
22
+ /**
23
+ * Loading context is the very first step in site building. Its options are
24
+ * directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
25
+ * context (which includes code translations). The `LoadContext` will be passed
26
+ * to plugin constructors.
27
+ */
28
+ async function loadContext(options) {
29
+ const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, } = options;
30
+ const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
31
+ const { siteConfig: initialSiteConfig, siteConfigPath } = await (0, config_1.loadSiteConfig)({
45
32
  siteDir,
46
33
  customConfigFilePath,
47
34
  });
48
- const { ssrTemplate } = initialSiteConfig;
49
- const baseOutDir = customOutDir
50
- ? path_1.default.resolve(customOutDir)
51
- : path_1.default.resolve(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME);
52
35
  const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
53
- const baseUrl = (0, i18n_1.localizePath)({
36
+ const baseUrl = (0, utils_1.localizePath)({
54
37
  path: initialSiteConfig.baseUrl,
55
38
  i18n,
56
39
  options,
57
40
  pathType: 'url',
58
41
  });
59
- const outDir = (0, i18n_1.localizePath)({
60
- path: baseOutDir,
42
+ const outDir = (0, utils_1.localizePath)({
43
+ path: path_1.default.resolve(siteDir, baseOutDir),
61
44
  i18n,
62
45
  options,
63
46
  pathType: 'fs',
64
47
  });
65
48
  const siteConfig = { ...initialSiteConfig, baseUrl };
66
- const codeTranslationFileContent = (_a = (await (0, translations_1.readCodeTranslationFileContent)({
49
+ const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({
67
50
  siteDir,
68
51
  locale: i18n.currentLocale,
69
- }))) !== null && _a !== void 0 ? _a : {};
52
+ })) ?? {};
70
53
  // We only need key->message for code translations
71
54
  const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
72
55
  return {
@@ -77,191 +60,62 @@ async function loadContext(siteDir, options = {}) {
77
60
  outDir,
78
61
  baseUrl,
79
62
  i18n,
80
- ssrTemplate: ssrTemplate !== null && ssrTemplate !== void 0 ? ssrTemplate : ssr_html_template_1.default,
81
63
  codeTranslations,
82
64
  };
83
65
  }
84
66
  exports.loadContext = loadContext;
85
- async function loadPluginConfigs(context) {
86
- let { plugins: presetPlugins, themes: presetThemes } = await (0, presets_1.default)(context);
87
- const { siteConfig, siteConfigPath } = context;
88
- const require = (0, module_1.createRequire)(siteConfigPath);
89
- function normalizeShorthand(pluginConfig, pluginType) {
90
- var _a;
91
- if (typeof pluginConfig === 'string') {
92
- return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, require, pluginType);
93
- }
94
- else if (Array.isArray(pluginConfig) &&
95
- typeof pluginConfig[0] === 'string') {
96
- return [
97
- (0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], require, pluginType),
98
- (_a = pluginConfig[1]) !== null && _a !== void 0 ? _a : {},
99
- ];
100
- }
101
- return pluginConfig;
102
- }
103
- presetPlugins = presetPlugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
104
- presetThemes = presetThemes.map((theme) => normalizeShorthand(theme, 'theme'));
105
- const standalonePlugins = (siteConfig.plugins || []).map((plugin) => normalizeShorthand(plugin, 'plugin'));
106
- const standaloneThemes = (siteConfig.themes || []).map((theme) => normalizeShorthand(theme, 'theme'));
107
- return [
108
- ...presetPlugins,
109
- ...presetThemes,
110
- // Site config should be the highest priority.
111
- ...standalonePlugins,
112
- ...standaloneThemes,
113
- ];
114
- }
115
- exports.loadPluginConfigs = loadPluginConfigs;
116
- // Make a fake plugin to:
117
- // - Resolve aliased theme components
118
- // - Inject scripts/stylesheets
119
- function createBootstrapPlugin({ siteConfig, }) {
120
- const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
121
- return {
122
- name: 'docusaurus-bootstrap-plugin',
123
- content: null,
124
- options: {},
125
- version: { type: 'synthetic' },
126
- getClientModules() {
127
- return siteConfigClientModules;
128
- },
129
- injectHtmlTags: () => {
130
- const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
131
- ? `<link rel="stylesheet" href="${source}">`
132
- : {
133
- tagName: 'link',
134
- attributes: {
135
- rel: 'stylesheet',
136
- ...source,
137
- },
138
- });
139
- const scriptsTags = scripts.map((source) => typeof source === 'string'
140
- ? `<script src="${source}"></script>`
141
- : {
142
- tagName: 'script',
143
- attributes: {
144
- ...source,
145
- },
146
- });
147
- return {
148
- headTags: [...stylesheetsTags, ...scriptsTags],
149
- };
150
- },
151
- };
152
- }
153
67
  /**
154
- * Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
155
- * folders. Adds a "fallback" mdx loader for mdx files that are not processed by
156
- * content plugins. This allows to do things such as importing repo/README.md as
157
- * a partial from another doc. Not ideal solution, but good enough for now
68
+ * This is the crux of the Docusaurus server-side. It reads everything it needs—
69
+ * code translations, config file, plugin modules... Plugins then use their
70
+ * lifecycles to generate content and other data. It is side-effect-ful because
71
+ * it generates temp files in the `.docusaurus` folder for the bundler.
158
72
  */
159
- function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
160
- return {
161
- name: 'docusaurus-mdx-fallback-plugin',
162
- content: null,
163
- options: {},
164
- version: { type: 'synthetic' },
165
- configureWebpack(config, isServer, { getJSLoader }) {
166
- // We need the mdx fallback loader to exclude files that were already
167
- // processed by content plugins mdx loaders. This works, but a bit
168
- // hacky... Not sure there's a way to handle that differently in webpack
169
- function getMDXFallbackExcludedPaths() {
170
- var _a;
171
- const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
172
- return rules.flatMap((rule) => {
173
- const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
174
- return isMDXRule ? rule.include : [];
175
- });
176
- }
177
- return {
178
- module: {
179
- rules: [
180
- {
181
- test: /\.mdx?$/i,
182
- exclude: getMDXFallbackExcludedPaths(),
183
- use: [
184
- getJSLoader({ isServer }),
185
- {
186
- loader: require.resolve('@docusaurus/mdx-loader'),
187
- options: {
188
- staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
189
- siteDir,
190
- isMDXPartial: (_filename) => true,
191
- isMDXPartialFrontMatterWarningDisabled: true,
192
- remarkPlugins: [remark_admonitions_1.default],
193
- },
194
- },
195
- ],
196
- },
197
- ],
198
- },
199
- };
200
- },
73
+ async function load(options) {
74
+ const { siteDir } = options;
75
+ const context = await loadContext(options);
76
+ const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, codeTranslations: siteCodeTranslations, } = context;
77
+ const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
78
+ const clientModules = (0, clientModules_1.loadClientModules)(plugins);
79
+ const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
80
+ const { registry, routesChunkNames, routesConfig, routesPaths } = (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
81
+ const codeTranslations = {
82
+ ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
83
+ ...siteCodeTranslations,
201
84
  };
202
- }
203
- async function load(siteDir, options = {}) {
204
- // Context.
205
- const context = await loadContext(siteDir, options);
206
- const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
207
- // Plugins.
208
- const pluginConfigs = await loadPluginConfigs(context);
209
- const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
210
- // Side-effect to replace the untranslated themeConfig by the translated one
211
- context.siteConfig.themeConfig = themeConfigTranslated;
212
- (0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
85
+ const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
86
+ // === Side-effects part ===
213
87
  const genWarning = (0, utils_1.generate)(generatedFilesDir, 'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
88
+
214
89
  DO NOT hand-modify files in this folder because they will be overwritten in the
215
90
  next build. You can clear all build artifacts (including this folder) with the
216
91
  \`docusaurus clear\` command.
217
92
  `);
218
- // Site config must be generated after plugins
219
- // We want the generated config to have been normalized by the plugins!
220
93
  const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `/*
221
- AUTOGENERATED - DON'T EDIT
222
- Your edits in this file will be overwritten in the next build!
223
- Modify the docusaurus.config.js file at your site's root instead.
224
- */
225
- export default ${JSON.stringify(siteConfig, null, 2)};`);
226
- plugins.push(createBootstrapPlugin({ siteConfig }));
227
- plugins.push(createMDXFallbackPlugin({ siteDir, siteConfig }));
228
- // Load client modules.
229
- const clientModules = (0, client_modules_1.default)(plugins);
230
- const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
231
- // import() is async so we use require() because client modules can have
232
- // CSS and the order matters for loading CSS.
233
- .map((module) => ` require('${(0, utils_1.escapePath)(module)}'),`)
234
- .join('\n')}\n];\n`);
235
- // Load extra head & body html tags.
236
- const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
237
- // Routing.
238
- const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
94
+ * AUTOGENERATED - DON'T EDIT
95
+ * Your edits in this file will be overwritten in the next build!
96
+ * Modify the docusaurus.config.js file at your site's root instead.
97
+ */
98
+ export default ${JSON.stringify(siteConfig, null, 2)};
99
+ `);
100
+ const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
101
+ ${clientModules
102
+ // Use `require()` because `import()` is async but client modules can have CSS
103
+ // and the order matters for loading CSS.
104
+ .map((clientModule) => ` require('${(0, utils_1.escapePath)(clientModule)}'),`)
105
+ .join('\n')}
106
+ ];
107
+ `);
239
108
  const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
240
- ${Object.keys(registry)
241
- .sort()
242
- .map((key) => ` '${key}': [${registry[key].loader}, '${(0, utils_1.escapePath)(registry[key].modulePath)}', require.resolveWeak('${(0, utils_1.escapePath)(registry[key].modulePath)}')],`)
243
- .join('\n')}};\n`);
109
+ ${Object.entries(registry)
110
+ .sort((a, b) => a[0].localeCompare(b[0]))
111
+ .map(([chunkName, modulePath]) => ` '${chunkName}': [() => import(/* webpackChunkName: '${chunkName}' */ '${modulePath}'), '${modulePath}', require.resolveWeak('${modulePath}')],`)
112
+ .join('\n')}};
113
+ `);
244
114
  const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
245
115
  const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
246
116
  const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
247
117
  const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
248
- const codeTranslationsWithFallbacks = {
249
- ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
250
- ...codeTranslations,
251
- };
252
- const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
253
- // Version metadata.
254
- const siteMetadata = {
255
- docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
256
- siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
257
- pluginVersions: {},
258
- };
259
- plugins
260
- .filter(({ version: { type } }) => type !== 'synthetic')
261
- .forEach(({ name, version }) => {
262
- siteMetadata.pluginVersions[name] = version;
263
- });
264
- checkDocusaurusPackagesVersion(siteMetadata);
118
+ const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslations, null, 2));
265
119
  const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
266
120
  await Promise.all([
267
121
  genWarning,
@@ -275,7 +129,7 @@ ${Object.keys(registry)
275
129
  genI18n,
276
130
  genCodeTranslations,
277
131
  ]);
278
- const props = {
132
+ return {
279
133
  siteConfig,
280
134
  siteConfigPath,
281
135
  siteMetadata,
@@ -290,28 +144,7 @@ ${Object.keys(registry)
290
144
  headTags,
291
145
  preBodyTags,
292
146
  postBodyTags,
293
- ssrTemplate,
294
147
  codeTranslations,
295
148
  };
296
- return props;
297
149
  }
298
150
  exports.load = load;
299
- // We want all @docusaurus/* packages to have the exact same version!
300
- // See https://github.com/facebook/docusaurus/issues/3371
301
- // See https://github.com/facebook/docusaurus/pull/3386
302
- function checkDocusaurusPackagesVersion(siteMetadata) {
303
- const { docusaurusVersion } = siteMetadata;
304
- Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
305
- var _a;
306
- if (versionInfo.type === 'package' &&
307
- ((_a = versionInfo.name) === null || _a === void 0 ? void 0 : _a.startsWith('@docusaurus/')) &&
308
- versionInfo.version &&
309
- versionInfo.version !== docusaurusVersion) {
310
- // should we throw instead?
311
- // It still could work with different versions
312
- logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
313
- All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
314
- Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
315
- }
316
- });
317
- }
@@ -0,0 +1,51 @@
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 { LoadContext, PluginModule, PluginOptions } from '@docusaurus/types';
8
+ declare type ImportedPluginModule = PluginModule & {
9
+ default?: PluginModule;
10
+ };
11
+ export declare type NormalizedPluginConfig = {
12
+ /**
13
+ * The default export of the plugin module, or alternatively, what's provided
14
+ * in the config file as inline plugins. Note that if a file is like:
15
+ *
16
+ * ```ts
17
+ * export default plugin() {...}
18
+ * export validateOptions() {...}
19
+ * ```
20
+ *
21
+ * Then the static methods may not exist here. `pluginModule.module` will
22
+ * always take priority.
23
+ */
24
+ plugin: PluginModule;
25
+ /** Options as they are provided in the config, not validated yet. */
26
+ options: PluginOptions;
27
+ /** Only available when a string is provided in config. */
28
+ pluginModule?: {
29
+ /**
30
+ * Raw module name as provided in the config. Shorthands have been resolved,
31
+ * so at least it's directly `require.resolve`able.
32
+ */
33
+ path: string;
34
+ /** Whatever gets imported with `require`. */
35
+ module: ImportedPluginModule;
36
+ };
37
+ /**
38
+ * Different from `pluginModule.path`, this one is always an absolute path,
39
+ * used to resolve relative paths returned from lifecycles. If it's an inline
40
+ * plugin, it will be path to the config file.
41
+ */
42
+ entryPath: string;
43
+ };
44
+ /**
45
+ * Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
46
+ * normalizes the return value. Plugin configs are ordered, mostly for theme
47
+ * alias shadowing. Site themes have the highest priority, and preset plugins
48
+ * are the lowest.
49
+ */
50
+ export declare function loadPluginConfigs(context: LoadContext): Promise<NormalizedPluginConfig[]>;
51
+ export {};
@@ -0,0 +1,101 @@
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 tslib_1 = require("tslib");
11
+ const module_1 = require("module");
12
+ const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
13
+ const presets_1 = require("./presets");
14
+ const moduleShorthand_1 = require("./moduleShorthand");
15
+ async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
16
+ // plugins: ["./plugin"]
17
+ if (typeof pluginConfig === 'string') {
18
+ const pluginModuleImport = pluginConfig;
19
+ const pluginPath = pluginRequire.resolve(pluginModuleImport);
20
+ const pluginModule = (0, import_fresh_1.default)(pluginPath);
21
+ return {
22
+ plugin: pluginModule?.default ?? pluginModule,
23
+ options: {},
24
+ pluginModule: {
25
+ path: pluginModuleImport,
26
+ module: pluginModule,
27
+ },
28
+ entryPath: pluginPath,
29
+ };
30
+ }
31
+ // plugins: [() => {...}]
32
+ if (typeof pluginConfig === 'function') {
33
+ return {
34
+ plugin: pluginConfig,
35
+ options: {},
36
+ entryPath: configPath,
37
+ };
38
+ }
39
+ // plugins: [
40
+ // ["./plugin",options],
41
+ // ]
42
+ if (typeof pluginConfig[0] === 'string') {
43
+ const pluginModuleImport = pluginConfig[0];
44
+ const pluginPath = pluginRequire.resolve(pluginModuleImport);
45
+ const pluginModule = (0, import_fresh_1.default)(pluginPath);
46
+ return {
47
+ plugin: pluginModule?.default ?? pluginModule,
48
+ options: pluginConfig[1],
49
+ pluginModule: {
50
+ path: pluginModuleImport,
51
+ module: pluginModule,
52
+ },
53
+ entryPath: pluginPath,
54
+ };
55
+ }
56
+ // plugins: [
57
+ // [() => {...}, options],
58
+ // ]
59
+ return {
60
+ plugin: pluginConfig[0],
61
+ options: pluginConfig[1],
62
+ entryPath: configPath,
63
+ };
64
+ }
65
+ /**
66
+ * Reads the site config's `presets`, `themes`, and `plugins`, imports them, and
67
+ * normalizes the return value. Plugin configs are ordered, mostly for theme
68
+ * alias shadowing. Site themes have the highest priority, and preset plugins
69
+ * are the lowest.
70
+ */
71
+ async function loadPluginConfigs(context) {
72
+ const preset = await (0, presets_1.loadPresets)(context);
73
+ const { siteConfig, siteConfigPath } = context;
74
+ const pluginRequire = (0, module_1.createRequire)(siteConfigPath);
75
+ function normalizeShorthand(pluginConfig, pluginType) {
76
+ if (typeof pluginConfig === 'string') {
77
+ return (0, moduleShorthand_1.resolveModuleName)(pluginConfig, pluginRequire, pluginType);
78
+ }
79
+ else if (Array.isArray(pluginConfig) &&
80
+ typeof pluginConfig[0] === 'string') {
81
+ return [
82
+ (0, moduleShorthand_1.resolveModuleName)(pluginConfig[0], pluginRequire, pluginType),
83
+ pluginConfig[1] ?? {},
84
+ ];
85
+ }
86
+ return pluginConfig;
87
+ }
88
+ preset.plugins = preset.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
89
+ preset.themes = preset.themes.map((theme) => normalizeShorthand(theme, 'theme'));
90
+ const standalonePlugins = siteConfig.plugins.map((plugin) => normalizeShorthand(plugin, 'plugin'));
91
+ const standaloneThemes = siteConfig.themes.map((theme) => normalizeShorthand(theme, 'theme'));
92
+ const pluginConfigs = [
93
+ ...preset.plugins,
94
+ ...preset.themes,
95
+ // Site config should be the highest priority.
96
+ ...standalonePlugins,
97
+ ...standaloneThemes,
98
+ ].filter((x) => Boolean(x));
99
+ return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, context.siteConfigPath, pluginRequire)));
100
+ }
101
+ exports.loadPluginConfigs = loadPluginConfigs;
@@ -4,14 +4,15 @@
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, 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, LoadedPlugin } from '@docusaurus/types';
8
+ /**
9
+ * Initializes the plugins, runs `loadContent`, `translateContent`,
10
+ * `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
11
+ * side-effect-ful (it generates temp files), so is this function. This function
12
+ * would also mutate `context.siteConfig.themeConfig` to translate it.
13
+ */
14
+ export declare function loadPlugins(context: LoadContext): Promise<{
13
15
  plugins: LoadedPlugin[];
14
16
  pluginsRouteConfigs: RouteConfig[];
15
- globalData: unknown;
16
- themeConfigTranslated: ThemeConfig;
17
+ globalData: GlobalData;
17
18
  }>;