@docusaurus/core 3.5.2 → 3.6.0

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 (71) hide show
  1. package/bin/beforeCli.mjs +1 -1
  2. package/bin/docusaurus.mjs +15 -4
  3. package/lib/babel/preset.d.ts +2 -2
  4. package/lib/babel/preset.js +10 -71
  5. package/lib/client/renderToHtml.js +15 -51
  6. package/lib/client/serverEntry.d.ts +1 -1
  7. package/lib/client/serverEntry.js +2 -0
  8. package/lib/commands/{build.d.ts → build/build.d.ts} +4 -3
  9. package/lib/commands/build/build.js +94 -0
  10. package/lib/commands/build/buildLocale.d.ts +13 -0
  11. package/lib/commands/build/buildLocale.js +143 -0
  12. package/lib/commands/deploy.d.ts +2 -1
  13. package/lib/commands/deploy.js +2 -2
  14. package/lib/commands/serve.js +2 -2
  15. package/lib/commands/start/utils.js +5 -6
  16. package/lib/commands/start/webpack.js +15 -9
  17. package/lib/commands/writeHeadingIds.js +1 -2
  18. package/lib/commands/writeTranslations.js +6 -6
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/server/configValidation.d.ts +3 -1
  22. package/lib/server/configValidation.js +35 -4
  23. package/lib/server/i18n.d.ts +1 -1
  24. package/lib/server/i18n.js +1 -1
  25. package/lib/server/plugins/plugins.js +13 -13
  26. package/lib/server/plugins/synthetic.d.ts +1 -1
  27. package/lib/server/plugins/synthetic.js +14 -17
  28. package/lib/server/site.js +10 -4
  29. package/lib/server/translations/translationsExtractor.d.ts +5 -11
  30. package/lib/server/translations/translationsExtractor.js +8 -196
  31. package/lib/ssg/ssg.d.ts +21 -0
  32. package/lib/{ssg.js → ssg/ssg.js} +91 -82
  33. package/lib/ssg/ssgExecutor.d.ts +16 -0
  34. package/lib/ssg/ssgExecutor.js +34 -0
  35. package/lib/{server/utils.d.ts → ssg/ssgNodeRequire.d.ts} +5 -2
  36. package/lib/ssg/ssgNodeRequire.js +40 -0
  37. package/lib/ssg/ssgParams.d.ts +28 -0
  38. package/lib/ssg/ssgParams.js +36 -0
  39. package/lib/{templates/templates.d.ts → ssg/ssgTemplate.d.ts} +7 -6
  40. package/lib/{templates/templates.js → ssg/ssgTemplate.js} +11 -9
  41. package/lib/ssg/ssgUtils.d.ts +17 -0
  42. package/lib/ssg/ssgUtils.js +58 -0
  43. package/lib/webpack/base.d.ts +4 -2
  44. package/lib/webpack/base.js +33 -20
  45. package/lib/webpack/client.d.ts +7 -3
  46. package/lib/webpack/client.js +32 -14
  47. package/lib/webpack/configure.d.ts +20 -6
  48. package/lib/webpack/configure.js +31 -16
  49. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +0 -11
  50. package/lib/webpack/plugins/ChunkAssetPlugin.js +48 -33
  51. package/lib/webpack/plugins/ForceTerminatePlugin.js +2 -2
  52. package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.d.ts +2 -2
  53. package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.js +5 -2
  54. package/lib/webpack/server.d.ts +3 -2
  55. package/lib/webpack/server.js +12 -10
  56. package/lib/webpack/{minification.d.ts → utils/getHttpsConfig.d.ts} +4 -2
  57. package/lib/webpack/utils/getHttpsConfig.js +60 -0
  58. package/package.json +19 -44
  59. package/lib/commands/build.js +0 -240
  60. package/lib/server/utils.js +0 -20
  61. package/lib/ssg.d.ts +0 -35
  62. package/lib/utils.d.ts +0 -9
  63. package/lib/utils.js +0 -78
  64. package/lib/webpack/minification.js +0 -96
  65. package/lib/webpack/plugins/WaitPlugin.d.ts +0 -16
  66. package/lib/webpack/plugins/WaitPlugin.js +0 -47
  67. package/lib/webpack/utils.d.ts +0 -33
  68. package/lib/webpack/utils.js +0 -215
  69. /package/lib/{templates/ssr.html.template.d.ts → ssg/ssgTemplate.html.d.ts} +0 -0
  70. /package/lib/{templates/ssr.html.template.js → ssg/ssgTemplate.html.js} +0 -0
  71. /package/lib/{templates → webpack/templates}/dev.html.template.ejs +0 -0
@@ -8,44 +8,59 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
11
- const pluginName = 'chunk-asset-plugin';
12
- /**
13
- * We modify webpack runtime to add an extra function called
14
- * "__webpack_require__.gca" that will allow us to get the corresponding chunk
15
- * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
16
- * For example: if you have a chunk named "my-chunk-name" that will map to
17
- * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
18
- * __webpack_require__.gca("my-chunk-name") will return
19
- * "/publicPath/0a84b5e7.c8e35c7a.js"
20
- *
21
- * "gca" stands for "get chunk asset"
11
+ // Adds a custom Docusaurus Webpack runtime function `__webpack_require__.gca`
12
+ // gca = Get Chunk Asset, it converts a chunkName to a JS asset URL
13
+ // It is called in Core client/docusaurus.ts for chunk preloading/prefetching
14
+ // Example: gca("814f3328") = "/baseUrl/assets/js/814f3328.03fcc178.js"
15
+ // See also: https://github.com/facebook/docusaurus/pull/10485
16
+ // The name of the custom Docusaurus Webpack runtime function
17
+ const DocusaurusGetChunkAssetFn = '__webpack_require__.gca';
18
+ const PluginName = 'Docusaurus-ChunkAssetPlugin';
19
+ function generateGetChunkAssetRuntimeCode(chunk) {
20
+ const chunkIdToName = chunk.getChunkMaps(false).name;
21
+ const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
22
+ chunkName,
23
+ chunkId,
24
+ ]));
25
+ const {
26
+ // publicPath = __webpack_require__.p
27
+ // Example: "/" or "/baseUrl/"
28
+ // https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/PublicPathRuntimeModule.js
29
+ publicPath,
30
+ // getChunkScriptFilename = __webpack_require__.u
31
+ // Example: getChunkScriptFilename("814f3328") = "814f3328.03fcc178.js"
32
+ // https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/GetChunkFilenameRuntimeModule.js
33
+ getChunkScriptFilename, } = webpack_1.default.RuntimeGlobals;
34
+ const code = `// Docusaurus function to get chunk asset
35
+ ${DocusaurusGetChunkAssetFn} = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return ${publicPath} + ${getChunkScriptFilename}(chunkId); };`;
36
+ return webpack_1.default.Template.asString(code);
37
+ }
38
+ /*
39
+ Note: we previously used `MainTemplate.hooks.requireExtensions.tap()`
40
+ But it will be removed in Webpack 6 and is not supported by Rspack
41
+ So instead we use equivalent code inspired by:
42
+ - https://github.com/webpack/webpack/blob/v5.94.0/lib/RuntimePlugin.js#L462
43
+ - https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/CompatRuntimeModule.js
22
44
  */
23
45
  class ChunkAssetPlugin {
24
46
  apply(compiler) {
25
- compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
26
- mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
27
- const chunkIdToName = chunk.getChunkMaps(false).name;
28
- const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
29
- chunkName,
30
- chunkId,
31
- ]));
32
- const buf = [source];
33
- buf.push('// function to get chunk asset');
34
- buf.push(
35
- // If chunkName is passed, we convert it to chunk asset url
36
- // .p => public path url ("/" or "/baseUrl/")
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
41
- //
42
- // Note: __webpack_require__.gca() is called in docusaurus.ts for
43
- // prefetching
44
- // Note: we previously used jsonpScriptSrc (Webpack 4)
45
- `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
46
- return webpack_1.default.Template.asString(buf);
47
+ compiler.hooks.thisCompilation.tap(PluginName, (compilation) => {
48
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(PluginName, (chunk) => {
49
+ compilation.addRuntimeModule(chunk, new ChunkAssetRuntimeModule());
47
50
  });
48
51
  });
49
52
  }
50
53
  }
51
54
  exports.default = ChunkAssetPlugin;
55
+ // Inspired by https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/CompatRuntimeModule.js
56
+ // See also https://rspack.dev/api/javascript-api/compilation#addruntimemodule
57
+ // See also https://rspack.dev/api/plugin-api/compilation-hooks#additionaltreeruntimerequirements
58
+ class ChunkAssetRuntimeModule extends webpack_1.default.RuntimeModule {
59
+ constructor() {
60
+ super('ChunkAssetRuntimeModule', webpack_1.default.RuntimeModule.STAGE_ATTACH);
61
+ this.fullHash = true;
62
+ }
63
+ generate() {
64
+ return generateGetChunkAssetRuntimeCode(this.chunk);
65
+ }
66
+ }
@@ -7,8 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
+ const bundler_1 = require("@docusaurus/bundler");
10
11
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
11
- const utils_1 = require("../utils");
12
12
  // When building, include the plugin to force terminate building if errors
13
13
  // happened in the client bundle.
14
14
  class ForceTerminatePlugin {
@@ -16,7 +16,7 @@ class ForceTerminatePlugin {
16
16
  compiler.hooks.done.tap('client:done', (stats) => {
17
17
  if (stats.hasErrors()) {
18
18
  const errorsWarnings = stats.toJson('errors-warnings');
19
- logger_1.default.error(`Client bundle compiled with errors therefore further build is impossible.\n${(0, utils_1.formatStatsErrorMessage)(errorsWarnings)}`);
19
+ logger_1.default.error(`Client bundle compiled with errors therefore further build is impossible.\n${(0, bundler_1.formatStatsErrorMessage)(errorsWarnings)}`);
20
20
  process.exit(1);
21
21
  }
22
22
  });
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import CopyWebpackPlugin from 'copy-webpack-plugin';
8
7
  import type { Props } from '@docusaurus/types';
8
+ import type { WebpackPluginInstance } from 'webpack';
9
9
  export declare function createStaticDirectoriesCopyPlugin({ props, }: {
10
10
  props: Props;
11
- }): Promise<CopyWebpackPlugin | undefined>;
11
+ }): Promise<WebpackPluginInstance | undefined>;
@@ -10,8 +10,11 @@ exports.createStaticDirectoriesCopyPlugin = createStaticDirectoriesCopyPlugin;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
- const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
13
+ const bundler_1 = require("@docusaurus/bundler");
14
14
  async function createStaticDirectoriesCopyPlugin({ props, }) {
15
+ const CopyPlugin = await (0, bundler_1.getCopyPlugin)({
16
+ currentBundler: props.currentBundler,
17
+ });
15
18
  const { outDir, siteDir, siteConfig: { staticDirectories: staticDirectoriesOption }, } = props;
16
19
  // The staticDirectories option can contain empty directories, or non-existent
17
20
  // directories (e.g. user deleted `static`). Instead of issuing an error, we
@@ -28,7 +31,7 @@ async function createStaticDirectoriesCopyPlugin({ props, }) {
28
31
  if (staticDirectories.length === 0) {
29
32
  return undefined;
30
33
  }
31
- return new copy_webpack_plugin_1.default({
34
+ return new CopyPlugin({
32
35
  patterns: staticDirectories.map((dir) => ({
33
36
  from: dir,
34
37
  to: outDir,
@@ -4,10 +4,11 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { Props } from '@docusaurus/types';
7
+ import type { ConfigureWebpackUtils, Props } from '@docusaurus/types';
8
8
  import type { Configuration } from 'webpack';
9
- export default function createServerConfig(params: {
9
+ export default function createServerConfig({ props, configureWebpackUtils, }: {
10
10
  props: Props;
11
+ configureWebpackUtils: ConfigureWebpackUtils;
11
12
  }): Promise<{
12
13
  config: Configuration;
13
14
  serverBundlePath: string;
@@ -11,36 +11,38 @@ const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
14
+ const bundler_1 = require("@docusaurus/bundler");
15
15
  const base_1 = require("./base");
16
- async function createServerConfig(params) {
17
- const { props } = params;
16
+ async function createServerConfig({ props, configureWebpackUtils, }) {
18
17
  const baseConfig = await (0, base_1.createBaseConfig)({
19
18
  props,
20
19
  isServer: true,
21
- // Minification of server bundle reduces size but doubles bundle time :/
22
20
  minify: false,
21
+ faster: props.siteConfig.future.experimental_faster,
22
+ configureWebpackUtils,
23
+ });
24
+ const ProgressBarPlugin = await (0, bundler_1.getProgressBarPlugin)({
25
+ currentBundler: props.currentBundler,
23
26
  });
24
27
  const outputFilename = 'server.bundle.js';
25
- const serverBundlePath = path_1.default.join(props.outDir, outputFilename);
28
+ const outputDir = path_1.default.join(props.outDir, '__server');
29
+ const serverBundlePath = path_1.default.join(outputDir, outputFilename);
26
30
  const config = (0, webpack_merge_1.default)(baseConfig, {
27
31
  target: `node${utils_1.NODE_MAJOR_VERSION}.${utils_1.NODE_MINOR_VERSION}`,
28
32
  entry: {
29
33
  main: path_1.default.resolve(__dirname, '../client/serverEntry.js'),
30
34
  },
31
35
  output: {
36
+ path: outputDir,
32
37
  filename: outputFilename,
33
38
  libraryTarget: 'commonjs2',
34
- // Workaround for Webpack 4 Bug (https://github.com/webpack/webpack/issues/6522)
35
- globalObject: 'this',
36
39
  },
37
40
  plugins: [
38
- // Show compilation progress bar.
39
- new webpackbar_1.default({
41
+ new ProgressBarPlugin({
40
42
  name: 'Server',
41
43
  color: 'yellow',
42
44
  }),
43
- ].filter(Boolean),
45
+ ],
44
46
  });
45
47
  return { config, serverBundlePath };
46
48
  }
@@ -4,5 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { WebpackPluginInstance } from 'webpack';
8
- export declare function getMinimizer(): WebpackPluginInstance[];
7
+ export default function getHttpsConfig(): Promise<boolean | {
8
+ cert: Buffer;
9
+ key: Buffer;
10
+ }>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = getHttpsConfig;
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
+ // Ensure the certificate and key provided are valid and if not
16
+ // throw an easy to debug error
17
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
18
+ let encrypted;
19
+ try {
20
+ // publicEncrypt will throw an error with an invalid cert
21
+ encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
22
+ }
23
+ catch (err) {
24
+ logger_1.default.error `The certificate path=${crtFile} is invalid.`;
25
+ throw err;
26
+ }
27
+ try {
28
+ // privateDecrypt will throw an error with an invalid key
29
+ crypto_1.default.privateDecrypt(key, encrypted);
30
+ }
31
+ catch (err) {
32
+ logger_1.default.error `The certificate key path=${keyFile} is invalid.`;
33
+ throw err;
34
+ }
35
+ }
36
+ // Read file and throw an error if it doesn't exist
37
+ async function readEnvFile(file, type) {
38
+ if (!(await fs_extra_1.default.pathExists(file))) {
39
+ throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
40
+ }
41
+ return fs_extra_1.default.readFile(file);
42
+ }
43
+ // Get the https config
44
+ // Return cert files if provided in env, otherwise just true or false
45
+ async function getHttpsConfig() {
46
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
47
+ const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
48
+ const isHttps = HTTPS === 'true';
49
+ if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
50
+ const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
51
+ const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
52
+ const config = {
53
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
54
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
55
+ };
56
+ validateKeyAndCerts({ ...config, keyFile, crtFile });
57
+ return config;
58
+ }
59
+ return isHttps;
60
+ }
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": "3.5.2",
4
+ "version": "3.6.0",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -33,53 +33,31 @@
33
33
  "url": "https://github.com/facebook/docusaurus/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@babel/core": "^7.23.3",
37
- "@babel/generator": "^7.23.3",
38
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
39
- "@babel/plugin-transform-runtime": "^7.22.9",
40
- "@babel/preset-env": "^7.22.9",
41
- "@babel/preset-react": "^7.22.5",
42
- "@babel/preset-typescript": "^7.22.5",
43
- "@babel/runtime": "^7.22.6",
44
- "@babel/runtime-corejs3": "^7.22.6",
45
- "@babel/traverse": "^7.22.8",
46
- "@docusaurus/cssnano-preset": "3.5.2",
47
- "@docusaurus/logger": "3.5.2",
48
- "@docusaurus/mdx-loader": "3.5.2",
49
- "@docusaurus/utils": "3.5.2",
50
- "@docusaurus/utils-common": "3.5.2",
51
- "@docusaurus/utils-validation": "3.5.2",
52
- "autoprefixer": "^10.4.14",
53
- "babel-loader": "^9.1.3",
54
- "babel-plugin-dynamic-import-node": "^2.3.3",
36
+ "@docusaurus/babel": "3.6.0",
37
+ "@docusaurus/bundler": "3.6.0",
38
+ "@docusaurus/logger": "3.6.0",
39
+ "@docusaurus/mdx-loader": "3.6.0",
40
+ "@docusaurus/utils": "3.6.0",
41
+ "@docusaurus/utils-common": "3.6.0",
42
+ "@docusaurus/utils-validation": "3.6.0",
55
43
  "boxen": "^6.2.1",
56
44
  "chalk": "^4.1.2",
57
45
  "chokidar": "^3.5.3",
58
- "clean-css": "^5.3.2",
59
46
  "cli-table3": "^0.6.3",
60
47
  "combine-promises": "^1.1.0",
61
48
  "commander": "^5.1.0",
62
- "copy-webpack-plugin": "^11.0.0",
63
49
  "core-js": "^3.31.1",
64
- "css-loader": "^6.8.1",
65
- "css-minimizer-webpack-plugin": "^5.0.1",
66
- "cssnano": "^6.1.2",
67
50
  "del": "^6.1.1",
68
51
  "detect-port": "^1.5.1",
69
52
  "escape-html": "^1.0.3",
70
53
  "eta": "^2.2.0",
71
54
  "eval": "^0.1.8",
72
- "file-loader": "^6.2.0",
73
55
  "fs-extra": "^11.1.1",
74
- "html-minifier-terser": "^7.2.0",
75
56
  "html-tags": "^3.3.1",
76
- "html-webpack-plugin": "^5.5.3",
57
+ "html-webpack-plugin": "^5.6.0",
77
58
  "leven": "^3.1.0",
78
59
  "lodash": "^4.17.21",
79
- "mini-css-extract-plugin": "^2.7.6",
80
60
  "p-map": "^4.0.0",
81
- "postcss": "^8.4.26",
82
- "postcss-loader": "^7.3.3",
83
61
  "prompts": "^2.4.2",
84
62
  "react-dev-utils": "^12.0.1",
85
63
  "react-helmet-async": "^1.3.0",
@@ -90,29 +68,26 @@
90
68
  "react-router-dom": "^5.3.4",
91
69
  "rtl-detect": "^1.0.4",
92
70
  "semver": "^7.5.4",
93
- "serve-handler": "^6.1.5",
71
+ "serve-handler": "^6.1.6",
94
72
  "shelljs": "^0.8.5",
95
- "terser-webpack-plugin": "^5.3.9",
96
73
  "tslib": "^2.6.0",
97
74
  "update-notifier": "^6.0.2",
98
- "url-loader": "^4.1.1",
99
- "webpack": "^5.88.1",
100
- "webpack-bundle-analyzer": "^4.9.0",
101
- "webpack-dev-server": "^4.15.1",
102
- "webpack-merge": "^5.9.0",
103
- "webpackbar": "^5.0.2"
75
+ "webpack": "^5.95.0",
76
+ "webpack-bundle-analyzer": "^4.10.2",
77
+ "webpack-dev-server": "^4.15.2",
78
+ "webpack-merge": "^6.0.1"
104
79
  },
105
80
  "devDependencies": {
106
- "@docusaurus/module-type-aliases": "3.5.2",
107
- "@docusaurus/types": "3.5.2",
81
+ "@docusaurus/module-type-aliases": "3.6.0",
82
+ "@docusaurus/types": "3.6.0",
108
83
  "@total-typescript/shoehorn": "^0.1.2",
109
84
  "@types/detect-port": "^1.3.3",
110
85
  "@types/react-dom": "^18.2.7",
111
86
  "@types/react-router-config": "^5.0.7",
112
87
  "@types/rtl-detect": "^1.0.0",
113
- "@types/serve-handler": "^6.1.1",
88
+ "@types/serve-handler": "^6.1.4",
114
89
  "@types/update-notifier": "^6.0.4",
115
- "@types/webpack-bundle-analyzer": "^4.6.0",
90
+ "@types/webpack-bundle-analyzer": "^4.7.0",
116
91
  "react-test-renderer": "^18.0.0",
117
92
  "tmp-promise": "^3.0.3",
118
93
  "tree-node-cli": "^1.6.0"
@@ -125,5 +100,5 @@
125
100
  "engines": {
126
101
  "node": ">=18.0"
127
102
  },
128
- "gitHead": "eeec303dd773774ed5a023884800da0b061f6942"
103
+ "gitHead": "05bba6d4f495ef6b0bec5d41453932bb97981830"
129
104
  }
@@ -1,240 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.build = build;
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 lodash_1 = tslib_1.__importDefault(require("lodash"));
14
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
- const utils_1 = require("@docusaurus/utils");
16
- const site_1 = require("../server/site");
17
- const brokenLinks_1 = require("../server/brokenLinks");
18
- const client_1 = require("../webpack/client");
19
- const server_1 = tslib_1.__importDefault(require("../webpack/server"));
20
- const configure_1 = require("../webpack/configure");
21
- const utils_2 = require("../webpack/utils");
22
- const utils_3 = require("../utils");
23
- const i18n_1 = require("../server/i18n");
24
- const ssg_1 = require("../ssg");
25
- const templates_1 = require("../templates/templates");
26
- const ssr_html_template_1 = tslib_1.__importDefault(require("../templates/ssr.html.template"));
27
- async function build(siteDirParam = '.', cliOptions = {},
28
- // When running build, we force terminate the process to prevent async
29
- // operations from never returning. However, if run as part of docusaurus
30
- // deploy, we have to let deploy finish.
31
- // See https://github.com/facebook/docusaurus/pull/2496
32
- forceTerminate = true) {
33
- process.env.BABEL_ENV = 'production';
34
- process.env.NODE_ENV = 'production';
35
- process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;
36
- if (cliOptions.dev) {
37
- logger_1.default.info `Building in dev mode`;
38
- process.env.BABEL_ENV = 'development';
39
- process.env.NODE_ENV = 'development';
40
- }
41
- const siteDir = await fs_extra_1.default.realpath(siteDirParam);
42
- ['SIGINT', 'SIGTERM'].forEach((sig) => {
43
- process.on(sig, () => process.exit());
44
- });
45
- async function tryToBuildLocale({ locale }) {
46
- try {
47
- await utils_3.PerfLogger.async(`${logger_1.default.name(locale)}`, () => buildLocale({
48
- siteDir,
49
- locale,
50
- cliOptions,
51
- }));
52
- }
53
- catch (err) {
54
- throw new Error(logger_1.default.interpolate `Unable to build website for locale name=${locale}.`, {
55
- cause: err,
56
- });
57
- }
58
- }
59
- const locales = await utils_3.PerfLogger.async('Get locales to build', () => getLocalesToBuild({ siteDir, cliOptions }));
60
- if (locales.length > 1) {
61
- logger_1.default.info `Website will be built for all these locales: ${locales}`;
62
- }
63
- await utils_3.PerfLogger.async(`Build`, () => (0, utils_1.mapAsyncSequential)(locales, async (locale) => {
64
- const isLastLocale = locales.indexOf(locale) === locales.length - 1;
65
- await tryToBuildLocale({ locale });
66
- if (isLastLocale) {
67
- logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
68
- }
69
- // TODO do we really need this historical forceTerminate exit???
70
- if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
71
- process.exit(0);
72
- }
73
- }));
74
- }
75
- async function getLocalesToBuild({ siteDir, cliOptions, }) {
76
- if (cliOptions.locale) {
77
- return [cliOptions.locale];
78
- }
79
- const context = await (0, site_1.loadContext)({
80
- siteDir,
81
- outDir: cliOptions.outDir,
82
- config: cliOptions.config,
83
- locale: cliOptions.locale,
84
- localizePath: cliOptions.locale ? false : undefined,
85
- });
86
- const i18n = await (0, i18n_1.loadI18n)(context.siteConfig, {
87
- locale: cliOptions.locale,
88
- });
89
- if (i18n.locales.length > 1) {
90
- logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
91
- }
92
- // We need the default locale to always be the 1st in the list. If we build it
93
- // last, it would "erase" the localized sites built in sub-folders
94
- return [
95
- i18n.defaultLocale,
96
- ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
97
- ];
98
- }
99
- async function buildLocale({ siteDir, locale, cliOptions, }) {
100
- // Temporary workaround to unlock the ability to translate the site config
101
- // We'll remove it if a better official API can be designed
102
- // See https://github.com/facebook/docusaurus/issues/4542
103
- process.env.DOCUSAURUS_CURRENT_LOCALE = locale;
104
- logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
105
- const site = await utils_3.PerfLogger.async('Load site', () => (0, site_1.loadSite)({
106
- siteDir,
107
- outDir: cliOptions.outDir,
108
- config: cliOptions.config,
109
- locale,
110
- localizePath: cliOptions.locale ? false : undefined,
111
- }));
112
- const { props } = site;
113
- const { outDir, plugins, siteConfig } = props;
114
- const router = siteConfig.future.experimental_router;
115
- // We can build the 2 configs in parallel
116
- const [{ clientConfig, clientManifestPath }, { serverConfig, serverBundlePath }] = await utils_3.PerfLogger.async('Creating webpack configs', () => Promise.all([
117
- getBuildClientConfig({
118
- props,
119
- cliOptions,
120
- }),
121
- getBuildServerConfig({
122
- props,
123
- }),
124
- ]));
125
- // Run webpack to build JS bundle (client) and static html files (server).
126
- await utils_3.PerfLogger.async('Bundling with Webpack', () => {
127
- if (router === 'hash') {
128
- return (0, utils_2.compile)([clientConfig]);
129
- }
130
- else {
131
- return (0, utils_2.compile)([clientConfig, serverConfig]);
132
- }
133
- });
134
- const { collectedData } = await utils_3.PerfLogger.async('SSG', () => executeSSG({
135
- props,
136
- serverBundlePath,
137
- clientManifestPath,
138
- router,
139
- }));
140
- // Remove server.bundle.js because it is not needed.
141
- await utils_3.PerfLogger.async('Deleting server bundle', () => ensureUnlink(serverBundlePath));
142
- // Plugin Lifecycle - postBuild.
143
- await utils_3.PerfLogger.async('postBuild()', () => executePluginsPostBuild({ plugins, props, collectedData }));
144
- // TODO execute this in parallel to postBuild?
145
- await utils_3.PerfLogger.async('Broken links checker', () => executeBrokenLinksCheck({ props, collectedData }));
146
- logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
147
- return outDir;
148
- }
149
- async function executeSSG({ props, serverBundlePath, clientManifestPath, router, }) {
150
- const manifest = await utils_3.PerfLogger.async('Read client manifest', () => fs_extra_1.default.readJSON(clientManifestPath, 'utf-8'));
151
- const ssrTemplate = await utils_3.PerfLogger.async('Compile SSR template', () => (0, templates_1.compileSSRTemplate)(props.siteConfig.ssrTemplate ?? ssr_html_template_1.default));
152
- const params = {
153
- trailingSlash: props.siteConfig.trailingSlash,
154
- outDir: props.outDir,
155
- baseUrl: props.baseUrl,
156
- manifest,
157
- headTags: props.headTags,
158
- preBodyTags: props.preBodyTags,
159
- postBodyTags: props.postBodyTags,
160
- ssrTemplate,
161
- noIndex: props.siteConfig.noIndex,
162
- DOCUSAURUS_VERSION: utils_1.DOCUSAURUS_VERSION,
163
- };
164
- if (router === 'hash') {
165
- utils_3.PerfLogger.start('Generate Hash Router entry point');
166
- const content = (0, templates_1.renderHashRouterTemplate)({ params });
167
- await (0, ssg_1.generateHashRouterEntrypoint)({ content, params });
168
- utils_3.PerfLogger.end('Generate Hash Router entry point');
169
- return { collectedData: {} };
170
- }
171
- const renderer = await utils_3.PerfLogger.async('Load App renderer', () => (0, ssg_1.loadAppRenderer)({
172
- serverBundlePath,
173
- }));
174
- const ssgResult = await utils_3.PerfLogger.async('Generate static files', () => (0, ssg_1.generateStaticFiles)({
175
- pathnames: props.routesPaths,
176
- renderer,
177
- params,
178
- }));
179
- return ssgResult;
180
- }
181
- async function executePluginsPostBuild({ plugins, props, collectedData, }) {
182
- const head = lodash_1.default.mapValues(collectedData, (d) => d.helmet);
183
- await Promise.all(plugins.map(async (plugin) => {
184
- if (!plugin.postBuild) {
185
- return;
186
- }
187
- await plugin.postBuild({
188
- ...props,
189
- head,
190
- content: plugin.content,
191
- });
192
- }));
193
- }
194
- async function executeBrokenLinksCheck({ props: { routes, siteConfig: { onBrokenLinks, onBrokenAnchors }, }, collectedData, }) {
195
- const collectedLinks = lodash_1.default.mapValues(collectedData, (d) => ({
196
- links: d.links,
197
- anchors: d.anchors,
198
- }));
199
- await (0, brokenLinks_1.handleBrokenLinks)({
200
- collectedLinks,
201
- routes,
202
- onBrokenLinks,
203
- onBrokenAnchors,
204
- });
205
- }
206
- async function getBuildClientConfig({ props, cliOptions, }) {
207
- const { plugins } = props;
208
- const result = await (0, client_1.createBuildClientConfig)({
209
- props,
210
- minify: cliOptions.minify ?? true,
211
- bundleAnalyzer: cliOptions.bundleAnalyzer ?? false,
212
- });
213
- let { config } = result;
214
- config = (0, configure_1.executePluginsConfigureWebpack)({
215
- plugins,
216
- config,
217
- isServer: false,
218
- jsLoader: props.siteConfig.webpack?.jsLoader,
219
- });
220
- return { clientConfig: config, clientManifestPath: result.clientManifestPath };
221
- }
222
- async function getBuildServerConfig({ props }) {
223
- const { plugins } = props;
224
- const result = await (0, server_1.default)({
225
- props,
226
- });
227
- let { config } = result;
228
- config = (0, configure_1.executePluginsConfigureWebpack)({
229
- plugins,
230
- config,
231
- isServer: true,
232
- jsLoader: props.siteConfig.webpack?.jsLoader,
233
- });
234
- return { serverConfig: config, serverBundlePath: result.serverBundlePath };
235
- }
236
- async function ensureUnlink(filepath) {
237
- if (await fs_extra_1.default.pathExists(filepath)) {
238
- await fs_extra_1.default.unlink(filepath);
239
- }
240
- }