@docusaurus/core 2.0.0-beta.16 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +14 -12
- package/bin/docusaurus.mjs +41 -93
- package/lib/babel/preset.js +2 -2
- package/lib/client/.eslintrc.js +2 -3
- package/lib/client/App.d.ts +1 -1
- package/lib/client/App.js +15 -7
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +34 -0
- package/lib/client/LinksCollector.d.ts +1 -1
- package/lib/client/LinksCollector.js +4 -5
- package/lib/client/PendingNavigation.d.ts +8 -17
- package/lib/client/PendingNavigation.js +39 -70
- package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
- package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
- package/lib/client/clientEntry.js +3 -4
- package/lib/client/docusaurus.d.ts +5 -5
- package/lib/client/docusaurus.js +26 -33
- package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
- package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -4
- package/lib/client/exports/BrowserOnly.js +2 -2
- package/lib/client/exports/ComponentCreator.js +65 -40
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +4 -5
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +18 -41
- package/lib/client/exports/Link.d.ts +3 -15
- package/lib/client/exports/Link.js +24 -30
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +3 -3
- package/lib/client/exports/useBaseUrl.js +8 -9
- package/lib/client/exports/useDocusaurusContext.js +1 -1
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +5 -5
- package/lib/client/exports/useIsBrowser.js +1 -1
- package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +12 -5
- package/lib/client/normalizeLocation.js +13 -8
- package/lib/client/prefetch.js +10 -28
- package/lib/client/preload.d.ts +1 -3
- package/lib/client/preload.js +5 -11
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.js +19 -18
- package/lib/client/theme-fallback/Error/index.js +7 -1
- package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
- package/lib/client/theme-fallback/Layout/index.js +2 -17
- package/lib/client/theme-fallback/Loading/index.js +2 -0
- package/lib/client/theme-fallback/NotFound/index.js +13 -5
- package/lib/client/theme-fallback/Root/index.d.ts +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -1
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +48 -30
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +6 -5
- package/lib/commands/deploy.d.ts +5 -5
- package/lib/commands/deploy.js +21 -45
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +6 -11
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +18 -19
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +33 -30
- package/lib/commands/swizzle/actions.d.ts +2 -2
- package/lib/commands/swizzle/actions.js +10 -10
- package/lib/commands/swizzle/common.d.ts +3 -3
- package/lib/commands/swizzle/common.js +8 -9
- package/lib/commands/swizzle/components.js +48 -13
- package/lib/commands/swizzle/config.js +21 -15
- package/lib/commands/swizzle/context.js +6 -12
- package/lib/commands/swizzle/index.d.ts +2 -2
- package/lib/commands/swizzle/index.js +5 -4
- package/lib/commands/swizzle/prompts.js +2 -2
- package/lib/commands/swizzle/tables.js +10 -13
- package/lib/commands/swizzle/themes.js +9 -8
- package/lib/commands/writeHeadingIds.d.ts +2 -9
- package/lib/commands/writeHeadingIds.js +11 -69
- package/lib/commands/writeTranslations.d.ts +3 -4
- package/lib/commands/writeTranslations.js +10 -14
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/brokenLinks.d.ts +3 -16
- package/lib/server/brokenLinks.js +37 -31
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +14 -9
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +39 -13
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/{choosePort.js → server/getHostPort.js} +24 -41
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +2 -11
- package/lib/server/i18n.js +7 -28
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +62 -229
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +65 -132
- package/lib/server/plugins/init.d.ts +6 -15
- package/lib/server/plugins/init.js +25 -83
- package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
- package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
- package/lib/server/plugins/pluginIds.d.ts +4 -0
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
- package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +112 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +169 -102
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +5 -14
- package/lib/server/translations/translations.js +23 -39
- package/lib/server/translations/translationsExtractor.d.ts +2 -2
- package/lib/server/translations/translationsExtractor.js +16 -19
- package/lib/server/utils.js +1 -1
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -1
- package/lib/webpack/base.js +12 -30
- package/lib/webpack/client.js +7 -8
- package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
- package/lib/webpack/plugins/LogPlugin.js +2 -2
- package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
- package/lib/webpack/plugins/WaitPlugin.js +3 -3
- package/lib/webpack/server.d.ts +2 -2
- package/lib/webpack/server.js +10 -8
- package/lib/webpack/utils.d.ts +9 -3
- package/lib/webpack/utils.js +20 -25
- package/package.json +38 -41
- package/lib/choosePort.d.ts +0 -11
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
- package/lib/client/client-lifecycles-dispatcher.js +0 -23
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/commandUtils.d.ts +0 -9
- package/lib/commands/commandUtils.js +0 -21
- package/lib/server/client-modules/index.js +0 -12
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/themes/alias.d.ts +0 -9
- package/lib/server/themes/alias.js +0 -48
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/index.d.ts +0 -9
- package/lib/server/versions/index.js +0 -51
package/bin/beforeCli.mjs
CHANGED
|
@@ -14,15 +14,21 @@ import path from 'path';
|
|
|
14
14
|
import updateNotifier from 'update-notifier';
|
|
15
15
|
import boxen from 'boxen';
|
|
16
16
|
import {createRequire} from 'module';
|
|
17
|
+
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
17
18
|
|
|
18
19
|
const packageJson = createRequire(import.meta.url)('../package.json');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** @type {Record<string, any>} */
|
|
21
|
+
let sitePkg;
|
|
22
|
+
try {
|
|
23
|
+
sitePkg = createRequire(path.resolve('package.json'))('./package.json');
|
|
24
|
+
} catch {
|
|
25
|
+
logger.warn`path=${'package.json'} file not found at CWD: path=${process.cwd()}.`;
|
|
26
|
+
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"'}.`;
|
|
27
|
+
sitePkg = {};
|
|
28
|
+
}
|
|
22
29
|
|
|
23
30
|
const {
|
|
24
31
|
name,
|
|
25
|
-
version,
|
|
26
32
|
engines: {node: requiredVersion},
|
|
27
33
|
} = packageJson;
|
|
28
34
|
|
|
@@ -40,12 +46,11 @@ export default async function beforeCli() {
|
|
|
40
46
|
const notifier = updateNotifier({
|
|
41
47
|
pkg: {
|
|
42
48
|
name,
|
|
43
|
-
version,
|
|
49
|
+
version: DOCUSAURUS_VERSION,
|
|
44
50
|
},
|
|
45
51
|
// Check is in background so it's fine to use a small value like 1h
|
|
46
52
|
// Use 0 for debugging
|
|
47
53
|
updateCheckInterval: 1000 * 60 * 60,
|
|
48
|
-
// updateCheckInterval: 0
|
|
49
54
|
});
|
|
50
55
|
|
|
51
56
|
// Hacky way to ensure we check for updates on first run
|
|
@@ -72,8 +77,7 @@ export default async function beforeCli() {
|
|
|
72
77
|
* @param {import('update-notifier').UpdateInfo} update
|
|
73
78
|
*/
|
|
74
79
|
function ignoreUpdate(update) {
|
|
75
|
-
const isCanaryRelease =
|
|
76
|
-
update && update.current && update.current.startsWith('0.0.0');
|
|
80
|
+
const isCanaryRelease = update?.current?.startsWith('0.0.0');
|
|
77
81
|
return isCanaryRelease;
|
|
78
82
|
}
|
|
79
83
|
|
|
@@ -98,9 +102,7 @@ export default async function beforeCli() {
|
|
|
98
102
|
.filter((p) => p.startsWith('@docusaurus'))
|
|
99
103
|
.map((p) => p.concat('@latest'))
|
|
100
104
|
.join(' ');
|
|
101
|
-
const isYarnUsed = await fs.pathExists(
|
|
102
|
-
path.resolve(process.cwd(), 'yarn.lock'),
|
|
103
|
-
);
|
|
105
|
+
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
|
|
104
106
|
const upgradeCommand = isYarnUsed
|
|
105
107
|
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
|
|
106
108
|
: `npm i ${siteDocusaurusPackagesForUpdate}`;
|
|
@@ -127,7 +129,7 @@ export default async function beforeCli() {
|
|
|
127
129
|
console.log(docusaurusUpdateMessage);
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
//
|
|
132
|
+
// Notify user if node version needs to be updated
|
|
131
133
|
if (!semver.satisfies(process.version, requiredVersion)) {
|
|
132
134
|
logger.error('Minimum Node.js version not met :(');
|
|
133
135
|
logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
|
package/bin/docusaurus.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import logger from '@docusaurus/logger';
|
|
12
12
|
import fs from 'fs-extra';
|
|
13
13
|
import cli from 'commander';
|
|
14
|
-
import {
|
|
14
|
+
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
15
15
|
import {
|
|
16
16
|
build,
|
|
17
17
|
swizzle,
|
|
@@ -29,9 +29,7 @@ await beforeCli();
|
|
|
29
29
|
|
|
30
30
|
const resolveDir = (dir = '.') => fs.realpath(dir);
|
|
31
31
|
|
|
32
|
-
cli
|
|
33
|
-
.version(createRequire(import.meta.url)('../package.json').version)
|
|
34
|
-
.usage('<command> [options]');
|
|
32
|
+
cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
|
|
35
33
|
|
|
36
34
|
cli
|
|
37
35
|
.command('build [siteDir]')
|
|
@@ -56,14 +54,8 @@ cli
|
|
|
56
54
|
'--no-minify',
|
|
57
55
|
'build website without minimizing JS bundles (default: false)',
|
|
58
56
|
)
|
|
59
|
-
.action(async (siteDir,
|
|
60
|
-
build(await resolveDir(siteDir),
|
|
61
|
-
bundleAnalyzer,
|
|
62
|
-
outDir,
|
|
63
|
-
config,
|
|
64
|
-
locale,
|
|
65
|
-
minify,
|
|
66
|
-
});
|
|
57
|
+
.action(async (siteDir, options) => {
|
|
58
|
+
build(await resolveDir(siteDir), options);
|
|
67
59
|
});
|
|
68
60
|
|
|
69
61
|
cli
|
|
@@ -88,9 +80,9 @@ cli
|
|
|
88
80
|
'copy TypeScript theme files when possible (default: false)',
|
|
89
81
|
)
|
|
90
82
|
.option('--danger', 'enable swizzle for unsafe component of themes')
|
|
91
|
-
.action(async (themeName, componentName, siteDir, options) =>
|
|
92
|
-
swizzle(await resolveDir(siteDir), themeName, componentName, options)
|
|
93
|
-
|
|
83
|
+
.action(async (themeName, componentName, siteDir, options) =>
|
|
84
|
+
swizzle(await resolveDir(siteDir), themeName, componentName, options),
|
|
85
|
+
);
|
|
94
86
|
|
|
95
87
|
cli
|
|
96
88
|
.command('deploy [siteDir]')
|
|
@@ -111,13 +103,9 @@ cli
|
|
|
111
103
|
'--skip-build',
|
|
112
104
|
'skip building website before deploy it (default: false)',
|
|
113
105
|
)
|
|
114
|
-
.action(async (siteDir,
|
|
115
|
-
deploy(await resolveDir(siteDir),
|
|
116
|
-
|
|
117
|
-
config,
|
|
118
|
-
skipBuild,
|
|
119
|
-
});
|
|
120
|
-
});
|
|
106
|
+
.action(async (siteDir, options) =>
|
|
107
|
+
deploy(await resolveDir(siteDir), options),
|
|
108
|
+
);
|
|
121
109
|
|
|
122
110
|
cli
|
|
123
111
|
.command('start [siteDir]')
|
|
@@ -138,18 +126,8 @@ cli
|
|
|
138
126
|
'--poll [interval]',
|
|
139
127
|
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
|
|
140
128
|
)
|
|
141
|
-
.action(
|
|
142
|
-
|
|
143
|
-
start(await resolveDir(siteDir), {
|
|
144
|
-
port,
|
|
145
|
-
host,
|
|
146
|
-
locale,
|
|
147
|
-
config,
|
|
148
|
-
hotOnly,
|
|
149
|
-
open,
|
|
150
|
-
poll,
|
|
151
|
-
});
|
|
152
|
-
},
|
|
129
|
+
.action(async (siteDir, options) =>
|
|
130
|
+
start(await resolveDir(siteDir), options),
|
|
153
131
|
);
|
|
154
132
|
|
|
155
133
|
cli
|
|
@@ -166,44 +144,25 @@ cli
|
|
|
166
144
|
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
|
167
145
|
.option('--build', 'build website before serving (default: false)')
|
|
168
146
|
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
|
169
|
-
.action(
|
|
170
|
-
|
|
171
|
-
siteDir,
|
|
172
|
-
{
|
|
173
|
-
dir = 'build',
|
|
174
|
-
port = 3000,
|
|
175
|
-
host = 'localhost',
|
|
176
|
-
build: buildSite = false,
|
|
177
|
-
config,
|
|
178
|
-
},
|
|
179
|
-
) => {
|
|
180
|
-
serve(await resolveDir(siteDir), {
|
|
181
|
-
dir,
|
|
182
|
-
port,
|
|
183
|
-
build: buildSite,
|
|
184
|
-
config,
|
|
185
|
-
host,
|
|
186
|
-
});
|
|
187
|
-
},
|
|
147
|
+
.action(async (siteDir, options) =>
|
|
148
|
+
serve(await resolveDir(siteDir), options),
|
|
188
149
|
);
|
|
189
150
|
|
|
190
151
|
cli
|
|
191
152
|
.command('clear [siteDir]')
|
|
192
153
|
.description('Remove build artifacts.')
|
|
193
|
-
.action(async (siteDir) =>
|
|
194
|
-
clear(await resolveDir(siteDir));
|
|
195
|
-
});
|
|
154
|
+
.action(async (siteDir) => clear(await resolveDir(siteDir)));
|
|
196
155
|
|
|
197
156
|
cli
|
|
198
157
|
.command('write-translations [siteDir]')
|
|
199
158
|
.description('Extract required translations of your site.')
|
|
200
159
|
.option(
|
|
201
160
|
'-l, --locale <locale>',
|
|
202
|
-
'the locale folder to write the translations
|
|
161
|
+
'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
|
|
203
162
|
)
|
|
204
163
|
.option(
|
|
205
164
|
'--override',
|
|
206
|
-
'
|
|
165
|
+
'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)',
|
|
207
166
|
)
|
|
208
167
|
.option(
|
|
209
168
|
'--config <config>',
|
|
@@ -211,20 +170,10 @@ cli
|
|
|
211
170
|
)
|
|
212
171
|
.option(
|
|
213
172
|
'--messagePrefix <messagePrefix>',
|
|
214
|
-
'
|
|
173
|
+
'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: "")',
|
|
215
174
|
)
|
|
216
|
-
.action(
|
|
217
|
-
|
|
218
|
-
siteDir,
|
|
219
|
-
{locale = undefined, override = false, messagePrefix = '', config},
|
|
220
|
-
) => {
|
|
221
|
-
writeTranslations(await resolveDir(siteDir), {
|
|
222
|
-
locale,
|
|
223
|
-
override,
|
|
224
|
-
config,
|
|
225
|
-
messagePrefix,
|
|
226
|
-
});
|
|
227
|
-
},
|
|
175
|
+
.action(async (siteDir, options) =>
|
|
176
|
+
writeTranslations(await resolveDir(siteDir), options),
|
|
228
177
|
);
|
|
229
178
|
|
|
230
179
|
cli
|
|
@@ -245,36 +194,35 @@ cli.arguments('<command>').action((cmd) => {
|
|
|
245
194
|
});
|
|
246
195
|
|
|
247
196
|
/**
|
|
248
|
-
* @param {string} command
|
|
197
|
+
* @param {string | undefined} command
|
|
249
198
|
*/
|
|
250
199
|
function isInternalCommand(command) {
|
|
251
|
-
return
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
200
|
+
return (
|
|
201
|
+
command &&
|
|
202
|
+
[
|
|
203
|
+
'start',
|
|
204
|
+
'build',
|
|
205
|
+
'swizzle',
|
|
206
|
+
'deploy',
|
|
207
|
+
'serve',
|
|
208
|
+
'clear',
|
|
209
|
+
'write-translations',
|
|
210
|
+
'write-heading-ids',
|
|
211
|
+
].includes(command)
|
|
212
|
+
);
|
|
261
213
|
}
|
|
262
214
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
cli.parse(process.argv);
|
|
215
|
+
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
|
216
|
+
await externalCommand(cli, await resolveDir('.'));
|
|
217
|
+
}
|
|
269
218
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
219
|
+
if (!process.argv.slice(2).length) {
|
|
220
|
+
cli.outputHelp();
|
|
273
221
|
}
|
|
274
222
|
|
|
275
|
-
|
|
223
|
+
cli.parse(process.argv);
|
|
276
224
|
|
|
277
225
|
process.on('unhandledRejection', (err) => {
|
|
278
|
-
logger.error(err);
|
|
226
|
+
logger.error(err instanceof Error ? err.stack : err);
|
|
279
227
|
process.exit(1);
|
|
280
228
|
});
|
package/lib/babel/preset.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const path_1 =
|
|
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 {
|
|
@@ -68,7 +68,7 @@ function getTransformOptions(isServer) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
function babelPresets(api) {
|
|
71
|
-
const callerName = api.caller((caller) => caller
|
|
71
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
72
72
|
return getTransformOptions(callerName === 'server');
|
|
73
73
|
}
|
|
74
74
|
exports.default = babelPresets;
|
package/lib/client/.eslintrc.js
CHANGED
|
@@ -11,12 +11,11 @@ module.exports = {
|
|
|
11
11
|
'error',
|
|
12
12
|
{
|
|
13
13
|
patterns: [
|
|
14
|
-
//
|
|
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
|
-
//
|
|
18
|
+
// Prevent importing server code in client bundle
|
|
20
19
|
'**/../babel/**',
|
|
21
20
|
'**/../server/**',
|
|
22
21
|
'**/../commands/**',
|
package/lib/client/App.d.ts
CHANGED
package/lib/client/App.js
CHANGED
|
@@ -5,25 +5,33 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import '@generated/client-modules';
|
|
8
9
|
import routes from '@generated/routes';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import { useLocation } from '@docusaurus/router';
|
|
11
|
+
import normalizeLocation from './normalizeLocation';
|
|
12
|
+
import renderRoutes from '@docusaurus/renderRoutes';
|
|
13
|
+
import { BrowserContextProvider } from './browserContext';
|
|
14
|
+
import { DocusaurusContextProvider } from './docusaurusContext';
|
|
12
15
|
import PendingNavigation from './PendingNavigation';
|
|
13
|
-
import BaseUrlIssueBanner from './
|
|
16
|
+
import BaseUrlIssueBanner from './BaseUrlIssueBanner';
|
|
17
|
+
import SiteMetadataDefaults from './SiteMetadataDefaults';
|
|
14
18
|
import Root from '@theme/Root';
|
|
15
|
-
import '
|
|
19
|
+
import SiteMetadata from '@theme/SiteMetadata';
|
|
16
20
|
// TODO, quick fix for CSS insertion order
|
|
17
21
|
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
18
22
|
import Error from '@theme/Error';
|
|
19
23
|
export default function App() {
|
|
24
|
+
const routeElement = renderRoutes(routes);
|
|
25
|
+
const location = useLocation();
|
|
20
26
|
return (<ErrorBoundary fallback={Error}>
|
|
21
27
|
<DocusaurusContextProvider>
|
|
22
28
|
<BrowserContextProvider>
|
|
23
29
|
<Root>
|
|
30
|
+
<SiteMetadataDefaults />
|
|
31
|
+
<SiteMetadata />
|
|
24
32
|
<BaseUrlIssueBanner />
|
|
25
|
-
<PendingNavigation
|
|
26
|
-
{
|
|
33
|
+
<PendingNavigation location={normalizeLocation(location)}>
|
|
34
|
+
{routeElement}
|
|
27
35
|
</PendingNavigation>
|
|
28
36
|
</Root>
|
|
29
37
|
</BrowserContextProvider>
|
package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts}
RENAMED
|
@@ -6,17 +6,22 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="react" />
|
|
8
8
|
import './styles.module.css';
|
|
9
|
+
declare const InsertBannerWindowAttribute = "__DOCUSAURUS_INSERT_BASEURL_BANNER";
|
|
9
10
|
declare global {
|
|
10
11
|
interface Window {
|
|
11
|
-
|
|
12
|
+
[InsertBannerWindowAttribute]: boolean;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* We want to help the users with a bad baseUrl configuration (very common
|
|
16
|
-
* error) Help message is inlined, and hidden if JS or CSS is able to load
|
|
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
|
+
*
|
|
17
22
|
* Note: it might create false positives (ie network failures): not a big deal
|
|
18
|
-
*
|
|
19
|
-
* pages
|
|
23
|
+
*
|
|
20
24
|
* @see https://github.com/facebook/docusaurus/pull/3621
|
|
21
25
|
*/
|
|
22
|
-
export default function
|
|
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
|
-
//
|
|
33
|
+
// Needs to work for older browsers!
|
|
34
34
|
function createInlineScript(baseUrl) {
|
|
35
35
|
return `
|
|
36
36
|
window['${InsertBannerWindowAttribute}'] = true;
|
|
@@ -60,7 +60,7 @@ function insertBanner() {
|
|
|
60
60
|
}
|
|
61
61
|
`;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
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
|
|
@@ -68,7 +68,10 @@ function BaseUrlIssueBannerEnabled() {
|
|
|
68
68
|
window[InsertBannerWindowAttribute] = false;
|
|
69
69
|
}, []);
|
|
70
70
|
return (<>
|
|
71
|
-
{!ExecutionEnvironment.canUseDOM && (
|
|
71
|
+
{!ExecutionEnvironment.canUseDOM && (
|
|
72
|
+
// Safe to use `ExecutionEnvironment`, because `Head` is purely
|
|
73
|
+
// side-effect and doesn't affect hydration
|
|
74
|
+
<Head>
|
|
72
75
|
<script>{createInlineScript(baseUrl)}</script>
|
|
73
76
|
</Head>)}
|
|
74
77
|
<div id={BannerContainerId}/>
|
|
@@ -76,17 +79,19 @@ function BaseUrlIssueBannerEnabled() {
|
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* We want to help the users with a bad baseUrl configuration (very common
|
|
79
|
-
* error) Help message is inlined, and hidden if JS or CSS is able to load
|
|
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
|
+
*
|
|
80
87
|
* Note: it might create false positives (ie network failures): not a big deal
|
|
81
|
-
*
|
|
82
|
-
* pages
|
|
88
|
+
*
|
|
83
89
|
* @see https://github.com/facebook/docusaurus/pull/3621
|
|
84
90
|
*/
|
|
85
|
-
export default function
|
|
91
|
+
export default function MaybeBaseUrlIssueBanner() {
|
|
86
92
|
const { siteConfig: { baseUrl, baseUrlIssueBanner }, } = useDocusaurusContext();
|
|
87
93
|
const { pathname } = useLocation();
|
|
88
|
-
// returns true for the homepage during SRR
|
|
89
94
|
const isHomePage = pathname === baseUrl;
|
|
90
95
|
const enabled = baseUrlIssueBanner && isHomePage;
|
|
91
|
-
return enabled ? <
|
|
96
|
+
return enabled ? <BaseUrlIssueBanner /> : null;
|
|
92
97
|
}
|
|
File without changes
|
|
@@ -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,34 @@
|
|
|
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 ClientLifecyclesDispatcher({ children, location, previousLocation, }) {
|
|
18
|
+
useLayoutEffect(() => {
|
|
19
|
+
if (previousLocation !== location) {
|
|
20
|
+
const { hash } = location;
|
|
21
|
+
if (!hash) {
|
|
22
|
+
window.scrollTo(0, 0);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const id = decodeURIComponent(hash.substring(1));
|
|
26
|
+
const element = document.getElementById(id);
|
|
27
|
+
element?.scrollIntoView();
|
|
28
|
+
}
|
|
29
|
+
dispatchLifecycleAction('onRouteDidUpdate', { previousLocation, location });
|
|
30
|
+
}
|
|
31
|
+
}, [previousLocation, location]);
|
|
32
|
+
return children;
|
|
33
|
+
}
|
|
34
|
+
export default ClientLifecyclesDispatcher;
|
|
@@ -13,7 +13,7 @@ declare type StatefulLinksCollector = LinksCollector & {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const createStatefulLinksCollector: () => StatefulLinksCollector;
|
|
15
15
|
export declare const useLinksCollector: () => LinksCollector;
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function LinksCollectorProvider({ children, linksCollector, }: {
|
|
17
17
|
children: ReactNode;
|
|
18
18
|
linksCollector: LinksCollector;
|
|
19
19
|
}): JSX.Element;
|
|
@@ -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 React, { useContext
|
|
7
|
+
import React, { useContext } from 'react';
|
|
8
8
|
export const createStatefulLinksCollector = () => {
|
|
9
9
|
// Set to dedup, as it's not useful to collect multiple times the same link
|
|
10
10
|
const allLinks = new Set();
|
|
@@ -15,13 +15,12 @@ export const createStatefulLinksCollector = () => {
|
|
|
15
15
|
getCollectedLinks: () => [...allLinks],
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
const Context = createContext({
|
|
18
|
+
const Context = React.createContext({
|
|
19
19
|
collectLink: () => {
|
|
20
|
-
//
|
|
21
|
-
// we only use the broken links checker server-side
|
|
20
|
+
// No-op for client. We only use the broken links checker server-side.
|
|
22
21
|
},
|
|
23
22
|
});
|
|
24
23
|
export const useLinksCollector = () => useContext(Context);
|
|
25
|
-
export function
|
|
24
|
+
export function LinksCollectorProvider({ children, linksCollector, }) {
|
|
26
25
|
return <Context.Provider value={linksCollector}>{children}</Context.Provider>;
|
|
27
26
|
}
|
|
@@ -4,29 +4,20 @@
|
|
|
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
|
-
/// <reference types="node" />
|
|
8
7
|
import React from 'react';
|
|
9
|
-
import { type RouteComponentProps } from 'react-router-dom';
|
|
10
|
-
import type { RouteConfig } from 'react-router-config';
|
|
11
8
|
import type { Location } from 'history';
|
|
12
|
-
|
|
13
|
-
interface Props extends RouteComponentProps {
|
|
14
|
-
readonly routes: RouteConfig[];
|
|
15
|
-
readonly delay: number;
|
|
9
|
+
declare type Props = {
|
|
16
10
|
readonly location: Location;
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
readonly children: JSX.Element;
|
|
12
|
+
};
|
|
13
|
+
declare type State = {
|
|
19
14
|
nextRouteHasLoaded: boolean;
|
|
20
|
-
}
|
|
15
|
+
};
|
|
21
16
|
declare class PendingNavigation extends React.Component<Props, State> {
|
|
22
|
-
previousLocation
|
|
23
|
-
|
|
17
|
+
private previousLocation;
|
|
18
|
+
private routeUpdateCleanupCb;
|
|
24
19
|
constructor(props: Props);
|
|
25
20
|
shouldComponentUpdate(nextProps: Props, nextState: State): boolean;
|
|
26
|
-
private clearProgressBarTimeout;
|
|
27
|
-
private startProgressBar;
|
|
28
|
-
private stopProgressBar;
|
|
29
21
|
render(): JSX.Element;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
|
-
export default _default;
|
|
23
|
+
export default PendingNavigation;
|