@docusaurus/core 2.0.0-beta.8bda3b2db → 2.0.0-beta.9
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.js +125 -0
- package/bin/docusaurus.js +36 -105
- package/lib/.tsbuildinfo +1 -1
- package/lib/babel/preset.js +1 -1
- package/lib/choosePort.js +10 -11
- package/lib/client/.tsbuildinfo +1 -1
- package/lib/client/App.js +8 -22
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +1 -0
- package/lib/client/docusaurus.js +0 -1
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/Interpolate.js +4 -0
- package/lib/client/exports/Link.js +11 -11
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +13 -9
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +21 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/useBaseUrl.js +1 -1
- package/lib/client/exports/useDocusaurusContext.js +2 -7
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +11 -27
- package/lib/commands/build.js +26 -23
- package/lib/commands/clear.js +2 -2
- package/lib/commands/commandUtils.js +2 -2
- package/lib/commands/deploy.js +24 -14
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +13 -13
- package/lib/commands/start.js +74 -72
- package/lib/commands/swizzle.js +33 -33
- package/lib/commands/writeHeadingIds.d.ts +8 -5
- package/lib/commands/writeHeadingIds.js +32 -31
- package/lib/commands/writeTranslations.js +25 -11
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -1
- package/lib/server/brokenLinks.js +13 -13
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.js +4 -3
- package/lib/server/duplicateRoutes.js +2 -2
- package/lib/server/html-tags/htmlTags.js +5 -5
- package/lib/server/html-tags/index.d.ts +2 -2
- package/lib/server/html-tags/index.js +3 -3
- package/lib/server/i18n.js +4 -4
- package/lib/server/index.js +99 -62
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -1
- package/lib/server/plugins/applyRouteTrailingSlash.js +3 -3
- package/lib/server/plugins/index.d.ts +3 -4
- package/lib/server/plugins/index.js +41 -27
- package/lib/server/plugins/init.d.ts +2 -6
- package/lib/server/plugins/init.js +7 -10
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +2 -2
- package/lib/server/presets/index.js +4 -7
- package/lib/server/routes.js +41 -23
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -12
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +19 -9
- package/lib/server/translations/translations.d.ts +4 -5
- package/lib/server/translations/translations.js +9 -9
- package/lib/server/translations/translationsExtractor.d.ts +2 -3
- package/lib/server/translations/translationsExtractor.js +58 -47
- package/lib/server/utils.d.ts +8 -2
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__tests/index.test.js +5 -5
- package/lib/server/versions/index.js +6 -6
- package/lib/webpack/base.js +28 -19
- package/lib/webpack/client.js +8 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -5
- package/lib/webpack/plugins/LogPlugin.js +3 -4
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.d.ts +2 -0
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.d.ts +5 -0
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +1 -1
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.d.ts +1 -0
- package/lib/webpack/server.js +11 -7
- package/lib/webpack/sharedModuleAliases.js +1 -1
- package/lib/webpack/utils.d.ts +2 -1
- package/lib/webpack/utils.js +28 -25
- package/package.json +45 -39
- package/tsconfig.client.json +1 -2
- package/tsconfig.json +5 -4
|
@@ -0,0 +1,11 @@
|
|
|
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 React, { ReactNode } from 'react';
|
|
8
|
+
export declare const Context: React.Context<boolean>;
|
|
9
|
+
export declare function BrowserContextProvider({ children, }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 React, { useEffect, useState } from 'react';
|
|
8
|
+
// Encapsulate the logic to avoid React hydration problems
|
|
9
|
+
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
10
|
+
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
+
// isBrowser is set to true only after a successful hydration
|
|
12
|
+
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
+
// Using useDocusaurusContext() (much more common need) should not trigger re-rendering after a successful hydration
|
|
14
|
+
export const Context = React.createContext(false);
|
|
15
|
+
export function BrowserContextProvider({ children, }) {
|
|
16
|
+
const [isBrowser, setIsBrowser] = useState(false);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setIsBrowser(true);
|
|
19
|
+
}, []);
|
|
20
|
+
return React.createElement(Context.Provider, { value: isBrowser }, children);
|
|
21
|
+
}
|
|
@@ -4,15 +4,5 @@
|
|
|
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
|
-
|
|
8
|
-
// eslint-disable-next-line no-restricted-imports
|
|
9
|
-
export {
|
|
10
|
-
// constants were only available on node
|
|
11
|
-
// this makes some useful constants available to frontend/themes too
|
|
12
|
-
// import {DEFAULT_PLUGIN_ID} '@docusaurus/constants'
|
|
13
|
-
DEFAULT_PLUGIN_ID,
|
|
14
|
-
} from '../../constants';
|
|
15
|
-
*/
|
|
16
|
-
// Not duplicating the constants seems to produce
|
|
17
|
-
// weird TS compilation side-effects
|
|
7
|
+
// Constants used on the client-side: duplicated from server-side code
|
|
18
8
|
export const DEFAULT_PLUGIN_ID = 'default';
|
|
@@ -4,7 +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 React from 'react';
|
|
7
|
+
import React, { ReactNode } from 'react';
|
|
8
8
|
import { DocusaurusContext } from '@docusaurus/types';
|
|
9
|
-
declare const
|
|
10
|
-
export
|
|
9
|
+
export declare const Context: React.Context<DocusaurusContext>;
|
|
10
|
+
export declare function DocusaurusContextProvider({ children, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 React from 'react';
|
|
8
|
+
import siteConfig from '@generated/docusaurus.config';
|
|
9
|
+
import globalData from '@generated/globalData';
|
|
10
|
+
import i18n from '@generated/i18n';
|
|
11
|
+
import codeTranslations from '@generated/codeTranslations';
|
|
12
|
+
import siteMetadata from '@generated/site-metadata';
|
|
13
|
+
// Static value on purpose: don't make it dynamic!
|
|
14
|
+
// Using context is still useful for testability reasons.
|
|
15
|
+
const contextValue = {
|
|
16
|
+
siteConfig,
|
|
17
|
+
siteMetadata,
|
|
18
|
+
globalData,
|
|
19
|
+
i18n,
|
|
20
|
+
codeTranslations,
|
|
21
|
+
};
|
|
22
|
+
export const Context = React.createContext(contextValue);
|
|
23
|
+
export function DocusaurusContextProvider({ children, }) {
|
|
24
|
+
return React.createElement(Context.Provider, { value: contextValue }, children);
|
|
25
|
+
}
|
|
@@ -27,7 +27,7 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
|
|
|
27
27
|
return absolute ? siteUrl + basePath : basePath;
|
|
28
28
|
}
|
|
29
29
|
export function useBaseUrlUtils() {
|
|
30
|
-
const { siteConfig: { baseUrl = '/', url: siteUrl } = {}
|
|
30
|
+
const { siteConfig: { baseUrl = '/', url: siteUrl } = {} } = useDocusaurusContext();
|
|
31
31
|
return {
|
|
32
32
|
withBaseUrl: (url, options) => {
|
|
33
33
|
return addBaseUrl(siteUrl, baseUrl, url, options);
|
|
@@ -5,13 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { useContext } from 'react';
|
|
8
|
-
import
|
|
8
|
+
import { Context } from './docusaurusContext';
|
|
9
9
|
function useDocusaurusContext() {
|
|
10
|
-
|
|
11
|
-
if (docusaurusContext === null) {
|
|
12
|
-
// should not happen normally
|
|
13
|
-
throw new Error('Docusaurus context not provided.');
|
|
14
|
-
}
|
|
15
|
-
return docusaurusContext;
|
|
10
|
+
return useContext(Context);
|
|
16
11
|
}
|
|
17
12
|
export default useDocusaurusContext;
|
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
8
|
-
|
|
9
|
-
// if we import something from outside the /client folder,
|
|
10
|
-
// the tsc directory structure is affected
|
|
11
|
-
// import {DEFAULT_PLUGIN_ID} from '../../constants';
|
|
12
|
-
const DEFAULT_PLUGIN_ID = 'default';
|
|
8
|
+
import { DEFAULT_PLUGIN_ID } from './constants';
|
|
13
9
|
export default function useGlobalData() {
|
|
14
10
|
const { globalData } = useDocusaurusContext();
|
|
15
11
|
if (!globalData) {
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { useContext } from 'react';
|
|
8
|
+
import { Context } from './browserContext';
|
|
9
|
+
export default function useIsBrowser() {
|
|
10
|
+
return useContext(Context);
|
|
11
|
+
}
|
|
@@ -4,8 +4,6 @@
|
|
|
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
|
-
|
|
8
|
-
pathname: string;
|
|
9
|
-
};
|
|
7
|
+
import type { Location } from '@docusaurus/history';
|
|
10
8
|
declare function normalizeLocation<T extends Location>(location: T): T;
|
|
11
9
|
export default normalizeLocation;
|
package/lib/client/prefetch.js
CHANGED
|
@@ -18,9 +18,7 @@ import path from 'path';
|
|
|
18
18
|
import fs from 'fs-extra';
|
|
19
19
|
import routes from '@generated/routes';
|
|
20
20
|
import packageJson from '../../package.json';
|
|
21
|
-
// eslint-disable-next-line import/no-unresolved
|
|
22
21
|
import preload from './preload';
|
|
23
|
-
// eslint-disable-next-line import/no-unresolved
|
|
24
22
|
import App from './App';
|
|
25
23
|
import {
|
|
26
24
|
createStatefulLinksCollector,
|
|
@@ -51,7 +49,8 @@ export default async function render(locals) {
|
|
|
51
49
|
),
|
|
52
50
|
);
|
|
53
51
|
|
|
54
|
-
const isNotDefinedErrorRegex =
|
|
52
|
+
const isNotDefinedErrorRegex =
|
|
53
|
+
/(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
|
|
55
54
|
|
|
56
55
|
if (isNotDefinedErrorRegex.test(e.message)) {
|
|
57
56
|
console.error(
|
|
@@ -131,10 +130,10 @@ async function doRender(locals) {
|
|
|
131
130
|
version: packageJson.version,
|
|
132
131
|
});
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return minify(renderedHtml, {
|
|
137
|
-
removeComments:
|
|
133
|
+
try {
|
|
134
|
+
// Minify html with https://github.com/DanielRuf/html-minifier-terser
|
|
135
|
+
return await minify(renderedHtml, {
|
|
136
|
+
removeComments: false,
|
|
138
137
|
removeRedundantAttributes: true,
|
|
139
138
|
removeEmptyAttributes: true,
|
|
140
139
|
removeScriptTypeAttributes: true,
|
|
@@ -142,27 +141,12 @@ async function doRender(locals) {
|
|
|
142
141
|
useShortDoctype: true,
|
|
143
142
|
minifyJS: true,
|
|
144
143
|
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// TODO this is a temporary error affecting only monorepos due to Terser 5 (async) being used by html-minifier-terser,
|
|
148
|
-
// instead of the expected Terser 4 (sync)
|
|
149
|
-
// TODO, remove this once we upgrade everything to Terser 5 (https://github.com/terser/html-minifier-terser/issues/46)
|
|
150
|
-
// See also
|
|
151
|
-
// - https://github.com/facebook/docusaurus/issues/3515
|
|
152
|
-
// - https://github.com/terser/html-minifier-terser/issues/49
|
|
153
|
-
try {
|
|
154
|
-
return doMinify();
|
|
155
144
|
} catch (e) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
chalk.red(
|
|
162
|
-
'\nDocusaurus user: you probably have this known error due to using a monorepo/workspace.\nWe have a workaround for you, please see https://github.com/facebook/docusaurus/issues/3515\n',
|
|
163
|
-
),
|
|
164
|
-
);
|
|
165
|
-
}
|
|
145
|
+
console.error(
|
|
146
|
+
chalk.red(
|
|
147
|
+
`Minification page with path "${locals.path}" failed because of following error:\n\n${e.stack}\n`,
|
|
148
|
+
),
|
|
149
|
+
);
|
|
166
150
|
throw e;
|
|
167
151
|
}
|
|
168
152
|
}
|
package/lib/commands/build.js
CHANGED
|
@@ -7,25 +7,28 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
-
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
|
|
10
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
11
|
+
const copy_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("copy-webpack-plugin"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
const react_loadable_ssr_addon_v5_slorber_1 = (0, tslib_1.__importDefault)(require("react-loadable-ssr-addon-v5-slorber"));
|
|
15
15
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
16
|
-
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
16
|
+
const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
|
|
17
17
|
const constants_1 = require("../constants");
|
|
18
18
|
const server_1 = require("../server");
|
|
19
19
|
const brokenLinks_1 = require("../server/brokenLinks");
|
|
20
|
-
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
21
|
-
const server_2 = tslib_1.__importDefault(require("../webpack/server"));
|
|
20
|
+
const client_1 = (0, tslib_1.__importDefault)(require("../webpack/client"));
|
|
21
|
+
const server_2 = (0, tslib_1.__importDefault)(require("../webpack/server"));
|
|
22
22
|
const utils_1 = require("../webpack/utils");
|
|
23
|
-
const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
|
|
23
|
+
const CleanWebpackPlugin_1 = (0, tslib_1.__importDefault)(require("../webpack/plugins/CleanWebpackPlugin"));
|
|
24
24
|
const i18n_1 = require("../server/i18n");
|
|
25
25
|
const utils_2 = require("@docusaurus/utils");
|
|
26
26
|
async function build(siteDir, cliOptions = {},
|
|
27
27
|
// TODO what's the purpose of this arg ?
|
|
28
28
|
forceTerminate = true) {
|
|
29
|
+
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
30
|
+
process.on(sig, () => process.exit());
|
|
31
|
+
});
|
|
29
32
|
async function tryToBuildLocale({ locale, isLastLocale, }) {
|
|
30
33
|
try {
|
|
31
34
|
// console.log(chalk.green(`Site successfully built in locale=${locale}`));
|
|
@@ -42,13 +45,13 @@ forceTerminate = true) {
|
|
|
42
45
|
throw e;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
const context = await server_1.loadContext(siteDir, {
|
|
48
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
46
49
|
customOutDir: cliOptions.outDir,
|
|
47
50
|
customConfigFilePath: cliOptions.config,
|
|
48
51
|
locale: cliOptions.locale,
|
|
49
52
|
localizePath: cliOptions.locale ? false : undefined,
|
|
50
53
|
});
|
|
51
|
-
const i18n = await i18n_1.loadI18n(context.siteConfig, {
|
|
54
|
+
const i18n = await (0, i18n_1.loadI18n)(context.siteConfig, {
|
|
52
55
|
locale: cliOptions.locale,
|
|
53
56
|
});
|
|
54
57
|
if (cliOptions.locale) {
|
|
@@ -65,7 +68,7 @@ forceTerminate = true) {
|
|
|
65
68
|
i18n.defaultLocale,
|
|
66
69
|
...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
|
|
67
70
|
];
|
|
68
|
-
const results = await utils_2.mapAsyncSequencial(orderedLocales, (locale) => {
|
|
71
|
+
const results = await (0, utils_2.mapAsyncSequencial)(orderedLocales, (locale) => {
|
|
69
72
|
const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
|
|
70
73
|
return tryToBuildLocale({ locale, isLastLocale });
|
|
71
74
|
});
|
|
@@ -77,7 +80,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
77
80
|
process.env.BABEL_ENV = 'production';
|
|
78
81
|
process.env.NODE_ENV = 'production';
|
|
79
82
|
console.log(chalk_1.default.blue(`\n[${locale}] Creating an optimized production build...`));
|
|
80
|
-
const props = await server_1.load(siteDir, {
|
|
83
|
+
const props = await (0, server_1.load)(siteDir, {
|
|
81
84
|
customOutDir: cliOptions.outDir,
|
|
82
85
|
customConfigFilePath: cliOptions.config,
|
|
83
86
|
locale,
|
|
@@ -86,7 +89,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
86
89
|
// Apply user webpack config.
|
|
87
90
|
const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks }, routes, } = props;
|
|
88
91
|
const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
|
|
89
|
-
let clientConfig = webpack_merge_1.default(client_1.default(props, cliOptions.minify), {
|
|
92
|
+
let clientConfig = (0, webpack_merge_1.default)((0, client_1.default)(props, cliOptions.minify), {
|
|
90
93
|
plugins: [
|
|
91
94
|
// Remove/clean build folders before building bundles.
|
|
92
95
|
new CleanWebpackPlugin_1.default({ verbose: false }),
|
|
@@ -99,7 +102,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
99
102
|
].filter(Boolean),
|
|
100
103
|
});
|
|
101
104
|
const allCollectedLinks = {};
|
|
102
|
-
let serverConfig = server_2.default({
|
|
105
|
+
let serverConfig = (0, server_2.default)({
|
|
103
106
|
props,
|
|
104
107
|
onLinksCollected: (staticPagePath, links) => {
|
|
105
108
|
allCollectedLinks[staticPagePath] = links;
|
|
@@ -107,7 +110,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
107
110
|
});
|
|
108
111
|
const staticDir = path_1.default.resolve(siteDir, constants_1.STATIC_DIR_NAME);
|
|
109
112
|
if (await fs_extra_1.default.pathExists(staticDir)) {
|
|
110
|
-
serverConfig = webpack_merge_1.default(serverConfig, {
|
|
113
|
+
serverConfig = (0, webpack_merge_1.default)(serverConfig, {
|
|
111
114
|
plugins: [
|
|
112
115
|
new copy_webpack_plugin_1.default({
|
|
113
116
|
patterns: [
|
|
@@ -125,13 +128,13 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
125
128
|
var _a, _b;
|
|
126
129
|
const { configureWebpack, configurePostCss } = plugin;
|
|
127
130
|
if (configurePostCss) {
|
|
128
|
-
clientConfig = utils_1.applyConfigurePostCss(configurePostCss, clientConfig);
|
|
131
|
+
clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
|
|
129
132
|
}
|
|
130
133
|
if (configureWebpack) {
|
|
131
|
-
clientConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
132
|
-
clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader);
|
|
133
|
-
serverConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
134
|
-
serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader);
|
|
134
|
+
clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
135
|
+
clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
|
|
136
|
+
serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
137
|
+
serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
|
|
135
138
|
}
|
|
136
139
|
});
|
|
137
140
|
// Make sure generated client-manifest is cleaned first so we don't reuse
|
|
@@ -140,7 +143,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
140
143
|
await fs_extra_1.default.unlink(clientManifestPath);
|
|
141
144
|
}
|
|
142
145
|
// Run webpack to build JS bundle (client) and static html files (server).
|
|
143
|
-
await utils_1.compile([clientConfig, serverConfig]);
|
|
146
|
+
await (0, utils_1.compile)([clientConfig, serverConfig]);
|
|
144
147
|
// Remove server.bundle.js because it is not needed.
|
|
145
148
|
if (serverConfig.output &&
|
|
146
149
|
serverConfig.output.filename &&
|
|
@@ -157,7 +160,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
157
160
|
}
|
|
158
161
|
await plugin.postBuild(props);
|
|
159
162
|
}));
|
|
160
|
-
await brokenLinks_1.handleBrokenLinks({
|
|
163
|
+
await (0, brokenLinks_1.handleBrokenLinks)({
|
|
161
164
|
allCollectedLinks,
|
|
162
165
|
routes,
|
|
163
166
|
onBrokenLinks,
|
package/lib/commands/clear.js
CHANGED
|
@@ -7,8 +7,8 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
12
|
const chalk = require("chalk");
|
|
13
13
|
const constants_1 = require("../constants");
|
|
14
14
|
function removePath(fsPath) {
|
|
@@ -8,7 +8,7 @@ const tslib_1 = require("tslib");
|
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
10
|
*/
|
|
11
|
-
const choosePort_1 = tslib_1.__importDefault(require("../choosePort"));
|
|
11
|
+
const choosePort_1 = (0, tslib_1.__importDefault)(require("../choosePort"));
|
|
12
12
|
const constants_1 = require("../constants");
|
|
13
13
|
function getCLIOptionHost(hostOption) {
|
|
14
14
|
return hostOption || 'localhost';
|
|
@@ -16,6 +16,6 @@ function getCLIOptionHost(hostOption) {
|
|
|
16
16
|
exports.getCLIOptionHost = getCLIOptionHost;
|
|
17
17
|
async function getCLIOptionPort(portOption, host) {
|
|
18
18
|
const basePort = portOption ? parseInt(portOption, 10) : constants_1.DEFAULT_PORT;
|
|
19
|
-
return choosePort_1.default(host, basePort);
|
|
19
|
+
return (0, choosePort_1.default)(host, basePort);
|
|
20
20
|
}
|
|
21
21
|
exports.getCLIOptionPort = getCLIOptionPort;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
-
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
|
12
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
11
|
+
const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
|
|
12
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
13
13
|
const server_1 = require("../server");
|
|
14
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
15
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
-
const os_1 = tslib_1.__importDefault(require("os"));
|
|
14
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./build"));
|
|
15
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
16
|
+
const os_1 = (0, tslib_1.__importDefault)(require("os"));
|
|
17
17
|
const buildRemoteBranchUrl_1 = require("./buildRemoteBranchUrl");
|
|
18
18
|
// GIT_PASS env variable should not appear in logs
|
|
19
19
|
function obfuscateGitPass(str) {
|
|
@@ -34,7 +34,7 @@ function shellExecLog(cmd) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async function deploy(siteDir, cliOptions = {}) {
|
|
37
|
-
const { outDir, siteConfig, siteConfigPath } = await server_1.loadContext(siteDir, {
|
|
37
|
+
const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)(siteDir, {
|
|
38
38
|
customConfigFilePath: cliOptions.config,
|
|
39
39
|
customOutDir: cliOptions.outDir,
|
|
40
40
|
});
|
|
@@ -77,9 +77,19 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
77
77
|
shelljs_1.default.echo('Skipping deploy on a pull request.');
|
|
78
78
|
shelljs_1.default.exit(0);
|
|
79
79
|
}
|
|
80
|
-
// github.io indicates organization repos that deploy via
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
// github.io indicates organization repos that deploy via default branch. All others use gh-pages.
|
|
81
|
+
// Organization deploys looks like:
|
|
82
|
+
// - Git repo: https://github.com/<organization>/<organization>.github.io
|
|
83
|
+
// - Site url: https://<organization>.github.io
|
|
84
|
+
const isGitHubPagesOrganizationDeploy = projectName.indexOf('.github.io') !== -1;
|
|
85
|
+
if (isGitHubPagesOrganizationDeploy &&
|
|
86
|
+
!process.env.DEPLOYMENT_BRANCH &&
|
|
87
|
+
!siteConfig.deploymentBranch) {
|
|
88
|
+
throw new Error(`For GitHub pages organization deployments, 'docusaurus deploy' does not assume anymore that 'master' is your default Git branch.
|
|
89
|
+
Please provide the branch name to deploy to as an environment variable, for example DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master .
|
|
90
|
+
You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
91
|
+
}
|
|
92
|
+
const deploymentBranch = process.env.DEPLOYMENT_BRANCH || siteConfig.deploymentBranch || 'gh-pages';
|
|
83
93
|
console.log(`${chalk_1.default.cyan('deploymentBranch:')} ${deploymentBranch}`);
|
|
84
94
|
const githubHost = process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com';
|
|
85
95
|
const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort;
|
|
@@ -89,7 +99,7 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
89
99
|
gitCredentials = `${gitCredentials}:${gitPass}`;
|
|
90
100
|
}
|
|
91
101
|
const useSSH = process.env.USE_SSH;
|
|
92
|
-
const remoteBranch = buildRemoteBranchUrl_1.buildUrl(githubHost, githubPort, gitCredentials, organizationName, projectName, useSSH !== undefined && useSSH.toLowerCase() === 'true');
|
|
102
|
+
const remoteBranch = (0, buildRemoteBranchUrl_1.buildUrl)(githubHost, githubPort, gitCredentials, organizationName, projectName, useSSH !== undefined && useSSH.toLowerCase() === 'true');
|
|
93
103
|
console.log(`${chalk_1.default.cyan('Remote branch:')} ${obfuscateGitPass(remoteBranch)}`);
|
|
94
104
|
// Check if this is a cross-repo publish.
|
|
95
105
|
const currentRepoUrl = shelljs_1.default
|
|
@@ -107,13 +117,13 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
107
117
|
const runDeploy = async (outputDirectory) => {
|
|
108
118
|
const fromPath = outputDirectory;
|
|
109
119
|
const toPath = await fs_extra_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), `${projectName}-${deploymentBranch}`));
|
|
110
|
-
if (shellExecLog(`git clone ${remoteBranch} ${toPath}`).code !== 0) {
|
|
120
|
+
if (shellExecLog(`git clone --depth 1 --no-single-branch ${remoteBranch} ${toPath}`).code !== 0) {
|
|
111
121
|
throw new Error(`Running "git clone" command in "${toPath}" failed.`);
|
|
112
122
|
}
|
|
113
123
|
shelljs_1.default.cd(toPath);
|
|
114
124
|
// If the default branch is the one we're deploying to, then we'll fail
|
|
115
125
|
// to create it. This is the case of a cross-repo publish, where we clone
|
|
116
|
-
// a github.io repo with a default
|
|
126
|
+
// a github.io repo with a default branch.
|
|
117
127
|
const defaultBranch = shelljs_1.default
|
|
118
128
|
.exec('git rev-parse --abbrev-ref HEAD')
|
|
119
129
|
.stdout.trim();
|
|
@@ -163,7 +173,7 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
163
173
|
if (!cliOptions.skipBuild) {
|
|
164
174
|
// Build static html files, then push to deploymentBranch branch of specified repo.
|
|
165
175
|
try {
|
|
166
|
-
await runDeploy(await build_1.default(siteDir, cliOptions, false));
|
|
176
|
+
await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
|
|
167
177
|
}
|
|
168
178
|
catch (buildError) {
|
|
169
179
|
console.error(buildError);
|
package/lib/commands/external.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
11
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
12
12
|
async function externalCommand(cli, siteDir) {
|
|
13
|
-
const context = await server_1.loadContext(siteDir);
|
|
14
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
15
|
-
const plugins = init_1.default({ pluginConfigs, context });
|
|
13
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
14
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
15
|
+
const plugins = (0, init_1.default)({ pluginConfigs, context });
|
|
16
16
|
// Plugin Lifecycle - extendCli.
|
|
17
17
|
plugins.forEach((plugin) => {
|
|
18
18
|
const { extendCli } = plugin;
|
package/lib/commands/serve.js
CHANGED
|
@@ -7,34 +7,34 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
11
|
-
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
12
|
-
const boxen_1 = tslib_1.__importDefault(require("boxen"));
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
11
|
+
const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
|
|
12
|
+
const boxen_1 = (0, tslib_1.__importDefault)(require("boxen"));
|
|
13
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
14
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
15
15
|
const server_1 = require("../server");
|
|
16
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
16
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./build"));
|
|
17
17
|
const commandUtils_1 = require("./commandUtils");
|
|
18
18
|
async function serve(siteDir, cliOptions) {
|
|
19
19
|
let dir = path_1.default.isAbsolute(cliOptions.dir)
|
|
20
20
|
? cliOptions.dir
|
|
21
21
|
: path_1.default.join(siteDir, cliOptions.dir);
|
|
22
22
|
if (cliOptions.build) {
|
|
23
|
-
dir = await build_1.default(siteDir, {
|
|
23
|
+
dir = await (0, build_1.default)(siteDir, {
|
|
24
24
|
config: cliOptions.config,
|
|
25
25
|
outDir: dir,
|
|
26
26
|
}, false);
|
|
27
27
|
}
|
|
28
|
-
const host = commandUtils_1.getCLIOptionHost(cliOptions.host);
|
|
29
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
28
|
+
const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
|
|
29
|
+
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
30
30
|
if (port === null) {
|
|
31
31
|
process.exit();
|
|
32
32
|
}
|
|
33
|
-
const { siteConfig: { baseUrl, trailingSlash }, } = await server_1.loadSiteConfig({
|
|
33
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, server_1.loadSiteConfig)({
|
|
34
34
|
siteDir,
|
|
35
35
|
customConfigFilePath: cliOptions.config,
|
|
36
36
|
});
|
|
37
|
-
const servingUrl = `http://${
|
|
37
|
+
const servingUrl = `http://${host}:${port}`;
|
|
38
38
|
const server = http_1.default.createServer((req, res) => {
|
|
39
39
|
var _a, _b;
|
|
40
40
|
// Automatically redirect requests to /baseUrl/
|
|
@@ -48,13 +48,13 @@ async function serve(siteDir, cliOptions) {
|
|
|
48
48
|
// Remove baseUrl before calling serveHandler
|
|
49
49
|
// Reason: /baseUrl/ should serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
50
50
|
req.url = (_b = req.url) === null || _b === void 0 ? void 0 : _b.replace(baseUrl, '/');
|
|
51
|
-
serve_handler_1.default(req, res, {
|
|
51
|
+
(0, serve_handler_1.default)(req, res, {
|
|
52
52
|
cleanUrls: true,
|
|
53
53
|
public: dir,
|
|
54
54
|
trailingSlash,
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
|
-
console.log(boxen_1.default(chalk_1.default.green(`Serving "${cliOptions.dir}" directory at "${servingUrl + baseUrl}".`), {
|
|
57
|
+
console.log((0, boxen_1.default)(chalk_1.default.green(`Serving "${cliOptions.dir}" directory at "${servingUrl + baseUrl}".`), {
|
|
58
58
|
borderColor: 'green',
|
|
59
59
|
padding: 1,
|
|
60
60
|
margin: 1,
|