@docusaurus/core 3.7.0-canary-6244 → 3.7.0-canary-6246
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 +3 -3
- package/lib/commands/deploy.js +70 -28
- package/lib/commands/serve.js +2 -2
- package/lib/commands/start/start.js +2 -2
- package/lib/commands/start/utils.js +17 -3
- package/lib/commands/start/webpack.js +1 -1
- package/lib/commands/utils/legacy/evalSourceMapMiddleware.d.ts +2 -0
- package/lib/commands/utils/legacy/evalSourceMapMiddleware.js +57 -0
- package/lib/commands/utils/openBrowser/openBrowser.d.ts +10 -0
- package/lib/commands/utils/openBrowser/openBrowser.js +106 -0
- package/lib/commands/utils/openBrowser/openChrome.applescript +94 -0
- package/package.json +13 -13
package/bin/beforeCli.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import fs from 'fs-extra';
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import {createRequire} from 'module';
|
|
13
|
-
import
|
|
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';
|
|
@@ -111,8 +111,8 @@ export default async function beforeCli() {
|
|
|
111
111
|
return undefined;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const yarnVersionResult =
|
|
115
|
-
if (yarnVersionResult
|
|
114
|
+
const yarnVersionResult = await execa.command('yarn --version');
|
|
115
|
+
if (yarnVersionResult.exitCode === 0) {
|
|
116
116
|
const majorVersion = parseInt(
|
|
117
117
|
yarnVersionResult.stdout?.trim().split('.')[0] ?? '',
|
|
118
118
|
10,
|
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
|
|
15
|
+
const execa_1 = tslib_1.__importDefault(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");
|
|
@@ -21,19 +21,41 @@ function obfuscateGitPass(str) {
|
|
|
21
21
|
const gitPass = process.env.GIT_PASS;
|
|
22
22
|
return gitPass ? str.replace(gitPass, 'GIT_PASS') : str;
|
|
23
23
|
}
|
|
24
|
+
const debugMode = !!process.env.DOCUSAURUS_DEPLOY_DEBUG;
|
|
24
25
|
// Log executed commands so that user can figure out mistakes on his own
|
|
25
26
|
// for example: https://github.com/facebook/docusaurus/issues/3875
|
|
26
|
-
function
|
|
27
|
+
function exec(cmd, options) {
|
|
28
|
+
const log = options?.log ?? true;
|
|
29
|
+
const failfast = options?.failfast ?? false;
|
|
27
30
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// TODO migrate to execa(file,[...args]) instead
|
|
32
|
+
// Use async/await everything
|
|
33
|
+
// Avoid execa.command: the args need to be escaped manually
|
|
34
|
+
const result = execa_1.default.commandSync(cmd);
|
|
35
|
+
if (log || debugMode) {
|
|
36
|
+
logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.exitCode}`}`;
|
|
37
|
+
}
|
|
38
|
+
if (debugMode) {
|
|
39
|
+
console.log(result);
|
|
40
|
+
}
|
|
41
|
+
if (failfast && result.exitCode !== 0) {
|
|
42
|
+
throw new Error(`Command returned unexpected exitCode ${result.exitCode}`);
|
|
43
|
+
}
|
|
30
44
|
return result;
|
|
31
45
|
}
|
|
32
46
|
catch (err) {
|
|
33
|
-
logger_1.default.
|
|
34
|
-
|
|
47
|
+
throw new Error(logger_1.default.interpolate `Error while executing command code=${obfuscateGitPass(cmd)}
|
|
48
|
+
In CWD code=${process.cwd()}`, { cause: err });
|
|
35
49
|
}
|
|
36
50
|
}
|
|
51
|
+
// Execa escape args and add necessary quotes automatically
|
|
52
|
+
// When using Execa.command, the args containing spaces must be escaped manually
|
|
53
|
+
function escapeArg(arg) {
|
|
54
|
+
return arg.replaceAll(' ', '\\ ');
|
|
55
|
+
}
|
|
56
|
+
function hasGit() {
|
|
57
|
+
return exec('git --version').exitCode === 0;
|
|
58
|
+
}
|
|
37
59
|
async function deploy(siteDirParam = '.', cliOptions = {}) {
|
|
38
60
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
39
61
|
const { outDir, siteConfig, siteConfigPath } = await (0, site_1.loadContext)({
|
|
@@ -48,16 +70,23 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
48
70
|
`);
|
|
49
71
|
}
|
|
50
72
|
logger_1.default.info('Deploy command invoked...');
|
|
51
|
-
if (!
|
|
52
|
-
throw new Error('Git not installed or
|
|
73
|
+
if (!hasGit()) {
|
|
74
|
+
throw new Error('Git not installed or not added to PATH!');
|
|
53
75
|
}
|
|
54
76
|
// Source repo is the repo from where the command is invoked
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const { stdout } = exec('git remote get-url origin', {
|
|
78
|
+
log: false,
|
|
79
|
+
failfast: true,
|
|
80
|
+
});
|
|
81
|
+
const sourceRepoUrl = stdout.trim();
|
|
58
82
|
// The source branch; defaults to the currently checked out branch
|
|
59
83
|
const sourceBranch = process.env.CURRENT_BRANCH ??
|
|
60
|
-
|
|
84
|
+
exec('git rev-parse --abbrev-ref HEAD', {
|
|
85
|
+
log: false,
|
|
86
|
+
failfast: true,
|
|
87
|
+
})
|
|
88
|
+
?.stdout?.toString()
|
|
89
|
+
.trim();
|
|
61
90
|
const gitUser = process.env.GIT_USER;
|
|
62
91
|
let useSSH = process.env.USE_SSH !== undefined &&
|
|
63
92
|
process.env.USE_SSH.toLowerCase() === 'true';
|
|
@@ -87,8 +116,11 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
87
116
|
// We never deploy on pull request.
|
|
88
117
|
const isPullRequest = process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST;
|
|
89
118
|
if (isPullRequest) {
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
exec('echo "Skipping deploy on a pull request."', {
|
|
120
|
+
log: false,
|
|
121
|
+
failfast: true,
|
|
122
|
+
});
|
|
123
|
+
process.exit(0);
|
|
92
124
|
}
|
|
93
125
|
// github.io indicates organization repos that deploy via default branch. All
|
|
94
126
|
// others use gh-pages (either case can be configured actually, but we can
|
|
@@ -126,21 +158,24 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
126
158
|
}
|
|
127
159
|
// Save the commit hash that triggers publish-gh-pages before checking
|
|
128
160
|
// out to deployment branch.
|
|
129
|
-
const currentCommit =
|
|
161
|
+
const currentCommit = exec('git rev-parse HEAD')?.stdout?.toString().trim();
|
|
130
162
|
const runDeploy = async (outputDirectory) => {
|
|
131
163
|
const targetDirectory = cliOptions.targetDir ?? '.';
|
|
132
164
|
const fromPath = outputDirectory;
|
|
133
165
|
const toPath = await fs_extra_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), `${projectName}-${deploymentBranch}`));
|
|
134
|
-
|
|
166
|
+
process.chdir(toPath);
|
|
135
167
|
// Clones the repo into the temp folder and checks out the target branch.
|
|
136
168
|
// If the branch doesn't exist, it creates a new one based on the
|
|
137
169
|
// repository default branch.
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
170
|
+
if (exec(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} ${escapeArg(toPath)}`).exitCode !== 0) {
|
|
171
|
+
exec(`git clone --depth 1 ${deploymentRepoURL} ${escapeArg(toPath)}`);
|
|
172
|
+
exec(`git checkout -b ${deploymentBranch}`);
|
|
141
173
|
}
|
|
142
174
|
// Clear out any existing contents in the target directory
|
|
143
|
-
|
|
175
|
+
exec(`git rm -rf ${escapeArg(targetDirectory)}`, {
|
|
176
|
+
log: false,
|
|
177
|
+
failfast: true,
|
|
178
|
+
});
|
|
144
179
|
const targetPath = path_1.default.join(toPath, targetDirectory);
|
|
145
180
|
try {
|
|
146
181
|
await fs_extra_1.default.copy(fromPath, targetPath);
|
|
@@ -149,22 +184,24 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
149
184
|
logger_1.default.error `Copying build assets from path=${fromPath} to path=${targetPath} failed.`;
|
|
150
185
|
throw err;
|
|
151
186
|
}
|
|
152
|
-
|
|
187
|
+
exec('git add --all', { failfast: true });
|
|
153
188
|
const gitUserName = process.env.GIT_USER_NAME;
|
|
154
189
|
if (gitUserName) {
|
|
155
|
-
|
|
190
|
+
exec(`git config user.name ${escapeArg(gitUserName)}`, { failfast: true });
|
|
156
191
|
}
|
|
157
192
|
const gitUserEmail = process.env.GIT_USER_EMAIL;
|
|
158
193
|
if (gitUserEmail) {
|
|
159
|
-
|
|
194
|
+
exec(`git config user.email ${escapeArg(gitUserEmail)}`, {
|
|
195
|
+
failfast: true,
|
|
196
|
+
});
|
|
160
197
|
}
|
|
161
198
|
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ??
|
|
162
199
|
`Deploy website - based on ${currentCommit}`;
|
|
163
|
-
const commitResults =
|
|
164
|
-
if (
|
|
200
|
+
const commitResults = exec(`git commit -m ${escapeArg(commitMessage)} --allow-empty`);
|
|
201
|
+
if (exec(`git push --force origin ${deploymentBranch}`).exitCode !== 0) {
|
|
165
202
|
throw new Error('Running "git push" command failed. Does the GitHub user account you are using have push access to the repository?');
|
|
166
203
|
}
|
|
167
|
-
else if (commitResults.
|
|
204
|
+
else if (commitResults.exitCode === 0) {
|
|
168
205
|
// The commit might return a non-zero value when site is up to date.
|
|
169
206
|
let websiteURL = '';
|
|
170
207
|
if (githubHost === 'github.com') {
|
|
@@ -176,8 +213,13 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
176
213
|
// GitHub enterprise hosting.
|
|
177
214
|
websiteURL = `https://${githubHost}/pages/${organizationName}/${projectName}/`;
|
|
178
215
|
}
|
|
179
|
-
|
|
180
|
-
|
|
216
|
+
try {
|
|
217
|
+
exec(`echo "Website is live at ${websiteURL}."`, { failfast: true });
|
|
218
|
+
process.exit(0);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
throw new Error(`Failed to execute command: ${err}`);
|
|
222
|
+
}
|
|
181
223
|
}
|
|
182
224
|
};
|
|
183
225
|
if (!cliOptions.skipBuild) {
|
package/lib/commands/serve.js
CHANGED
|
@@ -14,8 +14,8 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
17
|
-
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
18
17
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
18
|
+
const openBrowser_1 = tslib_1.__importDefault(require("./utils/openBrowser/openBrowser"));
|
|
19
19
|
const config_1 = require("../server/config");
|
|
20
20
|
const build_1 = require("./build/build");
|
|
21
21
|
const getHostPort_1 = require("../server/getHostPort");
|
|
@@ -86,6 +86,6 @@ async function serve(siteDirParam = '.', cliOptions = {}) {
|
|
|
86
86
|
logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
|
|
87
87
|
server.listen(port);
|
|
88
88
|
if (cliOptions.open && !process.env.CI) {
|
|
89
|
-
(0, openBrowser_1.default)(url);
|
|
89
|
+
await (0, openBrowser_1.default)(url);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.start = start;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
-
const openBrowser_1 = tslib_1.__importDefault(require("
|
|
12
|
+
const openBrowser_1 = tslib_1.__importDefault(require("../utils/openBrowser/openBrowser"));
|
|
13
13
|
const watcher_1 = require("./watcher");
|
|
14
14
|
const webpack_1 = require("./webpack");
|
|
15
15
|
const utils_1 = require("./utils");
|
|
@@ -41,6 +41,6 @@ async function start(siteDirParam = '.', cliOptions = {}) {
|
|
|
41
41
|
});
|
|
42
42
|
await devServer.start();
|
|
43
43
|
if (cliOptions.open) {
|
|
44
|
-
(0, openBrowser_1.default)(reloadableSite.getOpenUrl());
|
|
44
|
+
await (0, openBrowser_1.default)(reloadableSite.getOpenUrl());
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -10,13 +10,28 @@ exports.createOpenUrlContext = createOpenUrlContext;
|
|
|
10
10
|
exports.createReloadableSite = createReloadableSite;
|
|
11
11
|
const tslib_1 = require("tslib");
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
13
14
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
-
const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
|
|
17
17
|
const getHostPort_1 = require("../../server/getHostPort");
|
|
18
18
|
const site_1 = require("../../server/site");
|
|
19
19
|
const pluginsUtils_1 = require("../../server/plugins/pluginsUtils");
|
|
20
|
+
// This code was historically in CRA/react-dev-utils (deprecated in 2025)
|
|
21
|
+
// We internalized it, refactored and removed useless code paths
|
|
22
|
+
// See https://github.com/facebook/docusaurus/pull/10956
|
|
23
|
+
// See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/WebpackDevServerUtils.js
|
|
24
|
+
function getOpenUrlOrigin(protocol, host, port) {
|
|
25
|
+
const isUnspecifiedHost = host === '0.0.0.0' || host === '::';
|
|
26
|
+
const prettyHost = isUnspecifiedHost ? 'localhost' : host;
|
|
27
|
+
const localUrlForBrowser = url_1.default.format({
|
|
28
|
+
protocol,
|
|
29
|
+
hostname: prettyHost,
|
|
30
|
+
port,
|
|
31
|
+
pathname: '/',
|
|
32
|
+
});
|
|
33
|
+
return localUrlForBrowser;
|
|
34
|
+
}
|
|
20
35
|
async function createOpenUrlContext({ cliOptions, }) {
|
|
21
36
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
22
37
|
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
@@ -24,9 +39,8 @@ async function createOpenUrlContext({ cliOptions, }) {
|
|
|
24
39
|
return process.exit();
|
|
25
40
|
}
|
|
26
41
|
const getOpenUrl = ({ baseUrl, router }) => {
|
|
27
|
-
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
28
42
|
return (0, utils_1.normalizeUrl)([
|
|
29
|
-
|
|
43
|
+
getOpenUrlOrigin(protocol, host, port),
|
|
30
44
|
router === 'hash' ? '/#/' : '',
|
|
31
45
|
baseUrl,
|
|
32
46
|
]);
|
|
@@ -13,7 +13,7 @@ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
|
13
13
|
const bundler_1 = require("@docusaurus/bundler");
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
15
|
const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
|
|
16
|
-
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("
|
|
16
|
+
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("../utils/legacy/evalSourceMapMiddleware"));
|
|
17
17
|
const watcher_1 = require("./watcher");
|
|
18
18
|
const getHttpsConfig_1 = tslib_1.__importDefault(require("../../webpack/utils/getHttpsConfig"));
|
|
19
19
|
const configure_1 = require("../../webpack/configure");
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// TODO Legacy CRA react-dev-utils package code
|
|
9
|
+
// This code was in CRA/react-dev-utils (deprecated in 2025)
|
|
10
|
+
// We just copied the code as-is to remove a fat/useless dependency subtree
|
|
11
|
+
// See https://github.com/facebook/docusaurus/pull/10956
|
|
12
|
+
// See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/evalSourceMapMiddleware.js
|
|
13
|
+
|
|
14
|
+
/* eslint-disable */
|
|
15
|
+
|
|
16
|
+
function base64SourceMap(source) {
|
|
17
|
+
const base64 = Buffer.from(JSON.stringify(source.map()), 'utf8').toString(
|
|
18
|
+
'base64',
|
|
19
|
+
);
|
|
20
|
+
return `data:application/json;charset=utf-8;base64,${base64}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getSourceById(server, id) {
|
|
24
|
+
const module = Array.from(server._stats.compilation.modules).find(
|
|
25
|
+
(m) => server._stats.compilation.chunkGraph.getModuleId(m) == id,
|
|
26
|
+
);
|
|
27
|
+
return module.originalSource();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Middleware responsible for retrieving a generated source
|
|
32
|
+
* Receives a webpack internal url: "webpack-internal:///<module-id>"
|
|
33
|
+
* Returns a generated source: "<source-text><sourceMappingURL><sourceURL>"
|
|
34
|
+
*
|
|
35
|
+
* Based on EvalSourceMapDevToolModuleTemplatePlugin.js
|
|
36
|
+
*
|
|
37
|
+
* @param {import("webpack-dev-server").default} server
|
|
38
|
+
* @returns {import("express").Handler}
|
|
39
|
+
*/
|
|
40
|
+
module.exports = function createEvalSourceMapMiddleware(server) {
|
|
41
|
+
return function handleWebpackInternalMiddleware(req, res, next) {
|
|
42
|
+
if (req.url.startsWith('/__get-internal-source')) {
|
|
43
|
+
const fileName = req.query.fileName;
|
|
44
|
+
const id = fileName.match(/webpack-internal:\/\/\/(.+)/)[1];
|
|
45
|
+
if (!id || !server._stats) {
|
|
46
|
+
next();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const source = getSourceById(server, id);
|
|
50
|
+
const sourceMapURL = `//# sourceMappingURL=${base64SourceMap(source)}`;
|
|
51
|
+
const sourceURL = `//# sourceURL=webpack-internal:///${module.id}`;
|
|
52
|
+
res.end(`${source.source()}\n${sourceMapURL}\n${sourceURL}`);
|
|
53
|
+
} else {
|
|
54
|
+
next();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if it opened a browser
|
|
9
|
+
*/
|
|
10
|
+
export default function openBrowser(url: string): Promise<boolean>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = openBrowser;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
// This code was initially in CRA/react-dev-utils (deprecated in 2025)
|
|
12
|
+
// We copied and refactored it
|
|
13
|
+
// See https://github.com/facebook/docusaurus/pull/10956
|
|
14
|
+
// See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/openBrowser.js
|
|
15
|
+
/* eslint-disable */
|
|
16
|
+
const child_process_1 = require("child_process");
|
|
17
|
+
const open_1 = tslib_1.__importDefault(require("open"));
|
|
18
|
+
// Not sure if we need this, but let's keep a secret escape hatch
|
|
19
|
+
// CRA/react-dev-utils supported BROWSER/BROWSER_ARGS
|
|
20
|
+
const BrowserEnv = process.env.DOCUSAURUS_BROWSER;
|
|
21
|
+
const BrowserEnvArgs = process.env.DOCUSAURUS_BROWSER_ARGS
|
|
22
|
+
? process.env.DOCUSAURUS_BROWSER_ARGS.split(' ')
|
|
23
|
+
: [];
|
|
24
|
+
// If we're on OS X, the user hasn't specifically
|
|
25
|
+
// requested a different browser, we can try opening
|
|
26
|
+
// Chrome with AppleScript. This lets us reuse an
|
|
27
|
+
// existing tab when possible instead of creating a new one.
|
|
28
|
+
// Copied from https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/openBrowser.js
|
|
29
|
+
async function tryOpenWithAppleScript({ url, browser, }) {
|
|
30
|
+
const shouldTryOpenChromiumWithAppleScript = process.platform === 'darwin' &&
|
|
31
|
+
(typeof browser !== 'string' || browser === 'google chrome');
|
|
32
|
+
if (!shouldTryOpenChromiumWithAppleScript) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (shouldTryOpenChromiumWithAppleScript) {
|
|
36
|
+
// Will use the first open browser found from list
|
|
37
|
+
const supportedChromiumBrowsers = [
|
|
38
|
+
'Google Chrome Canary',
|
|
39
|
+
'Google Chrome Dev',
|
|
40
|
+
'Google Chrome Beta',
|
|
41
|
+
'Google Chrome',
|
|
42
|
+
'Microsoft Edge',
|
|
43
|
+
'Brave Browser',
|
|
44
|
+
'Vivaldi',
|
|
45
|
+
'Chromium',
|
|
46
|
+
];
|
|
47
|
+
for (let chromiumBrowser of supportedChromiumBrowsers) {
|
|
48
|
+
try {
|
|
49
|
+
// Try our best to reuse existing tab
|
|
50
|
+
// on OSX Chromium-based browser with AppleScript
|
|
51
|
+
(0, child_process_1.execSync)(`ps cax | grep "${chromiumBrowser}"`);
|
|
52
|
+
(0, child_process_1.execSync)(`osascript openChrome.applescript "${encodeURI(url)}" "${chromiumBrowser}"`, {
|
|
53
|
+
cwd: __dirname,
|
|
54
|
+
stdio: 'ignore',
|
|
55
|
+
});
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// Ignore errors.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function toOpenApp(params) {
|
|
66
|
+
if (!params.browser) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
// Handles "cross-platform" shortcuts like "chrome", "firefox", "edge"
|
|
70
|
+
if (open_1.default.apps[params.browser]) {
|
|
71
|
+
return {
|
|
72
|
+
name: open_1.default.apps[params.browser],
|
|
73
|
+
arguments: params.browserArgs,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Fallback to platform-specific app name
|
|
77
|
+
return {
|
|
78
|
+
name: params.browser,
|
|
79
|
+
arguments: params.browserArgs,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async function startBrowserProcess(params) {
|
|
83
|
+
if (await tryOpenWithAppleScript(params)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
await (0, open_1.default)(params.url, {
|
|
88
|
+
app: toOpenApp(params),
|
|
89
|
+
wait: false,
|
|
90
|
+
});
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns true if it opened a browser
|
|
99
|
+
*/
|
|
100
|
+
async function openBrowser(url) {
|
|
101
|
+
return startBrowserProcess({
|
|
102
|
+
url,
|
|
103
|
+
browser: BrowserEnv,
|
|
104
|
+
browserArgs: BrowserEnvArgs,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
(*
|
|
2
|
+
Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*)
|
|
7
|
+
|
|
8
|
+
property targetTab: null
|
|
9
|
+
property targetTabIndex: -1
|
|
10
|
+
property targetWindow: null
|
|
11
|
+
property theProgram: "Google Chrome"
|
|
12
|
+
|
|
13
|
+
on run argv
|
|
14
|
+
set theURL to item 1 of argv
|
|
15
|
+
|
|
16
|
+
-- Allow requested program to be optional,
|
|
17
|
+
-- default to Google Chrome
|
|
18
|
+
if (count of argv) > 1 then
|
|
19
|
+
set theProgram to item 2 of argv
|
|
20
|
+
end if
|
|
21
|
+
|
|
22
|
+
using terms from application "Google Chrome"
|
|
23
|
+
tell application theProgram
|
|
24
|
+
|
|
25
|
+
if (count every window) = 0 then
|
|
26
|
+
make new window
|
|
27
|
+
end if
|
|
28
|
+
|
|
29
|
+
-- 1: Looking for tab running debugger
|
|
30
|
+
-- then, Reload debugging tab if found
|
|
31
|
+
-- then return
|
|
32
|
+
set found to my lookupTabWithUrl(theURL)
|
|
33
|
+
if found then
|
|
34
|
+
set targetWindow's active tab index to targetTabIndex
|
|
35
|
+
tell targetTab to reload
|
|
36
|
+
tell targetWindow to activate
|
|
37
|
+
set index of targetWindow to 1
|
|
38
|
+
return
|
|
39
|
+
end if
|
|
40
|
+
|
|
41
|
+
-- 2: Looking for Empty tab
|
|
42
|
+
-- In case debugging tab was not found
|
|
43
|
+
-- We try to find an empty tab instead
|
|
44
|
+
set found to my lookupTabWithUrl("chrome://newtab/")
|
|
45
|
+
if found then
|
|
46
|
+
set targetWindow's active tab index to targetTabIndex
|
|
47
|
+
set URL of targetTab to theURL
|
|
48
|
+
tell targetWindow to activate
|
|
49
|
+
return
|
|
50
|
+
end if
|
|
51
|
+
|
|
52
|
+
-- 3: Create new tab
|
|
53
|
+
-- both debugging and empty tab were not found
|
|
54
|
+
-- make a new tab with url
|
|
55
|
+
tell window 1
|
|
56
|
+
activate
|
|
57
|
+
make new tab with properties {URL:theURL}
|
|
58
|
+
end tell
|
|
59
|
+
end tell
|
|
60
|
+
end using terms from
|
|
61
|
+
end run
|
|
62
|
+
|
|
63
|
+
-- Function:
|
|
64
|
+
-- Lookup tab with given url
|
|
65
|
+
-- if found, store tab, index, and window in properties
|
|
66
|
+
-- (properties were declared on top of file)
|
|
67
|
+
on lookupTabWithUrl(lookupUrl)
|
|
68
|
+
using terms from application "Google Chrome"
|
|
69
|
+
tell application theProgram
|
|
70
|
+
-- Find a tab with the given url
|
|
71
|
+
set found to false
|
|
72
|
+
set theTabIndex to -1
|
|
73
|
+
repeat with theWindow in every window
|
|
74
|
+
set theTabIndex to 0
|
|
75
|
+
repeat with theTab in every tab of theWindow
|
|
76
|
+
set theTabIndex to theTabIndex + 1
|
|
77
|
+
if (theTab's URL as string) contains lookupUrl then
|
|
78
|
+
-- assign tab, tab index, and window to properties
|
|
79
|
+
set targetTab to theTab
|
|
80
|
+
set targetTabIndex to theTabIndex
|
|
81
|
+
set targetWindow to theWindow
|
|
82
|
+
set found to true
|
|
83
|
+
exit repeat
|
|
84
|
+
end if
|
|
85
|
+
end repeat
|
|
86
|
+
|
|
87
|
+
if found then
|
|
88
|
+
exit repeat
|
|
89
|
+
end if
|
|
90
|
+
end repeat
|
|
91
|
+
end tell
|
|
92
|
+
end using terms from
|
|
93
|
+
return found
|
|
94
|
+
end lookupTabWithUrl
|
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.7.0-canary-
|
|
4
|
+
"version": "3.7.0-canary-6246",
|
|
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.7.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "3.7.0-canary-
|
|
38
|
-
"@docusaurus/logger": "3.7.0-canary-
|
|
39
|
-
"@docusaurus/mdx-loader": "3.7.0-canary-
|
|
40
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
41
|
-
"@docusaurus/utils-common": "3.7.0-canary-
|
|
42
|
-
"@docusaurus/utils-validation": "3.7.0-canary-
|
|
36
|
+
"@docusaurus/babel": "3.7.0-canary-6246",
|
|
37
|
+
"@docusaurus/bundler": "3.7.0-canary-6246",
|
|
38
|
+
"@docusaurus/logger": "3.7.0-canary-6246",
|
|
39
|
+
"@docusaurus/mdx-loader": "3.7.0-canary-6246",
|
|
40
|
+
"@docusaurus/utils": "3.7.0-canary-6246",
|
|
41
|
+
"@docusaurus/utils-common": "3.7.0-canary-6246",
|
|
42
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6246",
|
|
43
43
|
"boxen": "^6.2.1",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
@@ -52,14 +52,15 @@
|
|
|
52
52
|
"escape-html": "^1.0.3",
|
|
53
53
|
"eta": "^2.2.0",
|
|
54
54
|
"eval": "^0.1.8",
|
|
55
|
+
"execa": "5.1.1",
|
|
55
56
|
"fs-extra": "^11.1.1",
|
|
56
57
|
"html-tags": "^3.3.1",
|
|
57
58
|
"html-webpack-plugin": "^5.6.0",
|
|
58
59
|
"leven": "^3.1.0",
|
|
59
60
|
"lodash": "^4.17.21",
|
|
61
|
+
"open": "^8.4.0",
|
|
60
62
|
"p-map": "^4.0.0",
|
|
61
63
|
"prompts": "^2.4.2",
|
|
62
|
-
"react-dev-utils": "^12.0.1",
|
|
63
64
|
"react-helmet-async": "npm:@slorber/react-helmet-async@1.3.0",
|
|
64
65
|
"react-loadable": "npm:@docusaurus/react-loadable@6.0.0",
|
|
65
66
|
"react-loadable-ssr-addon-v5-slorber": "^1.0.1",
|
|
@@ -68,7 +69,6 @@
|
|
|
68
69
|
"react-router-dom": "^5.3.4",
|
|
69
70
|
"semver": "^7.5.4",
|
|
70
71
|
"serve-handler": "^6.1.6",
|
|
71
|
-
"shelljs": "^0.8.5",
|
|
72
72
|
"tinypool": "^1.0.2",
|
|
73
73
|
"tslib": "^2.6.0",
|
|
74
74
|
"update-notifier": "^6.0.2",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"webpack-merge": "^6.0.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@docusaurus/module-type-aliases": "3.7.0-canary-
|
|
82
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
81
|
+
"@docusaurus/module-type-aliases": "3.7.0-canary-6246",
|
|
82
|
+
"@docusaurus/types": "3.7.0-canary-6246",
|
|
83
83
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
84
84
|
"@types/detect-port": "^1.3.3",
|
|
85
85
|
"@types/react-dom": "^18.2.7",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=18.0"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "6e2458e85cfd031ba2930419774f37e0f0871d67"
|
|
103
103
|
}
|