@docusaurus/core 2.0.0-beta.13 → 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 (90) hide show
  1. package/bin/beforeCli.js +14 -15
  2. package/bin/docusaurus.js +7 -5
  3. package/lib/babel/preset.d.ts +1 -1
  4. package/lib/choosePort.js +8 -8
  5. package/lib/client/LinksCollector.d.ts +1 -1
  6. package/lib/client/PendingNavigation.d.ts +2 -2
  7. package/lib/client/exports/BrowserOnly.d.ts +1 -1
  8. package/lib/client/exports/BrowserOnly.js +7 -2
  9. package/lib/client/exports/ErrorBoundary.d.ts +1 -1
  10. package/lib/client/exports/ErrorBoundary.js +3 -1
  11. package/lib/client/exports/Interpolate.d.ts +1 -1
  12. package/lib/client/exports/Translate.d.ts +2 -2
  13. package/lib/client/exports/browserContext.d.ts +1 -1
  14. package/lib/client/exports/docusaurusContext.d.ts +2 -2
  15. package/lib/client/exports/useBaseUrl.js +2 -2
  16. package/lib/client/exports/useDocusaurusContext.d.ts +1 -1
  17. package/lib/client/nprogress.css +2 -2
  18. package/lib/client/preload.d.ts +1 -1
  19. package/lib/client/serverEntry.d.ts +10 -0
  20. package/lib/client/serverEntry.js +86 -126
  21. package/lib/commands/build.d.ts +1 -1
  22. package/lib/commands/build.js +17 -15
  23. package/lib/commands/clear.js +10 -11
  24. package/lib/commands/commandUtils.d.ts +1 -1
  25. package/lib/commands/deploy.d.ts +1 -1
  26. package/lib/commands/deploy.js +12 -14
  27. package/lib/commands/external.d.ts +1 -1
  28. package/lib/commands/external.js +1 -1
  29. package/lib/commands/serve.d.ts +1 -1
  30. package/lib/commands/serve.js +2 -8
  31. package/lib/commands/start.d.ts +1 -1
  32. package/lib/commands/start.js +23 -22
  33. package/lib/commands/swizzle.d.ts +1 -1
  34. package/lib/commands/swizzle.js +26 -35
  35. package/lib/commands/writeHeadingIds.d.ts +1 -1
  36. package/lib/commands/writeHeadingIds.js +4 -5
  37. package/lib/commands/writeTranslations.d.ts +2 -2
  38. package/lib/commands/writeTranslations.js +1 -1
  39. package/lib/server/brokenLinks.d.ts +1 -1
  40. package/lib/server/brokenLinks.js +1 -2
  41. package/lib/server/client-modules/index.d.ts +1 -1
  42. package/lib/server/config.d.ts +2 -2
  43. package/lib/server/config.js +5 -2
  44. package/lib/server/configValidation.d.ts +1 -1
  45. package/lib/server/configValidation.js +5 -4
  46. package/lib/server/duplicateRoutes.d.ts +1 -1
  47. package/lib/server/html-tags/index.d.ts +1 -1
  48. package/lib/server/i18n.d.ts +1 -1
  49. package/lib/server/i18n.js +6 -14
  50. package/lib/server/index.d.ts +1 -1
  51. package/lib/server/index.js +26 -15
  52. package/lib/server/loadSetup.d.ts +1 -1
  53. package/lib/server/moduleShorthand.js +11 -7
  54. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  55. package/lib/server/plugins/index.d.ts +1 -1
  56. package/lib/server/plugins/index.js +3 -3
  57. package/lib/server/plugins/init.d.ts +2 -2
  58. package/lib/server/plugins/init.js +10 -9
  59. package/lib/server/plugins/pluginIds.d.ts +1 -1
  60. package/lib/server/presets/index.d.ts +1 -1
  61. package/lib/server/presets/index.js +1 -1
  62. package/lib/server/routes.d.ts +1 -1
  63. package/lib/server/routes.js +1 -2
  64. package/lib/server/themes/alias.d.ts +1 -1
  65. package/lib/server/themes/index.d.ts +1 -1
  66. package/lib/server/translations/translations.d.ts +1 -1
  67. package/lib/server/translations/translations.js +7 -12
  68. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  69. package/lib/server/translations/translationsExtractor.js +123 -92
  70. package/lib/server/utils.d.ts +1 -1
  71. package/lib/server/versions/__tests/index.test.js +6 -5
  72. package/lib/server/versions/index.d.ts +1 -1
  73. package/lib/webpack/base.d.ts +2 -2
  74. package/lib/webpack/client.d.ts +2 -2
  75. package/lib/webpack/client.js +2 -2
  76. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +1 -1
  77. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +1 -1
  78. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  79. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  80. package/lib/webpack/server.d.ts +2 -2
  81. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  82. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  83. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  84. package/lib/webpack/utils.d.ts +4 -4
  85. package/lib/webpack/utils.js +19 -14
  86. package/package.json +22 -22
  87. package/lib/.tsbuildinfo +0 -1
  88. package/lib/client/.tsbuildinfo +0 -1
  89. package/tsconfig.client.json +0 -12
  90. package/tsconfig.json +0 -14
@@ -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'>;
@@ -7,6 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
10
12
  const utils_1 = require("@docusaurus/utils");
11
13
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
14
  const DEFAULT_I18N_LOCALE = 'en';
@@ -34,9 +36,7 @@ const PluginSchema = utils_validation_1.Joi.alternatives()
34
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()
35
37
  .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
36
38
  .length(2), utils_validation_1.Joi.bool().equal(false))
37
- // TODO isn't there a simpler way to customize the default Joi error message???
38
- // Not sure why Joi makes it complicated to add a custom error message...
39
- // See https://stackoverflow.com/a/54657686/82609
39
+ // @ts-expect-error: bad lib def, doesn't recognize an array of reports
40
40
  .error((errors) => {
41
41
  errors.forEach((error) => {
42
42
  error.message = ` => Bad Docusaurus plugin value as path [${error.path}].
@@ -58,6 +58,7 @@ const ThemeSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1
58
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));
59
59
  const LocaleConfigSchema = utils_validation_1.Joi.object({
60
60
  label: utils_validation_1.Joi.string(),
61
+ htmlLang: utils_validation_1.Joi.string(),
61
62
  direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
62
63
  });
63
64
  const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
@@ -147,7 +148,7 @@ function validateConfig(config) {
147
148
  if (error) {
148
149
  (0, utils_validation_1.logValidationBugReportHint)();
149
150
  if (utils_validation_1.isValidationDisabledEscapeHatch) {
150
- console.error(error);
151
+ logger_1.default.error(error.message);
151
152
  return config;
152
153
  }
153
154
  const unknownFields = error.details.reduce((formattedError, err) => {
@@ -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?: {
@@ -11,21 +11,16 @@ const tslib_1 = require("tslib");
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const rtl_detect_1 = require("rtl-detect");
14
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
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;
@@ -40,15 +35,12 @@ async function loadI18n(config, options = {}) {
40
35
  const { i18n: i18nConfig } = config;
41
36
  const currentLocale = (_a = options.locale) !== null && _a !== void 0 ? _a : i18nConfig.defaultLocale;
42
37
  if (!i18nConfig.locales.includes(currentLocale)) {
43
- console.warn(chalk_1.default.yellow(`The locale "${currentLocale}" was not found in your site configuration: Available locales are: ${i18nConfig.locales.join(',')}.
44
- Note: Docusaurus only support running one locale at a time.`));
38
+ logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
39
+ Note: Docusaurus only support running one locale at a time.`;
45
40
  }
46
41
  const locales = i18nConfig.locales.includes(currentLocale)
47
42
  ? i18nConfig.locales
48
43
  : i18nConfig.locales.concat(currentLocale);
49
- if (shouldWarnAboutNodeVersion(utils_1.NODE_MAJOR_VERSION, locales)) {
50
- console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use Node.js 14 or later (instead of ${utils_1.NODE_MAJOR_VERSION}).`));
51
- }
52
44
  function getLocaleConfig(locale) {
53
45
  return {
54
46
  ...getDefaultLocaleConfig(locale),
@@ -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;
@@ -9,9 +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 = (0, tslib_1.__importStar)(require("path"));
13
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
14
- const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
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
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);
@@ -243,8 +250,8 @@ ${Object.keys(registry)
243
250
  const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
244
251
  // Version metadata.
245
252
  const siteMetadata = {
246
- docusaurusVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(__dirname, '../../package.json')),
247
- siteVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(siteDir, 'package.json')),
253
+ docusaurusVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json')),
254
+ siteVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
248
255
  pluginVersions: {},
249
256
  };
250
257
  plugins
@@ -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;
@@ -295,10 +303,13 @@ function checkDocusaurusPackagesVersion(siteMetadata) {
295
303
  var _a;
296
304
  if (versionInfo.type === 'package' &&
297
305
  ((_a = versionInfo.name) === null || _a === void 0 ? void 0 : _a.startsWith('@docusaurus/')) &&
306
+ versionInfo.version &&
298
307
  versionInfo.version !== docusaurusVersion) {
299
308
  // should we throw instead?
300
309
  // It still could work with different versions
301
- 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?`));
310
+ logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
311
+ All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
312
+ Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
302
313
  }
303
314
  });
304
315
  }
@@ -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[];
@@ -12,7 +12,7 @@ const utils_1 = require("@docusaurus/utils");
12
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
13
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
14
  const init_1 = (0, tslib_1.__importDefault)(require("./init"));
15
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
15
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
16
16
  const lodash_1 = require("lodash");
17
17
  const translations_1 = require("../translations/translations");
18
18
  const applyRouteTrailingSlash_1 = (0, tslib_1.__importDefault)(require("./applyRouteTrailingSlash"));
@@ -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
  });
@@ -144,7 +144,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
144
144
  // TODO remove this deprecated lifecycle soon
145
145
  // deprecated since alpha-60
146
146
  // TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918
147
- 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'));
147
+ 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'}`;
148
148
  return plugin.routesLoaded(pluginsRouteConfigs);
149
149
  }));
150
150
  // Sort the route config. This ensures that route with nested
@@ -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;
@@ -13,7 +13,7 @@ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
13
  const lodash_1 = require("lodash");
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const utils_validation_1 = require("@docusaurus/utils-validation");
16
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
16
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
17
17
  const TranslationFileContentSchema = utils_validation_1.Joi.object()
18
18
  .pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
19
19
  message: utils_validation_1.Joi.string().allow('').required(),
@@ -70,9 +70,8 @@ async function writeTranslationFileContent({ filePath, content: newContent, opti
70
70
  // Warn about potential legacy keys
71
71
  const unknownKeys = (0, lodash_1.difference)(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
72
72
  if (unknownKeys.length > 0) {
73
- console.warn(chalk_1.default.yellow(`Some translation keys looks unknown to us in file ${filePath}
74
- Maybe you should remove them?
75
- - ${unknownKeys.join('\n- ')}`));
73
+ logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
74
+ Maybe you should remove them? ${unknownKeys}`;
76
75
  }
77
76
  const mergedContent = mergeTranslationFileContent({
78
77
  existingContent,
@@ -81,11 +80,9 @@ Maybe you should remove them?
81
80
  });
82
81
  // Avoid creating empty translation files
83
82
  if (Object.keys(mergedContent).length > 0) {
84
- console.log(`${Object.keys(mergedContent)
85
- .length.toString()
86
- .padStart(3, ' ')} translations will be written at "${(0, utils_1.toMessageRelativeFilePath)(filePath)}".`);
83
+ logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
87
84
  await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
88
- 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`);
89
86
  }
90
87
  }
91
88
  exports.writeTranslationFileContent = writeTranslationFileContent;
@@ -178,10 +175,8 @@ exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslat
178
175
  function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
179
176
  const unusedDefaultCodeMessages = (0, lodash_1.difference)(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
180
177
  if (unusedDefaultCodeMessages.length > 0) {
181
- console.warn(chalk_1.default.yellow(`Unused default message codes found.
182
- Please report this Docusaurus issue.
183
- - ${unusedDefaultCodeMessages.join('\n- ')}
184
- `));
178
+ logger_1.default.warn `Unused default message codes found.
179
+ Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
185
180
  }
186
181
  return (0, lodash_1.mapValues)(extractedCodeTranslations, (messageTranslation, messageId) => {
187
182
  var _a;
@@ -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 = {