@docusaurus/core 2.0.0-beta.18 → 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 +12 -7
- package/bin/docusaurus.mjs +21 -72
- package/lib/client/.eslintrc.js +2 -3
- package/lib/client/App.d.ts +1 -1
- package/lib/client/App.js +9 -5
- 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.js +1 -2
- package/lib/client/PendingNavigation.d.ts +8 -17
- package/lib/client/PendingNavigation.js +39 -70
- package/lib/client/clientEntry.js +1 -2
- package/lib/client/docusaurus.d.ts +5 -5
- package/lib/client/docusaurus.js +25 -29
- package/lib/client/exports/BrowserOnly.d.ts +3 -4
- package/lib/client/exports/BrowserOnly.js +1 -1
- package/lib/client/exports/ComponentCreator.js +51 -46
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +16 -39
- package/lib/client/exports/Link.d.ts +3 -15
- package/lib/client/exports/Link.js +21 -26
- package/lib/client/exports/useBaseUrl.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +3 -3
- package/lib/client/exports/useGlobalData.js +5 -5
- package/lib/client/flat.d.ts +10 -2
- package/lib/client/flat.js +11 -3
- package/lib/client/normalizeLocation.js +14 -5
- package/lib/client/prefetch.js +7 -25
- package/lib/client/preload.d.ts +1 -3
- package/lib/client/preload.js +2 -2
- package/lib/client/routeContext.js +1 -1
- package/lib/client/serverEntry.js +12 -11
- package/lib/client/theme-fallback/Error/index.js +2 -0
- package/lib/client/theme-fallback/Loading/index.js +2 -0
- package/lib/client/theme-fallback/NotFound/index.js +2 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +35 -15
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +3 -2
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +12 -9
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +5 -6
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +12 -12
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +14 -9
- package/lib/commands/swizzle/actions.d.ts +2 -2
- package/lib/commands/swizzle/actions.js +5 -4
- package/lib/commands/swizzle/common.d.ts +3 -3
- package/lib/commands/swizzle/components.js +41 -3
- package/lib/commands/swizzle/config.js +14 -11
- package/lib/commands/swizzle/context.js +6 -10
- package/lib/commands/swizzle/index.d.ts +2 -2
- package/lib/commands/swizzle/index.js +4 -3
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +5 -8
- package/lib/commands/writeTranslations.d.ts +3 -4
- package/lib/commands/writeTranslations.js +7 -9
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/brokenLinks.js +1 -2
- package/lib/server/{client-modules/index.d.ts → clientModules.d.ts} +5 -1
- package/lib/server/{client-modules/index.js → clientModules.js} +6 -1
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +11 -6
- package/lib/server/configValidation.js +6 -5
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/{choosePort.js → server/getHostPort.js} +21 -35
- 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 +4 -19
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +42 -210
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +8 -7
- package/lib/server/plugins/index.js +59 -134
- package/lib/server/plugins/init.d.ts +6 -19
- package/lib/server/plugins/init.js +16 -68
- 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 +4 -2
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +14 -6
- 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 +42 -8
- package/lib/server/routes.js +150 -92
- package/lib/server/{versions/index.d.ts → siteMetadata.d.ts} +5 -2
- package/lib/server/{versions/index.js → siteMetadata.js} +36 -3
- package/lib/server/translations/translations.d.ts +5 -13
- package/lib/server/translations/translations.js +5 -8
- package/lib/server/translations/translationsExtractor.d.ts +2 -4
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -3
- package/lib/webpack/base.js +8 -25
- package/lib/webpack/client.js +1 -1
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
- package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
- package/lib/webpack/server.d.ts +2 -2
- package/lib/webpack/server.js +5 -3
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +3 -3
- package/package.json +33 -36
- 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/duplicateRoutes.d.ts +0 -8
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.d.ts +0 -7
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -8
- package/lib/server/html-tags/index.js +0 -42
- 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 -50
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
package/lib/client/prefetch.js
CHANGED
|
@@ -4,20 +4,14 @@
|
|
|
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
|
-
function
|
|
8
|
-
if (typeof document === 'undefined') {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const fakeLink = document.createElement('link');
|
|
7
|
+
function supports(feature) {
|
|
12
8
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
const fakeLink = document.createElement('link');
|
|
10
|
+
return fakeLink.relList?.supports?.(feature);
|
|
16
11
|
}
|
|
17
12
|
catch (err) {
|
|
18
13
|
return false;
|
|
19
14
|
}
|
|
20
|
-
return false;
|
|
21
15
|
}
|
|
22
16
|
function linkPrefetchStrategy(url) {
|
|
23
17
|
return new Promise((resolve, reject) => {
|
|
@@ -28,8 +22,8 @@ function linkPrefetchStrategy(url) {
|
|
|
28
22
|
const link = document.createElement('link');
|
|
29
23
|
link.setAttribute('rel', 'prefetch');
|
|
30
24
|
link.setAttribute('href', url);
|
|
31
|
-
link.onload = resolve;
|
|
32
|
-
link.onerror = reject;
|
|
25
|
+
link.onload = () => resolve();
|
|
26
|
+
link.onerror = () => reject();
|
|
33
27
|
const parentElement = document.getElementsByTagName('head')[0] ??
|
|
34
28
|
document.getElementsByName('script')[0]?.parentNode;
|
|
35
29
|
parentElement?.appendChild(link);
|
|
@@ -51,21 +45,9 @@ function xhrPrefetchStrategy(url) {
|
|
|
51
45
|
req.send(null);
|
|
52
46
|
});
|
|
53
47
|
}
|
|
54
|
-
const supportedPrefetchStrategy =
|
|
48
|
+
const supportedPrefetchStrategy = supports('prefetch')
|
|
55
49
|
? linkPrefetchStrategy
|
|
56
50
|
: xhrPrefetchStrategy;
|
|
57
|
-
const preFetched = {};
|
|
58
51
|
export default function prefetch(url) {
|
|
59
|
-
return
|
|
60
|
-
if (preFetched[url]) {
|
|
61
|
-
resolve();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
supportedPrefetchStrategy(url)
|
|
65
|
-
.then(() => {
|
|
66
|
-
resolve();
|
|
67
|
-
preFetched[url] = true;
|
|
68
|
-
})
|
|
69
|
-
.catch(() => { }); // 404s are logged to the console anyway.
|
|
70
|
-
});
|
|
52
|
+
return supportedPrefetchStrategy(url).catch(() => { }); // 404s are logged to the console anyway.
|
|
71
53
|
}
|
package/lib/client/preload.d.ts
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
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 { type RouteConfig } from 'react-router-config';
|
|
8
7
|
/**
|
|
9
8
|
* Helper function to make sure all async components for that particular route
|
|
10
9
|
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
10
|
* screens.
|
|
12
11
|
*
|
|
13
|
-
* @param routes react-router-config
|
|
14
12
|
* @param pathname the route pathname, example: /docs/installation
|
|
15
13
|
* @returns Promise object represents whether pathname has been preloaded
|
|
16
14
|
*/
|
|
17
|
-
export default function preload(
|
|
15
|
+
export default function preload(pathname: string): Promise<void[]>;
|
package/lib/client/preload.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
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 routes from '@generated/routes';
|
|
7
8
|
import { matchRoutes } from 'react-router-config';
|
|
8
9
|
/**
|
|
9
10
|
* Helper function to make sure all async components for that particular route
|
|
10
11
|
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
12
|
* screens.
|
|
12
13
|
*
|
|
13
|
-
* @param routes react-router-config
|
|
14
14
|
* @param pathname the route pathname, example: /docs/installation
|
|
15
15
|
* @returns Promise object represents whether pathname has been preloaded
|
|
16
16
|
*/
|
|
17
|
-
export default function preload(
|
|
17
|
+
export default function preload(pathname) {
|
|
18
18
|
const matches = matchRoutes(routes, pathname);
|
|
19
19
|
return Promise.all(
|
|
20
20
|
// @ts-expect-error: ComponentCreator injected this method.
|
|
@@ -19,7 +19,7 @@ function mergeContexts({ parent, value, }) {
|
|
|
19
19
|
// TODO deep merge this
|
|
20
20
|
const data = { ...parent.data, ...value?.data };
|
|
21
21
|
return {
|
|
22
|
-
//
|
|
22
|
+
// Nested routes are not supposed to override plugin attribute
|
|
23
23
|
plugin: parent.plugin,
|
|
24
24
|
data,
|
|
25
25
|
};
|
|
@@ -14,15 +14,13 @@ import Loadable from 'react-loadable';
|
|
|
14
14
|
import { minify } from 'html-minifier-terser';
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import fs from 'fs-extra';
|
|
17
|
-
import routes from '@generated/routes';
|
|
18
17
|
import preload from './preload';
|
|
19
18
|
import App from './App';
|
|
20
19
|
import { createStatefulLinksCollector, LinksCollectorProvider, } from './LinksCollector';
|
|
21
20
|
import logger from '@docusaurus/logger';
|
|
22
21
|
// eslint-disable-next-line no-restricted-imports
|
|
23
22
|
import _ from 'lodash';
|
|
24
|
-
|
|
25
|
-
const packageJson = require('../../package.json');
|
|
23
|
+
import { DOCUSAURUS_VERSION } from '@docusaurus/utils';
|
|
26
24
|
const getCompiledSSRTemplate = _.memoize((template) => eta.compile(template.trim(), {
|
|
27
25
|
rmWhitespace: true,
|
|
28
26
|
}));
|
|
@@ -39,7 +37,7 @@ export default async function render(locals) {
|
|
|
39
37
|
const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
|
|
40
38
|
if (isNotDefinedErrorRegex.test(err.message)) {
|
|
41
39
|
logger.info `It looks like you are using code that should run on the client-side only.
|
|
42
|
-
To get around it, try using code=${'<BrowserOnly>'} (
|
|
40
|
+
To get around it, try using code=${'<BrowserOnly>'} (url=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (url=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
|
|
43
41
|
It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
|
|
44
42
|
}
|
|
45
43
|
throw err;
|
|
@@ -47,16 +45,18 @@ It might also require to wrap your client code in code=${'useEffect'} hook and/o
|
|
|
47
45
|
}
|
|
48
46
|
// Renderer for static-site-generator-webpack-plugin (async rendering).
|
|
49
47
|
async function doRender(locals) {
|
|
50
|
-
const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, baseUrl, ssrTemplate, noIndex, } = locals;
|
|
48
|
+
const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, onHeadTagsCollected, baseUrl, ssrTemplate, noIndex, } = locals;
|
|
51
49
|
const location = routesLocation[locals.path];
|
|
52
|
-
await preload(
|
|
50
|
+
await preload(location);
|
|
53
51
|
const modules = new Set();
|
|
54
|
-
const
|
|
52
|
+
const routerContext = {};
|
|
55
53
|
const helmetContext = {};
|
|
56
54
|
const linksCollector = createStatefulLinksCollector();
|
|
57
|
-
const appHtml = ReactDOMServer.renderToString(
|
|
55
|
+
const appHtml = ReactDOMServer.renderToString(
|
|
56
|
+
// @ts-expect-error: we are migrating away from react-loadable anyways
|
|
57
|
+
<Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
|
|
58
58
|
<HelmetProvider context={helmetContext}>
|
|
59
|
-
<StaticRouter location={location} context={
|
|
59
|
+
<StaticRouter location={location} context={routerContext}>
|
|
60
60
|
<LinksCollectorProvider linksCollector={linksCollector}>
|
|
61
61
|
<App />
|
|
62
62
|
</LinksCollectorProvider>
|
|
@@ -73,10 +73,11 @@ async function doRender(locals) {
|
|
|
73
73
|
helmet.link.toString(),
|
|
74
74
|
helmet.script.toString(),
|
|
75
75
|
];
|
|
76
|
+
onHeadTagsCollected(location, helmet);
|
|
76
77
|
const metaAttributes = metaStrings.filter(Boolean);
|
|
77
78
|
const { generatedFilesDir } = locals;
|
|
78
79
|
const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
|
|
79
|
-
const manifest =
|
|
80
|
+
const manifest = await fs.readJSON(manifestPath);
|
|
80
81
|
// Get all required assets for this particular page based on client
|
|
81
82
|
// manifest information.
|
|
82
83
|
const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
|
|
@@ -95,7 +96,7 @@ async function doRender(locals) {
|
|
|
95
96
|
scripts,
|
|
96
97
|
stylesheets,
|
|
97
98
|
noIndex,
|
|
98
|
-
version:
|
|
99
|
+
version: DOCUSAURUS_VERSION,
|
|
99
100
|
});
|
|
100
101
|
try {
|
|
101
102
|
// Minify html with https://github.com/DanielRuf/html-minifier-terser
|
|
@@ -4,6 +4,8 @@
|
|
|
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
|
+
// Should we translate theme-fallback?
|
|
8
|
+
/* eslint-disable @docusaurus/no-untranslated-text */
|
|
7
9
|
import React from 'react';
|
|
8
10
|
import Layout from '@theme/Layout';
|
|
9
11
|
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
@@ -4,6 +4,8 @@
|
|
|
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
|
+
// Should we translate theme-fallback?
|
|
8
|
+
/* eslint-disable @docusaurus/no-untranslated-text */
|
|
7
9
|
import React from 'react';
|
|
8
10
|
export default function Loading({ error, retry, pastDelay, }) {
|
|
9
11
|
if (error) {
|
|
@@ -4,6 +4,8 @@
|
|
|
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
|
+
// Should we translate theme-fallback?
|
|
8
|
+
/* eslint-disable @docusaurus/no-untranslated-text */
|
|
7
9
|
import React from 'react';
|
|
8
10
|
import Layout from '@theme/Layout';
|
|
9
11
|
import Head from '@docusaurus/Head';
|
package/lib/commands/build.d.ts
CHANGED
|
@@ -4,5 +4,9 @@
|
|
|
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 type
|
|
8
|
-
export
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
|
+
export declare type BuildCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
|
|
9
|
+
bundleAnalyzer?: boolean;
|
|
10
|
+
minify?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function build(siteDir: string, cliOptions: Partial<BuildCLIOptions>, forceTerminate?: boolean): Promise<string>;
|
package/lib/commands/build.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.build = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
12
|
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
|
|
@@ -22,7 +23,7 @@ const utils_1 = require("../webpack/utils");
|
|
|
22
23
|
const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
|
|
23
24
|
const i18n_1 = require("../server/i18n");
|
|
24
25
|
const utils_2 = require("@docusaurus/utils");
|
|
25
|
-
async function build(siteDir, cliOptions
|
|
26
|
+
async function build(siteDir, cliOptions,
|
|
26
27
|
// When running build, we force terminate the process to prevent async
|
|
27
28
|
// operations from never returning. However, if run as part of docusaurus
|
|
28
29
|
// deploy, we have to let deploy finish.
|
|
@@ -46,9 +47,10 @@ forceTerminate = true) {
|
|
|
46
47
|
throw err;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
const context = await (0, server_1.loadContext)(
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const context = await (0, server_1.loadContext)({
|
|
51
|
+
siteDir,
|
|
52
|
+
outDir: cliOptions.outDir,
|
|
53
|
+
config: cliOptions.config,
|
|
52
54
|
locale: cliOptions.locale,
|
|
53
55
|
localizePath: cliOptions.locale ? false : undefined,
|
|
54
56
|
});
|
|
@@ -73,19 +75,20 @@ forceTerminate = true) {
|
|
|
73
75
|
});
|
|
74
76
|
return results[0];
|
|
75
77
|
}
|
|
76
|
-
exports.
|
|
78
|
+
exports.build = build;
|
|
77
79
|
async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
|
|
78
80
|
process.env.BABEL_ENV = 'production';
|
|
79
81
|
process.env.NODE_ENV = 'production';
|
|
80
82
|
logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
|
|
81
|
-
const props = await (0, server_1.load)(
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
const props = await (0, server_1.load)({
|
|
84
|
+
siteDir,
|
|
85
|
+
outDir: cliOptions.outDir,
|
|
86
|
+
config: cliOptions.config,
|
|
84
87
|
locale,
|
|
85
88
|
localizePath: cliOptions.locale ? false : undefined,
|
|
86
89
|
});
|
|
87
90
|
// Apply user webpack config.
|
|
88
|
-
const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories }, routes, } = props;
|
|
91
|
+
const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories: staticDirectoriesOption, }, routes, } = props;
|
|
89
92
|
const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
|
|
90
93
|
let clientConfig = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
|
|
91
94
|
plugins: [
|
|
@@ -98,23 +101,36 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
98
101
|
new react_loadable_ssr_addon_v5_slorber_1.default({
|
|
99
102
|
filename: clientManifestPath,
|
|
100
103
|
}),
|
|
101
|
-
].filter(Boolean),
|
|
104
|
+
].filter((x) => Boolean(x)),
|
|
102
105
|
});
|
|
103
106
|
const allCollectedLinks = {};
|
|
107
|
+
const headTags = {};
|
|
104
108
|
let serverConfig = await (0, server_2.default)({
|
|
105
109
|
props,
|
|
106
110
|
onLinksCollected: (staticPagePath, links) => {
|
|
107
111
|
allCollectedLinks[staticPagePath] = links;
|
|
108
112
|
},
|
|
113
|
+
onHeadTagsCollected: (staticPagePath, tags) => {
|
|
114
|
+
headTags[staticPagePath] = tags;
|
|
115
|
+
},
|
|
109
116
|
});
|
|
117
|
+
// The staticDirectories option can contain empty directories, or non-existent
|
|
118
|
+
// directories (e.g. user deleted `static`). Instead of issuing an error, we
|
|
119
|
+
// just silently filter them out, because user could have never configured it
|
|
120
|
+
// in the first place (the default option should always "work").
|
|
121
|
+
const staticDirectories = (await Promise.all(staticDirectoriesOption.map(async (dir) => {
|
|
122
|
+
const staticDir = path_1.default.resolve(siteDir, dir);
|
|
123
|
+
if ((await fs_extra_1.default.pathExists(staticDir)) &&
|
|
124
|
+
(await fs_extra_1.default.readdir(staticDir)).length > 0) {
|
|
125
|
+
return staticDir;
|
|
126
|
+
}
|
|
127
|
+
return '';
|
|
128
|
+
}))).filter(Boolean);
|
|
110
129
|
if (staticDirectories.length > 0) {
|
|
111
|
-
await Promise.all(staticDirectories.map((dir) => fs_extra_1.default.ensureDir(dir)));
|
|
112
130
|
serverConfig = (0, webpack_merge_1.default)(serverConfig, {
|
|
113
131
|
plugins: [
|
|
114
132
|
new copy_webpack_plugin_1.default({
|
|
115
|
-
patterns: staticDirectories
|
|
116
|
-
.map((dir) => path_1.default.resolve(siteDir, dir))
|
|
117
|
-
.map((dir) => ({ from: dir, to: outDir })),
|
|
133
|
+
patterns: staticDirectories.map((dir) => ({ from: dir, to: outDir })),
|
|
118
134
|
}),
|
|
119
135
|
],
|
|
120
136
|
});
|
|
@@ -151,7 +167,11 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
151
167
|
if (!plugin.postBuild) {
|
|
152
168
|
return;
|
|
153
169
|
}
|
|
154
|
-
await plugin.postBuild({
|
|
170
|
+
await plugin.postBuild({
|
|
171
|
+
...props,
|
|
172
|
+
head: headTags,
|
|
173
|
+
content: plugin.content,
|
|
174
|
+
});
|
|
155
175
|
}));
|
|
156
176
|
await (0, brokenLinks_1.handleBrokenLinks)({
|
|
157
177
|
allCollectedLinks,
|
package/lib/commands/clear.d.ts
CHANGED
package/lib/commands/clear.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.clear = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -38,6 +39,6 @@ async function clear(siteDir) {
|
|
|
38
39
|
path: path_1.default.join(siteDir, p, '.cache'),
|
|
39
40
|
description: 'Webpack persistent cache folder',
|
|
40
41
|
}));
|
|
41
|
-
|
|
42
|
+
await Promise.all([generatedFolder, buildFolder, ...cacheFolders].map(removePath));
|
|
42
43
|
}
|
|
43
|
-
exports.
|
|
44
|
+
exports.clear = clear;
|
package/lib/commands/deploy.d.ts
CHANGED
|
@@ -4,5 +4,8 @@
|
|
|
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 type
|
|
8
|
-
export
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
|
+
export declare type DeployCLIOptions = Pick<LoadContextOptions, 'config' | 'locale' | 'outDir'> & {
|
|
9
|
+
skipBuild?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function deploy(siteDir: string, cliOptions: Partial<DeployCLIOptions>): Promise<void>;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.deploy = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
12
|
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
|
12
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
14
|
const utils_1 = require("@docusaurus/utils");
|
|
14
15
|
const server_1 = require("../server");
|
|
15
|
-
const build_1 =
|
|
16
|
+
const build_1 = require("./build");
|
|
16
17
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
18
|
const os_1 = tslib_1.__importDefault(require("os"));
|
|
18
19
|
// GIT_PASS env variable should not appear in logs
|
|
@@ -33,10 +34,11 @@ function shellExecLog(cmd) {
|
|
|
33
34
|
throw err;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
async function deploy(siteDir, cliOptions
|
|
37
|
-
const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)(
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
async function deploy(siteDir, cliOptions) {
|
|
38
|
+
const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)({
|
|
39
|
+
siteDir,
|
|
40
|
+
config: cliOptions.config,
|
|
41
|
+
outDir: cliOptions.outDir,
|
|
40
42
|
});
|
|
41
43
|
if (typeof siteConfig.trailingSlash === 'undefined') {
|
|
42
44
|
logger_1.default.warn(`When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
|
|
@@ -87,8 +89,9 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
87
89
|
shelljs_1.default.echo('Skipping deploy on a pull request.');
|
|
88
90
|
shelljs_1.default.exit(0);
|
|
89
91
|
}
|
|
90
|
-
// github.io indicates organization repos that deploy via default branch.
|
|
91
|
-
//
|
|
92
|
+
// github.io indicates organization repos that deploy via default branch. All
|
|
93
|
+
// others use gh-pages (either case can be configured actually, but we can
|
|
94
|
+
// make educated guesses). Organization deploys look like:
|
|
92
95
|
// - Git repo: https://github.com/<organization>/<organization>.github.io
|
|
93
96
|
// - Site url: https://<organization>.github.io
|
|
94
97
|
const isGitHubPagesOrganizationDeploy = projectName.includes('.github.io');
|
|
@@ -172,7 +175,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
172
175
|
if (!cliOptions.skipBuild) {
|
|
173
176
|
// Build site, then push to deploymentBranch branch of specified repo.
|
|
174
177
|
try {
|
|
175
|
-
await
|
|
178
|
+
await (0, build_1.build)(siteDir, cliOptions, false).then(runDeploy);
|
|
176
179
|
}
|
|
177
180
|
catch (err) {
|
|
178
181
|
logger_1.default.error('Deployment of the build output failed.');
|
|
@@ -184,4 +187,4 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
184
187
|
await runDeploy(outDir);
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
|
-
exports.
|
|
190
|
+
exports.deploy = deploy;
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { CommanderStatic } from 'commander';
|
|
8
|
-
export
|
|
8
|
+
export declare function externalCommand(cli: CommanderStatic, siteDir: string): Promise<void>;
|
package/lib/commands/external.js
CHANGED
|
@@ -6,16 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
|
|
9
|
+
exports.externalCommand = void 0;
|
|
10
10
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 =
|
|
11
|
+
const init_1 = require("../server/plugins/init");
|
|
12
12
|
async function externalCommand(cli, siteDir) {
|
|
13
|
-
const context = await (0, server_1.loadContext)(siteDir);
|
|
14
|
-
const
|
|
15
|
-
const plugins = await (0, init_1.default)({ pluginConfigs, context });
|
|
13
|
+
const context = await (0, server_1.loadContext)({ siteDir });
|
|
14
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
16
15
|
// Plugin Lifecycle - extendCli.
|
|
17
16
|
plugins.forEach((plugin) => {
|
|
18
17
|
plugin.extendCli?.(cli);
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
exports.
|
|
20
|
+
exports.externalCommand = externalCommand;
|
package/lib/commands/serve.d.ts
CHANGED
|
@@ -4,5 +4,10 @@
|
|
|
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 type {
|
|
8
|
-
|
|
7
|
+
import type { LoadContextOptions } from '../server';
|
|
8
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
9
|
+
export declare type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
|
|
10
|
+
dir?: string;
|
|
11
|
+
build?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function serve(siteDir: string, cliOptions: Partial<ServeCLIOptions>): Promise<void>;
|
package/lib/commands/serve.js
CHANGED
|
@@ -6,30 +6,30 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.serve = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
11
12
|
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
12
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
14
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const
|
|
15
|
-
const build_1 =
|
|
16
|
-
const
|
|
15
|
+
const config_1 = require("../server/config");
|
|
16
|
+
const build_1 = require("./build");
|
|
17
|
+
const getHostPort_1 = require("../server/getHostPort");
|
|
18
|
+
const utils_1 = require("@docusaurus/utils");
|
|
17
19
|
async function serve(siteDir, cliOptions) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: path_1.default.join(siteDir, cliOptions.dir);
|
|
20
|
+
const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
|
|
21
|
+
let dir = path_1.default.resolve(siteDir, buildDir);
|
|
21
22
|
if (cliOptions.build) {
|
|
22
|
-
dir = await (0, build_1.
|
|
23
|
+
dir = await (0, build_1.build)(siteDir, {
|
|
23
24
|
config: cliOptions.config,
|
|
24
25
|
outDir: dir,
|
|
25
26
|
}, false);
|
|
26
27
|
}
|
|
27
|
-
const host = (0,
|
|
28
|
-
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
28
|
+
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
29
29
|
if (port === null) {
|
|
30
30
|
process.exit();
|
|
31
31
|
}
|
|
32
|
-
const { siteConfig: { baseUrl, trailingSlash }, } = await (0,
|
|
32
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
|
|
33
33
|
siteDir,
|
|
34
34
|
customConfigFilePath: cliOptions.config,
|
|
35
35
|
});
|
|
@@ -53,7 +53,7 @@ async function serve(siteDir, cliOptions) {
|
|
|
53
53
|
directoryListing: false,
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
logger_1.default.success `Serving path=${
|
|
56
|
+
logger_1.default.success `Serving path=${buildDir} directory at url=${servingUrl + baseUrl}.`;
|
|
57
57
|
server.listen(port);
|
|
58
58
|
}
|
|
59
|
-
exports.
|
|
59
|
+
exports.serve = serve;
|
package/lib/commands/start.d.ts
CHANGED
|
@@ -4,5 +4,11 @@
|
|
|
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 type
|
|
8
|
-
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
9
|
+
export declare type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'locale' | 'config'> & {
|
|
10
|
+
hotOnly?: boolean;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
poll?: boolean | number;
|
|
13
|
+
};
|
|
14
|
+
export declare function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;
|
package/lib/commands/start.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.start = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const utils_1 = require("@docusaurus/utils");
|
|
11
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
@@ -22,38 +23,38 @@ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
|
22
23
|
const server_1 = require("../server");
|
|
23
24
|
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
24
25
|
const utils_2 = require("../webpack/utils");
|
|
25
|
-
const
|
|
26
|
+
const getHostPort_1 = require("../server/getHostPort");
|
|
26
27
|
const translations_1 = require("../server/translations/translations");
|
|
27
28
|
async function start(siteDir, cliOptions) {
|
|
28
29
|
process.env.NODE_ENV = 'development';
|
|
29
30
|
process.env.BABEL_ENV = 'development';
|
|
30
31
|
logger_1.default.info('Starting the development server...');
|
|
31
32
|
function loadSite() {
|
|
32
|
-
return (0, server_1.load)(
|
|
33
|
-
|
|
33
|
+
return (0, server_1.load)({
|
|
34
|
+
siteDir,
|
|
35
|
+
config: cliOptions.config,
|
|
34
36
|
locale: cliOptions.locale,
|
|
35
|
-
localizePath: undefined, //
|
|
37
|
+
localizePath: undefined, // Should this be configurable?
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
// Process all related files as a prop.
|
|
39
41
|
const props = await loadSite();
|
|
40
42
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
41
|
-
const host = (0,
|
|
42
|
-
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
43
|
+
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
43
44
|
if (port === null) {
|
|
44
45
|
process.exit();
|
|
45
46
|
}
|
|
46
47
|
const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
|
|
47
48
|
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
48
49
|
const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
|
|
49
|
-
logger_1.default.success `Docusaurus website is running at
|
|
50
|
+
logger_1.default.success `Docusaurus website is running at url=${openUrl}.`;
|
|
50
51
|
// Reload files processing.
|
|
51
52
|
const reload = lodash_1.default.debounce(() => {
|
|
52
53
|
loadSite()
|
|
53
54
|
.then(({ baseUrl: newBaseUrl }) => {
|
|
54
55
|
const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
|
|
55
56
|
if (newOpenUrl !== openUrl) {
|
|
56
|
-
logger_1.default.success `Docusaurus website is running at
|
|
57
|
+
logger_1.default.success `Docusaurus website is running at url=${newOpenUrl}.`;
|
|
57
58
|
}
|
|
58
59
|
})
|
|
59
60
|
.catch((err) => {
|
|
@@ -93,6 +94,10 @@ async function start(siteDir, cliOptions) {
|
|
|
93
94
|
});
|
|
94
95
|
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
|
|
95
96
|
let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props), {
|
|
97
|
+
watchOptions: {
|
|
98
|
+
ignored: /node_modules\/(?!@docusaurus)/,
|
|
99
|
+
poll: cliOptions.poll,
|
|
100
|
+
},
|
|
96
101
|
infrastructureLogging: {
|
|
97
102
|
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
98
103
|
level: 'warn',
|
|
@@ -198,4 +203,4 @@ async function start(siteDir, cliOptions) {
|
|
|
198
203
|
});
|
|
199
204
|
});
|
|
200
205
|
}
|
|
201
|
-
exports.
|
|
206
|
+
exports.start = start;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { SwizzleAction, SwizzleComponentConfig } from '@docusaurus/types';
|
|
8
|
-
import type {
|
|
8
|
+
import type { SwizzleCLIOptions } from './common';
|
|
9
9
|
export declare const SwizzleActions: SwizzleAction[];
|
|
10
|
-
export declare function getAction(componentConfig: SwizzleComponentConfig, options: Pick<
|
|
10
|
+
export declare function getAction(componentConfig: SwizzleComponentConfig, options: Pick<SwizzleCLIOptions, 'wrap' | 'eject'>): Promise<SwizzleAction>;
|
|
11
11
|
export declare type ActionParams = {
|
|
12
12
|
siteDir: string;
|
|
13
13
|
themePath: string;
|