@docusaurus/core 2.0.0-beta.13 → 2.0.0-beta.15

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.
Files changed (90) hide show
  1. package/bin/beforeCli.js +14 -15
  2. package/bin/docusaurus.js +7 -5
  3. package/lib/babel/preset.d.ts +1 -1
  4. package/lib/choosePort.js +8 -8
  5. package/lib/client/LinksCollector.d.ts +1 -1
  6. package/lib/client/PendingNavigation.d.ts +2 -2
  7. package/lib/client/exports/BrowserOnly.d.ts +1 -1
  8. package/lib/client/exports/BrowserOnly.js +7 -2
  9. package/lib/client/exports/ErrorBoundary.d.ts +1 -1
  10. package/lib/client/exports/ErrorBoundary.js +3 -1
  11. package/lib/client/exports/Interpolate.d.ts +1 -1
  12. package/lib/client/exports/Translate.d.ts +2 -2
  13. package/lib/client/exports/browserContext.d.ts +1 -1
  14. package/lib/client/exports/docusaurusContext.d.ts +2 -2
  15. package/lib/client/exports/useBaseUrl.js +2 -2
  16. package/lib/client/exports/useDocusaurusContext.d.ts +1 -1
  17. package/lib/client/nprogress.css +2 -2
  18. package/lib/client/preload.d.ts +1 -1
  19. package/lib/client/serverEntry.d.ts +10 -0
  20. package/lib/client/serverEntry.js +86 -126
  21. package/lib/commands/build.d.ts +1 -1
  22. package/lib/commands/build.js +17 -15
  23. package/lib/commands/clear.js +10 -11
  24. package/lib/commands/commandUtils.d.ts +1 -1
  25. package/lib/commands/deploy.d.ts +1 -1
  26. package/lib/commands/deploy.js +12 -14
  27. package/lib/commands/external.d.ts +1 -1
  28. package/lib/commands/external.js +1 -1
  29. package/lib/commands/serve.d.ts +1 -1
  30. package/lib/commands/serve.js +2 -8
  31. package/lib/commands/start.d.ts +1 -1
  32. package/lib/commands/start.js +23 -22
  33. package/lib/commands/swizzle.d.ts +1 -1
  34. package/lib/commands/swizzle.js +26 -35
  35. package/lib/commands/writeHeadingIds.d.ts +1 -1
  36. package/lib/commands/writeHeadingIds.js +4 -5
  37. package/lib/commands/writeTranslations.d.ts +2 -2
  38. package/lib/commands/writeTranslations.js +1 -1
  39. package/lib/server/brokenLinks.d.ts +1 -1
  40. package/lib/server/brokenLinks.js +1 -2
  41. package/lib/server/client-modules/index.d.ts +1 -1
  42. package/lib/server/config.d.ts +2 -2
  43. package/lib/server/config.js +5 -2
  44. package/lib/server/configValidation.d.ts +1 -1
  45. package/lib/server/configValidation.js +5 -4
  46. package/lib/server/duplicateRoutes.d.ts +1 -1
  47. package/lib/server/html-tags/index.d.ts +1 -1
  48. package/lib/server/i18n.d.ts +1 -1
  49. package/lib/server/i18n.js +6 -14
  50. package/lib/server/index.d.ts +1 -1
  51. package/lib/server/index.js +26 -15
  52. package/lib/server/loadSetup.d.ts +1 -1
  53. package/lib/server/moduleShorthand.js +11 -7
  54. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  55. package/lib/server/plugins/index.d.ts +1 -1
  56. package/lib/server/plugins/index.js +3 -3
  57. package/lib/server/plugins/init.d.ts +2 -2
  58. package/lib/server/plugins/init.js +10 -9
  59. package/lib/server/plugins/pluginIds.d.ts +1 -1
  60. package/lib/server/presets/index.d.ts +1 -1
  61. package/lib/server/presets/index.js +1 -1
  62. package/lib/server/routes.d.ts +1 -1
  63. package/lib/server/routes.js +1 -2
  64. package/lib/server/themes/alias.d.ts +1 -1
  65. package/lib/server/themes/index.d.ts +1 -1
  66. package/lib/server/translations/translations.d.ts +1 -1
  67. package/lib/server/translations/translations.js +7 -12
  68. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  69. package/lib/server/translations/translationsExtractor.js +123 -92
  70. package/lib/server/utils.d.ts +1 -1
  71. package/lib/server/versions/__tests/index.test.js +6 -5
  72. package/lib/server/versions/index.d.ts +1 -1
  73. package/lib/webpack/base.d.ts +2 -2
  74. package/lib/webpack/client.d.ts +2 -2
  75. package/lib/webpack/client.js +2 -2
  76. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +1 -1
  77. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +1 -1
  78. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  79. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  80. package/lib/webpack/server.d.ts +2 -2
  81. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  82. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  83. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  84. package/lib/webpack/utils.d.ts +4 -4
  85. package/lib/webpack/utils.js +19 -14
  86. package/package.json +22 -22
  87. package/lib/.tsbuildinfo +0 -1
  88. package/lib/client/.tsbuildinfo +0 -1
  89. package/tsconfig.client.json +0 -12
  90. package/tsconfig.json +0 -14
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
10
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
11
  const copy_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("copy-webpack-plugin"));
12
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
13
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
@@ -23,14 +23,16 @@ const CleanWebpackPlugin_1 = (0, tslib_1.__importDefault)(require("../webpack/pl
23
23
  const i18n_1 = require("../server/i18n");
24
24
  const utils_2 = require("@docusaurus/utils");
25
25
  async function build(siteDir, cliOptions = {},
26
- // TODO what's the purpose of this arg ?
26
+ // When running build, we force terminate the process to prevent async
27
+ // operations from never returning. However, if run as part of docusaurus
28
+ // deploy, we have to let deploy finish.
29
+ // See https://github.com/facebook/docusaurus/pull/2496
27
30
  forceTerminate = true) {
28
31
  ['SIGINT', 'SIGTERM'].forEach((sig) => {
29
32
  process.on(sig, () => process.exit());
30
33
  });
31
34
  async function tryToBuildLocale({ locale, isLastLocale, }) {
32
35
  try {
33
- // console.log(chalk.green(`Site successfully built in locale=${locale}`));
34
36
  return await buildLocale({
35
37
  siteDir,
36
38
  locale,
@@ -40,7 +42,7 @@ forceTerminate = true) {
40
42
  });
41
43
  }
42
44
  catch (e) {
43
- console.error(`Unable to build website for locale "${locale}".`);
45
+ logger_1.default.error `Unable to build website for locale name=${locale}.`;
44
46
  throw e;
45
47
  }
46
48
  }
@@ -58,16 +60,15 @@ forceTerminate = true) {
58
60
  }
59
61
  else {
60
62
  if (i18n.locales.length > 1) {
61
- console.log(chalk_1.default.yellow(`\nWebsite will be built for all these locales:
62
- - ${i18n.locales.join('\n- ')}`));
63
+ logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
63
64
  }
64
65
  // We need the default locale to always be the 1st in the list
65
- // If we build it last, it would "erase" the localized sites built in subfolders
66
+ // If we build it last, it would "erase" the localized sites built in sub-folders
66
67
  const orderedLocales = [
67
68
  i18n.defaultLocale,
68
69
  ...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
69
70
  ];
70
- const results = await (0, utils_2.mapAsyncSequencial)(orderedLocales, (locale) => {
71
+ const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
71
72
  const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
72
73
  return tryToBuildLocale({ locale, isLastLocale });
73
74
  });
@@ -78,7 +79,7 @@ exports.default = build;
78
79
  async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
79
80
  process.env.BABEL_ENV = 'production';
80
81
  process.env.NODE_ENV = 'production';
81
- console.log(chalk_1.default.blue(`\n[${locale}] Creating an optimized production build...`));
82
+ logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
82
83
  const props = await (0, server_1.load)(siteDir, {
83
84
  customOutDir: cliOptions.outDir,
84
85
  customConfigFilePath: cliOptions.config,
@@ -92,7 +93,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
92
93
  plugins: [
93
94
  // Remove/clean build folders before building bundles.
94
95
  new CleanWebpackPlugin_1.default({ verbose: false }),
95
- // Visualize size of webpack output files with an interactive zoomable treemap.
96
+ // Visualize size of webpack output files with an interactive zoomable tree map.
96
97
  cliOptions.bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
97
98
  // Generate client manifests file that will be used for server bundle.
98
99
  new react_loadable_ssr_addon_v5_slorber_1.default({
@@ -125,9 +126,9 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
125
126
  clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
126
127
  }
127
128
  if (configureWebpack) {
128
- clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
129
+ clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
129
130
  clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
130
- serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
131
+ serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
131
132
  serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
132
133
  }
133
134
  });
@@ -152,7 +153,8 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
152
153
  if (!plugin.postBuild) {
153
154
  return;
154
155
  }
155
- await plugin.postBuild(props);
156
+ // The plugin may reference `this`. We manually bind it again to prevent any bugs.
157
+ await plugin.postBuild({ ...props, content: plugin.content });
156
158
  }));
157
159
  await (0, brokenLinks_1.handleBrokenLinks)({
158
160
  allCollectedLinks,
@@ -161,9 +163,9 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
161
163
  outDir,
162
164
  baseUrl,
163
165
  });
164
- console.log(`${chalk_1.default.green(`Success!`)} Generated static files in "${chalk_1.default.cyan(path_1.default.relative(process.cwd(), outDir))}".`);
166
+ logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
165
167
  if (isLastLocale) {
166
- console.log(`\nUse ${chalk_1.default.greenBright('`npm run serve`')} command to test your build locally.\n`);
168
+ logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
167
169
  }
168
170
  if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
169
171
  process.exit(0);
@@ -9,18 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
12
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- function removePath(fsPath) {
15
- return fs_extra_1.default
16
- .remove(path_1.default.join(fsPath))
17
- .then(() => {
18
- console.log(chalk_1.default.green(`Successfully removed "${fsPath}" directory.`));
19
- })
20
- .catch((err) => {
21
- console.error(`Could not remove ${fsPath} directory.`);
22
- console.error(err);
23
- });
14
+ async function removePath(fsPath) {
15
+ try {
16
+ fs_extra_1.default.remove(path_1.default.join(fsPath));
17
+ logger_1.default.success `Removed the path=${fsPath} directory.`;
18
+ }
19
+ catch (e) {
20
+ logger_1.default.error `Could not remove path=${fsPath} directory.
21
+ ${e}`;
22
+ }
24
23
  }
25
24
  async function clear(siteDir) {
26
25
  return Promise.all([
@@ -4,6 +4,6 @@
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
- import { HostPortCLIOptions } from '@docusaurus/types';
7
+ import type { HostPortCLIOptions } from '@docusaurus/types';
8
8
  export declare function getCLIOptionHost(hostOption: HostPortCLIOptions['host']): string;
9
9
  export declare function getCLIOptionPort(portOption: HostPortCLIOptions['port'], host: string): Promise<number | null>;
@@ -4,7 +4,7 @@
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
- import { BuildCLIOptions } from '@docusaurus/types';
7
+ import type { BuildCLIOptions } from '@docusaurus/types';
8
8
  export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
9
9
  export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
10
10
  export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
@@ -10,7 +10,7 @@ exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = 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 shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
13
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
13
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
14
  const server_1 = require("../server");
15
15
  const build_1 = (0, tslib_1.__importDefault)(require("./build"));
16
16
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
@@ -25,11 +25,11 @@ function obfuscateGitPass(str) {
25
25
  function shellExecLog(cmd) {
26
26
  try {
27
27
  const result = shelljs_1.default.exec(cmd);
28
- console.log(`${chalk_1.default.cyan('CMD:')} ${obfuscateGitPass(cmd)} ${chalk_1.default.cyan(`(code: ${result.code})`)}`);
28
+ logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.code}`}`;
29
29
  return result;
30
30
  }
31
31
  catch (e) {
32
- console.log(`${chalk_1.default.red('CMD:')} ${obfuscateGitPass(cmd)}`);
32
+ logger_1.default.error `code=${obfuscateGitPass(cmd)}`;
33
33
  throw e;
34
34
  }
35
35
  }
@@ -66,14 +66,12 @@ async function deploy(siteDir, cliOptions = {}) {
66
66
  customOutDir: cliOptions.outDir,
67
67
  });
68
68
  if (typeof siteConfig.trailingSlash === 'undefined') {
69
- console.warn(chalk_1.default.yellow(`
70
- Docusaurus recommendation:
71
- When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
69
+ logger_1.default.warn(`When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
72
70
  Otherwise, GitHub Pages will add an extra trailing slash to your site urls only on direct-access (not when navigation) with a server redirect.
73
71
  This behavior can have SEO impacts and create relative link issues.
74
- `));
72
+ `);
75
73
  }
76
- console.log('Deploy command invoked...');
74
+ logger_1.default.info('Deploy command invoked...');
77
75
  if (!shelljs_1.default.which('git')) {
78
76
  throw new Error('Git not installed or on the PATH!');
79
77
  }
@@ -102,14 +100,14 @@ This behavior can have SEO impacts and create relative link issues.
102
100
  if (!organizationName) {
103
101
  throw new Error(`Missing project organization name. Did you forget to define "organizationName" in ${siteConfigPath}? You may also export it via the ORGANIZATION_NAME environment variable.`);
104
102
  }
105
- console.log(`${chalk_1.default.cyan('organizationName:')} ${organizationName}`);
103
+ logger_1.default.info `organizationName: name=${organizationName}`;
106
104
  const projectName = process.env.PROJECT_NAME ||
107
105
  process.env.CIRCLE_PROJECT_REPONAME ||
108
106
  siteConfig.projectName;
109
107
  if (!projectName) {
110
108
  throw new Error(`Missing project name. Did you forget to define "projectName" in ${siteConfigPath}? You may also export it via the PROJECT_NAME environment variable.`);
111
109
  }
112
- console.log(`${chalk_1.default.cyan('projectName:')} ${projectName}`);
110
+ logger_1.default.info `projectName: name=${projectName}`;
113
111
  // We never deploy on pull request.
114
112
  const isPullRequest = process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
115
113
  if (isPullRequest) {
@@ -129,7 +127,7 @@ Please provide the branch name to deploy to as an environment variable, for exam
129
127
  You can also set the deploymentBranch property in docusaurus.config.js .`);
130
128
  }
131
129
  const deploymentBranch = process.env.DEPLOYMENT_BRANCH || siteConfig.deploymentBranch || 'gh-pages';
132
- console.log(`${chalk_1.default.cyan('deploymentBranch:')} ${deploymentBranch}`);
130
+ logger_1.default.info `deploymentBranch: name=${deploymentBranch}`;
133
131
  const githubHost = process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com';
134
132
  const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort;
135
133
  let deploymentRepoURL;
@@ -141,7 +139,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
141
139
  const gitCredentials = gitPass ? `${gitUser}:${gitPass}` : gitUser;
142
140
  deploymentRepoURL = buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort);
143
141
  }
144
- console.log(`${chalk_1.default.cyan('Remote repo URL:')} ${obfuscateGitPass(deploymentRepoURL)}`);
142
+ logger_1.default.info `Remote repo URL: name=${obfuscateGitPass(deploymentRepoURL)}`;
145
143
  // Check if this is a cross-repo publish.
146
144
  const crossRepoPublish = !sourceRepoUrl.endsWith(`${organizationName}/${projectName}.git`);
147
145
  // We don't allow deploying to the same branch unless it's a cross publish.
@@ -160,7 +158,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
160
158
  // the files in the directory. If the 'clone' command fails, assume that
161
159
  // the deployment branch doesn't exist, and initialize git in an empty
162
160
  // directory, check out a clean deployment branch and add remote.
163
- if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} ${toPath}`).code === 0) {
161
+ if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} "${toPath}"`).code === 0) {
164
162
  shellExecLog('git rm -rf .');
165
163
  }
166
164
  else {
@@ -203,7 +201,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
203
201
  await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
204
202
  }
205
203
  catch (buildError) {
206
- console.error(buildError);
204
+ logger_1.default.error(buildError.message);
207
205
  process.exit(1);
208
206
  }
209
207
  }
@@ -4,5 +4,5 @@
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
- import { Command } from 'commander';
7
+ import type { Command } from 'commander';
8
8
  export default function externalCommand(cli: Command, siteDir: string): Promise<void>;
@@ -12,7 +12,7 @@ const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
12
12
  async function externalCommand(cli, siteDir) {
13
13
  const context = await (0, server_1.loadContext)(siteDir);
14
14
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
15
- const plugins = (0, init_1.default)({ pluginConfigs, context });
15
+ const plugins = await (0, init_1.default)({ pluginConfigs, context });
16
16
  // Plugin Lifecycle - extendCli.
17
17
  plugins.forEach((plugin) => {
18
18
  const { extendCli } = plugin;
@@ -4,5 +4,5 @@
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
- import { ServeCLIOptions } from '@docusaurus/types';
7
+ import type { ServeCLIOptions } from '@docusaurus/types';
8
8
  export default function serve(siteDir: string, cliOptions: ServeCLIOptions): Promise<void>;
@@ -9,8 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const http_1 = (0, tslib_1.__importDefault)(require("http"));
11
11
  const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
12
- const boxen_1 = (0, tslib_1.__importDefault)(require("boxen"));
13
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
12
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
13
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
15
14
  const server_1 = require("../server");
16
15
  const build_1 = (0, tslib_1.__importDefault)(require("./build"));
@@ -54,12 +53,7 @@ async function serve(siteDir, cliOptions) {
54
53
  trailingSlash,
55
54
  });
56
55
  });
57
- console.log((0, boxen_1.default)(chalk_1.default.green(`Serving "${cliOptions.dir}" directory at "${servingUrl + baseUrl}".`), {
58
- borderColor: 'green',
59
- padding: 1,
60
- margin: 1,
61
- align: 'center',
62
- }));
56
+ logger_1.default.success `Serving path=${cliOptions.dir} directory at path=${servingUrl + baseUrl}.`;
63
57
  server.listen(port);
64
58
  }
65
59
  exports.default = serve;
@@ -4,5 +4,5 @@
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
- import { StartCLIOptions } from '@docusaurus/types';
7
+ import type { StartCLIOptions } from '@docusaurus/types';
8
8
  export default function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;
@@ -8,7 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const utils_1 = require("@docusaurus/utils");
11
- const chalk = require("chalk");
11
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
12
12
  const chokidar_1 = (0, tslib_1.__importDefault)(require("chokidar"));
13
13
  const html_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("html-webpack-plugin"));
14
14
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
@@ -27,7 +27,7 @@ const translations_1 = require("../server/translations/translations");
27
27
  async function start(siteDir, cliOptions) {
28
28
  process.env.NODE_ENV = 'development';
29
29
  process.env.BABEL_ENV = 'development';
30
- console.log(chalk.blue('Starting the development server...'));
30
+ logger_1.default.info('Starting the development server...');
31
31
  function loadSite() {
32
32
  return (0, server_1.load)(siteDir, {
33
33
  customConfigFilePath: cliOptions.config,
@@ -46,18 +46,18 @@ async function start(siteDir, cliOptions) {
46
46
  const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
47
47
  const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
48
48
  const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
49
- console.log(chalk.cyanBright(`Docusaurus website is running at "${openUrl}".`));
49
+ logger_1.default.success `Docusaurus website is running at path=${openUrl}.`;
50
50
  // Reload files processing.
51
51
  const reload = (0, lodash_1.debounce)(() => {
52
52
  loadSite()
53
53
  .then(({ baseUrl: newBaseUrl }) => {
54
54
  const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
55
55
  if (newOpenUrl !== openUrl) {
56
- console.log(chalk.cyanBright(`Docusaurus website is running at "${newOpenUrl}".`));
56
+ logger_1.default.success `Docusaurus website is running at path=${newOpenUrl}.`;
57
57
  }
58
58
  })
59
59
  .catch((err) => {
60
- console.error(chalk.red(err.stack));
60
+ logger_1.default.error(err.stack);
61
61
  });
62
62
  }, 500);
63
63
  const { siteConfig, plugins = [] } = props;
@@ -101,7 +101,7 @@ async function start(siteDir, cliOptions) {
101
101
  plugins: [
102
102
  // Generates an `index.html` file with the <script> injected.
103
103
  new html_webpack_plugin_1.default({
104
- template: path_1.default.resolve(__dirname, '../client/templates/index.html.template.ejs'),
104
+ template: path_1.default.resolve(__dirname, '../webpack/templates/index.html.template.ejs'),
105
105
  // So we can define the position where the scripts are injected.
106
106
  inject: false,
107
107
  filename: 'index.html',
@@ -124,8 +124,19 @@ async function start(siteDir, cliOptions) {
124
124
  config, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
125
125
  }
126
126
  });
127
+ const compiler = (0, webpack_1.default)(config);
128
+ if (process.env.E2E_TEST) {
129
+ compiler.hooks.done.tap('done', (stats) => {
130
+ if (stats.hasErrors()) {
131
+ logger_1.default.error('E2E_TEST: Project has compiler errors.');
132
+ process.exit(1);
133
+ }
134
+ logger_1.default.success('E2E_TEST: Project can compile.');
135
+ process.exit(0);
136
+ });
137
+ }
127
138
  // https://webpack.js.org/configuration/dev-server
128
- const devServerConfig = {
139
+ const defaultDevServerConfig = {
129
140
  hot: cliOptions.hotOnly ? 'only' : true,
130
141
  liveReload: false,
131
142
  client: {
@@ -168,24 +179,14 @@ async function start(siteDir, cliOptions) {
168
179
  allowedHosts: 'all',
169
180
  host,
170
181
  port,
171
- onBeforeSetupMiddleware: (devServer) => {
182
+ setupMiddlewares: (middlewares, devServer) => {
172
183
  // This lets us fetch source contents from webpack for the error overlay.
173
- devServer.app.use((0, evalSourceMapMiddleware_1.default)(
174
- // @ts-expect-error: bad types
175
- devServer));
184
+ middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
185
+ return middlewares;
176
186
  },
177
187
  };
178
- const compiler = (0, webpack_1.default)(config);
179
- if (process.env.E2E_TEST) {
180
- compiler.hooks.done.tap('done', (stats) => {
181
- if (stats.hasErrors()) {
182
- console.log('E2E_TEST: Project has compiler errors.');
183
- process.exit(1);
184
- }
185
- console.log('E2E_TEST: Project can compile.');
186
- process.exit(0);
187
- });
188
- }
188
+ // Allow plugin authors to customize/override devServer config
189
+ const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
189
190
  const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
190
191
  devServer.startCallback(() => {
191
192
  if (cliOptions.open) {
@@ -4,6 +4,6 @@
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
- import { PluginConfig } from '@docusaurus/types';
7
+ import type { PluginConfig } from '@docusaurus/types';
8
8
  export declare function getPluginNames(plugins: PluginConfig[]): string[];
9
9
  export default function swizzle(siteDir: string, themeName?: string, componentName?: string, typescript?: boolean, danger?: boolean): Promise<void>;
@@ -8,7 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getPluginNames = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
11
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
12
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
13
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
14
14
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
@@ -82,20 +82,16 @@ function getComponentName(themePath, plugin, danger) {
82
82
  function themeComponents(themePath, plugin) {
83
83
  const components = colorCode(themePath, plugin);
84
84
  if (components.length === 0) {
85
- return `${chalk_1.default.red('No component to swizzle.')}`;
85
+ return 'No component to swizzle.';
86
86
  }
87
- return `
88
- ${chalk_1.default.cyan('Theme components available for swizzle.')}
87
+ return `Theme components available for swizzle.
89
88
 
90
- ${chalk_1.default.green('green =>')} safe: lower breaking change risk
91
- ${chalk_1.default.red('red =>')} unsafe: higher breaking change risk
89
+ ${logger_1.default.green(logger_1.default.bold('green =>'))} safe: lower breaking change risk
90
+ ${logger_1.default.red(logger_1.default.bold('red =>'))} unsafe: higher breaking change risk
92
91
 
93
92
  ${components.join('\n')}
94
93
  `;
95
94
  }
96
- function formattedThemeNames(themeNames) {
97
- return `Themes available for swizzle:\n- ${themeNames.join('\n- ')}`;
98
- }
99
95
  function colorCode(themePath, plugin) {
100
96
  var _a, _b;
101
97
  // support both commonjs and ES style exports
@@ -106,8 +102,8 @@ function colorCode(themePath, plugin) {
106
102
  : [];
107
103
  const [greenComponents, redComponents] = (0, lodash_1.partition)(components, (comp) => allowedComponent.includes(comp));
108
104
  return [
109
- ...greenComponents.map((component) => chalk_1.default.green(`safe: ${component}`)),
110
- ...redComponents.map((component) => chalk_1.default.red(`unsafe: ${component}`)),
105
+ ...greenComponents.map((component) => `${logger_1.default.green(logger_1.default.bold('safe:'))} ${component}`),
106
+ ...redComponents.map((component) => `${logger_1.default.red(logger_1.default.bold('unsafe:'))} ${component}`),
111
107
  ];
112
108
  }
113
109
  async function swizzle(siteDir, themeName, componentName, typescript, danger) {
@@ -115,7 +111,7 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
115
111
  const context = await (0, server_1.loadContext)(siteDir);
116
112
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
117
113
  const pluginNames = getPluginNames(pluginConfigs);
118
- const plugins = (0, init_1.default)({
114
+ const plugins = await (0, init_1.default)({
119
115
  pluginConfigs,
120
116
  context,
121
117
  });
@@ -123,8 +119,8 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
123
119
  ? plugins[index].getTypeScriptThemePath
124
120
  : plugins[index].getThemePath);
125
121
  if (!themeName) {
126
- console.log(formattedThemeNames(themeNames));
127
- process.exit(1);
122
+ logger_1.default.info `Themes available for swizzle: name=${themeNames}`;
123
+ return;
128
124
  }
129
125
  let pluginModule;
130
126
  try {
@@ -137,9 +133,9 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
137
133
  suggestion = name;
138
134
  }
139
135
  });
140
- chalk_1.default.red(`Theme ${themeName} not found. ${suggestion
141
- ? `Did you mean "${suggestion}" ?`
142
- : formattedThemeNames(themeNames)}`);
136
+ logger_1.default.error `Theme name=${themeName} not found. ${suggestion
137
+ ? logger_1.default.interpolate `Did you mean name=${suggestion}?`
138
+ : logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
143
139
  process.exit(1);
144
140
  }
145
141
  let pluginOptions = {};
@@ -166,19 +162,19 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
166
162
  }
167
163
  // support both commonjs and ES style exports
168
164
  const plugin = (_c = pluginModule.default) !== null && _c !== void 0 ? _c : pluginModule;
169
- const pluginInstance = plugin(context, pluginOptions);
165
+ const pluginInstance = await plugin(context, pluginOptions);
170
166
  const themePath = typescript
171
167
  ? (_d = pluginInstance.getTypeScriptThemePath) === null || _d === void 0 ? void 0 : _d.call(pluginInstance)
172
168
  : (_e = pluginInstance.getThemePath) === null || _e === void 0 ? void 0 : _e.call(pluginInstance);
173
169
  if (!themePath) {
174
- console.warn(chalk_1.default.yellow(typescript
175
- ? `${themeName} does not provide TypeScript theme code via "getTypeScriptThemePath()".`
176
- : `${themeName} does not provide any theme code.`));
170
+ logger_1.default.warn(typescript
171
+ ? logger_1.default.interpolate `name=${themeName} does not provide TypeScript theme code via ${'getTypeScriptThemePath()'}.`
172
+ : logger_1.default.interpolate `name=${themeName} does not provide any theme code.`);
177
173
  process.exit(1);
178
174
  }
179
175
  if (!componentName) {
180
- console.warn(themeComponents(themePath, pluginModule));
181
- process.exit(1);
176
+ logger_1.default.info(themeComponents(themePath, pluginModule));
177
+ return;
182
178
  }
183
179
  const components = getComponentName(themePath, pluginModule, Boolean(danger));
184
180
  const formattedComponentName = formatComponentName(componentName);
@@ -199,7 +195,8 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
199
195
  });
200
196
  if (mostSuitableMatch !== componentName) {
201
197
  mostSuitableComponent = mostSuitableMatch;
202
- console.log(chalk_1.default.red(`Component "${componentName}" doesn't exist.`), chalk_1.default.yellow(`"${mostSuitableComponent}" is swizzled instead of "${componentName}".`));
198
+ logger_1.default.error `Component name=${componentName} doesn't exist.`;
199
+ logger_1.default.info `name=${mostSuitableComponent} is swizzled instead of name=${componentName}.`;
203
200
  }
204
201
  }
205
202
  let fromPath = path_1.default.join(themePath, mostSuitableComponent);
@@ -223,23 +220,17 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
223
220
  suggestion = name;
224
221
  }
225
222
  });
226
- console.warn(chalk_1.default.red(`Component ${mostSuitableComponent} not found.`));
227
- console.warn(suggestion
228
- ? `Did you mean "${suggestion}"?`
229
- : `${themeComponents(themePath, pluginModule)}`);
223
+ logger_1.default.error `Component name=${mostSuitableComponent} not found. ${suggestion
224
+ ? logger_1.default.interpolate `Did you mean name=${suggestion} ?`
225
+ : themeComponents(themePath, pluginModule)}`;
230
226
  process.exit(1);
231
227
  }
232
228
  }
233
229
  if (!components.includes(mostSuitableComponent) && !danger) {
234
- console.warn(chalk_1.default.red(`${mostSuitableComponent} is an internal component and has a higher breaking change probability. If you want to swizzle it, use the "--danger" flag.`));
230
+ logger_1.default.error `name=${mostSuitableComponent} is an internal component and has a higher breaking change probability. If you want to swizzle it, use the code=${'--danger'} flag.`;
235
231
  process.exit(1);
236
232
  }
237
233
  await fs_extra_1.default.copy(fromPath, toPath);
238
- const relativeDir = path_1.default.relative(process.cwd(), toPath);
239
- const fromMsg = chalk_1.default.blue(mostSuitableComponent
240
- ? `${themeName} ${chalk_1.default.yellow(mostSuitableComponent)}`
241
- : themeName);
242
- const toMsg = chalk_1.default.cyan(relativeDir);
243
- console.log(`\n${chalk_1.default.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`);
234
+ logger_1.default.success `Copied code=${mostSuitableComponent ? `${themeName} ${mostSuitableComponent}` : themeName} to path=${path_1.default.relative(process.cwd(), toPath)}.`;
244
235
  }
245
236
  exports.default = swizzle;
@@ -4,7 +4,7 @@
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
- import { Slugger } from '@docusaurus/utils';
7
+ import { type Slugger } from '@docusaurus/utils';
8
8
  declare type Options = {
9
9
  maintainCase?: boolean;
10
10
  overwrite?: boolean;
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.transformMarkdownContent = exports.transformMarkdownHeadingLine = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
12
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
13
  const server_1 = require("../server");
14
14
  const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
15
15
  const utils_1 = require("@docusaurus/utils");
@@ -87,7 +87,7 @@ async function transformMarkdownFile(filepath, options) {
87
87
  async function getPathsToWatch(siteDir) {
88
88
  const context = await (0, server_1.loadContext)(siteDir);
89
89
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
90
- const plugins = (0, init_1.default)({
90
+ const plugins = await (0, init_1.default)({
91
91
  pluginConfigs,
92
92
  context,
93
93
  });
@@ -100,11 +100,10 @@ async function writeHeadingIds(siteDir, files, options) {
100
100
  const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
101
101
  const pathsModified = result.filter(Boolean);
102
102
  if (pathsModified.length) {
103
- console.log(chalk_1.default.green(`Heading ids added to Markdown files (${pathsModified.length}/${markdownFiles.length} files):
104
- - ${pathsModified.join('\n- ')}`));
103
+ logger_1.default.success `Heading ids added to Markdown files (number=${`${pathsModified.length}/${markdownFiles.length}`} files): ${pathsModified}`;
105
104
  }
106
105
  else {
107
- console.log(chalk_1.default.yellow(`${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the ${chalk_1.default.cyan('--overwrite')} option.`));
106
+ logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.`;
108
107
  }
109
108
  }
110
109
  exports.default = writeHeadingIds;
@@ -4,8 +4,8 @@
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
- import { ConfigOptions } from '@docusaurus/types';
8
- import { WriteTranslationsOptions } from '../server/translations/translations';
7
+ import type { ConfigOptions } from '@docusaurus/types';
8
+ import { type WriteTranslationsOptions } from '../server/translations/translations';
9
9
  export default function writeTranslations(siteDir: string, options: WriteTranslationsOptions & ConfigOptions & {
10
10
  locale?: string;
11
11
  }): Promise<void>;
@@ -51,7 +51,7 @@ async function writeTranslations(siteDir, options) {
51
51
  locale: options.locale,
52
52
  });
53
53
  const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
54
- const plugins = (0, init_1.default)({
54
+ const plugins = await (0, init_1.default)({
55
55
  pluginConfigs,
56
56
  context,
57
57
  });
@@ -4,7 +4,7 @@
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
- import { RouteConfig, ReportingSeverity } from '@docusaurus/types';
7
+ import type { RouteConfig, ReportingSeverity } from '@docusaurus/types';
8
8
  declare type BrokenLink = {
9
9
  link: string;
10
10
  resolvedLink: string;