@docusaurus/core 3.10.1-canary-6640 → 3.10.1-canary-6641
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/lib/commands/cli.js
CHANGED
|
@@ -109,6 +109,21 @@ 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
|
+
/*
|
|
113
|
+
TODO
|
|
114
|
+
.option(
|
|
115
|
+
'--https',
|
|
116
|
+
'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.',
|
|
117
|
+
)
|
|
118
|
+
.option(
|
|
119
|
+
'--ssl-cert <path>',
|
|
120
|
+
'path to a TLS certificate file (implies HTTPS). Preferred over the SSL_CRT_FILE env var; CLI takes precedence if both are set.',
|
|
121
|
+
)
|
|
122
|
+
.option(
|
|
123
|
+
'--ssl-key <path>',
|
|
124
|
+
'path to a TLS private key file (implies HTTPS). Preferred over the SSL_KEY_FILE env var; CLI takes precedence if both are set.',
|
|
125
|
+
)
|
|
126
|
+
*/
|
|
112
127
|
.action(start_1.start);
|
|
113
128
|
cli
|
|
114
129
|
.command('serve [siteDir]')
|
|
@@ -42,7 +42,15 @@ function registerWebpackE2ETestHook(compiler) {
|
|
|
42
42
|
async function createDevServerConfig({ cliOptions, props, host, port, }) {
|
|
43
43
|
const { baseUrl, siteDir, siteConfig } = props;
|
|
44
44
|
const pollingOptions = (0, watcher_1.createPollingOptions)(cliOptions);
|
|
45
|
-
const httpsConfig = await (0, getHttpsConfig_1.default)(
|
|
45
|
+
const httpsConfig = await (0, getHttpsConfig_1.default)({
|
|
46
|
+
/*
|
|
47
|
+
TODO Docusaurus v4: wire new CLI parameters
|
|
48
|
+
https: cliOptions.https,
|
|
49
|
+
sslCert: cliOptions.sslCert,
|
|
50
|
+
sslKey: cliOptions.sslKey,
|
|
51
|
+
|
|
52
|
+
*/
|
|
53
|
+
});
|
|
46
54
|
// https://webpack.js.org/configuration/dev-server
|
|
47
55
|
return {
|
|
48
56
|
hot: cliOptions.hotOnly ? 'only' : true,
|
|
@@ -4,7 +4,13 @@
|
|
|
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
|
-
|
|
7
|
+
type HttpsConfigOptions = {
|
|
8
|
+
https: boolean;
|
|
9
|
+
sslCert: string;
|
|
10
|
+
sslKey: string;
|
|
11
|
+
};
|
|
12
|
+
export default function getHttpsConfig(options?: Partial<HttpsConfigOptions>): Promise<boolean | {
|
|
8
13
|
cert: Buffer;
|
|
9
14
|
key: Buffer;
|
|
10
15
|
}>;
|
|
16
|
+
export {};
|
|
@@ -13,48 +13,109 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
13
13
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
15
|
// Ensure the certificate and key provided are valid and if not
|
|
16
|
-
// throw an easy to debug error
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// throw an easy to debug error.
|
|
17
|
+
//
|
|
18
|
+
// Works for any key type (RSA, ECDSA, EdDSA, ...) — parses both PEMs and
|
|
19
|
+
// checks that the public key embedded in the cert matches the public key
|
|
20
|
+
// derived from the private key.
|
|
21
|
+
function validateKeyAndCerts({ cert, key }) {
|
|
22
|
+
let certPublicKey;
|
|
19
23
|
try {
|
|
20
|
-
|
|
21
|
-
encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
|
|
24
|
+
certPublicKey = new crypto_1.default.X509Certificate(cert.content).publicKey;
|
|
22
25
|
}
|
|
23
|
-
catch (
|
|
24
|
-
logger_1.default.
|
|
25
|
-
throw err;
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new Error(logger_1.default.interpolate `The certificate path=${cert.path} is invalid.`, { cause: error });
|
|
26
28
|
}
|
|
29
|
+
let keyPublicKey;
|
|
27
30
|
try {
|
|
28
|
-
|
|
29
|
-
crypto_1.default.privateDecrypt(key, encrypted);
|
|
31
|
+
keyPublicKey = crypto_1.default.createPublicKey(crypto_1.default.createPrivateKey(key.content));
|
|
30
32
|
}
|
|
31
|
-
catch (
|
|
32
|
-
logger_1.default.
|
|
33
|
-
throw err;
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(logger_1.default.interpolate `The certificate key path=${key.path} is invalid.`, { cause: error });
|
|
34
35
|
}
|
|
36
|
+
if (!certPublicKey.equals(keyPublicKey)) {
|
|
37
|
+
throw new Error(logger_1.default.interpolate `The certificate path=${cert.path} and key path=${key.path} do not match.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getExplicitHttps(options) {
|
|
41
|
+
return (options.https ??
|
|
42
|
+
(typeof process.env.DOCUSAURUS_HTTPS !== 'undefined'
|
|
43
|
+
? process.env.DOCUSAURUS_HTTPS == 'true'
|
|
44
|
+
: undefined) ??
|
|
45
|
+
(typeof process.env.HTTPS !== 'undefined'
|
|
46
|
+
? process.env.HTTPS == 'true'
|
|
47
|
+
: undefined));
|
|
48
|
+
}
|
|
49
|
+
async function readCryptoFile(filepath, source) {
|
|
50
|
+
if (!(await fs_extra_1.default.pathExists(filepath))) {
|
|
51
|
+
throw new Error(logger_1.default.interpolate `You specified ${source}, but file at path path=${filepath} can't be found.`);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
path: filepath,
|
|
56
|
+
source,
|
|
57
|
+
content: await fs_extra_1.default.readFile(filepath),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(logger_1.default.interpolate `You specified ${source}, but file at path path=${filepath} can't be read.`, { cause: error });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function getCert(options, cwd) {
|
|
65
|
+
if (options.sslCert) {
|
|
66
|
+
return readCryptoFile(path_1.default.resolve(cwd, options.sslCert), 'CLI arg --ssl-cert');
|
|
67
|
+
}
|
|
68
|
+
if (process.env.DOCUSAURUS_SSL_CRT_FILE) {
|
|
69
|
+
return readCryptoFile(path_1.default.resolve(cwd, process.env.DOCUSAURUS_SSL_CRT_FILE), 'env DOCUSAURUS_SSL_CRT_FILE');
|
|
70
|
+
}
|
|
71
|
+
if (process.env.SSL_CRT_FILE) {
|
|
72
|
+
return readCryptoFile(path_1.default.resolve(cwd, process.env.SSL_CRT_FILE), 'env SSL_CRT_FILE');
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function getKeyFile(options, cwd) {
|
|
77
|
+
if (options.sslKey) {
|
|
78
|
+
return readCryptoFile(path_1.default.resolve(cwd, options.sslKey), 'CLI arg --ssl-key');
|
|
79
|
+
}
|
|
80
|
+
if (process.env.DOCUSAURUS_SSL_KEY_FILE) {
|
|
81
|
+
return readCryptoFile(path_1.default.resolve(cwd, process.env.DOCUSAURUS_SSL_KEY_FILE), 'env DOCUSAURUS_SSL_KEY_FILE');
|
|
82
|
+
}
|
|
83
|
+
if (process.env.SSL_KEY_FILE) {
|
|
84
|
+
return readCryptoFile(path_1.default.resolve(cwd, process.env.SSL_KEY_FILE), 'env SSL_KEY_FILE');
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
35
87
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error(`
|
|
88
|
+
function ensureCertKeyBothProvided(cert, key) {
|
|
89
|
+
if ((cert || key) && !(cert && key)) {
|
|
90
|
+
const fileProvided = (cert ?? key);
|
|
91
|
+
throw new Error(logger_1.default.interpolate `HTTPS support require proving a certificate and key at the same time.
|
|
92
|
+
You only provided a ${cert ? 'certificate' : 'key'} (with ${fileProvided.source}) at path path=${fileProvided.path}.`);
|
|
40
93
|
}
|
|
41
|
-
return fs_extra_1.default.readFile(file);
|
|
42
94
|
}
|
|
43
95
|
// Get the https config
|
|
44
|
-
// Return cert files if provided
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
96
|
+
// Return cert files if provided via CLI or env, otherwise just true or false.
|
|
97
|
+
// CLI options take precedence over env vars.
|
|
98
|
+
async function getHttpsConfig(options = {}) {
|
|
99
|
+
const cwd = await fs_extra_1.default.realpath(process.cwd());
|
|
100
|
+
const [cert, key] = await Promise.all([
|
|
101
|
+
getCert(options, cwd),
|
|
102
|
+
getKeyFile(options, cwd),
|
|
103
|
+
]);
|
|
104
|
+
// Providing both cert/key implies HTTPS
|
|
105
|
+
const inferredHttps = !!(cert && key);
|
|
106
|
+
const https = getExplicitHttps(options) ?? inferredHttps;
|
|
107
|
+
if (https && cert && key) {
|
|
108
|
+
validateKeyAndCerts({
|
|
109
|
+
cert,
|
|
110
|
+
key,
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
cert: cert.content,
|
|
114
|
+
key: key.content,
|
|
55
115
|
};
|
|
56
|
-
validateKeyAndCerts({ ...config, keyFile, crtFile });
|
|
57
|
-
return config;
|
|
58
116
|
}
|
|
59
|
-
|
|
117
|
+
ensureCertKeyBothProvided(cert, key);
|
|
118
|
+
// Apparently we can have https without cert/key (historical)
|
|
119
|
+
// although I don't know how this works 🤷♂️
|
|
120
|
+
return https;
|
|
60
121
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "3.10.1-canary-
|
|
4
|
+
"version": "3.10.1-canary-6641",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "3.10.1-canary-
|
|
37
|
-
"@docusaurus/bundler": "3.10.1-canary-
|
|
38
|
-
"@docusaurus/logger": "3.10.1-canary-
|
|
39
|
-
"@docusaurus/mdx-loader": "3.10.1-canary-
|
|
40
|
-
"@docusaurus/utils": "3.10.1-canary-
|
|
41
|
-
"@docusaurus/utils-common": "3.10.1-canary-
|
|
42
|
-
"@docusaurus/utils-validation": "3.10.1-canary-
|
|
36
|
+
"@docusaurus/babel": "3.10.1-canary-6641",
|
|
37
|
+
"@docusaurus/bundler": "3.10.1-canary-6641",
|
|
38
|
+
"@docusaurus/logger": "3.10.1-canary-6641",
|
|
39
|
+
"@docusaurus/mdx-loader": "3.10.1-canary-6641",
|
|
40
|
+
"@docusaurus/utils": "3.10.1-canary-6641",
|
|
41
|
+
"@docusaurus/utils-common": "3.10.1-canary-6641",
|
|
42
|
+
"@docusaurus/utils-validation": "3.10.1-canary-6641",
|
|
43
43
|
"boxen": "^6.2.1",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"webpack-merge": "^6.0.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@docusaurus/module-type-aliases": "3.10.1-canary-
|
|
81
|
-
"@docusaurus/types": "3.10.1-canary-
|
|
80
|
+
"@docusaurus/module-type-aliases": "3.10.1-canary-6641",
|
|
81
|
+
"@docusaurus/types": "3.10.1-canary-6641",
|
|
82
82
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
83
83
|
"@types/detect-port": "^1.3.3",
|
|
84
84
|
"@types/react-dom": "^19.2.3",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"engines": {
|
|
105
105
|
"node": ">=24.14"
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "0dfa1b9d632948a6dfc2c216e631e60f63a6682c"
|
|
108
108
|
}
|