@docusaurus/core 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21

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 (222) hide show
  1. package/bin/beforeCli.mjs +140 -0
  2. package/bin/docusaurus.mjs +236 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +10 -8
  5. package/lib/client/.eslintrc.js +2 -4
  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} +24 -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 +41 -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 +36 -0
  32. package/lib/client/exports/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -49
  36. package/lib/client/exports/Link.d.ts +4 -10
  37. package/lib/client/exports/Link.js +38 -38
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +11 -14
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +6 -13
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/client/exports/useRouteContext.d.ts +8 -0
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +12 -2
  56. package/lib/client/flat.js +19 -15
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +14 -10
  59. package/lib/client/prefetch.d.ts +1 -2
  60. package/lib/client/prefetch.js +12 -32
  61. package/lib/client/preload.d.ts +3 -4
  62. package/lib/client/preload.js +5 -12
  63. package/lib/client/routeContext.d.ts +13 -0
  64. package/lib/client/routeContext.js +31 -0
  65. package/lib/client/serverEntry.d.ts +10 -0
  66. package/lib/client/serverEntry.js +105 -146
  67. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  68. package/lib/client/theme-fallback/Error/index.js +45 -0
  69. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  70. package/lib/client/theme-fallback/Layout/index.js +2 -26
  71. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  72. package/lib/client/theme-fallback/Loading/index.js +50 -116
  73. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  74. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  75. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  76. package/lib/client/theme-fallback/Root/index.js +2 -6
  77. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  78. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  79. package/lib/commands/build.d.ts +6 -2
  80. package/lib/commands/build.js +80 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +32 -20
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +93 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +6 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +26 -27
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +106 -92
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +100 -0
  93. package/lib/commands/swizzle/common.d.ts +33 -0
  94. package/lib/commands/swizzle/common.js +56 -0
  95. package/lib/commands/swizzle/components.d.ts +29 -0
  96. package/lib/commands/swizzle/components.js +200 -0
  97. package/lib/commands/swizzle/config.d.ts +10 -0
  98. package/lib/commands/swizzle/config.js +84 -0
  99. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  100. package/lib/commands/swizzle/context.js +24 -0
  101. package/lib/commands/swizzle/index.d.ts +8 -0
  102. package/lib/commands/swizzle/index.js +116 -0
  103. package/lib/commands/swizzle/prompts.d.ts +12 -0
  104. package/lib/commands/swizzle/prompts.js +110 -0
  105. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  106. package/lib/commands/swizzle/tables.js +113 -0
  107. package/lib/commands/swizzle/themes.d.ts +20 -0
  108. package/lib/commands/swizzle/themes.js +106 -0
  109. package/lib/commands/writeHeadingIds.d.ts +2 -6
  110. package/lib/commands/writeHeadingIds.js +21 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +39 -20
  113. package/lib/index.d.ts +9 -9
  114. package/lib/index.js +14 -14
  115. package/lib/server/brokenLinks.d.ts +4 -17
  116. package/lib/server/brokenLinks.js +67 -56
  117. package/lib/server/clientModules.d.ts +12 -0
  118. package/lib/server/clientModules.js +20 -0
  119. package/lib/server/config.d.ts +5 -2
  120. package/lib/server/config.js +29 -6
  121. package/lib/server/configValidation.d.ts +4 -4
  122. package/lib/server/configValidation.js +80 -38
  123. package/lib/server/getHostPort.d.ts +14 -0
  124. package/lib/server/getHostPort.js +79 -0
  125. package/lib/server/htmlTags.d.ts +12 -0
  126. package/lib/server/htmlTags.js +62 -0
  127. package/lib/server/i18n.d.ts +3 -13
  128. package/lib/server/i18n.js +19 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +79 -163
  131. package/lib/server/plugins/configs.d.ts +51 -0
  132. package/lib/server/plugins/configs.js +101 -0
  133. package/lib/server/plugins/index.d.ts +9 -8
  134. package/lib/server/plugins/index.js +72 -135
  135. package/lib/server/plugins/init.d.ts +6 -5
  136. package/lib/server/plugins/init.js +44 -109
  137. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  138. package/lib/server/plugins/moduleShorthand.js +46 -0
  139. package/lib/server/plugins/pluginIds.d.ts +5 -1
  140. package/lib/server/plugins/pluginIds.js +12 -7
  141. package/lib/server/plugins/presets.d.ts +12 -0
  142. package/lib/server/plugins/presets.js +49 -0
  143. package/lib/server/plugins/routeConfig.d.ts +11 -0
  144. package/lib/server/plugins/routeConfig.js +54 -0
  145. package/lib/server/plugins/synthetic.d.ts +20 -0
  146. package/lib/server/plugins/synthetic.js +112 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +185 -95
  149. package/lib/server/siteMetadata.d.ts +12 -0
  150. package/lib/server/siteMetadata.js +81 -0
  151. package/lib/server/translations/translations.d.ts +11 -14
  152. package/lib/server/translations/translations.js +36 -60
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  154. package/lib/server/translations/translationsExtractor.js +158 -122
  155. package/lib/server/utils.d.ts +9 -3
  156. package/lib/server/utils.js +7 -9
  157. package/lib/webpack/aliases/index.d.ts +34 -0
  158. package/lib/webpack/aliases/index.js +106 -0
  159. package/lib/webpack/base.d.ts +3 -4
  160. package/lib/webpack/base.js +45 -57
  161. package/lib/webpack/client.d.ts +3 -3
  162. package/lib/webpack/client.js +12 -19
  163. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  164. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  165. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  166. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  167. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  168. package/lib/webpack/plugins/LogPlugin.js +4 -5
  169. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  170. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  171. package/lib/webpack/server.d.ts +5 -5
  172. package/lib/webpack/server.js +16 -12
  173. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  174. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  175. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +61 -182
  178. package/package.json +82 -77
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.tsbuildinfo +0 -1
  183. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  184. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  185. package/lib/client/nprogress.css +0 -36
  186. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  187. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  188. package/lib/commands/commandUtils.d.ts +0 -3
  189. package/lib/commands/commandUtils.js +0 -21
  190. package/lib/commands/swizzle.d.ts +0 -9
  191. package/lib/commands/swizzle.js +0 -245
  192. package/lib/constants.d.ts +0 -18
  193. package/lib/constants.js +0 -23
  194. package/lib/server/client-modules/index.js +0 -14
  195. package/lib/server/duplicateRoutes.d.ts +0 -10
  196. package/lib/server/duplicateRoutes.js +0 -38
  197. package/lib/server/html-tags/htmlTags.js +0 -40
  198. package/lib/server/html-tags/index.d.ts +0 -9
  199. package/lib/server/html-tags/index.js +0 -43
  200. package/lib/server/loadSetup.d.ts +0 -9
  201. package/lib/server/loadSetup.js +0 -25
  202. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
  203. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  204. package/lib/server/presets/index.d.ts +0 -11
  205. package/lib/server/presets/index.js +0 -48
  206. package/lib/server/themes/alias.d.ts +0 -8
  207. package/lib/server/themes/alias.js +0 -40
  208. package/lib/server/themes/index.d.ts +0 -12
  209. package/lib/server/themes/index.js +0 -47
  210. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  211. package/lib/server/versions/__fixtures__/package.json +0 -3
  212. package/lib/server/versions/__tests/index.test.js +0 -25
  213. package/lib/server/versions/index.d.ts +0 -10
  214. package/lib/server/versions/index.js +0 -50
  215. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  216. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  217. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  218. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  219. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  220. package/lib/webpack/sharedModuleAliases.js +0 -18
  221. package/tsconfig.client.json +0 -13
  222. package/tsconfig.json +0 -13
@@ -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
+ }
@@ -0,0 +1,236 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ // @ts-check
10
+
11
+ import fs from 'fs-extra';
12
+ import logger from '@docusaurus/logger';
13
+ import cli from 'commander';
14
+ import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
15
+ import {
16
+ build,
17
+ swizzle,
18
+ deploy,
19
+ start,
20
+ externalCommand,
21
+ serve,
22
+ clear,
23
+ writeTranslations,
24
+ writeHeadingIds,
25
+ } from '../lib/index.js';
26
+ import beforeCli from './beforeCli.mjs';
27
+
28
+ await beforeCli();
29
+
30
+ const resolveDir = (dir = '.') => fs.realpath(dir);
31
+
32
+ cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
33
+
34
+ cli
35
+ .command('build [siteDir]')
36
+ .description('Build website.')
37
+ .option(
38
+ '--bundle-analyzer',
39
+ 'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
40
+ )
41
+ .option(
42
+ '--out-dir <dir>',
43
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
44
+ )
45
+ .option(
46
+ '--config <config>',
47
+ 'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
48
+ )
49
+ .option(
50
+ '-l, --locale <locale>',
51
+ 'build the site in a specified locale. Build all known locales otherwise',
52
+ )
53
+ .option(
54
+ '--no-minify',
55
+ 'build website without minimizing JS bundles (default: false)',
56
+ )
57
+ .action(async (siteDir, options) => {
58
+ build(await resolveDir(siteDir), options);
59
+ });
60
+
61
+ cli
62
+ .command('swizzle [themeName] [componentName] [siteDir]')
63
+ .description(
64
+ 'Wraps or ejects the original theme files into website folder for customization.',
65
+ )
66
+ .option(
67
+ '-w, --wrap',
68
+ 'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.',
69
+ )
70
+ .option(
71
+ '-e, --eject',
72
+ 'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.',
73
+ )
74
+ .option(
75
+ '-l, --list',
76
+ 'only list the available themes/components without further prompting (default: false)',
77
+ )
78
+ .option(
79
+ '-t, --typescript',
80
+ 'copy TypeScript theme files when possible (default: false)',
81
+ )
82
+ .option('--danger', 'enable swizzle for unsafe component of themes')
83
+ .action(async (themeName, componentName, siteDir, options) =>
84
+ swizzle(await resolveDir(siteDir), themeName, componentName, options),
85
+ );
86
+
87
+ cli
88
+ .command('deploy [siteDir]')
89
+ .description('Deploy website to GitHub pages.')
90
+ .option(
91
+ '-l, --locale <locale>',
92
+ 'deploy the site in a specified locale. Deploy all known locales otherwise',
93
+ )
94
+ .option(
95
+ '--out-dir <dir>',
96
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
97
+ )
98
+ .option(
99
+ '--config <config>',
100
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
101
+ )
102
+ .option(
103
+ '--skip-build',
104
+ 'skip building website before deploy it (default: false)',
105
+ )
106
+ .action(async (siteDir, options) =>
107
+ deploy(await resolveDir(siteDir), options),
108
+ );
109
+
110
+ cli
111
+ .command('start [siteDir]')
112
+ .description('Start the development server.')
113
+ .option('-p, --port <port>', 'use specified port (default: 3000)')
114
+ .option('-h, --host <host>', 'use specified host (default: localhost)')
115
+ .option('-l, --locale <locale>', 'use specified site locale')
116
+ .option(
117
+ '--hot-only',
118
+ 'do not fallback to page refresh if hot reload fails (default: false)',
119
+ )
120
+ .option(
121
+ '--config <config>',
122
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
123
+ )
124
+ .option('--no-open', 'do not open page in the browser (default: false)')
125
+ .option(
126
+ '--poll [interval]',
127
+ 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
128
+ )
129
+ .option(
130
+ '--no-minify',
131
+ 'build website without minimizing JS bundles (default: false)',
132
+ )
133
+ .action(async (siteDir, options) =>
134
+ start(await resolveDir(siteDir), options),
135
+ );
136
+
137
+ cli
138
+ .command('serve [siteDir]')
139
+ .description('Serve website locally.')
140
+ .option(
141
+ '--dir <dir>',
142
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
143
+ )
144
+ .option(
145
+ '--config <config>',
146
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
147
+ )
148
+ .option('-p, --port <port>', 'use specified port (default: 3000)')
149
+ .option('--build', 'build website before serving (default: false)')
150
+ .option('-h, --host <host>', 'use specified host (default: localhost)')
151
+ .option(
152
+ '--no-open',
153
+ 'do not open page in the browser (default: false, or true in CI)',
154
+ )
155
+ .action(async (siteDir, options) =>
156
+ serve(await resolveDir(siteDir), options),
157
+ );
158
+
159
+ cli
160
+ .command('clear [siteDir]')
161
+ .description('Remove build artifacts.')
162
+ .action(async (siteDir) => clear(await resolveDir(siteDir)));
163
+
164
+ cli
165
+ .command('write-translations [siteDir]')
166
+ .description('Extract required translations of your site.')
167
+ .option(
168
+ '-l, --locale <locale>',
169
+ 'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
170
+ )
171
+ .option(
172
+ '--override',
173
+ '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)',
174
+ )
175
+ .option(
176
+ '--config <config>',
177
+ 'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)',
178
+ )
179
+ .option(
180
+ '--messagePrefix <messagePrefix>',
181
+ '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: "")',
182
+ )
183
+ .action(async (siteDir, options) =>
184
+ writeTranslations(await resolveDir(siteDir), options),
185
+ );
186
+
187
+ cli
188
+ .command('write-heading-ids [siteDir] [files...]')
189
+ .description('Generate heading ids in Markdown content.')
190
+ .option(
191
+ '--maintain-case',
192
+ "keep the headings' casing, otherwise make all lowercase (default: false)",
193
+ )
194
+ .option('--overwrite', 'overwrite existing heading IDs (default: false)')
195
+ .action(async (siteDir, files, options) =>
196
+ writeHeadingIds(await resolveDir(siteDir), files, options),
197
+ );
198
+
199
+ cli.arguments('<command>').action((cmd) => {
200
+ cli.outputHelp();
201
+ logger.error` Unknown command name=${cmd}.`;
202
+ });
203
+
204
+ /**
205
+ * @param {string | undefined} command
206
+ */
207
+ function isInternalCommand(command) {
208
+ return (
209
+ command &&
210
+ [
211
+ 'start',
212
+ 'build',
213
+ 'swizzle',
214
+ 'deploy',
215
+ 'serve',
216
+ 'clear',
217
+ 'write-translations',
218
+ 'write-heading-ids',
219
+ ].includes(command)
220
+ );
221
+ }
222
+
223
+ if (!isInternalCommand(process.argv.slice(2)[0])) {
224
+ await externalCommand(cli, await resolveDir('.'));
225
+ }
226
+
227
+ if (!process.argv.slice(2).length) {
228
+ cli.outputHelp();
229
+ }
230
+
231
+ cli.parse(process.argv);
232
+
233
+ process.on('unhandledRejection', (err) => {
234
+ logger.error(err instanceof Error ? err.stack : err);
235
+ process.exit(1);
236
+ });
@@ -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;
@@ -11,17 +11,15 @@ module.exports = {
11
11
  'error',
12
12
  {
13
13
  patterns: [
14
- // prevent importing lodash in client bundle
15
- // prefer shipping vanilla JS
14
+ // Prevent importing lodash in client bundle for bundle size
16
15
  'lodash',
17
16
  'lodash.**',
18
17
  'lodash/**',
19
- // prevent importing server code in client bundle
18
+ // Prevent importing server code in client bundle
20
19
  '**/../babel/**',
21
20
  '**/../server/**',
22
21
  '**/../commands/**',
23
22
  '**/../webpack/**',
24
- '**/../constants',
25
23
  ],
26
24
  },
27
25
  ],
@@ -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,7 +30,7 @@ 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
35
  return `
36
36
  window['${InsertBannerWindowAttribute}'] = true;
@@ -60,28 +60,38 @@ function insertBanner() {
60
60
  }
61
61
  `;
62
62
  }
63
- function BaseUrlIssueBannerEnabled() {
63
+ function BaseUrlIssueBanner() {
64
64
  const { siteConfig: { baseUrl }, } = useDocusaurusContext();
65
65
  // useLayoutEffect fires before DOMContentLoaded.
66
66
  // It gives the opportunity to avoid inserting the banner in the first place
67
67
  useLayoutEffect(() => {
68
68
  window[InsertBannerWindowAttribute] = false;
69
69
  }, []);
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 })));
70
+ return (<>
71
+ {!ExecutionEnvironment.canUseDOM && (
72
+ // Safe to use `ExecutionEnvironment`, because `Head` is purely
73
+ // side-effect and doesn't affect hydration
74
+ <Head>
75
+ <script>{createInlineScript(baseUrl)}</script>
76
+ </Head>)}
77
+ <div id={BannerContainerId}/>
78
+ </>);
74
79
  }
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() {
80
+ /**
81
+ * We want to help the users with a bad baseUrl configuration (very common
82
+ * error). Help message is inlined, and hidden if JS or CSS is able to load.
83
+ *
84
+ * This component only inserts the base URL banner for the homepage, to avoid
85
+ * polluting every statically rendered page.
86
+ *
87
+ * Note: it might create false positives (ie network failures): not a big deal
88
+ *
89
+ * @see https://github.com/facebook/docusaurus/pull/3621
90
+ */
91
+ export default function MaybeBaseUrlIssueBanner() {
81
92
  const { siteConfig: { baseUrl, baseUrlIssueBanner }, } = useDocusaurusContext();
82
93
  const { pathname } = useLocation();
83
- // returns true for the homepage during SRR
84
94
  const isHomePage = pathname === baseUrl;
85
95
  const enabled = baseUrlIssueBanner && isHomePage;
86
- return enabled ? React.createElement(BaseUrlIssueBannerEnabled, null) : null;
96
+ return enabled ? <BaseUrlIssueBanner /> : null;
87
97
  }
@@ -0,0 +1,16 @@
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 ReactElement } from 'react';
8
+ import type { ClientModule } from '@docusaurus/types';
9
+ import type { Location } from 'history';
10
+ export declare function dispatchLifecycleAction<K extends keyof ClientModule>(lifecycleAction: K, ...args: Parameters<NonNullable<ClientModule[K]>>): () => void;
11
+ declare function ClientLifecyclesDispatcher({ children, location, previousLocation, }: {
12
+ children: ReactElement;
13
+ location: Location;
14
+ previousLocation: Location | null;
15
+ }): JSX.Element;
16
+ export default ClientLifecyclesDispatcher;