@docusaurus/core 2.0.0-beta.fc64c12e4 → 2.0.0

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 (224) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/{docusaurus.js → docusaurus.mjs} +81 -118
  4. package/lib/babel/preset.d.ts +8 -3
  5. package/lib/babel/preset.js +10 -8
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +47 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -8
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +37 -0
  32. package/lib/client/exports/ExecutionEnvironment.js +7 -8
  33. package/lib/client/exports/Head.d.ts +2 -3
  34. package/lib/client/exports/Head.js +3 -4
  35. package/lib/client/exports/Interpolate.d.ts +2 -2
  36. package/lib/client/exports/Interpolate.js +18 -51
  37. package/lib/client/exports/Link.d.ts +4 -10
  38. package/lib/client/exports/Link.js +38 -38
  39. package/lib/client/exports/Translate.d.ts +1 -1
  40. package/lib/client/exports/Translate.js +11 -10
  41. package/lib/client/exports/constants.js +1 -11
  42. package/lib/client/exports/isInternalUrl.js +1 -1
  43. package/lib/client/exports/renderRoutes.d.ts +1 -2
  44. package/lib/client/exports/renderRoutes.js +1 -2
  45. package/lib/client/exports/router.d.ts +1 -1
  46. package/lib/client/exports/router.js +1 -1
  47. package/lib/client/exports/useBaseUrl.js +11 -14
  48. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  49. package/lib/client/exports/useDocusaurusContext.js +3 -9
  50. package/lib/client/exports/useGlobalData.d.ts +4 -3
  51. package/lib/client/exports/useGlobalData.js +6 -13
  52. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  53. package/lib/client/exports/useIsBrowser.js +11 -0
  54. package/lib/client/exports/useRouteContext.d.ts +8 -0
  55. package/lib/client/exports/useRouteContext.js +15 -0
  56. package/lib/client/flat.d.ts +12 -2
  57. package/lib/client/flat.js +19 -15
  58. package/lib/client/normalizeLocation.d.ts +2 -5
  59. package/lib/client/normalizeLocation.js +14 -10
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +12 -32
  62. package/lib/client/preload.d.ts +3 -4
  63. package/lib/client/preload.js +5 -12
  64. package/lib/client/routeContext.d.ts +13 -0
  65. package/lib/client/routeContext.js +31 -0
  66. package/lib/client/serverEntry.d.ts +10 -0
  67. package/lib/client/serverEntry.js +108 -146
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +45 -0
  70. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  71. package/lib/client/theme-fallback/Layout/index.js +2 -26
  72. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  73. package/lib/client/theme-fallback/Loading/index.js +50 -116
  74. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
  75. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  76. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  77. package/lib/client/theme-fallback/Root/index.js +2 -6
  78. package/lib/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +6 -2
  81. package/lib/commands/build.js +81 -64
  82. package/lib/commands/clear.d.ts +7 -1
  83. package/lib/commands/clear.js +34 -21
  84. package/lib/commands/deploy.d.ts +5 -2
  85. package/lib/commands/deploy.js +94 -81
  86. package/lib/commands/external.d.ts +2 -2
  87. package/lib/commands/external.js +9 -11
  88. package/lib/commands/serve.d.ts +8 -2
  89. package/lib/commands/serve.js +29 -28
  90. package/lib/commands/start.d.ts +9 -2
  91. package/lib/commands/start.js +107 -102
  92. package/lib/commands/swizzle/actions.d.ts +23 -0
  93. package/lib/commands/swizzle/actions.js +106 -0
  94. package/lib/commands/swizzle/common.d.ts +33 -0
  95. package/lib/commands/swizzle/common.js +56 -0
  96. package/lib/commands/swizzle/components.d.ts +29 -0
  97. package/lib/commands/swizzle/components.js +200 -0
  98. package/lib/commands/swizzle/config.d.ts +10 -0
  99. package/lib/commands/swizzle/config.js +84 -0
  100. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  101. package/lib/commands/swizzle/context.js +24 -0
  102. package/lib/commands/swizzle/index.d.ts +8 -0
  103. package/lib/commands/swizzle/index.js +119 -0
  104. package/lib/commands/swizzle/prompts.d.ts +12 -0
  105. package/lib/commands/swizzle/prompts.js +110 -0
  106. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  107. package/lib/commands/swizzle/tables.js +113 -0
  108. package/lib/commands/swizzle/themes.d.ts +20 -0
  109. package/lib/commands/swizzle/themes.js +106 -0
  110. package/lib/commands/writeHeadingIds.d.ts +2 -6
  111. package/lib/commands/writeHeadingIds.js +22 -81
  112. package/lib/commands/writeTranslations.d.ts +4 -5
  113. package/lib/commands/writeTranslations.js +46 -25
  114. package/lib/index.d.ts +9 -9
  115. package/lib/index.js +14 -14
  116. package/lib/server/brokenLinks.d.ts +4 -17
  117. package/lib/server/brokenLinks.js +67 -56
  118. package/lib/server/clientModules.d.ts +12 -0
  119. package/lib/server/clientModules.js +20 -0
  120. package/lib/server/config.d.ts +5 -2
  121. package/lib/server/config.js +29 -6
  122. package/lib/server/configValidation.d.ts +4 -4
  123. package/lib/server/configValidation.js +86 -41
  124. package/lib/server/getHostPort.d.ts +14 -0
  125. package/lib/server/getHostPort.js +79 -0
  126. package/lib/server/htmlTags.d.ts +12 -0
  127. package/lib/server/htmlTags.js +62 -0
  128. package/lib/server/i18n.d.ts +3 -13
  129. package/lib/server/i18n.js +21 -55
  130. package/lib/server/index.d.ts +28 -13
  131. package/lib/server/index.js +83 -165
  132. package/lib/server/plugins/configs.d.ts +51 -0
  133. package/lib/server/plugins/configs.js +101 -0
  134. package/lib/server/plugins/index.d.ts +9 -8
  135. package/lib/server/plugins/index.js +73 -137
  136. package/lib/server/plugins/init.d.ts +6 -5
  137. package/lib/server/plugins/init.js +44 -109
  138. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  139. package/lib/server/plugins/moduleShorthand.js +46 -0
  140. package/lib/server/plugins/pluginIds.d.ts +5 -1
  141. package/lib/server/plugins/pluginIds.js +12 -7
  142. package/lib/server/plugins/presets.d.ts +12 -0
  143. package/lib/server/plugins/presets.js +49 -0
  144. package/lib/server/plugins/routeConfig.d.ts +11 -0
  145. package/lib/server/plugins/routeConfig.js +54 -0
  146. package/lib/server/plugins/synthetic.d.ts +20 -0
  147. package/lib/server/plugins/synthetic.js +111 -0
  148. package/lib/server/routes.d.ts +39 -7
  149. package/lib/server/routes.js +166 -99
  150. package/lib/server/siteMetadata.d.ts +12 -0
  151. package/lib/server/siteMetadata.js +81 -0
  152. package/lib/server/translations/translations.d.ts +14 -19
  153. package/lib/server/translations/translations.js +40 -72
  154. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  155. package/lib/server/translations/translationsExtractor.js +158 -122
  156. package/lib/server/utils.d.ts +7 -1
  157. package/lib/server/utils.js +7 -8
  158. package/lib/webpack/aliases/index.d.ts +34 -0
  159. package/lib/webpack/aliases/index.js +106 -0
  160. package/lib/webpack/base.d.ts +3 -4
  161. package/lib/webpack/base.js +45 -57
  162. package/lib/webpack/client.d.ts +3 -3
  163. package/lib/webpack/client.js +12 -19
  164. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  165. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  166. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  167. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  168. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  169. package/lib/webpack/plugins/LogPlugin.js +4 -5
  170. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  171. package/lib/webpack/plugins/WaitPlugin.js +30 -29
  172. package/lib/webpack/server.d.ts +5 -5
  173. package/lib/webpack/server.js +21 -12
  174. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  175. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  176. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  177. package/lib/webpack/utils.d.ts +15 -31
  178. package/lib/webpack/utils.js +61 -182
  179. package/package.json +81 -77
  180. package/bin/beforeCli.js +0 -103
  181. package/lib/.tsbuildinfo +0 -1
  182. package/lib/choosePort.js +0 -105
  183. package/lib/client/.eslintrc.js +0 -29
  184. package/lib/client/.tsbuildinfo +0 -1
  185. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  186. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  187. package/lib/client/nprogress.css +0 -36
  188. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  189. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  190. package/lib/commands/commandUtils.d.ts +0 -3
  191. package/lib/commands/commandUtils.js +0 -21
  192. package/lib/commands/swizzle.d.ts +0 -9
  193. package/lib/commands/swizzle.js +0 -245
  194. package/lib/constants.d.ts +0 -18
  195. package/lib/constants.js +0 -23
  196. package/lib/server/client-modules/index.js +0 -14
  197. package/lib/server/duplicateRoutes.d.ts +0 -10
  198. package/lib/server/duplicateRoutes.js +0 -38
  199. package/lib/server/html-tags/htmlTags.js +0 -40
  200. package/lib/server/html-tags/index.d.ts +0 -9
  201. package/lib/server/html-tags/index.js +0 -43
  202. package/lib/server/loadSetup.d.ts +0 -9
  203. package/lib/server/loadSetup.js +0 -25
  204. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
  205. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  206. package/lib/server/presets/index.d.ts +0 -11
  207. package/lib/server/presets/index.js +0 -48
  208. package/lib/server/themes/alias.d.ts +0 -8
  209. package/lib/server/themes/alias.js +0 -39
  210. package/lib/server/themes/index.d.ts +0 -12
  211. package/lib/server/themes/index.js +0 -47
  212. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  213. package/lib/server/versions/__fixtures__/package.json +0 -3
  214. package/lib/server/versions/__tests/index.test.js +0 -25
  215. package/lib/server/versions/index.d.ts +0 -10
  216. package/lib/server/versions/index.js +0 -50
  217. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  218. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  219. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  220. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  221. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  222. package/lib/webpack/sharedModuleAliases.js +0 -18
  223. package/tsconfig.client.json +0 -13
  224. package/tsconfig.json +0 -13
@@ -1,37 +1,38 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Facebook, Inc. and its affiliates.
4
3
  *
5
4
  * This source code is licensed under the MIT license found in the
6
5
  * LICENSE file in the root directory of this source tree.
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const wait_on_1 = tslib_1.__importDefault(require("wait-on"));
7
+
8
+ const path = require('path');
9
+ const fs = require('fs-extra');
10
+ const {waitFile} = require('wait-file');
11
+
13
12
  class WaitPlugin {
14
- constructor(options) {
15
- this.filepath = options.filepath;
16
- }
17
- apply(compiler) {
18
- // Before finishing the compilation step
19
- compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
20
- // To prevent 'waitFile' error on waiting non-existing directory
21
- fs_extra_1.default.ensureDir(path_1.default.dirname(this.filepath), {}, () => {
22
- // Wait until file exist
23
- wait_on_1.default({
24
- resources: [this.filepath],
25
- interval: 300,
26
- })
27
- .then(() => {
28
- callback();
29
- })
30
- .catch((error) => {
31
- console.warn(`WaitPlugin error: ${error}`);
32
- });
33
- });
34
- });
35
- }
13
+ constructor(options) {
14
+ this.filepath = options.filepath;
15
+ }
16
+
17
+ apply(compiler) {
18
+ // Before finishing the compilation step
19
+ compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
20
+ // To prevent 'waitFile' error on waiting non-existing directory
21
+ fs.ensureDir(path.dirname(this.filepath), () => {
22
+ // Wait until file exist
23
+ waitFile({
24
+ resources: [this.filepath],
25
+ interval: 300,
26
+ })
27
+ .then(() => {
28
+ callback();
29
+ })
30
+ .catch((error) => {
31
+ console.warn(`WaitPlugin error: ${error}`);
32
+ });
33
+ });
34
+ });
35
+ }
36
36
  }
37
- exports.default = WaitPlugin;
37
+
38
+ module.exports = WaitPlugin;
@@ -4,9 +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 { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
9
- export default function createServerConfig({ props, onLinksCollected, }: {
7
+ import { type Locals } from '@slorber/static-site-generator-webpack-plugin';
8
+ import type { Props } from '@docusaurus/types';
9
+ import type { Configuration } from 'webpack';
10
+ export default function createServerConfig({ props, onLinksCollected, onHeadTagsCollected, }: Pick<Locals, 'onLinksCollected' | 'onHeadTagsCollected'> & {
10
11
  props: Props;
11
- onLinksCollected?: (staticPagePath: string, links: string[]) => void;
12
- }): Configuration;
12
+ }): Promise<Configuration>;
@@ -9,15 +9,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const path_1 = tslib_1.__importDefault(require("path"));
11
11
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
12
+ const utils_1 = require("@docusaurus/utils");
13
+ // Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
14
+ const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
12
15
  const base_1 = require("./base");
13
16
  const WaitPlugin_1 = tslib_1.__importDefault(require("./plugins/WaitPlugin"));
14
17
  const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
15
- const constants_1 = require("../constants");
16
- // Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
17
- const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
18
- function createServerConfig({ props, onLinksCollected = () => { }, }) {
19
- const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
20
- const config = base_1.createBaseConfig(props, true);
18
+ const ssr_html_template_1 = tslib_1.__importDefault(require("./templates/ssr.html.template"));
19
+ async function createServerConfig({ props, onLinksCollected, onHeadTagsCollected, }) {
20
+ const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, siteConfig: { noIndex, trailingSlash, ssrTemplate }, } = props;
21
+ const config = await (0, base_1.createBaseConfig)(props, true);
21
22
  const routesLocation = {};
22
23
  // Array of paths to be rendered. Relative to output directory
23
24
  const ssgPaths = routesPaths.map((str) => {
@@ -25,8 +26,8 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
25
26
  routesLocation[ssgPath] = str;
26
27
  return ssgPath;
27
28
  });
28
- const serverConfig = webpack_merge_1.default(config, {
29
- target: `node${constants_1.NODE_MAJOR_VERSION}.${constants_1.NODE_MINOR_VERSION}`,
29
+ const serverConfig = (0, webpack_merge_1.default)(config, {
30
+ target: `node${utils_1.NODE_MAJOR_VERSION}.${utils_1.NODE_MINOR_VERSION}`,
30
31
  entry: {
31
32
  main: path_1.default.resolve(__dirname, '../client/serverEntry.js'),
32
33
  },
@@ -52,15 +53,23 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
52
53
  preBodyTags,
53
54
  postBodyTags,
54
55
  onLinksCollected,
55
- ssrTemplate,
56
+ onHeadTagsCollected,
57
+ ssrTemplate: ssrTemplate ?? ssr_html_template_1.default,
56
58
  noIndex,
59
+ DOCUSAURUS_VERSION: utils_1.DOCUSAURUS_VERSION,
57
60
  },
58
61
  paths: ssgPaths,
59
62
  preferFoldersOutput: trailingSlash,
60
- // When using "new URL('file.js', import.meta.url)", Webpack will emit __filename, and this plugin will throw
61
- // not sure the __filename value has any importance for this plugin, just using an empty string to avoid the error
62
- // See https://github.com/facebook/docusaurus/issues/4922
63
+ // When using "new URL('file.js', import.meta.url)", Webpack will emit
64
+ // __filename, and this plugin will throw. not sure the __filename value
65
+ // has any importance for this plugin, just using an empty string to
66
+ // avoid the error. See https://github.com/facebook/docusaurus/issues/4922
63
67
  globals: { __filename: '' },
68
+ // Secret way to set SSR plugin concurrency option
69
+ // Waiting for feedback before documenting this officially?
70
+ concurrency: process.env.DOCUSAURUS_SSR_CONCURRENCY
71
+ ? parseInt(process.env.DOCUSAURUS_SSR_CONCURRENCY, 10)
72
+ : undefined,
64
73
  }),
65
74
  // Show compilation progress bar.
66
75
  new LogPlugin_1.default({
@@ -0,0 +1,8 @@
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
+ declare const _default: "\n<!DOCTYPE html>\n<html <%~ it.htmlAttributes %>>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"generator\" content=\"Docusaurus v<%= it.version %>\">\n <% if (it.noIndex) { %>\n <meta name=\"robots\" content=\"noindex, nofollow\" />\n <% } %>\n <%~ it.headTags %>\n <% it.metaAttributes.forEach((metaAttribute) => { %>\n <%~ metaAttribute %>\n <% }); %>\n <% it.stylesheets.forEach((stylesheet) => { %>\n <link rel=\"stylesheet\" href=\"<%= it.baseUrl %><%= stylesheet %>\" />\n <% }); %>\n <% it.scripts.forEach((script) => { %>\n <link rel=\"preload\" href=\"<%= it.baseUrl %><%= script %>\" as=\"script\">\n <% }); %>\n </head>\n <body <%~ it.bodyAttributes %>>\n <%~ it.preBodyTags %>\n <div id=\"__docusaurus\">\n <%~ it.appHtml %>\n </div>\n <% it.scripts.forEach((script) => { %>\n <script src=\"<%= it.baseUrl %><%= script %>\"></script>\n <% }); %>\n <%~ it.postBodyTags %>\n </body>\n</html>\n";
8
+ export default _default;
@@ -1,11 +1,12 @@
1
+ "use strict";
1
2
  /**
2
3
  * Copyright (c) Facebook, Inc. and its affiliates.
3
4
  *
4
5
  * This source code is licensed under the MIT license found in the
5
6
  * LICENSE file in the root directory of this source tree.
6
7
  */
7
-
8
- module.exports = `
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = `
9
10
  <!DOCTYPE html>
10
11
  <html <%~ it.htmlAttributes %>>
11
12
  <head>
@@ -5,13 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="node" />
8
- import { Configuration, RuleSetRule, WebpackPluginInstance } from 'webpack';
9
- import { TransformOptions } from '@babel/core';
10
- import { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
11
- export declare function getStyleLoaders(isServer: boolean, cssOptions?: {
8
+ import { type Configuration, type RuleSetRule, type WebpackPluginInstance } from 'webpack';
9
+ import type { TransformOptions } from '@babel/core';
10
+ import type { Plugin } from '@docusaurus/types';
11
+ export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
12
12
  [key: string]: unknown;
13
13
  }): RuleSetRule[];
14
- export declare function getCustomBabelConfigFilePath(siteDir: string): string | undefined;
14
+ export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
15
15
  export declare function getBabelOptions({ isServer, babelOptions, }?: {
16
16
  isServer?: boolean;
17
17
  babelOptions?: TransformOptions | string;
@@ -29,33 +29,17 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
29
29
  * @param content content loaded by the plugin
30
30
  * @returns final/ modified webpack config
31
31
  */
32
- export declare function applyConfigureWebpack(configureWebpack: ConfigureWebpackFn, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
33
- export declare function applyConfigurePostCss(configurePostCss: NonNullable<ConfigurePostCssFn>, config: Configuration): Configuration;
32
+ export declare function applyConfigureWebpack(configureWebpack: NonNullable<Plugin['configureWebpack']>, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
33
+ export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
34
+ declare global {
35
+ interface Error {
36
+ /** @see https://webpack.js.org/api/node/#error-handling */
37
+ details: unknown;
38
+ }
39
+ }
34
40
  export declare function compile(config: Configuration[]): Promise<void>;
35
- declare type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
36
- declare type FileLoaderUtils = {
37
- loaders: {
38
- file: (options: {
39
- folder: AssetFolder;
40
- }) => RuleSetRule;
41
- url: (options: {
42
- folder: AssetFolder;
43
- }) => RuleSetRule;
44
- inlineMarkdownImageFileLoader: string;
45
- inlineMarkdownLinkFileLoader: string;
46
- };
47
- rules: {
48
- images: () => RuleSetRule;
49
- fonts: () => RuleSetRule;
50
- media: () => RuleSetRule;
51
- svg: () => RuleSetRule;
52
- otherAssets: () => RuleSetRule;
53
- };
54
- };
55
- export declare function getFileLoaderUtils(): FileLoaderUtils;
56
- export declare function getHttpsConfig(): boolean | {
41
+ export declare function getHttpsConfig(): Promise<boolean | {
57
42
  cert: Buffer;
58
43
  key: Buffer;
59
- };
44
+ }>;
60
45
  export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
61
- export {};
@@ -6,21 +6,25 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getMinimizer = exports.getHttpsConfig = exports.getFileLoaderUtils = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
9
+ exports.getMinimizer = exports.getHttpsConfig = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
10
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 crypto_1 = tslib_1.__importDefault(require("crypto"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const utils_1 = require("@docusaurus/utils");
11
16
  const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
12
17
  const webpack_merge_1 = require("webpack-merge");
13
18
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
14
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
15
19
  const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
16
20
  const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
17
- const path_1 = tslib_1.__importDefault(require("path"));
18
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
19
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
20
- const constants_1 = require("../constants");
21
- const lodash_1 = require("lodash");
22
21
  // Utility method to get style loaders
23
- function getStyleLoaders(isServer, cssOptions = {}) {
22
+ function getStyleLoaders(isServer, cssOptionsArg = {}) {
23
+ const cssOptions = {
24
+ // TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
25
+ esModule: false,
26
+ ...cssOptionsArg,
27
+ };
24
28
  if (isServer) {
25
29
  return cssOptions.modules
26
30
  ? [
@@ -66,7 +70,7 @@ function getStyleLoaders(isServer, cssOptions = {}) {
66
70
  // https://github.com/facebook/create-react-app/issues/2677
67
71
  ident: 'postcss',
68
72
  plugins: [
69
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
73
+ // eslint-disable-next-line global-require
70
74
  require('autoprefixer'),
71
75
  ],
72
76
  },
@@ -75,9 +79,9 @@ function getStyleLoaders(isServer, cssOptions = {}) {
75
79
  ];
76
80
  }
77
81
  exports.getStyleLoaders = getStyleLoaders;
78
- function getCustomBabelConfigFilePath(siteDir) {
79
- const customBabelConfigurationPath = path_1.default.join(siteDir, constants_1.BABEL_CONFIG_FILE_NAME);
80
- return fs_extra_1.default.existsSync(customBabelConfigurationPath)
82
+ async function getCustomBabelConfigFilePath(siteDir) {
83
+ const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
84
+ return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
81
85
  ? customBabelConfigurationPath
82
86
  : undefined;
83
87
  }
@@ -90,13 +94,12 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
90
94
  caller: { name: isServer ? 'server' : 'client' },
91
95
  };
92
96
  }
93
- else {
94
- return Object.assign(babelOptions !== null && babelOptions !== void 0 ? babelOptions : { presets: [require.resolve('../babel/preset')] }, {
95
- babelrc: false,
96
- configFile: false,
97
- caller: { name: isServer ? 'server' : 'client' },
98
- });
99
- }
97
+ return {
98
+ ...(babelOptions ?? { presets: [require.resolve('../babel/preset')] }),
99
+ babelrc: false,
100
+ configFile: false,
101
+ caller: { name: isServer ? 'server' : 'client' },
102
+ };
100
103
  }
101
104
  exports.getBabelOptions = getBabelOptions;
102
105
  // Name is generic on purpose
@@ -111,22 +114,6 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
111
114
  ? getDefaultBabelLoader({ isServer, babelOptions })
112
115
  : jsLoader(isServer);
113
116
  exports.getCustomizableJSLoader = getCustomizableJSLoader;
114
- // TODO remove this before end of 2021?
115
- const warnBabelLoaderOnce = lodash_1.memoize(function () {
116
- console.warn(chalk_1.default.yellow('Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): "getBabelLoader(isServer)" is now deprecated in favor of "getJSLoader({isServer})".'));
117
- });
118
- const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
119
- warnBabelLoaderOnce();
120
- return getDefaultBabelLoader({ isServer, babelOptions });
121
- };
122
- // TODO remove this before end of 2021 ?
123
- const warnCacheLoaderOnce = lodash_1.memoize(function () {
124
- console.warn(chalk_1.default.yellow('Docusaurus uses Webpack 5 and getCacheLoader() usage is now deprecated.'));
125
- });
126
- function getCacheLoaderDeprecated() {
127
- warnCacheLoaderOnce();
128
- return null;
129
- }
130
117
  /**
131
118
  * Helper function to modify webpack config
132
119
  * @param configureWebpack a webpack config or a function to modify config
@@ -140,30 +127,23 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
140
127
  // Export some utility functions
141
128
  const utils = {
142
129
  getStyleLoaders,
143
- getJSLoader: exports.getCustomizableJSLoader(jsLoader),
144
- getBabelLoader: getBabelLoaderDeprecated,
145
- getCacheLoader: getCacheLoaderDeprecated,
130
+ getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
146
131
  };
147
132
  if (typeof configureWebpack === 'function') {
148
- const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
149
- if (res && typeof res === 'object') {
150
- // @ts-expect-error: annoying error due to enums: https://github.com/survivejs/webpack-merge/issues/179
151
- const customizeRules = mergeStrategy !== null && mergeStrategy !== void 0 ? mergeStrategy : {};
152
- return webpack_merge_1.mergeWithCustomize({
153
- customizeArray: webpack_merge_1.customizeArray(customizeRules),
154
- customizeObject: webpack_merge_1.customizeObject(customizeRules),
155
- })(config, res);
156
- }
133
+ const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
134
+ const customizeRules = mergeStrategy ?? {};
135
+ return (0, webpack_merge_1.mergeWithCustomize)({
136
+ customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
137
+ customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
138
+ })(config, res);
157
139
  }
158
140
  return config;
159
141
  }
160
142
  exports.applyConfigureWebpack = applyConfigureWebpack;
161
143
  function applyConfigurePostCss(configurePostCss, config) {
162
- var _a, _b;
163
- // TODO not ideal heuristic but good enough for our usecase?
144
+ // Not ideal heuristic but good enough for our use-case?
164
145
  function isPostCssLoader(loader) {
165
- var _a, _b;
166
- return !!((_b = (_a = loader) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.postcssOptions);
146
+ return !!loader?.options?.postcssOptions;
167
147
  }
168
148
  // Does not handle all edge cases, but good enough for now
169
149
  function overridePostCssOptions(entry) {
@@ -176,42 +156,39 @@ function applyConfigurePostCss(configurePostCss, config) {
176
156
  else if (Array.isArray(entry.use)) {
177
157
  entry.use
178
158
  .filter((u) => typeof u === 'object')
179
- .forEach(overridePostCssOptions);
159
+ .forEach((rule) => overridePostCssOptions(rule));
180
160
  }
181
161
  }
182
- (_b = (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.forEach(overridePostCssOptions);
162
+ config.module?.rules?.forEach((rule) => overridePostCssOptions(rule));
183
163
  return config;
184
164
  }
185
165
  exports.applyConfigurePostCss = applyConfigurePostCss;
186
166
  function compile(config) {
187
167
  return new Promise((resolve, reject) => {
188
- const compiler = webpack_1.default(config);
168
+ const compiler = (0, webpack_1.default)(config);
189
169
  compiler.run((err, stats) => {
190
- var _a;
191
170
  if (err) {
192
- console.error(err.stack || err);
193
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
171
+ logger_1.default.error(err.stack ?? err);
194
172
  if (err.details) {
195
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
196
- console.error(err.details);
173
+ logger_1.default.error(err.details);
197
174
  }
198
175
  reject(err);
199
176
  }
200
- // let plugins consume all the stats
201
- const errorsWarnings = stats === null || stats === void 0 ? void 0 : stats.toJson('errors-warnings');
202
- if (stats === null || stats === void 0 ? void 0 : stats.hasErrors()) {
177
+ // Let plugins consume all the stats
178
+ const errorsWarnings = stats?.toJson('errors-warnings');
179
+ if (stats?.hasErrors()) {
203
180
  reject(new Error('Failed to compile with errors.'));
204
181
  }
205
- if (errorsWarnings && (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
206
- (_a = errorsWarnings.warnings) === null || _a === void 0 ? void 0 : _a.forEach((warning) => {
207
- console.warn(warning);
182
+ if (errorsWarnings && stats?.hasWarnings()) {
183
+ errorsWarnings.warnings?.forEach((warning) => {
184
+ logger_1.default.warn(warning);
208
185
  });
209
186
  }
210
187
  // Webpack 5 requires calling close() so that persistent caching works
211
188
  // See https://github.com/webpack/webpack.js.org/pull/4775
212
189
  compiler.close((errClose) => {
213
190
  if (errClose) {
214
- console.error(chalk_1.default.red('Error while closing Webpack compiler:', errClose));
191
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
215
192
  reject(errClose);
216
193
  }
217
194
  else {
@@ -222,145 +199,46 @@ function compile(config) {
222
199
  });
223
200
  }
224
201
  exports.compile = compile;
225
- // Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
226
- function getFileLoaderUtils() {
227
- // files/images < 10kb will be inlined as base64 strings directly in the html
228
- const urlLoaderLimit = 10000;
229
- // defines the path/pattern of the assets handled by webpack
230
- const fileLoaderFileName = (folder) => `${constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[hash].[ext]`;
231
- const loaders = {
232
- file: (options) => {
233
- return {
234
- loader: require.resolve(`file-loader`),
235
- options: {
236
- name: fileLoaderFileName(options.folder),
237
- },
238
- };
239
- },
240
- url: (options) => {
241
- return {
242
- loader: require.resolve(`url-loader`),
243
- options: {
244
- limit: urlLoaderLimit,
245
- name: fileLoaderFileName(options.folder),
246
- fallback: require.resolve(`file-loader`),
247
- },
248
- };
249
- },
250
- // TODO find a better solution to avoid conflicts with the ideal-image plugin
251
- // TODO this may require a little breaking change for ideal-image users?
252
- // Maybe with the ideal image plugin, all md images should be "ideal"?
253
- // This is used to force url-loader+file-loader on markdown images
254
- // https://webpack.js.org/concepts/loaders/#inline
255
- inlineMarkdownImageFileLoader: `!url-loader?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=file-loader!`,
256
- inlineMarkdownLinkFileLoader: `!file-loader?name=${fileLoaderFileName('files')}!`,
257
- };
258
- const rules = {
259
- /**
260
- * Loads image assets, inlines images via a data URI if they are below
261
- * the size threshold
262
- */
263
- images: () => {
264
- return {
265
- use: [loaders.url({ folder: 'images' })],
266
- test: /\.(ico|jpg|jpeg|png|gif|webp)(\?.*)?$/,
267
- };
268
- },
269
- fonts: () => {
270
- return {
271
- use: [loaders.url({ folder: 'fonts' })],
272
- test: /\.(woff|woff2|eot|ttf|otf)$/,
273
- };
274
- },
275
- /**
276
- * Loads audio and video and inlines them via a data URI if they are below
277
- * the size threshold
278
- */
279
- media: () => {
280
- return {
281
- use: [loaders.url({ folder: 'medias' })],
282
- test: /\.(mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/,
283
- };
284
- },
285
- svg: () => {
286
- return {
287
- test: /\.svg?$/,
288
- oneOf: [
289
- {
290
- use: [
291
- {
292
- loader: '@svgr/webpack',
293
- options: {
294
- prettier: false,
295
- svgo: true,
296
- svgoConfig: {
297
- plugins: [{ removeViewBox: false }],
298
- },
299
- titleProp: true,
300
- ref: ![path_1.default],
301
- },
302
- },
303
- ],
304
- // We don't want to use SVGR loader for non-React source code
305
- // ie we don't want to use SVGR for CSS files...
306
- issuer: {
307
- and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
308
- },
309
- },
310
- {
311
- use: [loaders.url({ folder: 'images' })],
312
- },
313
- ],
314
- };
315
- },
316
- otherAssets: () => {
317
- return {
318
- use: [loaders.file({ folder: 'files' })],
319
- test: /\.(pdf|doc|docx|xls|xlsx|zip|rar)$/,
320
- };
321
- },
322
- };
323
- return { loaders, rules };
324
- }
325
- exports.getFileLoaderUtils = getFileLoaderUtils;
326
202
  // Ensure the certificate and key provided are valid and if not
327
203
  // throw an easy to debug error
328
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
204
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
329
205
  let encrypted;
330
206
  try {
331
207
  // publicEncrypt will throw an error with an invalid cert
332
208
  encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
333
209
  }
334
210
  catch (err) {
335
- throw new Error(`The certificate "${chalk_1.default.yellow(crtFile)}" is invalid.\n${err.message}`);
211
+ logger_1.default.error `The certificate path=${crtFile} is invalid.`;
212
+ throw err;
336
213
  }
337
214
  try {
338
215
  // privateDecrypt will throw an error with an invalid key
339
216
  crypto_1.default.privateDecrypt(key, encrypted);
340
217
  }
341
218
  catch (err) {
342
- throw new Error(`The certificate key "${chalk_1.default.yellow(keyFile)}" is invalid.\n${err.message}`);
219
+ logger_1.default.error `The certificate key path=${keyFile} is invalid.`;
220
+ throw err;
343
221
  }
344
222
  }
345
223
  // Read file and throw an error if it doesn't exist
346
- function readEnvFile(file, type) {
347
- if (!fs_extra_1.default.existsSync(file)) {
348
- throw new Error(`You specified ${chalk_1.default.cyan(type)} in your env, but the file "${chalk_1.default.yellow(file)}" can't be found.`);
224
+ async function readEnvFile(file, type) {
225
+ if (!(await fs_extra_1.default.pathExists(file))) {
226
+ throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
349
227
  }
350
- return fs_extra_1.default.readFileSync(file);
228
+ return fs_extra_1.default.readFile(file);
351
229
  }
352
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
353
230
  // Get the https config
354
231
  // Return cert files if provided in env, otherwise just true or false
355
- function getHttpsConfig() {
232
+ async function getHttpsConfig() {
233
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
356
234
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
357
235
  const isHttps = HTTPS === 'true';
358
236
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
359
237
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
360
238
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
361
239
  const config = {
362
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
363
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
240
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
241
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
364
242
  };
365
243
  validateKeyAndCerts({ ...config, keyFile, crtFile });
366
244
  return config;
@@ -386,12 +264,12 @@ function getMinimizer(useSimpleCssMinifier = false) {
386
264
  parallel: getTerserParallel(),
387
265
  terserOptions: {
388
266
  parse: {
389
- // we want uglify-js to parse ecma 8 code. However, we don't want it
267
+ // We want uglify-js to parse ecma 8 code. However, we don't want it
390
268
  // to apply any minification steps that turns valid ecma 5 code
391
269
  // into invalid ecma 5 code. This is why the 'compress' and 'output'
392
270
  // sections only apply transformations that are ecma 5 safe
393
271
  // https://github.com/facebook/create-react-app/pull/4234
394
- ecma: 8,
272
+ ecma: 2020,
395
273
  },
396
274
  compress: {
397
275
  ecma: 5,
@@ -403,8 +281,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
403
281
  output: {
404
282
  ecma: 5,
405
283
  comments: false,
406
- // Turned on because emoji and regex is not minified properly using default
407
- // https://github.com/facebook/create-react-app/issues/2488
284
+ // Turned on because emoji and regex is not minified properly using
285
+ // default. See https://github.com/facebook/create-react-app/issues/2488
408
286
  ascii_only: true,
409
287
  },
410
288
  },
@@ -429,6 +307,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
429
307
  level: {
430
308
  1: {
431
309
  all: false,
310
+ removeWhitespace: true,
432
311
  },
433
312
  2: {
434
313
  all: true,