@docusaurus/core 2.0.0-beta.2 → 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 (222) 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 -8
  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 +39 -39
  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 +6 -10
  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 +90 -142
  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 +83 -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 +20 -26
  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 +39 -20
  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 +2 -2
  122. package/lib/server/configValidation.js +76 -35
  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 -13
  130. package/lib/server/index.js +79 -163
  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 +9 -8
  134. package/lib/server/plugins/index.js +71 -131
  135. package/lib/server/plugins/init.d.ts +6 -5
  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 +5 -1
  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 +11 -14
  152. package/lib/server/translations/translations.js +36 -60
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  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 +41 -53
  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 +9 -15
  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 +15 -7
  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 +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +57 -176
  178. package/package.json +75 -73
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.tsbuildinfo +0 -1
  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 -40
  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/plugins/applyRouteTrailingSlash.d.ts +0 -8
  203. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  204. package/lib/server/presets/index.d.ts +0 -11
  205. package/lib/server/presets/index.js +0 -48
  206. package/lib/server/themes/alias.d.ts +0 -8
  207. package/lib/server/themes/alias.js +0 -40
  208. package/lib/server/themes/index.d.ts +0 -12
  209. package/lib/server/themes/index.js +0 -47
  210. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  211. package/lib/server/versions/__fixtures__/package.json +0 -3
  212. package/lib/server/versions/__tests/index.test.js +0 -25
  213. package/lib/server/versions/index.d.ts +0 -10
  214. package/lib/server/versions/index.js +0 -50
  215. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  216. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  217. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  218. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  219. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  220. package/lib/webpack/sharedModuleAliases.js +0 -18
  221. package/tsconfig.client.json +0 -13
  222. package/tsconfig.json +0 -13
@@ -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,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
- const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
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,39 @@ 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);
193
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
173
+ logger_1.default.error(err.stack || err);
194
174
  if (err.details) {
195
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
196
- console.error(err.details);
175
+ logger_1.default.error(err.details);
197
176
  }
198
177
  reject(err);
199
178
  }
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()) {
179
+ // Let plugins consume all the stats
180
+ const errorsWarnings = stats?.toJson('errors-warnings');
181
+ if (stats?.hasErrors()) {
203
182
  reject(new Error('Failed to compile with errors.'));
204
183
  }
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);
184
+ if (errorsWarnings && stats?.hasWarnings()) {
185
+ errorsWarnings.warnings?.forEach((warning) => {
186
+ logger_1.default.warn(warning);
208
187
  });
209
188
  }
210
189
  // Webpack 5 requires calling close() so that persistent caching works
211
190
  // See https://github.com/webpack/webpack.js.org/pull/4775
212
191
  compiler.close((errClose) => {
213
192
  if (errClose) {
214
- console.error(chalk_1.default.red('Error while closing Webpack compiler:', errClose));
193
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
215
194
  reject(errClose);
216
195
  }
217
196
  else {
@@ -222,145 +201,46 @@ function compile(config) {
222
201
  });
223
202
  }
224
203
  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
204
  // Ensure the certificate and key provided are valid and if not
327
205
  // throw an easy to debug error
328
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
206
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
329
207
  let encrypted;
330
208
  try {
331
209
  // publicEncrypt will throw an error with an invalid cert
332
210
  encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
333
211
  }
334
212
  catch (err) {
335
- 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}`);
336
215
  }
337
216
  try {
338
217
  // privateDecrypt will throw an error with an invalid key
339
218
  crypto_1.default.privateDecrypt(key, encrypted);
340
219
  }
341
220
  catch (err) {
342
- 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}`);
343
223
  }
344
224
  }
345
225
  // 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.`);
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.`);
349
229
  }
350
- return fs_extra_1.default.readFileSync(file);
230
+ return fs_extra_1.default.readFile(file);
351
231
  }
352
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
353
232
  // Get the https config
354
233
  // Return cert files if provided in env, otherwise just true or false
355
- function getHttpsConfig() {
234
+ async function getHttpsConfig() {
235
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
356
236
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
357
237
  const isHttps = HTTPS === 'true';
358
238
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
359
239
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
360
240
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
361
241
  const config = {
362
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
363
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
242
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
243
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
364
244
  };
365
245
  validateKeyAndCerts({ ...config, keyFile, crtFile });
366
246
  return config;
@@ -386,12 +266,12 @@ function getMinimizer(useSimpleCssMinifier = false) {
386
266
  parallel: getTerserParallel(),
387
267
  terserOptions: {
388
268
  parse: {
389
- // 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
390
270
  // to apply any minification steps that turns valid ecma 5 code
391
271
  // into invalid ecma 5 code. This is why the 'compress' and 'output'
392
272
  // sections only apply transformations that are ecma 5 safe
393
273
  // https://github.com/facebook/create-react-app/pull/4234
394
- ecma: 8,
274
+ ecma: 2020,
395
275
  },
396
276
  compress: {
397
277
  ecma: 5,
@@ -403,8 +283,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
403
283
  output: {
404
284
  ecma: 5,
405
285
  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
286
+ // Turned on because emoji and regex is not minified properly using
287
+ // default. See https://github.com/facebook/create-react-app/issues/2488
408
288
  ascii_only: true,
409
289
  },
410
290
  },
@@ -429,6 +309,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
429
309
  level: {
430
310
  1: {
431
311
  all: false,
312
+ removeWhitespace: true,
432
313
  },
433
314
  2: {
434
315
  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.2",
4
+ "version": "2.0.0-beta.20",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,107 +21,109 @@
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 -p tsconfig.server.json && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
28
+ "watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc -p tsconfig.server.json --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.2",
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.10",
35
+ "@babel/generator": "^7.17.10",
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.2",
51
- "@docusaurus/react-loadable": "5.5.0",
52
- "@docusaurus/types": "2.0.0-beta.2",
53
- "@docusaurus/utils": "2.0.0-beta.2",
54
- "@docusaurus/utils-common": "2.0.0-beta.2",
55
- "@docusaurus/utils-validation": "2.0.0-beta.2",
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.10",
38
+ "@babel/preset-env": "^7.17.10",
39
+ "@babel/preset-react": "^7.16.7",
40
+ "@babel/preset-typescript": "^7.16.7",
41
+ "@babel/runtime": "^7.17.9",
42
+ "@babel/runtime-corejs3": "^7.17.9",
43
+ "@babel/traverse": "^7.17.10",
44
+ "@docusaurus/cssnano-preset": "2.0.0-beta.20",
45
+ "@docusaurus/logger": "2.0.0-beta.20",
46
+ "@docusaurus/mdx-loader": "2.0.0-beta.20",
47
+ "@docusaurus/react-loadable": "5.5.2",
48
+ "@docusaurus/utils": "2.0.0-beta.20",
49
+ "@docusaurus/utils-common": "2.0.0-beta.20",
50
+ "@docusaurus/utils-validation": "2.0.0-beta.20",
51
+ "@slorber/static-site-generator-webpack-plugin": "^4.0.4",
52
+ "@svgr/webpack": "^6.2.1",
53
+ "autoprefixer": "^10.4.5",
54
+ "babel-loader": "^8.2.5",
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.3.0",
59
+ "cli-table3": "^0.6.2",
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.22.3",
64
+ "css-loader": "^6.7.1",
65
+ "css-minimizer-webpack-plugin": "^3.4.1",
66
+ "cssnano": "^5.1.7",
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",
81
- "html-tags": "^3.1.0",
82
- "html-webpack-plugin": "^5.3.2",
72
+ "fs-extra": "^10.1.0",
73
+ "html-minifier-terser": "^6.1.0",
74
+ "html-tags": "^3.2.0",
75
+ "html-webpack-plugin": "^5.5.0",
83
76
  "import-fresh": "^3.3.0",
84
- "is-root": "^2.1.0",
85
77
  "leven": "^3.1.0",
86
- "lodash": "^4.17.20",
87
- "mini-css-extract-plugin": "^1.6.0",
88
- "module-alias": "^2.2.2",
89
- "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",
78
+ "lodash": "^4.17.21",
79
+ "mini-css-extract-plugin": "^2.6.0",
80
+ "postcss": "^8.4.13",
81
+ "postcss-loader": "^6.2.1",
82
+ "prompts": "^2.4.2",
83
+ "react-dev-utils": "^12.0.1",
84
+ "react-helmet-async": "^1.3.0",
85
+ "react-loadable": "npm:@docusaurus/react-loadable@5.5.2",
97
86
  "react-loadable-ssr-addon-v5-slorber": "^1.0.1",
98
87
  "react-router": "^5.2.0",
99
88
  "react-router-config": "^5.1.1",
100
89
  "react-router-dom": "^5.2.0",
101
- "resolve-pathname": "^3.0.0",
102
- "rtl-detect": "^1.0.3",
103
- "semver": "^7.3.4",
90
+ "remark-admonitions": "^1.2.1",
91
+ "rtl-detect": "^1.0.4",
92
+ "semver": "^7.3.7",
104
93
  "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",
94
+ "shelljs": "^0.8.5",
95
+ "terser-webpack-plugin": "^5.3.1",
96
+ "tslib": "^2.4.0",
110
97
  "update-notifier": "^5.1.0",
111
98
  "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",
99
+ "wait-on": "^6.0.1",
100
+ "webpack": "^5.72.0",
101
+ "webpack-bundle-analyzer": "^4.5.0",
102
+ "webpack-dev-server": "^4.8.1",
116
103
  "webpack-merge": "^5.8.0",
117
- "webpackbar": "^5.0.0-3"
104
+ "webpackbar": "^5.0.2"
105
+ },
106
+ "devDependencies": {
107
+ "@docusaurus/module-type-aliases": "2.0.0-beta.20",
108
+ "@docusaurus/types": "2.0.0-beta.20",
109
+ "@types/detect-port": "^1.3.2",
110
+ "@types/react-dom": "^18.0.3",
111
+ "@types/react-router-config": "^5.0.6",
112
+ "@types/rtl-detect": "^1.0.0",
113
+ "@types/serve-handler": "^6.1.1",
114
+ "@types/update-notifier": "^5.1.0",
115
+ "@types/wait-on": "^5.3.1",
116
+ "@types/webpack-bundle-analyzer": "^4.4.1",
117
+ "react-test-renderer": "^17.0.2",
118
+ "tmp-promise": "^3.0.3",
119
+ "tree-node-cli": "^1.5.2"
118
120
  },
119
121
  "peerDependencies": {
120
122
  "react": "^16.8.4 || ^17.0.0",
121
123
  "react-dom": "^16.8.4 || ^17.0.0"
122
124
  },
123
125
  "engines": {
124
- "node": ">=12.13.0"
126
+ "node": ">=14"
125
127
  },
126
- "gitHead": "883f07fddffaf1657407c8e202e370cc436e25f7"
128
+ "gitHead": "ed5cdba401a5948e187e927039b142a0decc702d"
127
129
  }