@docusaurus/core 3.7.0-canary-6261 → 3.7.0-canary-6263

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.
@@ -8,12 +8,12 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.start = start;
10
10
  const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
11
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
12
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");
16
- async function start(siteDirParam = '.', cliOptions = {}) {
16
+ async function doStart(siteDirParam = '.', cliOptions = {}) {
17
17
  logger_1.default.info('Starting the development server...');
18
18
  // Temporary workaround to unlock the ability to translate the site config
19
19
  // We'll remove it if a better official API can be designed
@@ -44,3 +44,6 @@ async function start(siteDirParam = '.', cliOptions = {}) {
44
44
  await (0, openBrowser_1.default)(reloadableSite.getOpenUrl());
45
45
  }
46
46
  }
47
+ async function start(siteDirParam = '.', cliOptions = {}) {
48
+ return logger_1.PerfLogger.async('CLI start', () => doStart(siteDirParam, cliOptions));
49
+ }
@@ -14,7 +14,10 @@ const tslib_1 = require("tslib");
14
14
  // See https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/openBrowser.js
15
15
  /* eslint-disable */
16
16
  const child_process_1 = require("child_process");
17
+ const util_1 = require("util");
17
18
  const open_1 = tslib_1.__importDefault(require("open"));
19
+ const logger_1 = require("@docusaurus/logger");
20
+ const execPromise = (0, util_1.promisify)(child_process_1.exec);
18
21
  // Not sure if we need this, but let's keep a secret escape hatch
19
22
  // CRA/react-dev-utils supported BROWSER/BROWSER_ARGS
20
23
  const BrowserEnv = process.env.DOCUSAURUS_BROWSER;
@@ -33,30 +36,45 @@ async function tryOpenWithAppleScript({ url, browser, }) {
33
36
  return false;
34
37
  }
35
38
  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) {
39
+ async function getBrowsersToTry() {
40
+ // Will use the first open browser found from list
41
+ const supportedChromiumBrowsers = [
42
+ 'Google Chrome Canary',
43
+ 'Google Chrome Dev',
44
+ 'Google Chrome Beta',
45
+ 'Google Chrome',
46
+ 'Microsoft Edge',
47
+ 'Brave Browser',
48
+ 'Vivaldi',
49
+ 'Chromium',
50
+ ];
51
+ // Among all the supported browsers, retrieves to stdout the active ones
52
+ const command = `ps cax -o command | grep -E "^(${supportedChromiumBrowsers.join('|')})$"`;
53
+ const result = await execPromise(command);
54
+ const activeBrowsers = result.stdout.toString().trim().split('\n');
55
+ // This preserves the initial browser order
56
+ // We open Google Chrome Canary in priority over Google Chrome
57
+ return supportedChromiumBrowsers.filter((b) => activeBrowsers.includes(b));
58
+ }
59
+ async function tryBrowser(browserName) {
48
60
  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}"`, {
61
+ // This command runs the openChrome.applescript (copied from CRA)
62
+ const command = `osascript openChrome.applescript "${encodeURI(url)}" "${browserName}"`;
63
+ await execPromise(command, {
53
64
  cwd: __dirname,
54
- stdio: 'ignore',
55
65
  });
56
66
  return true;
57
67
  }
58
68
  catch (err) {
59
- // Ignore errors.
69
+ console.error(`Failed to open browser ${browserName} with AppleScript`, err);
70
+ return false;
71
+ }
72
+ }
73
+ const browsers = await logger_1.PerfLogger.async('getBrowsersToTry', () => getBrowsersToTry());
74
+ for (let browser of browsers) {
75
+ const success = await logger_1.PerfLogger.async(browser, () => tryBrowser(browser));
76
+ if (success) {
77
+ return true;
60
78
  }
61
79
  }
62
80
  }
@@ -80,7 +98,7 @@ function toOpenApp(params) {
80
98
  };
81
99
  }
82
100
  async function startBrowserProcess(params) {
83
- if (await tryOpenWithAppleScript(params)) {
101
+ if (await logger_1.PerfLogger.async('tryOpenWithAppleScript', () => tryOpenWithAppleScript(params))) {
84
102
  return true;
85
103
  }
86
104
  try {
@@ -16,6 +16,7 @@ const babel_1 = require("@docusaurus/babel");
16
16
  const bundler_1 = require("@docusaurus/bundler");
17
17
  const utils_1 = require("@docusaurus/utils");
18
18
  const aliases_1 = require("./aliases");
19
+ const BundlerCPUProfilerPlugin_1 = require("./plugins/BundlerCPUProfilerPlugin");
19
20
  const CSS_REGEX = /\.css$/i;
20
21
  const CSS_MODULE_REGEX = /\.module\.css$/i;
21
22
  exports.clientDir = path_1.default.join(__dirname, '..', 'client');
@@ -283,6 +284,8 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
283
284
  // for more reasoning
284
285
  ignoreOrder: true,
285
286
  }),
286
- ],
287
+ process.env.DOCUSAURUS_BUNDLER_CPU_PROFILE &&
288
+ new BundlerCPUProfilerPlugin_1.BundlerCPUProfilerPlugin(),
289
+ ].filter(Boolean),
287
290
  };
288
291
  }
@@ -0,0 +1,12 @@
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 type { Compiler } from 'webpack';
8
+ export declare class BundlerCPUProfilerPlugin {
9
+ output: string;
10
+ constructor(output?: string);
11
+ apply(compiler: Compiler): void;
12
+ }
@@ -0,0 +1,41 @@
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.BundlerCPUProfilerPlugin = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const node_inspector_1 = tslib_1.__importDefault(require("node:inspector"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ // Bundle CPU profiling plugin, contributed by the Rspack team
14
+ // Can be opened in https://www.speedscope.app/
15
+ // See also https://github.com/jerrykingxyz/docusaurus/pull/1
16
+ // See also https://github.com/facebook/docusaurus/pull/10985
17
+ class BundlerCPUProfilerPlugin {
18
+ constructor(output) {
19
+ this.output = output ?? './bundler-cpu-profile.json';
20
+ }
21
+ apply(compiler) {
22
+ const session = new node_inspector_1.default.Session();
23
+ session.connect();
24
+ session.post('Profiler.enable');
25
+ session.post('Profiler.start');
26
+ // In dev/watch mode, we restart the profiler before each compilation
27
+ compiler.hooks.watchRun.tapPromise(BundlerCPUProfilerPlugin.name, async () => {
28
+ session.post('Profiler.start');
29
+ });
30
+ compiler.hooks.done.tapPromise(BundlerCPUProfilerPlugin.name, async () => {
31
+ session.post('Profiler.stop', (error, param) => {
32
+ if (error) {
33
+ console.error('Failed to generate JS CPU profile:', error);
34
+ return;
35
+ }
36
+ fs_extra_1.default.writeFile(this.output, JSON.stringify(param.profile)).catch(console.error);
37
+ });
38
+ });
39
+ }
40
+ }
41
+ exports.BundlerCPUProfilerPlugin = BundlerCPUProfilerPlugin;
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-6261",
4
+ "version": "3.7.0-canary-6263",
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-6261",
37
- "@docusaurus/bundler": "3.7.0-canary-6261",
38
- "@docusaurus/logger": "3.7.0-canary-6261",
39
- "@docusaurus/mdx-loader": "3.7.0-canary-6261",
40
- "@docusaurus/utils": "3.7.0-canary-6261",
41
- "@docusaurus/utils-common": "3.7.0-canary-6261",
42
- "@docusaurus/utils-validation": "3.7.0-canary-6261",
36
+ "@docusaurus/babel": "3.7.0-canary-6263",
37
+ "@docusaurus/bundler": "3.7.0-canary-6263",
38
+ "@docusaurus/logger": "3.7.0-canary-6263",
39
+ "@docusaurus/mdx-loader": "3.7.0-canary-6263",
40
+ "@docusaurus/utils": "3.7.0-canary-6263",
41
+ "@docusaurus/utils-common": "3.7.0-canary-6263",
42
+ "@docusaurus/utils-validation": "3.7.0-canary-6263",
43
43
  "boxen": "^6.2.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -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-6261",
82
- "@docusaurus/types": "3.7.0-canary-6261",
81
+ "@docusaurus/module-type-aliases": "3.7.0-canary-6263",
82
+ "@docusaurus/types": "3.7.0-canary-6263",
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": "a93b982c4a8fd345bae11d2d896c5381af5af2b0"
102
+ "gitHead": "f87a715b107175497b8bb2d0ec7b8323c38e1853"
103
103
  }