@docusaurus/core 0.0.0-4630 → 0.0.0-4631

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 CHANGED
@@ -61,9 +61,9 @@ export default async function beforeCli() {
61
61
  notifier.config.set('lastUpdateCheck', 0);
62
62
  notifier.check();
63
63
  }
64
- } catch (e) {
64
+ } catch (err) {
65
65
  // Do not stop cli if this fails, see https://github.com/facebook/docusaurus/issues/5400
66
- logger.error(e);
66
+ logger.error(err);
67
67
  }
68
68
 
69
69
  /**
package/lib/choosePort.js CHANGED
@@ -55,7 +55,7 @@ function getProcessForPort(port) {
55
55
  const command = getProcessCommand(processId);
56
56
  return logger_1.default.interpolate `code=${command} subdue=${`(pid ${processId})`} in path=${directory}`;
57
57
  }
58
- catch (e) {
58
+ catch {
59
59
  return null;
60
60
  }
61
61
  }
@@ -64,41 +64,33 @@ function getProcessForPort(port) {
64
64
  * to choose another if port is already being used
65
65
  */
66
66
  async function choosePort(host, defaultPort) {
67
- return (0, detect_port_1.default)({ port: defaultPort, hostname: host }).then((port) => new Promise((resolve) => {
67
+ try {
68
+ const port = await (0, detect_port_1.default)({ port: defaultPort, hostname: host });
68
69
  if (port === defaultPort) {
69
- resolve(port);
70
- return;
70
+ return port;
71
71
  }
72
72
  const message = process.platform !== 'win32' && defaultPort < 1024 && !(0, is_root_1.default)()
73
73
  ? `Admin permissions are required to run a server on a port below 1024.`
74
74
  : `Something is already running on port ${defaultPort}.`;
75
- if (isInteractive) {
76
- clearConsole();
77
- const existingProcess = getProcessForPort(defaultPort);
78
- const question = {
79
- type: 'confirm',
80
- name: 'shouldChangePort',
81
- message: logger_1.default.yellow(`${logger_1.default.bold('[WARNING]')} ${message}${existingProcess ? ` Probably:\n ${existingProcess}` : ''}
82
-
83
- Would you like to run the app on another port instead?`),
84
- initial: true,
85
- };
86
- (0, prompts_1.default)(question).then((answer) => {
87
- if (answer.shouldChangePort === true) {
88
- resolve(port);
89
- }
90
- else {
91
- resolve(null);
92
- }
93
- });
94
- }
95
- else {
75
+ if (!isInteractive) {
96
76
  logger_1.default.error(message);
97
- resolve(null);
77
+ return null;
98
78
  }
99
- }), (err) => {
100
- throw new Error(`Could not find an open port at ${host}.
101
- ${`Network error message: "${err.message || err}".`}`);
102
- });
79
+ clearConsole();
80
+ const existingProcess = getProcessForPort(defaultPort);
81
+ const { shouldChangePort } = await (0, prompts_1.default)({
82
+ type: 'confirm',
83
+ name: 'shouldChangePort',
84
+ message: logger_1.default.yellow(`${logger_1.default.bold('[WARNING]')} ${message}${existingProcess ? ` Probably:\n ${existingProcess}` : ''}
85
+
86
+ Would you like to run the app on another port instead?`),
87
+ initial: true,
88
+ });
89
+ return shouldChangePort ? port : null;
90
+ }
91
+ catch (err) {
92
+ logger_1.default.error `Could not find an open port at ${host}.`;
93
+ throw err;
94
+ }
103
95
  }
104
96
  exports.default = choosePort;
@@ -34,16 +34,15 @@ export default async function render(locals) {
34
34
  try {
35
35
  return await doRender(locals);
36
36
  }
37
- catch (e) {
38
- logger.error `Docusaurus Node/SSR could not render static page with path path=${locals.path} because of following error:
39
- ${e.stack}`;
37
+ catch (err) {
38
+ logger.error `Docusaurus server-side rendering could not render static page with path path=${locals.path}.`;
40
39
  const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
41
- if (isNotDefinedErrorRegex.test(e.message)) {
40
+ if (isNotDefinedErrorRegex.test(err.message)) {
42
41
  logger.info `It looks like you are using code that should run on the client-side only.
43
42
  To get around it, try using code=${'<BrowserOnly>'} (path=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (path=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
44
43
  It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
45
44
  }
46
- throw new Error('Server-side rendering fails due to the error above.');
45
+ throw err;
47
46
  }
48
47
  }
49
48
  // Renderer for static-site-generator-webpack-plugin (async rendering).
@@ -110,9 +109,8 @@ async function doRender(locals) {
110
109
  minifyJS: true,
111
110
  });
112
111
  }
113
- catch (e) {
114
- logger.error `Minification of page path=${locals.path} failed because of following error:
115
- ${e.stack}`;
116
- throw e;
112
+ catch (err) {
113
+ logger.error `Minification of page path=${locals.path} failed.`;
114
+ throw err;
117
115
  }
118
116
  }
@@ -41,9 +41,9 @@ forceTerminate = true) {
41
41
  isLastLocale,
42
42
  });
43
43
  }
44
- catch (e) {
44
+ catch (err) {
45
45
  logger_1.default.error `Unable to build website for locale name=${locale}.`;
46
- throw e;
46
+ throw err;
47
47
  }
48
48
  }
49
49
  const context = await (0, server_1.loadContext)(siteDir, {
@@ -19,9 +19,9 @@ async function removePath(entry) {
19
19
  await fs_extra_1.default.remove(entry.path);
20
20
  logger_1.default.success `Removed the ${entry.description} at path=${entry.path}.`;
21
21
  }
22
- catch (e) {
23
- logger_1.default.error `Could not remove the ${entry.description} at path=${entry.path}.
24
- ${e}`;
22
+ catch (err) {
23
+ logger_1.default.error `Could not remove the ${entry.description} at path=${entry.path}.`;
24
+ logger_1.default.error(err);
25
25
  }
26
26
  }
27
27
  async function clear(siteDir) {
@@ -28,9 +28,9 @@ function shellExecLog(cmd) {
28
28
  logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.code}`}`;
29
29
  return result;
30
30
  }
31
- catch (e) {
31
+ catch (err) {
32
32
  logger_1.default.error `code=${obfuscateGitPass(cmd)}`;
33
- throw e;
33
+ throw err;
34
34
  }
35
35
  }
36
36
  function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
@@ -169,8 +169,9 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
169
169
  try {
170
170
  await fs_extra_1.default.copy(fromPath, toPath);
171
171
  }
172
- catch (error) {
173
- throw new Error(`Copying build assets from "${fromPath}" to "${toPath}" failed with error "${error}".`);
172
+ catch (err) {
173
+ logger_1.default.error `Copying build assets from path=${fromPath} to path=${toPath} failed.`;
174
+ throw err;
174
175
  }
175
176
  shellExecLog('git add --all');
176
177
  const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ||
@@ -200,9 +201,9 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
200
201
  try {
201
202
  await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
202
203
  }
203
- catch (buildError) {
204
- logger_1.default.error(buildError.message);
205
- process.exit(1);
204
+ catch (err) {
205
+ logger_1.default.error('Deployment of the build output failed.');
206
+ throw err;
206
207
  }
207
208
  }
208
209
  else {
@@ -25,7 +25,7 @@ async function getExtraSourceCodeFilePaths() {
25
25
  const themeCommonSourceDir = path_1.default.dirname(require.resolve('@docusaurus/theme-common/lib'));
26
26
  return (0, translationsExtractor_1.globSourceCodeFilePaths)([themeCommonSourceDir]);
27
27
  }
28
- catch (e) {
28
+ catch {
29
29
  return []; // User may not use a Docusaurus official theme? Quite unlikely...
30
30
  }
31
31
  }
@@ -98,7 +98,7 @@ async function isExistingFile(filePath) {
98
98
  try {
99
99
  return (await fs_extra_1.default.stat(filePath)).isFile();
100
100
  }
101
- catch (e) {
101
+ catch {
102
102
  return false;
103
103
  }
104
104
  }
@@ -93,7 +93,7 @@ const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, hel
93
93
  });
94
94
  }
95
95
  }
96
- catch (e) { }
96
+ catch { }
97
97
  return value;
98
98
  }, 'siteUrlCustomValidation');
99
99
  // TODO move to @docusaurus/utils-validation
@@ -35,8 +35,9 @@ async function readTranslationFileContent(filePath) {
35
35
  ensureTranslationFileContent(content);
36
36
  return content;
37
37
  }
38
- catch (e) {
39
- throw new Error(`Invalid translation file at ${filePath}.\n${e.message}`);
38
+ catch (err) {
39
+ logger_1.default.error `Invalid translation file at path=${filePath}.`;
40
+ throw err;
40
41
  }
41
42
  }
42
43
  return undefined;
@@ -103,11 +103,9 @@ async function extractSourceCodeFileTranslations(sourceCodeFilePath, babelOption
103
103
  const translations = await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
104
104
  return translations;
105
105
  }
106
- catch (e) {
107
- if (e instanceof Error) {
108
- e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`;
109
- }
110
- throw e;
106
+ catch (err) {
107
+ logger_1.default.error `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}.`;
108
+ throw err;
111
109
  }
112
110
  }
113
111
  exports.extractSourceCodeFileTranslations = extractSourceCodeFileTranslations;
@@ -6,5 +6,4 @@
6
6
  */
7
7
  import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
8
8
  export declare function getPackageJsonVersion(packageJsonPath: string): Promise<string | undefined>;
9
- export declare function getPackageJsonName(packageJsonPath: string): Promise<string | undefined>;
10
9
  export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<DocusaurusPluginVersionInformation>;
@@ -6,15 +6,14 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getPluginVersion = exports.getPackageJsonName = exports.getPackageJsonVersion = void 0;
9
+ exports.getPluginVersion = exports.getPackageJsonVersion = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
12
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  async function getPackageJsonVersion(packageJsonPath) {
14
14
  if (await fs_extra_1.default.pathExists(packageJsonPath)) {
15
15
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
16
- const { version } = require(packageJsonPath);
17
- return typeof version === 'string' ? version : undefined;
16
+ return require(packageJsonPath).version;
18
17
  }
19
18
  return undefined;
20
19
  }
@@ -22,12 +21,10 @@ exports.getPackageJsonVersion = getPackageJsonVersion;
22
21
  async function getPackageJsonName(packageJsonPath) {
23
22
  if (await fs_extra_1.default.pathExists(packageJsonPath)) {
24
23
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
25
- const { name } = require(packageJsonPath);
26
- return typeof name === 'string' ? name : undefined;
24
+ return require(packageJsonPath).name;
27
25
  }
28
26
  return undefined;
29
27
  }
30
- exports.getPackageJsonName = getPackageJsonName;
31
28
  async function getPluginVersion(pluginPath, siteDir) {
32
29
  let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
33
30
  while (potentialPluginPackageJsonDirectory !== '/') {
@@ -134,13 +134,13 @@ class CleanWebpackPlugin {
134
134
  });
135
135
  }
136
136
  }
137
- catch (error) {
138
- const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(error.message);
137
+ catch (err) {
138
+ const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(err.message);
139
139
  if (needsForce) {
140
140
  const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
141
141
  throw new Error(message);
142
142
  }
143
- throw error;
143
+ throw err;
144
144
  }
145
145
  }
146
146
  }
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": "0.0.0-4630",
4
+ "version": "0.0.0-4631",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.17.2",
42
42
  "@babel/runtime-corejs3": "^7.17.2",
43
43
  "@babel/traverse": "^7.17.3",
44
- "@docusaurus/cssnano-preset": "0.0.0-4630",
45
- "@docusaurus/logger": "0.0.0-4630",
46
- "@docusaurus/mdx-loader": "0.0.0-4630",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4631",
45
+ "@docusaurus/logger": "0.0.0-4631",
46
+ "@docusaurus/mdx-loader": "0.0.0-4631",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4630",
49
- "@docusaurus/utils-common": "0.0.0-4630",
50
- "@docusaurus/utils-validation": "0.0.0-4630",
48
+ "@docusaurus/utils": "0.0.0-4631",
49
+ "@docusaurus/utils-common": "0.0.0-4631",
50
+ "@docusaurus/utils-validation": "0.0.0-4631",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.1",
52
52
  "@svgr/webpack": "^6.2.1",
53
53
  "autoprefixer": "^10.4.2",
@@ -105,8 +105,8 @@
105
105
  "webpackbar": "^5.0.2"
106
106
  },
107
107
  "devDependencies": {
108
- "@docusaurus/module-type-aliases": "0.0.0-4630",
109
- "@docusaurus/types": "0.0.0-4630",
108
+ "@docusaurus/module-type-aliases": "0.0.0-4631",
109
+ "@docusaurus/types": "0.0.0-4631",
110
110
  "@types/detect-port": "^1.3.2",
111
111
  "@types/nprogress": "^0.2.0",
112
112
  "@types/react-dom": "^17.0.11",
@@ -126,5 +126,5 @@
126
126
  "engines": {
127
127
  "node": ">=14"
128
128
  },
129
- "gitHead": "aadefa165fdcbb364fd83ca33a18b987b94c28b0"
129
+ "gitHead": "f280d17b332a55e34b33a59274fc584384687d47"
130
130
  }