@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
@@ -6,34 +6,43 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.sortAliases = void 0;
9
10
  const tslib_1 = require("tslib");
10
- const globby_1 = tslib_1.__importDefault(require("globby"));
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const path_1 = tslib_1.__importDefault(require("path"));
11
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const lodash_1 = require("lodash");
15
- function themeAlias(themePath, addOriginalAlias) {
16
- if (!fs_extra_1.default.pathExistsSync(themePath)) {
14
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
15
+ // Order of Webpack aliases is important because one alias can shadow another
16
+ // This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
17
+ // See https://github.com/facebook/docusaurus/pull/3922
18
+ // See https://github.com/facebook/docusaurus/issues/5382
19
+ function sortAliases(aliases) {
20
+ // Alphabetical order by default
21
+ const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
22
+ // @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
23
+ entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
24
+ return Object.fromEntries(entries);
25
+ }
26
+ exports.sortAliases = sortAliases;
27
+ async function themeAlias(themePath, addOriginalAlias) {
28
+ if (!(await fs_extra_1.default.pathExists(themePath))) {
17
29
  return {};
18
30
  }
19
- const themeComponentFiles = globby_1.default.sync(['**/*.{js,jsx,ts,tsx}'], {
31
+ const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
20
32
  cwd: themePath,
21
33
  });
22
- // See https://github.com/facebook/docusaurus/pull/3922
23
- // ensure @theme/NavbarItem alias is created after @theme/NavbarItem/LocaleDropdown
24
- const sortedThemeComponentFiles = lodash_1.sortBy(themeComponentFiles, (file) => file.endsWith('/index.js'));
25
34
  const aliases = {};
26
- sortedThemeComponentFiles.forEach((relativeSource) => {
35
+ themeComponentFiles.forEach((relativeSource) => {
27
36
  const filePath = path_1.default.join(themePath, relativeSource);
28
- const fileName = utils_1.fileToPath(relativeSource);
29
- const aliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme', fileName]).replace(/\/$/, ''));
37
+ const fileName = (0, utils_1.fileToPath)(relativeSource);
38
+ const aliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme', fileName]).replace(/\/$/, ''));
30
39
  aliases[aliasName] = filePath;
31
40
  if (addOriginalAlias) {
32
41
  // For swizzled components to access the original.
33
- const originalAliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme-original', fileName]).replace(/\/$/, ''));
42
+ const originalAliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme-original', fileName]).replace(/\/$/, ''));
34
43
  aliases[originalAliasName] = filePath;
35
44
  }
36
45
  });
37
- return aliases;
46
+ return sortAliases(aliases);
38
47
  }
39
48
  exports.default = themeAlias;
@@ -4,5 +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 { ThemeAlias } from '@docusaurus/types';
8
- export default function loadThemeAlias(themePaths: string[], userThemePaths?: string[]): ThemeAlias;
7
+ import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
8
+ export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
9
+ export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
10
+ siteDir: string;
11
+ plugins: LoadedPlugin[];
12
+ }): Promise<ThemeAliases>;
@@ -6,30 +6,42 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.loadPluginsThemeAliases = exports.loadThemeAliases = void 0;
9
10
  const tslib_1 = require("tslib");
10
- const alias_1 = tslib_1.__importDefault(require("./alias"));
11
- function buildThemeAliases(themeAliases, aliases = {}) {
12
- Object.keys(themeAliases).forEach((aliasKey) => {
13
- if (aliasKey in aliases) {
14
- const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
15
- // eslint-disable-next-line no-param-reassign
16
- aliases[`@theme-init/${componentName}`] = aliases[aliasKey];
17
- }
18
- // eslint-disable-next-line no-param-reassign
19
- aliases[aliasKey] = themeAliases[aliasKey];
20
- });
21
- return aliases;
11
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
+ const utils_1 = require("@docusaurus/utils");
13
+ const alias_1 = (0, tslib_1.__importStar)(require("./alias"));
14
+ const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
15
+ async function loadThemeAliases(themePaths, userThemePaths) {
16
+ const aliases = {};
17
+ for (const themePath of themePaths) {
18
+ const themeAliases = await (0, alias_1.default)(themePath, true);
19
+ Object.keys(themeAliases).forEach((aliasKey) => {
20
+ // If this alias shadows a previous one, use @theme-init to preserve the
21
+ // initial one. @theme-init is only applied once: to the initial theme
22
+ // that provided this component
23
+ if (aliasKey in aliases) {
24
+ const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
25
+ const initAlias = `@theme-init/${componentName}`;
26
+ if (!(initAlias in aliases)) {
27
+ aliases[initAlias] = aliases[aliasKey];
28
+ }
29
+ }
30
+ aliases[aliasKey] = themeAliases[aliasKey];
31
+ });
32
+ }
33
+ for (const themePath of userThemePaths) {
34
+ const userThemeAliases = await (0, alias_1.default)(themePath, false);
35
+ Object.assign(aliases, userThemeAliases);
36
+ }
37
+ return (0, alias_1.sortAliases)(aliases);
22
38
  }
23
- function loadThemeAlias(themePaths, userThemePaths = []) {
24
- let aliases = {};
25
- themePaths.forEach((themePath) => {
26
- const themeAliases = alias_1.default(themePath, true);
27
- aliases = { ...aliases, ...buildThemeAliases(themeAliases, aliases) };
28
- });
29
- userThemePaths.forEach((themePath) => {
30
- const userThemeAliases = alias_1.default(themePath, false);
31
- aliases = { ...aliases, ...buildThemeAliases(userThemeAliases, aliases) };
32
- });
33
- return aliases;
39
+ exports.loadThemeAliases = loadThemeAliases;
40
+ function loadPluginsThemeAliases({ siteDir, plugins, }) {
41
+ const pluginThemes = plugins
42
+ .map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
43
+ .filter((x) => Boolean(x));
44
+ const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
45
+ return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
34
46
  }
35
- exports.default = loadThemeAlias;
47
+ exports.loadPluginsThemeAliases = loadPluginsThemeAliases;
@@ -1,5 +1,10 @@
1
- import { InitPlugin } from '../plugins/init';
2
- import { TranslationFileContent, TranslationFile, TranslationMessage } from '@docusaurus/types';
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { TranslationFileContent, TranslationFile, TranslationMessage, InitializedPlugin } from '@docusaurus/types';
3
8
  export declare type WriteTranslationsOptions = {
4
9
  override?: boolean;
5
10
  messagePrefix?: string;
@@ -21,15 +26,15 @@ export declare function getCodeTranslationsFilePath(context: TranslationContext)
21
26
  export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
22
27
  export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
23
28
  export declare function writePluginTranslations({ siteDir, plugin, locale, translationFile, options, }: TranslationContext & {
24
- plugin: InitPlugin;
29
+ plugin: InitializedPlugin;
25
30
  translationFile: TranslationFile;
26
31
  options?: WriteTranslationsOptions;
27
32
  }): Promise<void>;
28
33
  export declare function localizePluginTranslationFile({ siteDir, plugin, locale, translationFile, }: TranslationContext & {
29
- plugin: InitPlugin;
34
+ plugin: InitializedPlugin;
30
35
  translationFile: TranslationFile;
31
36
  }): Promise<TranslationFile>;
32
- export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitPlugin[]): Promise<Record<string, string>>;
37
+ export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<Record<string, string>>;
33
38
  export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
34
39
  extractedCodeTranslations: Record<string, TranslationMessage>;
35
40
  defaultCodeMessages: Record<string, string>;
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getCodeTranslationsFilePath = exports.getTranslationsLocaleDirPath = exports.getTranslationsDirPath = exports.writeTranslationFileContent = exports.readTranslationFileContent = exports.ensureTranslationFileContent = void 0;
4
- const tslib_1 = require("tslib");
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
- const lodash_1 = require("lodash");
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getCodeTranslationsFilePath = exports.getTranslationsLocaleDirPath = exports.getTranslationsDirPath = exports.writeTranslationFileContent = exports.readTranslationFileContent = exports.ensureTranslationFileContent = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const utils_validation_1 = require("@docusaurus/utils-validation");
16
- const chalk_1 = 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(),
@@ -35,8 +35,9 @@ async function readTranslationFileContent(filePath) {
35
35
  ensureTranslationFileContent(content);
36
36
  return content;
37
37
  }
38
- catch (e) {
39
- throw new Error(`Invalid translation file at path=${filePath}.\n${e.message}`);
38
+ catch (err) {
39
+ logger_1.default.error `Invalid translation file at path=${filePath}.`;
40
+ throw err;
40
41
  }
41
42
  }
42
43
  return undefined;
@@ -44,7 +45,7 @@ async function readTranslationFileContent(filePath) {
44
45
  exports.readTranslationFileContent = readTranslationFileContent;
45
46
  function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
46
47
  // Apply messagePrefix to all messages
47
- const newContentTransformed = lodash_1.mapValues(newContent, (value) => {
48
+ const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => {
48
49
  var _a;
49
50
  return ({
50
51
  ...value,
@@ -56,7 +57,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
56
57
  Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
57
58
  var _a, _b;
58
59
  result[key] = {
59
- // If the messages already exist, we don't override them (unless requested)
60
+ // If messages already exist, we don't override them (unless requested)
60
61
  message: options.override
61
62
  ? message
62
63
  : (_b = (_a = existingContent[key]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : message,
@@ -68,11 +69,10 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
68
69
  async function writeTranslationFileContent({ filePath, content: newContent, options = {}, }) {
69
70
  const existingContent = await readTranslationFileContent(filePath);
70
71
  // Warn about potential legacy keys
71
- const unknownKeys = lodash_1.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
72
+ const unknownKeys = lodash_1.default.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
72
73
  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- ')}`));
74
+ logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
75
+ Maybe you should remove them? ${unknownKeys}`;
76
76
  }
77
77
  const mergedContent = mergeTranslationFileContent({
78
78
  existingContent,
@@ -81,11 +81,9 @@ Maybe you should remove them?
81
81
  });
82
82
  // Avoid creating empty translation files
83
83
  if (Object.keys(mergedContent).length > 0) {
84
- console.log(`${Object.keys(mergedContent)
85
- .length.toString()
86
- .padStart(3, ' ')} translations will be written at ${utils_1.toMessageRelativeFilePath(filePath)}`);
84
+ logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
87
85
  await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
88
- await fs_extra_1.default.writeFile(filePath, JSON.stringify(mergedContent, null, 2));
86
+ await fs_extra_1.default.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
89
87
  }
90
88
  }
91
89
  exports.writeTranslationFileContent = writeTranslationFileContent;
@@ -119,12 +117,12 @@ exports.writeCodeTranslations = writeCodeTranslations;
119
117
  // (json/yaml/toml/xml...)
120
118
  function addTranslationFileExtension(translationFilePath) {
121
119
  if (translationFilePath.endsWith('.json')) {
122
- throw new Error(`Translation file path does not need to end with .json, we addt the extension automatically. translationFilePath=${translationFilePath}`);
120
+ throw new Error(`Translation file path at "${translationFilePath}" does not need to end with ".json", we add the extension automatically.`);
123
121
  }
124
122
  return `${translationFilePath}.json`;
125
123
  }
126
124
  function getPluginTranslationFilePath({ siteDir, plugin, locale, translationFilePath, }) {
127
- const dirPath = utils_1.getPluginI18nPath({
125
+ const dirPath = (0, utils_1.getPluginI18nPath)({
128
126
  siteDir,
129
127
  locale,
130
128
  pluginName: plugin.name,
@@ -165,32 +163,26 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
165
163
  },
166
164
  };
167
165
  }
168
- else {
169
- return translationFile;
170
- }
166
+ return translationFile;
171
167
  }
172
168
  exports.localizePluginTranslationFile = localizePluginTranslationFile;
173
169
  async function getPluginsDefaultCodeTranslationMessages(plugins) {
174
170
  const pluginsMessages = await Promise.all(plugins.map((plugin) => { var _a, _b; return (_b = (_a = plugin.getDefaultCodeTranslationMessages) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : {}; }));
175
- return pluginsMessages.reduce((allMessages, pluginMessages) => {
176
- return { ...allMessages, ...pluginMessages };
177
- }, {});
171
+ return pluginsMessages.reduce((allMessages, pluginMessages) => ({ ...allMessages, ...pluginMessages }), {});
178
172
  }
179
173
  exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
180
174
  function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
181
- const unusedDefaultCodeMessages = lodash_1.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
175
+ const unusedDefaultCodeMessages = lodash_1.default.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
182
176
  if (unusedDefaultCodeMessages.length > 0) {
183
- console.warn(chalk_1.default.yellow(`Unused default message codes found.
184
- Please report this Docusaurus issue.
185
- - ${unusedDefaultCodeMessages.join('\n- ')}
186
- `));
177
+ logger_1.default.warn `Unused default message codes found.
178
+ Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
187
179
  }
188
- return lodash_1.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
180
+ return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
189
181
  var _a;
190
- return {
182
+ return ({
191
183
  ...messageTranslation,
192
184
  message: (_a = defaultCodeMessages[messageId]) !== null && _a !== void 0 ? _a : messageTranslation.message,
193
- };
185
+ });
194
186
  });
195
187
  }
196
188
  exports.applyDefaultCodeTranslations = applyDefaultCodeTranslations;
@@ -1,8 +1,13 @@
1
- import { TransformOptions } from '@babel/core';
2
- import { TranslationFileContent, TranslationMessage } from '@docusaurus/types';
3
- import { InitPlugin } from '../plugins/init';
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type TransformOptions } from '@babel/core';
8
+ import type { InitializedPlugin, TranslationFileContent, TranslationMessage } from '@docusaurus/types';
4
9
  export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<string[]>;
5
- export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitPlugin[], babelOptions: TransformOptions): Promise<TranslationFileContent>;
10
+ export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
6
11
  declare type SourceCodeFileTranslations = {
7
12
  sourceCodeFilePath: string;
8
13
  translations: Record<string, TranslationMessage>;