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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/docusaurus.mjs +221 -0
  4. package/lib/babel/preset.d.ts +8 -3
  5. package/lib/babel/preset.js +10 -8
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +47 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -8
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +37 -0
  32. package/lib/client/exports/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -49
  36. package/lib/client/exports/Link.d.ts +4 -10
  37. package/lib/client/exports/Link.js +40 -40
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +11 -14
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +6 -13
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/client/exports/useRouteContext.d.ts +8 -0
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +12 -2
  56. package/lib/client/flat.js +19 -15
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +14 -10
  59. package/lib/client/prefetch.d.ts +1 -2
  60. package/lib/client/prefetch.js +12 -32
  61. package/lib/client/preload.d.ts +3 -4
  62. package/lib/client/preload.js +5 -12
  63. package/lib/client/routeContext.d.ts +13 -0
  64. package/lib/client/routeContext.js +31 -0
  65. package/lib/client/serverEntry.d.ts +10 -0
  66. package/lib/client/serverEntry.js +108 -146
  67. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  68. package/lib/client/theme-fallback/Error/index.js +45 -0
  69. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  70. package/lib/client/theme-fallback/Layout/index.js +2 -26
  71. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  72. package/lib/client/theme-fallback/Loading/index.js +50 -116
  73. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  74. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  75. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  76. package/lib/client/theme-fallback/Root/index.js +2 -6
  77. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  78. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  79. package/lib/commands/build.d.ts +6 -2
  80. package/lib/commands/build.js +81 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +34 -21
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +104 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +9 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +29 -28
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +109 -101
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +101 -0
  93. package/lib/commands/swizzle/common.d.ts +33 -0
  94. package/lib/commands/swizzle/common.js +56 -0
  95. package/lib/commands/swizzle/components.d.ts +29 -0
  96. package/lib/commands/swizzle/components.js +200 -0
  97. package/lib/commands/swizzle/config.d.ts +10 -0
  98. package/lib/commands/swizzle/config.js +84 -0
  99. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  100. package/lib/commands/swizzle/context.js +24 -0
  101. package/lib/commands/swizzle/index.d.ts +8 -0
  102. package/lib/commands/swizzle/index.js +118 -0
  103. package/lib/commands/swizzle/prompts.d.ts +12 -0
  104. package/lib/commands/swizzle/prompts.js +110 -0
  105. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  106. package/lib/commands/swizzle/tables.js +113 -0
  107. package/lib/commands/swizzle/themes.d.ts +20 -0
  108. package/lib/commands/swizzle/themes.js +106 -0
  109. package/lib/commands/writeHeadingIds.d.ts +2 -6
  110. package/lib/commands/writeHeadingIds.js +22 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +46 -25
  113. package/lib/index.d.ts +9 -9
  114. package/lib/index.js +14 -14
  115. package/lib/server/brokenLinks.d.ts +4 -17
  116. package/lib/server/brokenLinks.js +67 -56
  117. package/lib/server/clientModules.d.ts +12 -0
  118. package/lib/server/clientModules.js +20 -0
  119. package/lib/server/config.d.ts +5 -2
  120. package/lib/server/config.js +29 -6
  121. package/lib/server/configValidation.d.ts +4 -4
  122. package/lib/server/configValidation.js +86 -41
  123. package/lib/server/getHostPort.d.ts +14 -0
  124. package/lib/server/getHostPort.js +79 -0
  125. package/lib/server/htmlTags.d.ts +12 -0
  126. package/lib/server/htmlTags.js +62 -0
  127. package/lib/server/i18n.d.ts +3 -13
  128. package/lib/server/i18n.js +21 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +83 -165
  131. package/lib/server/plugins/configs.d.ts +51 -0
  132. package/lib/server/plugins/configs.js +101 -0
  133. package/lib/server/plugins/index.d.ts +9 -8
  134. package/lib/server/plugins/index.js +73 -134
  135. package/lib/server/plugins/init.d.ts +6 -5
  136. package/lib/server/plugins/init.js +44 -109
  137. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  138. package/lib/server/plugins/moduleShorthand.js +46 -0
  139. package/lib/server/plugins/pluginIds.d.ts +5 -1
  140. package/lib/server/plugins/pluginIds.js +12 -7
  141. package/lib/server/plugins/presets.d.ts +12 -0
  142. package/lib/server/plugins/presets.js +49 -0
  143. package/lib/server/plugins/routeConfig.d.ts +11 -0
  144. package/lib/server/plugins/routeConfig.js +54 -0
  145. package/lib/server/plugins/synthetic.d.ts +20 -0
  146. package/lib/server/plugins/synthetic.js +111 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +182 -95
  149. package/lib/server/siteMetadata.d.ts +12 -0
  150. package/lib/server/siteMetadata.js +81 -0
  151. package/lib/server/translations/translations.d.ts +14 -19
  152. package/lib/server/translations/translations.js +40 -72
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  154. package/lib/server/translations/translationsExtractor.js +158 -122
  155. package/lib/server/utils.d.ts +9 -3
  156. package/lib/server/utils.js +7 -9
  157. package/lib/webpack/aliases/index.d.ts +34 -0
  158. package/lib/webpack/aliases/index.js +106 -0
  159. package/lib/webpack/base.d.ts +3 -4
  160. package/lib/webpack/base.js +45 -57
  161. package/lib/webpack/client.d.ts +3 -3
  162. package/lib/webpack/client.js +12 -19
  163. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  164. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  165. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  166. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  167. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  168. package/lib/webpack/plugins/LogPlugin.js +4 -5
  169. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  170. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  171. package/lib/webpack/server.d.ts +5 -5
  172. package/lib/webpack/server.js +22 -9
  173. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  174. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  175. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +61 -182
  178. package/package.json +81 -77
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.eslintrc.js +0 -29
  183. package/lib/client/.tsbuildinfo +0 -1
  184. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  185. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  186. package/lib/client/nprogress.css +0 -36
  187. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  188. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  189. package/lib/commands/commandUtils.d.ts +0 -3
  190. package/lib/commands/commandUtils.js +0 -21
  191. package/lib/commands/swizzle.d.ts +0 -9
  192. package/lib/commands/swizzle.js +0 -245
  193. package/lib/constants.d.ts +0 -18
  194. package/lib/constants.js +0 -23
  195. package/lib/server/client-modules/index.js +0 -14
  196. package/lib/server/duplicateRoutes.d.ts +0 -10
  197. package/lib/server/duplicateRoutes.js +0 -38
  198. package/lib/server/html-tags/htmlTags.js +0 -40
  199. package/lib/server/html-tags/index.d.ts +0 -9
  200. package/lib/server/html-tags/index.js +0 -43
  201. package/lib/server/loadSetup.d.ts +0 -9
  202. package/lib/server/loadSetup.js +0 -25
  203. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
  204. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  205. package/lib/server/presets/index.d.ts +0 -11
  206. package/lib/server/presets/index.js +0 -48
  207. package/lib/server/themes/alias.d.ts +0 -8
  208. package/lib/server/themes/alias.js +0 -40
  209. package/lib/server/themes/index.d.ts +0 -12
  210. package/lib/server/themes/index.js +0 -47
  211. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  212. package/lib/server/versions/__fixtures__/package.json +0 -3
  213. package/lib/server/versions/__tests/index.test.js +0 -25
  214. package/lib/server/versions/index.d.ts +0 -10
  215. package/lib/server/versions/index.js +0 -50
  216. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  217. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  218. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  219. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  220. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  221. package/lib/webpack/sharedModuleAliases.js +0 -18
  222. package/tsconfig.client.json +0 -13
  223. package/tsconfig.json +0 -13
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
+ }
@@ -0,0 +1,221 @@
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 logger from '@docusaurus/logger';
12
+ import cli from 'commander';
13
+ import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
14
+ import {
15
+ build,
16
+ swizzle,
17
+ deploy,
18
+ start,
19
+ externalCommand,
20
+ serve,
21
+ clear,
22
+ writeTranslations,
23
+ writeHeadingIds,
24
+ } from '../lib/index.js';
25
+ import beforeCli from './beforeCli.mjs';
26
+
27
+ await beforeCli();
28
+
29
+ cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
30
+
31
+ cli
32
+ .command('build [siteDir]')
33
+ .description('Build website.')
34
+ .option(
35
+ '--bundle-analyzer',
36
+ 'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
37
+ )
38
+ .option(
39
+ '--out-dir <dir>',
40
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
41
+ )
42
+ .option(
43
+ '--config <config>',
44
+ 'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
45
+ )
46
+ .option(
47
+ '-l, --locale <locale>',
48
+ 'build the site in a specified locale. Build all known locales otherwise',
49
+ )
50
+ .option(
51
+ '--no-minify',
52
+ 'build website without minimizing JS bundles (default: false)',
53
+ )
54
+ // @ts-expect-error: Promise<string> is not assignable to Promise<void>... but
55
+ // good enough here.
56
+ .action(build);
57
+
58
+ cli
59
+ .command('swizzle [themeName] [componentName] [siteDir]')
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
+ )
71
+ .option(
72
+ '-l, --list',
73
+ 'only list the available themes/components without further prompting (default: false)',
74
+ )
75
+ .option(
76
+ '-t, --typescript',
77
+ 'copy TypeScript theme files when possible (default: false)',
78
+ )
79
+ .option('--danger', 'enable swizzle for unsafe component of themes')
80
+ .action(swizzle);
81
+
82
+ cli
83
+ .command('deploy [siteDir]')
84
+ .description('Deploy website to GitHub pages.')
85
+ .option(
86
+ '-l, --locale <locale>',
87
+ 'deploy the site in a specified locale. Deploy all known locales otherwise',
88
+ )
89
+ .option(
90
+ '--out-dir <dir>',
91
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
92
+ )
93
+ .option(
94
+ '--config <config>',
95
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
96
+ )
97
+ .option(
98
+ '--skip-build',
99
+ 'skip building website before deploy it (default: false)',
100
+ )
101
+ .action(deploy);
102
+
103
+ cli
104
+ .command('start [siteDir]')
105
+ .description('Start the development server.')
106
+ .option('-p, --port <port>', 'use specified port (default: 3000)')
107
+ .option('-h, --host <host>', 'use specified host (default: localhost)')
108
+ .option('-l, --locale <locale>', 'use specified site locale')
109
+ .option(
110
+ '--hot-only',
111
+ 'do not fallback to page refresh if hot reload fails (default: false)',
112
+ )
113
+ .option(
114
+ '--config <config>',
115
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
116
+ )
117
+ .option('--no-open', 'do not open page in the browser (default: false)')
118
+ .option(
119
+ '--poll [interval]',
120
+ 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
121
+ )
122
+ .option(
123
+ '--no-minify',
124
+ 'build website without minimizing JS bundles (default: false)',
125
+ )
126
+ .action(start);
127
+
128
+ cli
129
+ .command('serve [siteDir]')
130
+ .description('Serve website locally.')
131
+ .option(
132
+ '--dir <dir>',
133
+ 'the full path for the new output directory, relative to the current workspace (default: build)',
134
+ )
135
+ .option(
136
+ '--config <config>',
137
+ 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
138
+ )
139
+ .option('-p, --port <port>', 'use specified port (default: 3000)')
140
+ .option('--build', 'build website before serving (default: false)')
141
+ .option('-h, --host <host>', 'use specified host (default: localhost)')
142
+ .option(
143
+ '--no-open',
144
+ 'do not open page in the browser (default: false, or true in CI)',
145
+ )
146
+ .action(serve);
147
+
148
+ cli
149
+ .command('clear [siteDir]')
150
+ .description('Remove build artifacts.')
151
+ .action(clear);
152
+
153
+ cli
154
+ .command('write-translations [siteDir]')
155
+ .description('Extract required translations of your site.')
156
+ .option(
157
+ '-l, --locale <locale>',
158
+ 'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
159
+ )
160
+ .option(
161
+ '--override',
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)',
163
+ )
164
+ .option(
165
+ '--config <config>',
166
+ 'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)',
167
+ )
168
+ .option(
169
+ '--messagePrefix <messagePrefix>',
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: "")',
171
+ )
172
+ .action(writeTranslations);
173
+
174
+ cli
175
+ .command('write-heading-ids [siteDir] [files...]')
176
+ .description('Generate heading ids in Markdown content.')
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);
183
+
184
+ cli.arguments('<command>').action((cmd) => {
185
+ cli.outputHelp();
186
+ logger.error` Unknown command name=${cmd}.`;
187
+ });
188
+
189
+ /**
190
+ * @param {string | undefined} command
191
+ */
192
+ function isInternalCommand(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
+ );
206
+ }
207
+
208
+ if (!isInternalCommand(process.argv.slice(2)[0])) {
209
+ await externalCommand(cli);
210
+ }
211
+
212
+ if (!process.argv.slice(2).length) {
213
+ cli.outputHelp();
214
+ }
215
+
216
+ cli.parse(process.argv);
217
+
218
+ process.on('unhandledRejection', (err) => {
219
+ logger.error(err instanceof Error ? err.stack : err);
220
+ process.exit(1);
221
+ });
@@ -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
  }
@@ -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;
@@ -0,0 +1,39 @@
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 { useLayoutEffect } from 'react';
8
+ import clientModules from '@generated/client-modules';
9
+ export function dispatchLifecycleAction(lifecycleAction, ...args) {
10
+ const callbacks = clientModules.map((clientModule) => {
11
+ const lifecycleFunction = (clientModule.default?.[lifecycleAction] ??
12
+ clientModule[lifecycleAction]);
13
+ return lifecycleFunction?.(...args);
14
+ });
15
+ return () => callbacks.forEach((cb) => cb?.());
16
+ }
17
+ function scrollAfterNavigation(location) {
18
+ const { hash } = location;
19
+ if (!hash) {
20
+ window.scrollTo(0, 0);
21
+ }
22
+ else {
23
+ const id = decodeURIComponent(hash.substring(1));
24
+ const element = document.getElementById(id);
25
+ element?.scrollIntoView();
26
+ }
27
+ }
28
+ function ClientLifecyclesDispatcher({ children, location, previousLocation, }) {
29
+ useLayoutEffect(() => {
30
+ if (previousLocation !== location) {
31
+ if (previousLocation) {
32
+ scrollAfterNavigation(location);
33
+ }
34
+ dispatchLifecycleAction('onRouteDidUpdate', { previousLocation, location });
35
+ }
36
+ }, [previousLocation, location]);
37
+ return children;
38
+ }
39
+ export default ClientLifecyclesDispatcher;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { ReactNode } from 'react';
7
+ import { type ReactNode } from 'react';
8
8
  declare type LinksCollector = {
9
9
  collectLink: (link: string) => void;
10
10
  };
@@ -13,8 +13,8 @@ declare type StatefulLinksCollector = LinksCollector & {
13
13
  };
14
14
  export declare const createStatefulLinksCollector: () => StatefulLinksCollector;
15
15
  export declare const useLinksCollector: () => LinksCollector;
16
- export declare const ProvideLinksCollector: ({ children, linksCollector, }: {
16
+ export declare function LinksCollectorProvider({ children, linksCollector, }: {
17
17
  children: ReactNode;
18
18
  linksCollector: LinksCollector;
19
- }) => JSX.Element;
19
+ }): JSX.Element;
20
20
  export {};