@docusaurus/core 2.0.0-beta.12faed89d → 2.0.0-beta.13

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 (111) hide show
  1. package/bin/beforeCli.js +33 -8
  2. package/bin/docusaurus.js +36 -40
  3. package/lib/.tsbuildinfo +1 -1
  4. package/lib/babel/preset.d.ts +6 -0
  5. package/lib/babel/preset.js +3 -3
  6. package/lib/choosePort.js +12 -13
  7. package/lib/client/.eslintrc.js +0 -1
  8. package/lib/client/.tsbuildinfo +1 -1
  9. package/lib/client/App.js +12 -22
  10. package/lib/client/LinksCollector.d.ts +2 -2
  11. package/lib/client/LinksCollector.js +4 -8
  12. package/lib/client/PendingNavigation.d.ts +24 -1
  13. package/lib/client/PendingNavigation.js +1 -1
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
  16. package/lib/client/client-lifecycles-dispatcher.js +0 -2
  17. package/lib/client/docusaurus.d.ts +6 -0
  18. package/lib/client/docusaurus.js +11 -19
  19. package/lib/client/exports/BrowserOnly.js +5 -3
  20. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  21. package/lib/client/exports/ErrorBoundary.js +35 -0
  22. package/lib/client/exports/Interpolate.js +12 -15
  23. package/lib/client/exports/Link.js +9 -9
  24. package/lib/client/exports/Translate.d.ts +2 -2
  25. package/lib/client/exports/Translate.js +13 -9
  26. package/lib/client/exports/browserContext.d.ts +11 -0
  27. package/lib/client/exports/browserContext.js +21 -0
  28. package/lib/client/exports/constants.js +1 -11
  29. package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
  30. package/lib/client/exports/docusaurusContext.js +25 -0
  31. package/lib/client/exports/useBaseUrl.js +2 -4
  32. package/lib/client/exports/useDocusaurusContext.js +2 -7
  33. package/lib/client/exports/useGlobalData.js +1 -5
  34. package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
  35. package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
  36. package/lib/client/flat.d.ts +2 -1
  37. package/lib/client/flat.js +7 -9
  38. package/lib/client/normalizeLocation.d.ts +1 -3
  39. package/lib/client/prefetch.js +0 -1
  40. package/lib/client/serverEntry.js +15 -31
  41. package/lib/client/theme-fallback/Error/index.js +47 -0
  42. package/lib/client/theme-fallback/Layout/index.js +1 -1
  43. package/lib/client/theme-fallback/Loading/index.js +2 -2
  44. package/lib/client/theme-fallback/Root/index.js +1 -3
  45. package/lib/commands/build.js +34 -37
  46. package/lib/commands/clear.d.ts +6 -0
  47. package/lib/commands/clear.js +9 -9
  48. package/lib/commands/commandUtils.d.ts +6 -0
  49. package/lib/commands/commandUtils.js +7 -7
  50. package/lib/commands/deploy.d.ts +3 -0
  51. package/lib/commands/deploy.js +90 -53
  52. package/lib/commands/external.js +4 -4
  53. package/lib/commands/serve.js +13 -13
  54. package/lib/commands/start.js +82 -72
  55. package/lib/commands/swizzle.js +34 -34
  56. package/lib/commands/writeHeadingIds.d.ts +9 -6
  57. package/lib/commands/writeHeadingIds.js +32 -32
  58. package/lib/commands/writeTranslations.js +31 -11
  59. package/lib/server/brokenLinks.js +13 -17
  60. package/lib/server/client-modules/index.js +1 -3
  61. package/lib/server/config.js +4 -4
  62. package/lib/server/configValidation.d.ts +1 -1
  63. package/lib/server/configValidation.js +11 -6
  64. package/lib/server/duplicateRoutes.js +8 -2
  65. package/lib/server/html-tags/htmlTags.js +5 -6
  66. package/lib/server/html-tags/index.js +2 -2
  67. package/lib/server/i18n.js +16 -13
  68. package/lib/server/index.js +128 -58
  69. package/lib/server/loadSetup.js +3 -3
  70. package/lib/server/moduleShorthand.d.ts +9 -0
  71. package/lib/server/moduleShorthand.js +42 -0
  72. package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
  73. package/lib/server/plugins/index.d.ts +1 -1
  74. package/lib/server/plugins/index.js +24 -20
  75. package/lib/server/plugins/init.js +9 -12
  76. package/lib/server/plugins/pluginIds.js +6 -4
  77. package/lib/server/presets/index.js +12 -12
  78. package/lib/server/routes.js +9 -11
  79. package/lib/server/themes/alias.d.ts +1 -0
  80. package/lib/server/themes/alias.js +21 -12
  81. package/lib/server/themes/index.d.ts +1 -1
  82. package/lib/server/themes/index.js +22 -23
  83. package/lib/server/translations/translations.d.ts +6 -0
  84. package/lib/server/translations/translations.js +15 -17
  85. package/lib/server/translations/translationsExtractor.d.ts +7 -1
  86. package/lib/server/translations/translationsExtractor.js +65 -56
  87. package/lib/server/utils.d.ts +8 -2
  88. package/lib/server/utils.js +8 -10
  89. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  90. package/lib/server/versions/__tests/index.test.js +5 -5
  91. package/lib/server/versions/index.js +6 -6
  92. package/lib/webpack/base.js +14 -16
  93. package/lib/webpack/client.js +8 -17
  94. package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
  95. package/lib/webpack/plugins/LogPlugin.js +5 -6
  96. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  97. package/lib/webpack/server.js +9 -9
  98. package/lib/webpack/utils.d.ts +0 -22
  99. package/lib/webpack/utils.js +26 -125
  100. package/package.json +55 -50
  101. package/tsconfig.client.json +1 -2
  102. package/tsconfig.json +5 -4
  103. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  104. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  105. package/lib/constants.d.ts +0 -18
  106. package/lib/constants.js +0 -23
  107. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  108. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  109. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  110. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  111. package/lib/webpack/sharedModuleAliases.js +0 -18
@@ -10,7 +10,7 @@ exports.getPluginVersion = exports.getPackageJsonName = exports.getPackageJsonVe
10
10
  const fs_extra_1 = require("fs-extra");
11
11
  const path_1 = require("path");
12
12
  function getPackageJsonVersion(packageJsonPath) {
13
- if (fs_extra_1.existsSync(packageJsonPath)) {
13
+ if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
14
14
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
15
15
  const { version } = require(packageJsonPath);
16
16
  return typeof version === 'string' ? version : undefined;
@@ -19,7 +19,7 @@ function getPackageJsonVersion(packageJsonPath) {
19
19
  }
20
20
  exports.getPackageJsonVersion = getPackageJsonVersion;
21
21
  function getPackageJsonName(packageJsonPath) {
22
- if (fs_extra_1.existsSync(packageJsonPath)) {
22
+ if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
23
23
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
24
24
  const { name } = require(packageJsonPath);
25
25
  return typeof name === 'string' ? name : undefined;
@@ -28,10 +28,10 @@ function getPackageJsonName(packageJsonPath) {
28
28
  }
29
29
  exports.getPackageJsonName = getPackageJsonName;
30
30
  function getPluginVersion(pluginPath, siteDir) {
31
- let potentialPluginPackageJsonDirectory = path_1.dirname(pluginPath);
31
+ let potentialPluginPackageJsonDirectory = (0, path_1.dirname)(pluginPath);
32
32
  while (potentialPluginPackageJsonDirectory !== '/') {
33
- const packageJsonPath = path_1.join(potentialPluginPackageJsonDirectory, 'package.json');
34
- if (fs_extra_1.existsSync(packageJsonPath) && fs_extra_1.lstatSync(packageJsonPath).isFile()) {
33
+ const packageJsonPath = (0, path_1.join)(potentialPluginPackageJsonDirectory, 'package.json');
34
+ if ((0, fs_extra_1.existsSync)(packageJsonPath) && (0, fs_extra_1.lstatSync)(packageJsonPath).isFile()) {
35
35
  if (potentialPluginPackageJsonDirectory === siteDir) {
36
36
  // If the plugin belongs to the same docusaurus project, we classify it as local plugin.
37
37
  return { type: 'project' };
@@ -42,7 +42,7 @@ function getPluginVersion(pluginPath, siteDir) {
42
42
  version: getPackageJsonVersion(packageJsonPath),
43
43
  };
44
44
  }
45
- potentialPluginPackageJsonDirectory = path_1.dirname(potentialPluginPackageJsonDirectory);
45
+ potentialPluginPackageJsonDirectory = (0, path_1.dirname)(potentialPluginPackageJsonDirectory);
46
46
  }
47
47
  // In rare cases where a plugin is a path where no parent directory contains package.json, we can only classify it as local.
48
48
  return { type: 'local' };
@@ -8,12 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createBaseConfig = exports.getDocusaurusAliases = exports.excludeJS = exports.clientDir = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
13
- const path_1 = tslib_1.__importDefault(require("path"));
11
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
+ const mini_css_extract_plugin_1 = (0, tslib_1.__importDefault)(require("mini-css-extract-plugin"));
13
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
14
  const utils_1 = require("./utils");
15
- const constants_1 = require("../constants");
16
- const sharedModuleAliases_1 = tslib_1.__importDefault(require("./sharedModuleAliases"));
17
15
  const themes_1 = require("../server/themes");
18
16
  const utils_2 = require("@docusaurus/utils");
19
17
  const CSS_REGEX = /\.css$/;
@@ -55,10 +53,10 @@ function createBaseConfig(props, isServer, minify = true) {
55
53
  const isProd = process.env.NODE_ENV === 'production';
56
54
  const minimizeEnabled = minify && isProd && !isServer;
57
55
  const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
58
- const fileLoaderUtils = utils_1.getFileLoaderUtils();
56
+ const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
59
57
  const name = isServer ? 'server' : 'client';
60
58
  const mode = isProd ? 'production' : 'development';
61
- const themeAliases = themes_1.loadPluginsThemeAliases({ siteDir, plugins });
59
+ const themeAliases = (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
62
60
  return {
63
61
  mode,
64
62
  name,
@@ -73,7 +71,7 @@ function createBaseConfig(props, isServer, minify = true) {
73
71
  siteMetadata.docusaurusVersion,
74
72
  // Webpack does not evict the cache correctly on alias/swizzle change, so we force eviction.
75
73
  // See https://github.com/webpack/webpack/issues/13627
76
- utils_2.md5Hash(JSON.stringify(themeAliases)),
74
+ (0, utils_2.md5Hash)(JSON.stringify(themeAliases)),
77
75
  ].join('-'),
78
76
  // When one of those modules/dependencies change (including transitive deps), cache is invalidated
79
77
  buildDependencies: {
@@ -94,6 +92,7 @@ function createBaseConfig(props, isServer, minify = true) {
94
92
  ? 'assets/js/[name].[contenthash:8].js'
95
93
  : '[name].js',
96
94
  publicPath: baseUrl,
95
+ hashFunction: 'xxhash64',
97
96
  },
98
97
  // Don't throw warning when asset created is over 250kb
99
98
  performance: {
@@ -103,17 +102,16 @@ function createBaseConfig(props, isServer, minify = true) {
103
102
  resolve: {
104
103
  unsafeCache: false,
105
104
  extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
106
- symlinks: false,
105
+ symlinks: true,
107
106
  roots: [
108
107
  // Allow resolution of url("/fonts/xyz.ttf") by webpack
109
108
  // See https://webpack.js.org/configuration/resolve/#resolveroots
110
109
  // See https://github.com/webpack-contrib/css-loader/issues/1256
111
- path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
110
+ ...siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
112
111
  siteDir,
113
112
  process.cwd(),
114
113
  ],
115
114
  alias: {
116
- ...sharedModuleAliases_1.default,
117
115
  '@site': siteDir,
118
116
  '@generated': generatedFilesDir,
119
117
  // Note: a @docusaurus alias would also catch @docusaurus/theme-common,
@@ -140,7 +138,7 @@ function createBaseConfig(props, isServer, minify = true) {
140
138
  // Only minimize client bundle in production because server bundle is only used for static site generation
141
139
  minimize: minimizeEnabled,
142
140
  minimizer: minimizeEnabled
143
- ? utils_1.getMinimizer(useSimpleCssMinifier)
141
+ ? (0, utils_1.getMinimizer)(useSimpleCssMinifier)
144
142
  : undefined,
145
143
  splitChunks: isServer
146
144
  ? false
@@ -180,16 +178,16 @@ function createBaseConfig(props, isServer, minify = true) {
180
178
  test: /\.(j|t)sx?$/,
181
179
  exclude: excludeJS,
182
180
  use: [
183
- utils_1.getCustomizableJSLoader((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
181
+ (0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
184
182
  isServer,
185
- babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
183
+ babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
186
184
  }),
187
185
  ],
188
186
  },
189
187
  {
190
188
  test: CSS_REGEX,
191
189
  exclude: CSS_MODULE_REGEX,
192
- use: utils_1.getStyleLoaders(isServer, {
190
+ use: (0, utils_1.getStyleLoaders)(isServer, {
193
191
  importLoaders: 1,
194
192
  sourceMap: !isProd,
195
193
  }),
@@ -198,7 +196,7 @@ function createBaseConfig(props, isServer, minify = true) {
198
196
  // using the extension .module.css
199
197
  {
200
198
  test: CSS_MODULE_REGEX,
201
- use: utils_1.getStyleLoaders(isServer, {
199
+ use: (0, utils_1.getStyleLoaders)(isServer, {
202
200
  modules: {
203
201
  localIdentName: isProd
204
202
  ? `[local]_[contenthash:base64:4]`
@@ -7,28 +7,19 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
10
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
11
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
+ const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
13
13
  const base_1 = require("./base");
14
- const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
15
- const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
14
+ const ChunkAssetPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/ChunkAssetPlugin"));
15
+ const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
16
16
  function createClientConfig(props, minify = true) {
17
17
  var _a;
18
- const isProd = process.env.NODE_ENV === 'production';
19
18
  const isBuilding = process.argv[2] === 'build';
20
- const config = base_1.createBaseConfig(props, false, minify);
21
- const clientConfig = webpack_merge_1.default(config, {
19
+ const config = (0, base_1.createBaseConfig)(props, false, minify);
20
+ const clientConfig = (0, webpack_merge_1.default)(config, {
22
21
  // target: 'browserslist', // useless, disabled on purpose (errors on existing sites with no browserslist cfg)
23
- entry: [
24
- // Instead of the default WebpackDevServer client, we use a custom one
25
- // like CRA to bring better experience.
26
- // note: the one in ./dev is modified to work with Docusaurus
27
- // !isProd && require.resolve('react-dev-utils/hotDevServer.js'),
28
- !isProd &&
29
- require.resolve('./react-dev-utils-webpack5/webpackHotDevClient.js'),
30
- path_1.default.resolve(__dirname, '../client/clientEntry.js'),
31
- ].filter(Boolean),
22
+ entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
32
23
  optimization: {
33
24
  // Keep the runtime chunk separated to enable long term caching
34
25
  // https://twitter.com/wSokra/status/969679223278505985
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
10
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
11
  const del_1 = require("del");
12
12
  class CleanWebpackPlugin {
13
13
  constructor(options = {}) {
@@ -41,7 +41,6 @@ class CleanWebpackPlugin {
41
41
  }
42
42
  apply(compiler) {
43
43
  if (!compiler.options.output || !compiler.options.output.path) {
44
- // eslint-disable-next-line no-console
45
44
  console.warn('clean-webpack-plugin: options.output.path not defined. Plugin disabled...');
46
45
  return;
47
46
  }
@@ -76,7 +75,6 @@ class CleanWebpackPlugin {
76
75
  */
77
76
  if (stats.hasErrors()) {
78
77
  if (this.verbose) {
79
- // eslint-disable-next-line no-console
80
78
  console.warn('clean-webpack-plugin: pausing due to webpack errors');
81
79
  }
82
80
  return;
@@ -88,17 +86,13 @@ class CleanWebpackPlugin {
88
86
  all: false,
89
87
  assets: true,
90
88
  }).assets || [];
91
- const assets = statsAssets.map((asset) => {
92
- return asset.name;
93
- });
89
+ const assets = statsAssets.map((asset) => asset.name);
94
90
  /**
95
91
  * Get all files that were in the previous build but not the current
96
92
  *
97
93
  * (relies on del's cwd: outputPath option)
98
94
  */
99
- const staleFiles = this.currentAssets.filter((previousAsset) => {
100
- return assets.includes(previousAsset) === false;
101
- });
95
+ const staleFiles = this.currentAssets.filter((previousAsset) => assets.includes(previousAsset) === false);
102
96
  /**
103
97
  * Save assets for next compilation
104
98
  */
@@ -116,7 +110,7 @@ class CleanWebpackPlugin {
116
110
  }
117
111
  removeFiles(patterns) {
118
112
  try {
119
- const deleted = del_1.sync(patterns, {
113
+ const deleted = (0, del_1.sync)(patterns, {
120
114
  force: false,
121
115
  // Change context to build directory
122
116
  cwd: this.outputPath,
@@ -135,7 +129,6 @@ class CleanWebpackPlugin {
135
129
  * https://github.com/webpack/webpack/issues/1904
136
130
  * https://github.com/johnagan/clean-webpack-plugin/issues/11
137
131
  */
138
- // eslint-disable-next-line no-console
139
132
  console.warn(`clean-webpack-plugin: removed ${filename}`);
140
133
  });
141
134
  }
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
2
  /**
5
3
  * Copyright (c) Facebook, Inc. and its affiliates.
6
4
  *
7
5
  * This source code is licensed under the MIT license found in the
8
6
  * LICENSE file in the root directory of this source tree.
9
7
  */
10
- const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
11
- // import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages';
12
- const formatWebpackMessages_1 = tslib_1.__importDefault(require("../react-dev-utils-webpack5/formatWebpackMessages"));
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const tslib_1 = require("tslib");
10
+ const webpackbar_1 = (0, tslib_1.__importDefault)(require("webpackbar"));
11
+ const formatWebpackMessages_1 = (0, tslib_1.__importDefault)(require("react-dev-utils/formatWebpackMessages"));
13
12
  function showError(arr) {
14
13
  console.log(`\n\n${arr.join('\n')}`);
15
14
  }
@@ -23,7 +22,7 @@ class LogPlugin extends webpackbar_1.default {
23
22
  // TODO do we really want to keep this legacy logic?
24
23
  // let's wait and see how the react-dev-utils support Webpack5
25
24
  // we probably want to print the error stacktraces here
26
- const messages = formatWebpackMessages_1.default(errorsWarnings);
25
+ const messages = (0, formatWebpackMessages_1.default)(errorsWarnings);
27
26
  if (messages.errors.length) {
28
27
  showError(messages.errors);
29
28
  }
@@ -7,9 +7,9 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const wait_on_1 = tslib_1.__importDefault(require("wait-on"));
10
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
+ const wait_on_1 = (0, tslib_1.__importDefault)(require("wait-on"));
13
13
  class WaitPlugin {
14
14
  constructor(options) {
15
15
  this.filepath = options.filepath;
@@ -20,7 +20,7 @@ class WaitPlugin {
20
20
  // To prevent 'waitFile' error on waiting non-existing directory
21
21
  fs_extra_1.default.ensureDir(path_1.default.dirname(this.filepath), {}, () => {
22
22
  // Wait until file exist
23
- wait_on_1.default({
23
+ (0, wait_on_1.default)({
24
24
  resources: [this.filepath],
25
25
  interval: 300,
26
26
  })
@@ -7,17 +7,17 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
11
- const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
10
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
12
12
  const base_1 = require("./base");
13
- const WaitPlugin_1 = tslib_1.__importDefault(require("./plugins/WaitPlugin"));
14
- const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
15
- const constants_1 = require("../constants");
13
+ const WaitPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/WaitPlugin"));
14
+ const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
15
+ const utils_1 = require("@docusaurus/utils");
16
16
  // Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
17
- const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
17
+ const static_site_generator_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("@slorber/static-site-generator-webpack-plugin"));
18
18
  function createServerConfig({ props, onLinksCollected = () => { }, }) {
19
19
  const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
20
- const config = base_1.createBaseConfig(props, true);
20
+ const config = (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) => {
@@ -25,8 +25,8 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
25
25
  routesLocation[ssgPath] = str;
26
26
  return ssgPath;
27
27
  });
28
- const serverConfig = webpack_merge_1.default(config, {
29
- target: `node${constants_1.NODE_MAJOR_VERSION}.${constants_1.NODE_MINOR_VERSION}`,
28
+ const serverConfig = (0, webpack_merge_1.default)(config, {
29
+ target: `node${utils_1.NODE_MAJOR_VERSION}.${utils_1.NODE_MINOR_VERSION}`,
30
30
  entry: {
31
31
  main: path_1.default.resolve(__dirname, '../client/serverEntry.js'),
32
32
  },
@@ -32,30 +32,8 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
32
32
  export declare function applyConfigureWebpack(configureWebpack: ConfigureWebpackFn, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
33
33
  export declare function applyConfigurePostCss(configurePostCss: NonNullable<ConfigurePostCssFn>, config: Configuration): Configuration;
34
34
  export declare function compile(config: Configuration[]): Promise<void>;
35
- declare type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
36
- declare type FileLoaderUtils = {
37
- loaders: {
38
- file: (options: {
39
- folder: AssetFolder;
40
- }) => RuleSetRule;
41
- url: (options: {
42
- folder: AssetFolder;
43
- }) => RuleSetRule;
44
- inlineMarkdownImageFileLoader: string;
45
- inlineMarkdownLinkFileLoader: string;
46
- };
47
- rules: {
48
- images: () => RuleSetRule;
49
- fonts: () => RuleSetRule;
50
- media: () => RuleSetRule;
51
- svg: () => RuleSetRule;
52
- otherAssets: () => RuleSetRule;
53
- };
54
- };
55
- export declare function getFileLoaderUtils(): FileLoaderUtils;
56
35
  export declare function getHttpsConfig(): boolean | {
57
36
  cert: Buffer;
58
37
  key: Buffer;
59
38
  };
60
39
  export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
61
- export {};
@@ -6,18 +6,18 @@
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 mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
11
+ const mini_css_extract_plugin_1 = (0, tslib_1.__importDefault)(require("mini-css-extract-plugin"));
12
12
  const webpack_merge_1 = require("webpack-merge");
13
- const webpack_1 = tslib_1.__importDefault(require("webpack"));
14
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
15
- const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
16
- 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");
13
+ const webpack_1 = (0, tslib_1.__importDefault)(require("webpack"));
14
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
15
+ const terser_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("terser-webpack-plugin"));
16
+ const css_minimizer_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("css-minimizer-webpack-plugin"));
17
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
18
+ const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
19
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
20
+ const utils_1 = require("@docusaurus/utils");
21
21
  const lodash_1 = require("lodash");
22
22
  // Utility method to get style loaders
23
23
  function getStyleLoaders(isServer, cssOptions = {}) {
@@ -66,7 +66,7 @@ function getStyleLoaders(isServer, cssOptions = {}) {
66
66
  // https://github.com/facebook/create-react-app/issues/2677
67
67
  ident: 'postcss',
68
68
  plugins: [
69
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
69
+ // eslint-disable-next-line global-require
70
70
  require('autoprefixer'),
71
71
  ],
72
72
  },
@@ -76,7 +76,7 @@ function getStyleLoaders(isServer, cssOptions = {}) {
76
76
  }
77
77
  exports.getStyleLoaders = getStyleLoaders;
78
78
  function getCustomBabelConfigFilePath(siteDir) {
79
- const customBabelConfigurationPath = path_1.default.join(siteDir, constants_1.BABEL_CONFIG_FILE_NAME);
79
+ const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
80
80
  return fs_extra_1.default.existsSync(customBabelConfigurationPath)
81
81
  ? customBabelConfigurationPath
82
82
  : undefined;
@@ -112,7 +112,7 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
112
112
  : jsLoader(isServer);
113
113
  exports.getCustomizableJSLoader = getCustomizableJSLoader;
114
114
  // TODO remove this before end of 2021?
115
- const warnBabelLoaderOnce = lodash_1.memoize(function () {
115
+ const warnBabelLoaderOnce = (0, lodash_1.memoize)(() => {
116
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
117
  });
118
118
  const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
@@ -120,7 +120,7 @@ const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, bab
120
120
  return getDefaultBabelLoader({ isServer, babelOptions });
121
121
  };
122
122
  // TODO remove this before end of 2021 ?
123
- const warnCacheLoaderOnce = lodash_1.memoize(function () {
123
+ const warnCacheLoaderOnce = (0, lodash_1.memoize)(() => {
124
124
  console.warn(chalk_1.default.yellow('Docusaurus uses Webpack 5 and getCacheLoader() usage is now deprecated.'));
125
125
  });
126
126
  function getCacheLoaderDeprecated() {
@@ -140,18 +140,17 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
140
140
  // Export some utility functions
141
141
  const utils = {
142
142
  getStyleLoaders,
143
- getJSLoader: exports.getCustomizableJSLoader(jsLoader),
143
+ getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
144
144
  getBabelLoader: getBabelLoaderDeprecated,
145
145
  getCacheLoader: getCacheLoaderDeprecated,
146
146
  };
147
147
  if (typeof configureWebpack === 'function') {
148
148
  const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
149
149
  if (res && typeof res === 'object') {
150
- // @ts-expect-error: annoying error due to enums: https://github.com/survivejs/webpack-merge/issues/179
151
150
  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),
151
+ return (0, webpack_merge_1.mergeWithCustomize)({
152
+ customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
153
+ customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
155
154
  })(config, res);
156
155
  }
157
156
  }
@@ -176,16 +175,16 @@ function applyConfigurePostCss(configurePostCss, config) {
176
175
  else if (Array.isArray(entry.use)) {
177
176
  entry.use
178
177
  .filter((u) => typeof u === 'object')
179
- .forEach(overridePostCssOptions);
178
+ .forEach((rule) => overridePostCssOptions(rule));
180
179
  }
181
180
  }
182
- (_b = (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.forEach(overridePostCssOptions);
181
+ (_b = (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.forEach((rule) => overridePostCssOptions(rule));
183
182
  return config;
184
183
  }
185
184
  exports.applyConfigurePostCss = applyConfigurePostCss;
186
185
  function compile(config) {
187
186
  return new Promise((resolve, reject) => {
188
- const compiler = webpack_1.default(config);
187
+ const compiler = (0, webpack_1.default)(config);
189
188
  compiler.run((err, stats) => {
190
189
  var _a;
191
190
  if (err) {
@@ -222,110 +221,9 @@ function compile(config) {
222
221
  });
223
222
  }
224
223
  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
224
  // Ensure the certificate and key provided are valid and if not
327
225
  // throw an easy to debug error
328
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
226
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
329
227
  let encrypted;
330
228
  try {
331
229
  // publicEncrypt will throw an error with an invalid cert
@@ -391,10 +289,11 @@ function getMinimizer(useSimpleCssMinifier = false) {
391
289
  // into invalid ecma 5 code. This is why the 'compress' and 'output'
392
290
  // sections only apply transformations that are ecma 5 safe
393
291
  // https://github.com/facebook/create-react-app/pull/4234
394
- ecma: 8,
292
+ ecma: 2020,
395
293
  },
396
294
  compress: {
397
295
  ecma: 5,
296
+ // @ts-expect-error: API change in new version?
398
297
  warnings: false,
399
298
  },
400
299
  mangle: {
@@ -425,10 +324,12 @@ function getMinimizer(useSimpleCssMinifier = false) {
425
324
  },
426
325
  // CleanCss options
427
326
  {
327
+ // @ts-expect-error: API change in new version?
428
328
  inline: false,
429
329
  level: {
430
330
  1: {
431
331
  all: false,
332
+ removeWhitespace: true,
432
333
  },
433
334
  2: {
434
335
  all: true,