@docusaurus/core 3.10.1 → 4.0.0-canary-6808
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 +9 -11
- package/lib/client/BaseUrlIssueBanner/index.js +1 -1
- package/lib/client/exports/ComponentCreator.js +0 -2
- package/lib/client/exports/Link.d.ts +3 -3
- package/lib/client/exports/Link.js +17 -17
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/preload.js +1 -3
- package/lib/client/serverEntry.js +1 -6
- package/lib/client/serverHelmetUtils.js +0 -1
- package/lib/commands/build/buildLocale.d.ts +1 -1
- package/lib/commands/build/buildLocale.js +0 -4
- package/lib/commands/build/buildUtils.d.ts +1 -1
- package/lib/commands/cli.js +3 -0
- package/lib/commands/deploy.js +39 -56
- package/lib/commands/serve.js +3 -2
- package/lib/commands/start/start.d.ts +3 -0
- package/lib/commands/start/webpack.js +20 -2
- package/lib/commands/swizzle/actions.js +5 -0
- package/lib/commands/utils/listenToServer.d.ts +5 -0
- package/lib/commands/utils/listenToServer.js +24 -0
- package/lib/commands/utils/openBrowser/openBrowser.js +3 -3
- package/lib/commands/writeHeadingIds.js +3 -3
- package/lib/server/codegen/codegenRoutes.js +0 -1
- package/lib/server/config.js +1 -1
- package/lib/server/configValidation.js +11 -17
- package/lib/server/getHostPort.js +1 -2
- package/lib/server/htmlTags.js +2 -3
- package/lib/server/i18n.js +2 -6
- package/lib/server/plugins/plugins.js +1 -9
- package/lib/server/site.js +2 -1
- package/lib/server/siteMetadata.d.ts +6 -1
- package/lib/server/siteMetadata.js +15 -12
- package/lib/server/translations/translations.js +1 -1
- package/lib/ssg/ssgEnv.js +2 -3
- package/lib/ssg/ssgExecutor.js +22 -5
- package/lib/ssg/ssgGlobalResult.js +1 -10
- package/lib/ssg/ssgParams.d.ts +0 -1
- package/lib/ssg/ssgParams.js +0 -1
- package/lib/ssg/ssgRenderer.js +1 -5
- package/lib/ssg/ssgTemplate.js +4 -6
- package/lib/ssg/ssgWorkerThread.js +0 -1
- package/lib/webpack/base.js +12 -22
- package/lib/webpack/server.js +1 -1
- package/lib/webpack/utils/getHttpsConfig.d.ts +7 -1
- package/lib/webpack/utils/getHttpsConfig.js +93 -32
- package/package.json +41 -41
package/bin/beforeCli.mjs
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
import fs from 'fs-extra';
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import {createRequire} from 'module';
|
|
13
|
-
import execa from 'execa';
|
|
13
|
+
import {execa} from 'execa';
|
|
14
14
|
import {logger} from '@docusaurus/logger';
|
|
15
15
|
import semver from 'semver';
|
|
16
16
|
import updateNotifier from 'update-notifier';
|
|
17
17
|
import boxen from 'boxen';
|
|
18
18
|
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
|
|
19
19
|
|
|
20
|
-
const packageJson = /** @type {import("../package.json")} */ (
|
|
20
|
+
const packageJson = /** @type {typeof import("../package.json")} */ (
|
|
21
21
|
createRequire(import.meta.url)('../package.json')
|
|
22
22
|
);
|
|
23
23
|
/** @type {Record<string, any>} */
|
|
@@ -111,15 +111,13 @@ export default async function beforeCli() {
|
|
|
111
111
|
return undefined;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const yarnVersionResult = await execa
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return majorVersion;
|
|
122
|
-
}
|
|
114
|
+
const yarnVersionResult = await execa`yarn --version`;
|
|
115
|
+
const majorVersion = parseInt(
|
|
116
|
+
yarnVersionResult.stdout?.trim().split('.')[0] ?? '',
|
|
117
|
+
10,
|
|
118
|
+
);
|
|
119
|
+
if (!Number.isNaN(majorVersion)) {
|
|
120
|
+
return majorVersion;
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
return undefined;
|
|
@@ -53,7 +53,7 @@ function insertBanner() {
|
|
|
53
53
|
var suggestedBaseUrl = actualHomePagePath.substr(-1) === '/'
|
|
54
54
|
? actualHomePagePath
|
|
55
55
|
: actualHomePagePath + '/';
|
|
56
|
-
suggestionContainer.
|
|
56
|
+
suggestionContainer.textContent = suggestedBaseUrl;
|
|
57
57
|
}
|
|
58
58
|
`;
|
|
59
59
|
}
|
|
@@ -94,14 +94,12 @@ export default function ComponentCreator(path, hash) {
|
|
|
94
94
|
});
|
|
95
95
|
val[keyPaths[keyPaths.length - 1]] = chunk;
|
|
96
96
|
});
|
|
97
|
-
/* eslint-disable no-underscore-dangle */
|
|
98
97
|
const Component = loadedModules.__comp;
|
|
99
98
|
delete loadedModules.__comp;
|
|
100
99
|
const routeContext = loadedModules.__context;
|
|
101
100
|
delete loadedModules.__context;
|
|
102
101
|
const routeProps = loadedModules.__props;
|
|
103
102
|
delete loadedModules.__props;
|
|
104
|
-
/* eslint-enable no-underscore-dangle */
|
|
105
103
|
// Is there any way to put this RouteContextProvider upper in the tree?
|
|
106
104
|
return (<RouteContextProvider value={routeContext}>
|
|
107
105
|
<Component {...loadedModules} {...routeProps} {...props}/>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
8
|
import type { Props } from '@docusaurus/Link';
|
|
9
|
-
declare
|
|
10
|
-
export default
|
|
9
|
+
declare function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl, ...props }: Props): ReactNode;
|
|
10
|
+
export default Link;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { useEffect, useImperativeHandle, useRef, } from 'react';
|
|
7
|
+
import React, { useCallback, useEffect, useImperativeHandle, useRef, } from 'react';
|
|
8
8
|
import { NavLink, Link as RRLink } from 'react-router-dom';
|
|
9
9
|
import { applyTrailingSlash } from '@docusaurus/utils-common';
|
|
10
10
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
@@ -18,14 +18,14 @@ import { useBaseUrlUtils } from './useBaseUrl';
|
|
|
18
18
|
// this is because useBaseUrl() actually transforms relative links
|
|
19
19
|
// like "introduction" to "/baseUrl/introduction" => bad behavior to fix
|
|
20
20
|
const shouldAddBaseUrlAutomatically = (to) => to.startsWith('/');
|
|
21
|
-
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }
|
|
21
|
+
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }) {
|
|
22
22
|
const { siteConfig } = useDocusaurusContext();
|
|
23
23
|
const { trailingSlash, baseUrl } = siteConfig;
|
|
24
24
|
const router = siteConfig.future.experimental_router;
|
|
25
25
|
const { withBaseUrl } = useBaseUrlUtils();
|
|
26
26
|
const brokenLinks = useBrokenLinks();
|
|
27
27
|
const innerRef = useRef(null);
|
|
28
|
-
useImperativeHandle(
|
|
28
|
+
useImperativeHandle(props.ref, () => innerRef.current);
|
|
29
29
|
// IMPORTANT: using to or href should not change anything
|
|
30
30
|
// For example, MDX links will ALWAYS give us the href props
|
|
31
31
|
// Using one prop or the other should not be used to distinguish
|
|
@@ -64,18 +64,23 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
64
64
|
const LinkComponent = (isNavLink ? NavLink : RRLink);
|
|
65
65
|
const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
|
|
66
66
|
const ioRef = useRef(undefined);
|
|
67
|
-
const handleRef = (el) => {
|
|
67
|
+
const handleRef = useCallback((el) => {
|
|
68
68
|
innerRef.current = el;
|
|
69
|
+
ioRef.current?.disconnect();
|
|
70
|
+
ioRef.current = undefined;
|
|
69
71
|
if (IOSupported && el && isInternal) {
|
|
70
72
|
// If IO supported and element reference found, set up Observer.
|
|
71
|
-
|
|
73
|
+
const observer = new window.IntersectionObserver((entries) => {
|
|
72
74
|
entries.forEach((entry) => {
|
|
73
75
|
if (el === entry.target) {
|
|
74
76
|
// If element is in viewport, stop observing and run callback.
|
|
75
77
|
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
|
|
76
78
|
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
observer.unobserve(el);
|
|
80
|
+
observer.disconnect();
|
|
81
|
+
if (ioRef.current === observer) {
|
|
82
|
+
ioRef.current = undefined;
|
|
83
|
+
}
|
|
79
84
|
if (targetLink != null) {
|
|
80
85
|
window.docusaurus.prefetch(targetLink);
|
|
81
86
|
}
|
|
@@ -84,9 +89,10 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
84
89
|
});
|
|
85
90
|
});
|
|
86
91
|
// Add element to the observer.
|
|
87
|
-
ioRef.current
|
|
92
|
+
ioRef.current = observer;
|
|
93
|
+
observer.observe(el);
|
|
88
94
|
}
|
|
89
|
-
};
|
|
95
|
+
}, [IOSupported, isInternal, targetLink]);
|
|
90
96
|
const onInteractionEnter = () => {
|
|
91
97
|
if (!preloaded.current && targetLink != null) {
|
|
92
98
|
window.docusaurus.preload(targetLink);
|
|
@@ -100,13 +106,7 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
100
106
|
window.docusaurus.prefetch(targetLink);
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
|
-
|
|
104
|
-
return () => {
|
|
105
|
-
if (IOSupported && ioRef.current) {
|
|
106
|
-
ioRef.current.disconnect();
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}, [ioRef, targetLink, IOSupported, isInternal]);
|
|
109
|
+
}, [targetLink, IOSupported, isInternal]);
|
|
110
110
|
// It is simple local anchor link targeting current page?
|
|
111
111
|
const isAnchorLink = targetLink?.startsWith('#') ?? false;
|
|
112
112
|
// See also RR logic:
|
|
@@ -139,4 +139,4 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
139
139
|
// element"
|
|
140
140
|
{...(isNavLink && { isActive, activeClassName })} {...testOnlyProps}/>);
|
|
141
141
|
}
|
|
142
|
-
export default
|
|
142
|
+
export default Link;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Spec: https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
|
|
9
9
|
// In particular: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
|
10
10
|
export function hasProtocol(url) {
|
|
11
|
-
return /^(?:[A-
|
|
11
|
+
return /^(?:[A-Z][A-Z\d+.-]*:|\/\/)/i.test(url);
|
|
12
12
|
}
|
|
13
13
|
export default function isInternalUrl(url) {
|
|
14
14
|
return typeof url !== 'undefined' && !hasProtocol(url);
|
package/lib/client/preload.js
CHANGED
|
@@ -15,8 +15,6 @@ import { matchRoutes } from 'react-router-config';
|
|
|
15
15
|
* @returns Promise object represents whether pathname has been preloaded
|
|
16
16
|
*/
|
|
17
17
|
export default function preload(pathname) {
|
|
18
|
-
const matches = Array.from(new Set([pathname, decodeURI(pathname)]))
|
|
19
|
-
.map((p) => matchRoutes(routes, p))
|
|
20
|
-
.flat();
|
|
18
|
+
const matches = Array.from(new Set([pathname, decodeURI(pathname)])).flatMap((p) => matchRoutes(routes, p));
|
|
21
19
|
return Promise.all(matches.map((match) => match.route.component.preload?.()));
|
|
22
20
|
}
|
|
@@ -13,7 +13,7 @@ import preload from './preload';
|
|
|
13
13
|
import App from './App';
|
|
14
14
|
import { createStatefulBrokenLinks, BrokenLinksProvider, } from './BrokenLinksContext';
|
|
15
15
|
import { toPageCollectedMetadataInternal } from './serverHelmetUtils';
|
|
16
|
-
const render = async ({ pathname
|
|
16
|
+
const render = async ({ pathname }) => {
|
|
17
17
|
await preload(pathname);
|
|
18
18
|
const modules = new Set();
|
|
19
19
|
const routerContext = {};
|
|
@@ -33,11 +33,6 @@ const render = async ({ pathname, v4RemoveLegacyPostBuildHeadAttribute, }) => {
|
|
|
33
33
|
const html = await renderToHtml(app);
|
|
34
34
|
const { helmet } = helmetContext;
|
|
35
35
|
const metadata = toPageCollectedMetadataInternal({ helmet });
|
|
36
|
-
// TODO Docusaurus v4 remove with deprecated postBuild({head}) API
|
|
37
|
-
// the returned collectedData must be serializable to run in workers
|
|
38
|
-
if (v4RemoveLegacyPostBuildHeadAttribute) {
|
|
39
|
-
metadata.helmet = null;
|
|
40
|
-
}
|
|
41
36
|
const collectedData = {
|
|
42
37
|
metadata,
|
|
43
38
|
anchors: statefulBrokenLinks.getCollectedAnchors(),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { BuildCLIOptions } from './build';
|
|
7
|
+
import type { BuildCLIOptions } from './build';
|
|
8
8
|
export type BuildLocaleParams = {
|
|
9
9
|
siteDir: string;
|
|
10
10
|
locale: string;
|
|
@@ -99,9 +99,6 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
|
|
|
99
99
|
logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
|
|
100
100
|
}
|
|
101
101
|
async function executePluginsPostBuild({ plugins, props, collectedData, }) {
|
|
102
|
-
const head = props.siteConfig.future.v4.removeLegacyPostBuildHeadAttribute
|
|
103
|
-
? {}
|
|
104
|
-
: lodash_1.default.mapValues(collectedData, (d) => d.metadata.helmet);
|
|
105
102
|
const routesBuildMetadata = lodash_1.default.mapValues(collectedData, (d) => d.metadata.public);
|
|
106
103
|
await Promise.all(plugins.map(async (plugin) => {
|
|
107
104
|
if (!plugin.postBuild) {
|
|
@@ -109,7 +106,6 @@ async function executePluginsPostBuild({ plugins, props, collectedData, }) {
|
|
|
109
106
|
}
|
|
110
107
|
await plugin.postBuild({
|
|
111
108
|
...props,
|
|
112
|
-
head,
|
|
113
109
|
routesBuildMetadata,
|
|
114
110
|
content: plugin.content,
|
|
115
111
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { BuildCLIOptions } from './build';
|
|
7
|
+
import type { BuildCLIOptions } from './build';
|
|
8
8
|
/**
|
|
9
9
|
* We disable locale path localization if CLI has a single "--locale" option
|
|
10
10
|
* yarn build --locale fr => baseUrl=/ instead of baseUrl=/fr/
|
package/lib/commands/cli.js
CHANGED
|
@@ -109,6 +109,9 @@ async function createCLIProgram({ cli, cliArgs, siteDir, config, }) {
|
|
|
109
109
|
.option('--no-open', 'do not open page in the browser (default: false)')
|
|
110
110
|
.option('--poll [interval]', 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds', normalizePollValue)
|
|
111
111
|
.option('--no-minify', 'build website without minimizing JS bundles (default: false)')
|
|
112
|
+
.option('--https', 'serve the dev site over HTTPS using a self-signed cert (default: false). Preferred over the HTTPS=true env var. Implied when both --ssl-cert and --ssl-key are provided.')
|
|
113
|
+
.option('--ssl-cert <path>', 'path to a TLS certificate file (implies HTTPS). Preferred over the SSL_CRT_FILE env var; CLI takes precedence if both are set.')
|
|
114
|
+
.option('--ssl-key <path>', 'path to a TLS private key file (implies HTTPS). Preferred over the SSL_KEY_FILE env var; CLI takes precedence if both are set.')
|
|
112
115
|
.action(start_1.start);
|
|
113
116
|
cli
|
|
114
117
|
.command('serve [siteDir]')
|
package/lib/commands/deploy.js
CHANGED
|
@@ -12,7 +12,7 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const os_1 = tslib_1.__importDefault(require("os"));
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
-
const execa_1 =
|
|
15
|
+
const execa_1 = require("execa");
|
|
16
16
|
const utils_1 = require("@docusaurus/utils");
|
|
17
17
|
const site_1 = require("../server/site");
|
|
18
18
|
const build_1 = require("./build/build");
|
|
@@ -24,14 +24,12 @@ function obfuscateGitPass(str) {
|
|
|
24
24
|
const debugMode = !!process.env.DOCUSAURUS_DEPLOY_DEBUG;
|
|
25
25
|
// Log executed commands so that user can figure out mistakes on his own
|
|
26
26
|
// for example: https://github.com/facebook/docusaurus/issues/3875
|
|
27
|
-
function exec(
|
|
27
|
+
async function exec(file, args, options) {
|
|
28
28
|
const log = options?.log ?? true;
|
|
29
|
-
const failfast = options?.failfast ??
|
|
29
|
+
const failfast = options?.failfast ?? true;
|
|
30
|
+
const cmd = [file, ...args].join(' ');
|
|
30
31
|
try {
|
|
31
|
-
|
|
32
|
-
// Use async/await everything
|
|
33
|
-
// Avoid execa.command: the args need to be escaped manually
|
|
34
|
-
const result = execa_1.default.commandSync(cmd);
|
|
32
|
+
const result = await (0, execa_1.execa)(file, args, { reject: false });
|
|
35
33
|
if (log || debugMode) {
|
|
36
34
|
logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.exitCode}`}`;
|
|
37
35
|
}
|
|
@@ -39,7 +37,8 @@ function exec(cmd, options) {
|
|
|
39
37
|
console.log(result);
|
|
40
38
|
}
|
|
41
39
|
if (failfast && result.exitCode !== 0) {
|
|
42
|
-
throw new Error(`Command returned unexpected exitCode ${result.exitCode}
|
|
40
|
+
throw new Error(`Command returned unexpected exitCode ${result.exitCode}
|
|
41
|
+
${result.stderr}`);
|
|
43
42
|
}
|
|
44
43
|
return result;
|
|
45
44
|
}
|
|
@@ -48,13 +47,8 @@ function exec(cmd, options) {
|
|
|
48
47
|
In CWD code=${process.cwd()}`, { cause: err });
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function escapeArg(arg) {
|
|
54
|
-
return arg.replaceAll(' ', '\\ ');
|
|
55
|
-
}
|
|
56
|
-
function hasGit() {
|
|
57
|
-
return exec('git --version').exitCode === 0;
|
|
50
|
+
async function hasGit() {
|
|
51
|
+
return (await exec('git', ['--version'], { failfast: false })).exitCode === 0;
|
|
58
52
|
}
|
|
59
53
|
async function deploy(siteDirParam = '.', cliOptions = {}) {
|
|
60
54
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
@@ -70,23 +64,16 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
70
64
|
`);
|
|
71
65
|
}
|
|
72
66
|
logger_1.default.info('Deploy command invoked...');
|
|
73
|
-
if (!hasGit()) {
|
|
67
|
+
if (!(await hasGit())) {
|
|
74
68
|
throw new Error('Git not installed or not added to PATH!');
|
|
75
69
|
}
|
|
76
70
|
// Source repo is the repo from where the command is invoked
|
|
77
|
-
const
|
|
71
|
+
const sourceRepoUrl = (await exec('git', ['remote', 'get-url', 'origin'], {
|
|
78
72
|
log: false,
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
const sourceRepoUrl = stdout.trim();
|
|
73
|
+
})).stdout.trim();
|
|
82
74
|
// The source branch; defaults to the currently checked out branch
|
|
83
75
|
const sourceBranch = process.env.CURRENT_BRANCH ??
|
|
84
|
-
exec('git rev-parse --abbrev-ref HEAD', {
|
|
85
|
-
log: false,
|
|
86
|
-
failfast: true,
|
|
87
|
-
})
|
|
88
|
-
?.stdout?.toString()
|
|
89
|
-
.trim();
|
|
76
|
+
(await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { log: false })).stdout.trim();
|
|
90
77
|
const gitUser = process.env.GIT_USER;
|
|
91
78
|
let useSSH = process.env.USE_SSH !== undefined &&
|
|
92
79
|
process.env.USE_SSH.toLowerCase() === 'true';
|
|
@@ -116,10 +103,7 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
116
103
|
// We never deploy on pull request.
|
|
117
104
|
const isPullRequest = process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST;
|
|
118
105
|
if (isPullRequest) {
|
|
119
|
-
|
|
120
|
-
log: false,
|
|
121
|
-
failfast: true,
|
|
122
|
-
});
|
|
106
|
+
logger_1.default.info('Skipping deploy on a pull request.');
|
|
123
107
|
process.exit(0);
|
|
124
108
|
}
|
|
125
109
|
// github.io indicates organization repos that deploy via default branch. All
|
|
@@ -158,7 +142,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
158
142
|
}
|
|
159
143
|
// Save the commit hash that triggers publish-gh-pages before checking
|
|
160
144
|
// out to deployment branch.
|
|
161
|
-
const currentCommit = exec('git rev-parse HEAD')
|
|
145
|
+
const currentCommit = (await exec('git', ['rev-parse', 'HEAD'])).stdout.trim();
|
|
162
146
|
const runDeploy = async (outputDirectory) => {
|
|
163
147
|
const targetDirectory = cliOptions.targetDir ?? '.';
|
|
164
148
|
const fromPath = outputDirectory;
|
|
@@ -167,43 +151,47 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
167
151
|
// Clones the repo into the temp folder and checks out the target branch.
|
|
168
152
|
// If the branch doesn't exist, it creates a new one based on the
|
|
169
153
|
// repository default branch.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
const cloneResult = await exec('git', [
|
|
155
|
+
'clone',
|
|
156
|
+
'--depth',
|
|
157
|
+
'1',
|
|
158
|
+
'--branch',
|
|
159
|
+
deploymentBranch,
|
|
160
|
+
deploymentRepoURL,
|
|
161
|
+
toPath,
|
|
162
|
+
], { failfast: false });
|
|
163
|
+
if (cloneResult.exitCode !== 0) {
|
|
164
|
+
await exec('git', ['clone', '--depth', '1', deploymentRepoURL, toPath]);
|
|
165
|
+
await exec('git', ['checkout', '-b', deploymentBranch]);
|
|
173
166
|
}
|
|
174
167
|
// Clear out any existing contents in the target directory
|
|
175
|
-
exec(
|
|
176
|
-
log: false,
|
|
177
|
-
failfast: true,
|
|
178
|
-
});
|
|
168
|
+
await exec('git', ['rm', '-rf', targetDirectory], { log: false });
|
|
179
169
|
const targetPath = path_1.default.join(toPath, targetDirectory);
|
|
180
170
|
try {
|
|
181
171
|
await fs_extra_1.default.copy(fromPath, targetPath);
|
|
182
172
|
}
|
|
183
173
|
catch (err) {
|
|
184
|
-
|
|
185
|
-
throw err;
|
|
174
|
+
throw new Error(`Failed to copy build assets from path=${fromPath} to path=${targetPath}.`, { cause: err });
|
|
186
175
|
}
|
|
187
|
-
exec('git add --all'
|
|
176
|
+
await exec('git', ['add', '--all']);
|
|
188
177
|
const gitUserName = process.env.GIT_USER_NAME;
|
|
189
178
|
if (gitUserName) {
|
|
190
|
-
exec(
|
|
179
|
+
await exec('git', ['config', 'user.name', gitUserName]);
|
|
191
180
|
}
|
|
192
181
|
const gitUserEmail = process.env.GIT_USER_EMAIL;
|
|
193
182
|
if (gitUserEmail) {
|
|
194
|
-
exec(
|
|
195
|
-
failfast: true,
|
|
196
|
-
});
|
|
183
|
+
await exec('git', ['config', 'user.email', gitUserEmail]);
|
|
197
184
|
}
|
|
198
185
|
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ??
|
|
199
186
|
`Deploy website - based on ${currentCommit}`;
|
|
200
|
-
|
|
201
|
-
|
|
187
|
+
// The commit might return a non-zero value when site is up to date.
|
|
188
|
+
const commitResults = await exec('git', ['commit', '-m', commitMessage, '--allow-empty'], { failfast: false });
|
|
189
|
+
const pushResult = await exec('git', ['push', '--force', 'origin', deploymentBranch], { failfast: false });
|
|
190
|
+
if (pushResult.exitCode !== 0) {
|
|
202
191
|
throw new Error('Running "git push" command failed. Does the GitHub user account you are using have push access to the repository?');
|
|
203
192
|
}
|
|
204
193
|
else if (commitResults.exitCode === 0) {
|
|
205
|
-
|
|
206
|
-
let websiteURL = '';
|
|
194
|
+
let websiteURL;
|
|
207
195
|
if (githubHost === 'github.com') {
|
|
208
196
|
websiteURL = projectName.includes('.github.io')
|
|
209
197
|
? `https://${organizationName}.github.io/`
|
|
@@ -213,13 +201,8 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
213
201
|
// GitHub enterprise hosting.
|
|
214
202
|
websiteURL = `https://${githubHost}/pages/${organizationName}/${projectName}/`;
|
|
215
203
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
process.exit(0);
|
|
219
|
-
}
|
|
220
|
-
catch (err) {
|
|
221
|
-
throw new Error(`Failed to execute command: ${err}`);
|
|
222
|
-
}
|
|
204
|
+
logger_1.default.success `Website is live at url=${websiteURL}.`;
|
|
205
|
+
process.exit(0);
|
|
223
206
|
}
|
|
224
207
|
};
|
|
225
208
|
if (!cliOptions.skipBuild) {
|
package/lib/commands/serve.js
CHANGED
|
@@ -19,6 +19,7 @@ const openBrowser_1 = tslib_1.__importDefault(require("./utils/openBrowser/openB
|
|
|
19
19
|
const config_1 = require("../server/config");
|
|
20
20
|
const build_1 = require("./build/build");
|
|
21
21
|
const getHostPort_1 = require("../server/getHostPort");
|
|
22
|
+
const listenToServer_1 = require("./utils/listenToServer");
|
|
22
23
|
function redirect(res, location) {
|
|
23
24
|
res.writeHead(302, {
|
|
24
25
|
Location: location,
|
|
@@ -56,7 +57,7 @@ async function serve(siteDirParam = '.', cliOptions = {}) {
|
|
|
56
57
|
if (baseUrl !== '/') {
|
|
57
58
|
// Not super robust, but should be good enough for our use case
|
|
58
59
|
// See https://github.com/facebook/docusaurus/pull/10090
|
|
59
|
-
const looksLikeAsset = !!req.url.match(/\.[a-
|
|
60
|
+
const looksLikeAsset = !!req.url.match(/\.[a-z\d]{1,4}$/i);
|
|
60
61
|
if (!looksLikeAsset) {
|
|
61
62
|
const normalizedUrl = (0, utils_common_1.applyTrailingSlash)(req.url, {
|
|
62
63
|
trailingSlash,
|
|
@@ -84,7 +85,7 @@ async function serve(siteDirParam = '.', cliOptions = {}) {
|
|
|
84
85
|
});
|
|
85
86
|
const url = servingUrl + baseUrl;
|
|
86
87
|
logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
|
|
87
|
-
|
|
88
|
+
await (0, listenToServer_1.listenToServer)({ server, host, port });
|
|
88
89
|
if (cliOptions.open && !process.env.CI) {
|
|
89
90
|
await (0, openBrowser_1.default)(url);
|
|
90
91
|
}
|
|
@@ -11,5 +11,8 @@ export type StartCLIOptions = HostPortOptions & Pick<LoadContextParams, 'locale'
|
|
|
11
11
|
open?: boolean;
|
|
12
12
|
poll?: boolean | number;
|
|
13
13
|
minify?: boolean;
|
|
14
|
+
https?: true;
|
|
15
|
+
sslCert?: string;
|
|
16
|
+
sslKey?: string;
|
|
14
17
|
};
|
|
15
18
|
export declare function start(siteDirParam?: string, cliOptions?: Partial<StartCLIOptions>): Promise<void>;
|
|
@@ -41,7 +41,11 @@ function registerWebpackE2ETestHook(compiler) {
|
|
|
41
41
|
async function createDevServerConfig({ cliOptions, props, host, port, }) {
|
|
42
42
|
const { baseUrl, siteDir, siteConfig } = props;
|
|
43
43
|
const pollingOptions = (0, watcher_1.createPollingOptions)(cliOptions);
|
|
44
|
-
const httpsConfig = await (0, getHttpsConfig_1.default)(
|
|
44
|
+
const httpsConfig = await (0, getHttpsConfig_1.default)({
|
|
45
|
+
https: cliOptions.https,
|
|
46
|
+
sslCert: cliOptions.sslCert,
|
|
47
|
+
sslKey: cliOptions.sslKey,
|
|
48
|
+
});
|
|
45
49
|
// https://webpack.js.org/configuration/dev-server
|
|
46
50
|
return {
|
|
47
51
|
hot: cliOptions.hotOnly ? 'only' : true,
|
|
@@ -134,5 +138,19 @@ async function createWebpackDevServer({ props, cliOptions, openUrlContext, }) {
|
|
|
134
138
|
});
|
|
135
139
|
// Allow plugin authors to customize/override devServer config
|
|
136
140
|
const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
|
|
137
|
-
return
|
|
141
|
+
return createDevServer({
|
|
142
|
+
devServerConfig,
|
|
143
|
+
compiler,
|
|
144
|
+
currentBundler: props.currentBundler,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async function createDevServer({ devServerConfig, compiler, currentBundler, }) {
|
|
148
|
+
if (currentBundler.name === 'webpack') {
|
|
149
|
+
return new webpack_dev_server_1.default(devServerConfig, compiler);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const RspackDevServer = await (0, bundler_1.importRspackDevServer)();
|
|
153
|
+
// @ts-expect-error: different types
|
|
154
|
+
return new RspackDevServer(devServerConfig, compiler);
|
|
155
|
+
}
|
|
138
156
|
}
|
|
@@ -39,6 +39,11 @@ async function eject({ siteDir, themePath, componentName, typescript, }) {
|
|
|
39
39
|
: `${fromPath}.*`;
|
|
40
40
|
const globPatternPosix = (0, utils_1.posixPath)(globPattern);
|
|
41
41
|
const filesToCopy = await (0, utils_1.Globby)(globPatternPosix, {
|
|
42
|
+
// Workaround for Tinyglobby bug?
|
|
43
|
+
// We glob absolute from the theme root path, not from cwd
|
|
44
|
+
// See https://github.com/SuperchupuDev/tinyglobby/issues/186
|
|
45
|
+
cwd: themePath,
|
|
46
|
+
absolute: true,
|
|
42
47
|
ignore: lodash_1.default.compact([
|
|
43
48
|
'**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}',
|
|
44
49
|
// When ejecting JS components, we want to avoid emitting TS files
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listenToServer = listenToServer;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
const logger_1 = require("@docusaurus/logger");
|
|
11
|
+
async function listenToServer({ server, port, host, }) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
server.once('listening', () => resolve());
|
|
14
|
+
server.once('error', (err) => {
|
|
15
|
+
if (err.code === 'EADDRINUSE') {
|
|
16
|
+
reject(new Error(logger_1.logger.interpolate `Address in use, another server is already listening on the requested port number=${port} and host name=${host}`, { cause: err }));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reject(err);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
server.listen(port, host);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -15,7 +15,7 @@ const tslib_1 = require("tslib");
|
|
|
15
15
|
/* eslint-disable */
|
|
16
16
|
const child_process_1 = require("child_process");
|
|
17
17
|
const util_1 = require("util");
|
|
18
|
-
const open_1 = tslib_1.
|
|
18
|
+
const open_1 = tslib_1.__importStar(require("open"));
|
|
19
19
|
const logger_1 = require("@docusaurus/logger");
|
|
20
20
|
const execPromise = (0, util_1.promisify)(child_process_1.exec);
|
|
21
21
|
// Not sure if we need this, but let's keep a secret escape hatch
|
|
@@ -101,9 +101,9 @@ function toOpenApp(params) {
|
|
|
101
101
|
return undefined;
|
|
102
102
|
}
|
|
103
103
|
// Handles "cross-platform" shortcuts like "chrome", "firefox", "edge"
|
|
104
|
-
if (open_1.
|
|
104
|
+
if (open_1.apps[params.browser]) {
|
|
105
105
|
return {
|
|
106
|
-
name: open_1.
|
|
106
|
+
name: open_1.apps[params.browser],
|
|
107
107
|
arguments: params.browserArgs,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
@@ -63,9 +63,9 @@ async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
|
|
|
63
63
|
validateOptions(options);
|
|
64
64
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
65
65
|
const patterns = files.length ? files : await getPathsToWatch(siteDir);
|
|
66
|
-
const markdownFiles = await (0, utils_1.safeGlobby)(patterns, {
|
|
67
|
-
expandDirectories:
|
|
68
|
-
});
|
|
66
|
+
const markdownFiles = (await (0, utils_1.safeGlobby)(patterns, {
|
|
67
|
+
expandDirectories: true,
|
|
68
|
+
})).filter((file) => file.endsWith('.md') || file.endsWith('.mdx'));
|
|
69
69
|
if (markdownFiles.length === 0) {
|
|
70
70
|
logger_1.default.warn `No markdown files found in siteDir path=${siteDir} for patterns: ${patterns}`;
|
|
71
71
|
return;
|
|
@@ -85,7 +85,6 @@ ${indent(parts.join(',\n'))}
|
|
|
85
85
|
}
|
|
86
86
|
const isModule = (value) => typeof value === 'string' ||
|
|
87
87
|
(typeof value === 'object' &&
|
|
88
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
89
88
|
!!value?.__import);
|
|
90
89
|
/**
|
|
91
90
|
* Takes a {@link Module} (which is nothing more than a path plus some metadata
|
package/lib/server/config.js
CHANGED
|
@@ -33,7 +33,7 @@ async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
|
|
|
33
33
|
if (!(await fs_extra_1.default.pathExists(siteConfigPath))) {
|
|
34
34
|
throw new Error(`Config file at "${siteConfigPath}" not found.`);
|
|
35
35
|
}
|
|
36
|
-
const importedConfig = await (0, utils_1.loadFreshModule)(siteConfigPath);
|
|
36
|
+
const importedConfig = await (0, utils_1.loadFreshModule)(siteConfigPath, { default: true });
|
|
37
37
|
const loadedConfig = typeof importedConfig === 'function'
|
|
38
38
|
? await importedConfig()
|
|
39
39
|
: await importedConfig;
|