@docusaurus/core 2.0.0-beta.2 → 2.0.0-beta.20
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 +138 -0
- package/bin/docusaurus.mjs +228 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/client/.eslintrc.js +2 -4
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +30 -27
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +24 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +39 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +11 -5
- package/lib/client/docusaurus.js +29 -42
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +67 -41
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +39 -39
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -10
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +11 -31
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +7 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +49 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- 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 +77 -61
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +32 -20
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +83 -71
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +6 -11
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +20 -26
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +105 -91
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +83 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +116 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +21 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +39 -20
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +65 -54
- 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 -6
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +76 -35
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +19 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +79 -163
- 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 +71 -131
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +43 -108
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- 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 +185 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +11 -14
- package/lib/server/translations/translations.js +36 -60
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +159 -121
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +41 -53
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +8 -8
- package/lib/webpack/plugins/CleanWebpackPlugin.js +9 -15
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +15 -7
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +57 -176
- package/package.json +75 -73
- package/bin/docusaurus.js +0 -325
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -40
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,138 @@
|
|
|
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 logger from '@docusaurus/logger';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import semver from 'semver';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import updateNotifier from 'update-notifier';
|
|
15
|
+
import boxen from 'boxen';
|
|
16
|
+
import {createRequire} from 'module';
|
|
17
|
+
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
18
|
+
|
|
19
|
+
const packageJson = createRequire(import.meta.url)('../package.json');
|
|
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
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
name,
|
|
32
|
+
engines: {node: requiredVersion},
|
|
33
|
+
} = packageJson;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Notify user if `@docusaurus` packages are outdated
|
|
37
|
+
*
|
|
38
|
+
* Note: this is a 2-step process to avoid delaying cli usage by awaiting a
|
|
39
|
+
* response:
|
|
40
|
+
* - 1st run: trigger background job to check releases + store result
|
|
41
|
+
* - 2nd run: display potential update to users
|
|
42
|
+
*
|
|
43
|
+
* cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
|
|
44
|
+
*/
|
|
45
|
+
export default async function beforeCli() {
|
|
46
|
+
const notifier = updateNotifier({
|
|
47
|
+
pkg: {
|
|
48
|
+
name,
|
|
49
|
+
version: DOCUSAURUS_VERSION,
|
|
50
|
+
},
|
|
51
|
+
// Check is in background so it's fine to use a small value like 1h
|
|
52
|
+
// Use 0 for debugging
|
|
53
|
+
updateCheckInterval: 1000 * 60 * 60,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Hacky way to ensure we check for updates on first run
|
|
57
|
+
// Note: the notification will only happen in the 2nd run
|
|
58
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
59
|
+
try {
|
|
60
|
+
if (
|
|
61
|
+
notifier.config &&
|
|
62
|
+
// @ts-expect-error: this is an internal API
|
|
63
|
+
!notifier.disabled &&
|
|
64
|
+
Date.now() - notifier.config.get('lastUpdateCheck') < 50
|
|
65
|
+
) {
|
|
66
|
+
notifier.config.set('lastUpdateCheck', 0);
|
|
67
|
+
notifier.check();
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
// Do not stop cli if this fails, see https://github.com/facebook/docusaurus/issues/5400
|
|
71
|
+
logger.error(err);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* We don't want to display update message for canary releases.
|
|
76
|
+
* See https://github.com/facebook/docusaurus/issues/5378
|
|
77
|
+
* @param {import('update-notifier').UpdateInfo} update
|
|
78
|
+
*/
|
|
79
|
+
function ignoreUpdate(update) {
|
|
80
|
+
const isCanaryRelease = update?.current?.startsWith('0.0.0');
|
|
81
|
+
return isCanaryRelease;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
notifier.config &&
|
|
86
|
+
notifier.update &&
|
|
87
|
+
semver.lt(notifier.update.current, notifier.update.latest)
|
|
88
|
+
) {
|
|
89
|
+
// Because notifier clears cached data after reading it, leading to notifier
|
|
90
|
+
// not consistently displaying the update.
|
|
91
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
92
|
+
notifier.config.set('update', notifier.update);
|
|
93
|
+
|
|
94
|
+
if (ignoreUpdate(notifier.update)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const siteDocusaurusPackagesForUpdate = Object.keys({
|
|
99
|
+
...sitePkg.dependencies,
|
|
100
|
+
...sitePkg.devDependencies,
|
|
101
|
+
})
|
|
102
|
+
.filter((p) => p.startsWith('@docusaurus'))
|
|
103
|
+
.map((p) => p.concat('@latest'))
|
|
104
|
+
.join(' ');
|
|
105
|
+
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
|
|
106
|
+
const upgradeCommand = isYarnUsed
|
|
107
|
+
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
|
|
108
|
+
: `npm i ${siteDocusaurusPackagesForUpdate}`;
|
|
109
|
+
|
|
110
|
+
/** @type {import('boxen').Options} */
|
|
111
|
+
const boxenOptions = {
|
|
112
|
+
padding: 1,
|
|
113
|
+
margin: 1,
|
|
114
|
+
align: 'center',
|
|
115
|
+
borderColor: 'yellow',
|
|
116
|
+
borderStyle: 'round',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const docusaurusUpdateMessage = boxen(
|
|
120
|
+
`Update available ${logger.dim(
|
|
121
|
+
`${notifier.update.current}`,
|
|
122
|
+
)} → ${logger.green(`${notifier.update.latest}`)}
|
|
123
|
+
|
|
124
|
+
To upgrade Docusaurus packages with the latest version, run the following command:
|
|
125
|
+
${logger.code(upgradeCommand)}`,
|
|
126
|
+
boxenOptions,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
console.log(docusaurusUpdateMessage);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Notify user if node version needs to be updated
|
|
133
|
+
if (!semver.satisfies(process.version, requiredVersion)) {
|
|
134
|
+
logger.error('Minimum Node.js version not met :(');
|
|
135
|
+
logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
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 fs from 'fs-extra';
|
|
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
|
+
.action(async (siteDir, options) =>
|
|
130
|
+
start(await resolveDir(siteDir), options),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
cli
|
|
134
|
+
.command('serve [siteDir]')
|
|
135
|
+
.description('Serve website locally.')
|
|
136
|
+
.option(
|
|
137
|
+
'--dir <dir>',
|
|
138
|
+
'the full path for the new output directory, relative to the current workspace (default: build)',
|
|
139
|
+
)
|
|
140
|
+
.option(
|
|
141
|
+
'--config <config>',
|
|
142
|
+
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
|
|
143
|
+
)
|
|
144
|
+
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
|
145
|
+
.option('--build', 'build website before serving (default: false)')
|
|
146
|
+
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
|
147
|
+
.action(async (siteDir, options) =>
|
|
148
|
+
serve(await resolveDir(siteDir), options),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
cli
|
|
152
|
+
.command('clear [siteDir]')
|
|
153
|
+
.description('Remove build artifacts.')
|
|
154
|
+
.action(async (siteDir) => clear(await resolveDir(siteDir)));
|
|
155
|
+
|
|
156
|
+
cli
|
|
157
|
+
.command('write-translations [siteDir]')
|
|
158
|
+
.description('Extract required translations of your site.')
|
|
159
|
+
.option(
|
|
160
|
+
'-l, --locale <locale>',
|
|
161
|
+
'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
|
|
162
|
+
)
|
|
163
|
+
.option(
|
|
164
|
+
'--override',
|
|
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)',
|
|
166
|
+
)
|
|
167
|
+
.option(
|
|
168
|
+
'--config <config>',
|
|
169
|
+
'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)',
|
|
170
|
+
)
|
|
171
|
+
.option(
|
|
172
|
+
'--messagePrefix <messagePrefix>',
|
|
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: "")',
|
|
174
|
+
)
|
|
175
|
+
.action(async (siteDir, options) =>
|
|
176
|
+
writeTranslations(await resolveDir(siteDir), options),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
cli
|
|
180
|
+
.command('write-heading-ids [siteDir] [files...]')
|
|
181
|
+
.description('Generate heading ids in Markdown content.')
|
|
182
|
+
.option(
|
|
183
|
+
'--maintain-case',
|
|
184
|
+
"keep the headings' casing, otherwise make all lowercase (default: false)",
|
|
185
|
+
)
|
|
186
|
+
.option('--overwrite', 'overwrite existing heading IDs (default: false)')
|
|
187
|
+
.action(async (siteDir, files, options) =>
|
|
188
|
+
writeHeadingIds(await resolveDir(siteDir), files, options),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
cli.arguments('<command>').action((cmd) => {
|
|
192
|
+
cli.outputHelp();
|
|
193
|
+
logger.error` Unknown command name=${cmd}.`;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {string | undefined} command
|
|
198
|
+
*/
|
|
199
|
+
function isInternalCommand(command) {
|
|
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
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
|
216
|
+
await externalCommand(cli, await resolveDir('.'));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!process.argv.slice(2).length) {
|
|
220
|
+
cli.outputHelp();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
cli.parse(process.argv);
|
|
224
|
+
|
|
225
|
+
process.on('unhandledRejection', (err) => {
|
|
226
|
+
logger.error(err instanceof Error ? err.stack : err);
|
|
227
|
+
process.exit(1);
|
|
228
|
+
});
|
package/lib/babel/preset.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
package/lib/babel/preset.js
CHANGED
|
@@ -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
|
|
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,9 +47,9 @@ 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,
|
|
50
|
-
// explicitly specify the version so that it can reuse the
|
|
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
54
|
version: require('@babel/runtime/package.json').version,
|
|
54
55
|
regenerator: true,
|
|
@@ -67,7 +68,7 @@ function getTransformOptions(isServer) {
|
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
function babelPresets(api) {
|
|
70
|
-
const callerName = api.caller((caller) => caller
|
|
71
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
71
72
|
return getTransformOptions(callerName === 'server');
|
|
72
73
|
}
|
|
73
74
|
exports.default = babelPresets;
|
package/lib/client/.eslintrc.js
CHANGED
|
@@ -11,17 +11,15 @@ 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/**',
|
|
23
22
|
'**/../webpack/**',
|
|
24
|
-
'**/../constants',
|
|
25
23
|
],
|
|
26
24
|
},
|
|
27
25
|
],
|
package/lib/client/App.d.ts
CHANGED
|
@@ -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 '
|
|
9
|
-
|
|
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
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import '@generated/client-modules';
|
|
8
9
|
import routes from '@generated/routes';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import renderRoutes from './exports/renderRoutes';
|
|
15
|
-
import DocusaurusContext from './exports/context';
|
|
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';
|
|
16
15
|
import PendingNavigation from './PendingNavigation';
|
|
17
|
-
import BaseUrlIssueBanner from './
|
|
16
|
+
import BaseUrlIssueBanner from './BaseUrlIssueBanner';
|
|
17
|
+
import SiteMetadataDefaults from './SiteMetadataDefaults';
|
|
18
18
|
import Root from '@theme/Root';
|
|
19
|
-
import '
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
import SiteMetadata from '@theme/SiteMetadata';
|
|
20
|
+
// TODO, quick fix for CSS insertion order
|
|
21
|
+
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
22
|
+
import Error from '@theme/Error';
|
|
23
|
+
export default function App() {
|
|
24
|
+
const routeElement = renderRoutes(routes);
|
|
25
|
+
const location = useLocation();
|
|
26
|
+
return (<ErrorBoundary fallback={Error}>
|
|
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
|
-
//
|
|
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
|
|
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 (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 ?
|
|
96
|
+
return enabled ? <BaseUrlIssueBanner /> : null;
|
|
87
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,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;
|