@docusaurus/core 2.0.0-beta.15 → 2.0.0-beta.16

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 (131) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/{docusaurus.js → docusaurus.mjs} +62 -40
  3. package/lib/babel/preset.d.ts +1 -2
  4. package/lib/babel/preset.js +5 -4
  5. package/lib/choosePort.js +22 -30
  6. package/lib/client/App.d.ts +1 -2
  7. package/lib/client/App.js +13 -8
  8. package/lib/client/LinksCollector.js +1 -1
  9. package/lib/client/PendingNavigation.d.ts +4 -4
  10. package/lib/client/PendingNavigation.js +4 -6
  11. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
  12. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  13. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  14. package/lib/client/client-lifecycles-dispatcher.js +5 -7
  15. package/lib/client/clientEntry.js +11 -5
  16. package/lib/client/docusaurus.js +6 -4
  17. package/lib/client/exports/BrowserOnly.d.ts +1 -2
  18. package/lib/client/exports/BrowserOnly.js +2 -3
  19. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  20. package/lib/client/exports/ComponentCreator.js +7 -6
  21. package/lib/client/exports/ErrorBoundary.d.ts +2 -2
  22. package/lib/client/exports/ErrorBoundary.js +1 -2
  23. package/lib/client/exports/Head.d.ts +2 -3
  24. package/lib/client/exports/Head.js +3 -4
  25. package/lib/client/exports/Interpolate.js +9 -12
  26. package/lib/client/exports/Link.d.ts +11 -5
  27. package/lib/client/exports/Link.js +13 -7
  28. package/lib/client/exports/Translate.js +2 -1
  29. package/lib/client/exports/browserContext.js +3 -2
  30. package/lib/client/exports/docusaurusContext.js +1 -1
  31. package/lib/client/exports/isInternalUrl.js +1 -1
  32. package/lib/client/exports/renderRoutes.d.ts +1 -2
  33. package/lib/client/exports/renderRoutes.js +1 -2
  34. package/lib/client/exports/router.d.ts +1 -1
  35. package/lib/client/exports/router.js +1 -1
  36. package/lib/client/exports/useDocusaurusContext.d.ts +1 -2
  37. package/lib/client/exports/useDocusaurusContext.js +1 -2
  38. package/lib/client/flat.d.ts +1 -2
  39. package/lib/client/flat.js +1 -2
  40. package/lib/client/normalizeLocation.d.ts +2 -3
  41. package/lib/client/normalizeLocation.js +1 -2
  42. package/lib/client/prefetch.d.ts +1 -2
  43. package/lib/client/prefetch.js +1 -2
  44. package/lib/client/preload.d.ts +2 -1
  45. package/lib/client/preload.js +2 -1
  46. package/lib/client/serverEntry.js +23 -19
  47. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  48. package/lib/client/theme-fallback/Error/index.js +21 -29
  49. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  50. package/lib/client/theme-fallback/Layout/index.js +10 -19
  51. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  52. package/lib/client/theme-fallback/Loading/index.js +46 -114
  53. package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
  54. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  55. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  56. package/lib/client/theme-fallback/Root/index.js +2 -5
  57. package/lib/commands/build.js +33 -34
  58. package/lib/commands/clear.js +23 -11
  59. package/lib/commands/deploy.js +12 -11
  60. package/lib/commands/external.d.ts +2 -2
  61. package/lib/commands/external.js +1 -1
  62. package/lib/commands/serve.js +3 -2
  63. package/lib/commands/start.js +4 -4
  64. package/lib/commands/swizzle/actions.d.ts +23 -0
  65. package/lib/commands/swizzle/actions.js +102 -0
  66. package/lib/commands/swizzle/common.d.ts +33 -0
  67. package/lib/commands/swizzle/common.js +57 -0
  68. package/lib/commands/swizzle/components.d.ts +29 -0
  69. package/lib/commands/swizzle/components.js +165 -0
  70. package/lib/commands/swizzle/config.d.ts +10 -0
  71. package/lib/commands/swizzle/config.js +77 -0
  72. package/lib/commands/swizzle/context.d.ts +8 -0
  73. package/lib/commands/swizzle/context.js +30 -0
  74. package/lib/commands/swizzle/index.d.ts +8 -0
  75. package/lib/commands/swizzle/index.js +115 -0
  76. package/lib/commands/swizzle/prompts.d.ts +12 -0
  77. package/lib/commands/swizzle/prompts.js +110 -0
  78. package/lib/commands/swizzle/tables.d.ts +9 -0
  79. package/lib/commands/swizzle/tables.js +116 -0
  80. package/lib/commands/swizzle/themes.d.ts +20 -0
  81. package/lib/commands/swizzle/themes.js +105 -0
  82. package/lib/commands/writeHeadingIds.d.ts +1 -1
  83. package/lib/commands/writeHeadingIds.js +13 -14
  84. package/lib/commands/writeTranslations.js +10 -7
  85. package/lib/index.d.ts +10 -9
  86. package/lib/index.js +20 -19
  87. package/lib/server/brokenLinks.js +30 -20
  88. package/lib/server/config.js +1 -1
  89. package/lib/server/configValidation.d.ts +1 -1
  90. package/lib/server/configValidation.js +32 -23
  91. package/lib/server/duplicateRoutes.js +2 -4
  92. package/lib/server/html-tags/htmlTags.js +1 -2
  93. package/lib/server/i18n.d.ts +0 -1
  94. package/lib/server/i18n.js +16 -26
  95. package/lib/server/index.d.ts +1 -1
  96. package/lib/server/index.js +17 -15
  97. package/lib/server/loadSetup.d.ts +1 -2
  98. package/lib/server/loadSetup.js +2 -2
  99. package/lib/server/moduleShorthand.js +1 -1
  100. package/lib/server/plugins/index.js +9 -9
  101. package/lib/server/plugins/init.d.ts +11 -1
  102. package/lib/server/plugins/init.js +23 -28
  103. package/lib/server/plugins/pluginIds.js +4 -3
  104. package/lib/server/presets/index.d.ts +2 -2
  105. package/lib/server/presets/index.js +3 -3
  106. package/lib/server/routes.js +13 -7
  107. package/lib/server/themes/alias.d.ts +1 -1
  108. package/lib/server/themes/alias.js +5 -6
  109. package/lib/server/themes/index.d.ts +2 -2
  110. package/lib/server/themes/index.js +10 -9
  111. package/lib/server/translations/translations.js +10 -11
  112. package/lib/server/translations/translationsExtractor.js +20 -19
  113. package/lib/server/versions/index.d.ts +2 -3
  114. package/lib/server/versions/index.js +22 -21
  115. package/lib/webpack/base.d.ts +2 -2
  116. package/lib/webpack/base.js +30 -22
  117. package/lib/webpack/client.d.ts +1 -1
  118. package/lib/webpack/client.js +7 -4
  119. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
  120. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  121. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
  122. package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
  123. package/lib/webpack/server.d.ts +1 -1
  124. package/lib/webpack/server.js +6 -5
  125. package/lib/webpack/utils.d.ts +3 -3
  126. package/lib/webpack/utils.js +17 -37
  127. package/package.json +56 -56
  128. package/bin/beforeCli.js +0 -124
  129. package/lib/commands/swizzle.d.ts +0 -9
  130. package/lib/commands/swizzle.js +0 -236
  131. package/lib/server/versions/__tests/index.test.js +0 -26
@@ -14,8 +14,8 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
14
  const utils_1 = require("./utils");
15
15
  const themes_1 = require("../server/themes");
16
16
  const utils_2 = require("@docusaurus/utils");
17
- const CSS_REGEX = /\.css$/;
18
- const CSS_MODULE_REGEX = /\.module\.css$/;
17
+ const CSS_REGEX = /\.css$/i;
18
+ const CSS_MODULE_REGEX = /\.module\.css$/i;
19
19
  exports.clientDir = path_1.default.join(__dirname, '..', 'client');
20
20
  const LibrariesToTranspile = [
21
21
  'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
@@ -28,15 +28,15 @@ function excludeJS(modulePath) {
28
28
  }
29
29
  // Don't transpile node_modules except any docusaurus npm package
30
30
  return (/node_modules/.test(modulePath) &&
31
- !/(docusaurus)((?!node_modules).)*\.jsx?$/.test(modulePath) &&
31
+ !/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
32
32
  !LibrariesToTranspileRegex.test(modulePath));
33
33
  }
34
34
  exports.excludeJS = excludeJS;
35
- function getDocusaurusAliases() {
35
+ async function getDocusaurusAliases() {
36
36
  const dirPath = path_1.default.resolve(__dirname, '../client/exports');
37
37
  const extensions = ['.js', '.ts', '.tsx'];
38
38
  const aliases = {};
39
- fs_extra_1.default.readdirSync(dirPath)
39
+ (await fs_extra_1.default.readdir(dirPath))
40
40
  .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
41
41
  .forEach((fileName) => {
42
42
  const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
@@ -46,7 +46,7 @@ function getDocusaurusAliases() {
46
46
  return aliases;
47
47
  }
48
48
  exports.getDocusaurusAliases = getDocusaurusAliases;
49
- function createBaseConfig(props, isServer, minify = true) {
49
+ async function createBaseConfig(props, isServer, minify = true) {
50
50
  var _a;
51
51
  const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
52
52
  const totalPages = routesPaths.length;
@@ -56,7 +56,7 @@ function createBaseConfig(props, isServer, minify = true) {
56
56
  const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
57
57
  const name = isServer ? 'server' : 'client';
58
58
  const mode = isProd ? 'production' : 'development';
59
- const themeAliases = (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
59
+ const themeAliases = await (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
60
60
  return {
61
61
  mode,
62
62
  name,
@@ -69,16 +69,19 @@ function createBaseConfig(props, isServer, minify = true) {
69
69
  // When version string changes, cache is evicted
70
70
  version: [
71
71
  siteMetadata.docusaurusVersion,
72
- // Webpack does not evict the cache correctly on alias/swizzle change, so we force eviction.
72
+ // Webpack does not evict the cache correctly on alias/swizzle change,
73
+ // so we force eviction.
73
74
  // See https://github.com/webpack/webpack/issues/13627
74
75
  (0, utils_2.md5Hash)(JSON.stringify(themeAliases)),
75
76
  ].join('-'),
76
- // When one of those modules/dependencies change (including transitive deps), cache is invalidated
77
+ // When one of those modules/dependencies change (including transitive
78
+ // deps), cache is invalidated
77
79
  buildDependencies: {
78
80
  config: [
79
81
  __filename,
80
82
  path_1.default.join(__dirname, isServer ? 'server.js' : 'client.js'),
81
- // Docusaurus config changes can affect MDX/JSX compilation, so we'd rather evict the cache.
83
+ // Docusaurus config changes can affect MDX/JSX compilation, so we'd
84
+ // rather evict the cache.
82
85
  // See https://github.com/questdb/questdb.io/issues/493
83
86
  siteConfigPath,
84
87
  ],
@@ -117,17 +120,18 @@ function createBaseConfig(props, isServer, minify = true) {
117
120
  // Note: a @docusaurus alias would also catch @docusaurus/theme-common,
118
121
  // so we use fine-grained aliases instead
119
122
  // '@docusaurus': path.resolve(__dirname, '../client/exports'),
120
- ...getDocusaurusAliases(),
123
+ ...(await getDocusaurusAliases()),
121
124
  ...themeAliases,
122
125
  },
123
- // This allows you to set a fallback for where Webpack should look for modules.
124
- // We want `@docusaurus/core` own dependencies/`node_modules` to "win" if there is conflict
125
- // Example: if there is core-js@3 in user's own node_modules, but core depends on
126
- // core-js@2, we should use core-js@2.
126
+ // This allows you to set a fallback for where Webpack should look for
127
+ // modules. We want `@docusaurus/core` own dependencies/`node_modules` to
128
+ // "win" if there is conflict. Example: if there is core-js@3 in user's
129
+ // own node_modules, but core depends on core-js@2, we should use
130
+ // core-js@2.
127
131
  modules: [
128
132
  path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
129
133
  'node_modules',
130
- path_1.default.resolve(fs_extra_1.default.realpathSync(process.cwd()), 'node_modules'),
134
+ path_1.default.resolve(await fs_extra_1.default.realpath(process.cwd()), 'node_modules'),
131
135
  ],
132
136
  },
133
137
  resolveLoader: {
@@ -135,7 +139,8 @@ function createBaseConfig(props, isServer, minify = true) {
135
139
  },
136
140
  optimization: {
137
141
  removeAvailableModules: false,
138
- // Only minimize client bundle in production because server bundle is only used for static site generation
142
+ // Only minimize client bundle in production because server bundle is only
143
+ // used for static site generation
139
144
  minimize: minimizeEnabled,
140
145
  minimizer: minimizeEnabled
141
146
  ? (0, utils_1.getMinimizer)(useSimpleCssMinifier)
@@ -143,7 +148,9 @@ function createBaseConfig(props, isServer, minify = true) {
143
148
  splitChunks: isServer
144
149
  ? false
145
150
  : {
146
- // Since the chunk name includes all origin chunk names it's recommended for production builds with long term caching to NOT include [name] in the filenames
151
+ // Since the chunk name includes all origin chunk names it's
152
+ // recommended for production builds with long term caching to NOT
153
+ // include [name] in the filenames
147
154
  name: false,
148
155
  cacheGroups: {
149
156
  // disable the built-in cacheGroups
@@ -175,12 +182,12 @@ function createBaseConfig(props, isServer, minify = true) {
175
182
  fileLoaderUtils.rules.svg(),
176
183
  fileLoaderUtils.rules.otherAssets(),
177
184
  {
178
- test: /\.(j|t)sx?$/,
185
+ test: /\.[jt]sx?$/i,
179
186
  exclude: excludeJS,
180
187
  use: [
181
188
  (0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
182
189
  isServer,
183
- babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
190
+ babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
184
191
  }),
185
192
  ],
186
193
  },
@@ -217,8 +224,9 @@ function createBaseConfig(props, isServer, minify = true) {
217
224
  chunkFilename: isProd
218
225
  ? 'assets/css/[name].[contenthash:8].css'
219
226
  : '[name].css',
220
- // remove css order warnings if css imports are not sorted alphabetically
221
- // see https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422 for more reasoning
227
+ // remove css order warnings if css imports are not sorted
228
+ // alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
229
+ // for more reasoning
222
230
  ignoreOrder: true,
223
231
  }),
224
232
  ],
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import type { Configuration } from 'webpack';
8
8
  import type { Props } from '@docusaurus/types';
9
- export default function createClientConfig(props: Props, minify?: boolean): Configuration;
9
+ export default function createClientConfig(props: Props, minify?: boolean): Promise<Configuration>;
@@ -13,12 +13,14 @@ const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
13
13
  const base_1 = require("./base");
14
14
  const ChunkAssetPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/ChunkAssetPlugin"));
15
15
  const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
16
- function createClientConfig(props, minify = true) {
16
+ async function createClientConfig(props, minify = true) {
17
17
  var _a;
18
18
  const isBuilding = process.argv[2] === 'build';
19
- const config = (0, base_1.createBaseConfig)(props, false, minify);
19
+ const config = await (0, base_1.createBaseConfig)(props, false, minify);
20
20
  const clientConfig = (0, webpack_merge_1.default)(config, {
21
- // target: 'browserslist', // useless, disabled on purpose (errors on existing sites with no browserslist cfg)
21
+ // useless, disabled on purpose (errors on existing sites with no
22
+ // browserslist config)
23
+ // target: 'browserslist',
22
24
  entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
23
25
  optimization: {
24
26
  // Keep the runtime chunk separated to enable long term caching
@@ -33,7 +35,8 @@ function createClientConfig(props, minify = true) {
33
35
  }),
34
36
  ],
35
37
  });
36
- // When building include the plugin to force terminate building if errors happened in the client bundle.
38
+ // When building, include the plugin to force terminate building if errors
39
+ // happened in the client bundle.
37
40
  if (isBuilding) {
38
41
  (_a = clientConfig.plugins) === null || _a === void 0 ? void 0 : _a.push({
39
42
  apply: (compiler) => {
@@ -5,7 +5,17 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type Compiler } from 'webpack';
8
- declare class ChunkAssetPlugin {
8
+ /**
9
+ * We modify webpack runtime to add an extra function called
10
+ * "__webpack_require__.gca" that will allow us to get the corresponding chunk
11
+ * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
12
+ * For example: if you have a chunk named "my-chunk-name" that will map to
13
+ * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
14
+ * __webpack_require__.gca("my-chunk-name") will return
15
+ * "/publicPath/0a84b5e7.c8e35c7a.js"
16
+ *
17
+ * "gca" stands for "get chunk asset"
18
+ */
19
+ export default class ChunkAssetPlugin {
9
20
  apply(compiler: Compiler): void;
10
21
  }
11
- export default ChunkAssetPlugin;
@@ -8,16 +8,20 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const webpack_1 = require("webpack");
10
10
  const pluginName = 'chunk-asset-plugin';
11
+ /**
12
+ * We modify webpack runtime to add an extra function called
13
+ * "__webpack_require__.gca" that will allow us to get the corresponding chunk
14
+ * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
15
+ * For example: if you have a chunk named "my-chunk-name" that will map to
16
+ * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
17
+ * __webpack_require__.gca("my-chunk-name") will return
18
+ * "/publicPath/0a84b5e7.c8e35c7a.js"
19
+ *
20
+ * "gca" stands for "get chunk asset"
21
+ */
11
22
  class ChunkAssetPlugin {
12
23
  apply(compiler) {
13
24
  compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
14
- /* We modify webpack runtime to add an extra function called "__webpack_require__.gca"
15
- that will allow us to get the corresponding chunk asset for a webpack chunk.
16
- Pass it the chunkName or chunkId you want to load.
17
- For example: if you have a chunk named "my-chunk-name" that will map to "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
18
- __webpack_require__.gca("my-chunk-name") will return "/publicPath/0a84b5e7.c8e35c7a.js"
19
- "gca" stands for "get chunk asset"
20
- */
21
25
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
22
26
  const chunkIdToName = chunk.getChunkMaps(false).name;
23
27
  const chunkNameToId = Object.create(null);
@@ -30,10 +34,13 @@ class ChunkAssetPlugin {
30
34
  buf.push(
31
35
  // If chunkName is passed, we convert it to chunk asset url
32
36
  // .p => public path url ("/" or "/baseUrl/")
33
- // .u(chunkId) => chunk asset url ("assets/js/x63b64xd.contentHash.js")
34
- // not sure where this is documented, but this link was helpful: https://programmer.help/blogs/5d68849083e1a.html
37
+ // .u(chunkId) =>
38
+ // chunk asset url ("assets/js/x63b64xd.contentHash.js")
39
+ // not sure where this is documented, but this link was helpful:
40
+ // https://programmer.help/blogs/5d68849083e1a.html
35
41
  //
36
- // Note: __webpack_require__.gca() is called in docusaurus.ts for prefetching
42
+ // Note: __webpack_require__.gca() is called in docusaurus.ts for
43
+ // prefetching
37
44
  // Note: we previously used jsonpScriptSrc (Webpack 4)
38
45
  `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
39
46
  return webpack_1.Template.asString(buf);
@@ -13,8 +13,8 @@
13
13
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
14
  * copies of the Software, and to permit persons to whom the Software is
15
15
  * furnished to do so, subject to the following conditions:
16
- * The above copyright notice and this permission notice shall be included in all
17
- * copies or substantial portions of the Software.
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
18
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
19
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
20
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -54,7 +54,7 @@ export interface Options {
54
54
  */
55
55
  cleanOnceBeforeBuildPatterns?: string[];
56
56
  }
57
- declare class CleanWebpackPlugin {
57
+ export default class CleanWebpackPlugin {
58
58
  private readonly verbose;
59
59
  private readonly cleanStaleWebpackAssets;
60
60
  private readonly protectWebpackAssets;
@@ -69,10 +69,10 @@ declare class CleanWebpackPlugin {
69
69
  *
70
70
  * Only happens once.
71
71
  *
72
- * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.
72
+ * Warning: It is recommended to initially clean your build directory outside
73
+ * of webpack to minimize unexpected behavior.
73
74
  */
74
75
  handleInitial(): void;
75
76
  handleDone(stats: Stats): void;
76
77
  removeFiles(patterns: string[]): void;
77
78
  }
78
- export default CleanWebpackPlugin;
@@ -60,7 +60,8 @@ class CleanWebpackPlugin {
60
60
  *
61
61
  * Only happens once.
62
62
  *
63
- * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.
63
+ * Warning: It is recommended to initially clean your build directory outside
64
+ * of webpack to minimize unexpected behavior.
64
65
  */
65
66
  handleInitial() {
66
67
  if (this.initialClean) {
@@ -133,13 +134,13 @@ class CleanWebpackPlugin {
133
134
  });
134
135
  }
135
136
  }
136
- catch (error) {
137
- const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(error.message);
137
+ catch (err) {
138
+ const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(err.message);
138
139
  if (needsForce) {
139
140
  const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
140
141
  throw new Error(message);
141
142
  }
142
- throw error;
143
+ throw err;
143
144
  }
144
145
  }
145
146
  }
@@ -9,4 +9,4 @@ import type { Props } from '@docusaurus/types';
9
9
  export default function createServerConfig({ props, onLinksCollected, }: {
10
10
  props: Props;
11
11
  onLinksCollected?: (staticPagePath: string, links: string[]) => void;
12
- }): Configuration;
12
+ }): Promise<Configuration>;
@@ -15,9 +15,9 @@ const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"))
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  // Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
17
17
  const static_site_generator_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("@slorber/static-site-generator-webpack-plugin"));
18
- function createServerConfig({ props, onLinksCollected = () => { }, }) {
18
+ async function createServerConfig({ props, onLinksCollected = () => { }, }) {
19
19
  const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
20
- const config = (0, base_1.createBaseConfig)(props, true);
20
+ const config = await (0, base_1.createBaseConfig)(props, true);
21
21
  const routesLocation = {};
22
22
  // Array of paths to be rendered. Relative to output directory
23
23
  const ssgPaths = routesPaths.map((str) => {
@@ -57,9 +57,10 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
57
57
  },
58
58
  paths: ssgPaths,
59
59
  preferFoldersOutput: trailingSlash,
60
- // When using "new URL('file.js', import.meta.url)", Webpack will emit __filename, and this plugin will throw
61
- // not sure the __filename value has any importance for this plugin, just using an empty string to avoid the error
62
- // See https://github.com/facebook/docusaurus/issues/4922
60
+ // When using "new URL('file.js', import.meta.url)", Webpack will emit
61
+ // __filename, and this plugin will throw. not sure the __filename value
62
+ // has any importance for this plugin, just using an empty string to
63
+ // avoid the error. See https://github.com/facebook/docusaurus/issues/4922
63
64
  globals: { __filename: '' },
64
65
  }),
65
66
  // Show compilation progress bar.
@@ -11,7 +11,7 @@ import type { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
11
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,8 +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
- export declare function getHttpsConfig(): boolean | {
35
+ export declare function getHttpsConfig(): Promise<boolean | {
36
36
  cert: Buffer;
37
37
  key: Buffer;
38
- };
38
+ }>;
39
39
  export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
@@ -18,7 +18,6 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
18
18
  const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
19
19
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
20
20
  const utils_1 = require("@docusaurus/utils");
21
- const lodash_1 = require("lodash");
22
21
  // Utility method to get style loaders
23
22
  function getStyleLoaders(isServer, cssOptionsArg = {}) {
24
23
  const cssOptions = {
@@ -80,9 +79,9 @@ function getStyleLoaders(isServer, cssOptionsArg = {}) {
80
79
  ];
81
80
  }
82
81
  exports.getStyleLoaders = getStyleLoaders;
83
- function getCustomBabelConfigFilePath(siteDir) {
82
+ async function getCustomBabelConfigFilePath(siteDir) {
84
83
  const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
85
- return fs_extra_1.default.existsSync(customBabelConfigurationPath)
84
+ return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
86
85
  ? customBabelConfigurationPath
87
86
  : undefined;
88
87
  }
@@ -95,13 +94,12 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
95
94
  caller: { name: isServer ? 'server' : 'client' },
96
95
  };
97
96
  }
98
- else {
99
- return Object.assign(babelOptions !== null && babelOptions !== void 0 ? babelOptions : { presets: [require.resolve('../babel/preset')] }, {
100
- babelrc: false,
101
- configFile: false,
102
- caller: { name: isServer ? 'server' : 'client' },
103
- });
104
- }
97
+ return {
98
+ ...(babelOptions !== null && babelOptions !== void 0 ? babelOptions : { presets: [require.resolve('../babel/preset')] }),
99
+ babelrc: false,
100
+ configFile: false,
101
+ caller: { name: isServer ? 'server' : 'client' },
102
+ };
105
103
  }
106
104
  exports.getBabelOptions = getBabelOptions;
107
105
  // Name is generic on purpose
@@ -116,22 +114,6 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
116
114
  ? getDefaultBabelLoader({ isServer, babelOptions })
117
115
  : jsLoader(isServer);
118
116
  exports.getCustomizableJSLoader = getCustomizableJSLoader;
119
- // TODO remove this before end of 2021?
120
- const warnBabelLoaderOnce = (0, lodash_1.memoize)(() => {
121
- logger_1.default.warn `Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): code=${'getBabelLoader(isServer)'} is now deprecated in favor of code=${'getJSLoader(isServer)'}.`;
122
- });
123
- const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
124
- warnBabelLoaderOnce();
125
- return getDefaultBabelLoader({ isServer, babelOptions });
126
- };
127
- // TODO remove this before end of 2021 ?
128
- const warnCacheLoaderOnce = (0, lodash_1.memoize)(() => {
129
- logger_1.default.warn `Docusaurus uses Webpack 5 and code=${'getCacheLoader()'} usage is now deprecated.`;
130
- });
131
- function getCacheLoaderDeprecated() {
132
- warnCacheLoaderOnce();
133
- return null;
134
- }
135
117
  /**
136
118
  * Helper function to modify webpack config
137
119
  * @param configureWebpack a webpack config or a function to modify config
@@ -146,8 +128,6 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
146
128
  const utils = {
147
129
  getStyleLoaders,
148
130
  getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
149
- getBabelLoader: getBabelLoaderDeprecated,
150
- getCacheLoader: getCacheLoaderDeprecated,
151
131
  };
152
132
  if (typeof configureWebpack === 'function') {
153
133
  const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
@@ -248,24 +228,24 @@ ${err}`);
248
228
  }
249
229
  }
250
230
  // Read file and throw an error if it doesn't exist
251
- function readEnvFile(file, type) {
252
- if (!fs_extra_1.default.existsSync(file)) {
231
+ async function readEnvFile(file, type) {
232
+ if (!(await fs_extra_1.default.pathExists(file))) {
253
233
  throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
254
234
  }
255
- return fs_extra_1.default.readFileSync(file);
235
+ return fs_extra_1.default.readFile(file);
256
236
  }
257
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
258
237
  // Get the https config
259
238
  // Return cert files if provided in env, otherwise just true or false
260
- function getHttpsConfig() {
239
+ async function getHttpsConfig() {
240
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
261
241
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
262
242
  const isHttps = HTTPS === 'true';
263
243
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
264
244
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
265
245
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
266
246
  const config = {
267
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
268
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
247
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
248
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
269
249
  };
270
250
  validateKeyAndCerts({ ...config, keyFile, crtFile });
271
251
  return config;
@@ -308,8 +288,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
308
288
  output: {
309
289
  ecma: 5,
310
290
  comments: false,
311
- // Turned on because emoji and regex is not minified properly using default
312
- // https://github.com/facebook/create-react-app/issues/2488
291
+ // Turned on because emoji and regex is not minified properly using
292
+ // default. See https://github.com/facebook/create-react-app/issues/2488
313
293
  ascii_only: true,
314
294
  },
315
295
  },