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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/bin/beforeCli.mjs +14 -12
  2. package/bin/docusaurus.mjs +41 -93
  3. package/lib/babel/preset.js +2 -2
  4. package/lib/client/.eslintrc.js +2 -3
  5. package/lib/client/App.d.ts +1 -1
  6. package/lib/client/App.js +15 -7
  7. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
  8. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
  9. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  10. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  11. package/lib/client/ClientLifecyclesDispatcher.js +34 -0
  12. package/lib/client/LinksCollector.d.ts +1 -1
  13. package/lib/client/LinksCollector.js +4 -5
  14. package/lib/client/PendingNavigation.d.ts +8 -17
  15. package/lib/client/PendingNavigation.js +39 -70
  16. package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
  17. package/lib/client/SiteMetadataDefaults.js +19 -0
  18. package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
  19. package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
  20. package/lib/client/clientEntry.js +3 -4
  21. package/lib/client/docusaurus.d.ts +5 -5
  22. package/lib/client/docusaurus.js +26 -33
  23. package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
  24. package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
  25. package/lib/client/exports/BrowserOnly.d.ts +3 -4
  26. package/lib/client/exports/BrowserOnly.js +2 -2
  27. package/lib/client/exports/ComponentCreator.js +65 -40
  28. package/lib/client/exports/ErrorBoundary.d.ts +2 -2
  29. package/lib/client/exports/ErrorBoundary.js +4 -5
  30. package/lib/client/exports/Interpolate.d.ts +1 -1
  31. package/lib/client/exports/Interpolate.js +18 -41
  32. package/lib/client/exports/Link.d.ts +3 -15
  33. package/lib/client/exports/Link.js +24 -30
  34. package/lib/client/exports/Translate.d.ts +2 -2
  35. package/lib/client/exports/Translate.js +3 -3
  36. package/lib/client/exports/useBaseUrl.js +8 -9
  37. package/lib/client/exports/useDocusaurusContext.js +1 -1
  38. package/lib/client/exports/useGlobalData.d.ts +4 -3
  39. package/lib/client/exports/useGlobalData.js +5 -5
  40. package/lib/client/exports/useIsBrowser.js +1 -1
  41. package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
  42. package/lib/client/exports/useRouteContext.js +15 -0
  43. package/lib/client/flat.d.ts +12 -2
  44. package/lib/client/flat.js +12 -5
  45. package/lib/client/normalizeLocation.js +13 -8
  46. package/lib/client/prefetch.js +10 -28
  47. package/lib/client/preload.d.ts +1 -3
  48. package/lib/client/preload.js +5 -11
  49. package/lib/client/routeContext.d.ts +13 -0
  50. package/lib/client/routeContext.js +31 -0
  51. package/lib/client/serverEntry.js +19 -18
  52. package/lib/client/theme-fallback/Error/index.js +7 -1
  53. package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
  54. package/lib/client/theme-fallback/Layout/index.js +2 -17
  55. package/lib/client/theme-fallback/Loading/index.js +2 -0
  56. package/lib/client/theme-fallback/NotFound/index.js +13 -5
  57. package/lib/client/theme-fallback/Root/index.d.ts +4 -4
  58. package/lib/client/theme-fallback/Root/index.js +2 -1
  59. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  60. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  61. package/lib/commands/build.d.ts +6 -2
  62. package/lib/commands/build.js +48 -30
  63. package/lib/commands/clear.d.ts +1 -1
  64. package/lib/commands/clear.js +6 -5
  65. package/lib/commands/deploy.d.ts +5 -5
  66. package/lib/commands/deploy.js +21 -45
  67. package/lib/commands/external.d.ts +1 -1
  68. package/lib/commands/external.js +6 -11
  69. package/lib/commands/serve.d.ts +7 -2
  70. package/lib/commands/serve.js +18 -19
  71. package/lib/commands/start.d.ts +8 -2
  72. package/lib/commands/start.js +33 -30
  73. package/lib/commands/swizzle/actions.d.ts +2 -2
  74. package/lib/commands/swizzle/actions.js +10 -10
  75. package/lib/commands/swizzle/common.d.ts +3 -3
  76. package/lib/commands/swizzle/common.js +8 -9
  77. package/lib/commands/swizzle/components.js +48 -13
  78. package/lib/commands/swizzle/config.js +21 -15
  79. package/lib/commands/swizzle/context.js +6 -12
  80. package/lib/commands/swizzle/index.d.ts +2 -2
  81. package/lib/commands/swizzle/index.js +5 -4
  82. package/lib/commands/swizzle/prompts.js +2 -2
  83. package/lib/commands/swizzle/tables.js +10 -13
  84. package/lib/commands/swizzle/themes.js +9 -8
  85. package/lib/commands/writeHeadingIds.d.ts +2 -9
  86. package/lib/commands/writeHeadingIds.js +11 -69
  87. package/lib/commands/writeTranslations.d.ts +3 -4
  88. package/lib/commands/writeTranslations.js +10 -14
  89. package/lib/index.d.ts +9 -10
  90. package/lib/index.js +18 -19
  91. package/lib/server/brokenLinks.d.ts +3 -16
  92. package/lib/server/brokenLinks.js +37 -31
  93. package/lib/server/clientModules.d.ts +12 -0
  94. package/lib/server/clientModules.js +20 -0
  95. package/lib/server/config.d.ts +5 -2
  96. package/lib/server/config.js +14 -9
  97. package/lib/server/configValidation.d.ts +1 -1
  98. package/lib/server/configValidation.js +39 -13
  99. package/lib/server/getHostPort.d.ts +14 -0
  100. package/lib/{choosePort.js → server/getHostPort.js} +24 -41
  101. package/lib/server/htmlTags.d.ts +12 -0
  102. package/lib/server/htmlTags.js +62 -0
  103. package/lib/server/i18n.d.ts +2 -11
  104. package/lib/server/i18n.js +7 -28
  105. package/lib/server/index.d.ts +28 -13
  106. package/lib/server/index.js +62 -229
  107. package/lib/server/plugins/configs.d.ts +51 -0
  108. package/lib/server/plugins/configs.js +101 -0
  109. package/lib/server/plugins/index.d.ts +9 -8
  110. package/lib/server/plugins/index.js +65 -132
  111. package/lib/server/plugins/init.d.ts +6 -15
  112. package/lib/server/plugins/init.js +25 -83
  113. package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
  114. package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
  115. package/lib/server/plugins/pluginIds.d.ts +4 -0
  116. package/lib/server/plugins/pluginIds.js +6 -4
  117. package/lib/server/plugins/presets.d.ts +12 -0
  118. package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
  119. package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
  120. package/lib/server/plugins/routeConfig.js +54 -0
  121. package/lib/server/plugins/synthetic.d.ts +20 -0
  122. package/lib/server/plugins/synthetic.js +112 -0
  123. package/lib/server/routes.d.ts +39 -7
  124. package/lib/server/routes.js +169 -102
  125. package/lib/server/siteMetadata.d.ts +12 -0
  126. package/lib/server/siteMetadata.js +81 -0
  127. package/lib/server/translations/translations.d.ts +5 -14
  128. package/lib/server/translations/translations.js +23 -39
  129. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  130. package/lib/server/translations/translationsExtractor.js +16 -19
  131. package/lib/server/utils.js +1 -1
  132. package/lib/webpack/aliases/index.d.ts +34 -0
  133. package/lib/webpack/aliases/index.js +106 -0
  134. package/lib/webpack/base.d.ts +0 -1
  135. package/lib/webpack/base.js +12 -30
  136. package/lib/webpack/client.js +7 -8
  137. package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
  138. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
  139. package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
  140. package/lib/webpack/plugins/LogPlugin.js +2 -2
  141. package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
  142. package/lib/webpack/plugins/WaitPlugin.js +3 -3
  143. package/lib/webpack/server.d.ts +2 -2
  144. package/lib/webpack/server.js +10 -8
  145. package/lib/webpack/utils.d.ts +9 -3
  146. package/lib/webpack/utils.js +20 -25
  147. package/package.json +38 -41
  148. package/lib/choosePort.d.ts +0 -11
  149. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
  150. package/lib/client/client-lifecycles-dispatcher.js +0 -23
  151. package/lib/client/nprogress.css +0 -36
  152. package/lib/commands/commandUtils.d.ts +0 -9
  153. package/lib/commands/commandUtils.js +0 -21
  154. package/lib/server/client-modules/index.js +0 -12
  155. package/lib/server/duplicateRoutes.d.ts +0 -10
  156. package/lib/server/duplicateRoutes.js +0 -42
  157. package/lib/server/html-tags/htmlTags.js +0 -38
  158. package/lib/server/html-tags/index.d.ts +0 -9
  159. package/lib/server/html-tags/index.js +0 -43
  160. package/lib/server/loadSetup.js +0 -25
  161. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  162. package/lib/server/presets/index.d.ts +0 -11
  163. package/lib/server/themes/alias.d.ts +0 -9
  164. package/lib/server/themes/alias.js +0 -48
  165. package/lib/server/themes/index.d.ts +0 -12
  166. package/lib/server/themes/index.js +0 -47
  167. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  168. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  169. package/lib/server/versions/__fixtures__/package.json +0 -3
  170. package/lib/server/versions/index.d.ts +0 -9
  171. package/lib/server/versions/index.js +0 -51
@@ -6,14 +6,14 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
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;
9
+ exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getTranslationsLocaleDirPath = void 0;
10
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"));
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const lodash_1 = 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 logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
16
+ const logger_1 = 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(),
@@ -27,11 +27,10 @@ function ensureTranslationFileContent(content) {
27
27
  convert: false,
28
28
  });
29
29
  }
30
- exports.ensureTranslationFileContent = ensureTranslationFileContent;
31
30
  async function readTranslationFileContent(filePath) {
32
31
  if (await fs_extra_1.default.pathExists(filePath)) {
33
32
  try {
34
- const content = JSON.parse(await fs_extra_1.default.readFile(filePath, 'utf8'));
33
+ const content = await fs_extra_1.default.readJSON(filePath);
35
34
  ensureTranslationFileContent(content);
36
35
  return content;
37
36
  }
@@ -42,26 +41,21 @@ async function readTranslationFileContent(filePath) {
42
41
  }
43
42
  return undefined;
44
43
  }
45
- exports.readTranslationFileContent = readTranslationFileContent;
46
44
  function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
47
45
  // Apply messagePrefix to all messages
48
- const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => {
49
- var _a;
50
- return ({
51
- ...value,
52
- message: `${(_a = options.messagePrefix) !== null && _a !== void 0 ? _a : ''}${value.message}`,
53
- });
54
- });
46
+ const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => ({
47
+ ...value,
48
+ message: `${options.messagePrefix ?? ''}${value.message}`,
49
+ }));
55
50
  const result = { ...existingContent };
56
51
  // We only add missing keys here, we don't delete existing ones
57
52
  Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
58
- var _a, _b;
59
53
  result[key] = {
60
54
  // If messages already exist, we don't override them (unless requested)
61
55
  message: options.override
62
56
  ? message
63
- : (_b = (_a = existingContent[key]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : message,
64
- description, // description
57
+ : existingContent[key]?.message ?? message,
58
+ description,
65
59
  };
66
60
  });
67
61
  return result;
@@ -69,7 +63,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
69
63
  async function writeTranslationFileContent({ filePath, content: newContent, options = {}, }) {
70
64
  const existingContent = await readTranslationFileContent(filePath);
71
65
  // Warn about potential legacy keys
72
- const unknownKeys = lodash_1.default.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
66
+ const unknownKeys = lodash_1.default.difference(Object.keys(existingContent ?? {}), Object.keys(newContent));
73
67
  if (unknownKeys.length > 0) {
74
68
  logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
75
69
  Maybe you should remove them? ${unknownKeys}`;
@@ -82,24 +76,17 @@ Maybe you should remove them? ${unknownKeys}`;
82
76
  // Avoid creating empty translation files
83
77
  if (Object.keys(mergedContent).length > 0) {
84
78
  logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
85
- await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
86
- await fs_extra_1.default.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
79
+ await fs_extra_1.default.outputFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
87
80
  }
88
81
  }
89
- exports.writeTranslationFileContent = writeTranslationFileContent;
90
- // should we make this configurable?
91
- function getTranslationsDirPath(context) {
92
- return path_1.default.resolve(path_1.default.join(context.siteDir, `i18n`));
93
- }
94
- exports.getTranslationsDirPath = getTranslationsDirPath;
82
+ // Should we make this configurable?
95
83
  function getTranslationsLocaleDirPath(context) {
96
- return path_1.default.join(getTranslationsDirPath(context), context.locale);
84
+ return path_1.default.join(context.siteDir, utils_1.I18N_DIR_NAME, context.locale);
97
85
  }
98
86
  exports.getTranslationsLocaleDirPath = getTranslationsLocaleDirPath;
99
87
  function getCodeTranslationsFilePath(context) {
100
- return path_1.default.join(getTranslationsLocaleDirPath(context), 'code.json');
88
+ return path_1.default.join(getTranslationsLocaleDirPath(context), utils_1.CODE_TRANSLATIONS_FILE_NAME);
101
89
  }
102
- exports.getCodeTranslationsFilePath = getCodeTranslationsFilePath;
103
90
  async function readCodeTranslationFileContent(context) {
104
91
  return readTranslationFileContent(getCodeTranslationsFilePath(context));
105
92
  }
@@ -154,7 +141,7 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
154
141
  });
155
142
  const localizedContent = await readTranslationFileContent(filePath);
156
143
  if (localizedContent) {
157
- // localized messages "override" default unlocalized messages
144
+ // Localized messages "override" default unlocalized messages
158
145
  return {
159
146
  path: translationFile.path,
160
147
  content: {
@@ -167,7 +154,7 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
167
154
  }
168
155
  exports.localizePluginTranslationFile = localizePluginTranslationFile;
169
156
  async function getPluginsDefaultCodeTranslationMessages(plugins) {
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 : {}; }));
157
+ const pluginsMessages = await Promise.all(plugins.map((plugin) => plugin.getDefaultCodeTranslationMessages?.() ?? {}));
171
158
  return pluginsMessages.reduce((allMessages, pluginMessages) => ({ ...allMessages, ...pluginMessages }), {});
172
159
  }
173
160
  exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
@@ -177,12 +164,9 @@ function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMe
177
164
  logger_1.default.warn `Unused default message codes found.
178
165
  Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
179
166
  }
180
- return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
181
- var _a;
182
- return ({
183
- ...messageTranslation,
184
- message: (_a = defaultCodeMessages[messageId]) !== null && _a !== void 0 ? _a : messageTranslation.message,
185
- });
186
- });
167
+ return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => ({
168
+ ...messageTranslation,
169
+ message: defaultCodeMessages[messageId] ?? messageTranslation.message,
170
+ }));
187
171
  }
188
172
  exports.applyDefaultCodeTranslations = applyDefaultCodeTranslations;
@@ -5,12 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type TransformOptions } from '@babel/core';
8
- import type { InitializedPlugin, TranslationFileContent, TranslationMessage } from '@docusaurus/types';
8
+ import type { InitializedPlugin, TranslationFileContent } 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 = {
12
12
  sourceCodeFilePath: string;
13
- translations: Record<string, TranslationMessage>;
13
+ translations: TranslationFileContent;
14
14
  warnings: string[];
15
15
  };
16
16
  export declare function extractAllSourceCodeFileTranslations(sourceCodeFilePaths: string[], babelOptions: TransformOptions): Promise<SourceCodeFileTranslations[]>;
@@ -8,12 +8,12 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.extractSourceCodeFileTranslations = exports.extractAllSourceCodeFileTranslations = exports.extractSiteSourceCodeTranslations = exports.globSourceCodeFilePaths = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const traverse_1 = (0, tslib_1.__importDefault)(require("@babel/traverse"));
13
- const generator_1 = (0, tslib_1.__importDefault)(require("@babel/generator"));
14
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
13
+ const generator_1 = tslib_1.__importDefault(require("@babel/generator"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const core_1 = require("@babel/core");
16
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
16
+ const path_1 = tslib_1.__importDefault(require("path"));
17
17
  const utils_1 = require("@docusaurus/utils");
18
18
  const utils_2 = require("../utils");
19
19
  // We only support extracting source code translations from these kind of files
@@ -34,18 +34,17 @@ function getSiteSourceCodeFilePaths(siteDir) {
34
34
  return [path_1.default.join(siteDir, utils_1.SRC_DIR_NAME)];
35
35
  }
36
36
  function getPluginSourceCodeFilePaths(plugin) {
37
- var _a, _b, _c;
38
37
  // The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
39
38
  // We can use this method as well to know which folders we should try to
40
39
  // extract translations from. Hacky/implicit, but do we want to introduce a
41
40
  // new lifecycle method just for that???
42
- const codePaths = (_b = (_a = plugin.getPathsToWatch) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : [];
41
+ const codePaths = plugin.getPathsToWatch?.() ?? [];
43
42
  // We also include theme code
44
- const themePath = (_c = plugin.getThemePath) === null || _c === void 0 ? void 0 : _c.call(plugin);
43
+ const themePath = plugin.getThemePath?.();
45
44
  if (themePath) {
46
45
  codePaths.push(themePath);
47
46
  }
48
- return codePaths;
47
+ return codePaths.map((p) => path_1.default.resolve(plugin.path, p));
49
48
  }
50
49
  async function globSourceCodeFilePaths(dirPaths) {
51
50
  const filePaths = await (0, utils_2.safeGlobby)(dirPaths);
@@ -119,8 +118,7 @@ https://github.com/pugjs/babel-walk
119
118
  */
120
119
  function extractSourceCodeAstTranslations(ast, sourceCodeFilePath) {
121
120
  function sourceWarningPart(node) {
122
- var _a;
123
- return `File: ${sourceCodeFilePath} at line ${(_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line}
121
+ return `File: ${sourceCodeFilePath} at line ${node.loc?.start.line}
124
122
  Full code: ${(0, generator_1.default)(node).code}`;
125
123
  }
126
124
  const translations = {};
@@ -142,8 +140,8 @@ Full code: ${(0, generator_1.default)(node).code}`;
142
140
  .node.name === 'translate' ||
143
141
  specifier.get('imported')
144
142
  .node.value === 'translate'));
145
- translateComponentName = defaultImport === null || defaultImport === void 0 ? void 0 : defaultImport.get('local').node.name;
146
- translateFunctionName = callbackImport === null || callbackImport === void 0 ? void 0 : callbackImport.get('local').node.name;
143
+ translateComponentName = defaultImport?.get('local').node.name;
144
+ translateFunctionName = callbackImport?.get('local').node.name;
147
145
  },
148
146
  });
149
147
  (0, traverse_1.default)(ast, {
@@ -205,15 +203,14 @@ ${sourceWarningPart(path.node)}`);
205
203
  .filter((children) => !(children.isJSXText() &&
206
204
  children.node.value.replace('\n', '').trim() === ''))
207
205
  .pop();
208
- const isJSXText = singleChildren && singleChildren.isJSXText();
209
- const isJSXExpressionContainer = singleChildren &&
210
- singleChildren.isJSXExpressionContainer() &&
206
+ const isJSXText = singleChildren?.isJSXText();
207
+ const isJSXExpressionContainer = singleChildren?.isJSXExpressionContainer() &&
211
208
  singleChildren.get('expression').evaluate().confident;
212
209
  if (isJSXText || isJSXExpressionContainer) {
213
210
  message = isJSXText
214
211
  ? singleChildren.node.value.trim().replace(/\s+/g, ' ')
215
212
  : singleChildren.get('expression').evaluate().value;
216
- translations[id !== null && id !== void 0 ? id : message] = {
213
+ translations[id ?? message] = {
217
214
  message,
218
215
  ...(description && { description }),
219
216
  };
@@ -237,8 +234,8 @@ ${sourceWarningPart(path.node)}`);
237
234
  if (firstArgEvaluated.confident &&
238
235
  typeof firstArgEvaluated.value === 'object') {
239
236
  const { message, id, description } = firstArgEvaluated.value;
240
- translations[id !== null && id !== void 0 ? id : message] = {
241
- message: message !== null && message !== void 0 ? message : id,
237
+ translations[id ?? message] = {
238
+ message: message ?? id,
242
239
  ...(description && { description }),
243
240
  };
244
241
  }
@@ -8,7 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.safeGlobby = exports.getAllFinalRoutes = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  // Recursively get the final routes (routes with no subroutes)
14
14
  function getAllFinalRoutes(routeConfig) {
@@ -0,0 +1,34 @@
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 { LoadedPlugin } from '@docusaurus/types';
8
+ /**
9
+ * Aliases used for Webpack resolution (useful for implementing swizzling)
10
+ */
11
+ declare type ThemeAliases = {
12
+ [alias: string]: string;
13
+ };
14
+ /**
15
+ * Order of Webpack aliases is important because one alias can shadow another.
16
+ * This ensures `@theme/NavbarItem` alias is after
17
+ * `@theme/NavbarItem/LocaleDropdown`.
18
+ *
19
+ * @see https://github.com/facebook/docusaurus/pull/3922
20
+ * @see https://github.com/facebook/docusaurus/issues/5382
21
+ */
22
+ export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
23
+ export declare function createAliasesForTheme(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
24
+ export declare function loadThemeAliases({ siteDir, plugins, }: {
25
+ siteDir: string;
26
+ plugins: LoadedPlugin[];
27
+ }): Promise<ThemeAliases>;
28
+ /**
29
+ * Note: a `@docusaurus` alias would also catch `@docusaurus/theme-common`, so
30
+ * instead of naively aliasing this to `client/exports`, we use fine-grained
31
+ * aliases instead.
32
+ */
33
+ export declare function loadDocusaurusAliases(): Promise<ThemeAliases>;
34
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.loadDocusaurusAliases = exports.loadThemeAliases = exports.createAliasesForTheme = exports.sortAliases = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
15
+ const ThemeFallbackDir = path_1.default.join(__dirname, '../../client/theme-fallback');
16
+ /**
17
+ * Order of Webpack aliases is important because one alias can shadow another.
18
+ * This ensures `@theme/NavbarItem` alias is after
19
+ * `@theme/NavbarItem/LocaleDropdown`.
20
+ *
21
+ * @see https://github.com/facebook/docusaurus/pull/3922
22
+ * @see https://github.com/facebook/docusaurus/issues/5382
23
+ */
24
+ function sortAliases(aliases) {
25
+ // Alphabetical order by default
26
+ const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
27
+ // @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
28
+ entries.sort(([alias1], [alias2]) =>
29
+ // eslint-disable-next-line no-nested-ternary
30
+ alias1.includes(`${alias2}/`) ? -1 : alias2.includes(`${alias1}/`) ? 1 : 0);
31
+ return Object.fromEntries(entries);
32
+ }
33
+ exports.sortAliases = sortAliases;
34
+ async function createAliasesForTheme(themePath, addOriginalAlias) {
35
+ if (!(await fs_extra_1.default.pathExists(themePath))) {
36
+ return {};
37
+ }
38
+ const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
39
+ cwd: themePath,
40
+ });
41
+ const aliases = {};
42
+ themeComponentFiles.forEach((relativeSource) => {
43
+ const filePath = path_1.default.join(themePath, relativeSource);
44
+ const fileName = (0, utils_1.fileToPath)(relativeSource);
45
+ const aliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme', fileName]).replace(/\/$/, ''));
46
+ aliases[aliasName] = filePath;
47
+ if (addOriginalAlias) {
48
+ // For swizzled components to access the original.
49
+ const originalAliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme-original', fileName]).replace(/\/$/, ''));
50
+ aliases[originalAliasName] = filePath;
51
+ }
52
+ });
53
+ return sortAliases(aliases);
54
+ }
55
+ exports.createAliasesForTheme = createAliasesForTheme;
56
+ async function createThemeAliases(themePaths, userThemePaths) {
57
+ const aliases = {};
58
+ for (const themePath of themePaths) {
59
+ const themeAliases = await createAliasesForTheme(themePath, true);
60
+ Object.entries(themeAliases).forEach(([aliasKey, alias]) => {
61
+ // If this alias shadows a previous one, use @theme-init to preserve the
62
+ // initial one. @theme-init is only applied once: to the initial theme
63
+ // that provided this component
64
+ if (aliasKey in aliases) {
65
+ const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
66
+ const initAlias = `@theme-init/${componentName}`;
67
+ if (!(initAlias in aliases)) {
68
+ aliases[initAlias] = aliases[aliasKey];
69
+ }
70
+ }
71
+ aliases[aliasKey] = alias;
72
+ });
73
+ }
74
+ for (const themePath of userThemePaths) {
75
+ const userThemeAliases = await createAliasesForTheme(themePath, false);
76
+ Object.assign(aliases, userThemeAliases);
77
+ }
78
+ return sortAliases(aliases);
79
+ }
80
+ function loadThemeAliases({ siteDir, plugins, }) {
81
+ const pluginThemes = plugins
82
+ .map((plugin) => plugin.getThemePath && path_1.default.resolve(plugin.path, plugin.getThemePath()))
83
+ .filter((x) => Boolean(x));
84
+ const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
85
+ return createThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
86
+ }
87
+ exports.loadThemeAliases = loadThemeAliases;
88
+ /**
89
+ * Note: a `@docusaurus` alias would also catch `@docusaurus/theme-common`, so
90
+ * instead of naively aliasing this to `client/exports`, we use fine-grained
91
+ * aliases instead.
92
+ */
93
+ async function loadDocusaurusAliases() {
94
+ const dirPath = path_1.default.resolve(__dirname, '../../client/exports');
95
+ const extensions = ['.js', '.ts', '.tsx'];
96
+ const aliases = {};
97
+ (await fs_extra_1.default.readdir(dirPath))
98
+ .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
99
+ .forEach((fileName) => {
100
+ const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
101
+ const aliasName = `@docusaurus/${fileNameWithoutExtension}`;
102
+ aliases[aliasName] = path_1.default.resolve(dirPath, fileName);
103
+ });
104
+ return aliases;
105
+ }
106
+ exports.loadDocusaurusAliases = loadDocusaurusAliases;
@@ -8,5 +8,4 @@ import type { Configuration } from 'webpack';
8
8
  import type { Props } from '@docusaurus/types';
9
9
  export declare const clientDir: string;
10
10
  export declare function excludeJS(modulePath: string): boolean;
11
- export declare function getDocusaurusAliases(): Promise<Record<string, string>>;
12
11
  export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
@@ -6,23 +6,23 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createBaseConfig = exports.getDocusaurusAliases = exports.excludeJS = exports.clientDir = void 0;
9
+ exports.createBaseConfig = exports.excludeJS = exports.clientDir = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const mini_css_extract_plugin_1 = (0, tslib_1.__importDefault)(require("mini-css-extract-plugin"));
13
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
13
+ const path_1 = tslib_1.__importDefault(require("path"));
14
14
  const utils_1 = require("./utils");
15
- const themes_1 = require("../server/themes");
15
+ const aliases_1 = require("./aliases");
16
16
  const utils_2 = require("@docusaurus/utils");
17
17
  const CSS_REGEX = /\.css$/i;
18
18
  const CSS_MODULE_REGEX = /\.module\.css$/i;
19
19
  exports.clientDir = path_1.default.join(__dirname, '..', 'client');
20
20
  const LibrariesToTranspile = [
21
- 'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
21
+ 'copy-text-to-clipboard', // Contains optional catch binding, incompatible with recent versions of Edge
22
22
  ];
23
23
  const LibrariesToTranspileRegex = new RegExp(LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'));
24
24
  function excludeJS(modulePath) {
25
- // always transpile client dir
25
+ // Always transpile client dir
26
26
  if (modulePath.startsWith(exports.clientDir)) {
27
27
  return false;
28
28
  }
@@ -32,22 +32,7 @@ function excludeJS(modulePath) {
32
32
  !LibrariesToTranspileRegex.test(modulePath));
33
33
  }
34
34
  exports.excludeJS = excludeJS;
35
- async function getDocusaurusAliases() {
36
- const dirPath = path_1.default.resolve(__dirname, '../client/exports');
37
- const extensions = ['.js', '.ts', '.tsx'];
38
- const aliases = {};
39
- (await fs_extra_1.default.readdir(dirPath))
40
- .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
41
- .forEach((fileName) => {
42
- const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
43
- const aliasName = `@docusaurus/${fileNameWithoutExtension}`;
44
- aliases[aliasName] = path_1.default.resolve(dirPath, fileName);
45
- });
46
- return aliases;
47
- }
48
- exports.getDocusaurusAliases = getDocusaurusAliases;
49
35
  async function createBaseConfig(props, isServer, minify = true) {
50
- var _a;
51
36
  const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
52
37
  const totalPages = routesPaths.length;
53
38
  const isProd = process.env.NODE_ENV === 'production';
@@ -56,7 +41,7 @@ async function createBaseConfig(props, isServer, minify = true) {
56
41
  const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
57
42
  const name = isServer ? 'server' : 'client';
58
43
  const mode = isProd ? 'production' : 'development';
59
- const themeAliases = await (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
44
+ const themeAliases = await (0, aliases_1.loadThemeAliases)({ siteDir, plugins });
60
45
  return {
61
46
  mode,
62
47
  name,
@@ -117,10 +102,7 @@ async function createBaseConfig(props, isServer, minify = true) {
117
102
  alias: {
118
103
  '@site': siteDir,
119
104
  '@generated': generatedFilesDir,
120
- // Note: a @docusaurus alias would also catch @docusaurus/theme-common,
121
- // so we use fine-grained aliases instead
122
- // '@docusaurus': path.resolve(__dirname, '../client/exports'),
123
- ...(await getDocusaurusAliases()),
105
+ ...(await (0, aliases_1.loadDocusaurusAliases)()),
124
106
  ...themeAliases,
125
107
  },
126
108
  // This allows you to set a fallback for where Webpack should look for
@@ -153,7 +135,7 @@ async function createBaseConfig(props, isServer, minify = true) {
153
135
  // include [name] in the filenames
154
136
  name: false,
155
137
  cacheGroups: {
156
- // disable the built-in cacheGroups
138
+ // Disable the built-in cacheGroups
157
139
  default: false,
158
140
  common: {
159
141
  name: 'common',
@@ -185,7 +167,7 @@ async function createBaseConfig(props, isServer, minify = true) {
185
167
  test: /\.[jt]sx?$/i,
186
168
  exclude: excludeJS,
187
169
  use: [
188
- (0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
170
+ (0, utils_1.getCustomizableJSLoader)(siteConfig.webpack?.jsLoader)({
189
171
  isServer,
190
172
  babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
191
173
  }),
@@ -224,7 +206,7 @@ async function createBaseConfig(props, isServer, minify = true) {
224
206
  chunkFilename: isProd
225
207
  ? 'assets/css/[name].[contenthash:8].css'
226
208
  : '[name].css',
227
- // remove css order warnings if css imports are not sorted
209
+ // Remove css order warnings if css imports are not sorted
228
210
  // alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
229
211
  // for more reasoning
230
212
  ignoreOrder: true,
@@ -7,18 +7,17 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
- const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
10
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
13
13
  const base_1 = require("./base");
14
- const ChunkAssetPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/ChunkAssetPlugin"));
15
- const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
14
+ const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
15
+ const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
16
16
  async function createClientConfig(props, minify = true) {
17
- var _a;
18
17
  const isBuilding = process.argv[2] === 'build';
19
18
  const config = await (0, base_1.createBaseConfig)(props, false, minify);
20
19
  const clientConfig = (0, webpack_merge_1.default)(config, {
21
- // useless, disabled on purpose (errors on existing sites with no
20
+ // Useless, disabled on purpose (errors on existing sites with no
22
21
  // browserslist config)
23
22
  // target: 'browserslist',
24
23
  entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
@@ -38,7 +37,7 @@ async function createClientConfig(props, minify = true) {
38
37
  // When building, include the plugin to force terminate building if errors
39
38
  // happened in the client bundle.
40
39
  if (isBuilding) {
41
- (_a = clientConfig.plugins) === null || _a === void 0 ? void 0 : _a.push({
40
+ clientConfig.plugins?.push({
42
41
  apply: (compiler) => {
43
42
  compiler.hooks.done.tap('client:done', (stats) => {
44
43
  if (stats.hasErrors()) {
@@ -6,7 +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
- const webpack_1 = require("webpack");
9
+ const tslib_1 = require("tslib");
10
+ const webpack_1 = tslib_1.__importDefault(require("webpack"));
10
11
  const pluginName = 'chunk-asset-plugin';
11
12
  /**
12
13
  * We modify webpack runtime to add an extra function called
@@ -24,11 +25,10 @@ class ChunkAssetPlugin {
24
25
  compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
25
26
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
26
27
  const chunkIdToName = chunk.getChunkMaps(false).name;
27
- const chunkNameToId = Object.create(null);
28
- Object.keys(chunkIdToName).forEach((chunkId) => {
29
- const chunkName = chunkIdToName[chunkId];
30
- chunkNameToId[chunkName] = chunkId;
31
- });
28
+ const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
29
+ chunkName,
30
+ chunkId,
31
+ ]));
32
32
  const buf = [source];
33
33
  buf.push('// function to get chunk asset');
34
34
  buf.push(
@@ -43,7 +43,7 @@ class ChunkAssetPlugin {
43
43
  // prefetching
44
44
  // Note: we previously used jsonpScriptSrc (Webpack 4)
45
45
  `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
46
- return webpack_1.Template.asString(buf);
46
+ return webpack_1.default.Template.asString(buf);
47
47
  });
48
48
  });
49
49
  }
@@ -24,7 +24,7 @@
24
24
  * SOFTWARE.
25
25
  */
26
26
  import type { Compiler, Stats } from 'webpack';
27
- export interface Options {
27
+ export declare type Options = {
28
28
  /**
29
29
  * Write Logs to Console
30
30
  * (Always enabled when dry is true)
@@ -53,7 +53,7 @@ export interface Options {
53
53
  * default: ['**\/*']
54
54
  */
55
55
  cleanOnceBeforeBuildPatterns?: string[];
56
- }
56
+ };
57
57
  export default class CleanWebpackPlugin {
58
58
  private readonly verbose;
59
59
  private readonly cleanStaleWebpackAssets;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
10
+ const path_1 = tslib_1.__importDefault(require("path"));
11
11
  const del_1 = require("del");
12
12
  class CleanWebpackPlugin {
13
13
  constructor(options = {}) {
@@ -86,7 +86,7 @@ class CleanWebpackPlugin {
86
86
  const statsAssets = stats.toJson({
87
87
  all: false,
88
88
  assets: true,
89
- }).assets || [];
89
+ }).assets ?? [];
90
90
  const assets = statsAssets.map((asset) => asset.name);
91
91
  /**
92
92
  * Get all files that were in the previous build but not the current
@@ -7,8 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const webpackbar_1 = (0, tslib_1.__importDefault)(require("webpackbar"));
11
- const formatWebpackMessages_1 = (0, tslib_1.__importDefault)(require("react-dev-utils/formatWebpackMessages"));
10
+ const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
11
+ const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
12
12
  function showError(arr) {
13
13
  console.log(`\n\n${arr.join('\n')}`);
14
14
  }
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Compiler } from 'webpack';
8
- interface WaitPluginOptions {
8
+ declare type WaitPluginOptions = {
9
9
  filepath: string;
10
- }
10
+ };
11
11
  export default class WaitPlugin {
12
12
  filepath: string;
13
13
  constructor(options: WaitPluginOptions);