@docusaurus/core 2.0.0-beta.14 → 2.0.0-beta.15

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 (81) hide show
  1. package/bin/docusaurus.js +1 -1
  2. package/lib/babel/preset.d.ts +1 -1
  3. package/lib/client/LinksCollector.d.ts +1 -1
  4. package/lib/client/PendingNavigation.d.ts +2 -2
  5. package/lib/client/exports/BrowserOnly.d.ts +1 -1
  6. package/lib/client/exports/BrowserOnly.js +7 -2
  7. package/lib/client/exports/ErrorBoundary.d.ts +1 -1
  8. package/lib/client/exports/ErrorBoundary.js +3 -1
  9. package/lib/client/exports/Interpolate.d.ts +1 -1
  10. package/lib/client/exports/Translate.d.ts +2 -2
  11. package/lib/client/exports/browserContext.d.ts +1 -1
  12. package/lib/client/exports/docusaurusContext.d.ts +2 -2
  13. package/lib/client/exports/useBaseUrl.js +2 -2
  14. package/lib/client/exports/useDocusaurusContext.d.ts +1 -1
  15. package/lib/client/nprogress.css +2 -2
  16. package/lib/client/preload.d.ts +1 -1
  17. package/lib/client/serverEntry.d.ts +10 -0
  18. package/lib/client/serverEntry.js +81 -115
  19. package/lib/commands/build.d.ts +1 -1
  20. package/lib/commands/build.js +11 -7
  21. package/lib/commands/commandUtils.d.ts +1 -1
  22. package/lib/commands/deploy.d.ts +1 -1
  23. package/lib/commands/deploy.js +1 -1
  24. package/lib/commands/external.d.ts +1 -1
  25. package/lib/commands/external.js +1 -1
  26. package/lib/commands/serve.d.ts +1 -1
  27. package/lib/commands/start.d.ts +1 -1
  28. package/lib/commands/start.js +4 -5
  29. package/lib/commands/swizzle.d.ts +1 -1
  30. package/lib/commands/swizzle.js +2 -2
  31. package/lib/commands/writeHeadingIds.d.ts +1 -1
  32. package/lib/commands/writeHeadingIds.js +1 -1
  33. package/lib/commands/writeTranslations.d.ts +2 -2
  34. package/lib/commands/writeTranslations.js +1 -1
  35. package/lib/server/brokenLinks.d.ts +1 -1
  36. package/lib/server/brokenLinks.js +1 -2
  37. package/lib/server/client-modules/index.d.ts +1 -1
  38. package/lib/server/config.d.ts +2 -2
  39. package/lib/server/config.js +5 -2
  40. package/lib/server/configValidation.d.ts +1 -1
  41. package/lib/server/configValidation.js +2 -3
  42. package/lib/server/duplicateRoutes.d.ts +1 -1
  43. package/lib/server/html-tags/index.d.ts +1 -1
  44. package/lib/server/i18n.d.ts +1 -1
  45. package/lib/server/i18n.js +3 -8
  46. package/lib/server/index.d.ts +1 -1
  47. package/lib/server/index.js +18 -10
  48. package/lib/server/loadSetup.d.ts +1 -1
  49. package/lib/server/moduleShorthand.js +11 -7
  50. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  51. package/lib/server/plugins/index.d.ts +1 -1
  52. package/lib/server/plugins/index.js +1 -1
  53. package/lib/server/plugins/init.d.ts +2 -2
  54. package/lib/server/plugins/init.js +10 -9
  55. package/lib/server/plugins/pluginIds.d.ts +1 -1
  56. package/lib/server/presets/index.d.ts +1 -1
  57. package/lib/server/presets/index.js +1 -1
  58. package/lib/server/routes.d.ts +1 -1
  59. package/lib/server/routes.js +1 -2
  60. package/lib/server/themes/alias.d.ts +1 -1
  61. package/lib/server/themes/index.d.ts +1 -1
  62. package/lib/server/translations/translations.d.ts +1 -1
  63. package/lib/server/translations/translations.js +1 -1
  64. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  65. package/lib/server/translations/translationsExtractor.js +121 -88
  66. package/lib/server/utils.d.ts +1 -1
  67. package/lib/server/versions/__tests/index.test.js +6 -5
  68. package/lib/server/versions/index.d.ts +1 -1
  69. package/lib/webpack/base.d.ts +2 -2
  70. package/lib/webpack/client.d.ts +2 -2
  71. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +1 -1
  72. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +1 -1
  73. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  74. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  75. package/lib/webpack/server.d.ts +2 -2
  76. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  77. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  78. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  79. package/lib/webpack/utils.d.ts +4 -4
  80. package/lib/webpack/utils.js +8 -5
  81. package/package.json +22 -22
@@ -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 { ConfigOptions } from '@docusaurus/types';
8
- import { WriteTranslationsOptions } from '../server/translations/translations';
7
+ import type { ConfigOptions } from '@docusaurus/types';
8
+ import { type WriteTranslationsOptions } from '../server/translations/translations';
9
9
  export default function writeTranslations(siteDir: string, options: WriteTranslationsOptions & ConfigOptions & {
10
10
  locale?: string;
11
11
  }): Promise<void>;
@@ -51,7 +51,7 @@ async function writeTranslations(siteDir, options) {
51
51
  locale: options.locale,
52
52
  });
53
53
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
54
- const plugins = (0, init_1.default)({
54
+ const plugins = await (0, init_1.default)({
55
55
  pluginConfigs,
56
56
  context,
57
57
  });
@@ -4,7 +4,7 @@
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, ReportingSeverity } from '@docusaurus/types';
7
+ import type { RouteConfig, ReportingSeverity } from '@docusaurus/types';
8
8
  declare type BrokenLink = {
9
9
  link: string;
10
10
  resolvedLink: string;
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenLinksErrorMessage = exports.getAllBrokenLinks = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const react_router_config_1 = require("react-router-config");
12
- const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathname"));
13
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
14
13
  const lodash_1 = require("lodash");
15
14
  const utils_1 = require("@docusaurus/utils");
@@ -29,7 +28,7 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
29
28
  // we must resolve the links before using matchRoutes
30
29
  // resolvePathname is used internally by ReactRouter
31
30
  function resolveLink(link) {
32
- const resolvedLink = (0, resolve_pathname_1.default)(onlyPathname(link), pagePath);
31
+ const resolvedLink = (0, utils_1.resolvePathname)(onlyPathname(link), pagePath);
33
32
  return { link, resolvedLink };
34
33
  }
35
34
  function isBrokenLink(link) {
@@ -4,5 +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
- import { Plugin } from '@docusaurus/types';
7
+ import type { Plugin } from '@docusaurus/types';
8
8
  export default function loadClientModules(plugins: Plugin<unknown>[]): string[];
@@ -4,5 +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
- import { DocusaurusConfig } from '@docusaurus/types';
8
- export default function loadConfig(configPath: string): DocusaurusConfig;
7
+ import type { DocusaurusConfig } from '@docusaurus/types';
8
+ export default function loadConfig(configPath: string): Promise<DocusaurusConfig>;
@@ -10,11 +10,14 @@ const tslib_1 = require("tslib");
10
10
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
11
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const configValidation_1 = require("./configValidation");
13
- function loadConfig(configPath) {
13
+ async function loadConfig(configPath) {
14
14
  if (!fs_extra_1.default.existsSync(configPath)) {
15
15
  throw new Error(`Config file at "${configPath}" not found.`);
16
16
  }
17
- const loadedConfig = (0, import_fresh_1.default)(configPath);
17
+ const importedConfig = (0, import_fresh_1.default)(configPath);
18
+ const loadedConfig = importedConfig instanceof Function
19
+ ? await importedConfig()
20
+ : await importedConfig;
18
21
  return (0, configValidation_1.validateConfig)(loadedConfig);
19
22
  }
20
23
  exports.default = loadConfig;
@@ -4,7 +4,7 @@
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 { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
7
+ import type { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
8
8
  import { Joi } from '@docusaurus/utils-validation';
9
9
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
10
10
  export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner' | 'staticDirectories'>;
@@ -36,9 +36,7 @@ const PluginSchema = utils_validation_1.Joi.alternatives()
36
36
  .try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array().ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required()), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
37
37
  .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
38
38
  .length(2), utils_validation_1.Joi.bool().equal(false))
39
- // TODO isn't there a simpler way to customize the default Joi error message???
40
- // Not sure why Joi makes it complicated to add a custom error message...
41
- // See https://stackoverflow.com/a/54657686/82609
39
+ // @ts-expect-error: bad lib def, doesn't recognize an array of reports
42
40
  .error((errors) => {
43
41
  errors.forEach((error) => {
44
42
  error.message = ` => Bad Docusaurus plugin value as path [${error.path}].
@@ -60,6 +58,7 @@ const ThemeSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1
60
58
  const PresetSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required()).length(2));
61
59
  const LocaleConfigSchema = utils_validation_1.Joi.object({
62
60
  label: utils_validation_1.Joi.string(),
61
+ htmlLang: utils_validation_1.Joi.string(),
63
62
  direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
64
63
  });
65
64
  const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
@@ -4,7 +4,7 @@
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 { ReportingSeverity, RouteConfig } from '@docusaurus/types';
7
+ import type { ReportingSeverity, RouteConfig } from '@docusaurus/types';
8
8
  export declare function getAllDuplicateRoutes(pluginsRouteConfigs: RouteConfig[]): string[];
9
9
  export declare function getDuplicateRoutesMessage(allDuplicateRoutes: string[]): string;
10
10
  export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
@@ -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 { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
7
+ import type { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
8
8
  export declare function createHtmlTagsString(tags: HtmlTags): string;
9
9
  export declare function loadHtmlTags(plugins: LoadedPlugin[]): InjectedHtmlTags;
@@ -4,7 +4,7 @@
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 { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
7
+ import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
8
8
  export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
9
9
  export declare function shouldWarnAboutNodeVersion(version: number, locales: string[]): boolean;
10
10
  export declare function loadI18n(config: DocusaurusConfig, options?: {
@@ -13,19 +13,14 @@ const utils_1 = require("@docusaurus/utils");
13
13
  const rtl_detect_1 = require("rtl-detect");
14
14
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
15
15
  function getDefaultLocaleLabel(locale) {
16
- // Intl.DisplayNames is ES2021 - Node14+
17
- // https://v8.dev/features/intl-displaynames
18
- if (typeof Intl.DisplayNames !== 'undefined') {
19
- const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
20
- return (languageName.charAt(0).toLocaleUpperCase(locale) +
21
- languageName.substring(1));
22
- }
23
- return locale;
16
+ const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
17
+ return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
24
18
  }
25
19
  function getDefaultLocaleConfig(locale) {
26
20
  return {
27
21
  label: getDefaultLocaleLabel(locale),
28
22
  direction: (0, rtl_detect_1.getLangDir)(locale),
23
+ htmlLang: locale,
29
24
  };
30
25
  }
31
26
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
@@ -4,7 +4,7 @@
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 { DocusaurusConfig, LoadContext, PluginConfig, Props } from '@docusaurus/types';
7
+ import type { DocusaurusConfig, LoadContext, PluginConfig, Props } from '@docusaurus/types';
8
8
  export declare type LoadContextOptions = {
9
9
  customOutDir?: string;
10
10
  customConfigFilePath?: string;
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
- const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
14
+ const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../webpack/templates/ssr.html.template"));
15
15
  const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
16
16
  const config_1 = (0, tslib_1.__importDefault)(require("./config"));
17
17
  const plugins_1 = require("./plugins");
@@ -77,7 +77,7 @@ async function loadContext(siteDir, options = {}) {
77
77
  outDir,
78
78
  baseUrl,
79
79
  i18n,
80
- ssrTemplate,
80
+ ssrTemplate: ssrTemplate !== null && ssrTemplate !== void 0 ? ssrTemplate : ssr_html_template_1.default,
81
81
  codeTranslations,
82
82
  };
83
83
  }
@@ -150,7 +150,7 @@ function createBootstrapPlugin({ siteConfig, }) {
150
150
  },
151
151
  };
152
152
  }
153
- // Configurer Webpack fallback mdx loader for md/mdx files out of content-plugin folders
153
+ // Configure Webpack fallback mdx loader for md/mdx files out of content-plugin folders
154
154
  // Adds a "fallback" mdx loader for mdx files that are not processed by content plugins
155
155
  // This allows to do things such as importing repo/README.md as a partial from another doc
156
156
  // Not ideal solution though, but good enough for now
@@ -208,9 +208,19 @@ async function load(siteDir, options = {}) {
208
208
  // Side-effect to replace the untranslated themeConfig by the translated one
209
209
  context.siteConfig.themeConfig = themeConfigTranslated;
210
210
  (0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
211
+ const genWarning = (0, utils_1.generate)(generatedFilesDir, 'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
212
+ DO NOT hand-modify files in this folder because they will be overwritten in the
213
+ next build. You can clear all build artifacts (including this folder) with the
214
+ \`docusaurus clear\` command.
215
+ `);
211
216
  // Site config must be generated after plugins
212
217
  // We want the generated config to have been normalized by the plugins!
213
- const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
218
+ const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `/*
219
+ AUTOGENERATED - DON'T EDIT
220
+ Your edits in this file will be overwritten in the next build!
221
+ Modify the docusaurus.config.js file at your site's root instead.
222
+ */
223
+ export default ${JSON.stringify(siteConfig, null, 2)};`);
214
224
  plugins.push(createBootstrapPlugin({ siteConfig }));
215
225
  plugins.push(createMDXFallbackPlugin({ siteDir, siteConfig }));
216
226
  // Load client modules.
@@ -218,8 +228,7 @@ async function load(siteDir, options = {}) {
218
228
  const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
219
229
  // import() is async so we use require() because client modules can have
220
230
  // CSS and the order matters for loading CSS.
221
- // We need to JSON.stringify so that if its on windows, backslash are escaped.
222
- .map((module) => ` require(${JSON.stringify(module)}),`)
231
+ .map((module) => ` require('${(0, utils_1.escapePath)(module)}'),`)
223
232
  .join('\n')}\n];\n`);
224
233
  // Load extra head & body html tags.
225
234
  const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
@@ -228,9 +237,7 @@ async function load(siteDir, options = {}) {
228
237
  const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
229
238
  ${Object.keys(registry)
230
239
  .sort()
231
- .map((key) =>
232
- // We need to JSON.stringify so that if its on windows, backslash are escaped.
233
- ` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
240
+ .map((key) => ` '${key}': [${registry[key].loader}, '${(0, utils_1.escapePath)(registry[key].modulePath)}', require.resolveWeak('${(0, utils_1.escapePath)(registry[key].modulePath)}')],`)
234
241
  .join('\n')}};\n`);
235
242
  const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
236
243
  const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
@@ -255,6 +262,7 @@ ${Object.keys(registry)
255
262
  checkDocusaurusPackagesVersion(siteMetadata);
256
263
  const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
257
264
  await Promise.all([
265
+ genWarning,
258
266
  genClientModules,
259
267
  genSiteConfig,
260
268
  genRegistry,
@@ -280,7 +288,7 @@ ${Object.keys(registry)
280
288
  headTags,
281
289
  preBodyTags,
282
290
  postBodyTags,
283
- ssrTemplate: ssrTemplate || ssr_html_template_1.default,
291
+ ssrTemplate,
284
292
  codeTranslations,
285
293
  };
286
294
  return props;
@@ -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 { Props } from '@docusaurus/types';
7
+ import type { Props } from '@docusaurus/types';
8
8
  declare const loadSetup: (name: string) => Promise<Props>;
9
9
  export default loadSetup;
@@ -28,15 +28,19 @@ function getNamePatterns(moduleName, moduleType) {
28
28
  exports.getNamePatterns = getNamePatterns;
29
29
  function resolveModuleName(moduleName, moduleRequire, moduleType) {
30
30
  const modulePatterns = getNamePatterns(moduleName, moduleType);
31
- // eslint-disable-next-line no-restricted-syntax
32
- for (const module of modulePatterns) {
31
+ const module = modulePatterns.find((m) => {
33
32
  try {
34
- moduleRequire.resolve(module);
35
- return module;
33
+ moduleRequire.resolve(m);
34
+ return true;
36
35
  }
37
- catch (e) { }
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')}`);
38
43
  }
39
- throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
40
- ${modulePatterns.map((module) => `- ${module}`).join('\n')}`);
44
+ return module;
41
45
  }
42
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;
@@ -4,7 +4,7 @@
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';
7
+ import type { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
8
  export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
9
9
  export declare function loadPlugins({ pluginConfigs, context, }: {
10
10
  pluginConfigs: PluginConfig[];
@@ -52,7 +52,7 @@ function sortConfig(routeConfigs, baseUrl = '/') {
52
52
  exports.sortConfig = sortConfig;
53
53
  async function loadPlugins({ pluginConfigs, context, }) {
54
54
  // 1. Plugin Lifecycle - Initialization/Constructor.
55
- const plugins = (0, init_1.default)({
55
+ const plugins = await (0, init_1.default)({
56
56
  pluginConfigs,
57
57
  context,
58
58
  });
@@ -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, InitializedPlugin } from '@docusaurus/types';
7
+ import type { LoadContext, PluginConfig, InitializedPlugin } from '@docusaurus/types';
8
8
  export default function initPlugins({ pluginConfigs, context, }: {
9
9
  pluginConfigs: PluginConfig[];
10
10
  context: LoadContext;
11
- }): InitializedPlugin[];
11
+ }): Promise<InitializedPlugin[]>;
@@ -85,7 +85,7 @@ function getThemeValidationFunction(normalizedPluginConfig) {
85
85
  return normalizedPluginConfig.plugin.validateThemeConfig;
86
86
  }
87
87
  }
88
- function initPlugins({ pluginConfigs, context, }) {
88
+ async function initPlugins({ pluginConfigs, context, }) {
89
89
  // We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json
90
90
  // declares the dependency on these plugins.
91
91
  const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
@@ -130,11 +130,7 @@ function initPlugins({ pluginConfigs, context, }) {
130
130
  };
131
131
  }
132
132
  }
133
- const plugins = pluginConfigs
134
- .map((pluginConfig) => {
135
- if (!pluginConfig) {
136
- return null;
137
- }
133
+ async function initializePlugin(pluginConfig) {
138
134
  const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
139
135
  const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
140
136
  const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
@@ -143,14 +139,19 @@ function initPlugins({ pluginConfigs, context, }) {
143
139
  ...context.siteConfig.themeConfig,
144
140
  ...doValidateThemeConfig(normalizedPluginConfig),
145
141
  };
146
- const pluginInstance = normalizedPluginConfig.plugin(context, pluginOptions);
142
+ const pluginInstance = await normalizedPluginConfig.plugin(context, pluginOptions);
147
143
  return {
148
144
  ...pluginInstance,
149
145
  options: pluginOptions,
150
146
  version: pluginVersion,
151
147
  };
152
- })
153
- .filter((item) => Boolean(item));
148
+ }
149
+ const plugins = (await Promise.all(pluginConfigs.map((pluginConfig) => {
150
+ if (!pluginConfig) {
151
+ return null;
152
+ }
153
+ return initializePlugin(pluginConfig);
154
+ }))).filter((item) => Boolean(item));
154
155
  (0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
155
156
  return plugins;
156
157
  }
@@ -4,5 +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
- import { InitializedPlugin } from '@docusaurus/types';
7
+ import type { InitializedPlugin } from '@docusaurus/types';
8
8
  export declare function ensureUniquePluginInstanceIds(plugins: InitializedPlugin[]): void;
@@ -4,7 +4,7 @@
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 } from '@docusaurus/types';
7
+ import type { LoadContext, PluginConfig } from '@docusaurus/types';
8
8
  export default function loadPresets(context: LoadContext): {
9
9
  plugins: PluginConfig[];
10
10
  themes: PluginConfig[];
@@ -14,7 +14,7 @@ function loadPresets(context) {
14
14
  // We need to resolve presets from the perspective of the siteDir, since the siteDir's package.json
15
15
  // declares the dependency on these presets.
16
16
  const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
17
- const presets = (context.siteConfig || {}).presets || [];
17
+ const presets = context.siteConfig.presets || [];
18
18
  const unflatPlugins = [];
19
19
  const unflatThemes = [];
20
20
  presets.forEach((presetItem) => {
@@ -4,7 +4,7 @@
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 { ChunkRegistry, RouteConfig, ChunkNames } from '@docusaurus/types';
7
+ import type { ChunkRegistry, RouteConfig, ChunkNames } from '@docusaurus/types';
8
8
  declare type LoadedRoutes = {
9
9
  registry: {
10
10
  [chunkName: string]: ChunkRegistry;
@@ -122,8 +122,7 @@ registry, value, prefix, name) {
122
122
  if (isModule(value)) {
123
123
  const modulePath = getModulePath(value);
124
124
  const chunkName = (0, utils_1.genChunkName)(modulePath, prefix, name);
125
- // We need to JSON.stringify so that if its on windows, backslashes are escaped.
126
- const loader = `() => import(/* webpackChunkName: '${chunkName}' */ ${JSON.stringify(modulePath)})`;
125
+ const loader = `() => import(/* webpackChunkName: '${chunkName}' */ '${(0, utils_1.escapePath)(modulePath)}')`;
127
126
  registry[chunkName] = {
128
127
  loader,
129
128
  modulePath,
@@ -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 { ThemeAliases } from '@docusaurus/types';
7
+ import type { ThemeAliases } from '@docusaurus/types';
8
8
  export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
9
9
  export default function themeAlias(themePath: string, addOriginalAlias: boolean): ThemeAliases;
@@ -4,7 +4,7 @@
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 { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
7
+ import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
8
8
  export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): ThemeAliases;
9
9
  export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
10
10
  siteDir: string;
@@ -4,7 +4,7 @@
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 { TranslationFileContent, TranslationFile, TranslationMessage, InitializedPlugin } from '@docusaurus/types';
7
+ import type { TranslationFileContent, TranslationFile, TranslationMessage, InitializedPlugin } from '@docusaurus/types';
8
8
  export declare type WriteTranslationsOptions = {
9
9
  override?: boolean;
10
10
  messagePrefix?: string;
@@ -82,7 +82,7 @@ Maybe you should remove them? ${unknownKeys}`;
82
82
  if (Object.keys(mergedContent).length > 0) {
83
83
  logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
84
84
  await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
85
- await fs_extra_1.default.writeFile(filePath, JSON.stringify(mergedContent, null, 2));
85
+ await fs_extra_1.default.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
86
86
  }
87
87
  }
88
88
  exports.writeTranslationFileContent = writeTranslationFileContent;
@@ -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 { TransformOptions } from '@babel/core';
8
- import { InitializedPlugin, TranslationFileContent, TranslationMessage } from '@docusaurus/types';
7
+ import { type TransformOptions } from '@babel/core';
8
+ import type { InitializedPlugin, TranslationFileContent, TranslationMessage } from '@docusaurus/types';
9
9
  export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<string[]>;
10
10
  export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
11
11
  declare type SourceCodeFileTranslations = {