@docusaurus/core 2.0.0-beta.fc64c12e4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/{docusaurus.js → docusaurus.mjs} +81 -118
  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/ExecutionEnvironment.js +7 -8
  33. package/lib/client/exports/Head.d.ts +2 -3
  34. package/lib/client/exports/Head.js +3 -4
  35. package/lib/client/exports/Interpolate.d.ts +2 -2
  36. package/lib/client/exports/Interpolate.js +18 -51
  37. package/lib/client/exports/Link.d.ts +4 -10
  38. package/lib/client/exports/Link.js +38 -38
  39. package/lib/client/exports/Translate.d.ts +1 -1
  40. package/lib/client/exports/Translate.js +11 -10
  41. package/lib/client/exports/constants.js +1 -11
  42. package/lib/client/exports/isInternalUrl.js +1 -1
  43. package/lib/client/exports/renderRoutes.d.ts +1 -2
  44. package/lib/client/exports/renderRoutes.js +1 -2
  45. package/lib/client/exports/router.d.ts +1 -1
  46. package/lib/client/exports/router.js +1 -1
  47. package/lib/client/exports/useBaseUrl.js +11 -14
  48. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  49. package/lib/client/exports/useDocusaurusContext.js +3 -9
  50. package/lib/client/exports/useGlobalData.d.ts +4 -3
  51. package/lib/client/exports/useGlobalData.js +6 -13
  52. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  53. package/lib/client/exports/useIsBrowser.js +11 -0
  54. package/lib/client/exports/useRouteContext.d.ts +8 -0
  55. package/lib/client/exports/useRouteContext.js +15 -0
  56. package/lib/client/flat.d.ts +12 -2
  57. package/lib/client/flat.js +19 -15
  58. package/lib/client/normalizeLocation.d.ts +2 -5
  59. package/lib/client/normalizeLocation.js +14 -10
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +12 -32
  62. package/lib/client/preload.d.ts +3 -4
  63. package/lib/client/preload.js +5 -12
  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 +108 -146
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +45 -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 +50 -116
  74. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
  75. package/lib/client/theme-fallback/NotFound/index.js +19 -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/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +6 -2
  81. package/lib/commands/build.js +81 -64
  82. package/lib/commands/clear.d.ts +7 -1
  83. package/lib/commands/clear.js +34 -21
  84. package/lib/commands/deploy.d.ts +5 -2
  85. package/lib/commands/deploy.js +94 -81
  86. package/lib/commands/external.d.ts +2 -2
  87. package/lib/commands/external.js +9 -11
  88. package/lib/commands/serve.d.ts +8 -2
  89. package/lib/commands/serve.js +29 -28
  90. package/lib/commands/start.d.ts +9 -2
  91. package/lib/commands/start.js +107 -102
  92. package/lib/commands/swizzle/actions.d.ts +23 -0
  93. package/lib/commands/swizzle/actions.js +106 -0
  94. package/lib/commands/swizzle/common.d.ts +33 -0
  95. package/lib/commands/swizzle/common.js +56 -0
  96. package/lib/commands/swizzle/components.d.ts +29 -0
  97. package/lib/commands/swizzle/components.js +200 -0
  98. package/lib/commands/swizzle/config.d.ts +10 -0
  99. package/lib/commands/swizzle/config.js +84 -0
  100. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  101. package/lib/commands/swizzle/context.js +24 -0
  102. package/lib/commands/swizzle/index.d.ts +8 -0
  103. package/lib/commands/swizzle/index.js +119 -0
  104. package/lib/commands/swizzle/prompts.d.ts +12 -0
  105. package/lib/commands/swizzle/prompts.js +110 -0
  106. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  107. package/lib/commands/swizzle/tables.js +113 -0
  108. package/lib/commands/swizzle/themes.d.ts +20 -0
  109. package/lib/commands/swizzle/themes.js +106 -0
  110. package/lib/commands/writeHeadingIds.d.ts +2 -6
  111. package/lib/commands/writeHeadingIds.js +22 -81
  112. package/lib/commands/writeTranslations.d.ts +4 -5
  113. package/lib/commands/writeTranslations.js +46 -25
  114. package/lib/index.d.ts +9 -9
  115. package/lib/index.js +14 -14
  116. package/lib/server/brokenLinks.d.ts +4 -17
  117. package/lib/server/brokenLinks.js +67 -56
  118. package/lib/server/clientModules.d.ts +12 -0
  119. package/lib/server/clientModules.js +20 -0
  120. package/lib/server/config.d.ts +5 -2
  121. package/lib/server/config.js +29 -6
  122. package/lib/server/configValidation.d.ts +4 -4
  123. package/lib/server/configValidation.js +86 -41
  124. package/lib/server/getHostPort.d.ts +14 -0
  125. package/lib/server/getHostPort.js +79 -0
  126. package/lib/server/htmlTags.d.ts +12 -0
  127. package/lib/server/htmlTags.js +62 -0
  128. package/lib/server/i18n.d.ts +3 -13
  129. package/lib/server/i18n.js +21 -55
  130. package/lib/server/index.d.ts +28 -13
  131. package/lib/server/index.js +83 -165
  132. package/lib/server/plugins/configs.d.ts +51 -0
  133. package/lib/server/plugins/configs.js +101 -0
  134. package/lib/server/plugins/index.d.ts +9 -8
  135. package/lib/server/plugins/index.js +73 -137
  136. package/lib/server/plugins/init.d.ts +6 -5
  137. package/lib/server/plugins/init.js +44 -109
  138. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  139. package/lib/server/plugins/moduleShorthand.js +46 -0
  140. package/lib/server/plugins/pluginIds.d.ts +5 -1
  141. package/lib/server/plugins/pluginIds.js +12 -7
  142. package/lib/server/plugins/presets.d.ts +12 -0
  143. package/lib/server/plugins/presets.js +49 -0
  144. package/lib/server/plugins/routeConfig.d.ts +11 -0
  145. package/lib/server/plugins/routeConfig.js +54 -0
  146. package/lib/server/plugins/synthetic.d.ts +20 -0
  147. package/lib/server/plugins/synthetic.js +111 -0
  148. package/lib/server/routes.d.ts +39 -7
  149. package/lib/server/routes.js +166 -99
  150. package/lib/server/siteMetadata.d.ts +12 -0
  151. package/lib/server/siteMetadata.js +81 -0
  152. package/lib/server/translations/translations.d.ts +14 -19
  153. package/lib/server/translations/translations.js +40 -72
  154. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  155. package/lib/server/translations/translationsExtractor.js +158 -122
  156. package/lib/server/utils.d.ts +7 -1
  157. package/lib/server/utils.js +7 -8
  158. package/lib/webpack/aliases/index.d.ts +34 -0
  159. package/lib/webpack/aliases/index.js +106 -0
  160. package/lib/webpack/base.d.ts +3 -4
  161. package/lib/webpack/base.js +45 -57
  162. package/lib/webpack/client.d.ts +3 -3
  163. package/lib/webpack/client.js +12 -19
  164. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  165. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  166. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  167. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  168. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  169. package/lib/webpack/plugins/LogPlugin.js +4 -5
  170. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  171. package/lib/webpack/plugins/WaitPlugin.js +30 -29
  172. package/lib/webpack/server.d.ts +5 -5
  173. package/lib/webpack/server.js +21 -12
  174. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  175. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  176. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  177. package/lib/webpack/utils.d.ts +15 -31
  178. package/lib/webpack/utils.js +61 -182
  179. package/package.json +81 -77
  180. package/bin/beforeCli.js +0 -103
  181. package/lib/.tsbuildinfo +0 -1
  182. package/lib/choosePort.js +0 -105
  183. package/lib/client/.eslintrc.js +0 -29
  184. package/lib/client/.tsbuildinfo +0 -1
  185. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  186. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  187. package/lib/client/nprogress.css +0 -36
  188. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  189. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  190. package/lib/commands/commandUtils.d.ts +0 -3
  191. package/lib/commands/commandUtils.js +0 -21
  192. package/lib/commands/swizzle.d.ts +0 -9
  193. package/lib/commands/swizzle.js +0 -245
  194. package/lib/constants.d.ts +0 -18
  195. package/lib/constants.js +0 -23
  196. package/lib/server/client-modules/index.js +0 -14
  197. package/lib/server/duplicateRoutes.d.ts +0 -10
  198. package/lib/server/duplicateRoutes.js +0 -38
  199. package/lib/server/html-tags/htmlTags.js +0 -40
  200. package/lib/server/html-tags/index.d.ts +0 -9
  201. package/lib/server/html-tags/index.js +0 -43
  202. package/lib/server/loadSetup.d.ts +0 -9
  203. package/lib/server/loadSetup.js +0 -25
  204. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
  205. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  206. package/lib/server/presets/index.d.ts +0 -11
  207. package/lib/server/presets/index.js +0 -48
  208. package/lib/server/themes/alias.d.ts +0 -8
  209. package/lib/server/themes/alias.js +0 -39
  210. package/lib/server/themes/index.d.ts +0 -12
  211. package/lib/server/themes/index.js +0 -47
  212. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  213. package/lib/server/versions/__fixtures__/package.json +0 -3
  214. package/lib/server/versions/__tests/index.test.js +0 -25
  215. package/lib/server/versions/index.d.ts +0 -10
  216. package/lib/server/versions/index.js +0 -50
  217. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  218. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  219. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  220. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  221. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  222. package/lib/webpack/sharedModuleAliases.js +0 -18
  223. package/tsconfig.client.json +0 -13
  224. package/tsconfig.json +0 -13
package/README.md CHANGED
@@ -0,0 +1 @@
1
+ # Docusaurus core
@@ -0,0 +1,140 @@
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
+
8
+ // @ts-check
9
+
10
+ import fs from 'fs-extra';
11
+ import path from 'path';
12
+ import {createRequire} from 'module';
13
+ import logger from '@docusaurus/logger';
14
+ import semver from 'semver';
15
+ import updateNotifier from 'update-notifier';
16
+ import boxen from 'boxen';
17
+ import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
18
+
19
+ const packageJson = /** @type {import("../package.json")} */ (
20
+ createRequire(import.meta.url)('../package.json')
21
+ );
22
+ /** @type {Record<string, any>} */
23
+ let sitePkg;
24
+ try {
25
+ sitePkg = createRequire(path.resolve('package.json'))('./package.json');
26
+ } catch {
27
+ logger.warn`path=${'package.json'} file not found at CWD: path=${process.cwd()}.`;
28
+ logger.info`This is non-critical, but could lead to undesired behavior downstream. Docusaurus assumes that path=${'package.json'} exists at CWD, because it's where the package manager looks up the script at. A common reason is because you have changed directory in the script. Instead of writing code=${'"start": "cd website && docusaurus start"'}, consider using the code=${'[siteDir]'} argument: code=${'"start": "docusaurus start website"'}.`;
29
+ sitePkg = {};
30
+ }
31
+
32
+ const {
33
+ name,
34
+ engines: {node: requiredVersion},
35
+ } = packageJson;
36
+
37
+ /**
38
+ * Notify user if `@docusaurus` packages are outdated
39
+ *
40
+ * Note: this is a 2-step process to avoid delaying cli usage by awaiting a
41
+ * response:
42
+ * - 1st run: trigger background job to check releases + store result
43
+ * - 2nd run: display potential update to users
44
+ *
45
+ * cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
46
+ */
47
+ export default async function beforeCli() {
48
+ const notifier = updateNotifier({
49
+ pkg: {
50
+ name,
51
+ version: DOCUSAURUS_VERSION,
52
+ },
53
+ // Check is in background so it's fine to use a small value like 1h
54
+ // Use 0 for debugging
55
+ updateCheckInterval: 1000 * 60 * 60,
56
+ });
57
+
58
+ // Hacky way to ensure we check for updates on first run
59
+ // Note: the notification will only happen in the 2nd run
60
+ // See https://github.com/yeoman/update-notifier/issues/209
61
+ try {
62
+ if (
63
+ notifier.config &&
64
+ // @ts-expect-error: this is an internal API
65
+ !notifier.disabled &&
66
+ Date.now() - notifier.config.get('lastUpdateCheck') < 50
67
+ ) {
68
+ notifier.config.set('lastUpdateCheck', 0);
69
+ notifier.check();
70
+ }
71
+ } catch (err) {
72
+ // Do not stop cli if this fails, see https://github.com/facebook/docusaurus/issues/5400
73
+ logger.error(err);
74
+ }
75
+
76
+ /**
77
+ * We don't want to display update message for canary releases.
78
+ * See https://github.com/facebook/docusaurus/issues/5378
79
+ * @param {import('update-notifier').UpdateInfo} update
80
+ */
81
+ function ignoreUpdate(update) {
82
+ const isCanaryRelease = update?.current?.startsWith('0.0.0');
83
+ return isCanaryRelease;
84
+ }
85
+
86
+ if (
87
+ notifier.config &&
88
+ notifier.update &&
89
+ semver.lt(notifier.update.current, notifier.update.latest)
90
+ ) {
91
+ // Because notifier clears cached data after reading it, leading to notifier
92
+ // not consistently displaying the update.
93
+ // See https://github.com/yeoman/update-notifier/issues/209
94
+ notifier.config.set('update', notifier.update);
95
+
96
+ if (ignoreUpdate(notifier.update)) {
97
+ return;
98
+ }
99
+
100
+ const siteDocusaurusPackagesForUpdate = Object.keys({
101
+ ...sitePkg.dependencies,
102
+ ...sitePkg.devDependencies,
103
+ })
104
+ .filter((p) => p.startsWith('@docusaurus'))
105
+ .map((p) => p.concat('@latest'))
106
+ .join(' ');
107
+ const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
108
+ const upgradeCommand = isYarnUsed
109
+ ? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
110
+ : `npm i ${siteDocusaurusPackagesForUpdate}`;
111
+
112
+ /** @type {import('boxen').Options} */
113
+ const boxenOptions = {
114
+ padding: 1,
115
+ margin: 1,
116
+ align: 'center',
117
+ borderColor: 'yellow',
118
+ borderStyle: 'round',
119
+ };
120
+
121
+ const docusaurusUpdateMessage = boxen(
122
+ `Update available ${logger.dim(
123
+ `${notifier.update.current}`,
124
+ )} → ${logger.green(`${notifier.update.latest}`)}
125
+
126
+ To upgrade Docusaurus packages with the latest version, run the following command:
127
+ ${logger.code(upgradeCommand)}`,
128
+ boxenOptions,
129
+ );
130
+
131
+ console.log(docusaurusUpdateMessage);
132
+ }
133
+
134
+ // Notify user if node version needs to be updated
135
+ if (!semver.satisfies(process.version, requiredVersion)) {
136
+ logger.error('Minimum Node.js version not met :(');
137
+ logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
138
+ process.exit(1);
139
+ }
140
+ }
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
- // TODO remove when fixed: https://github.com/Stuk/eslint-plugin-header/issues/39
4
- /* eslint-disable header/header */
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
@@ -9,10 +6,12 @@
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
11
8
 
12
- const chalk = require('chalk');
13
- const path = require('path');
14
- const cli = require('commander');
15
- const {
9
+ // @ts-check
10
+
11
+ import logger from '@docusaurus/logger';
12
+ import cli from 'commander';
13
+ import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
14
+ import {
16
15
  build,
17
16
  swizzle,
18
17
  deploy,
@@ -22,18 +21,19 @@ const {
22
21
  clear,
23
22
  writeTranslations,
24
23
  writeHeadingIds,
25
- } = require('../lib');
24
+ } from '../lib/index.js';
25
+ import beforeCli from './beforeCli.mjs';
26
26
 
27
- require('./beforeCli');
27
+ await beforeCli();
28
28
 
29
- cli.version(require('../package.json').version).usage('<command> [options]');
29
+ cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
30
30
 
31
31
  cli
32
32
  .command('build [siteDir]')
33
33
  .description('Build website.')
34
34
  .option(
35
35
  '--bundle-analyzer',
36
- 'visualize size of webpack output files with an interactive zoomable treemap (default: false)',
36
+ 'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
37
37
  )
38
38
  .option(
39
39
  '--out-dir <dir>',
@@ -51,33 +51,33 @@ cli
51
51
  '--no-minify',
52
52
  'build website without minimizing JS bundles (default: false)',
53
53
  )
54
- .action((siteDir = '.', {bundleAnalyzer, config, outDir, locale, minify}) => {
55
- build(path.resolve(siteDir), {
56
- bundleAnalyzer,
57
- outDir,
58
- config,
59
- locale,
60
- minify,
61
- });
62
- });
54
+ // @ts-expect-error: Promise<string> is not assignable to Promise<void>... but
55
+ // good enough here.
56
+ .action(build);
63
57
 
64
58
  cli
65
59
  .command('swizzle [themeName] [componentName] [siteDir]')
66
- .description('Copy the theme files into website folder for customization.')
60
+ .description(
61
+ 'Wraps or ejects the original theme files into website folder for customization.',
62
+ )
63
+ .option(
64
+ '-w, --wrap',
65
+ 'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.',
66
+ )
67
+ .option(
68
+ '-e, --eject',
69
+ 'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.',
70
+ )
67
71
  .option(
68
- '--typescript',
72
+ '-l, --list',
73
+ 'only list the available themes/components without further prompting (default: false)',
74
+ )
75
+ .option(
76
+ '-t, --typescript',
69
77
  'copy TypeScript theme files when possible (default: false)',
70
78
  )
71
- .option('--danger', 'enable swizzle for internal component of themes')
72
- .action((themeName, componentName, siteDir = '.', {typescript, danger}) => {
73
- swizzle(
74
- path.resolve(siteDir),
75
- themeName,
76
- componentName,
77
- typescript,
78
- danger,
79
- );
80
- });
79
+ .option('--danger', 'enable swizzle for unsafe component of themes')
80
+ .action(swizzle);
81
81
 
82
82
  cli
83
83
  .command('deploy [siteDir]')
@@ -98,13 +98,7 @@ cli
98
98
  '--skip-build',
99
99
  'skip building website before deploy it (default: false)',
100
100
  )
101
- .action((siteDir = '.', {outDir, skipBuild, config}) => {
102
- deploy(path.resolve(siteDir), {
103
- outDir,
104
- config,
105
- skipBuild,
106
- });
107
- });
101
+ .action(deploy);
108
102
 
109
103
  cli
110
104
  .command('start [siteDir]')
@@ -125,19 +119,11 @@ cli
125
119
  '--poll [interval]',
126
120
  'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
127
121
  )
128
- .action(
129
- (siteDir = '.', {port, host, locale, config, hotOnly, open, poll}) => {
130
- start(path.resolve(siteDir), {
131
- port,
132
- host,
133
- locale,
134
- config,
135
- hotOnly,
136
- open,
137
- poll,
138
- });
139
- },
140
- );
122
+ .option(
123
+ '--no-minify',
124
+ 'build website without minimizing JS bundles (default: false)',
125
+ )
126
+ .action(start);
141
127
 
142
128
  cli
143
129
  .command('serve [siteDir]')
@@ -153,44 +139,27 @@ cli
153
139
  .option('-p, --port <port>', 'use specified port (default: 3000)')
154
140
  .option('--build', 'build website before serving (default: false)')
155
141
  .option('-h, --host <host>', 'use specified host (default: localhost)')
156
- .action(
157
- (
158
- siteDir = '.',
159
- {
160
- dir = 'build',
161
- port = 3000,
162
- host = 'localhost',
163
- build: buildSite = false,
164
- config,
165
- },
166
- ) => {
167
- serve(path.resolve(siteDir), {
168
- dir,
169
- port,
170
- build: buildSite,
171
- config,
172
- host,
173
- });
174
- },
175
- );
142
+ .option(
143
+ '--no-open',
144
+ 'do not open page in the browser (default: false, or true in CI)',
145
+ )
146
+ .action(serve);
176
147
 
177
148
  cli
178
149
  .command('clear [siteDir]')
179
150
  .description('Remove build artifacts.')
180
- .action((siteDir = '.') => {
181
- clear(path.resolve(siteDir));
182
- });
151
+ .action(clear);
183
152
 
184
153
  cli
185
154
  .command('write-translations [siteDir]')
186
155
  .description('Extract required translations of your site.')
187
156
  .option(
188
157
  '-l, --locale <locale>',
189
- 'the locale folder to write the translations\n"--locale fr" will write translations in ./i18n/fr folder)',
158
+ 'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
190
159
  )
191
160
  .option(
192
161
  '--override',
193
- 'by default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden',
162
+ 'By default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden. (default: false)',
194
163
  )
195
164
  .option(
196
165
  '--config <config>',
@@ -198,63 +167,57 @@ cli
198
167
  )
199
168
  .option(
200
169
  '--messagePrefix <messagePrefix>',
201
- 'allows to init new written messages with a given prefix. This might help you to highlight untranslated message to make them stand out in the UI',
170
+ 'Allows to init new written messages with a given prefix. This might help you to highlight untranslated message by making them stand out in the UI (default: "")',
202
171
  )
203
- .action(
204
- (
205
- siteDir = '.',
206
- {locale = undefined, override = false, messagePrefix = '', config},
207
- ) => {
208
- writeTranslations(path.resolve(siteDir), {
209
- locale,
210
- override,
211
- config,
212
- messagePrefix,
213
- });
214
- },
215
- );
172
+ .action(writeTranslations);
216
173
 
217
174
  cli
218
- .command('write-heading-ids [contentDir]')
175
+ .command('write-heading-ids [siteDir] [files...]')
219
176
  .description('Generate heading ids in Markdown content.')
220
- .action((siteDir = '.') => {
221
- writeHeadingIds(siteDir);
222
- });
177
+ .option(
178
+ '--maintain-case',
179
+ "keep the headings' casing, otherwise make all lowercase (default: false)",
180
+ )
181
+ .option('--overwrite', 'overwrite existing heading IDs (default: false)')
182
+ .action(writeHeadingIds);
223
183
 
224
184
  cli.arguments('<command>').action((cmd) => {
225
185
  cli.outputHelp();
226
- console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}.`);
227
- console.log();
186
+ logger.error` Unknown command name=${cmd}.`;
228
187
  });
229
188
 
189
+ /**
190
+ * @param {string | undefined} command
191
+ */
230
192
  function isInternalCommand(command) {
231
- return [
232
- 'start',
233
- 'build',
234
- 'swizzle',
235
- 'deploy',
236
- 'serve',
237
- 'clear',
238
- 'write-translations',
239
- 'write-heading-ids',
240
- ].includes(command);
193
+ return (
194
+ command &&
195
+ [
196
+ 'start',
197
+ 'build',
198
+ 'swizzle',
199
+ 'deploy',
200
+ 'serve',
201
+ 'clear',
202
+ 'write-translations',
203
+ 'write-heading-ids',
204
+ ].includes(command)
205
+ );
241
206
  }
242
207
 
243
- async function run() {
244
- if (!isInternalCommand(process.argv.slice(2)[0])) {
245
- await externalCommand(cli, path.resolve('.'));
246
- }
247
-
248
- cli.parse(process.argv);
208
+ if (!isInternalCommand(process.argv.slice(2)[0])) {
209
+ await externalCommand(cli);
210
+ }
249
211
 
250
- if (!process.argv.slice(2).length) {
251
- cli.outputHelp();
252
- }
212
+ if (!process.argv.slice(2).length) {
213
+ cli.outputHelp();
253
214
  }
254
215
 
255
- run();
216
+ cli.parse(process.argv);
256
217
 
257
218
  process.on('unhandledRejection', (err) => {
258
- console.error(chalk.red(err.stack));
219
+ logger.error(err instanceof Error ? err.stack : err);
220
+ logger.info`Docusaurus version: number=${DOCUSAURUS_VERSION}
221
+ Node version: number=${process.version}`;
259
222
  process.exit(1);
260
223
  });
@@ -1,3 +1,8 @@
1
- import { ConfigAPI, TransformOptions } from '@babel/core';
2
- declare function babelPresets(api: ConfigAPI): TransformOptions;
3
- export default babelPresets;
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 { ConfigAPI, TransformOptions } from '@babel/core';
8
+ export default function babelPresets(api: ConfigAPI): TransformOptions;
@@ -1,17 +1,18 @@
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 path_1 = tslib_1.__importDefault(require("path"));
11
11
  function getTransformOptions(isServer) {
12
12
  const absoluteRuntimePath = path_1.default.dirname(require.resolve(`@babel/runtime/package.json`));
13
13
  return {
14
- // All optional newlines and whitespace will be omitted when generating code in compact mode
14
+ // All optional newlines and whitespace will be omitted when generating code
15
+ // in compact mode
15
16
  compact: true,
16
17
  presets: [
17
18
  isServer
@@ -46,11 +47,12 @@ function getTransformOptions(isServer) {
46
47
  {
47
48
  corejs: false,
48
49
  helpers: true,
49
- // By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0, better to
50
- // explicitly specify the version so that it can reuse the helper better
51
- // See https://github.com/babel/babel/issues/10261
50
+ // By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
51
+ // better to explicitly specify the version so that it can reuse the
52
+ // helper better. See https://github.com/babel/babel/issues/10261
52
53
  // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
53
- version: require('@babel/runtime/package.json').version,
54
+ version: require('@babel/runtime/package.json')
55
+ .version,
54
56
  regenerator: true,
55
57
  useESModules: true,
56
58
  // Undocumented option that lets us encapsulate our runtime, ensuring
@@ -67,7 +69,7 @@ function getTransformOptions(isServer) {
67
69
  };
68
70
  }
69
71
  function babelPresets(api) {
70
- const callerName = api.caller((caller) => caller === null || caller === void 0 ? void 0 : caller.name);
72
+ const callerName = api.caller((caller) => caller?.name);
71
73
  return getTransformOptions(callerName === 'server');
72
74
  }
73
75
  exports.default = babelPresets;
@@ -5,6 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="react" />
8
- import './client-lifecycles-dispatcher';
9
- declare function App(): JSX.Element;
10
- export default App;
8
+ import '@generated/client-modules';
9
+ export default function App(): JSX.Element;
package/lib/client/App.js CHANGED
@@ -4,34 +4,37 @@
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, { useEffect, useState } from 'react';
7
+ import React from 'react';
8
+ import '@generated/client-modules';
8
9
  import routes from '@generated/routes';
9
- import siteConfig from '@generated/docusaurus.config';
10
- import globalData from '@generated/globalData';
11
- import i18n from '@generated/i18n';
12
- import codeTranslations from '@generated/codeTranslations';
13
- import siteMetadata from '@generated/site-metadata';
14
- import renderRoutes from './exports/renderRoutes';
15
- import DocusaurusContext from './exports/context';
16
- import PendingNavigation from './PendingNavigation';
17
- import BaseUrlIssueBanner from './baseUrlIssueBanner/BaseUrlIssueBanner';
10
+ import { useLocation } from '@docusaurus/router';
11
+ import renderRoutes from '@docusaurus/renderRoutes';
18
12
  import Root from '@theme/Root';
19
- import './client-lifecycles-dispatcher';
20
- function App() {
21
- const [isClient, setIsClient] = useState(false);
22
- useEffect(() => {
23
- setIsClient(true);
24
- }, []);
25
- return (React.createElement(DocusaurusContext.Provider, { value: {
26
- siteConfig,
27
- siteMetadata,
28
- globalData,
29
- i18n,
30
- codeTranslations,
31
- isClient,
32
- } },
33
- React.createElement(Root, null,
34
- React.createElement(BaseUrlIssueBanner, null),
35
- React.createElement(PendingNavigation, { routes: routes }, renderRoutes(routes)))));
13
+ import SiteMetadata from '@theme/SiteMetadata';
14
+ import normalizeLocation from './normalizeLocation';
15
+ import { BrowserContextProvider } from './browserContext';
16
+ import { DocusaurusContextProvider } from './docusaurusContext';
17
+ import PendingNavigation from './PendingNavigation';
18
+ import BaseUrlIssueBanner from './BaseUrlIssueBanner';
19
+ import SiteMetadataDefaults from './SiteMetadataDefaults';
20
+ // TODO, quick fix for CSS insertion order
21
+ // eslint-disable-next-line import/order
22
+ import ErrorBoundary from '@docusaurus/ErrorBoundary';
23
+ export default function App() {
24
+ const routeElement = renderRoutes(routes);
25
+ const location = useLocation();
26
+ return (<ErrorBoundary>
27
+ <DocusaurusContextProvider>
28
+ <BrowserContextProvider>
29
+ <Root>
30
+ <SiteMetadataDefaults />
31
+ <SiteMetadata />
32
+ <BaseUrlIssueBanner />
33
+ <PendingNavigation location={normalizeLocation(location)}>
34
+ {routeElement}
35
+ </PendingNavigation>
36
+ </Root>
37
+ </BrowserContextProvider>
38
+ </DocusaurusContextProvider>
39
+ </ErrorBoundary>);
36
40
  }
37
- export default App;
@@ -0,0 +1,27 @@
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
+ import './styles.module.css';
9
+ declare const InsertBannerWindowAttribute = "__DOCUSAURUS_INSERT_BASEURL_BANNER";
10
+ declare global {
11
+ interface Window {
12
+ [InsertBannerWindowAttribute]: boolean;
13
+ }
14
+ }
15
+ /**
16
+ * We want to help the users with a bad baseUrl configuration (very common
17
+ * error). Help message is inlined, and hidden if JS or CSS is able to load.
18
+ *
19
+ * This component only inserts the base URL banner for the homepage, to avoid
20
+ * polluting every statically rendered page.
21
+ *
22
+ * Note: it might create false positives (ie network failures): not a big deal
23
+ *
24
+ * @see https://github.com/facebook/docusaurus/pull/3621
25
+ */
26
+ export default function MaybeBaseUrlIssueBanner(): JSX.Element | null;
27
+ export {};
@@ -30,8 +30,9 @@ function createInlineHtmlBanner(baseUrl) {
30
30
  </div>
31
31
  `;
32
32
  }
33
- // fn needs to work for older browsers!
33
+ // Needs to work for older browsers!
34
34
  function createInlineScript(baseUrl) {
35
+ /* language=js */
35
36
  return `
36
37
  window['${InsertBannerWindowAttribute}'] = true;
37
38
 
@@ -60,28 +61,38 @@ function insertBanner() {
60
61
  }
61
62
  `;
62
63
  }
63
- function BaseUrlIssueBannerEnabled() {
64
+ function BaseUrlIssueBanner() {
64
65
  const { siteConfig: { baseUrl }, } = useDocusaurusContext();
65
66
  // useLayoutEffect fires before DOMContentLoaded.
66
67
  // It gives the opportunity to avoid inserting the banner in the first place
67
68
  useLayoutEffect(() => {
68
69
  window[InsertBannerWindowAttribute] = false;
69
70
  }, []);
70
- return (React.createElement(React.Fragment, null,
71
- !ExecutionEnvironment.canUseDOM && (React.createElement(Head, null,
72
- React.createElement("script", null, createInlineScript(baseUrl)))),
73
- React.createElement("div", { id: BannerContainerId })));
71
+ return (<>
72
+ {!ExecutionEnvironment.canUseDOM && (
73
+ // Safe to use `ExecutionEnvironment`, because `Head` is purely
74
+ // side-effect and doesn't affect hydration
75
+ <Head>
76
+ <script>{createInlineScript(baseUrl)}</script>
77
+ </Head>)}
78
+ <div id={BannerContainerId}/>
79
+ </>);
74
80
  }
75
- // We want to help the users with a bad baseUrl configuration (very common error)
76
- // Help message is inlined, and hidden if JS or CSS is able to load
77
- // Note: it might create false positives (ie network failures): not a big deal
78
- // Note: we only inline this for the homepage to avoid polluting all the site's pages
79
- // See https://github.com/facebook/docusaurus/pull/3621
80
- export default function BaseUrlIssueBanner() {
81
+ /**
82
+ * We want to help the users with a bad baseUrl configuration (very common
83
+ * error). Help message is inlined, and hidden if JS or CSS is able to load.
84
+ *
85
+ * This component only inserts the base URL banner for the homepage, to avoid
86
+ * polluting every statically rendered page.
87
+ *
88
+ * Note: it might create false positives (ie network failures): not a big deal
89
+ *
90
+ * @see https://github.com/facebook/docusaurus/pull/3621
91
+ */
92
+ export default function MaybeBaseUrlIssueBanner() {
81
93
  const { siteConfig: { baseUrl, baseUrlIssueBanner }, } = useDocusaurusContext();
82
94
  const { pathname } = useLocation();
83
- // returns true for the homepage during SRR
84
95
  const isHomePage = pathname === baseUrl;
85
96
  const enabled = baseUrlIssueBanner && isHomePage;
86
- return enabled ? React.createElement(BaseUrlIssueBannerEnabled, null) : null;
97
+ return enabled ? <BaseUrlIssueBanner /> : null;
87
98
  }