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

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 (171) hide show
  1. package/bin/beforeCli.mjs +14 -12
  2. package/bin/docusaurus.mjs +41 -93
  3. package/lib/babel/preset.js +2 -2
  4. package/lib/client/.eslintrc.js +2 -3
  5. package/lib/client/App.d.ts +1 -1
  6. package/lib/client/App.js +15 -7
  7. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
  8. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
  9. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  10. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  11. package/lib/client/ClientLifecyclesDispatcher.js +34 -0
  12. package/lib/client/LinksCollector.d.ts +1 -1
  13. package/lib/client/LinksCollector.js +4 -5
  14. package/lib/client/PendingNavigation.d.ts +8 -17
  15. package/lib/client/PendingNavigation.js +39 -70
  16. package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
  17. package/lib/client/SiteMetadataDefaults.js +19 -0
  18. package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
  19. package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
  20. package/lib/client/clientEntry.js +3 -4
  21. package/lib/client/docusaurus.d.ts +5 -5
  22. package/lib/client/docusaurus.js +26 -33
  23. package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
  24. package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
  25. package/lib/client/exports/BrowserOnly.d.ts +3 -4
  26. package/lib/client/exports/BrowserOnly.js +2 -2
  27. package/lib/client/exports/ComponentCreator.js +65 -40
  28. package/lib/client/exports/ErrorBoundary.d.ts +2 -2
  29. package/lib/client/exports/ErrorBoundary.js +4 -5
  30. package/lib/client/exports/Interpolate.d.ts +1 -1
  31. package/lib/client/exports/Interpolate.js +18 -41
  32. package/lib/client/exports/Link.d.ts +3 -15
  33. package/lib/client/exports/Link.js +24 -30
  34. package/lib/client/exports/Translate.d.ts +2 -2
  35. package/lib/client/exports/Translate.js +3 -3
  36. package/lib/client/exports/useBaseUrl.js +8 -9
  37. package/lib/client/exports/useDocusaurusContext.js +1 -1
  38. package/lib/client/exports/useGlobalData.d.ts +4 -3
  39. package/lib/client/exports/useGlobalData.js +5 -5
  40. package/lib/client/exports/useIsBrowser.js +1 -1
  41. package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
  42. package/lib/client/exports/useRouteContext.js +15 -0
  43. package/lib/client/flat.d.ts +12 -2
  44. package/lib/client/flat.js +12 -5
  45. package/lib/client/normalizeLocation.js +13 -8
  46. package/lib/client/prefetch.js +10 -28
  47. package/lib/client/preload.d.ts +1 -3
  48. package/lib/client/preload.js +5 -11
  49. package/lib/client/routeContext.d.ts +13 -0
  50. package/lib/client/routeContext.js +31 -0
  51. package/lib/client/serverEntry.js +19 -18
  52. package/lib/client/theme-fallback/Error/index.js +7 -1
  53. package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
  54. package/lib/client/theme-fallback/Layout/index.js +2 -17
  55. package/lib/client/theme-fallback/Loading/index.js +2 -0
  56. package/lib/client/theme-fallback/NotFound/index.js +13 -5
  57. package/lib/client/theme-fallback/Root/index.d.ts +4 -4
  58. package/lib/client/theme-fallback/Root/index.js +2 -1
  59. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  60. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  61. package/lib/commands/build.d.ts +6 -2
  62. package/lib/commands/build.js +48 -30
  63. package/lib/commands/clear.d.ts +1 -1
  64. package/lib/commands/clear.js +6 -5
  65. package/lib/commands/deploy.d.ts +5 -5
  66. package/lib/commands/deploy.js +21 -45
  67. package/lib/commands/external.d.ts +1 -1
  68. package/lib/commands/external.js +6 -11
  69. package/lib/commands/serve.d.ts +7 -2
  70. package/lib/commands/serve.js +18 -19
  71. package/lib/commands/start.d.ts +8 -2
  72. package/lib/commands/start.js +33 -30
  73. package/lib/commands/swizzle/actions.d.ts +2 -2
  74. package/lib/commands/swizzle/actions.js +10 -10
  75. package/lib/commands/swizzle/common.d.ts +3 -3
  76. package/lib/commands/swizzle/common.js +8 -9
  77. package/lib/commands/swizzle/components.js +48 -13
  78. package/lib/commands/swizzle/config.js +21 -15
  79. package/lib/commands/swizzle/context.js +6 -12
  80. package/lib/commands/swizzle/index.d.ts +2 -2
  81. package/lib/commands/swizzle/index.js +5 -4
  82. package/lib/commands/swizzle/prompts.js +2 -2
  83. package/lib/commands/swizzle/tables.js +10 -13
  84. package/lib/commands/swizzle/themes.js +9 -8
  85. package/lib/commands/writeHeadingIds.d.ts +2 -9
  86. package/lib/commands/writeHeadingIds.js +11 -69
  87. package/lib/commands/writeTranslations.d.ts +3 -4
  88. package/lib/commands/writeTranslations.js +10 -14
  89. package/lib/index.d.ts +9 -10
  90. package/lib/index.js +18 -19
  91. package/lib/server/brokenLinks.d.ts +3 -16
  92. package/lib/server/brokenLinks.js +37 -31
  93. package/lib/server/clientModules.d.ts +12 -0
  94. package/lib/server/clientModules.js +20 -0
  95. package/lib/server/config.d.ts +5 -2
  96. package/lib/server/config.js +14 -9
  97. package/lib/server/configValidation.d.ts +1 -1
  98. package/lib/server/configValidation.js +39 -13
  99. package/lib/server/getHostPort.d.ts +14 -0
  100. package/lib/{choosePort.js → server/getHostPort.js} +24 -41
  101. package/lib/server/htmlTags.d.ts +12 -0
  102. package/lib/server/htmlTags.js +62 -0
  103. package/lib/server/i18n.d.ts +2 -11
  104. package/lib/server/i18n.js +7 -28
  105. package/lib/server/index.d.ts +28 -13
  106. package/lib/server/index.js +62 -229
  107. package/lib/server/plugins/configs.d.ts +51 -0
  108. package/lib/server/plugins/configs.js +101 -0
  109. package/lib/server/plugins/index.d.ts +9 -8
  110. package/lib/server/plugins/index.js +65 -132
  111. package/lib/server/plugins/init.d.ts +6 -15
  112. package/lib/server/plugins/init.js +25 -83
  113. package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
  114. package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
  115. package/lib/server/plugins/pluginIds.d.ts +4 -0
  116. package/lib/server/plugins/pluginIds.js +6 -4
  117. package/lib/server/plugins/presets.d.ts +12 -0
  118. package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
  119. package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
  120. package/lib/server/plugins/routeConfig.js +54 -0
  121. package/lib/server/plugins/synthetic.d.ts +20 -0
  122. package/lib/server/plugins/synthetic.js +112 -0
  123. package/lib/server/routes.d.ts +39 -7
  124. package/lib/server/routes.js +169 -102
  125. package/lib/server/siteMetadata.d.ts +12 -0
  126. package/lib/server/siteMetadata.js +81 -0
  127. package/lib/server/translations/translations.d.ts +5 -14
  128. package/lib/server/translations/translations.js +23 -39
  129. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  130. package/lib/server/translations/translationsExtractor.js +16 -19
  131. package/lib/server/utils.js +1 -1
  132. package/lib/webpack/aliases/index.d.ts +34 -0
  133. package/lib/webpack/aliases/index.js +106 -0
  134. package/lib/webpack/base.d.ts +0 -1
  135. package/lib/webpack/base.js +12 -30
  136. package/lib/webpack/client.js +7 -8
  137. package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
  138. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
  139. package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
  140. package/lib/webpack/plugins/LogPlugin.js +2 -2
  141. package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
  142. package/lib/webpack/plugins/WaitPlugin.js +3 -3
  143. package/lib/webpack/server.d.ts +2 -2
  144. package/lib/webpack/server.js +10 -8
  145. package/lib/webpack/utils.d.ts +9 -3
  146. package/lib/webpack/utils.js +20 -25
  147. package/package.json +38 -41
  148. package/lib/choosePort.d.ts +0 -11
  149. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
  150. package/lib/client/client-lifecycles-dispatcher.js +0 -23
  151. package/lib/client/nprogress.css +0 -36
  152. package/lib/commands/commandUtils.d.ts +0 -9
  153. package/lib/commands/commandUtils.js +0 -21
  154. package/lib/server/client-modules/index.js +0 -12
  155. package/lib/server/duplicateRoutes.d.ts +0 -10
  156. package/lib/server/duplicateRoutes.js +0 -42
  157. package/lib/server/html-tags/htmlTags.js +0 -38
  158. package/lib/server/html-tags/index.d.ts +0 -9
  159. package/lib/server/html-tags/index.js +0 -43
  160. package/lib/server/loadSetup.js +0 -25
  161. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  162. package/lib/server/presets/index.d.ts +0 -11
  163. package/lib/server/themes/alias.d.ts +0 -9
  164. package/lib/server/themes/alias.js +0 -48
  165. package/lib/server/themes/index.d.ts +0 -12
  166. package/lib/server/themes/index.js +0 -47
  167. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  168. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  169. package/lib/server/versions/__fixtures__/package.json +0 -3
  170. package/lib/server/versions/index.d.ts +0 -9
  171. package/lib/server/versions/index.js +0 -51
@@ -4,9 +4,12 @@
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
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  import Layout from '@theme/Layout';
9
11
  import ErrorBoundary from '@docusaurus/ErrorBoundary';
12
+ import Head from '@docusaurus/Head';
10
13
  function ErrorDisplay({ error, tryAgain }) {
11
14
  return (<div style={{
12
15
  display: 'flex',
@@ -32,7 +35,10 @@ export default function Error({ error, tryAgain }) {
32
35
  // Note: we display the original error here, not the error that we
33
36
  // captured in this extra error boundary
34
37
  fallback={() => <ErrorDisplay error={error} tryAgain={tryAgain}/>}>
35
- <Layout title="Page Error">
38
+ <Head>
39
+ <title>Page Error</title>
40
+ </Head>
41
+ <Layout>
36
42
  <ErrorDisplay error={error} tryAgain={tryAgain}/>
37
43
  </Layout>
38
44
  </ErrorBoundary>);
@@ -7,4 +7,4 @@
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
8
  /// <reference types="react" />
9
9
  import type { Props } from '@theme/Layout';
10
- export default function Layout({ children, title, description, }: Props): JSX.Element;
10
+ export default function Layout({ children }: Props): JSX.Element;
@@ -5,21 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import Head from '@docusaurus/Head';
9
- import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
- import useBaseUrl from '@docusaurus/useBaseUrl';
11
- export default function Layout({ children, title, description, }) {
12
- const context = useDocusaurusContext();
13
- const { siteConfig } = context;
14
- const { favicon, tagline, title: defaultTitle } = siteConfig;
15
- const faviconUrl = useBaseUrl(favicon);
16
- return (<>
17
- <Head defaultTitle={`${defaultTitle}${tagline ? ` · ${tagline}` : ''}`}>
18
- {title && <title>{`${title} · ${tagline}`}</title>}
19
- {favicon && <link rel="icon" href={faviconUrl}/>}
20
- {description && <meta name="description" content={description}/>}
21
- {description && (<meta property="og:description" content={description}/>)}
22
- </Head>
23
- {children}
24
- </>);
8
+ export default function Layout({ children }) {
9
+ return <>{children}</>;
25
10
  }
@@ -4,6 +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
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  export default function Loading({ error, retry, pastDelay, }) {
9
11
  if (error) {
@@ -4,18 +4,26 @@
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
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  import Layout from '@theme/Layout';
11
+ import Head from '@docusaurus/Head';
9
12
  export default function NotFound() {
10
- return (<Layout title="Page Not Found">
11
- <div style={{
13
+ return (<>
14
+ <Head>
15
+ <title>Page Not Found</title>
16
+ </Head>
17
+ <Layout>
18
+ <div style={{
12
19
  display: 'flex',
13
20
  justifyContent: 'center',
14
21
  alignItems: 'center',
15
22
  height: '50vh',
16
23
  fontSize: '20px',
17
24
  }}>
18
- <h1>Oops, page not found </h1>
19
- </div>
20
- </Layout>);
25
+ <h1>Oops, page not found </h1>
26
+ </div>
27
+ </Layout>
28
+ </>);
21
29
  }
@@ -4,7 +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 { ReactNode } from 'react';
8
- export default function Root({ children }: {
9
- children: ReactNode;
10
- }): ReactNode;
7
+ /// <reference types="@docusaurus/module-type-aliases" />
8
+ /// <reference types="react" />
9
+ import type { Props } from '@theme/Root';
10
+ export default function Root({ children }: Props): JSX.Element;
@@ -4,6 +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 React from 'react';
7
8
  // Wrapper at the very top of the app, that is applied constantly
8
9
  // and does not depend on current route (unlike the layout)
9
10
  //
@@ -12,5 +13,5 @@
12
13
  //
13
14
  // See https://github.com/facebook/docusaurus/issues/3919
14
15
  export default function Root({ children }) {
15
- return children;
16
+ return <>{children}</>;
16
17
  }
@@ -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 type { 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(siteDir: string, cliOptions: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
@@ -6,23 +6,24 @@
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 logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
- const copy_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("copy-webpack-plugin"));
12
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
- const react_loadable_ssr_addon_v5_slorber_1 = (0, tslib_1.__importDefault)(require("react-loadable-ssr-addon-v5-slorber"));
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
+ const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
13
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
+ const path_1 = tslib_1.__importDefault(require("path"));
15
+ const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
15
16
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
16
- const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
17
+ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
17
18
  const server_1 = require("../server");
18
19
  const brokenLinks_1 = require("../server/brokenLinks");
19
- const client_1 = (0, tslib_1.__importDefault)(require("../webpack/client"));
20
- const server_2 = (0, tslib_1.__importDefault)(require("../webpack/server"));
20
+ const client_1 = tslib_1.__importDefault(require("../webpack/client"));
21
+ const server_2 = tslib_1.__importDefault(require("../webpack/server"));
21
22
  const utils_1 = require("../webpack/utils");
22
- const CleanWebpackPlugin_1 = (0, tslib_1.__importDefault)(require("../webpack/plugins/CleanWebpackPlugin"));
23
+ const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
23
24
  const i18n_1 = require("../server/i18n");
24
25
  const utils_2 = require("@docusaurus/utils");
25
- async function build(siteDir, cliOptions = {},
26
+ async function build(siteDir, cliOptions,
26
27
  // When running build, we force terminate the process to prevent async
27
28
  // operations from never returning. However, if run as part of docusaurus
28
29
  // deploy, we have to let deploy finish.
@@ -46,9 +47,10 @@ forceTerminate = true) {
46
47
  throw err;
47
48
  }
48
49
  }
49
- const context = await (0, server_1.loadContext)(siteDir, {
50
- customOutDir: cliOptions.outDir,
51
- customConfigFilePath: cliOptions.config,
50
+ const context = await (0, server_1.loadContext)({
51
+ siteDir,
52
+ outDir: cliOptions.outDir,
53
+ config: cliOptions.config,
52
54
  locale: cliOptions.locale,
53
55
  localizePath: cliOptions.locale ? false : undefined,
54
56
  });
@@ -73,20 +75,20 @@ forceTerminate = true) {
73
75
  });
74
76
  return results[0];
75
77
  }
76
- exports.default = build;
78
+ exports.build = build;
77
79
  async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
78
- var _a;
79
80
  process.env.BABEL_ENV = 'production';
80
81
  process.env.NODE_ENV = 'production';
81
82
  logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
82
- const props = await (0, server_1.load)(siteDir, {
83
- customOutDir: cliOptions.outDir,
84
- customConfigFilePath: cliOptions.config,
83
+ const props = await (0, server_1.load)({
84
+ siteDir,
85
+ outDir: cliOptions.outDir,
86
+ config: cliOptions.config,
85
87
  locale,
86
88
  localizePath: cliOptions.locale ? false : undefined,
87
89
  });
88
90
  // Apply user webpack config.
89
- const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories }, routes, } = props;
91
+ const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories: staticDirectoriesOption, }, routes, } = props;
90
92
  const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
91
93
  let clientConfig = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
92
94
  plugins: [
@@ -99,39 +101,51 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
99
101
  new react_loadable_ssr_addon_v5_slorber_1.default({
100
102
  filename: clientManifestPath,
101
103
  }),
102
- ].filter(Boolean),
104
+ ].filter((x) => Boolean(x)),
103
105
  });
104
106
  const allCollectedLinks = {};
107
+ const headTags = {};
105
108
  let serverConfig = await (0, server_2.default)({
106
109
  props,
107
110
  onLinksCollected: (staticPagePath, links) => {
108
111
  allCollectedLinks[staticPagePath] = links;
109
112
  },
113
+ onHeadTagsCollected: (staticPagePath, tags) => {
114
+ headTags[staticPagePath] = tags;
115
+ },
110
116
  });
117
+ // The staticDirectories option can contain empty directories, or non-existent
118
+ // directories (e.g. user deleted `static`). Instead of issuing an error, we
119
+ // just silently filter them out, because user could have never configured it
120
+ // in the first place (the default option should always "work").
121
+ const staticDirectories = (await Promise.all(staticDirectoriesOption.map(async (dir) => {
122
+ const staticDir = path_1.default.resolve(siteDir, dir);
123
+ if ((await fs_extra_1.default.pathExists(staticDir)) &&
124
+ (await fs_extra_1.default.readdir(staticDir)).length > 0) {
125
+ return staticDir;
126
+ }
127
+ return '';
128
+ }))).filter(Boolean);
111
129
  if (staticDirectories.length > 0) {
112
- await Promise.all(staticDirectories.map((dir) => fs_extra_1.default.ensureDir(dir)));
113
130
  serverConfig = (0, webpack_merge_1.default)(serverConfig, {
114
131
  plugins: [
115
132
  new copy_webpack_plugin_1.default({
116
- patterns: staticDirectories
117
- .map((dir) => path_1.default.resolve(siteDir, dir))
118
- .map((dir) => ({ from: dir, to: outDir })),
133
+ patterns: staticDirectories.map((dir) => ({ from: dir, to: outDir })),
119
134
  }),
120
135
  ],
121
136
  });
122
137
  }
123
138
  // Plugin Lifecycle - configureWebpack and configurePostCss.
124
139
  plugins.forEach((plugin) => {
125
- var _a, _b;
126
140
  const { configureWebpack, configurePostCss } = plugin;
127
141
  if (configurePostCss) {
128
- clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
142
+ clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
129
143
  }
130
144
  if (configureWebpack) {
131
145
  clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
132
- clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
146
+ clientConfig, false, props.siteConfig.webpack?.jsLoader, plugin.content);
133
147
  serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
134
- serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
148
+ serverConfig, true, props.siteConfig.webpack?.jsLoader, plugin.content);
135
149
  }
136
150
  });
137
151
  // Make sure generated client-manifest is cleaned first so we don't reuse
@@ -142,7 +156,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
142
156
  // Run webpack to build JS bundle (client) and static html files (server).
143
157
  await (0, utils_1.compile)([clientConfig, serverConfig]);
144
158
  // Remove server.bundle.js because it is not needed.
145
- if (typeof ((_a = serverConfig.output) === null || _a === void 0 ? void 0 : _a.filename) === 'string') {
159
+ if (typeof serverConfig.output?.filename === 'string') {
146
160
  const serverBundle = path_1.default.join(outDir, serverConfig.output.filename);
147
161
  if (await fs_extra_1.default.pathExists(serverBundle)) {
148
162
  await fs_extra_1.default.unlink(serverBundle);
@@ -153,7 +167,11 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
153
167
  if (!plugin.postBuild) {
154
168
  return;
155
169
  }
156
- await plugin.postBuild({ ...props, content: plugin.content });
170
+ await plugin.postBuild({
171
+ ...props,
172
+ head: headTags,
173
+ content: plugin.content,
174
+ });
157
175
  }));
158
176
  await (0, brokenLinks_1.handleBrokenLinks)({
159
177
  allCollectedLinks,
@@ -4,4 +4,4 @@
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 clear(siteDir: string): Promise<unknown>;
7
+ export declare function clear(siteDir: string): Promise<void>;
@@ -6,10 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.clear = void 0;
9
10
  const tslib_1 = require("tslib");
10
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
14
  const utils_1 = require("@docusaurus/utils");
14
15
  async function removePath(entry) {
15
16
  if (!(await fs_extra_1.default.pathExists(entry.path))) {
@@ -38,6 +39,6 @@ async function clear(siteDir) {
38
39
  path: path_1.default.join(siteDir, p, '.cache'),
39
40
  description: 'Webpack persistent cache folder',
40
41
  }));
41
- return Promise.all([generatedFolder, buildFolder, ...cacheFolders].map(removePath));
42
+ await Promise.all([generatedFolder, buildFolder, ...cacheFolders].map(removePath));
42
43
  }
43
- exports.default = clear;
44
+ exports.clear = clear;
@@ -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 type { BuildCLIOptions } from '@docusaurus/types';
8
- export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
9
- export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
10
- export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
11
- 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(siteDir: string, cliOptions: Partial<DeployCLIOptions>): Promise<void>;
@@ -6,15 +6,16 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = void 0;
9
+ exports.deploy = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
13
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
14
15
  const server_1 = require("../server");
15
- const build_1 = (0, tslib_1.__importDefault)(require("./build"));
16
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
17
- const os_1 = (0, tslib_1.__importDefault)(require("os"));
16
+ const build_1 = require("./build");
17
+ const path_1 = tslib_1.__importDefault(require("path"));
18
+ const os_1 = tslib_1.__importDefault(require("os"));
18
19
  // GIT_PASS env variable should not appear in logs
19
20
  function obfuscateGitPass(str) {
20
21
  const gitPass = process.env.GIT_PASS;
@@ -33,37 +34,11 @@ function shellExecLog(cmd) {
33
34
  throw err;
34
35
  }
35
36
  }
36
- function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
37
- if (githubPort) {
38
- return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
39
- }
40
- return `git@${githubHost}:${organizationName}/${projectName}.git`;
41
- }
42
- exports.buildSshUrl = buildSshUrl;
43
- function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
44
- if (githubPort) {
45
- return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
46
- }
47
- return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
48
- }
49
- exports.buildHttpsUrl = buildHttpsUrl;
50
- function hasSSHProtocol(sourceRepoUrl) {
51
- try {
52
- if (new URL(sourceRepoUrl).protocol === 'ssh:') {
53
- return true;
54
- }
55
- return false;
56
- }
57
- catch {
58
- // Fails when there isn't a protocol
59
- return /^(?:[\w-]+@)?[\w.-]+:[\w./_-]+/.test(sourceRepoUrl); // git@github.com:facebook/docusaurus.git
60
- }
61
- }
62
- exports.hasSSHProtocol = hasSSHProtocol;
63
- async function deploy(siteDir, cliOptions = {}) {
64
- const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)(siteDir, {
65
- customConfigFilePath: cliOptions.config,
66
- customOutDir: cliOptions.outDir,
37
+ async function deploy(siteDir, cliOptions) {
38
+ const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)({
39
+ siteDir,
40
+ config: cliOptions.config,
41
+ outDir: cliOptions.outDir,
67
42
  });
68
43
  if (typeof siteConfig.trailingSlash === 'undefined') {
69
44
  logger_1.default.warn(`When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
@@ -87,7 +62,7 @@ This behavior can have SEO impacts and create relative link issues.
87
62
  process.env.USE_SSH.toLowerCase() === 'true';
88
63
  if (!gitUser && !useSSH) {
89
64
  // If USE_SSH is unspecified: try inferring from repo URL
90
- if (process.env.USE_SSH === undefined && hasSSHProtocol(sourceRepoUrl)) {
65
+ if (process.env.USE_SSH === undefined && (0, utils_1.hasSSHProtocol)(sourceRepoUrl)) {
91
66
  useSSH = true;
92
67
  }
93
68
  else {
@@ -114,8 +89,9 @@ This behavior can have SEO impacts and create relative link issues.
114
89
  shelljs_1.default.echo('Skipping deploy on a pull request.');
115
90
  shelljs_1.default.exit(0);
116
91
  }
117
- // github.io indicates organization repos that deploy via default branch.
118
- // All others use gh-pages. Organization deploys looks like:
92
+ // github.io indicates organization repos that deploy via default branch. All
93
+ // others use gh-pages (either case can be configured actually, but we can
94
+ // make educated guesses). Organization deploys look like:
119
95
  // - Git repo: https://github.com/<organization>/<organization>.github.io
120
96
  // - Site url: https://<organization>.github.io
121
97
  const isGitHubPagesOrganizationDeploy = projectName.includes('.github.io');
@@ -132,12 +108,12 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
132
108
  const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort;
133
109
  let deploymentRepoURL;
134
110
  if (useSSH) {
135
- deploymentRepoURL = buildSshUrl(githubHost, organizationName, projectName, githubPort);
111
+ deploymentRepoURL = (0, utils_1.buildSshUrl)(githubHost, organizationName, projectName, githubPort);
136
112
  }
137
113
  else {
138
114
  const gitPass = process.env.GIT_PASS;
139
115
  const gitCredentials = gitPass ? `${gitUser}:${gitPass}` : gitUser;
140
- deploymentRepoURL = buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort);
116
+ deploymentRepoURL = (0, utils_1.buildHttpsUrl)(gitCredentials, githubHost, organizationName, projectName, githubPort);
141
117
  }
142
118
  logger_1.default.info `Remote repo URL: name=${obfuscateGitPass(deploymentRepoURL)}`;
143
119
  // Check if this is a cross-repo publish.
@@ -199,7 +175,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
199
175
  if (!cliOptions.skipBuild) {
200
176
  // Build site, then push to deploymentBranch branch of specified repo.
201
177
  try {
202
- await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
178
+ await (0, build_1.build)(siteDir, cliOptions, false).then(runDeploy);
203
179
  }
204
180
  catch (err) {
205
181
  logger_1.default.error('Deployment of the build output failed.');
@@ -211,4 +187,4 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
211
187
  await runDeploy(outDir);
212
188
  }
213
189
  }
214
- exports.default = deploy;
190
+ exports.deploy = deploy;
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { CommanderStatic } from 'commander';
8
- export default function externalCommand(cli: CommanderStatic, siteDir: string): Promise<void>;
8
+ export declare function externalCommand(cli: CommanderStatic, siteDir: string): Promise<void>;
@@ -6,20 +6,15 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
9
+ exports.externalCommand = void 0;
10
10
  const server_1 = require("../server");
11
- const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
11
+ const init_1 = require("../server/plugins/init");
12
12
  async function externalCommand(cli, siteDir) {
13
- const context = await (0, server_1.loadContext)(siteDir);
14
- const pluginConfigs = await (0, server_1.loadPluginConfigs)(context);
15
- const plugins = await (0, init_1.default)({ pluginConfigs, context });
13
+ const context = await (0, server_1.loadContext)({ siteDir });
14
+ const plugins = await (0, init_1.initPlugins)(context);
16
15
  // Plugin Lifecycle - extendCli.
17
16
  plugins.forEach((plugin) => {
18
- const { extendCli } = plugin;
19
- if (!extendCli) {
20
- return;
21
- }
22
- extendCli(cli);
17
+ plugin.extendCli?.(cli);
23
18
  });
24
19
  }
25
- exports.default = externalCommand;
20
+ exports.externalCommand = externalCommand;
@@ -4,5 +4,10 @@
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 { ServeCLIOptions } from '@docusaurus/types';
8
- export default function serve(siteDir: string, cliOptions: ServeCLIOptions): Promise<void>;
7
+ import type { LoadContextOptions } from '../server';
8
+ import { type HostPortOptions } from '../server/getHostPort';
9
+ export declare type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
10
+ dir?: string;
11
+ build?: boolean;
12
+ };
13
+ export declare function serve(siteDir: string, cliOptions: Partial<ServeCLIOptions>): Promise<void>;
@@ -6,38 +6,37 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.serve = void 0;
9
10
  const tslib_1 = require("tslib");
10
- const http_1 = (0, tslib_1.__importDefault)(require("http"));
11
- const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
12
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
- const server_1 = require("../server");
15
- const build_1 = (0, tslib_1.__importDefault)(require("./build"));
16
- const commandUtils_1 = require("./commandUtils");
11
+ const http_1 = tslib_1.__importDefault(require("http"));
12
+ const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const path_1 = tslib_1.__importDefault(require("path"));
15
+ const config_1 = require("../server/config");
16
+ const build_1 = require("./build");
17
+ const getHostPort_1 = require("../server/getHostPort");
18
+ const utils_1 = require("@docusaurus/utils");
17
19
  async function serve(siteDir, cliOptions) {
18
- let dir = path_1.default.isAbsolute(cliOptions.dir)
19
- ? cliOptions.dir
20
- : path_1.default.join(siteDir, cliOptions.dir);
20
+ const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
21
+ let dir = path_1.default.resolve(siteDir, buildDir);
21
22
  if (cliOptions.build) {
22
- dir = await (0, build_1.default)(siteDir, {
23
+ dir = await (0, build_1.build)(siteDir, {
23
24
  config: cliOptions.config,
24
25
  outDir: dir,
25
26
  }, false);
26
27
  }
27
- const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
28
- const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
28
+ const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
29
29
  if (port === null) {
30
30
  process.exit();
31
31
  }
32
- const { siteConfig: { baseUrl, trailingSlash }, } = await (0, server_1.loadSiteConfig)({
32
+ const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
33
33
  siteDir,
34
34
  customConfigFilePath: cliOptions.config,
35
35
  });
36
36
  const servingUrl = `http://${host}:${port}`;
37
37
  const server = http_1.default.createServer((req, res) => {
38
- var _a, _b;
39
38
  // Automatically redirect requests to /baseUrl/
40
- if (!((_a = req.url) === null || _a === void 0 ? void 0 : _a.startsWith(baseUrl))) {
39
+ if (!req.url?.startsWith(baseUrl)) {
41
40
  res.writeHead(302, {
42
41
  Location: baseUrl,
43
42
  });
@@ -46,7 +45,7 @@ async function serve(siteDir, cliOptions) {
46
45
  }
47
46
  // Remove baseUrl before calling serveHandler, because /baseUrl/ should
48
47
  // serve /build/index.html, not /build/baseUrl/index.html (does not exist)
49
- req.url = (_b = req.url) === null || _b === void 0 ? void 0 : _b.replace(baseUrl, '/');
48
+ req.url = req.url?.replace(baseUrl, '/');
50
49
  (0, serve_handler_1.default)(req, res, {
51
50
  cleanUrls: true,
52
51
  public: dir,
@@ -54,7 +53,7 @@ async function serve(siteDir, cliOptions) {
54
53
  directoryListing: false,
55
54
  });
56
55
  });
57
- logger_1.default.success `Serving path=${cliOptions.dir} directory at path=${servingUrl + baseUrl}.`;
56
+ logger_1.default.success `Serving path=${buildDir} directory at url=${servingUrl + baseUrl}.`;
58
57
  server.listen(port);
59
58
  }
60
- exports.default = serve;
59
+ exports.serve = serve;
@@ -4,5 +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 { StartCLIOptions } from '@docusaurus/types';
8
- export default function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;
7
+ import { type LoadContextOptions } from '../server';
8
+ import { type HostPortOptions } from '../server/getHostPort';
9
+ export declare type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'locale' | 'config'> & {
10
+ hotOnly?: boolean;
11
+ open?: boolean;
12
+ poll?: boolean | number;
13
+ };
14
+ export declare function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;