@docusaurus/core 2.0.0-beta.2 → 2.0.0-beta.22

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 (223) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/docusaurus.mjs +221 -0
  4. package/lib/babel/preset.d.ts +8 -3
  5. package/lib/babel/preset.js +10 -8
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +47 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -8
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +37 -0
  32. package/lib/client/exports/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -49
  36. package/lib/client/exports/Link.d.ts +4 -10
  37. package/lib/client/exports/Link.js +40 -40
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +11 -14
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +6 -13
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/client/exports/useRouteContext.d.ts +8 -0
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +12 -2
  56. package/lib/client/flat.js +19 -15
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +14 -10
  59. package/lib/client/prefetch.d.ts +1 -2
  60. package/lib/client/prefetch.js +12 -32
  61. package/lib/client/preload.d.ts +3 -4
  62. package/lib/client/preload.js +5 -12
  63. package/lib/client/routeContext.d.ts +13 -0
  64. package/lib/client/routeContext.js +31 -0
  65. package/lib/client/serverEntry.d.ts +10 -0
  66. package/lib/client/serverEntry.js +108 -146
  67. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  68. package/lib/client/theme-fallback/Error/index.js +45 -0
  69. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  70. package/lib/client/theme-fallback/Layout/index.js +2 -26
  71. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  72. package/lib/client/theme-fallback/Loading/index.js +50 -116
  73. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  74. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  75. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  76. package/lib/client/theme-fallback/Root/index.js +2 -6
  77. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  78. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  79. package/lib/commands/build.d.ts +6 -2
  80. package/lib/commands/build.js +81 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +34 -21
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +104 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +9 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +29 -28
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +109 -101
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +101 -0
  93. package/lib/commands/swizzle/common.d.ts +33 -0
  94. package/lib/commands/swizzle/common.js +56 -0
  95. package/lib/commands/swizzle/components.d.ts +29 -0
  96. package/lib/commands/swizzle/components.js +200 -0
  97. package/lib/commands/swizzle/config.d.ts +10 -0
  98. package/lib/commands/swizzle/config.js +84 -0
  99. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  100. package/lib/commands/swizzle/context.js +24 -0
  101. package/lib/commands/swizzle/index.d.ts +8 -0
  102. package/lib/commands/swizzle/index.js +118 -0
  103. package/lib/commands/swizzle/prompts.d.ts +12 -0
  104. package/lib/commands/swizzle/prompts.js +110 -0
  105. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  106. package/lib/commands/swizzle/tables.js +113 -0
  107. package/lib/commands/swizzle/themes.d.ts +20 -0
  108. package/lib/commands/swizzle/themes.js +106 -0
  109. package/lib/commands/writeHeadingIds.d.ts +2 -6
  110. package/lib/commands/writeHeadingIds.js +22 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +46 -25
  113. package/lib/index.d.ts +9 -9
  114. package/lib/index.js +14 -14
  115. package/lib/server/brokenLinks.d.ts +4 -17
  116. package/lib/server/brokenLinks.js +67 -56
  117. package/lib/server/clientModules.d.ts +12 -0
  118. package/lib/server/clientModules.js +20 -0
  119. package/lib/server/config.d.ts +5 -2
  120. package/lib/server/config.js +29 -6
  121. package/lib/server/configValidation.d.ts +4 -4
  122. package/lib/server/configValidation.js +86 -41
  123. package/lib/server/getHostPort.d.ts +14 -0
  124. package/lib/server/getHostPort.js +79 -0
  125. package/lib/server/htmlTags.d.ts +12 -0
  126. package/lib/server/htmlTags.js +62 -0
  127. package/lib/server/i18n.d.ts +3 -13
  128. package/lib/server/i18n.js +21 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +83 -165
  131. package/lib/server/plugins/configs.d.ts +51 -0
  132. package/lib/server/plugins/configs.js +101 -0
  133. package/lib/server/plugins/index.d.ts +9 -8
  134. package/lib/server/plugins/index.js +73 -134
  135. package/lib/server/plugins/init.d.ts +6 -5
  136. package/lib/server/plugins/init.js +44 -109
  137. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  138. package/lib/server/plugins/moduleShorthand.js +46 -0
  139. package/lib/server/plugins/pluginIds.d.ts +5 -1
  140. package/lib/server/plugins/pluginIds.js +12 -7
  141. package/lib/server/plugins/presets.d.ts +12 -0
  142. package/lib/server/plugins/presets.js +49 -0
  143. package/lib/server/plugins/routeConfig.d.ts +11 -0
  144. package/lib/server/plugins/routeConfig.js +54 -0
  145. package/lib/server/plugins/synthetic.d.ts +20 -0
  146. package/lib/server/plugins/synthetic.js +111 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +182 -95
  149. package/lib/server/siteMetadata.d.ts +12 -0
  150. package/lib/server/siteMetadata.js +81 -0
  151. package/lib/server/translations/translations.d.ts +14 -19
  152. package/lib/server/translations/translations.js +40 -72
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  154. package/lib/server/translations/translationsExtractor.js +158 -122
  155. package/lib/server/utils.d.ts +9 -3
  156. package/lib/server/utils.js +7 -9
  157. package/lib/webpack/aliases/index.d.ts +34 -0
  158. package/lib/webpack/aliases/index.js +106 -0
  159. package/lib/webpack/base.d.ts +3 -4
  160. package/lib/webpack/base.js +45 -57
  161. package/lib/webpack/client.d.ts +3 -3
  162. package/lib/webpack/client.js +12 -19
  163. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  164. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  165. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  166. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  167. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  168. package/lib/webpack/plugins/LogPlugin.js +4 -5
  169. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  170. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  171. package/lib/webpack/server.d.ts +5 -5
  172. package/lib/webpack/server.js +22 -9
  173. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  174. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  175. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +61 -182
  178. package/package.json +81 -77
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.eslintrc.js +0 -29
  183. package/lib/client/.tsbuildinfo +0 -1
  184. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  185. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  186. package/lib/client/nprogress.css +0 -36
  187. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  188. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  189. package/lib/commands/commandUtils.d.ts +0 -3
  190. package/lib/commands/commandUtils.js +0 -21
  191. package/lib/commands/swizzle.d.ts +0 -9
  192. package/lib/commands/swizzle.js +0 -245
  193. package/lib/constants.d.ts +0 -18
  194. package/lib/constants.js +0 -23
  195. package/lib/server/client-modules/index.js +0 -14
  196. package/lib/server/duplicateRoutes.d.ts +0 -10
  197. package/lib/server/duplicateRoutes.js +0 -38
  198. package/lib/server/html-tags/htmlTags.js +0 -40
  199. package/lib/server/html-tags/index.d.ts +0 -9
  200. package/lib/server/html-tags/index.js +0 -43
  201. package/lib/server/loadSetup.d.ts +0 -9
  202. package/lib/server/loadSetup.js +0 -25
  203. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
  204. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  205. package/lib/server/presets/index.d.ts +0 -11
  206. package/lib/server/presets/index.js +0 -48
  207. package/lib/server/themes/alias.d.ts +0 -8
  208. package/lib/server/themes/alias.js +0 -40
  209. package/lib/server/themes/index.d.ts +0 -12
  210. package/lib/server/themes/index.js +0 -47
  211. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  212. package/lib/server/versions/__fixtures__/package.json +0 -3
  213. package/lib/server/versions/__tests/index.test.js +0 -25
  214. package/lib/server/versions/index.d.ts +0 -10
  215. package/lib/server/versions/index.js +0 -50
  216. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  217. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  218. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  219. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  220. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  221. package/lib/webpack/sharedModuleAliases.js +0 -18
  222. package/tsconfig.client.json +0 -13
  223. package/tsconfig.json +0 -13
@@ -4,9 +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
-
8
7
  import React from 'react';
9
-
10
8
  // Wrapper at the very top of the app, that is applied constantly
11
9
  // and does not depend on current route (unlike the layout)
12
10
  //
@@ -14,8 +12,6 @@ import React from 'react';
14
12
  // and these providers won't reset state when we navigate
15
13
  //
16
14
  // See https://github.com/facebook/docusaurus/issues/3919
17
- function Root({children}) {
18
- return <>{children}</>;
15
+ export default function Root({ children }) {
16
+ return <>{children}</>;
19
17
  }
20
-
21
- export default Root;
@@ -4,4 +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
- export default function htmlTagObjectToString(tagDefinition: unknown): string;
7
+ /// <reference types="react" />
8
+ export default function SiteMetadata(): JSX.Element | null;
@@ -0,0 +1,10 @@
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
+ // To be implemented by the theme with <Head>
8
+ export default function SiteMetadata() {
9
+ return null;
10
+ }
@@ -4,5 +4,9 @@
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 { BuildCLIOptions } from '@docusaurus/types';
8
- export default function build(siteDir: string, cliOptions?: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
7
+ import { type LoadContextOptions } from '../server';
8
+ export declare type BuildCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
9
+ bundleAnalyzer?: boolean;
10
+ minify?: boolean;
11
+ };
12
+ export declare function build(siteDirParam?: string, cliOptions?: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
@@ -6,29 +6,35 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.build = void 0;
9
10
  const tslib_1 = require("tslib");
10
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
11
- const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
12
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
14
16
  const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
15
17
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
16
18
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
17
- const constants_1 = require("../constants");
18
19
  const server_1 = require("../server");
19
20
  const brokenLinks_1 = require("../server/brokenLinks");
20
21
  const client_1 = tslib_1.__importDefault(require("../webpack/client"));
21
22
  const server_2 = tslib_1.__importDefault(require("../webpack/server"));
22
- const utils_1 = require("../webpack/utils");
23
+ const utils_2 = require("../webpack/utils");
23
24
  const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
24
25
  const i18n_1 = require("../server/i18n");
25
- const utils_2 = require("@docusaurus/utils");
26
- async function build(siteDir, cliOptions = {},
27
- // TODO what's the purpose of this arg ?
26
+ async function build(siteDirParam = '.', cliOptions = {},
27
+ // When running build, we force terminate the process to prevent async
28
+ // operations from never returning. However, if run as part of docusaurus
29
+ // deploy, we have to let deploy finish.
30
+ // See https://github.com/facebook/docusaurus/pull/2496
28
31
  forceTerminate = true) {
32
+ const siteDir = await fs_extra_1.default.realpath(siteDirParam);
33
+ ['SIGINT', 'SIGTERM'].forEach((sig) => {
34
+ process.on(sig, () => process.exit());
35
+ });
29
36
  async function tryToBuildLocale({ locale, isLastLocale, }) {
30
37
  try {
31
- // console.log(chalk.green(`Site successfully built in locale=${locale}`));
32
38
  return await buildLocale({
33
39
  siteDir,
34
40
  locale,
@@ -37,101 +43,110 @@ forceTerminate = true) {
37
43
  isLastLocale,
38
44
  });
39
45
  }
40
- catch (e) {
41
- console.error(`Unable to build website for locale "${locale}".`);
42
- throw e;
46
+ catch (err) {
47
+ logger_1.default.error `Unable to build website for locale name=${locale}.`;
48
+ throw err;
43
49
  }
44
50
  }
45
- const context = await server_1.loadContext(siteDir, {
46
- customOutDir: cliOptions.outDir,
47
- customConfigFilePath: cliOptions.config,
51
+ const context = await (0, server_1.loadContext)({
52
+ siteDir,
53
+ outDir: cliOptions.outDir,
54
+ config: cliOptions.config,
48
55
  locale: cliOptions.locale,
49
56
  localizePath: cliOptions.locale ? false : undefined,
50
57
  });
51
- const i18n = await i18n_1.loadI18n(context.siteConfig, {
58
+ const i18n = await (0, i18n_1.loadI18n)(context.siteConfig, {
52
59
  locale: cliOptions.locale,
53
60
  });
54
61
  if (cliOptions.locale) {
55
62
  return tryToBuildLocale({ locale: cliOptions.locale, isLastLocale: true });
56
63
  }
57
- else {
58
- if (i18n.locales.length > 1) {
59
- console.log(chalk_1.default.yellow(`\nWebsite will be built for all these locales:
60
- - ${i18n.locales.join('\n- ')}`));
61
- }
62
- // We need the default locale to always be the 1st in the list
63
- // If we build it last, it would "erase" the localized sites built in subfolders
64
- const orderedLocales = [
65
- i18n.defaultLocale,
66
- ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
67
- ];
68
- const results = await utils_2.mapAsyncSequencial(orderedLocales, (locale) => {
69
- const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
70
- return tryToBuildLocale({ locale, isLastLocale });
71
- });
72
- return results[0];
64
+ if (i18n.locales.length > 1) {
65
+ logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
73
66
  }
67
+ // We need the default locale to always be the 1st in the list. If we build it
68
+ // last, it would "erase" the localized sites built in sub-folders
69
+ const orderedLocales = [
70
+ i18n.defaultLocale,
71
+ ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
72
+ ];
73
+ const results = await (0, utils_1.mapAsyncSequential)(orderedLocales, (locale) => {
74
+ const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
75
+ return tryToBuildLocale({ locale, isLastLocale });
76
+ });
77
+ return results[0];
74
78
  }
75
- exports.default = build;
79
+ exports.build = build;
76
80
  async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
77
81
  process.env.BABEL_ENV = 'production';
78
82
  process.env.NODE_ENV = 'production';
79
- console.log(chalk_1.default.blue(`\n[${locale}] Creating an optimized production build...`));
80
- const props = await server_1.load(siteDir, {
81
- customOutDir: cliOptions.outDir,
82
- customConfigFilePath: cliOptions.config,
83
+ logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
84
+ const props = await (0, server_1.load)({
85
+ siteDir,
86
+ outDir: cliOptions.outDir,
87
+ config: cliOptions.config,
83
88
  locale,
84
89
  localizePath: cliOptions.locale ? false : undefined,
85
90
  });
86
91
  // Apply user webpack config.
87
- const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks }, routes, } = props;
92
+ const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories: staticDirectoriesOption, }, routes, } = props;
88
93
  const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
89
- let clientConfig = webpack_merge_1.default(client_1.default(props, cliOptions.minify), {
94
+ let clientConfig = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
90
95
  plugins: [
91
96
  // Remove/clean build folders before building bundles.
92
97
  new CleanWebpackPlugin_1.default({ verbose: false }),
93
- // Visualize size of webpack output files with an interactive zoomable treemap.
98
+ // Visualize size of webpack output files with an interactive zoomable
99
+ // tree map.
94
100
  cliOptions.bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
95
101
  // Generate client manifests file that will be used for server bundle.
96
102
  new react_loadable_ssr_addon_v5_slorber_1.default({
97
103
  filename: clientManifestPath,
98
104
  }),
99
- ].filter(Boolean),
105
+ ].filter((x) => Boolean(x)),
100
106
  });
101
107
  const allCollectedLinks = {};
102
- let serverConfig = server_2.default({
108
+ const headTags = {};
109
+ let serverConfig = await (0, server_2.default)({
103
110
  props,
104
111
  onLinksCollected: (staticPagePath, links) => {
105
112
  allCollectedLinks[staticPagePath] = links;
106
113
  },
114
+ onHeadTagsCollected: (staticPagePath, tags) => {
115
+ headTags[staticPagePath] = tags;
116
+ },
107
117
  });
108
- const staticDir = path_1.default.resolve(siteDir, constants_1.STATIC_DIR_NAME);
109
- if (await fs_extra_1.default.pathExists(staticDir)) {
110
- serverConfig = webpack_merge_1.default(serverConfig, {
118
+ // The staticDirectories option can contain empty directories, or non-existent
119
+ // directories (e.g. user deleted `static`). Instead of issuing an error, we
120
+ // just silently filter them out, because user could have never configured it
121
+ // in the first place (the default option should always "work").
122
+ const staticDirectories = (await Promise.all(staticDirectoriesOption.map(async (dir) => {
123
+ const staticDir = path_1.default.resolve(siteDir, dir);
124
+ if ((await fs_extra_1.default.pathExists(staticDir)) &&
125
+ (await fs_extra_1.default.readdir(staticDir)).length > 0) {
126
+ return staticDir;
127
+ }
128
+ return '';
129
+ }))).filter(Boolean);
130
+ if (staticDirectories.length > 0) {
131
+ serverConfig = (0, webpack_merge_1.default)(serverConfig, {
111
132
  plugins: [
112
133
  new copy_webpack_plugin_1.default({
113
- patterns: [
114
- {
115
- from: staticDir,
116
- to: outDir,
117
- },
118
- ],
134
+ patterns: staticDirectories.map((dir) => ({ from: dir, to: outDir })),
119
135
  }),
120
136
  ],
121
137
  });
122
138
  }
123
139
  // Plugin Lifecycle - configureWebpack and configurePostCss.
124
140
  plugins.forEach((plugin) => {
125
- var _a, _b;
126
141
  const { configureWebpack, configurePostCss } = plugin;
127
142
  if (configurePostCss) {
128
- clientConfig = utils_1.applyConfigurePostCss(configurePostCss, clientConfig);
143
+ clientConfig = (0, utils_2.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
129
144
  }
130
145
  if (configureWebpack) {
131
- clientConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
132
- clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
133
- serverConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
134
- serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
146
+ clientConfig = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
147
+ clientConfig, false, props.siteConfig.webpack?.jsLoader, plugin.content);
148
+ serverConfig = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
149
+ serverConfig, true, props.siteConfig.webpack?.jsLoader, plugin.content);
135
150
  }
136
151
  });
137
152
  // Make sure generated client-manifest is cleaned first so we don't reuse
@@ -140,11 +155,9 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
140
155
  await fs_extra_1.default.unlink(clientManifestPath);
141
156
  }
142
157
  // Run webpack to build JS bundle (client) and static html files (server).
143
- await utils_1.compile([clientConfig, serverConfig]);
158
+ await (0, utils_2.compile)([clientConfig, serverConfig]);
144
159
  // Remove server.bundle.js because it is not needed.
145
- if (serverConfig.output &&
146
- serverConfig.output.filename &&
147
- typeof serverConfig.output.filename === 'string') {
160
+ if (typeof serverConfig.output?.filename === 'string') {
148
161
  const serverBundle = path_1.default.join(outDir, serverConfig.output.filename);
149
162
  if (await fs_extra_1.default.pathExists(serverBundle)) {
150
163
  await fs_extra_1.default.unlink(serverBundle);
@@ -155,18 +168,22 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
155
168
  if (!plugin.postBuild) {
156
169
  return;
157
170
  }
158
- await plugin.postBuild(props);
171
+ await plugin.postBuild({
172
+ ...props,
173
+ head: headTags,
174
+ content: plugin.content,
175
+ });
159
176
  }));
160
- await brokenLinks_1.handleBrokenLinks({
177
+ await (0, brokenLinks_1.handleBrokenLinks)({
161
178
  allCollectedLinks,
162
179
  routes,
163
180
  onBrokenLinks,
164
181
  outDir,
165
182
  baseUrl,
166
183
  });
167
- console.log(`${chalk_1.default.green(`Success!`)} Generated static files in "${chalk_1.default.cyan(path_1.default.relative(process.cwd(), outDir))}".`);
184
+ logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
168
185
  if (isLastLocale) {
169
- console.log(`\nUse ${chalk_1.default.greenBright('`npm run serve`')} command to test your build locally.\n`);
186
+ logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
170
187
  }
171
188
  if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
172
189
  process.exit(0);
@@ -1 +1,7 @@
1
- export default function clear(siteDir: string): Promise<unknown>;
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
+ export declare function clear(siteDirParam?: string): Promise<void>;
@@ -1,32 +1,45 @@
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
  */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.clear = void 0;
10
+ const tslib_1 = require("tslib");
10
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
12
  const path_1 = tslib_1.__importDefault(require("path"));
12
- const chalk = require("chalk");
13
- const constants_1 = require("../constants");
14
- function removePath(fsPath) {
15
- return fs_extra_1.default
16
- .remove(path_1.default.join(fsPath))
17
- .then(() => {
18
- console.log(chalk.green(`Successfully removed "${fsPath}" directory.`));
19
- })
20
- .catch((err) => {
21
- console.error(`Could not remove ${fsPath} directory.`);
22
- console.error(err);
23
- });
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ async function removePath(entry) {
16
+ if (!(await fs_extra_1.default.pathExists(entry.path))) {
17
+ return;
18
+ }
19
+ try {
20
+ await fs_extra_1.default.remove(entry.path);
21
+ logger_1.default.success `Removed the ${entry.description} at path=${entry.path}.`;
22
+ }
23
+ catch (err) {
24
+ logger_1.default.error `Could not remove the ${entry.description} at path=${entry.path}.`;
25
+ logger_1.default.error(err);
26
+ }
24
27
  }
25
- async function clear(siteDir) {
26
- return Promise.all([
27
- removePath(path_1.default.join(siteDir, constants_1.GENERATED_FILES_DIR_NAME)),
28
- removePath(path_1.default.join(siteDir, constants_1.DEFAULT_BUILD_DIR_NAME)),
29
- removePath(path_1.default.join(siteDir, 'node_modules', '.cache')),
30
- ]);
28
+ async function clear(siteDirParam = '.') {
29
+ const siteDir = await fs_extra_1.default.realpath(siteDirParam);
30
+ const generatedFolder = {
31
+ path: path_1.default.join(siteDir, utils_1.GENERATED_FILES_DIR_NAME),
32
+ description: 'generated folder',
33
+ };
34
+ const buildFolder = {
35
+ path: path_1.default.join(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME),
36
+ description: 'build output folder',
37
+ };
38
+ // In Yarn PnP, cache is stored in `.yarn/.cache` because n_m doesn't exist
39
+ const cacheFolders = ['node_modules', '.yarn'].map((p) => ({
40
+ path: path_1.default.join(siteDir, p, '.cache'),
41
+ description: 'Webpack persistent cache folder',
42
+ }));
43
+ await Promise.all([generatedFolder, buildFolder, ...cacheFolders].map(removePath));
31
44
  }
32
- exports.default = clear;
45
+ exports.clear = clear;
@@ -4,5 +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 { BuildCLIOptions } from '@docusaurus/types';
8
- export default function deploy(siteDir: string, cliOptions?: Partial<BuildCLIOptions>): Promise<void>;
7
+ import { type LoadContextOptions } from '../server';
8
+ export declare type DeployCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
9
+ skipBuild?: boolean;
10
+ };
11
+ export declare function deploy(siteDirParam?: string, cliOptions?: Partial<DeployCLIOptions>): Promise<void>;