@docusaurus/core 2.0.0-beta.15 → 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 (131) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/{docusaurus.js → docusaurus.mjs} +62 -40
  3. package/lib/babel/preset.d.ts +1 -2
  4. package/lib/babel/preset.js +5 -4
  5. package/lib/choosePort.js +22 -30
  6. package/lib/client/App.d.ts +1 -2
  7. package/lib/client/App.js +13 -8
  8. package/lib/client/LinksCollector.js +1 -1
  9. package/lib/client/PendingNavigation.d.ts +4 -4
  10. package/lib/client/PendingNavigation.js +4 -6
  11. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
  12. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  13. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  14. package/lib/client/client-lifecycles-dispatcher.js +5 -7
  15. package/lib/client/clientEntry.js +11 -5
  16. package/lib/client/docusaurus.js +6 -4
  17. package/lib/client/exports/BrowserOnly.d.ts +1 -2
  18. package/lib/client/exports/BrowserOnly.js +2 -3
  19. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  20. package/lib/client/exports/ComponentCreator.js +7 -6
  21. package/lib/client/exports/ErrorBoundary.d.ts +2 -2
  22. package/lib/client/exports/ErrorBoundary.js +1 -2
  23. package/lib/client/exports/Head.d.ts +2 -3
  24. package/lib/client/exports/Head.js +3 -4
  25. package/lib/client/exports/Interpolate.js +9 -12
  26. package/lib/client/exports/Link.d.ts +11 -5
  27. package/lib/client/exports/Link.js +13 -7
  28. package/lib/client/exports/Translate.js +2 -1
  29. package/lib/client/exports/browserContext.js +3 -2
  30. package/lib/client/exports/docusaurusContext.js +1 -1
  31. package/lib/client/exports/isInternalUrl.js +1 -1
  32. package/lib/client/exports/renderRoutes.d.ts +1 -2
  33. package/lib/client/exports/renderRoutes.js +1 -2
  34. package/lib/client/exports/router.d.ts +1 -1
  35. package/lib/client/exports/router.js +1 -1
  36. package/lib/client/exports/useDocusaurusContext.d.ts +1 -2
  37. package/lib/client/exports/useDocusaurusContext.js +1 -2
  38. package/lib/client/flat.d.ts +1 -2
  39. package/lib/client/flat.js +1 -2
  40. package/lib/client/normalizeLocation.d.ts +2 -3
  41. package/lib/client/normalizeLocation.js +1 -2
  42. package/lib/client/prefetch.d.ts +1 -2
  43. package/lib/client/prefetch.js +1 -2
  44. package/lib/client/preload.d.ts +2 -1
  45. package/lib/client/preload.js +2 -1
  46. package/lib/client/serverEntry.js +23 -19
  47. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  48. package/lib/client/theme-fallback/Error/index.js +21 -29
  49. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  50. package/lib/client/theme-fallback/Layout/index.js +10 -19
  51. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  52. package/lib/client/theme-fallback/Loading/index.js +46 -114
  53. package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
  54. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  55. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  56. package/lib/client/theme-fallback/Root/index.js +2 -5
  57. package/lib/commands/build.js +33 -34
  58. package/lib/commands/clear.js +23 -11
  59. package/lib/commands/deploy.js +12 -11
  60. package/lib/commands/external.d.ts +2 -2
  61. package/lib/commands/external.js +1 -1
  62. package/lib/commands/serve.js +3 -2
  63. package/lib/commands/start.js +4 -4
  64. package/lib/commands/swizzle/actions.d.ts +23 -0
  65. package/lib/commands/swizzle/actions.js +102 -0
  66. package/lib/commands/swizzle/common.d.ts +33 -0
  67. package/lib/commands/swizzle/common.js +57 -0
  68. package/lib/commands/swizzle/components.d.ts +29 -0
  69. package/lib/commands/swizzle/components.js +165 -0
  70. package/lib/commands/swizzle/config.d.ts +10 -0
  71. package/lib/commands/swizzle/config.js +77 -0
  72. package/lib/commands/swizzle/context.d.ts +8 -0
  73. package/lib/commands/swizzle/context.js +30 -0
  74. package/lib/commands/swizzle/index.d.ts +8 -0
  75. package/lib/commands/swizzle/index.js +115 -0
  76. package/lib/commands/swizzle/prompts.d.ts +12 -0
  77. package/lib/commands/swizzle/prompts.js +110 -0
  78. package/lib/commands/swizzle/tables.d.ts +9 -0
  79. package/lib/commands/swizzle/tables.js +116 -0
  80. package/lib/commands/swizzle/themes.d.ts +20 -0
  81. package/lib/commands/swizzle/themes.js +105 -0
  82. package/lib/commands/writeHeadingIds.d.ts +1 -1
  83. package/lib/commands/writeHeadingIds.js +13 -14
  84. package/lib/commands/writeTranslations.js +10 -7
  85. package/lib/index.d.ts +10 -9
  86. package/lib/index.js +20 -19
  87. package/lib/server/brokenLinks.js +30 -20
  88. package/lib/server/config.js +1 -1
  89. package/lib/server/configValidation.d.ts +1 -1
  90. package/lib/server/configValidation.js +32 -23
  91. package/lib/server/duplicateRoutes.js +2 -4
  92. package/lib/server/html-tags/htmlTags.js +1 -2
  93. package/lib/server/i18n.d.ts +0 -1
  94. package/lib/server/i18n.js +16 -26
  95. package/lib/server/index.d.ts +1 -1
  96. package/lib/server/index.js +17 -15
  97. package/lib/server/loadSetup.d.ts +1 -2
  98. package/lib/server/loadSetup.js +2 -2
  99. package/lib/server/moduleShorthand.js +1 -1
  100. package/lib/server/plugins/index.js +9 -9
  101. package/lib/server/plugins/init.d.ts +11 -1
  102. package/lib/server/plugins/init.js +23 -28
  103. package/lib/server/plugins/pluginIds.js +4 -3
  104. package/lib/server/presets/index.d.ts +2 -2
  105. package/lib/server/presets/index.js +3 -3
  106. package/lib/server/routes.js +13 -7
  107. package/lib/server/themes/alias.d.ts +1 -1
  108. package/lib/server/themes/alias.js +5 -6
  109. package/lib/server/themes/index.d.ts +2 -2
  110. package/lib/server/themes/index.js +10 -9
  111. package/lib/server/translations/translations.js +10 -11
  112. package/lib/server/translations/translationsExtractor.js +20 -19
  113. package/lib/server/versions/index.d.ts +2 -3
  114. package/lib/server/versions/index.js +22 -21
  115. package/lib/webpack/base.d.ts +2 -2
  116. package/lib/webpack/base.js +30 -22
  117. package/lib/webpack/client.d.ts +1 -1
  118. package/lib/webpack/client.js +7 -4
  119. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
  120. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  121. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
  122. package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
  123. package/lib/webpack/server.d.ts +1 -1
  124. package/lib/webpack/server.js +6 -5
  125. package/lib/webpack/utils.d.ts +3 -3
  126. package/lib/webpack/utils.js +17 -37
  127. package/package.json +56 -56
  128. package/bin/beforeCli.js +0 -124
  129. package/lib/commands/swizzle.d.ts +0 -9
  130. package/lib/commands/swizzle.js +0 -236
  131. package/lib/server/versions/__tests/index.test.js +0 -26
@@ -6,6 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.normalizePluginConfigs = void 0;
9
10
  const tslib_1 = require("tslib");
10
11
  const module_1 = require("module");
11
12
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
@@ -13,7 +14,7 @@ const utils_1 = require("@docusaurus/utils");
13
14
  const versions_1 = require("../versions");
14
15
  const pluginIds_1 = require("./pluginIds");
15
16
  const utils_validation_1 = require("@docusaurus/utils-validation");
16
- function normalizePluginConfig(pluginConfig, pluginRequire) {
17
+ async function normalizePluginConfig(pluginConfig, pluginRequire) {
17
18
  var _a, _b, _c, _d;
18
19
  // plugins: ['./plugin']
19
20
  if (typeof pluginConfig === 'string') {
@@ -65,15 +66,17 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
65
66
  }
66
67
  throw new Error(`Unexpected: can't load plugin for following plugin config.\n${JSON.stringify(pluginConfig)}`);
67
68
  }
69
+ async function normalizePluginConfigs(pluginConfigs, pluginRequire) {
70
+ return Promise.all(pluginConfigs.map((pluginConfig) => normalizePluginConfig(pluginConfig, pluginRequire)));
71
+ }
72
+ exports.normalizePluginConfigs = normalizePluginConfigs;
68
73
  function getOptionValidationFunction(normalizedPluginConfig) {
69
74
  var _a, _b, _c, _d;
70
75
  if (normalizedPluginConfig.pluginModule) {
71
76
  // support both commonjs and ES modules
72
77
  return ((_c = (_b = (_a = normalizedPluginConfig.pluginModule.module) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.validateOptions) !== null && _c !== void 0 ? _c : (_d = normalizedPluginConfig.pluginModule.module) === null || _d === void 0 ? void 0 : _d.validateOptions);
73
78
  }
74
- else {
75
- return normalizedPluginConfig.plugin.validateOptions;
76
- }
79
+ return normalizedPluginConfig.plugin.validateOptions;
77
80
  }
78
81
  function getThemeValidationFunction(normalizedPluginConfig) {
79
82
  var _a, _b;
@@ -81,24 +84,21 @@ function getThemeValidationFunction(normalizedPluginConfig) {
81
84
  // support both commonjs and ES modules
82
85
  return ((_b = (_a = normalizedPluginConfig.pluginModule.module.default) === null || _a === void 0 ? void 0 : _a.validateThemeConfig) !== null && _b !== void 0 ? _b : normalizedPluginConfig.pluginModule.module.validateThemeConfig);
83
86
  }
84
- else {
85
- return normalizedPluginConfig.plugin.validateThemeConfig;
86
- }
87
+ return normalizedPluginConfig.plugin.validateThemeConfig;
87
88
  }
88
89
  async function initPlugins({ pluginConfigs, context, }) {
89
- // We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json
90
- // declares the dependency on these plugins.
90
+ // We need to resolve plugins from the perspective of the siteDir, since the
91
+ // siteDir's package.json declares the dependency on these plugins.
91
92
  const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
92
- function doGetPluginVersion(normalizedPluginConfig) {
93
+ const pluginConfigsNormalized = await normalizePluginConfigs(pluginConfigs, pluginRequire);
94
+ async function doGetPluginVersion(normalizedPluginConfig) {
93
95
  var _a, _b;
94
96
  // get plugin version
95
97
  if ((_a = normalizedPluginConfig.pluginModule) === null || _a === void 0 ? void 0 : _a.path) {
96
98
  const pluginPath = pluginRequire.resolve((_b = normalizedPluginConfig.pluginModule) === null || _b === void 0 ? void 0 : _b.path);
97
99
  return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
98
100
  }
99
- else {
100
- return { type: 'local' };
101
- }
101
+ return { type: 'local' };
102
102
  }
103
103
  function doValidateThemeConfig(normalizedPluginConfig) {
104
104
  const validateThemeConfig = getThemeValidationFunction(normalizedPluginConfig);
@@ -108,9 +108,7 @@ async function initPlugins({ pluginConfigs, context, }) {
108
108
  themeConfig: context.siteConfig.themeConfig,
109
109
  });
110
110
  }
111
- else {
112
- return context.siteConfig.themeConfig;
113
- }
111
+ return context.siteConfig.themeConfig;
114
112
  }
115
113
  function doValidatePluginOptions(normalizedPluginConfig) {
116
114
  var _a;
@@ -121,18 +119,15 @@ async function initPlugins({ pluginConfigs, context, }) {
121
119
  options: normalizedPluginConfig.options,
122
120
  });
123
121
  }
124
- else {
125
- // Important to ensure all plugins have an id
126
- // as we don't go through the Joi schema that adds it
127
- return {
128
- ...normalizedPluginConfig.options,
129
- id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID,
130
- };
131
- }
122
+ // Important to ensure all plugins have an id
123
+ // as we don't go through the Joi schema that adds it
124
+ return {
125
+ ...normalizedPluginConfig.options,
126
+ id: (_a = normalizedPluginConfig.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID,
127
+ };
132
128
  }
133
- async function initializePlugin(pluginConfig) {
134
- const normalizedPluginConfig = normalizePluginConfig(pluginConfig, pluginRequire);
135
- const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
129
+ async function initializePlugin(normalizedPluginConfig) {
130
+ const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
136
131
  const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
137
132
  // Side-effect: merge the normalized theme config in the original one
138
133
  context.siteConfig.themeConfig = {
@@ -146,7 +141,7 @@ async function initPlugins({ pluginConfigs, context, }) {
146
141
  version: pluginVersion,
147
142
  };
148
143
  }
149
- const plugins = (await Promise.all(pluginConfigs.map((pluginConfig) => {
144
+ const plugins = (await Promise.all(pluginConfigsNormalized.map((pluginConfig) => {
150
145
  if (!pluginConfig) {
151
146
  return null;
152
147
  }
@@ -7,14 +7,15 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ensureUniquePluginInstanceIds = void 0;
10
- const lodash_1 = require("lodash");
10
+ const tslib_1 = require("tslib");
11
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
11
12
  const utils_1 = require("@docusaurus/utils");
12
13
  // It is forbidden to have 2 plugins of the same name sharing the same id
13
14
  // this is required to support multi-instance plugins without conflict
14
15
  function ensureUniquePluginInstanceIds(plugins) {
15
- const pluginsByName = (0, lodash_1.groupBy)(plugins, (p) => p.name);
16
+ const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
16
17
  Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
17
- const pluginInstancesById = (0, lodash_1.groupBy)(pluginInstances, (p) => { var _a; return (_a = p.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; });
18
+ const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => { var _a; return (_a = p.options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID; });
18
19
  Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
19
20
  if (pluginInstancesWithId.length !== 1) {
20
21
  throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { LoadContext, PluginConfig } from '@docusaurus/types';
8
- export default function loadPresets(context: LoadContext): {
8
+ export default function loadPresets(context: LoadContext): Promise<{
9
9
  plugins: PluginConfig[];
10
10
  themes: PluginConfig[];
11
- };
11
+ }>;
@@ -10,9 +10,9 @@ const tslib_1 = require("tslib");
10
10
  const module_1 = require("module");
11
11
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const moduleShorthand_1 = require("../moduleShorthand");
13
- function loadPresets(context) {
14
- // We need to resolve presets from the perspective of the siteDir, since the siteDir's package.json
15
- // declares the dependency on these presets.
13
+ async function loadPresets(context) {
14
+ // We need to resolve presets from the perspective of the siteDir, since the
15
+ // siteDir's package.json declares the dependency on these presets.
16
16
  const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
17
17
  const presets = context.siteConfig.presets || [];
18
18
  const unflatPlugins = [];
@@ -7,11 +7,10 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const utils_1 = require("@docusaurus/utils");
10
- const lodash_1 = require("lodash");
11
10
  const querystring_1 = require("querystring");
12
11
  function indent(str) {
13
12
  const spaces = ' ';
14
- return `${spaces}${str.replace(/(\n)/g, `\n${spaces}`)}`;
13
+ return `${spaces}${str.replace(/\n/g, `\n${spaces}`)}`;
15
14
  }
16
15
  const createRouteCodeString = ({ routePath, routeHash, exact, subroutesCodeStrings, props, }) => {
17
16
  const parts = [
@@ -46,10 +45,15 @@ const RoutesImportsCode = [
46
45
  `import ComponentCreator from '@docusaurus/ComponentCreator';`,
47
46
  ].join('\n');
48
47
  function isModule(value) {
49
- if ((0, lodash_1.isString)(value)) {
48
+ var _a, _b;
49
+ if (typeof value === 'string') {
50
50
  return true;
51
51
  }
52
- if ((0, lodash_1.isPlainObject)(value) && (0, lodash_1.has)(value, '__import') && (0, lodash_1.has)(value, 'path')) {
52
+ if (typeof value === 'object' &&
53
+ (
54
+ // eslint-disable-next-line no-underscore-dangle
55
+ (_a = value) === null || _a === void 0 ? void 0 : _a.__import) &&
56
+ ((_b = value) === null || _b === void 0 ? void 0 : _b.path)) {
53
57
  return true;
54
58
  }
55
59
  return false;
@@ -68,12 +72,14 @@ async function loadRoutes(pluginsRouteConfigs, baseUrl) {
68
72
  // This is the higher level overview of route code generation.
69
73
  function generateRouteCode(routeConfig) {
70
74
  const { path: routePath, component, modules = {}, routes: subroutes, exact, priority, ...props } = routeConfig;
71
- if (!(0, lodash_1.isString)(routePath) || !component) {
72
- throw new Error(`Invalid route config: path must be a string and component is required.\n${JSON.stringify(routeConfig)}`);
75
+ if (typeof routePath !== 'string' || !component) {
76
+ throw new Error(`Invalid route config: path must be a string and component is required.
77
+ ${JSON.stringify(routeConfig)}`);
73
78
  }
74
79
  // Collect all page paths for injecting it later in the plugin lifecycle
75
80
  // This is useful for plugins like sitemaps, redirects etc...
76
- // If a route has subroutes, it is not necessarily a valid page path (more likely to be a wrapper)
81
+ // If a route has subroutes, it is not necessarily a valid page path (more
82
+ // likely to be a wrapper)
77
83
  if (!subroutes) {
78
84
  routesPaths.push(routePath);
79
85
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import type { ThemeAliases } from '@docusaurus/types';
8
8
  export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
9
- export default function themeAlias(themePath: string, addOriginalAlias: boolean): ThemeAliases;
9
+ export default function themeAlias(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
@@ -11,25 +11,24 @@ const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
12
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const lodash_1 = require("lodash");
14
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
15
15
  // Order of Webpack aliases is important because one alias can shadow another
16
16
  // This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
17
17
  // See https://github.com/facebook/docusaurus/pull/3922
18
18
  // See https://github.com/facebook/docusaurus/issues/5382
19
19
  function sortAliases(aliases) {
20
20
  // Alphabetical order by default
21
- const entries = (0, lodash_1.sortBy)(Object.entries(aliases), ([alias]) => alias);
21
+ const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
22
22
  // @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
23
23
  entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
24
24
  return Object.fromEntries(entries);
25
25
  }
26
26
  exports.sortAliases = sortAliases;
27
- // TODO make async
28
- function themeAlias(themePath, addOriginalAlias) {
29
- if (!fs_extra_1.default.pathExistsSync(themePath)) {
27
+ async function themeAlias(themePath, addOriginalAlias) {
28
+ if (!(await fs_extra_1.default.pathExists(themePath))) {
30
29
  return {};
31
30
  }
32
- const themeComponentFiles = utils_1.Globby.sync(['**/*.{js,jsx,ts,tsx}'], {
31
+ const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
33
32
  cwd: themePath,
34
33
  });
35
34
  const aliases = {};
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
8
- export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): ThemeAliases;
8
+ export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
9
9
  export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
10
10
  siteDir: string;
11
11
  plugins: LoadedPlugin[];
12
- }): ThemeAliases;
12
+ }): Promise<ThemeAliases>;
@@ -12,13 +12,14 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const alias_1 = (0, tslib_1.__importStar)(require("./alias"));
14
14
  const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
15
- function loadThemeAliases(themePaths, userThemePaths) {
15
+ async function loadThemeAliases(themePaths, userThemePaths) {
16
16
  const aliases = {};
17
- themePaths.forEach((themePath) => {
18
- const themeAliases = (0, alias_1.default)(themePath, true);
17
+ for (const themePath of themePaths) {
18
+ const themeAliases = await (0, alias_1.default)(themePath, true);
19
19
  Object.keys(themeAliases).forEach((aliasKey) => {
20
- // If this alias shadows a previous one, use @theme-init to preserve the initial one.
21
- // @theme-init is only applied once: to the initial theme that provided this component
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
22
23
  if (aliasKey in aliases) {
23
24
  const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
24
25
  const initAlias = `@theme-init/${componentName}`;
@@ -28,11 +29,11 @@ function loadThemeAliases(themePaths, userThemePaths) {
28
29
  }
29
30
  aliases[aliasKey] = themeAliases[aliasKey];
30
31
  });
31
- });
32
- userThemePaths.forEach((themePath) => {
33
- const userThemeAliases = (0, alias_1.default)(themePath, false);
32
+ }
33
+ for (const themePath of userThemePaths) {
34
+ const userThemeAliases = await (0, alias_1.default)(themePath, false);
34
35
  Object.assign(aliases, userThemeAliases);
35
- });
36
+ }
36
37
  return (0, alias_1.sortAliases)(aliases);
37
38
  }
38
39
  exports.loadThemeAliases = loadThemeAliases;
@@ -10,7 +10,7 @@ exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationM
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
- const lodash_1 = require("lodash");
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
16
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
@@ -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 ${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 = (0, 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,7 +69,7 @@ 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 = (0, 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
74
  logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
74
75
  Maybe you should remove them? ${unknownKeys}`;
@@ -162,9 +163,7 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
162
163
  },
163
164
  };
164
165
  }
165
- else {
166
- return translationFile;
167
- }
166
+ return translationFile;
168
167
  }
169
168
  exports.localizePluginTranslationFile = localizePluginTranslationFile;
170
169
  async function getPluginsDefaultCodeTranslationMessages(plugins) {
@@ -173,12 +172,12 @@ async function getPluginsDefaultCodeTranslationMessages(plugins) {
173
172
  }
174
173
  exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
175
174
  function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
176
- const unusedDefaultCodeMessages = (0, lodash_1.difference)(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
175
+ const unusedDefaultCodeMessages = lodash_1.default.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
177
176
  if (unusedDefaultCodeMessages.length > 0) {
178
177
  logger_1.default.warn `Unused default message codes found.
179
178
  Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
180
179
  }
181
- return (0, lodash_1.mapValues)(extractedCodeTranslations, (messageTranslation, messageId) => {
180
+ return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
182
181
  var _a;
183
182
  return ({
184
183
  ...messageTranslation,
@@ -36,8 +36,9 @@ function getSiteSourceCodeFilePaths(siteDir) {
36
36
  function getPluginSourceCodeFilePaths(plugin) {
37
37
  var _a, _b, _c;
38
38
  // The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
39
- // We can use this method as well to know which folders we should try to extract translations from
40
- // Hacky/implicit, but do we want to introduce a new lifecycle method just for that???
39
+ // We can use this method as well to know which folders we should try to
40
+ // extract translations from. Hacky/implicit, but do we want to introduce a
41
+ // new lifecycle method just for that???
41
42
  const codePaths = (_b = (_a = plugin.getPathsToWatch) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : [];
42
43
  // We also include theme code
43
44
  const themePath = (_c = plugin.getThemePath) === null || _c === void 0 ? void 0 : _c.call(plugin);
@@ -54,14 +55,16 @@ exports.globSourceCodeFilePaths = globSourceCodeFilePaths;
54
55
  async function getSourceCodeFilePaths(siteDir, plugins) {
55
56
  const sitePaths = getSiteSourceCodeFilePaths(siteDir);
56
57
  // The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
57
- // We can use this method as well to know which folders we should try to extract translations from
58
- // Hacky/implicit, but do we want to introduce a new lifecycle method for that???
58
+ // We can use this method as well to know which folders we should try to
59
+ // extract translations from. Hacky/implicit, but do we want to introduce a
60
+ // new lifecycle method for that???
59
61
  const pluginsPaths = plugins.flatMap(getPluginSourceCodeFilePaths);
60
62
  const allPaths = [...sitePaths, ...pluginsPaths];
61
63
  return globSourceCodeFilePaths(allPaths);
62
64
  }
63
65
  async function extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions, extraSourceCodeFilePaths = []) {
64
- // Should we warn here if the same translation "key" is found in multiple source code files?
66
+ // Should we warn here if the same translation "key" is found in multiple
67
+ // source code files?
65
68
  function toTranslationFileContent(sourceCodeFileTranslations) {
66
69
  return sourceCodeFileTranslations.reduce((acc, item) => ({ ...acc, ...item.translations }), {});
67
70
  }
@@ -92,18 +95,17 @@ async function extractSourceCodeFileTranslations(sourceCodeFilePath, babelOption
92
95
  const ast = (0, core_1.parse)(code, {
93
96
  ...babelOptions,
94
97
  ast: true,
95
- // filename is important, because babel does not process the same files according to their js/ts extensions
96
- // see see https://twitter.com/NicoloRibaudo/status/1321130735605002243
98
+ // filename is important, because babel does not process the same files
99
+ // according to their js/ts extensions.
100
+ // See https://twitter.com/NicoloRibaudo/status/1321130735605002243
97
101
  filename: sourceCodeFilePath,
98
102
  });
99
103
  const translations = await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
100
104
  return translations;
101
105
  }
102
- catch (e) {
103
- if (e instanceof Error) {
104
- e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`;
105
- }
106
- throw e;
106
+ catch (err) {
107
+ logger_1.default.error `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}.`;
108
+ throw err;
107
109
  }
108
110
  }
109
111
  exports.extractSourceCodeFileTranslations = extractSourceCodeFileTranslations;
@@ -169,12 +171,10 @@ Full code: ${(0, generator_1.default)(node).code}`;
169
171
  typeof attributeValueEvaluated.value === 'string') {
170
172
  return attributeValueEvaluated.value;
171
173
  }
172
- else {
173
- warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
174
+ warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
174
175
  Example: <Translate id="optional id" description="optional description">Message</Translate>
175
176
  Dynamically constructed values are not allowed, because they prevent translations to be extracted.
176
177
  ${sourceWarningPart(path.node)}`);
177
- }
178
178
  }
179
179
  return undefined;
180
180
  }
@@ -191,7 +191,7 @@ ${sourceWarningPart(path.node)}`);
191
191
  }
192
192
  else {
193
193
  translations[id] = {
194
- message: message !== null && message !== void 0 ? message : id,
194
+ message: id,
195
195
  ...(description && { description }),
196
196
  };
197
197
  }
@@ -199,8 +199,9 @@ ${sourceWarningPart(path.node)}`);
199
199
  }
200
200
  // Handle single non-empty content
201
201
  const singleChildren = childrenPath
202
- // Remove empty/useless text nodes that might be around our translation!
203
- // Makes the translation system more reliable to JSX formatting issues
202
+ // Remove empty/useless text nodes that might be around our
203
+ // translation! Makes the translation system more reliable to JSX
204
+ // formatting issues
204
205
  .filter((children) => !(children.isJSXText() &&
205
206
  children.node.value.replace('\n', '').trim() === ''))
206
207
  .pop();
@@ -231,7 +232,7 @@ ${sourceWarningPart(path.node)}`);
231
232
  const args = path.get('arguments');
232
233
  if (args.length === 1 || args.length === 2) {
233
234
  const firstArgPath = args[0];
234
- // evaluation allows translate("x" + "y"); to be considered as translate("xy");
235
+ // translate("x" + "y"); => translate("xy");
235
236
  const firstArgEvaluated = firstArgPath.evaluate();
236
237
  if (firstArgEvaluated.confident &&
237
238
  typeof firstArgEvaluated.value === 'object') {
@@ -5,6 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
8
- export declare function getPackageJsonVersion(packageJsonPath: string): string | undefined;
9
- export declare function getPackageJsonName(packageJsonPath: string): string | undefined;
10
- export declare function getPluginVersion(pluginPath: string, siteDir: string): DocusaurusPluginVersionInformation;
8
+ export declare function getPackageJsonVersion(packageJsonPath: string): Promise<string | undefined>;
9
+ export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<DocusaurusPluginVersionInformation>;
@@ -6,45 +6,46 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getPluginVersion = exports.getPackageJsonName = exports.getPackageJsonVersion = void 0;
10
- const fs_extra_1 = require("fs-extra");
11
- const path_1 = require("path");
12
- function getPackageJsonVersion(packageJsonPath) {
13
- if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
9
+ exports.getPluginVersion = exports.getPackageJsonVersion = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
+ async function getPackageJsonVersion(packageJsonPath) {
14
+ if (await fs_extra_1.default.pathExists(packageJsonPath)) {
14
15
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
15
- const { version } = require(packageJsonPath);
16
- return typeof version === 'string' ? version : undefined;
16
+ return require(packageJsonPath).version;
17
17
  }
18
18
  return undefined;
19
19
  }
20
20
  exports.getPackageJsonVersion = getPackageJsonVersion;
21
- function getPackageJsonName(packageJsonPath) {
22
- if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
21
+ async function getPackageJsonName(packageJsonPath) {
22
+ if (await fs_extra_1.default.pathExists(packageJsonPath)) {
23
23
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
24
- const { name } = require(packageJsonPath);
25
- return typeof name === 'string' ? name : undefined;
24
+ return require(packageJsonPath).name;
26
25
  }
27
26
  return undefined;
28
27
  }
29
- exports.getPackageJsonName = getPackageJsonName;
30
- function getPluginVersion(pluginPath, siteDir) {
31
- let potentialPluginPackageJsonDirectory = (0, path_1.dirname)(pluginPath);
28
+ async function getPluginVersion(pluginPath, siteDir) {
29
+ let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
32
30
  while (potentialPluginPackageJsonDirectory !== '/') {
33
- const packageJsonPath = (0, path_1.join)(potentialPluginPackageJsonDirectory, 'package.json');
34
- if ((0, fs_extra_1.existsSync)(packageJsonPath) && (0, fs_extra_1.lstatSync)(packageJsonPath).isFile()) {
31
+ const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
32
+ if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
33
+ (await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
35
34
  if (potentialPluginPackageJsonDirectory === siteDir) {
36
- // If the plugin belongs to the same docusaurus project, we classify it as local plugin.
35
+ // If the plugin belongs to the same docusaurus project, we classify it
36
+ // as local plugin.
37
37
  return { type: 'project' };
38
38
  }
39
39
  return {
40
40
  type: 'package',
41
- name: getPackageJsonName(packageJsonPath),
42
- version: getPackageJsonVersion(packageJsonPath),
41
+ name: await getPackageJsonName(packageJsonPath),
42
+ version: await getPackageJsonVersion(packageJsonPath),
43
43
  };
44
44
  }
45
- potentialPluginPackageJsonDirectory = (0, path_1.dirname)(potentialPluginPackageJsonDirectory);
45
+ potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
46
46
  }
47
- // In rare cases where a plugin is a path where no parent directory contains package.json, we can only classify it as local.
47
+ // In the case where a plugin is a path where no parent directory contains
48
+ // package.json (e.g. inline plugin), we can only classify it as local.
48
49
  return { type: 'local' };
49
50
  }
50
51
  exports.getPluginVersion = getPluginVersion;
@@ -8,5 +8,5 @@ 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(): Record<string, string>;
12
- export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Configuration;
11
+ export declare function getDocusaurusAliases(): Promise<Record<string, string>>;
12
+ export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;