@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18

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 (200) hide show
  1. package/bin/beforeCli.mjs +133 -0
  2. package/bin/docusaurus.mjs +279 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +31 -43
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +23 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +7 -11
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
  14. package/lib/client/SiteMetadataDefaults.js +19 -0
  15. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  16. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  17. package/lib/client/browserContext.d.ts +11 -0
  18. package/lib/client/browserContext.js +22 -0
  19. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  20. package/lib/client/client-lifecycles-dispatcher.js +6 -10
  21. package/lib/client/clientEntry.js +13 -7
  22. package/lib/client/docusaurus.d.ts +6 -0
  23. package/lib/client/docusaurus.js +16 -25
  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 +2 -3
  27. package/lib/client/exports/BrowserOnly.js +14 -7
  28. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  29. package/lib/client/exports/ComponentCreator.js +40 -19
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +35 -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 -26
  36. package/lib/client/exports/Link.d.ts +11 -5
  37. package/lib/client/exports/Link.js +31 -20
  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 +8 -5
  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 +4 -8
  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/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +4 -2
  56. package/lib/client/flat.js +9 -13
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +2 -7
  59. package/lib/client/nprogress.css +2 -2
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +4 -6
  62. package/lib/client/preload.d.ts +3 -2
  63. package/lib/client/preload.js +5 -10
  64. package/lib/client/routeContext.d.ts +13 -0
  65. package/lib/client/routeContext.js +31 -0
  66. package/lib/client/serverEntry.d.ts +10 -0
  67. package/lib/client/serverEntry.js +90 -142
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +43 -0
  70. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  71. package/lib/client/theme-fallback/Layout/index.js +2 -26
  72. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  73. package/lib/client/theme-fallback/Loading/index.js +47 -115
  74. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  75. package/lib/client/theme-fallback/NotFound/index.js +17 -18
  76. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  77. package/lib/client/theme-fallback/Root/index.js +2 -6
  78. package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +1 -1
  81. package/lib/commands/build.js +50 -54
  82. package/lib/commands/clear.d.ts +6 -0
  83. package/lib/commands/clear.js +30 -19
  84. package/lib/commands/commandUtils.d.ts +7 -1
  85. package/lib/commands/commandUtils.js +7 -7
  86. package/lib/commands/deploy.d.ts +1 -1
  87. package/lib/commands/deploy.js +83 -66
  88. package/lib/commands/external.d.ts +2 -2
  89. package/lib/commands/external.js +4 -8
  90. package/lib/commands/serve.d.ts +1 -1
  91. package/lib/commands/serve.js +25 -12
  92. package/lib/commands/start.d.ts +1 -1
  93. package/lib/commands/start.js +96 -87
  94. package/lib/commands/swizzle/actions.d.ts +23 -0
  95. package/lib/commands/swizzle/actions.js +101 -0
  96. package/lib/commands/swizzle/common.d.ts +33 -0
  97. package/lib/commands/swizzle/common.js +56 -0
  98. package/lib/commands/swizzle/components.d.ts +29 -0
  99. package/lib/commands/swizzle/components.js +162 -0
  100. package/lib/commands/swizzle/config.d.ts +10 -0
  101. package/lib/commands/swizzle/config.js +80 -0
  102. package/lib/commands/swizzle/context.d.ts +8 -0
  103. package/lib/commands/swizzle/context.js +28 -0
  104. package/lib/commands/swizzle/index.d.ts +8 -0
  105. package/lib/commands/swizzle/index.js +115 -0
  106. package/lib/commands/swizzle/prompts.d.ts +12 -0
  107. package/lib/commands/swizzle/prompts.js +110 -0
  108. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  109. package/lib/commands/swizzle/tables.js +113 -0
  110. package/lib/commands/swizzle/themes.d.ts +20 -0
  111. package/lib/commands/swizzle/themes.js +106 -0
  112. package/lib/commands/writeHeadingIds.d.ts +2 -6
  113. package/lib/commands/writeHeadingIds.js +19 -76
  114. package/lib/commands/writeTranslations.d.ts +2 -2
  115. package/lib/commands/writeTranslations.js +37 -17
  116. package/lib/index.d.ts +10 -9
  117. package/lib/index.js +20 -19
  118. package/lib/server/brokenLinks.d.ts +4 -17
  119. package/lib/server/brokenLinks.js +64 -52
  120. package/lib/server/client-modules/index.d.ts +2 -2
  121. package/lib/server/client-modules/index.js +4 -3
  122. package/lib/server/config.d.ts +2 -2
  123. package/lib/server/config.js +8 -5
  124. package/lib/server/configValidation.d.ts +4 -2
  125. package/lib/server/configValidation.js +93 -37
  126. package/lib/server/duplicateRoutes.d.ts +1 -3
  127. package/lib/server/duplicateRoutes.js +17 -13
  128. package/lib/server/html-tags/htmlTags.js +7 -8
  129. package/lib/server/html-tags/index.d.ts +2 -3
  130. package/lib/server/html-tags/index.js +3 -4
  131. package/lib/server/i18n.d.ts +2 -3
  132. package/lib/server/i18n.js +27 -48
  133. package/lib/server/index.d.ts +9 -2
  134. package/lib/server/index.js +175 -96
  135. package/lib/server/moduleShorthand.d.ts +9 -0
  136. package/lib/server/moduleShorthand.js +46 -0
  137. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
  138. package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
  139. package/lib/server/plugins/index.d.ts +4 -5
  140. package/lib/server/plugins/index.js +69 -45
  141. package/lib/server/plugins/init.d.ts +15 -5
  142. package/lib/server/plugins/init.js +68 -81
  143. package/lib/server/plugins/pluginIds.d.ts +2 -2
  144. package/lib/server/plugins/pluginIds.js +8 -5
  145. package/lib/server/presets/index.d.ts +3 -3
  146. package/lib/server/presets/index.js +16 -23
  147. package/lib/server/routes.d.ts +3 -5
  148. package/lib/server/routes.js +68 -36
  149. package/lib/server/themes/alias.d.ts +3 -2
  150. package/lib/server/themes/alias.js +24 -13
  151. package/lib/server/themes/index.d.ts +6 -2
  152. package/lib/server/themes/index.js +36 -24
  153. package/lib/server/translations/translations.d.ts +21 -17
  154. package/lib/server/translations/translations.js +33 -54
  155. package/lib/server/translations/translationsExtractor.d.ts +12 -5
  156. package/lib/server/translations/translationsExtractor.js +159 -121
  157. package/lib/server/utils.d.ts +9 -3
  158. package/lib/server/utils.js +7 -9
  159. package/lib/server/versions/index.d.ts +3 -4
  160. package/lib/server/versions/index.js +22 -24
  161. package/lib/webpack/base.d.ts +6 -4
  162. package/lib/webpack/base.js +51 -36
  163. package/lib/webpack/client.d.ts +3 -3
  164. package/lib/webpack/client.js +12 -19
  165. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  166. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  167. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  168. package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
  169. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  170. package/lib/webpack/plugins/LogPlugin.js +4 -5
  171. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  172. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  173. package/lib/webpack/server.d.ts +3 -3
  174. package/lib/webpack/server.js +14 -7
  175. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  176. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  177. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  178. package/lib/webpack/utils.d.ts +15 -30
  179. package/lib/webpack/utils.js +57 -175
  180. package/package.json +77 -70
  181. package/bin/docusaurus.js +0 -326
  182. package/lib/.tsbuildinfo +0 -5732
  183. package/lib/client/.tsbuildinfo +0 -4171
  184. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  185. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  186. package/lib/commands/swizzle.d.ts +0 -9
  187. package/lib/commands/swizzle.js +0 -245
  188. package/lib/constants.d.ts +0 -18
  189. package/lib/constants.js +0 -23
  190. package/lib/server/loadSetup.js +0 -25
  191. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  192. package/lib/server/versions/__fixtures__/package.json +0 -3
  193. package/lib/server/versions/__tests/index.test.js +0 -25
  194. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  195. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  196. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  197. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  198. package/lib/webpack/sharedModuleAliases.js +0 -18
  199. package/tsconfig.client.json +0 -13
  200. package/tsconfig.json +0 -13
@@ -4,133 +4,65 @@
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
- export default ({error, retry, pastDelay}) => {
11
- if (error) {
12
- return (
13
- <div
14
- style={{
15
- align: 'center',
16
- color: '#fff',
17
- backgroundColor: '#fa383e',
18
- borderColor: '#fa383e',
19
- borderStyle: 'solid',
20
- borderRadius: '0.25rem',
21
- borderWidth: '1px',
22
- boxSizing: 'border-box',
23
- display: 'block',
24
- padding: '1rem',
25
- flex: '0 0 50%',
26
- marginLeft: '25%',
27
- marginRight: '25%',
28
- marginTop: '5rem',
29
- maxWidth: '50%',
30
- width: '100%',
31
- }}>
8
+ export default function Loading({ error, retry, pastDelay, }) {
9
+ if (error) {
10
+ return (<div style={{
11
+ textAlign: 'center',
12
+ color: '#fff',
13
+ backgroundColor: '#fa383e',
14
+ borderColor: '#fa383e',
15
+ borderStyle: 'solid',
16
+ borderRadius: '0.25rem',
17
+ borderWidth: '1px',
18
+ boxSizing: 'border-box',
19
+ display: 'block',
20
+ padding: '1rem',
21
+ flex: '0 0 50%',
22
+ marginLeft: '25%',
23
+ marginRight: '25%',
24
+ marginTop: '5rem',
25
+ maxWidth: '50%',
26
+ width: '100%',
27
+ }}>
32
28
  <p>{error.message}</p>
33
29
  <div>
34
30
  <button type="button" onClick={retry}>
35
31
  Retry
36
32
  </button>
37
33
  </div>
38
- </div>
39
- );
40
- }
41
-
42
- if (pastDelay) {
43
- return (
44
- <div
45
- style={{
46
- display: 'flex',
47
- justifyContent: 'center',
48
- alignItems: 'center',
49
- height: '100vh',
50
- }}>
51
- <svg
52
- id="loader"
53
- style={{
54
- width: 128,
55
- height: 110,
56
- position: 'absolute',
57
- top: 'calc(100vh - 64%)',
58
- }}
59
- viewBox="0 0 45 45"
60
- xmlns="http://www.w3.org/2000/svg"
61
- stroke="#61dafb">
62
- <g
63
- fill="none"
64
- fillRule="evenodd"
65
- transform="translate(1 1)"
66
- strokeWidth="2">
34
+ </div>);
35
+ }
36
+ if (pastDelay) {
37
+ return (<div style={{
38
+ display: 'flex',
39
+ justifyContent: 'center',
40
+ alignItems: 'center',
41
+ height: '100vh',
42
+ }}>
43
+ <svg id="loader" style={{
44
+ width: 128,
45
+ height: 110,
46
+ position: 'absolute',
47
+ top: 'calc(100vh - 64%)',
48
+ }} viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" stroke="#61dafb">
49
+ <g fill="none" fillRule="evenodd" transform="translate(1 1)" strokeWidth="2">
67
50
  <circle cx="22" cy="22" r="6" strokeOpacity="0">
68
- <animate
69
- attributeName="r"
70
- begin="1.5s"
71
- dur="3s"
72
- values="6;22"
73
- calcMode="linear"
74
- repeatCount="indefinite"
75
- />
76
- <animate
77
- attributeName="stroke-opacity"
78
- begin="1.5s"
79
- dur="3s"
80
- values="1;0"
81
- calcMode="linear"
82
- repeatCount="indefinite"
83
- />
84
- <animate
85
- attributeName="stroke-width"
86
- begin="1.5s"
87
- dur="3s"
88
- values="2;0"
89
- calcMode="linear"
90
- repeatCount="indefinite"
91
- />
51
+ <animate attributeName="r" begin="1.5s" dur="3s" values="6;22" calcMode="linear" repeatCount="indefinite"/>
52
+ <animate attributeName="stroke-opacity" begin="1.5s" dur="3s" values="1;0" calcMode="linear" repeatCount="indefinite"/>
53
+ <animate attributeName="stroke-width" begin="1.5s" dur="3s" values="2;0" calcMode="linear" repeatCount="indefinite"/>
92
54
  </circle>
93
55
  <circle cx="22" cy="22" r="6" strokeOpacity="0">
94
- <animate
95
- attributeName="r"
96
- begin="3s"
97
- dur="3s"
98
- values="6;22"
99
- calcMode="linear"
100
- repeatCount="indefinite"
101
- />
102
- <animate
103
- attributeName="stroke-opacity"
104
- begin="3s"
105
- dur="3s"
106
- values="1;0"
107
- calcMode="linear"
108
- repeatCount="indefinite"
109
- />
110
- <animate
111
- attributeName="stroke-width"
112
- begin="3s"
113
- dur="3s"
114
- values="2;0"
115
- calcMode="linear"
116
- repeatCount="indefinite"
117
- />
56
+ <animate attributeName="r" begin="3s" dur="3s" values="6;22" calcMode="linear" repeatCount="indefinite"/>
57
+ <animate attributeName="stroke-opacity" begin="3s" dur="3s" values="1;0" calcMode="linear" repeatCount="indefinite"/>
58
+ <animate attributeName="stroke-width" begin="3s" dur="3s" values="2;0" calcMode="linear" repeatCount="indefinite"/>
118
59
  </circle>
119
60
  <circle cx="22" cy="22" r="8">
120
- <animate
121
- attributeName="r"
122
- begin="0s"
123
- dur="1.5s"
124
- values="6;1;2;3;4;5;6"
125
- calcMode="linear"
126
- repeatCount="indefinite"
127
- />
61
+ <animate attributeName="r" begin="0s" dur="1.5s" values="6;1;2;3;4;5;6" calcMode="linear" repeatCount="indefinite"/>
128
62
  </circle>
129
63
  </g>
130
64
  </svg>
131
- </div>
132
- );
133
- }
134
-
135
- return null;
136
- };
65
+ </div>);
66
+ }
67
+ return null;
68
+ }
@@ -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 React from 'react';
8
- export default React.createContext(null);
7
+ /// <reference types="react" />
8
+ export default function NotFound(): JSX.Element;
@@ -4,25 +4,24 @@
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
8
  import Layout from '@theme/Layout';
10
-
11
- function NotFound() {
12
- return (
13
- <Layout title="Page Not Found">
14
- <div
15
- style={{
16
- display: 'flex',
17
- justifyContent: 'center',
18
- alignItems: 'center',
19
- height: '50vh',
20
- fontSize: '20px',
9
+ import Head from '@docusaurus/Head';
10
+ export default function NotFound() {
11
+ return (<>
12
+ <Head>
13
+ <title>Page Not Found</title>
14
+ </Head>
15
+ <Layout>
16
+ <div style={{
17
+ display: 'flex',
18
+ justifyContent: 'center',
19
+ alignItems: 'center',
20
+ height: '50vh',
21
+ fontSize: '20px',
21
22
  }}>
22
- <h1>Oops, page not found </h1>
23
- </div>
24
- </Layout>
25
- );
23
+ <h1>Oops, page not found </h1>
24
+ </div>
25
+ </Layout>
26
+ </>);
26
27
  }
27
-
28
- export default NotFound;
@@ -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
+ /// <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,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;
@@ -0,0 +1,8 @@
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
+ /// <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,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 { BuildCLIOptions } from '@docusaurus/types';
7
+ import type { BuildCLIOptions } from '@docusaurus/types';
8
8
  export default function build(siteDir: string, cliOptions?: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
@@ -7,14 +7,13 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
11
11
  const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const path_1 = tslib_1.__importDefault(require("path"));
14
14
  const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
15
15
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
16
16
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
17
- const constants_1 = require("../constants");
18
17
  const server_1 = require("../server");
19
18
  const brokenLinks_1 = require("../server/brokenLinks");
20
19
  const client_1 = tslib_1.__importDefault(require("../webpack/client"));
@@ -24,11 +23,16 @@ const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins
24
23
  const i18n_1 = require("../server/i18n");
25
24
  const utils_2 = require("@docusaurus/utils");
26
25
  async function build(siteDir, cliOptions = {},
27
- // TODO what's the purpose of this arg ?
26
+ // When running build, we force terminate the process to prevent async
27
+ // operations from never returning. However, if run as part of docusaurus
28
+ // deploy, we have to let deploy finish.
29
+ // See https://github.com/facebook/docusaurus/pull/2496
28
30
  forceTerminate = true) {
31
+ ['SIGINT', 'SIGTERM'].forEach((sig) => {
32
+ process.on(sig, () => process.exit());
33
+ });
29
34
  async function tryToBuildLocale({ locale, isLastLocale, }) {
30
35
  try {
31
- // console.log(chalk.green(`Site successfully built in locale=${locale}`));
32
36
  return await buildLocale({
33
37
  siteDir,
34
38
  locale,
@@ -37,60 +41,58 @@ forceTerminate = true) {
37
41
  isLastLocale,
38
42
  });
39
43
  }
40
- catch (e) {
41
- console.error(`Unable to build website for locale ${locale}.`);
42
- throw e;
44
+ catch (err) {
45
+ logger_1.default.error `Unable to build website for locale name=${locale}.`;
46
+ throw err;
43
47
  }
44
48
  }
45
- const context = await server_1.loadContext(siteDir, {
49
+ const context = await (0, server_1.loadContext)(siteDir, {
46
50
  customOutDir: cliOptions.outDir,
47
51
  customConfigFilePath: cliOptions.config,
48
52
  locale: cliOptions.locale,
49
53
  localizePath: cliOptions.locale ? false : undefined,
50
54
  });
51
- const i18n = await i18n_1.loadI18n(context.siteConfig, {
55
+ const i18n = await (0, i18n_1.loadI18n)(context.siteConfig, {
52
56
  locale: cliOptions.locale,
53
57
  });
54
58
  if (cliOptions.locale) {
55
59
  return tryToBuildLocale({ locale: cliOptions.locale, isLastLocale: true });
56
60
  }
57
- else {
58
- if (i18n.locales.length > 1) {
59
- console.log(chalk_1.default.yellow(`\nSite 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];
61
+ if (i18n.locales.length > 1) {
62
+ logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
73
63
  }
64
+ // We need the default locale to always be the 1st in the list. If we build it
65
+ // last, it would "erase" the localized sites built in sub-folders
66
+ const orderedLocales = [
67
+ i18n.defaultLocale,
68
+ ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
69
+ ];
70
+ const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
71
+ const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
72
+ return tryToBuildLocale({ locale, isLastLocale });
73
+ });
74
+ return results[0];
74
75
  }
75
76
  exports.default = build;
76
77
  async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
77
78
  process.env.BABEL_ENV = 'production';
78
79
  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, {
80
+ logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
81
+ const props = await (0, server_1.load)(siteDir, {
81
82
  customOutDir: cliOptions.outDir,
82
83
  customConfigFilePath: cliOptions.config,
83
84
  locale,
84
85
  localizePath: cliOptions.locale ? false : undefined,
85
86
  });
86
87
  // Apply user webpack config.
87
- const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks }, routes, } = props;
88
+ const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories }, routes, } = props;
88
89
  const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
89
- let clientConfig = webpack_merge_1.default(client_1.default(props, cliOptions.minify), {
90
+ let clientConfig = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
90
91
  plugins: [
91
92
  // Remove/clean build folders before building bundles.
92
93
  new CleanWebpackPlugin_1.default({ verbose: false }),
93
- // Visualize size of webpack output files with an interactive zoomable treemap.
94
+ // Visualize size of webpack output files with an interactive zoomable
95
+ // tree map.
94
96
  cliOptions.bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
95
97
  // Generate client manifests file that will be used for server bundle.
96
98
  new react_loadable_ssr_addon_v5_slorber_1.default({
@@ -99,39 +101,35 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
99
101
  ].filter(Boolean),
100
102
  });
101
103
  const allCollectedLinks = {};
102
- let serverConfig = server_2.default({
104
+ let serverConfig = await (0, server_2.default)({
103
105
  props,
104
106
  onLinksCollected: (staticPagePath, links) => {
105
107
  allCollectedLinks[staticPagePath] = links;
106
108
  },
107
109
  });
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, {
110
+ if (staticDirectories.length > 0) {
111
+ await Promise.all(staticDirectories.map((dir) => fs_extra_1.default.ensureDir(dir)));
112
+ serverConfig = (0, webpack_merge_1.default)(serverConfig, {
111
113
  plugins: [
112
114
  new copy_webpack_plugin_1.default({
113
- patterns: [
114
- {
115
- from: staticDir,
116
- to: outDir,
117
- },
118
- ],
115
+ patterns: staticDirectories
116
+ .map((dir) => path_1.default.resolve(siteDir, dir))
117
+ .map((dir) => ({ from: dir, to: outDir })),
119
118
  }),
120
119
  ],
121
120
  });
122
121
  }
123
122
  // Plugin Lifecycle - configureWebpack and configurePostCss.
124
123
  plugins.forEach((plugin) => {
125
- var _a, _b;
126
124
  const { configureWebpack, configurePostCss } = plugin;
127
125
  if (configurePostCss) {
128
- clientConfig = utils_1.applyConfigurePostCss(configurePostCss, clientConfig);
126
+ clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
129
127
  }
130
128
  if (configureWebpack) {
131
- clientConfig = 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);
133
- serverConfig = 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);
129
+ clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
130
+ clientConfig, false, props.siteConfig.webpack?.jsLoader, plugin.content);
131
+ serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
132
+ serverConfig, true, props.siteConfig.webpack?.jsLoader, plugin.content);
135
133
  }
136
134
  });
137
135
  // Make sure generated client-manifest is cleaned first so we don't reuse
@@ -140,11 +138,9 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
140
138
  await fs_extra_1.default.unlink(clientManifestPath);
141
139
  }
142
140
  // Run webpack to build JS bundle (client) and static html files (server).
143
- await utils_1.compile([clientConfig, serverConfig]);
141
+ await (0, utils_1.compile)([clientConfig, serverConfig]);
144
142
  // Remove server.bundle.js because it is not needed.
145
- if (serverConfig.output &&
146
- serverConfig.output.filename &&
147
- typeof serverConfig.output.filename === 'string') {
143
+ if (typeof serverConfig.output?.filename === 'string') {
148
144
  const serverBundle = path_1.default.join(outDir, serverConfig.output.filename);
149
145
  if (await fs_extra_1.default.pathExists(serverBundle)) {
150
146
  await fs_extra_1.default.unlink(serverBundle);
@@ -155,18 +151,18 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
155
151
  if (!plugin.postBuild) {
156
152
  return;
157
153
  }
158
- await plugin.postBuild(props);
154
+ await plugin.postBuild({ ...props, content: plugin.content });
159
155
  }));
160
- await brokenLinks_1.handleBrokenLinks({
156
+ await (0, brokenLinks_1.handleBrokenLinks)({
161
157
  allCollectedLinks,
162
158
  routes,
163
159
  onBrokenLinks,
164
160
  outDir,
165
161
  baseUrl,
166
162
  });
167
- console.log(`${chalk_1.default.green(`Success!`)} Generated static files in ${chalk_1.default.cyan(path_1.default.relative(process.cwd(), outDir))}.`);
163
+ logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
168
164
  if (isLastLocale) {
169
- console.log(`\nUse ${chalk_1.default.greenBright('`npm run serve`')} to test your build locally.\n`);
165
+ logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
170
166
  }
171
167
  if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
172
168
  process.exit(0);
@@ -1 +1,7 @@
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
+ */
1
7
  export default function clear(siteDir: string): Promise<unknown>;
@@ -1,32 +1,43 @@
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
+ const tslib_1 = require("tslib");
10
10
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
11
  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(`Removing ${fsPath}`)}`);
19
- })
20
- .catch((err) => {
21
- console.error(`Could not remove ${fsPath}`);
22
- console.error(err);
23
- });
12
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ async function removePath(entry) {
15
+ if (!(await fs_extra_1.default.pathExists(entry.path))) {
16
+ return;
17
+ }
18
+ try {
19
+ await fs_extra_1.default.remove(entry.path);
20
+ logger_1.default.success `Removed the ${entry.description} at path=${entry.path}.`;
21
+ }
22
+ catch (err) {
23
+ logger_1.default.error `Could not remove the ${entry.description} at path=${entry.path}.`;
24
+ logger_1.default.error(err);
25
+ }
24
26
  }
25
27
  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
+ const generatedFolder = {
29
+ path: path_1.default.join(siteDir, utils_1.GENERATED_FILES_DIR_NAME),
30
+ description: 'generated folder',
31
+ };
32
+ const buildFolder = {
33
+ path: path_1.default.join(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME),
34
+ description: 'build output folder',
35
+ };
36
+ // In Yarn PnP, cache is stored in `.yarn/.cache` because n_m doesn't exist
37
+ const cacheFolders = ['node_modules', '.yarn'].map((p) => ({
38
+ path: path_1.default.join(siteDir, p, '.cache'),
39
+ description: 'Webpack persistent cache folder',
40
+ }));
41
+ return Promise.all([generatedFolder, buildFolder, ...cacheFolders].map(removePath));
31
42
  }
32
43
  exports.default = clear;
@@ -1,3 +1,9 @@
1
- import { HostPortCLIOptions } from '@docusaurus/types';
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 type { HostPortCLIOptions } from '@docusaurus/types';
2
8
  export declare function getCLIOptionHost(hostOption: HostPortCLIOptions['host']): string;
3
9
  export declare function getCLIOptionPort(portOption: HostPortCLIOptions['port'], host: string): Promise<number | null>;
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCLIOptionPort = exports.getCLIOptionHost = void 0;
4
- const tslib_1 = require("tslib");
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getCLIOptionPort = exports.getCLIOptionHost = void 0;
10
+ const tslib_1 = require("tslib");
11
11
  const choosePort_1 = tslib_1.__importDefault(require("../choosePort"));
12
- const constants_1 = require("../constants");
12
+ const utils_1 = require("@docusaurus/utils");
13
13
  function getCLIOptionHost(hostOption) {
14
- return hostOption || 'localhost';
14
+ return hostOption ?? 'localhost';
15
15
  }
16
16
  exports.getCLIOptionHost = getCLIOptionHost;
17
17
  async function getCLIOptionPort(portOption, host) {
18
- const basePort = portOption ? parseInt(portOption, 10) : constants_1.DEFAULT_PORT;
19
- return choosePort_1.default(host, basePort);
18
+ const basePort = portOption ? parseInt(portOption, 10) : utils_1.DEFAULT_PORT;
19
+ return (0, choosePort_1.default)(host, basePort);
20
20
  }
21
21
  exports.getCLIOptionPort = getCLIOptionPort;
@@ -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 { BuildCLIOptions } from '@docusaurus/types';
7
+ import type { BuildCLIOptions } from '@docusaurus/types';
8
8
  export default function deploy(siteDir: string, cliOptions?: Partial<BuildCLIOptions>): Promise<void>;