@docusaurus/core 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
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/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +79 -118
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -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 +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -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 +12 -6
- package/lib/client/docusaurus.js +30 -43
- 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 +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- 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 +38 -38
- 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 -13
- 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 +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -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 +108 -146
- 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 +50 -116
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- 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/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +94 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +109 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -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 +84 -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 +119 -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 +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- 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 +67 -56
- 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 +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- 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 +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- 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 +73 -137
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- 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 +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- 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 +45 -57
- 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 +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- 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 +21 -12
- 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 +61 -182
- package/package.json +81 -77
- package/bin/beforeCli.js +0 -100
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- 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 -9
- 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
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Docusaurus core
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// @ts-check
|
|
9
|
+
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import {createRequire} from 'module';
|
|
13
|
+
import logger from '@docusaurus/logger';
|
|
14
|
+
import semver from 'semver';
|
|
15
|
+
import updateNotifier from 'update-notifier';
|
|
16
|
+
import boxen from 'boxen';
|
|
17
|
+
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
18
|
+
|
|
19
|
+
const packageJson = /** @type {import("../package.json")} */ (
|
|
20
|
+
createRequire(import.meta.url)('../package.json')
|
|
21
|
+
);
|
|
22
|
+
/** @type {Record<string, any>} */
|
|
23
|
+
let sitePkg;
|
|
24
|
+
try {
|
|
25
|
+
sitePkg = createRequire(path.resolve('package.json'))('./package.json');
|
|
26
|
+
} catch {
|
|
27
|
+
logger.warn`path=${'package.json'} file not found at CWD: path=${process.cwd()}.`;
|
|
28
|
+
logger.info`This is non-critical, but could lead to undesired behavior downstream. Docusaurus assumes that path=${'package.json'} exists at CWD, because it's where the package manager looks up the script at. A common reason is because you have changed directory in the script. Instead of writing code=${'"start": "cd website && docusaurus start"'}, consider using the code=${'[siteDir]'} argument: code=${'"start": "docusaurus start website"'}.`;
|
|
29
|
+
sitePkg = {};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
name,
|
|
34
|
+
engines: {node: requiredVersion},
|
|
35
|
+
} = packageJson;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Notify user if `@docusaurus` packages are outdated
|
|
39
|
+
*
|
|
40
|
+
* Note: this is a 2-step process to avoid delaying cli usage by awaiting a
|
|
41
|
+
* response:
|
|
42
|
+
* - 1st run: trigger background job to check releases + store result
|
|
43
|
+
* - 2nd run: display potential update to users
|
|
44
|
+
*
|
|
45
|
+
* cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
|
|
46
|
+
*/
|
|
47
|
+
export default async function beforeCli() {
|
|
48
|
+
const notifier = updateNotifier({
|
|
49
|
+
pkg: {
|
|
50
|
+
name,
|
|
51
|
+
version: DOCUSAURUS_VERSION,
|
|
52
|
+
},
|
|
53
|
+
// Check is in background so it's fine to use a small value like 1h
|
|
54
|
+
// Use 0 for debugging
|
|
55
|
+
updateCheckInterval: 1000 * 60 * 60,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Hacky way to ensure we check for updates on first run
|
|
59
|
+
// Note: the notification will only happen in the 2nd run
|
|
60
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
61
|
+
try {
|
|
62
|
+
if (
|
|
63
|
+
notifier.config &&
|
|
64
|
+
// @ts-expect-error: this is an internal API
|
|
65
|
+
!notifier.disabled &&
|
|
66
|
+
Date.now() - notifier.config.get('lastUpdateCheck') < 50
|
|
67
|
+
) {
|
|
68
|
+
notifier.config.set('lastUpdateCheck', 0);
|
|
69
|
+
notifier.check();
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
// Do not stop cli if this fails, see https://github.com/facebook/docusaurus/issues/5400
|
|
73
|
+
logger.error(err);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* We don't want to display update message for canary releases.
|
|
78
|
+
* See https://github.com/facebook/docusaurus/issues/5378
|
|
79
|
+
* @param {import('update-notifier').UpdateInfo} update
|
|
80
|
+
*/
|
|
81
|
+
function ignoreUpdate(update) {
|
|
82
|
+
const isCanaryRelease = update?.current?.startsWith('0.0.0');
|
|
83
|
+
return isCanaryRelease;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
notifier.config &&
|
|
88
|
+
notifier.update &&
|
|
89
|
+
semver.lt(notifier.update.current, notifier.update.latest)
|
|
90
|
+
) {
|
|
91
|
+
// Because notifier clears cached data after reading it, leading to notifier
|
|
92
|
+
// not consistently displaying the update.
|
|
93
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
94
|
+
notifier.config.set('update', notifier.update);
|
|
95
|
+
|
|
96
|
+
if (ignoreUpdate(notifier.update)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const siteDocusaurusPackagesForUpdate = Object.keys({
|
|
101
|
+
...sitePkg.dependencies,
|
|
102
|
+
...sitePkg.devDependencies,
|
|
103
|
+
})
|
|
104
|
+
.filter((p) => p.startsWith('@docusaurus'))
|
|
105
|
+
.map((p) => p.concat('@latest'))
|
|
106
|
+
.join(' ');
|
|
107
|
+
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
|
|
108
|
+
const upgradeCommand = isYarnUsed
|
|
109
|
+
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
|
|
110
|
+
: `npm i ${siteDocusaurusPackagesForUpdate}`;
|
|
111
|
+
|
|
112
|
+
/** @type {import('boxen').Options} */
|
|
113
|
+
const boxenOptions = {
|
|
114
|
+
padding: 1,
|
|
115
|
+
margin: 1,
|
|
116
|
+
align: 'center',
|
|
117
|
+
borderColor: 'yellow',
|
|
118
|
+
borderStyle: 'round',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const docusaurusUpdateMessage = boxen(
|
|
122
|
+
`Update available ${logger.dim(
|
|
123
|
+
`${notifier.update.current}`,
|
|
124
|
+
)} → ${logger.green(`${notifier.update.latest}`)}
|
|
125
|
+
|
|
126
|
+
To upgrade Docusaurus packages with the latest version, run the following command:
|
|
127
|
+
${logger.code(upgradeCommand)}`,
|
|
128
|
+
boxenOptions,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
console.log(docusaurusUpdateMessage);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Notify user if node version needs to be updated
|
|
135
|
+
if (!semver.satisfies(process.version, requiredVersion)) {
|
|
136
|
+
logger.error('Minimum Node.js version not met :(');
|
|
137
|
+
logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// TODO remove when fixed: https://github.com/Stuk/eslint-plugin-header/issues/39
|
|
4
|
-
/* eslint-disable header/header */
|
|
5
2
|
/**
|
|
6
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
4
|
*
|
|
@@ -9,10 +6,12 @@
|
|
|
9
6
|
* LICENSE file in the root directory of this source tree.
|
|
10
7
|
*/
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
// @ts-check
|
|
10
|
+
|
|
11
|
+
import logger from '@docusaurus/logger';
|
|
12
|
+
import cli from 'commander';
|
|
13
|
+
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
14
|
+
import {
|
|
16
15
|
build,
|
|
17
16
|
swizzle,
|
|
18
17
|
deploy,
|
|
@@ -22,18 +21,19 @@ const {
|
|
|
22
21
|
clear,
|
|
23
22
|
writeTranslations,
|
|
24
23
|
writeHeadingIds,
|
|
25
|
-
}
|
|
24
|
+
} from '../lib/index.js';
|
|
25
|
+
import beforeCli from './beforeCli.mjs';
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
await beforeCli();
|
|
28
28
|
|
|
29
|
-
cli.version(
|
|
29
|
+
cli.version(DOCUSAURUS_VERSION).usage('<command> [options]');
|
|
30
30
|
|
|
31
31
|
cli
|
|
32
32
|
.command('build [siteDir]')
|
|
33
33
|
.description('Build website.')
|
|
34
34
|
.option(
|
|
35
35
|
'--bundle-analyzer',
|
|
36
|
-
'visualize size of webpack output files with an interactive zoomable
|
|
36
|
+
'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
|
|
37
37
|
)
|
|
38
38
|
.option(
|
|
39
39
|
'--out-dir <dir>',
|
|
@@ -51,33 +51,33 @@ cli
|
|
|
51
51
|
'--no-minify',
|
|
52
52
|
'build website without minimizing JS bundles (default: false)',
|
|
53
53
|
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
outDir,
|
|
58
|
-
config,
|
|
59
|
-
locale,
|
|
60
|
-
minify,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
54
|
+
// @ts-expect-error: Promise<string> is not assignable to Promise<void>... but
|
|
55
|
+
// good enough here.
|
|
56
|
+
.action(build);
|
|
63
57
|
|
|
64
58
|
cli
|
|
65
59
|
.command('swizzle [themeName] [componentName] [siteDir]')
|
|
66
|
-
.description(
|
|
60
|
+
.description(
|
|
61
|
+
'Wraps or ejects the original theme files into website folder for customization.',
|
|
62
|
+
)
|
|
63
|
+
.option(
|
|
64
|
+
'-w, --wrap',
|
|
65
|
+
'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.',
|
|
66
|
+
)
|
|
67
|
+
.option(
|
|
68
|
+
'-e, --eject',
|
|
69
|
+
'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.',
|
|
70
|
+
)
|
|
67
71
|
.option(
|
|
68
|
-
'--
|
|
72
|
+
'-l, --list',
|
|
73
|
+
'only list the available themes/components without further prompting (default: false)',
|
|
74
|
+
)
|
|
75
|
+
.option(
|
|
76
|
+
'-t, --typescript',
|
|
69
77
|
'copy TypeScript theme files when possible (default: false)',
|
|
70
78
|
)
|
|
71
|
-
.option('--danger', 'enable swizzle for
|
|
72
|
-
.action(
|
|
73
|
-
swizzle(
|
|
74
|
-
path.resolve(siteDir),
|
|
75
|
-
themeName,
|
|
76
|
-
componentName,
|
|
77
|
-
typescript,
|
|
78
|
-
danger,
|
|
79
|
-
);
|
|
80
|
-
});
|
|
79
|
+
.option('--danger', 'enable swizzle for unsafe component of themes')
|
|
80
|
+
.action(swizzle);
|
|
81
81
|
|
|
82
82
|
cli
|
|
83
83
|
.command('deploy [siteDir]')
|
|
@@ -98,13 +98,7 @@ cli
|
|
|
98
98
|
'--skip-build',
|
|
99
99
|
'skip building website before deploy it (default: false)',
|
|
100
100
|
)
|
|
101
|
-
.action(
|
|
102
|
-
deploy(path.resolve(siteDir), {
|
|
103
|
-
outDir,
|
|
104
|
-
config,
|
|
105
|
-
skipBuild,
|
|
106
|
-
});
|
|
107
|
-
});
|
|
101
|
+
.action(deploy);
|
|
108
102
|
|
|
109
103
|
cli
|
|
110
104
|
.command('start [siteDir]')
|
|
@@ -125,19 +119,11 @@ cli
|
|
|
125
119
|
'--poll [interval]',
|
|
126
120
|
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
|
|
127
121
|
)
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
locale,
|
|
134
|
-
config,
|
|
135
|
-
hotOnly,
|
|
136
|
-
open,
|
|
137
|
-
poll,
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
);
|
|
122
|
+
.option(
|
|
123
|
+
'--no-minify',
|
|
124
|
+
'build website without minimizing JS bundles (default: false)',
|
|
125
|
+
)
|
|
126
|
+
.action(start);
|
|
141
127
|
|
|
142
128
|
cli
|
|
143
129
|
.command('serve [siteDir]')
|
|
@@ -153,44 +139,27 @@ cli
|
|
|
153
139
|
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
|
154
140
|
.option('--build', 'build website before serving (default: false)')
|
|
155
141
|
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
port = 3000,
|
|
162
|
-
host = 'localhost',
|
|
163
|
-
build: buildSite = false,
|
|
164
|
-
config,
|
|
165
|
-
},
|
|
166
|
-
) => {
|
|
167
|
-
serve(path.resolve(siteDir), {
|
|
168
|
-
dir,
|
|
169
|
-
port,
|
|
170
|
-
build: buildSite,
|
|
171
|
-
config,
|
|
172
|
-
host,
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
);
|
|
142
|
+
.option(
|
|
143
|
+
'--no-open',
|
|
144
|
+
'do not open page in the browser (default: false, or true in CI)',
|
|
145
|
+
)
|
|
146
|
+
.action(serve);
|
|
176
147
|
|
|
177
148
|
cli
|
|
178
149
|
.command('clear [siteDir]')
|
|
179
150
|
.description('Remove build artifacts.')
|
|
180
|
-
.action(
|
|
181
|
-
clear(path.resolve(siteDir));
|
|
182
|
-
});
|
|
151
|
+
.action(clear);
|
|
183
152
|
|
|
184
153
|
cli
|
|
185
154
|
.command('write-translations [siteDir]')
|
|
186
155
|
.description('Extract required translations of your site.')
|
|
187
156
|
.option(
|
|
188
157
|
'-l, --locale <locale>',
|
|
189
|
-
'the locale folder to write the translations
|
|
158
|
+
'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.',
|
|
190
159
|
)
|
|
191
160
|
.option(
|
|
192
161
|
'--override',
|
|
193
|
-
'
|
|
162
|
+
'By default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden. (default: false)',
|
|
194
163
|
)
|
|
195
164
|
.option(
|
|
196
165
|
'--config <config>',
|
|
@@ -198,63 +167,55 @@ cli
|
|
|
198
167
|
)
|
|
199
168
|
.option(
|
|
200
169
|
'--messagePrefix <messagePrefix>',
|
|
201
|
-
'
|
|
170
|
+
'Allows to init new written messages with a given prefix. This might help you to highlight untranslated message by making them stand out in the UI (default: "")',
|
|
202
171
|
)
|
|
203
|
-
.action(
|
|
204
|
-
(
|
|
205
|
-
siteDir = '.',
|
|
206
|
-
{locale = undefined, override = false, messagePrefix = '', config},
|
|
207
|
-
) => {
|
|
208
|
-
writeTranslations(path.resolve(siteDir), {
|
|
209
|
-
locale,
|
|
210
|
-
override,
|
|
211
|
-
config,
|
|
212
|
-
messagePrefix,
|
|
213
|
-
});
|
|
214
|
-
},
|
|
215
|
-
);
|
|
172
|
+
.action(writeTranslations);
|
|
216
173
|
|
|
217
174
|
cli
|
|
218
|
-
.command('write-heading-ids [
|
|
175
|
+
.command('write-heading-ids [siteDir] [files...]')
|
|
219
176
|
.description('Generate heading ids in Markdown content.')
|
|
220
|
-
.
|
|
221
|
-
|
|
222
|
-
|
|
177
|
+
.option(
|
|
178
|
+
'--maintain-case',
|
|
179
|
+
"keep the headings' casing, otherwise make all lowercase (default: false)",
|
|
180
|
+
)
|
|
181
|
+
.option('--overwrite', 'overwrite existing heading IDs (default: false)')
|
|
182
|
+
.action(writeHeadingIds);
|
|
223
183
|
|
|
224
184
|
cli.arguments('<command>').action((cmd) => {
|
|
225
185
|
cli.outputHelp();
|
|
226
|
-
|
|
227
|
-
console.log();
|
|
186
|
+
logger.error` Unknown command name=${cmd}.`;
|
|
228
187
|
});
|
|
229
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @param {string | undefined} command
|
|
191
|
+
*/
|
|
230
192
|
function isInternalCommand(command) {
|
|
231
|
-
return
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
193
|
+
return (
|
|
194
|
+
command &&
|
|
195
|
+
[
|
|
196
|
+
'start',
|
|
197
|
+
'build',
|
|
198
|
+
'swizzle',
|
|
199
|
+
'deploy',
|
|
200
|
+
'serve',
|
|
201
|
+
'clear',
|
|
202
|
+
'write-translations',
|
|
203
|
+
'write-heading-ids',
|
|
204
|
+
].includes(command)
|
|
205
|
+
);
|
|
241
206
|
}
|
|
242
207
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
cli.parse(process.argv);
|
|
208
|
+
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
|
209
|
+
await externalCommand(cli);
|
|
210
|
+
}
|
|
249
211
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
212
|
+
if (!process.argv.slice(2).length) {
|
|
213
|
+
cli.outputHelp();
|
|
253
214
|
}
|
|
254
215
|
|
|
255
|
-
|
|
216
|
+
cli.parse(process.argv);
|
|
256
217
|
|
|
257
218
|
process.on('unhandledRejection', (err) => {
|
|
258
|
-
|
|
219
|
+
logger.error(err instanceof Error ? err.stack : err);
|
|
259
220
|
process.exit(1);
|
|
260
221
|
});
|
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,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,
|
|
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
|
-
version: require('@babel/runtime/package.json')
|
|
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
|
|
72
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
71
73
|
return getTransformOptions(callerName === 'server');
|
|
72
74
|
}
|
|
73
75
|
exports.default = babelPresets;
|
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 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 '
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
//
|
|
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
|
|
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 (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 ?
|
|
97
|
+
return enabled ? <BaseUrlIssueBanner /> : null;
|
|
87
98
|
}
|
|
File without changes
|