@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.16

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 (191) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/docusaurus.mjs +280 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +32 -41
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +19 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +5 -9
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  16. package/lib/client/client-lifecycles-dispatcher.js +5 -9
  17. package/lib/client/clientEntry.js +11 -5
  18. package/lib/client/docusaurus.d.ts +6 -0
  19. package/lib/client/docusaurus.js +17 -23
  20. package/lib/client/exports/BrowserOnly.d.ts +2 -3
  21. package/lib/client/exports/BrowserOnly.js +14 -7
  22. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  23. package/lib/client/exports/ComponentCreator.js +7 -6
  24. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  25. package/lib/client/exports/ErrorBoundary.js +36 -0
  26. package/lib/client/exports/Head.d.ts +2 -3
  27. package/lib/client/exports/Head.js +3 -4
  28. package/lib/client/exports/Interpolate.d.ts +1 -1
  29. package/lib/client/exports/Interpolate.js +15 -21
  30. package/lib/client/exports/Link.d.ts +11 -5
  31. package/lib/client/exports/Link.js +29 -17
  32. package/lib/client/exports/Translate.d.ts +3 -3
  33. package/lib/client/exports/Translate.js +15 -10
  34. package/lib/client/exports/browserContext.d.ts +11 -0
  35. package/lib/client/exports/browserContext.js +22 -0
  36. package/lib/client/exports/constants.js +1 -11
  37. package/lib/client/exports/docusaurusContext.d.ts +12 -0
  38. package/lib/client/exports/docusaurusContext.js +25 -0
  39. package/lib/client/exports/isInternalUrl.js +1 -1
  40. package/lib/client/exports/renderRoutes.d.ts +1 -2
  41. package/lib/client/exports/renderRoutes.js +1 -2
  42. package/lib/client/exports/router.d.ts +1 -1
  43. package/lib/client/exports/router.js +1 -1
  44. package/lib/client/exports/useBaseUrl.js +3 -5
  45. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  46. package/lib/client/exports/useDocusaurusContext.js +3 -9
  47. package/lib/client/exports/useGlobalData.js +4 -8
  48. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  49. package/lib/client/exports/useIsBrowser.js +11 -0
  50. package/lib/client/flat.d.ts +2 -2
  51. package/lib/client/flat.js +8 -11
  52. package/lib/client/normalizeLocation.d.ts +2 -5
  53. package/lib/client/normalizeLocation.js +1 -2
  54. package/lib/client/nprogress.css +2 -2
  55. package/lib/client/prefetch.d.ts +1 -2
  56. package/lib/client/prefetch.js +1 -3
  57. package/lib/client/preload.d.ts +3 -2
  58. package/lib/client/preload.js +2 -1
  59. package/lib/client/serverEntry.d.ts +10 -0
  60. package/lib/client/serverEntry.js +90 -142
  61. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  62. package/lib/client/theme-fallback/Error/index.js +39 -0
  63. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  64. package/lib/client/theme-fallback/Layout/index.js +10 -19
  65. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  66. package/lib/client/theme-fallback/Loading/index.js +47 -115
  67. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  68. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  69. package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
  70. package/lib/client/theme-fallback/Root/index.js +2 -7
  71. package/lib/commands/build.d.ts +1 -1
  72. package/lib/commands/build.js +59 -61
  73. package/lib/commands/clear.d.ts +6 -0
  74. package/lib/commands/clear.js +32 -21
  75. package/lib/commands/commandUtils.d.ts +7 -1
  76. package/lib/commands/commandUtils.js +7 -7
  77. package/lib/commands/deploy.d.ts +4 -1
  78. package/lib/commands/deploy.js +115 -71
  79. package/lib/commands/external.d.ts +2 -2
  80. package/lib/commands/external.js +4 -4
  81. package/lib/commands/serve.d.ts +1 -1
  82. package/lib/commands/serve.js +30 -16
  83. package/lib/commands/start.d.ts +1 -1
  84. package/lib/commands/start.js +100 -89
  85. package/lib/commands/swizzle/actions.d.ts +23 -0
  86. package/lib/commands/swizzle/actions.js +102 -0
  87. package/lib/commands/swizzle/common.d.ts +33 -0
  88. package/lib/commands/swizzle/common.js +57 -0
  89. package/lib/commands/swizzle/components.d.ts +29 -0
  90. package/lib/commands/swizzle/components.js +165 -0
  91. package/lib/commands/swizzle/config.d.ts +10 -0
  92. package/lib/commands/swizzle/config.js +77 -0
  93. package/lib/{client/exports → commands/swizzle}/context.d.ts +2 -4
  94. package/lib/commands/swizzle/context.js +30 -0
  95. package/lib/commands/swizzle/index.d.ts +8 -0
  96. package/lib/commands/swizzle/index.js +115 -0
  97. package/lib/commands/swizzle/prompts.d.ts +12 -0
  98. package/lib/commands/swizzle/prompts.js +110 -0
  99. package/lib/commands/swizzle/tables.d.ts +9 -0
  100. package/lib/commands/swizzle/tables.js +116 -0
  101. package/lib/commands/swizzle/themes.d.ts +20 -0
  102. package/lib/commands/swizzle/themes.js +105 -0
  103. package/lib/commands/writeHeadingIds.d.ts +9 -6
  104. package/lib/commands/writeHeadingIds.js +44 -46
  105. package/lib/commands/writeTranslations.d.ts +2 -2
  106. package/lib/commands/writeTranslations.js +36 -14
  107. package/lib/index.d.ts +10 -9
  108. package/lib/index.js +20 -19
  109. package/lib/server/brokenLinks.d.ts +1 -1
  110. package/lib/server/brokenLinks.js +38 -33
  111. package/lib/server/client-modules/index.d.ts +1 -1
  112. package/lib/server/client-modules/index.js +1 -3
  113. package/lib/server/config.d.ts +2 -2
  114. package/lib/server/config.js +10 -7
  115. package/lib/server/configValidation.d.ts +4 -2
  116. package/lib/server/configValidation.js +63 -32
  117. package/lib/server/duplicateRoutes.d.ts +1 -1
  118. package/lib/server/duplicateRoutes.js +10 -6
  119. package/lib/server/html-tags/htmlTags.js +8 -9
  120. package/lib/server/html-tags/index.d.ts +2 -2
  121. package/lib/server/html-tags/index.js +3 -3
  122. package/lib/server/i18n.d.ts +1 -2
  123. package/lib/server/i18n.js +31 -46
  124. package/lib/server/index.d.ts +9 -2
  125. package/lib/server/index.js +165 -87
  126. package/lib/server/loadSetup.d.ts +2 -3
  127. package/lib/server/loadSetup.js +5 -5
  128. package/lib/server/moduleShorthand.d.ts +9 -0
  129. package/lib/server/moduleShorthand.js +46 -0
  130. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
  131. package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
  132. package/lib/server/plugins/index.d.ts +3 -4
  133. package/lib/server/plugins/index.js +53 -37
  134. package/lib/server/plugins/init.d.ts +11 -5
  135. package/lib/server/plugins/init.js +40 -47
  136. package/lib/server/plugins/pluginIds.d.ts +2 -2
  137. package/lib/server/plugins/pluginIds.js +8 -5
  138. package/lib/server/presets/index.d.ts +3 -3
  139. package/lib/server/presets/index.js +14 -14
  140. package/lib/server/routes.d.ts +1 -1
  141. package/lib/server/routes.js +51 -28
  142. package/lib/server/themes/alias.d.ts +3 -2
  143. package/lib/server/themes/alias.js +24 -15
  144. package/lib/server/themes/index.d.ts +6 -2
  145. package/lib/server/themes/index.js +36 -24
  146. package/lib/server/translations/translations.d.ts +10 -5
  147. package/lib/server/translations/translations.js +27 -35
  148. package/lib/server/translations/translationsExtractor.d.ts +9 -4
  149. package/lib/server/translations/translationsExtractor.js +160 -119
  150. package/lib/server/utils.d.ts +9 -3
  151. package/lib/server/utils.js +8 -10
  152. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  153. package/lib/server/versions/index.d.ts +3 -4
  154. package/lib/server/versions/index.js +22 -21
  155. package/lib/webpack/base.d.ts +4 -4
  156. package/lib/webpack/base.js +54 -38
  157. package/lib/webpack/client.d.ts +3 -3
  158. package/lib/webpack/client.js +15 -21
  159. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  160. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  161. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  162. package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
  163. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  164. package/lib/webpack/plugins/LogPlugin.js +5 -6
  165. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  166. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  167. package/lib/webpack/server.d.ts +3 -3
  168. package/lib/webpack/server.js +18 -11
  169. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  170. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  171. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  172. package/lib/webpack/utils.d.ts +9 -30
  173. package/lib/webpack/utils.js +58 -171
  174. package/package.json +76 -69
  175. package/bin/docusaurus.js +0 -326
  176. package/lib/.tsbuildinfo +0 -5732
  177. package/lib/client/.tsbuildinfo +0 -4171
  178. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  179. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  180. package/lib/commands/swizzle.d.ts +0 -9
  181. package/lib/commands/swizzle.js +0 -245
  182. package/lib/constants.d.ts +0 -18
  183. package/lib/constants.js +0 -23
  184. package/lib/server/versions/__tests/index.test.js +0 -25
  185. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  186. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  187. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  188. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  189. package/lib/webpack/sharedModuleAliases.js +0 -18
  190. package/tsconfig.client.json +0 -13
  191. package/tsconfig.json +0 -13
@@ -7,8 +7,6 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  function loadClientModules(plugins) {
10
- return [].concat(...plugins
11
- .map((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; })
12
- .filter(Boolean));
10
+ return plugins.flatMap((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; });
13
11
  }
14
12
  exports.default = loadClientModules;
@@ -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>;
@@ -7,14 +7,17 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
- const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
10
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
+ const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const configValidation_1 = require("./configValidation");
13
- function loadConfig(configPath) {
14
- if (!fs_extra_1.default.existsSync(configPath)) {
15
- throw new Error(`Config file "${configPath}" not found`);
13
+ async function loadConfig(configPath) {
14
+ if (!(await fs_extra_1.default.pathExists(configPath))) {
15
+ throw new Error(`Config file at "${configPath}" not found.`);
16
16
  }
17
- const loadedConfig = import_fresh_1.default(configPath);
18
- return configValidation_1.validateConfig(loadedConfig);
17
+ const importedConfig = (0, import_fresh_1.default)(configPath);
18
+ const loadedConfig = importedConfig instanceof Function
19
+ ? await importedConfig()
20
+ : await importedConfig;
21
+ return (0, configValidation_1.validateConfig)(loadedConfig);
19
22
  }
20
23
  exports.default = loadConfig;
@@ -4,7 +4,9 @@
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
+ import { Joi } from '@docusaurus/utils-validation';
8
9
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
9
- export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner'>;
10
+ export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories'>;
11
+ export declare const ConfigSchema: Joi.ObjectSchema<any>;
10
12
  export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
@@ -6,8 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.validateConfig = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
- const constants_1 = require("../constants");
9
+ exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
+ const utils_1 = require("@docusaurus/utils");
11
11
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
12
  const DEFAULT_I18N_LOCALE = 'en';
13
13
  exports.DEFAULT_I18N_CONFIG = {
@@ -27,19 +27,30 @@ exports.DEFAULT_CONFIG = {
27
27
  themeConfig: {},
28
28
  titleDelimiter: '|',
29
29
  noIndex: false,
30
+ tagline: '',
30
31
  baseUrlIssueBanner: true,
32
+ staticDirectories: [utils_1.STATIC_DIR_NAME],
31
33
  };
32
- const PluginSchema = utils_validation_1.Joi.alternatives()
33
- .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()
34
- .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
35
- .length(2), utils_validation_1.Joi.bool().equal(false))
36
- // TODO isn't there a simpler way to customize the default Joi error message???
37
- // Not sure why Joi makes it complicated to add a custom error message...
38
- // See https://stackoverflow.com/a/54657686/82609
39
- .error((errors) => {
40
- errors.forEach((error) => {
41
- error.message = ` => Bad Docusaurus plugin value as path [${error.path}].
42
- Example valid plugin config:
34
+ function createPluginSchema(theme = false) {
35
+ return (utils_validation_1.Joi.alternatives()
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
+ .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
38
+ .length(2), utils_validation_1.Joi.bool().equal(false))
39
+ // @ts-expect-error: bad lib def, doesn't recognize an array of reports
40
+ .error((errors) => {
41
+ errors.forEach((error) => {
42
+ const validConfigExample = theme
43
+ ? `Example valid theme config:
44
+ {
45
+ themes: [
46
+ ["@docusaurus/theme-classic",options],
47
+ "./myTheme",
48
+ ["./myTheme",{someOption: 42}],
49
+ function myTheme() { },
50
+ [function myTheme() { },options]
51
+ ],
52
+ };`
53
+ : `Example valid plugin config:
43
54
  {
44
55
  plugins: [
45
56
  ["@docusaurus/plugin-content-docs",options],
@@ -48,15 +59,20 @@ Example valid plugin config:
48
59
  function myPlugin() { },
49
60
  [function myPlugin() { },options]
50
61
  ],
51
- };
62
+ };`;
63
+ error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
64
+ ${validConfigExample}
52
65
  `;
53
- });
54
- return errors;
55
- });
56
- const ThemeSchema = 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));
66
+ });
67
+ return errors;
68
+ }));
69
+ }
70
+ const PluginSchema = createPluginSchema(false);
71
+ const ThemeSchema = createPluginSchema(true);
57
72
  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));
58
73
  const LocaleConfigSchema = utils_validation_1.Joi.object({
59
74
  label: utils_validation_1.Joi.string(),
75
+ htmlLang: utils_validation_1.Joi.string(),
60
76
  direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
61
77
  });
62
78
  const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
@@ -68,16 +84,29 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
68
84
  })
69
85
  .optional()
70
86
  .default(exports.DEFAULT_I18N_CONFIG);
87
+ const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, helpers) => {
88
+ try {
89
+ const { pathname } = new URL(value);
90
+ if (pathname !== '/') {
91
+ helpers.warn('docusaurus.configValidationWarning', {
92
+ warningMessage: `the url is not supposed to contain a sub-path like '${pathname}', please use the baseUrl field for sub-paths`,
93
+ });
94
+ }
95
+ }
96
+ catch { }
97
+ return value;
98
+ }, 'siteUrlCustomValidation');
71
99
  // TODO move to @docusaurus/utils-validation
72
- const ConfigSchema = utils_validation_1.Joi.object({
100
+ exports.ConfigSchema = utils_validation_1.Joi.object({
73
101
  baseUrl: utils_validation_1.Joi.string()
74
102
  .required()
75
- .regex(new RegExp('/$', 'm'))
76
- .message('{{#label}} must be a string with a trailing `/`'),
103
+ .regex(/\/$/m)
104
+ .message('{{#label}} must be a string with a trailing slash.'),
77
105
  baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
78
- favicon: utils_validation_1.Joi.string().required(),
106
+ favicon: utils_validation_1.Joi.string().optional(),
79
107
  title: utils_validation_1.Joi.string().required(),
80
- url: utils_validation_1.URISchema.required(),
108
+ url: SiteUrlSchema,
109
+ trailingSlash: utils_validation_1.Joi.boolean(),
81
110
  i18n: I18N_CONFIG_SCHEMA,
82
111
  onBrokenLinks: utils_validation_1.Joi.string()
83
112
  .equal('ignore', 'log', 'warn', 'error', 'throw')
@@ -89,7 +118,11 @@ const ConfigSchema = utils_validation_1.Joi.object({
89
118
  .equal('ignore', 'log', 'warn', 'error', 'throw')
90
119
  .default(exports.DEFAULT_CONFIG.onDuplicateRoutes),
91
120
  organizationName: utils_validation_1.Joi.string().allow(''),
121
+ staticDirectories: utils_validation_1.Joi.array()
122
+ .items(utils_validation_1.Joi.string())
123
+ .default(exports.DEFAULT_CONFIG.staticDirectories),
92
124
  projectName: utils_validation_1.Joi.string().allow(''),
125
+ deploymentBranch: utils_validation_1.Joi.string().optional(),
93
126
  customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
94
127
  githubHost: utils_validation_1.Joi.string(),
95
128
  plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
@@ -106,10 +139,10 @@ const ConfigSchema = utils_validation_1.Joi.object({
106
139
  ssrTemplate: utils_validation_1.Joi.string(),
107
140
  stylesheets: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
108
141
  href: utils_validation_1.Joi.string().required(),
109
- type: utils_validation_1.Joi.string().required(),
142
+ type: utils_validation_1.Joi.string(),
110
143
  }).unknown()),
111
144
  clientModules: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
112
- tagline: utils_validation_1.Joi.string().allow(''),
145
+ tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
113
146
  titleDelimiter: utils_validation_1.Joi.string().default('|'),
114
147
  noIndex: utils_validation_1.Joi.bool().default(false),
115
148
  webpack: utils_validation_1.Joi.object({
@@ -117,18 +150,16 @@ const ConfigSchema = utils_validation_1.Joi.object({
117
150
  .try(utils_validation_1.Joi.string().equal('babel'), utils_validation_1.Joi.function())
118
151
  .optional(),
119
152
  }).optional(),
153
+ }).messages({
154
+ 'docusaurus.configValidationWarning': 'Docusaurus config validation warning. Field {#label}: {#warningMessage}',
120
155
  });
121
156
  // TODO move to @docusaurus/utils-validation
122
157
  function validateConfig(config) {
123
- const { error, value } = ConfigSchema.validate(config, {
158
+ const { error, warning, value } = exports.ConfigSchema.validate(config, {
124
159
  abortEarly: false,
125
160
  });
161
+ (0, utils_validation_1.printWarning)(warning);
126
162
  if (error) {
127
- utils_validation_1.logValidationBugReportHint();
128
- if (utils_validation_1.isValidationDisabledEscapeHatch) {
129
- console.error(error);
130
- return config;
131
- }
132
163
  const unknownFields = error.details.reduce((formattedError, err) => {
133
164
  if (err.type === 'object.unknown') {
134
165
  return `${formattedError}"${err.path}",`;
@@ -139,7 +170,7 @@ function validateConfig(config) {
139
170
  ? `${accumulatedErr}${err.message}\n`
140
171
  : accumulatedErr, '');
141
172
  formattedError = unknownFields
142
- ? `${formattedError}These field(s) [${unknownFields}] are not recognized in ${constants_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the 'customFields' attribute.\nSee https://docusaurus.io/docs/docusaurus.config.js/#customfields`
173
+ ? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/docusaurus.config.js/#customfields`
143
174
  : formattedError;
144
175
  throw new Error(formattedError);
145
176
  }
@@ -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;
@@ -1,19 +1,23 @@
1
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
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getAllDuplicateRoutes = void 0;
4
10
  const utils_1 = require("@docusaurus/utils");
5
11
  const utils_2 = require("./utils");
6
12
  function getAllDuplicateRoutes(pluginsRouteConfigs) {
7
- const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
13
+ const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
8
14
  const seenRoutes = {};
9
15
  return allRoutes.filter((route) => {
10
16
  if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
11
17
  return true;
12
18
  }
13
- else {
14
- seenRoutes[route] = true;
15
- return false;
16
- }
19
+ seenRoutes[route] = true;
20
+ return false;
17
21
  });
18
22
  }
19
23
  exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
@@ -32,7 +36,7 @@ function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
32
36
  const message = getDuplicateRoutesMessage(duplicatePaths);
33
37
  if (message) {
34
38
  const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
35
- utils_1.reportMessage(finalMessage, onDuplicateRoutes);
39
+ (0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
36
40
  }
37
41
  }
38
42
  exports.handleDuplicateRoutes = handleDuplicateRoutes;
@@ -7,22 +7,21 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const lodash_1 = require("lodash");
11
- const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
12
- const void_1 = tslib_1.__importDefault(require("html-tags/void"));
10
+ const html_tags_1 = (0, tslib_1.__importDefault)(require("html-tags"));
11
+ const void_1 = (0, tslib_1.__importDefault)(require("html-tags/void"));
12
+ const escape_html_1 = (0, tslib_1.__importDefault)(require("escape-html"));
13
13
  function assertIsHtmlTagObject(val) {
14
- if (!lodash_1.isPlainObject(val)) {
15
- throw new Error(`"${val}" is not a valid HTML tag object`);
14
+ if (typeof val !== 'object' || !val) {
15
+ throw new Error(`"${val}" is not a valid HTML tag object.`);
16
16
  }
17
- // @ts-expect-error: If tagName doesn't exist, it will throw.
18
17
  if (typeof val.tagName !== 'string') {
19
- throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string`);
18
+ throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
20
19
  }
21
20
  }
22
21
  function htmlTagObjectToString(tagDefinition) {
23
22
  assertIsHtmlTagObject(tagDefinition);
24
23
  if (html_tags_1.default.indexOf(tagDefinition.tagName) === -1) {
25
- throw new Error(`Error loading ${JSON.stringify(tagDefinition)}, "${tagDefinition.tagName}" is not a valid HTML tags`);
24
+ throw new Error(`Error loading ${JSON.stringify(tagDefinition)}, "${tagDefinition.tagName}" is not a valid HTML tags.`);
26
25
  }
27
26
  const isVoidTag = void_1.default.indexOf(tagDefinition.tagName) !== -1;
28
27
  const tagAttributes = tagDefinition.attributes || {};
@@ -32,7 +31,7 @@ function htmlTagObjectToString(tagDefinition) {
32
31
  if (tagAttributes[attributeName] === true) {
33
32
  return attributeName;
34
33
  }
35
- return `${attributeName}="${tagAttributes[attributeName]}"`;
34
+ return `${attributeName}="${(0, escape_html_1.default)(tagAttributes[attributeName])}"`;
36
35
  });
37
36
  return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${(!isVoidTag && tagDefinition.innerHTML) || ''}${isVoidTag ? '' : `</${tagDefinition.tagName}>`}`;
38
37
  }
@@ -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 { Plugin, InjectedHtmlTags, HtmlTags } from '@docusaurus/types';
7
+ import type { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
8
8
  export declare function createHtmlTagsString(tags: HtmlTags): string;
9
- export declare function loadHtmlTags(plugins: Plugin<unknown>[]): InjectedHtmlTags;
9
+ export declare function loadHtmlTags(plugins: LoadedPlugin[]): InjectedHtmlTags;
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadHtmlTags = exports.createHtmlTagsString = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const htmlTags_1 = tslib_1.__importDefault(require("./htmlTags"));
11
+ const htmlTags_1 = (0, tslib_1.__importDefault)(require("./htmlTags"));
12
12
  function toString(val) {
13
- return typeof val === 'string' ? val : htmlTags_1.default(val);
13
+ return typeof val === 'string' ? val : (0, htmlTags_1.default)(val);
14
14
  }
15
15
  function createHtmlTagsString(tags) {
16
16
  return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
@@ -21,7 +21,7 @@ function loadHtmlTags(plugins) {
21
21
  if (!plugin.injectHtmlTags) {
22
22
  return acc;
23
23
  }
24
- const { headTags, preBodyTags, postBodyTags } = plugin.injectHtmlTags() || {};
24
+ const { headTags, preBodyTags, postBodyTags } = plugin.injectHtmlTags({ content: plugin.content }) || {};
25
25
  return {
26
26
  headTags: headTags
27
27
  ? `${acc.headTags}\n${createHtmlTagsString(headTags)}`
@@ -4,9 +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 { 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
- export declare function shouldWarnAboutNodeVersion(version: number, locales: string[]): boolean;
10
9
  export declare function loadI18n(config: DocusaurusConfig, options?: {
11
10
  locale?: string;
12
11
  }): Promise<I18n>;
@@ -1,58 +1,47 @@
1
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
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localizePath = exports.loadI18n = exports.shouldWarnAboutNodeVersion = exports.getDefaultLocaleConfig = void 0;
9
+ exports.localizePath = exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
4
10
  const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
11
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
12
  const utils_1 = require("@docusaurus/utils");
7
13
  const rtl_detect_1 = require("rtl-detect");
8
- const constants_1 = require("../constants");
9
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
14
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
10
15
  function getDefaultLocaleLabel(locale) {
11
- // Intl.DisplayNames is ES2021 - Node14+
12
- // https://v8.dev/features/intl-displaynames
13
- // @ts-expect-error: wait for TS support of ES2021 feature
14
- if (typeof Intl.DisplayNames !== 'undefined') {
15
- // @ts-expect-error: wait for TS support of ES2021 feature
16
- return new Intl.DisplayNames([locale], { type: 'language' }).of(locale);
17
- }
18
- return locale;
16
+ const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
17
+ return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
19
18
  }
20
19
  function getDefaultLocaleConfig(locale) {
21
20
  return {
22
21
  label: getDefaultLocaleLabel(locale),
23
- direction: rtl_detect_1.getLangDir(locale),
22
+ direction: (0, rtl_detect_1.getLangDir)(locale),
23
+ htmlLang: locale,
24
24
  };
25
25
  }
26
26
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
27
- function shouldWarnAboutNodeVersion(version, locales) {
28
- const isOnlyEnglish = locales.length === 1 && locales.includes('en');
29
- const isOlderNodeVersion = version < 14;
30
- return isOlderNodeVersion && !isOnlyEnglish;
31
- }
32
- exports.shouldWarnAboutNodeVersion = shouldWarnAboutNodeVersion;
33
27
  async function loadI18n(config, options = {}) {
34
28
  var _a;
35
29
  const { i18n: i18nConfig } = config;
36
30
  const currentLocale = (_a = options.locale) !== null && _a !== void 0 ? _a : i18nConfig.defaultLocale;
37
31
  if (!i18nConfig.locales.includes(currentLocale)) {
38
- console.warn(chalk_1.default.yellow(`The locale=${currentLocale} was not found in your site configuration: config.i18n.locales=[${i18nConfig.locales.join(',')}]
39
- Note: Docusaurus only support running one locale at a time.`));
32
+ logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
33
+ Note: Docusaurus only support running one locale at a time.`;
40
34
  }
41
35
  const locales = i18nConfig.locales.includes(currentLocale)
42
36
  ? i18nConfig.locales
43
37
  : i18nConfig.locales.concat(currentLocale);
44
- if (shouldWarnAboutNodeVersion(constants_1.NODE_MAJOR_VERSION, locales)) {
45
- console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use NodeJS >= 14 (instead of ${constants_1.NODE_MAJOR_VERSION})`));
46
- }
47
38
  function getLocaleConfig(locale) {
48
39
  return {
49
40
  ...getDefaultLocaleConfig(locale),
50
41
  ...i18nConfig.localeConfigs[locale],
51
42
  };
52
43
  }
53
- const localeConfigs = locales.reduce((acc, locale) => {
54
- return { ...acc, [locale]: getLocaleConfig(locale) };
55
- }, {});
44
+ const localeConfigs = locales.reduce((acc, locale) => ({ ...acc, [locale]: getLocaleConfig(locale) }), {});
56
45
  return {
57
46
  defaultLocale: i18nConfig.defaultLocale,
58
47
  locales,
@@ -62,26 +51,22 @@ Note: Docusaurus only support running one locale at a time.`));
62
51
  }
63
52
  exports.loadI18n = loadI18n;
64
53
  function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
65
- const shouldLocalizePath = typeof options.localizePath === 'undefined'
66
- ? // By default, we don't localize the path of defaultLocale
67
- i18n.currentLocale !== i18n.defaultLocale
68
- : options.localizePath;
69
- if (shouldLocalizePath) {
70
- // FS paths need special care, for Windows support
71
- if (pathType === 'fs') {
72
- return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
73
- }
74
- // Url paths
75
- else if (pathType === 'url') {
76
- return utils_1.normalizeUrl([originalPath, '/', i18n.currentLocale, '/']);
77
- }
78
- // should never happen
79
- else {
80
- throw new Error(`unhandled pathType=${pathType}`);
81
- }
82
- }
83
- else {
54
+ var _a;
55
+ const shouldLocalizePath =
56
+ // By default, we don't localize the path of defaultLocale
57
+ (_a = options.localizePath) !== null && _a !== void 0 ? _a : i18n.currentLocale !== i18n.defaultLocale;
58
+ if (!shouldLocalizePath) {
84
59
  return originalPath;
85
60
  }
61
+ // FS paths need special care, for Windows support
62
+ if (pathType === 'fs') {
63
+ return path_1.default.join(originalPath, i18n.currentLocale);
64
+ }
65
+ // Url paths; add a trailing slash so it's a valid base URL
66
+ if (pathType === 'url') {
67
+ return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
68
+ }
69
+ // should never happen
70
+ throw new Error(`Unhandled path type "${pathType}".`);
86
71
  }
87
72
  exports.localizePath = localizePath;
@@ -4,13 +4,20 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { 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
11
  locale?: string;
12
12
  localizePath?: boolean;
13
13
  };
14
+ export declare function loadSiteConfig({ siteDir, customConfigFilePath, }: {
15
+ siteDir: string;
16
+ customConfigFilePath?: string;
17
+ }): Promise<{
18
+ siteConfig: DocusaurusConfig;
19
+ siteConfigPath: string;
20
+ }>;
14
21
  export declare function loadContext(siteDir: string, options?: LoadContextOptions): Promise<LoadContext>;
15
- export declare function loadPluginConfigs(context: LoadContext): PluginConfig[];
22
+ export declare function loadPluginConfigs(context: LoadContext): Promise<PluginConfig[]>;
16
23
  export declare function load(siteDir: string, options?: LoadContextOptions): Promise<Props>;