@docusaurus/core 2.0.0-beta.1decd6f80 → 2.0.0-beta.20

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