@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
package/bin/beforeCli.mjs CHANGED
@@ -11,7 +11,7 @@ import fs from 'fs-extra';
11
11
  import path from 'path';
12
12
  import {createRequire} from 'module';
13
13
  import shell from 'shelljs';
14
- import logger from '@docusaurus/logger';
14
+ import {logger} from '@docusaurus/logger';
15
15
  import semver from 'semver';
16
16
  import updateNotifier from 'update-notifier';
17
17
  import boxen from 'boxen';
@@ -9,7 +9,7 @@
9
9
  // @ts-check
10
10
 
11
11
  import {inspect} from 'node:util';
12
- import logger from '@docusaurus/logger';
12
+ import {logger} from '@docusaurus/logger';
13
13
  import cli from 'commander';
14
14
  import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
15
15
  import {
@@ -33,6 +33,15 @@ process.env.NODE_ENV ??= 'development';
33
33
 
34
34
  await beforeCli();
35
35
 
36
+ /**
37
+ * @param {string} locale
38
+ * @param {string[]} locales
39
+ * @returns {string[]}
40
+ */
41
+ function concatLocaleOptions(locale, locales = []) {
42
+ return locales.concat(locale);
43
+ }
44
+
36
45
  cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
37
46
 
38
47
  cli
@@ -55,8 +64,9 @@ cli
55
64
  'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
56
65
  )
57
66
  .option(
58
- '-l, --locale <locale>',
59
- 'build the site in a specified locale. Build all known locales otherwise',
67
+ '-l, --locale <locale...>',
68
+ 'build the site in the specified locale(s). Build all known locales otherwise',
69
+ concatLocaleOptions,
60
70
  )
61
71
  .option(
62
72
  '--no-minify',
@@ -101,7 +111,8 @@ cli
101
111
  .description('Deploy website to GitHub pages.')
102
112
  .option(
103
113
  '-l, --locale <locale>',
104
- 'deploy the site in a specified locale. Deploy all known locales otherwise',
114
+ 'deploy the site in the specified locale(s). Deploy all known locales otherwise',
115
+ concatLocaleOptions,
105
116
  )
106
117
  .option(
107
118
  '--out-dir <dir>',
@@ -4,5 +4,5 @@
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 { ConfigAPI, TransformOptions } from '@babel/core';
8
- export default function babelPresets(api: ConfigAPI): TransformOptions;
7
+ import BabelPreset from '@docusaurus/babel/preset';
8
+ export default BabelPreset;
@@ -6,75 +6,14 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.default = babelPresets;
10
9
  const tslib_1 = require("tslib");
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- function getTransformOptions(isServer) {
13
- const absoluteRuntimePath = path_1.default.dirname(require.resolve(`@babel/runtime/package.json`));
14
- return {
15
- // All optional newlines and whitespace will be omitted when generating code
16
- // in compact mode
17
- compact: true,
18
- presets: [
19
- isServer
20
- ? [
21
- require.resolve('@babel/preset-env'),
22
- {
23
- targets: {
24
- node: 'current',
25
- },
26
- },
27
- ]
28
- : [
29
- require.resolve('@babel/preset-env'),
30
- {
31
- useBuiltIns: 'entry',
32
- loose: true,
33
- corejs: '3',
34
- // Do not transform modules to CJS
35
- modules: false,
36
- // Exclude transforms that make all code slower
37
- exclude: ['transform-typeof-symbol'],
38
- },
39
- ],
40
- [
41
- require.resolve('@babel/preset-react'),
42
- {
43
- runtime: 'automatic',
44
- },
45
- ],
46
- require.resolve('@babel/preset-typescript'),
47
- ],
48
- plugins: [
49
- // Polyfills the runtime needed for async/await, generators, and friends
50
- // https://babeljs.io/docs/en/babel-plugin-transform-runtime
51
- [
52
- require.resolve('@babel/plugin-transform-runtime'),
53
- {
54
- corejs: false,
55
- helpers: true,
56
- // By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
57
- // better to explicitly specify the version so that it can reuse the
58
- // helper better. See https://github.com/babel/babel/issues/10261
59
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
60
- version: require('@babel/runtime/package.json')
61
- .version,
62
- regenerator: true,
63
- useESModules: true,
64
- // Undocumented option that lets us encapsulate our runtime, ensuring
65
- // the correct version is used
66
- // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
67
- absoluteRuntime: absoluteRuntimePath,
68
- },
69
- ],
70
- // Adds syntax support for import()
71
- isServer
72
- ? require.resolve('babel-plugin-dynamic-import-node')
73
- : require.resolve('@babel/plugin-syntax-dynamic-import'),
74
- ],
75
- };
76
- }
77
- function babelPresets(api) {
78
- const callerName = api.caller((caller) => caller?.name);
79
- return getTransformOptions(callerName === 'server');
80
- }
10
+ // TODO Docusaurus v4, do breaking change and expose babel preset cleanly
11
+ /*
12
+ this just ensure retro-compatibility with our former init template .babelrc.js:
13
+
14
+ module.exports = {
15
+ presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
16
+ };
17
+ */
18
+ const preset_1 = tslib_1.__importDefault(require("@docusaurus/babel/preset"));
19
+ exports.default = preset_1.default;
@@ -5,57 +5,21 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { renderToPipeableStream } from 'react-dom/server';
8
- import { Writable } from 'stream';
8
+ import { PassThrough } from 'node:stream';
9
+ import { text } from 'node:stream/consumers';
10
+ // See also https://github.com/facebook/react/issues/31134
11
+ // See also https://github.com/facebook/docusaurus/issues/9985#issuecomment-2396367797
9
12
  export async function renderToHtml(app) {
10
- // Inspired from
11
- // https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
12
- // https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/static-entry.js
13
- const writableStream = new WritableAsPromise();
14
- const { pipe } = renderToPipeableStream(app, {
15
- onError(error) {
16
- writableStream.destroy(error);
17
- },
18
- onAllReady() {
19
- pipe(writableStream);
20
- },
21
- });
22
- return writableStream.getPromise();
23
- }
24
- // WritableAsPromise inspired by https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/server-utils/writable-as-promise.js
25
- /* eslint-disable no-underscore-dangle */
26
- class WritableAsPromise extends Writable {
27
- _output;
28
- _deferred;
29
- constructor() {
30
- super();
31
- this._output = ``;
32
- this._deferred = {
33
- promise: null,
34
- resolve: () => null,
35
- reject: () => null,
36
- };
37
- this._deferred.promise = new Promise((resolve, reject) => {
38
- this._deferred.resolve = resolve;
39
- this._deferred.reject = reject;
13
+ return new Promise((resolve, reject) => {
14
+ const passThrough = new PassThrough();
15
+ const { pipe } = renderToPipeableStream(app, {
16
+ onError(error) {
17
+ reject(error);
18
+ },
19
+ onAllReady() {
20
+ pipe(passThrough);
21
+ text(passThrough).then(resolve, reject);
22
+ },
40
23
  });
41
- }
42
- _write(chunk, _enc, next) {
43
- this._output += chunk.toString();
44
- next();
45
- }
46
- _destroy(error, next) {
47
- if (error instanceof Error) {
48
- this._deferred.reject(error);
49
- }
50
- else {
51
- next();
52
- }
53
- }
54
- end() {
55
- this._deferred.resolve(this._output);
56
- return this.destroy();
57
- }
58
- getPromise() {
59
- return this._deferred.promise;
60
- }
24
+ });
61
25
  }
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { AppRenderer } from '../common';
8
- declare const render: AppRenderer;
8
+ declare const render: AppRenderer['render'];
9
9
  export default render;
@@ -31,6 +31,8 @@ const render = async ({ pathname }) => {
31
31
  </Loadable.Capture>);
32
32
  const html = await renderToHtml(app);
33
33
  const collectedData = {
34
+ // TODO Docusaurus v4 refactor: helmet state is non-serializable
35
+ // this makes it impossible to run SSG in a worker thread
34
36
  helmet: helmetContext.helmet,
35
37
  anchors: statefulBrokenLinks.getCollectedAnchors(),
36
38
  links: statefulBrokenLinks.getCollectedLinks(),
@@ -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 LoadContextParams } from '../server/site';
8
- export type BuildCLIOptions = Pick<LoadContextParams, 'config' | 'locale' | 'outDir'> & {
7
+ import { type LoadContextParams } from '../../server/site';
8
+ export type BuildCLIOptions = Pick<LoadContextParams, 'config' | 'outDir'> & {
9
+ locale?: [string, ...string[]];
9
10
  bundleAnalyzer?: boolean;
10
11
  minify?: boolean;
11
12
  dev?: boolean;
12
13
  };
13
- export declare function build(siteDirParam?: string, cliOptions?: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<void>;
14
+ export declare function build(siteDirParam?: string, cliOptions?: Partial<BuildCLIOptions>): Promise<void>;
@@ -0,0 +1,94 @@
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 logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ const site_1 = require("../../server/site");
15
+ const i18n_1 = require("../../server/i18n");
16
+ const buildLocale_1 = require("./buildLocale");
17
+ async function build(siteDirParam = '.', cliOptions = {}) {
18
+ process.env.BABEL_ENV = 'production';
19
+ process.env.NODE_ENV = 'production';
20
+ if (cliOptions.dev) {
21
+ logger_1.default.info `Building in dev mode`;
22
+ process.env.BABEL_ENV = 'development';
23
+ process.env.NODE_ENV = 'development';
24
+ }
25
+ const siteDir = await fs_extra_1.default.realpath(siteDirParam);
26
+ ['SIGINT', 'SIGTERM'].forEach((sig) => {
27
+ process.on(sig, () => process.exit());
28
+ });
29
+ const locales = await logger_1.PerfLogger.async('Get locales to build', () => getLocalesToBuild({ siteDir, cliOptions }));
30
+ if (locales.length > 1) {
31
+ logger_1.default.info `Website will be built for all these locales: ${locales}`;
32
+ }
33
+ await logger_1.PerfLogger.async(`Build`, () => (0, utils_1.mapAsyncSequential)(locales, async (locale) => {
34
+ await tryToBuildLocale({ siteDir, locale, cliOptions });
35
+ }));
36
+ logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
37
+ }
38
+ // We need the default locale to always be the 1st in the list. If we build it
39
+ // last, it would "erase" the localized sites built in sub-folders
40
+ function orderLocales({ locales, defaultLocale, }) {
41
+ if (locales.includes(defaultLocale)) {
42
+ return [
43
+ defaultLocale,
44
+ ...locales.filter((locale) => locale !== defaultLocale),
45
+ ];
46
+ }
47
+ else {
48
+ return locales;
49
+ }
50
+ }
51
+ async function getLocalesToBuild({ siteDir, cliOptions, }) {
52
+ // We disable locale path localization if CLI has single "--locale" option
53
+ // yarn build --locale fr => baseUrl=/ instead of baseUrl=/fr/
54
+ const localizePath = cliOptions.locale?.length === 1 ? false : undefined;
55
+ const context = await (0, site_1.loadContext)({
56
+ siteDir,
57
+ outDir: cliOptions.outDir,
58
+ config: cliOptions.config,
59
+ localizePath,
60
+ });
61
+ const i18n = await (0, i18n_1.loadI18n)(context.siteConfig);
62
+ const locales = cliOptions.locale ?? i18n.locales;
63
+ return orderLocales({
64
+ locales: locales,
65
+ defaultLocale: i18n.defaultLocale,
66
+ });
67
+ }
68
+ async function tryToBuildLocale(params) {
69
+ try {
70
+ await logger_1.PerfLogger.async(`${logger_1.default.name(params.locale)}`, async () => {
71
+ // Note: I tried to run buildLocale in worker_threads (still sequentially)
72
+ // It didn't work and I got SIGSEGV / SIGBUS errors
73
+ // See https://x.com/sebastienlorber/status/1848413716372480338
74
+ await runBuildLocaleTask(params);
75
+ });
76
+ }
77
+ catch (err) {
78
+ throw new Error(logger_1.default.interpolate `Unable to build website for locale name=${params.locale}.`, {
79
+ cause: err,
80
+ });
81
+ }
82
+ }
83
+ async function runBuildLocaleTask(params) {
84
+ // Note: I tried to run buildLocale task in worker_threads (sequentially)
85
+ // It didn't work and I got SIGSEGV / SIGBUS errors
86
+ // Goal was to isolate memory of each localized site build
87
+ // See also https://x.com/sebastienlorber/status/1848413716372480338
88
+ //
89
+ // Running in child_process worked but is more complex and requires
90
+ // specifying the memory of the child process + weird logging issues to fix
91
+ //
92
+ // Note in the future we could try to enable concurrent localized site builds
93
+ await (0, buildLocale_1.buildLocale)(params);
94
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { BuildCLIOptions } from './build';
8
+ export type BuildLocaleParams = {
9
+ siteDir: string;
10
+ locale: string;
11
+ cliOptions: Partial<BuildCLIOptions>;
12
+ };
13
+ export declare function buildLocale({ siteDir, locale, cliOptions, }: BuildLocaleParams): Promise<void>;
@@ -0,0 +1,143 @@
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.buildLocale = buildLocale;
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 bundler_1 = require("@docusaurus/bundler");
15
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
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 ssgExecutor_1 = require("../../ssg/ssgExecutor");
22
+ async function buildLocale({ siteDir, locale, cliOptions, }) {
23
+ // Temporary workaround to unlock the ability to translate the site config
24
+ // We'll remove it if a better official API can be designed
25
+ // See https://github.com/facebook/docusaurus/issues/4542
26
+ process.env.DOCUSAURUS_CURRENT_LOCALE = locale;
27
+ logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
28
+ const site = await logger_1.PerfLogger.async('Load site', () => (0, site_1.loadSite)({
29
+ siteDir,
30
+ outDir: cliOptions.outDir,
31
+ config: cliOptions.config,
32
+ locale,
33
+ localizePath: cliOptions.locale?.length === 1 ? false : undefined,
34
+ }));
35
+ const { props } = site;
36
+ const { outDir, plugins, siteConfig } = props;
37
+ const router = siteConfig.future.experimental_router;
38
+ const configureWebpackUtils = await (0, configure_1.createConfigureWebpackUtils)({ siteConfig });
39
+ // We can build the 2 configs in parallel
40
+ const [{ clientConfig, clientManifestPath }, { serverConfig, serverBundlePath }] = await logger_1.PerfLogger.async(`Creating ${props.currentBundler.name} bundler configs`, () => Promise.all([
41
+ getBuildClientConfig({
42
+ props,
43
+ cliOptions,
44
+ configureWebpackUtils,
45
+ }),
46
+ getBuildServerConfig({
47
+ props,
48
+ configureWebpackUtils,
49
+ }),
50
+ ]));
51
+ // Run webpack to build JS bundle (client) and static html files (server).
52
+ await logger_1.PerfLogger.async(`Bundling with ${props.currentBundler.name}`, () => {
53
+ return (0, bundler_1.compile)({
54
+ configs:
55
+ // For hash router we don't do SSG and can skip the server bundle
56
+ router === 'hash' ? [clientConfig] : [clientConfig, serverConfig],
57
+ currentBundler: configureWebpackUtils.currentBundler,
58
+ });
59
+ });
60
+ const { collectedData } = await logger_1.PerfLogger.async('SSG', () => (0, ssgExecutor_1.executeSSG)({
61
+ props,
62
+ serverBundlePath,
63
+ clientManifestPath,
64
+ router,
65
+ }));
66
+ await cleanupServerBundle(serverBundlePath);
67
+ // Plugin Lifecycle - postBuild.
68
+ await logger_1.PerfLogger.async('postBuild()', () => executePluginsPostBuild({ plugins, props, collectedData }));
69
+ // TODO execute this in parallel to postBuild?
70
+ await logger_1.PerfLogger.async('Broken links checker', () => executeBrokenLinksCheck({ props, collectedData }));
71
+ logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
72
+ }
73
+ async function executePluginsPostBuild({ plugins, props, collectedData, }) {
74
+ const head = lodash_1.default.mapValues(collectedData, (d) => d.helmet);
75
+ await Promise.all(plugins.map(async (plugin) => {
76
+ if (!plugin.postBuild) {
77
+ return;
78
+ }
79
+ await plugin.postBuild({
80
+ ...props,
81
+ head,
82
+ content: plugin.content,
83
+ });
84
+ }));
85
+ }
86
+ async function executeBrokenLinksCheck({ props: { routes, siteConfig: { onBrokenLinks, onBrokenAnchors }, }, collectedData, }) {
87
+ const collectedLinks = lodash_1.default.mapValues(collectedData, (d) => ({
88
+ links: d.links,
89
+ anchors: d.anchors,
90
+ }));
91
+ await (0, brokenLinks_1.handleBrokenLinks)({
92
+ collectedLinks,
93
+ routes,
94
+ onBrokenLinks,
95
+ onBrokenAnchors,
96
+ });
97
+ }
98
+ async function getBuildClientConfig({ props, cliOptions, configureWebpackUtils, }) {
99
+ const { plugins } = props;
100
+ const result = await (0, client_1.createBuildClientConfig)({
101
+ props,
102
+ minify: cliOptions.minify ?? true,
103
+ faster: props.siteConfig.future.experimental_faster,
104
+ configureWebpackUtils,
105
+ bundleAnalyzer: cliOptions.bundleAnalyzer ?? false,
106
+ });
107
+ let { config } = result;
108
+ config = (0, configure_1.executePluginsConfigureWebpack)({
109
+ plugins,
110
+ config,
111
+ isServer: false,
112
+ configureWebpackUtils,
113
+ });
114
+ return { clientConfig: config, clientManifestPath: result.clientManifestPath };
115
+ }
116
+ async function getBuildServerConfig({ props, configureWebpackUtils, }) {
117
+ const { plugins } = props;
118
+ const result = await (0, server_1.default)({
119
+ props,
120
+ configureWebpackUtils,
121
+ });
122
+ let { config } = result;
123
+ config = (0, configure_1.executePluginsConfigureWebpack)({
124
+ plugins,
125
+ config,
126
+ isServer: true,
127
+ configureWebpackUtils,
128
+ });
129
+ return { serverConfig: config, serverBundlePath: result.serverBundlePath };
130
+ }
131
+ // Remove /build/server server.bundle.js because it is not needed.
132
+ async function cleanupServerBundle(serverBundlePath) {
133
+ if (process.env.DOCUSAURUS_KEEP_SERVER_BUNDLE === 'true') {
134
+ logger_1.default.warn("Will NOT delete server bundle because DOCUSAURUS_KEEP_SERVER_BUNDLE is set to 'true'");
135
+ }
136
+ else {
137
+ await logger_1.PerfLogger.async('Deleting server bundle', async () => {
138
+ // For now we assume server entry is at the root of the server out dir
139
+ const serverDir = path_1.default.dirname(serverBundlePath);
140
+ await fs_extra_1.default.rm(serverDir, { recursive: true, force: true });
141
+ });
142
+ }
143
+ }
@@ -5,7 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type LoadContextParams } from '../server/site';
8
- export type DeployCLIOptions = Pick<LoadContextParams, 'config' | 'locale' | 'outDir'> & {
8
+ export type DeployCLIOptions = Pick<LoadContextParams, 'config' | 'outDir'> & {
9
+ locale?: [string, ...string[]];
9
10
  skipBuild?: boolean;
10
11
  targetDir?: string;
11
12
  };
@@ -15,7 +15,7 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
16
16
  const utils_1 = require("@docusaurus/utils");
17
17
  const site_1 = require("../server/site");
18
- const build_1 = require("./build");
18
+ const build_1 = require("./build/build");
19
19
  // GIT_PASS env variable should not appear in logs
20
20
  function obfuscateGitPass(str) {
21
21
  const gitPass = process.env.GIT_PASS;
@@ -183,7 +183,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
183
183
  if (!cliOptions.skipBuild) {
184
184
  // Build site, then push to deploymentBranch branch of specified repo.
185
185
  try {
186
- await (0, build_1.build)(siteDir, cliOptions, false);
186
+ await (0, build_1.build)(siteDir, cliOptions);
187
187
  await runDeploy(outDir);
188
188
  }
189
189
  catch (err) {
@@ -17,7 +17,7 @@ const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
17
17
  const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
18
18
  const utils_common_1 = require("@docusaurus/utils-common");
19
19
  const config_1 = require("../server/config");
20
- const build_1 = require("./build");
20
+ const build_1 = require("./build/build");
21
21
  const getHostPort_1 = require("../server/getHostPort");
22
22
  function redirect(res, location) {
23
23
  res.writeHead(302, {
@@ -33,7 +33,7 @@ async function serve(siteDirParam = '.', cliOptions = {}) {
33
33
  await (0, build_1.build)(siteDir, {
34
34
  config: cliOptions.config,
35
35
  outDir,
36
- }, false);
36
+ });
37
37
  }
38
38
  const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
39
39
  if (port === null) {
@@ -13,9 +13,8 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
15
15
  const utils_1 = require("@docusaurus/utils");
16
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
17
17
  const getHostPort_1 = require("../../server/getHostPort");
18
- const utils_2 = require("../../utils");
19
18
  const site_1 = require("../../server/site");
20
19
  const pluginsUtils_1 = require("../../server/plugins/pluginsUtils");
21
20
  async function createOpenUrlContext({ cliOptions, }) {
@@ -46,8 +45,8 @@ async function createLoadSiteParams({ siteDirParam, cliOptions, }) {
46
45
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
47
46
  async function createReloadableSite(startParams) {
48
47
  const openUrlContext = await createOpenUrlContext(startParams);
49
- const loadSiteParams = await utils_2.PerfLogger.async('createLoadSiteParams', () => createLoadSiteParams(startParams));
50
- let site = await utils_2.PerfLogger.async('Load site', () => (0, site_1.loadSite)(loadSiteParams));
48
+ const loadSiteParams = await logger_1.PerfLogger.async('createLoadSiteParams', () => createLoadSiteParams(startParams));
49
+ let site = await logger_1.PerfLogger.async('Load site', () => (0, site_1.loadSite)(loadSiteParams));
51
50
  const get = () => site;
52
51
  const getOpenUrl = () => openUrlContext.getOpenUrl({
53
52
  baseUrl: site.props.baseUrl,
@@ -60,7 +59,7 @@ async function createReloadableSite(startParams) {
60
59
  const reloadBase = async () => {
61
60
  try {
62
61
  const oldSite = site;
63
- site = await utils_2.PerfLogger.async('Reload site', () => (0, site_1.reloadSite)(site));
62
+ site = await logger_1.PerfLogger.async('Reload site', () => (0, site_1.reloadSite)(site));
64
63
  if (oldSite.props.baseUrl !== site.props.baseUrl) {
65
64
  printOpenUrlMessage();
66
65
  }
@@ -77,7 +76,7 @@ async function createReloadableSite(startParams) {
77
76
  // but we should still support it and probably use a task queuing system
78
77
  const reloadPlugin = async (plugin) => {
79
78
  try {
80
- site = await utils_2.PerfLogger.async(`Reload site plugin ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, () => {
79
+ site = await logger_1.PerfLogger.async(`Reload site plugin ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, () => {
81
80
  const pluginIdentifier = { name: plugin.name, id: plugin.options.id };
82
81
  return (0, site_1.reloadSitePlugin)(site, pluginIdentifier);
83
82
  });