@docusaurus/core 2.0.0-beta.ff31de0ff → 2.0.0-rc.1

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/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/docusaurus.mjs +221 -0
  4. package/lib/babel/preset.d.ts +8 -3
  5. package/lib/babel/preset.js +10 -8
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +47 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -7
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +37 -0
  32. package/lib/client/exports/ExecutionEnvironment.js +7 -8
  33. package/lib/client/exports/Head.d.ts +2 -3
  34. package/lib/client/exports/Head.js +3 -4
  35. package/lib/client/exports/Interpolate.d.ts +2 -2
  36. package/lib/client/exports/Interpolate.js +20 -49
  37. package/lib/client/exports/Link.d.ts +4 -10
  38. package/lib/client/exports/Link.js +44 -38
  39. package/lib/client/exports/Translate.d.ts +1 -1
  40. package/lib/client/exports/Translate.js +14 -9
  41. package/lib/client/exports/constants.js +1 -11
  42. package/lib/client/exports/isInternalUrl.js +1 -1
  43. package/lib/client/exports/renderRoutes.d.ts +1 -2
  44. package/lib/client/exports/renderRoutes.js +1 -2
  45. package/lib/client/exports/router.d.ts +1 -1
  46. package/lib/client/exports/router.js +1 -1
  47. package/lib/client/exports/useBaseUrl.js +11 -14
  48. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  49. package/lib/client/exports/useDocusaurusContext.js +3 -9
  50. package/lib/client/exports/useGlobalData.d.ts +4 -3
  51. package/lib/client/exports/useGlobalData.js +8 -15
  52. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  53. package/lib/client/exports/useIsBrowser.js +11 -0
  54. package/lib/client/exports/useRouteContext.d.ts +8 -0
  55. package/lib/client/exports/useRouteContext.js +15 -0
  56. package/lib/client/flat.d.ts +12 -2
  57. package/lib/client/flat.js +19 -15
  58. package/lib/client/normalizeLocation.d.ts +2 -5
  59. package/lib/client/normalizeLocation.js +14 -10
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +12 -32
  62. package/lib/client/preload.d.ts +3 -4
  63. package/lib/client/preload.js +5 -12
  64. package/lib/client/routeContext.d.ts +13 -0
  65. package/lib/client/routeContext.js +31 -0
  66. package/lib/client/serverEntry.d.ts +10 -0
  67. package/lib/client/serverEntry.js +109 -136
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +45 -0
  70. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  71. package/lib/client/theme-fallback/Layout/index.js +2 -26
  72. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  73. package/lib/client/theme-fallback/Loading/index.js +50 -116
  74. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  75. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  76. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  77. package/lib/client/theme-fallback/Root/index.js +2 -6
  78. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +6 -2
  81. package/lib/commands/build.js +81 -64
  82. package/lib/commands/clear.d.ts +7 -1
  83. package/lib/commands/clear.js +34 -21
  84. package/lib/commands/deploy.d.ts +5 -2
  85. package/lib/commands/deploy.js +102 -81
  86. package/lib/commands/external.d.ts +2 -2
  87. package/lib/commands/external.js +9 -11
  88. package/lib/commands/serve.d.ts +8 -2
  89. package/lib/commands/serve.js +40 -20
  90. package/lib/commands/start.d.ts +9 -2
  91. package/lib/commands/start.js +111 -101
  92. package/lib/commands/swizzle/actions.d.ts +23 -0
  93. package/lib/commands/swizzle/actions.js +106 -0
  94. package/lib/commands/swizzle/common.d.ts +33 -0
  95. package/lib/commands/swizzle/common.js +56 -0
  96. package/lib/commands/swizzle/components.d.ts +29 -0
  97. package/lib/commands/swizzle/components.js +200 -0
  98. package/lib/commands/swizzle/config.d.ts +10 -0
  99. package/lib/commands/swizzle/config.js +84 -0
  100. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  101. package/lib/commands/swizzle/context.js +24 -0
  102. package/lib/commands/swizzle/index.d.ts +8 -0
  103. package/lib/commands/swizzle/index.js +119 -0
  104. package/lib/commands/swizzle/prompts.d.ts +12 -0
  105. package/lib/commands/swizzle/prompts.js +110 -0
  106. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  107. package/lib/commands/swizzle/tables.js +113 -0
  108. package/lib/commands/swizzle/themes.d.ts +20 -0
  109. package/lib/commands/swizzle/themes.js +106 -0
  110. package/lib/commands/writeHeadingIds.d.ts +2 -6
  111. package/lib/commands/writeHeadingIds.js +22 -81
  112. package/lib/commands/writeTranslations.d.ts +4 -5
  113. package/lib/commands/writeTranslations.js +48 -28
  114. package/lib/index.d.ts +9 -9
  115. package/lib/index.js +14 -14
  116. package/lib/server/brokenLinks.d.ts +4 -17
  117. package/lib/server/brokenLinks.js +67 -56
  118. package/lib/server/clientModules.d.ts +12 -0
  119. package/lib/server/clientModules.js +20 -0
  120. package/lib/server/config.d.ts +5 -2
  121. package/lib/server/config.js +29 -6
  122. package/lib/server/configValidation.d.ts +5 -3
  123. package/lib/server/configValidation.js +105 -44
  124. package/lib/server/getHostPort.d.ts +14 -0
  125. package/lib/server/getHostPort.js +79 -0
  126. package/lib/server/htmlTags.d.ts +12 -0
  127. package/lib/server/htmlTags.js +62 -0
  128. package/lib/server/i18n.d.ts +3 -13
  129. package/lib/server/i18n.js +21 -55
  130. package/lib/server/index.d.ts +28 -6
  131. package/lib/server/index.js +86 -173
  132. package/lib/server/plugins/configs.d.ts +51 -0
  133. package/lib/server/plugins/configs.js +101 -0
  134. package/lib/server/plugins/index.d.ts +10 -10
  135. package/lib/server/plugins/index.js +76 -128
  136. package/lib/server/plugins/init.d.ts +6 -9
  137. package/lib/server/plugins/init.js +44 -109
  138. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  139. package/lib/server/plugins/moduleShorthand.js +46 -0
  140. package/lib/server/plugins/pluginIds.d.ts +6 -2
  141. package/lib/server/plugins/pluginIds.js +12 -7
  142. package/lib/server/plugins/presets.d.ts +12 -0
  143. package/lib/server/plugins/presets.js +49 -0
  144. package/lib/server/plugins/routeConfig.d.ts +11 -0
  145. package/lib/server/plugins/routeConfig.js +54 -0
  146. package/lib/server/plugins/synthetic.d.ts +20 -0
  147. package/lib/server/plugins/synthetic.js +111 -0
  148. package/lib/server/routes.d.ts +39 -7
  149. package/lib/server/routes.js +182 -95
  150. package/lib/server/siteMetadata.d.ts +12 -0
  151. package/lib/server/siteMetadata.js +81 -0
  152. package/lib/server/translations/translations.d.ts +16 -22
  153. package/lib/server/translations/translations.js +41 -73
  154. package/lib/server/translations/translationsExtractor.d.ts +10 -5
  155. package/lib/server/translations/translationsExtractor.js +158 -122
  156. package/lib/server/utils.d.ts +9 -3
  157. package/lib/server/utils.js +7 -9
  158. package/lib/webpack/aliases/index.d.ts +34 -0
  159. package/lib/webpack/aliases/index.js +106 -0
  160. package/lib/webpack/base.d.ts +3 -4
  161. package/lib/webpack/base.js +56 -58
  162. package/lib/webpack/client.d.ts +3 -3
  163. package/lib/webpack/client.js +12 -19
  164. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  165. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  166. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  167. package/lib/webpack/plugins/CleanWebpackPlugin.js +34 -18
  168. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  169. package/lib/webpack/plugins/LogPlugin.js +4 -5
  170. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  171. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  172. package/lib/webpack/server.d.ts +5 -5
  173. package/lib/webpack/server.js +23 -8
  174. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  175. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  176. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  177. package/lib/webpack/utils.d.ts +16 -31
  178. package/lib/webpack/utils.js +63 -183
  179. package/package.json +83 -77
  180. package/bin/docusaurus.js +0 -326
  181. package/lib/.tsbuildinfo +0 -5682
  182. package/lib/choosePort.js +0 -105
  183. package/lib/client/.eslintrc.js +0 -29
  184. package/lib/client/.tsbuildinfo +0 -4127
  185. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  186. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  187. package/lib/client/nprogress.css +0 -36
  188. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  189. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  190. package/lib/commands/commandUtils.d.ts +0 -3
  191. package/lib/commands/commandUtils.js +0 -21
  192. package/lib/commands/swizzle.d.ts +0 -9
  193. package/lib/commands/swizzle.js +0 -245
  194. package/lib/constants.d.ts +0 -18
  195. package/lib/constants.js +0 -23
  196. package/lib/server/client-modules/index.js +0 -14
  197. package/lib/server/duplicateRoutes.d.ts +0 -10
  198. package/lib/server/duplicateRoutes.js +0 -38
  199. package/lib/server/html-tags/htmlTags.js +0 -39
  200. package/lib/server/html-tags/index.d.ts +0 -9
  201. package/lib/server/html-tags/index.js +0 -43
  202. package/lib/server/loadSetup.d.ts +0 -9
  203. package/lib/server/loadSetup.js +0 -25
  204. package/lib/server/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 -39
  208. package/lib/server/themes/index.d.ts +0 -8
  209. package/lib/server/themes/index.js +0 -35
  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
@@ -6,21 +6,25 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getMinimizer = exports.getHttpsConfig = exports.getFileLoaderUtils = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
9
+ exports.getMinimizer = exports.getHttpsConfig = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
10
10
  const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const utils_1 = require("@docusaurus/utils");
11
16
  const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
12
17
  const webpack_merge_1 = require("webpack-merge");
13
18
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
14
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
15
19
  const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
16
20
  const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
17
- const path_1 = tslib_1.__importDefault(require("path"));
18
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
19
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
20
- const constants_1 = require("../constants");
21
- const lodash_1 = require("lodash");
22
21
  // Utility method to get style loaders
23
- function getStyleLoaders(isServer, cssOptions = {}) {
22
+ function getStyleLoaders(isServer, cssOptionsArg = {}) {
23
+ const cssOptions = {
24
+ // TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
25
+ esModule: false,
26
+ ...cssOptionsArg,
27
+ };
24
28
  if (isServer) {
25
29
  return cssOptions.modules
26
30
  ? [
@@ -66,7 +70,7 @@ function getStyleLoaders(isServer, cssOptions = {}) {
66
70
  // https://github.com/facebook/create-react-app/issues/2677
67
71
  ident: 'postcss',
68
72
  plugins: [
69
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
73
+ // eslint-disable-next-line global-require
70
74
  require('autoprefixer'),
71
75
  ],
72
76
  },
@@ -75,9 +79,9 @@ function getStyleLoaders(isServer, cssOptions = {}) {
75
79
  ];
76
80
  }
77
81
  exports.getStyleLoaders = getStyleLoaders;
78
- function getCustomBabelConfigFilePath(siteDir) {
79
- const customBabelConfigurationPath = path_1.default.join(siteDir, constants_1.BABEL_CONFIG_FILE_NAME);
80
- return fs_extra_1.default.existsSync(customBabelConfigurationPath)
82
+ async function getCustomBabelConfigFilePath(siteDir) {
83
+ const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
84
+ return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
81
85
  ? customBabelConfigurationPath
82
86
  : undefined;
83
87
  }
@@ -90,13 +94,12 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
90
94
  caller: { name: isServer ? 'server' : 'client' },
91
95
  };
92
96
  }
93
- else {
94
- return Object.assign(babelOptions !== null && babelOptions !== void 0 ? babelOptions : { presets: [require.resolve('../babel/preset')] }, {
95
- babelrc: false,
96
- configFile: false,
97
- caller: { name: isServer ? 'server' : 'client' },
98
- });
99
- }
97
+ return {
98
+ ...(babelOptions ?? { presets: [require.resolve('../babel/preset')] }),
99
+ babelrc: false,
100
+ configFile: false,
101
+ caller: { name: isServer ? 'server' : 'client' },
102
+ };
100
103
  }
101
104
  exports.getBabelOptions = getBabelOptions;
102
105
  // Name is generic on purpose
@@ -111,58 +114,36 @@ 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);
148
- 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),
154
- })(config, res);
155
- }
133
+ const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
134
+ const customizeRules = mergeStrategy ?? {};
135
+ return (0, webpack_merge_1.mergeWithCustomize)({
136
+ customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
137
+ customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
138
+ })(config, res);
156
139
  }
157
140
  return config;
158
141
  }
159
142
  exports.applyConfigureWebpack = applyConfigureWebpack;
160
143
  function applyConfigurePostCss(configurePostCss, config) {
161
- var _a, _b;
162
- // TODO not ideal heuristic but good enough for our usecase?
144
+ // Not ideal heuristic but good enough for our use-case?
163
145
  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);
146
+ return !!loader?.options?.postcssOptions;
166
147
  }
167
148
  // Does not handle all edge cases, but good enough for now
168
149
  function overridePostCssOptions(entry) {
@@ -175,42 +156,39 @@ function applyConfigurePostCss(configurePostCss, config) {
175
156
  else if (Array.isArray(entry.use)) {
176
157
  entry.use
177
158
  .filter((u) => typeof u === 'object')
178
- .forEach(overridePostCssOptions);
159
+ .forEach((rule) => overridePostCssOptions(rule));
179
160
  }
180
161
  }
181
- (_b = (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.forEach(overridePostCssOptions);
162
+ config.module?.rules?.forEach((rule) => overridePostCssOptions(rule));
182
163
  return config;
183
164
  }
184
165
  exports.applyConfigurePostCss = applyConfigurePostCss;
185
166
  function compile(config) {
186
167
  return new Promise((resolve, reject) => {
187
- const compiler = webpack_1.default(config);
168
+ const compiler = (0, webpack_1.default)(config);
188
169
  compiler.run((err, stats) => {
189
- var _a;
190
170
  if (err) {
191
- console.error(err.stack || err);
192
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
171
+ logger_1.default.error(err.stack ?? err);
193
172
  if (err.details) {
194
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
195
- console.error(err.details);
173
+ logger_1.default.error(err.details);
196
174
  }
197
175
  reject(err);
198
176
  }
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()) {
177
+ // Let plugins consume all the stats
178
+ const errorsWarnings = stats?.toJson('errors-warnings');
179
+ if (stats?.hasErrors()) {
202
180
  reject(new Error('Failed to compile with errors.'));
203
181
  }
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);
182
+ if (errorsWarnings && stats?.hasWarnings()) {
183
+ errorsWarnings.warnings?.forEach((warning) => {
184
+ logger_1.default.warn(warning);
207
185
  });
208
186
  }
209
187
  // Webpack 5 requires calling close() so that persistent caching works
210
188
  // See https://github.com/webpack/webpack.js.org/pull/4775
211
189
  compiler.close((errClose) => {
212
190
  if (errClose) {
213
- console.error(chalk_1.default.red('Error while closing Webpack compiler', errClose));
191
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
214
192
  reject(errClose);
215
193
  }
216
194
  else {
@@ -221,145 +199,46 @@ function compile(config) {
221
199
  });
222
200
  }
223
201
  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
202
  // Ensure the certificate and key provided are valid and if not
326
203
  // throw an easy to debug error
327
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
204
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
328
205
  let encrypted;
329
206
  try {
330
207
  // publicEncrypt will throw an error with an invalid cert
331
208
  encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
332
209
  }
333
210
  catch (err) {
334
- throw new Error(`The certificate "${chalk_1.default.yellow(crtFile)}" is invalid.\n${err.message}`);
211
+ logger_1.default.error `The certificate path=${crtFile} is invalid.`;
212
+ throw err;
335
213
  }
336
214
  try {
337
215
  // privateDecrypt will throw an error with an invalid key
338
216
  crypto_1.default.privateDecrypt(key, encrypted);
339
217
  }
340
218
  catch (err) {
341
- throw new Error(`The certificate key "${chalk_1.default.yellow(keyFile)}" is invalid.\n${err.message}`);
219
+ logger_1.default.error `The certificate key path=${keyFile} is invalid.`;
220
+ throw err;
342
221
  }
343
222
  }
344
223
  // 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.`);
224
+ async function readEnvFile(file, type) {
225
+ if (!(await fs_extra_1.default.pathExists(file))) {
226
+ throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
348
227
  }
349
- return fs_extra_1.default.readFileSync(file);
228
+ return fs_extra_1.default.readFile(file);
350
229
  }
351
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
352
230
  // Get the https config
353
231
  // Return cert files if provided in env, otherwise just true or false
354
- function getHttpsConfig() {
232
+ async function getHttpsConfig() {
233
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
355
234
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
356
235
  const isHttps = HTTPS === 'true';
357
236
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
358
237
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
359
238
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
360
239
  const config = {
361
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
362
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
240
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
241
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
363
242
  };
364
243
  validateKeyAndCerts({ ...config, keyFile, crtFile });
365
244
  return config;
@@ -385,12 +264,12 @@ function getMinimizer(useSimpleCssMinifier = false) {
385
264
  parallel: getTerserParallel(),
386
265
  terserOptions: {
387
266
  parse: {
388
- // we want uglify-js to parse ecma 8 code. However, we don't want it
267
+ // We want uglify-js to parse ecma 8 code. However, we don't want it
389
268
  // to apply any minification steps that turns valid ecma 5 code
390
269
  // into invalid ecma 5 code. This is why the 'compress' and 'output'
391
270
  // sections only apply transformations that are ecma 5 safe
392
271
  // https://github.com/facebook/create-react-app/pull/4234
393
- ecma: 8,
272
+ ecma: 2020,
394
273
  },
395
274
  compress: {
396
275
  ecma: 5,
@@ -402,8 +281,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
402
281
  output: {
403
282
  ecma: 5,
404
283
  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
284
+ // Turned on because emoji and regex is not minified properly using
285
+ // default. See https://github.com/facebook/create-react-app/issues/2488
407
286
  ascii_only: true,
408
287
  },
409
288
  },
@@ -428,6 +307,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
428
307
  level: {
429
308
  1: {
430
309
  all: false,
310
+ removeWhitespace: true,
431
311
  },
432
312
  2: {
433
313
  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.ff31de0ff",
4
+ "version": "2.0.0-rc.1",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,105 +21,111 @@
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 --build && node ../../admin/scripts/copyUntypedFiles.js",
28
+ "watch": "run-p -c copy:watch build:watch",
29
+ "build:watch": "tsc --build --watch",
30
+ "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
29
31
  },
30
32
  "bugs": {
31
33
  "url": "https://github.com/facebook/docusaurus/issues"
32
34
  },
33
- "devDependencies": {
34
- "@docusaurus/module-type-aliases": "2.0.0-beta.ff31de0ff",
35
- "@types/detect-port": "^1.3.0",
36
- "@types/nprogress": "^0.2.0",
37
- "tmp-promise": "^3.0.2"
38
- },
39
35
  "dependencies": {
40
- "@babel/core": "^7.12.16",
41
- "@babel/generator": "^7.12.15",
36
+ "@babel/core": "^7.18.6",
37
+ "@babel/generator": "^7.18.7",
42
38
  "@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.ff31de0ff",
51
- "@docusaurus/react-loadable": "5.5.0",
52
- "@docusaurus/types": "2.0.0-beta.ff31de0ff",
53
- "@docusaurus/utils": "2.0.0-beta.ff31de0ff",
54
- "@docusaurus/utils-validation": "2.0.0-beta.ff31de0ff",
55
- "@endiliey/static-site-generator-webpack-plugin": "^4.0.0",
56
- "@svgr/webpack": "^5.5.0",
57
- "autoprefixer": "^10.2.5",
58
- "babel-loader": "^8.2.2",
59
- "babel-plugin-dynamic-import-node": "2.3.0",
60
- "boxen": "^5.0.1",
61
- "chalk": "^4.1.1",
62
- "chokidar": "^3.5.1",
63
- "clean-css": "^5.1.2",
39
+ "@babel/plugin-transform-runtime": "^7.18.6",
40
+ "@babel/preset-env": "^7.18.6",
41
+ "@babel/preset-react": "^7.18.6",
42
+ "@babel/preset-typescript": "^7.18.6",
43
+ "@babel/runtime": "^7.18.6",
44
+ "@babel/runtime-corejs3": "^7.18.6",
45
+ "@babel/traverse": "^7.18.8",
46
+ "@docusaurus/cssnano-preset": "2.0.0-rc.1",
47
+ "@docusaurus/logger": "2.0.0-rc.1",
48
+ "@docusaurus/mdx-loader": "2.0.0-rc.1",
49
+ "@docusaurus/react-loadable": "5.5.2",
50
+ "@docusaurus/utils": "2.0.0-rc.1",
51
+ "@docusaurus/utils-common": "2.0.0-rc.1",
52
+ "@docusaurus/utils-validation": "2.0.0-rc.1",
53
+ "@slorber/static-site-generator-webpack-plugin": "^4.0.7",
54
+ "@svgr/webpack": "^6.2.1",
55
+ "autoprefixer": "^10.4.7",
56
+ "babel-loader": "^8.2.5",
57
+ "babel-plugin-dynamic-import-node": "^2.3.3",
58
+ "boxen": "^6.2.1",
59
+ "chalk": "^4.1.2",
60
+ "chokidar": "^3.5.3",
61
+ "clean-css": "^5.3.0",
62
+ "cli-table3": "^0.6.2",
63
+ "combine-promises": "^1.1.0",
64
64
  "commander": "^5.1.0",
65
- "copy-webpack-plugin": "^8.1.1",
66
- "core-js": "^3.9.1",
67
- "css-loader": "^5.1.1",
68
- "css-minimizer-webpack-plugin": "^2.0.0",
69
- "cssnano": "^5.0.4",
70
- "del": "^6.0.0",
65
+ "copy-webpack-plugin": "^11.0.0",
66
+ "core-js": "^3.23.3",
67
+ "css-loader": "^6.7.1",
68
+ "css-minimizer-webpack-plugin": "^4.0.0",
69
+ "cssnano": "^5.1.12",
70
+ "del": "^6.1.1",
71
71
  "detect-port": "^1.3.0",
72
- "eta": "^1.12.1",
73
- "express": "^4.17.1",
72
+ "escape-html": "^1.0.3",
73
+ "eta": "^1.12.3",
74
74
  "file-loader": "^6.2.0",
75
- "fs-extra": "^10.0.0",
76
- "github-slugger": "^1.3.0",
77
- "globby": "^11.0.2",
78
- "html-minifier-terser": "^5.1.1",
79
- "html-tags": "^3.1.0",
80
- "html-webpack-plugin": "^5.3.1",
75
+ "fs-extra": "^10.1.0",
76
+ "html-minifier-terser": "^6.1.0",
77
+ "html-tags": "^3.2.0",
78
+ "html-webpack-plugin": "^5.5.0",
81
79
  "import-fresh": "^3.3.0",
82
- "is-root": "^2.1.0",
83
80
  "leven": "^3.1.0",
84
- "lodash": "^4.17.20",
85
- "mini-css-extract-plugin": "^1.6.0",
86
- "module-alias": "^2.2.2",
87
- "nprogress": "^0.2.0",
88
- "postcss": "^8.2.15",
89
- "postcss-loader": "^5.3.0",
90
- "prompts": "^2.4.1",
91
- "react-dev-utils": "^11.0.1",
92
- "react-error-overlay": "^6.0.9",
93
- "react-helmet": "^6.1.0",
94
- "react-loadable": "^5.5.0",
81
+ "lodash": "^4.17.21",
82
+ "mini-css-extract-plugin": "^2.6.1",
83
+ "postcss": "^8.4.14",
84
+ "postcss-loader": "^7.0.0",
85
+ "prompts": "^2.4.2",
86
+ "react-dev-utils": "^12.0.1",
87
+ "react-helmet-async": "^1.3.0",
88
+ "react-loadable": "npm:@docusaurus/react-loadable@5.5.2",
95
89
  "react-loadable-ssr-addon-v5-slorber": "^1.0.1",
96
- "react-router": "^5.2.0",
90
+ "react-router": "^5.3.3",
97
91
  "react-router-config": "^5.1.1",
98
- "react-router-dom": "^5.2.0",
99
- "resolve-pathname": "^3.0.0",
100
- "rtl-detect": "^1.0.3",
101
- "semver": "^7.3.4",
92
+ "react-router-dom": "^5.3.3",
93
+ "rtl-detect": "^1.0.4",
94
+ "semver": "^7.3.7",
102
95
  "serve-handler": "^6.1.3",
103
- "shelljs": "^0.8.4",
104
- "std-env": "^2.2.1",
105
- "strip-ansi": "^6.0.0",
106
- "terser-webpack-plugin": "^5.1.2",
107
- "tslib": "^2.2.0",
96
+ "shelljs": "^0.8.5",
97
+ "terser-webpack-plugin": "^5.3.3",
98
+ "tslib": "^2.4.0",
108
99
  "update-notifier": "^5.1.0",
109
100
  "url-loader": "^4.1.1",
110
- "wait-on": "^5.3.0",
111
- "webpack": "^5.37.0",
112
- "webpack-bundle-analyzer": "^4.4.2",
113
- "webpack-dev-server": "^3.11.2",
114
- "webpack-merge": "^5.7.3",
115
- "webpackbar": "^5.0.0-3"
101
+ "wait-on": "^6.0.1",
102
+ "webpack": "^5.73.0",
103
+ "webpack-bundle-analyzer": "^4.5.0",
104
+ "webpack-dev-server": "^4.9.3",
105
+ "webpack-merge": "^5.8.0",
106
+ "webpackbar": "^5.0.2"
107
+ },
108
+ "devDependencies": {
109
+ "@docusaurus/module-type-aliases": "2.0.0-rc.1",
110
+ "@docusaurus/types": "2.0.0-rc.1",
111
+ "@types/detect-port": "^1.3.2",
112
+ "@types/react-dom": "^18.0.6",
113
+ "@types/react-router-config": "^5.0.6",
114
+ "@types/rtl-detect": "^1.0.0",
115
+ "@types/serve-handler": "^6.1.1",
116
+ "@types/update-notifier": "^5.1.0",
117
+ "@types/wait-on": "^5.3.1",
118
+ "@types/webpack-bundle-analyzer": "^4.4.1",
119
+ "react-test-renderer": "^17.0.2",
120
+ "tmp-promise": "^3.0.3",
121
+ "tree-node-cli": "^1.5.2"
116
122
  },
117
123
  "peerDependencies": {
118
124
  "react": "^16.8.4 || ^17.0.0",
119
125
  "react-dom": "^16.8.4 || ^17.0.0"
120
126
  },
121
127
  "engines": {
122
- "node": ">=12.13.0"
128
+ "node": ">=16.14"
123
129
  },
124
- "gitHead": "6cacb313da4a21283fe08176097df89df836ee23"
130
+ "gitHead": "c8ddd02a8e68dfaf515c20465a049a83153bd205"
125
131
  }