@docusaurus/core 3.7.0-canary-6245 → 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.
@@ -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("react-dev-utils/openBrowser"));
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
- urls.localUrlForBrowser,
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("react-dev-utils/evalSourceMapMiddleware"));
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,2 @@
1
+ declare function _exports(server: import("webpack-dev-server").default): import("express").Handler;
2
+ export = _exports;
@@ -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-6245",
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-6245",
37
- "@docusaurus/bundler": "3.7.0-canary-6245",
38
- "@docusaurus/logger": "3.7.0-canary-6245",
39
- "@docusaurus/mdx-loader": "3.7.0-canary-6245",
40
- "@docusaurus/utils": "3.7.0-canary-6245",
41
- "@docusaurus/utils-common": "3.7.0-canary-6245",
42
- "@docusaurus/utils-validation": "3.7.0-canary-6245",
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",
@@ -58,9 +58,9 @@
58
58
  "html-webpack-plugin": "^5.6.0",
59
59
  "leven": "^3.1.0",
60
60
  "lodash": "^4.17.21",
61
+ "open": "^8.4.0",
61
62
  "p-map": "^4.0.0",
62
63
  "prompts": "^2.4.2",
63
- "react-dev-utils": "^12.0.1",
64
64
  "react-helmet-async": "npm:@slorber/react-helmet-async@1.3.0",
65
65
  "react-loadable": "npm:@docusaurus/react-loadable@6.0.0",
66
66
  "react-loadable-ssr-addon-v5-slorber": "^1.0.1",
@@ -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-6245",
82
- "@docusaurus/types": "3.7.0-canary-6245",
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": "65621de892b3c3b011c9888712803039301672c9"
102
+ "gitHead": "6e2458e85cfd031ba2930419774f37e0f0871d67"
103
103
  }