@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

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 (189) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +29 -38
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +19 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +5 -9
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  16. package/lib/client/client-lifecycles-dispatcher.js +6 -10
  17. package/lib/client/clientEntry.js +11 -5
  18. package/lib/client/docusaurus.d.ts +6 -0
  19. package/lib/client/docusaurus.js +16 -25
  20. package/lib/client/exports/BrowserOnly.d.ts +2 -3
  21. package/lib/client/exports/BrowserOnly.js +13 -7
  22. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  23. package/lib/client/exports/ComponentCreator.js +7 -6
  24. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  25. package/lib/client/exports/ErrorBoundary.js +35 -0
  26. package/lib/client/exports/Head.d.ts +2 -3
  27. package/lib/client/exports/Head.js +3 -4
  28. package/lib/client/exports/Interpolate.d.ts +1 -1
  29. package/lib/client/exports/Interpolate.js +16 -22
  30. package/lib/client/exports/Link.d.ts +11 -5
  31. package/lib/client/exports/Link.js +24 -19
  32. package/lib/client/exports/Translate.d.ts +3 -3
  33. package/lib/client/exports/Translate.js +14 -10
  34. package/lib/client/exports/browserContext.d.ts +11 -0
  35. package/lib/client/exports/browserContext.js +22 -0
  36. package/lib/client/exports/constants.js +1 -11
  37. package/lib/client/exports/docusaurusContext.d.ts +12 -0
  38. package/lib/client/exports/docusaurusContext.js +25 -0
  39. package/lib/client/exports/isInternalUrl.js +1 -1
  40. package/lib/client/exports/renderRoutes.d.ts +1 -2
  41. package/lib/client/exports/renderRoutes.js +1 -2
  42. package/lib/client/exports/router.d.ts +1 -1
  43. package/lib/client/exports/router.js +1 -1
  44. package/lib/client/exports/useBaseUrl.js +3 -5
  45. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  46. package/lib/client/exports/useDocusaurusContext.js +3 -9
  47. package/lib/client/exports/useGlobalData.js +1 -5
  48. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  49. package/lib/client/exports/useIsBrowser.js +11 -0
  50. package/lib/client/flat.d.ts +2 -2
  51. package/lib/client/flat.js +8 -11
  52. package/lib/client/normalizeLocation.d.ts +2 -5
  53. package/lib/client/normalizeLocation.js +1 -2
  54. package/lib/client/nprogress.css +2 -2
  55. package/lib/client/prefetch.d.ts +1 -2
  56. package/lib/client/prefetch.js +1 -3
  57. package/lib/client/preload.d.ts +3 -2
  58. package/lib/client/preload.js +2 -1
  59. package/lib/client/serverEntry.d.ts +10 -0
  60. package/lib/client/serverEntry.js +90 -142
  61. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  62. package/lib/client/theme-fallback/Error/index.js +39 -0
  63. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  64. package/lib/client/theme-fallback/Layout/index.js +10 -19
  65. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  66. package/lib/client/theme-fallback/Loading/index.js +47 -115
  67. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  68. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  69. package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
  70. package/lib/client/theme-fallback/Root/index.js +2 -7
  71. package/lib/commands/build.d.ts +1 -1
  72. package/lib/commands/build.js +50 -54
  73. package/lib/commands/clear.d.ts +6 -0
  74. package/lib/commands/clear.js +30 -19
  75. package/lib/commands/commandUtils.d.ts +7 -1
  76. package/lib/commands/commandUtils.js +6 -6
  77. package/lib/commands/deploy.d.ts +4 -1
  78. package/lib/commands/deploy.js +102 -66
  79. package/lib/commands/external.d.ts +2 -2
  80. package/lib/commands/external.js +3 -3
  81. package/lib/commands/serve.d.ts +1 -1
  82. package/lib/commands/serve.js +13 -19
  83. package/lib/commands/start.d.ts +1 -1
  84. package/lib/commands/start.js +93 -83
  85. package/lib/commands/swizzle/actions.d.ts +23 -0
  86. package/lib/commands/swizzle/actions.js +102 -0
  87. package/lib/commands/swizzle/common.d.ts +33 -0
  88. package/lib/commands/swizzle/common.js +56 -0
  89. package/lib/commands/swizzle/components.d.ts +29 -0
  90. package/lib/commands/swizzle/components.js +162 -0
  91. package/lib/commands/swizzle/config.d.ts +10 -0
  92. package/lib/commands/swizzle/config.js +80 -0
  93. package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
  94. package/lib/commands/swizzle/context.js +30 -0
  95. package/lib/commands/swizzle/index.d.ts +8 -0
  96. package/lib/commands/swizzle/index.js +115 -0
  97. package/lib/commands/swizzle/prompts.d.ts +12 -0
  98. package/lib/commands/swizzle/prompts.js +110 -0
  99. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  100. package/lib/commands/swizzle/tables.js +116 -0
  101. package/lib/commands/swizzle/themes.d.ts +20 -0
  102. package/lib/commands/swizzle/themes.js +103 -0
  103. package/lib/commands/writeHeadingIds.d.ts +9 -6
  104. package/lib/commands/writeHeadingIds.js +41 -43
  105. package/lib/commands/writeTranslations.d.ts +2 -2
  106. package/lib/commands/writeTranslations.js +35 -14
  107. package/lib/index.d.ts +10 -9
  108. package/lib/index.js +20 -19
  109. package/lib/server/brokenLinks.d.ts +1 -1
  110. package/lib/server/brokenLinks.js +57 -38
  111. package/lib/server/client-modules/index.d.ts +1 -1
  112. package/lib/server/client-modules/index.js +1 -3
  113. package/lib/server/config.d.ts +2 -2
  114. package/lib/server/config.js +7 -4
  115. package/lib/server/configValidation.d.ts +2 -2
  116. package/lib/server/configValidation.js +43 -28
  117. package/lib/server/duplicateRoutes.d.ts +1 -1
  118. package/lib/server/duplicateRoutes.js +10 -6
  119. package/lib/server/html-tags/htmlTags.js +2 -4
  120. package/lib/server/html-tags/index.d.ts +1 -1
  121. package/lib/server/html-tags/index.js +1 -1
  122. package/lib/server/i18n.d.ts +1 -2
  123. package/lib/server/i18n.js +32 -46
  124. package/lib/server/index.d.ts +2 -2
  125. package/lib/server/index.js +147 -68
  126. package/lib/server/moduleShorthand.d.ts +9 -0
  127. package/lib/server/moduleShorthand.js +46 -0
  128. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  129. package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
  130. package/lib/server/plugins/index.d.ts +2 -2
  131. package/lib/server/plugins/index.js +34 -35
  132. package/lib/server/plugins/init.d.ts +12 -2
  133. package/lib/server/plugins/init.js +48 -58
  134. package/lib/server/plugins/pluginIds.d.ts +1 -1
  135. package/lib/server/plugins/pluginIds.js +8 -5
  136. package/lib/server/presets/index.d.ts +3 -3
  137. package/lib/server/presets/index.js +12 -13
  138. package/lib/server/routes.d.ts +1 -1
  139. package/lib/server/routes.js +50 -29
  140. package/lib/server/themes/alias.d.ts +3 -2
  141. package/lib/server/themes/alias.js +22 -14
  142. package/lib/server/themes/index.d.ts +3 -3
  143. package/lib/server/themes/index.js +26 -26
  144. package/lib/server/translations/translations.d.ts +7 -1
  145. package/lib/server/translations/translations.js +30 -45
  146. package/lib/server/translations/translationsExtractor.d.ts +9 -3
  147. package/lib/server/translations/translationsExtractor.js +159 -120
  148. package/lib/server/utils.d.ts +9 -3
  149. package/lib/server/utils.js +7 -9
  150. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  151. package/lib/server/versions/index.d.ts +3 -4
  152. package/lib/server/versions/index.js +22 -21
  153. package/lib/webpack/base.d.ts +4 -4
  154. package/lib/webpack/base.js +38 -33
  155. package/lib/webpack/client.d.ts +3 -3
  156. package/lib/webpack/client.js +12 -19
  157. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  158. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  159. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  160. package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
  161. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  162. package/lib/webpack/plugins/LogPlugin.js +4 -5
  163. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  164. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  165. package/lib/webpack/server.d.ts +3 -3
  166. package/lib/webpack/server.js +9 -8
  167. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  168. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  169. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  170. package/lib/webpack/utils.d.ts +7 -29
  171. package/lib/webpack/utils.js +54 -171
  172. package/package.json +74 -69
  173. package/lib/.tsbuildinfo +0 -1
  174. package/lib/client/.tsbuildinfo +0 -1
  175. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  176. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  177. package/lib/commands/swizzle.d.ts +0 -9
  178. package/lib/commands/swizzle.js +0 -245
  179. package/lib/constants.d.ts +0 -18
  180. package/lib/constants.js +0 -23
  181. package/lib/server/loadSetup.js +0 -25
  182. package/lib/server/versions/__tests/index.test.js +0 -25
  183. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  184. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  185. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  186. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  187. package/lib/webpack/sharedModuleAliases.js +0 -18
  188. package/tsconfig.client.json +0 -13
  189. 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>
@@ -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 { ConfigureWebpackFn, ConfigurePostCssFn } 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;
@@ -32,30 +32,8 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
32
32
  export declare function applyConfigureWebpack(configureWebpack: ConfigureWebpackFn, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
33
33
  export declare function applyConfigurePostCss(configurePostCss: NonNullable<ConfigurePostCssFn>, config: Configuration): Configuration;
34
34
  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 | {
35
+ export declare function getHttpsConfig(): Promise<boolean | {
57
36
  cert: Buffer;
58
37
  key: Buffer;
59
- };
38
+ }>;
60
39
  export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
61
- 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,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,18 +127,15 @@ 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
133
  const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
149
134
  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),
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),
155
139
  })(config, res);
156
140
  }
157
141
  }
@@ -159,11 +143,9 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
159
143
  }
160
144
  exports.applyConfigureWebpack = applyConfigureWebpack;
161
145
  function applyConfigurePostCss(configurePostCss, config) {
162
- var _a, _b;
163
- // TODO not ideal heuristic but good enough for our usecase?
146
+ // not ideal heuristic but good enough for our use-case?
164
147
  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);
148
+ return !!loader?.options?.postcssOptions;
167
149
  }
168
150
  // Does not handle all edge cases, but good enough for now
169
151
  function overridePostCssOptions(entry) {
@@ -176,42 +158,41 @@ function applyConfigurePostCss(configurePostCss, config) {
176
158
  else if (Array.isArray(entry.use)) {
177
159
  entry.use
178
160
  .filter((u) => typeof u === 'object')
179
- .forEach(overridePostCssOptions);
161
+ .forEach((rule) => overridePostCssOptions(rule));
180
162
  }
181
163
  }
182
- (_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));
183
165
  return config;
184
166
  }
185
167
  exports.applyConfigurePostCss = applyConfigurePostCss;
186
168
  function compile(config) {
187
169
  return new Promise((resolve, reject) => {
188
- const compiler = webpack_1.default(config);
170
+ const compiler = (0, webpack_1.default)(config);
189
171
  compiler.run((err, stats) => {
190
- var _a;
191
172
  if (err) {
192
- console.error(err.stack || err);
173
+ logger_1.default.error(err.stack || err);
193
174
  // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
194
175
  if (err.details) {
195
176
  // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
196
- console.error(err.details);
177
+ logger_1.default.error(err.details);
197
178
  }
198
179
  reject(err);
199
180
  }
200
181
  // 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()) {
182
+ const errorsWarnings = stats?.toJson('errors-warnings');
183
+ if (stats?.hasErrors()) {
203
184
  reject(new Error('Failed to compile with errors.'));
204
185
  }
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);
186
+ if (errorsWarnings && stats?.hasWarnings()) {
187
+ errorsWarnings.warnings?.forEach((warning) => {
188
+ logger_1.default.warn(warning);
208
189
  });
209
190
  }
210
191
  // Webpack 5 requires calling close() so that persistent caching works
211
192
  // See https://github.com/webpack/webpack.js.org/pull/4775
212
193
  compiler.close((errClose) => {
213
194
  if (errClose) {
214
- console.error(chalk_1.default.red('Error while closing Webpack compiler:', errClose));
195
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
215
196
  reject(errClose);
216
197
  }
217
198
  else {
@@ -222,145 +203,46 @@ function compile(config) {
222
203
  });
223
204
  }
224
205
  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
206
  // Ensure the certificate and key provided are valid and if not
327
207
  // throw an easy to debug error
328
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
208
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
329
209
  let encrypted;
330
210
  try {
331
211
  // publicEncrypt will throw an error with an invalid cert
332
212
  encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
333
213
  }
334
214
  catch (err) {
335
- throw new Error(`The certificate "${chalk_1.default.yellow(crtFile)}" is invalid.\n${err.message}`);
215
+ throw new Error(`The certificate ${crtFile} is invalid.
216
+ ${err}`);
336
217
  }
337
218
  try {
338
219
  // privateDecrypt will throw an error with an invalid key
339
220
  crypto_1.default.privateDecrypt(key, encrypted);
340
221
  }
341
222
  catch (err) {
342
- throw new Error(`The certificate key "${chalk_1.default.yellow(keyFile)}" is invalid.\n${err.message}`);
223
+ throw new Error(`The certificate key ${keyFile} is invalid.
224
+ ${err}`);
343
225
  }
344
226
  }
345
227
  // 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.`);
228
+ async function readEnvFile(file, type) {
229
+ if (!(await fs_extra_1.default.pathExists(file))) {
230
+ throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
349
231
  }
350
- return fs_extra_1.default.readFileSync(file);
232
+ return fs_extra_1.default.readFile(file);
351
233
  }
352
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
353
234
  // Get the https config
354
235
  // Return cert files if provided in env, otherwise just true or false
355
- function getHttpsConfig() {
236
+ async function getHttpsConfig() {
237
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
356
238
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
357
239
  const isHttps = HTTPS === 'true';
358
240
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
359
241
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
360
242
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
361
243
  const config = {
362
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
363
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
244
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
245
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
364
246
  };
365
247
  validateKeyAndCerts({ ...config, keyFile, crtFile });
366
248
  return config;
@@ -391,7 +273,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
391
273
  // into invalid ecma 5 code. This is why the 'compress' and 'output'
392
274
  // sections only apply transformations that are ecma 5 safe
393
275
  // https://github.com/facebook/create-react-app/pull/4234
394
- ecma: 8,
276
+ ecma: 2020,
395
277
  },
396
278
  compress: {
397
279
  ecma: 5,
@@ -403,8 +285,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
403
285
  output: {
404
286
  ecma: 5,
405
287
  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
288
+ // Turned on because emoji and regex is not minified properly using
289
+ // default. See https://github.com/facebook/create-react-app/issues/2488
408
290
  ascii_only: true,
409
291
  },
410
292
  },
@@ -429,6 +311,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
429
311
  level: {
430
312
  1: {
431
313
  all: false,
314
+ removeWhitespace: true,
432
315
  },
433
316
  2: {
434
317
  all: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "2.0.0-beta.15a2b59f9",
4
+ "version": "2.0.0-beta.17",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,107 +21,112 @@
21
21
  "directory": "packages/docusaurus"
22
22
  },
23
23
  "bin": {
24
- "docusaurus": "bin/docusaurus.js"
24
+ "docusaurus": "bin/docusaurus.mjs"
25
25
  },
26
26
  "scripts": {
27
- "build": "tsc && tsc -p tsconfig.client.json && node copyUntypedFiles.js",
28
- "watch": "node copyUntypedFiles.js && concurrently -n \"server,client\" --kill-others \"tsc --watch\" \"tsc -p tsconfig.client.json --watch\""
27
+ "build": "tsc && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
28
+ "watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc --watch\" \"tsc -p tsconfig.client.json --watch\""
29
29
  },
30
30
  "bugs": {
31
31
  "url": "https://github.com/facebook/docusaurus/issues"
32
32
  },
33
- "devDependencies": {
34
- "@docusaurus/module-type-aliases": "2.0.0-beta.15a2b59f9",
35
- "@types/detect-port": "^1.3.0",
36
- "@types/nprogress": "^0.2.0",
37
- "tmp-promise": "^3.0.2"
38
- },
39
33
  "dependencies": {
40
- "@babel/core": "^7.12.16",
41
- "@babel/generator": "^7.12.15",
34
+ "@babel/core": "^7.17.5",
35
+ "@babel/generator": "^7.17.3",
42
36
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
43
- "@babel/plugin-transform-runtime": "^7.12.15",
44
- "@babel/preset-env": "^7.12.16",
45
- "@babel/preset-react": "^7.12.13",
46
- "@babel/preset-typescript": "^7.12.16",
47
- "@babel/runtime": "^7.12.5",
48
- "@babel/runtime-corejs3": "^7.12.13",
49
- "@babel/traverse": "^7.12.13",
50
- "@docusaurus/cssnano-preset": "2.0.0-beta.15a2b59f9",
51
- "@docusaurus/react-loadable": "5.5.0",
52
- "@docusaurus/types": "2.0.0-beta.15a2b59f9",
53
- "@docusaurus/utils": "2.0.0-beta.15a2b59f9",
54
- "@docusaurus/utils-common": "2.0.0-beta.15a2b59f9",
55
- "@docusaurus/utils-validation": "2.0.0-beta.15a2b59f9",
56
- "@slorber/static-site-generator-webpack-plugin": "^4.0.0",
57
- "@svgr/webpack": "^5.5.0",
58
- "autoprefixer": "^10.2.5",
59
- "babel-loader": "^8.2.2",
37
+ "@babel/plugin-transform-runtime": "^7.17.0",
38
+ "@babel/preset-env": "^7.16.11",
39
+ "@babel/preset-react": "^7.16.7",
40
+ "@babel/preset-typescript": "^7.16.7",
41
+ "@babel/runtime": "^7.17.2",
42
+ "@babel/runtime-corejs3": "^7.17.2",
43
+ "@babel/traverse": "^7.17.3",
44
+ "@docusaurus/cssnano-preset": "2.0.0-beta.17",
45
+ "@docusaurus/logger": "2.0.0-beta.17",
46
+ "@docusaurus/mdx-loader": "2.0.0-beta.17",
47
+ "@docusaurus/react-loadable": "5.5.2",
48
+ "@docusaurus/utils": "2.0.0-beta.17",
49
+ "@docusaurus/utils-common": "2.0.0-beta.17",
50
+ "@docusaurus/utils-validation": "2.0.0-beta.17",
51
+ "@slorber/static-site-generator-webpack-plugin": "^4.0.1",
52
+ "@svgr/webpack": "^6.2.1",
53
+ "autoprefixer": "^10.4.2",
54
+ "babel-loader": "^8.2.3",
60
55
  "babel-plugin-dynamic-import-node": "2.3.0",
61
- "boxen": "^5.0.1",
62
- "chalk": "^4.1.1",
63
- "chokidar": "^3.5.1",
64
- "clean-css": "^5.1.2",
56
+ "boxen": "^6.2.1",
57
+ "chokidar": "^3.5.3",
58
+ "clean-css": "^5.2.4",
59
+ "cli-table3": "^0.6.1",
60
+ "combine-promises": "^1.1.0",
65
61
  "commander": "^5.1.0",
66
- "copy-webpack-plugin": "^9.0.0",
67
- "core-js": "^3.9.1",
68
- "css-loader": "^5.1.1",
69
- "css-minimizer-webpack-plugin": "^3.0.1",
70
- "cssnano": "^5.0.4",
62
+ "copy-webpack-plugin": "^10.2.4",
63
+ "core-js": "^3.21.1",
64
+ "css-loader": "^6.6.0",
65
+ "css-minimizer-webpack-plugin": "^3.4.1",
66
+ "cssnano": "^5.0.17",
71
67
  "del": "^6.0.0",
72
68
  "detect-port": "^1.3.0",
73
69
  "escape-html": "^1.0.3",
74
- "eta": "^1.12.1",
75
- "express": "^4.17.1",
70
+ "eta": "^1.12.3",
76
71
  "file-loader": "^6.2.0",
77
- "fs-extra": "^10.0.0",
78
- "github-slugger": "^1.3.0",
79
- "globby": "^11.0.2",
80
- "html-minifier-terser": "^5.1.1",
72
+ "fs-extra": "^10.0.1",
73
+ "html-minifier-terser": "^6.1.0",
81
74
  "html-tags": "^3.1.0",
82
- "html-webpack-plugin": "^5.3.2",
75
+ "html-webpack-plugin": "^5.5.0",
83
76
  "import-fresh": "^3.3.0",
84
77
  "is-root": "^2.1.0",
85
78
  "leven": "^3.1.0",
86
- "lodash": "^4.17.20",
87
- "mini-css-extract-plugin": "^1.6.0",
88
- "module-alias": "^2.2.2",
79
+ "lodash": "^4.17.21",
80
+ "mini-css-extract-plugin": "^2.5.3",
89
81
  "nprogress": "^0.2.0",
90
- "postcss": "^8.2.15",
91
- "postcss-loader": "^5.3.0",
92
- "prompts": "^2.4.1",
93
- "react-dev-utils": "^11.0.1",
94
- "react-error-overlay": "^6.0.9",
95
- "react-helmet": "^6.1.0",
96
- "react-loadable": "^5.5.0",
82
+ "postcss": "^8.4.7",
83
+ "postcss-loader": "^6.2.1",
84
+ "prompts": "^2.4.2",
85
+ "react-dev-utils": "^12.0.0",
86
+ "react-helmet-async": "^1.2.3",
87
+ "react-loadable": "npm:@docusaurus/react-loadable@5.5.2",
97
88
  "react-loadable-ssr-addon-v5-slorber": "^1.0.1",
98
89
  "react-router": "^5.2.0",
99
90
  "react-router-config": "^5.1.1",
100
91
  "react-router-dom": "^5.2.0",
101
- "resolve-pathname": "^3.0.0",
102
- "rtl-detect": "^1.0.3",
92
+ "remark-admonitions": "^1.2.1",
93
+ "rtl-detect": "^1.0.4",
103
94
  "semver": "^7.3.4",
104
95
  "serve-handler": "^6.1.3",
105
- "shelljs": "^0.8.4",
106
- "std-env": "^2.2.1",
107
- "strip-ansi": "^6.0.0",
108
- "terser-webpack-plugin": "^5.1.3",
109
- "tslib": "^2.2.0",
96
+ "shelljs": "^0.8.5",
97
+ "terser-webpack-plugin": "^5.3.1",
98
+ "tslib": "^2.3.1",
110
99
  "update-notifier": "^5.1.0",
111
100
  "url-loader": "^4.1.1",
112
- "wait-on": "^5.3.0",
113
- "webpack": "^5.40.0",
114
- "webpack-bundle-analyzer": "^4.4.2",
115
- "webpack-dev-server": "^3.11.2",
101
+ "wait-on": "^6.0.1",
102
+ "webpack": "^5.69.1",
103
+ "webpack-bundle-analyzer": "^4.5.0",
104
+ "webpack-dev-server": "^4.7.4",
116
105
  "webpack-merge": "^5.8.0",
117
- "webpackbar": "^5.0.0-3"
106
+ "webpackbar": "^5.0.2"
107
+ },
108
+ "devDependencies": {
109
+ "@docusaurus/module-type-aliases": "2.0.0-beta.17",
110
+ "@docusaurus/types": "2.0.0-beta.17",
111
+ "@types/detect-port": "^1.3.2",
112
+ "@types/nprogress": "^0.2.0",
113
+ "@types/react-dom": "^17.0.11",
114
+ "@types/react-router-config": "^5.0.6",
115
+ "@types/rtl-detect": "^1.0.0",
116
+ "@types/serve-handler": "^6.1.1",
117
+ "@types/update-notifier": "^5.1.0",
118
+ "@types/wait-on": "^5.3.1",
119
+ "@types/webpack-bundle-analyzer": "^4.4.1",
120
+ "react-test-renderer": "^17.0.2",
121
+ "tmp-promise": "^3.0.3",
122
+ "tree-node-cli": "^1.5.2"
118
123
  },
119
124
  "peerDependencies": {
120
125
  "react": "^16.8.4 || ^17.0.0",
121
126
  "react-dom": "^16.8.4 || ^17.0.0"
122
127
  },
123
128
  "engines": {
124
- "node": ">=12.13.0"
129
+ "node": ">=14"
125
130
  },
126
- "gitHead": "34881586224092fb9b5b2f455a46e19b3eee7f08"
131
+ "gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
127
132
  }