@docusaurus/core 2.0.0-beta.20 → 2.0.0-beta.21

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 (66) hide show
  1. package/bin/beforeCli.mjs +6 -4
  2. package/bin/docusaurus.mjs +9 -1
  3. package/lib/babel/preset.js +2 -1
  4. package/lib/client/App.js +5 -5
  5. package/lib/client/ClientLifecyclesDispatcher.js +1 -1
  6. package/lib/client/PendingNavigation.js +3 -1
  7. package/lib/client/SiteMetadataDefaults.js +4 -2
  8. package/lib/client/docusaurus.d.ts +1 -1
  9. package/lib/client/docusaurus.js +1 -1
  10. package/lib/client/exports/ComponentCreator.d.ts +5 -0
  11. package/lib/client/exports/ComponentCreator.js +14 -7
  12. package/lib/client/exports/ErrorBoundary.js +8 -7
  13. package/lib/client/exports/Link.d.ts +1 -1
  14. package/lib/client/exports/Link.js +1 -1
  15. package/lib/client/exports/isInternalUrl.js +1 -1
  16. package/lib/client/exports/useGlobalData.js +0 -3
  17. package/lib/client/prefetch.js +2 -2
  18. package/lib/client/preload.js +1 -3
  19. package/lib/client/serverEntry.js +23 -12
  20. package/lib/client/theme-fallback/Error/index.js +2 -2
  21. package/lib/client/theme-fallback/Loading/index.js +1 -1
  22. package/lib/client/theme-fallback/NotFound/index.js +1 -1
  23. package/lib/commands/build.js +9 -9
  24. package/lib/commands/deploy.js +13 -13
  25. package/lib/commands/serve.d.ts +2 -1
  26. package/lib/commands/serve.js +10 -5
  27. package/lib/commands/start.d.ts +1 -0
  28. package/lib/commands/start.js +6 -6
  29. package/lib/commands/swizzle/actions.js +6 -8
  30. package/lib/commands/swizzle/common.js +1 -1
  31. package/lib/commands/swizzle/components.js +1 -1
  32. package/lib/commands/swizzle/config.js +9 -8
  33. package/lib/commands/swizzle/prompts.js +8 -8
  34. package/lib/commands/swizzle/tables.js +1 -1
  35. package/lib/commands/swizzle/themes.js +3 -3
  36. package/lib/commands/writeHeadingIds.d.ts +1 -1
  37. package/lib/commands/writeHeadingIds.js +1 -1
  38. package/lib/server/brokenLinks.js +4 -4
  39. package/lib/server/config.js +17 -2
  40. package/lib/server/configValidation.d.ts +3 -3
  41. package/lib/server/configValidation.js +6 -5
  42. package/lib/server/getHostPort.js +3 -3
  43. package/lib/server/htmlTags.js +1 -1
  44. package/lib/server/i18n.js +1 -1
  45. package/lib/server/index.js +3 -3
  46. package/lib/server/plugins/configs.js +2 -2
  47. package/lib/server/plugins/index.js +3 -3
  48. package/lib/server/plugins/init.js +4 -4
  49. package/lib/server/plugins/routeConfig.d.ts +1 -1
  50. package/lib/server/plugins/routeConfig.js +2 -2
  51. package/lib/server/plugins/synthetic.js +1 -1
  52. package/lib/server/routes.js +2 -2
  53. package/lib/server/siteMetadata.js +1 -1
  54. package/lib/server/translations/translations.js +1 -1
  55. package/lib/server/translations/translationsExtractor.js +9 -11
  56. package/lib/server/utils.d.ts +1 -1
  57. package/lib/webpack/aliases/index.js +1 -1
  58. package/lib/webpack/base.js +11 -11
  59. package/lib/webpack/client.d.ts +1 -1
  60. package/lib/webpack/client.js +1 -1
  61. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +0 -19
  62. package/lib/webpack/plugins/CleanWebpackPlugin.js +26 -4
  63. package/lib/webpack/server.d.ts +2 -2
  64. package/lib/webpack/server.js +3 -3
  65. package/lib/webpack/utils.js +15 -17
  66. package/package.json +39 -36
@@ -9,13 +9,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.serve = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const http_1 = tslib_1.__importDefault(require("http"));
12
- const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
13
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
16
+ const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
15
17
  const config_1 = require("../server/config");
16
18
  const build_1 = require("./build");
17
19
  const getHostPort_1 = require("../server/getHostPort");
18
- const utils_1 = require("@docusaurus/utils");
19
20
  async function serve(siteDir, cliOptions) {
20
21
  const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
21
22
  let dir = path_1.default.resolve(siteDir, buildDir);
@@ -45,7 +46,7 @@ async function serve(siteDir, cliOptions) {
45
46
  }
46
47
  // Remove baseUrl before calling serveHandler, because /baseUrl/ should
47
48
  // serve /build/index.html, not /build/baseUrl/index.html (does not exist)
48
- req.url = req.url?.replace(baseUrl, '/');
49
+ req.url = req.url.replace(baseUrl, '/');
49
50
  (0, serve_handler_1.default)(req, res, {
50
51
  cleanUrls: true,
51
52
  public: dir,
@@ -53,7 +54,11 @@ async function serve(siteDir, cliOptions) {
53
54
  directoryListing: false,
54
55
  });
55
56
  });
56
- logger_1.default.success `Serving path=${buildDir} directory at url=${servingUrl + baseUrl}.`;
57
+ const url = servingUrl + baseUrl;
58
+ logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
57
59
  server.listen(port);
60
+ if (cliOptions.open && !process.env.CI) {
61
+ (0, openBrowser_1.default)(url);
62
+ }
58
63
  }
59
64
  exports.serve = serve;
@@ -10,5 +10,6 @@ export declare type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions,
10
10
  hotOnly?: boolean;
11
11
  open?: boolean;
12
12
  poll?: boolean | number;
13
+ minify?: boolean;
13
14
  };
14
15
  export declare function start(siteDir: string, cliOptions: Partial<StartCLIOptions>): Promise<void>;
@@ -8,12 +8,12 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.start = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const utils_1 = require("@docusaurus/utils");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
13
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
13
15
  const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
14
16
  const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
15
- const path_1 = tslib_1.__importDefault(require("path"));
16
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
17
17
  const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
18
18
  const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
19
19
  const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
@@ -47,14 +47,14 @@ async function start(siteDir, cliOptions) {
47
47
  const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
48
48
  const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
49
49
  const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
50
- logger_1.default.success `Docusaurus website is running at url=${openUrl}.`;
50
+ logger_1.default.success `Docusaurus website is running at: url=${openUrl}`;
51
51
  // Reload files processing.
52
52
  const reload = lodash_1.default.debounce(() => {
53
53
  loadSite()
54
54
  .then(({ baseUrl: newBaseUrl }) => {
55
55
  const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
56
56
  if (newOpenUrl !== openUrl) {
57
- logger_1.default.success `Docusaurus website is running at url=${newOpenUrl}.`;
57
+ logger_1.default.success `Docusaurus website is running at: url=${newOpenUrl}`;
58
58
  }
59
59
  })
60
60
  .catch((err) => {
@@ -93,7 +93,7 @@ async function start(siteDir, cliOptions) {
93
93
  ...{ pollingOptions },
94
94
  });
95
95
  ['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
96
- let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props), {
96
+ let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
97
97
  watchOptions: {
98
98
  ignored: /node_modules\/(?!@docusaurus)/,
99
99
  poll: cliOptions.poll,
@@ -8,10 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.wrap = exports.eject = exports.getAction = exports.SwizzleActions = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
12
  const path_1 = tslib_1.__importDefault(require("path"));
14
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const prompts_1 = require("./prompts");
17
17
  exports.SwizzleActions = ['wrap', 'eject'];
@@ -43,19 +43,17 @@ async function eject({ siteDir, themePath, componentName, }) {
43
43
  // This should never happen
44
44
  throw new Error(logger_1.default.interpolate `No files to copy from path=${fromPath} with glob code=${globPatternPosix}`);
45
45
  }
46
- const toPath = isDirectory
47
- ? path_1.default.join(siteDir, utils_1.THEME_PATH, componentName)
48
- : path_1.default.join(siteDir, utils_1.THEME_PATH);
46
+ const toPath = path_1.default.join(siteDir, utils_1.THEME_PATH);
49
47
  await fs_extra_1.default.ensureDir(toPath);
50
48
  const createdFiles = await Promise.all(filesToCopy.map(async (sourceFile) => {
51
- const fileName = path_1.default.basename(sourceFile);
52
- const targetFile = path_1.default.join(toPath, fileName);
49
+ const targetFile = path_1.default.join(toPath, path_1.default.relative(themePath, sourceFile));
53
50
  try {
54
51
  const fileContents = await fs_extra_1.default.readFile(sourceFile, 'utf-8');
55
52
  await fs_extra_1.default.outputFile(targetFile, fileContents.trimStart().replace(/^\/\*.+?\*\/\s*/ms, ''));
56
53
  }
57
54
  catch (err) {
58
- throw new Error(logger_1.default.interpolate `Could not copy file from path=${sourceFile} to path=${targetFile}`);
55
+ logger_1.default.error `Could not copy file from path=${sourceFile} to path=${targetFile}`;
56
+ throw err;
59
57
  }
60
58
  return targetFile;
61
59
  }));
@@ -72,8 +70,8 @@ async function wrap({ siteDir, themePath, componentName: themeComponentName, typ
72
70
  const toPath = path_1.default.resolve(siteDir, utils_1.THEME_PATH, wrapperFileName);
73
71
  const content = typescript
74
72
  ? `import React, {ComponentProps} from 'react';
75
- import type ${componentName}Type from '@theme/${themeComponentName}';
76
73
  import ${componentName} from '@theme-${importType}/${themeComponentName}';
74
+ import type ${componentName}Type from '@theme/${themeComponentName}';
77
75
 
78
76
  type Props = ComponentProps<typeof ${componentName}Type>;
79
77
 
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.findClosestValue = exports.findStringIgnoringCase = exports.normalizeOptions = exports.actionStatusSuffix = exports.actionStatusColor = exports.actionStatusLabel = exports.PartiallySafeHint = exports.SwizzleActionsStatuses = exports.SwizzleActions = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const leven_1 = tslib_1.__importDefault(require("leven"));
12
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
+ const leven_1 = tslib_1.__importDefault(require("leven"));
14
14
  exports.SwizzleActions = ['wrap', 'eject'];
15
15
  exports.SwizzleActionsStatuses = [
16
16
  'safe',
@@ -8,10 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getComponentName = exports.getThemeComponents = exports.listComponentNames = exports.readComponentNames = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
12
  const path_1 = tslib_1.__importDefault(require("path"));
14
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const prompts_1 = require("./prompts");
17
17
  const common_1 = require("./common");
@@ -7,20 +7,20 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getThemeSwizzleConfig = exports.normalizeSwizzleConfig = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
10
12
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
13
  const common_1 = require("./common");
12
14
  const themes_1 = require("./themes");
13
15
  function getModuleSwizzleConfig(swizzlePlugin) {
14
- const getSwizzleConfig = swizzlePlugin.plugin.plugin?.getSwizzleConfig ??
15
- swizzlePlugin.plugin.pluginModule?.module.getSwizzleConfig ??
16
- swizzlePlugin.plugin.pluginModule?.module?.getSwizzleConfig;
16
+ const getSwizzleConfig = swizzlePlugin.plugin.plugin.getSwizzleConfig ??
17
+ swizzlePlugin.plugin.pluginModule?.module.getSwizzleConfig;
17
18
  if (getSwizzleConfig) {
18
19
  return getSwizzleConfig();
19
20
  }
20
21
  // TODO deprecate getSwizzleComponentList later
21
- const getSwizzleComponentList = swizzlePlugin.plugin.plugin?.getSwizzleComponentList ??
22
- swizzlePlugin.plugin.pluginModule?.module.getSwizzleComponentList ??
23
- swizzlePlugin.plugin.pluginModule?.module?.getSwizzleComponentList;
22
+ const getSwizzleComponentList = swizzlePlugin.plugin.plugin.getSwizzleComponentList ??
23
+ swizzlePlugin.plugin.pluginModule?.module.getSwizzleComponentList;
24
24
  if (getSwizzleComponentList) {
25
25
  const safeComponents = getSwizzleComponentList() ?? [];
26
26
  const safeComponentConfig = {
@@ -74,8 +74,9 @@ function getThemeSwizzleConfig(themeName, plugins) {
74
74
  try {
75
75
  return normalizeSwizzleConfig(config);
76
76
  }
77
- catch (e) {
78
- throw new Error(`Invalid Swizzle config for theme ${themeName}.\n${e.message}`);
77
+ catch (err) {
78
+ logger_1.default.error `Invalid Swizzle config for theme name=${themeName}.`;
79
+ throw err;
79
80
  }
80
81
  }
81
82
  return FallbackSwizzleConfig;
@@ -13,14 +13,14 @@ const prompts_1 = tslib_1.__importDefault(require("prompts"));
13
13
  const common_1 = require("./common");
14
14
  const ExitTitle = logger_1.default.yellow('[Exit]');
15
15
  async function askThemeName(themeNames) {
16
- const { themeName } = await (0, prompts_1.default)({
16
+ const { themeName } = (await (0, prompts_1.default)({
17
17
  type: 'select',
18
18
  name: 'themeName',
19
19
  message: 'Select a theme to swizzle:',
20
20
  choices: themeNames
21
21
  .map((theme) => ({ title: theme, value: theme }))
22
22
  .concat({ title: ExitTitle, value: '[Exit]' }),
23
- });
23
+ }));
24
24
  if (!themeName || themeName === '[Exit]') {
25
25
  process.exit(0);
26
26
  }
@@ -37,7 +37,7 @@ async function askComponentName(themeComponents) {
37
37
  partiallySafe,
38
38
  })}`;
39
39
  }
40
- const { componentName } = await (0, prompts_1.default)({
40
+ const { componentName } = (await (0, prompts_1.default)({
41
41
  type: 'autocomplete',
42
42
  name: 'componentName',
43
43
  message: `
@@ -57,7 +57,7 @@ ${common_1.PartiallySafeHint} = not safe for all swizzle actions
57
57
  async suggest(input, choices) {
58
58
  return choices.filter((choice) => choice.title.toLowerCase().includes(input.toLowerCase()));
59
59
  },
60
- });
60
+ }));
61
61
  logger_1.default.newLine();
62
62
  if (!componentName || componentName === '[Exit]') {
63
63
  return process.exit(0);
@@ -66,7 +66,7 @@ ${common_1.PartiallySafeHint} = not safe for all swizzle actions
66
66
  }
67
67
  exports.askComponentName = askComponentName;
68
68
  async function askSwizzleDangerousComponent() {
69
- const { switchToDanger } = await (0, prompts_1.default)({
69
+ const { switchToDanger } = (await (0, prompts_1.default)({
70
70
  type: 'select',
71
71
  name: 'switchToDanger',
72
72
  message: `Do you really want to swizzle this unsafe internal component?`,
@@ -78,7 +78,7 @@ async function askSwizzleDangerousComponent() {
78
78
  },
79
79
  { title: ExitTitle, value: '[Exit]' },
80
80
  ],
81
- });
81
+ }));
82
82
  if (typeof switchToDanger === 'undefined' || switchToDanger === '[Exit]') {
83
83
  return process.exit(0);
84
84
  }
@@ -86,7 +86,7 @@ async function askSwizzleDangerousComponent() {
86
86
  }
87
87
  exports.askSwizzleDangerousComponent = askSwizzleDangerousComponent;
88
88
  async function askSwizzleAction(componentConfig) {
89
- const { action } = await (0, prompts_1.default)({
89
+ const { action } = (await (0, prompts_1.default)({
90
90
  type: 'select',
91
91
  name: 'action',
92
92
  message: `Which swizzle action do you want to do?`,
@@ -101,7 +101,7 @@ async function askSwizzleAction(componentConfig) {
101
101
  },
102
102
  { title: ExitTitle, value: '[Exit]' },
103
103
  ],
104
- });
104
+ }));
105
105
  if (typeof action === 'undefined' || action === '[Exit]') {
106
106
  return process.exit(0);
107
107
  }
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.themeComponentsTable = exports.helpTables = void 0;
10
10
  const tslib_1 = require("tslib");
11
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
11
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
13
  const cli_table3_1 = tslib_1.__importDefault(require("cli-table3"));
13
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const actions_1 = require("./actions");
15
15
  const common_1 = require("./common");
16
16
  function tableStatusLabel(status) {
@@ -8,10 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getThemePath = exports.getThemeName = exports.getThemeNames = exports.getPluginByThemeName = exports.pluginToThemeName = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
11
  const path_1 = tslib_1.__importDefault(require("path"));
13
- const leven_1 = tslib_1.__importDefault(require("leven"));
14
12
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const leven_1 = tslib_1.__importDefault(require("leven"));
15
15
  const prompts_1 = require("./prompts");
16
16
  const common_1 = require("./common");
17
17
  function pluginToThemeName(plugin) {
@@ -65,7 +65,7 @@ function handleInvalidThemeName({ themeNameParam, themeNames, }) {
65
65
  : logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
66
66
  return process.exit(1);
67
67
  }
68
- async function validateThemeName({ themeNameParam, themeNames, }) {
68
+ function validateThemeName({ themeNameParam, themeNames, }) {
69
69
  const isValidName = themeNames.includes(themeNameParam);
70
70
  if (!isValidName) {
71
71
  return handleInvalidThemeName({
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type WriteHeadingIDOptions } from '@docusaurus/utils';
8
- export declare function writeHeadingIds(siteDir: string, files: string[], options: WriteHeadingIDOptions): Promise<void>;
8
+ export declare function writeHeadingIds(siteDir: string, files: string[] | undefined, options: WriteHeadingIDOptions): Promise<void>;
@@ -32,7 +32,7 @@ async function transformMarkdownFile(filepath, options) {
32
32
  async function getPathsToWatch(siteDir) {
33
33
  const context = await (0, server_1.loadContext)({ siteDir });
34
34
  const plugins = await (0, init_1.initPlugins)(context);
35
- return plugins.flatMap((plugin) => plugin?.getPathsToWatch?.() ?? []);
35
+ return plugins.flatMap((plugin) => plugin.getPathsToWatch?.() ?? []);
36
36
  }
37
37
  async function writeHeadingIds(siteDir, files, options) {
38
38
  const markdownFiles = await (0, utils_2.safeGlobby)(files ?? (await getPathsToWatch(siteDir)), {
@@ -8,14 +8,14 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.handleBrokenLinks = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const react_router_config_1 = require("react-router-config");
12
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
16
+ const react_router_config_1 = require("react-router-config");
14
17
  const utils_1 = require("@docusaurus/utils");
15
18
  const utils_2 = require("./utils");
16
- const path_1 = tslib_1.__importDefault(require("path"));
17
- const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
18
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
19
19
  // matchRoutes does not support qs/anchors, so we remove it!
20
20
  function onlyPathname(link) {
21
21
  return link.split('#')[0].split('?')[0];
@@ -11,10 +11,25 @@ const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
15
  const utils_1 = require("@docusaurus/utils");
15
16
  const configValidation_1 = require("./configValidation");
17
+ async function findConfig(siteDir) {
18
+ // We could support .mjs, .ts, etc. in the future
19
+ const candidates = ['.js', '.cjs'].map((ext) => utils_1.DEFAULT_CONFIG_FILE_NAME + ext);
20
+ const configPath = await (0, utils_1.findAsyncSequential)(candidates.map((file) => path_1.default.join(siteDir, file)), fs_extra_1.default.pathExists);
21
+ if (!configPath) {
22
+ logger_1.default.error('No config file found.');
23
+ logger_1.default.info `Expected one of:${candidates}
24
+ You can provide a custom config path with the code=${'--config'} option.`;
25
+ throw new Error();
26
+ }
27
+ return configPath;
28
+ }
16
29
  async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
17
- const siteConfigPath = path_1.default.resolve(siteDir, customConfigFilePath ?? utils_1.DEFAULT_CONFIG_FILE_NAME);
30
+ const siteConfigPath = customConfigFilePath
31
+ ? path_1.default.resolve(siteDir, customConfigFilePath)
32
+ : await findConfig(siteDir);
18
33
  if (!(await fs_extra_1.default.pathExists(siteConfigPath))) {
19
34
  throw new Error(`Config file at "${siteConfigPath}" not found.`);
20
35
  }
@@ -22,7 +37,7 @@ async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
22
37
  const loadedConfig = typeof importedConfig === 'function'
23
38
  ? await importedConfig()
24
39
  : await importedConfig;
25
- const siteConfig = (0, configValidation_1.validateConfig)(loadedConfig);
40
+ const siteConfig = (0, configValidation_1.validateConfig)(loadedConfig, path_1.default.relative(siteDir, siteConfigPath));
26
41
  return { siteConfig, siteConfigPath };
27
42
  }
28
43
  exports.loadSiteConfig = loadSiteConfig;
@@ -4,9 +4,9 @@
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 type { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
8
7
  import { Joi } from '@docusaurus/utils-validation';
8
+ import type { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
9
9
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
10
10
  export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories'>;
11
- export declare const ConfigSchema: Joi.ObjectSchema<any>;
12
- export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
11
+ export declare const ConfigSchema: Joi.ObjectSchema<DocusaurusConfig>;
12
+ export declare function validateConfig(config: unknown, siteConfigPath: string): DocusaurusConfig;
@@ -65,7 +65,7 @@ function createPluginSchema(theme) {
65
65
  [function myPlugin() { },options]
66
66
  ],
67
67
  };`;
68
- error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
68
+ error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value ${error.path.reduce((acc, cur) => typeof cur === 'string' ? `${acc}.${cur}` : `${acc}[${cur}]`)}.
69
69
  ${validConfigExample}
70
70
  `;
71
71
  });
@@ -100,7 +100,7 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
100
100
  .default(exports.DEFAULT_I18N_CONFIG);
101
101
  const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, helpers) => {
102
102
  try {
103
- const { pathname } = new URL(value);
103
+ const { pathname } = new URL(String(value));
104
104
  if (pathname !== '/') {
105
105
  helpers.warn('docusaurus.configValidationWarning', {
106
106
  warningMessage: `the url is not supposed to contain a sub-path like '${pathname}', please use the baseUrl field for sub-paths`,
@@ -139,6 +139,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
139
139
  deploymentBranch: utils_validation_1.Joi.string().optional(),
140
140
  customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
141
141
  githubHost: utils_validation_1.Joi.string(),
142
+ githubPort: utils_validation_1.Joi.string(),
142
143
  plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
143
144
  themes: utils_validation_1.Joi.array().items(ThemeSchema).default(exports.DEFAULT_CONFIG.themes),
144
145
  presets: utils_validation_1.Joi.array().items(PresetSchema).default(exports.DEFAULT_CONFIG.presets),
@@ -180,7 +181,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
180
181
  'docusaurus.configValidationWarning': 'Docusaurus config validation warning. Field {#label}: {#warningMessage}',
181
182
  });
182
183
  // TODO move to @docusaurus/utils-validation
183
- function validateConfig(config) {
184
+ function validateConfig(config, siteConfigPath) {
184
185
  const { error, warning, value } = exports.ConfigSchema.validate(config, {
185
186
  abortEarly: false,
186
187
  });
@@ -188,7 +189,7 @@ function validateConfig(config) {
188
189
  if (error) {
189
190
  const unknownFields = error.details.reduce((formattedError, err) => {
190
191
  if (err.type === 'object.unknown') {
191
- return `${formattedError}"${err.path}",`;
192
+ return `${formattedError}"${err.path.reduce((acc, cur) => typeof cur === 'string' ? `${acc}.${cur}` : `${acc}[${cur}]`)}",`;
192
193
  }
193
194
  return formattedError;
194
195
  }, '');
@@ -196,7 +197,7 @@ function validateConfig(config) {
196
197
  ? `${accumulatedErr}${err.message}\n`
197
198
  : accumulatedErr, '');
198
199
  formattedError = unknownFields
199
- ? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/api/docusaurus-config/#customfields`
200
+ ? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${siteConfigPath}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/api/docusaurus-config/#customfields`
200
201
  : formattedError;
201
202
  throw new Error(formattedError);
202
203
  }
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getHostPort = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const child_process_1 = require("child_process");
12
- const detect_port_1 = tslib_1.__importDefault(require("detect-port"));
13
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
+ const detect_port_1 = tslib_1.__importDefault(require("detect-port"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const prompts_1 = tslib_1.__importDefault(require("prompts"));
16
16
  const execOptions = {
@@ -55,14 +55,14 @@ async function choosePort(host, defaultPort) {
55
55
  }
56
56
  clearConsole();
57
57
  const existingProcess = getProcessForPort(defaultPort);
58
- const { shouldChangePort } = await (0, prompts_1.default)({
58
+ const { shouldChangePort } = (await (0, prompts_1.default)({
59
59
  type: 'confirm',
60
60
  name: 'shouldChangePort',
61
61
  message: logger_1.default.yellow(`${logger_1.default.bold('[WARNING]')} ${message}${existingProcess ? ` Probably:\n ${existingProcess}` : ''}
62
62
 
63
63
  Would you like to run the app on another port instead?`),
64
64
  initial: true,
65
- });
65
+ }));
66
66
  return shouldChangePort ? port : null;
67
67
  }
68
68
  catch (err) {
@@ -8,10 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadHtmlTags = void 0;
10
10
  const tslib_1 = require("tslib");
11
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
11
12
  const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
12
13
  const void_1 = tslib_1.__importDefault(require("html-tags/void"));
13
14
  const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
14
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
15
15
  function assertIsHtmlTagObject(val) {
16
16
  if (typeof val !== 'object' || !val) {
17
17
  throw new Error(`"${val}" is not a valid HTML tag object.`);
@@ -8,8 +8,8 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const rtl_detect_1 = require("rtl-detect");
12
11
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
+ const rtl_detect_1 = require("rtl-detect");
13
13
  function getDefaultLocaleLabel(locale) {
14
14
  const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
15
15
  return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.load = exports.loadContext = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const utils_1 = require("@docusaurus/utils");
12
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const utils_1 = require("@docusaurus/utils");
14
14
  const config_1 = require("./config");
15
15
  const clientModules_1 = require("./clientModules");
16
16
  const plugins_1 = require("./plugins");
@@ -90,7 +90,7 @@ DO NOT hand-modify files in this folder because they will be overwritten in the
90
90
  next build. You can clear all build artifacts (including this folder) with the
91
91
  \`docusaurus clear\` command.
92
92
  `);
93
- const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, utils_1.DEFAULT_CONFIG_FILE_NAME, `/*
93
+ const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, `${utils_1.DEFAULT_CONFIG_FILE_NAME}.mjs`, `/*
94
94
  * AUTOGENERATED - DON'T EDIT
95
95
  * Your edits in this file will be overwritten in the next build!
96
96
  * Modify the docusaurus.config.js file at your site's root instead.
@@ -19,7 +19,7 @@ async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
19
19
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
20
20
  const pluginModule = (0, import_fresh_1.default)(pluginPath);
21
21
  return {
22
- plugin: pluginModule?.default ?? pluginModule,
22
+ plugin: pluginModule.default ?? pluginModule,
23
23
  options: {},
24
24
  pluginModule: {
25
25
  path: pluginModuleImport,
@@ -44,7 +44,7 @@ async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
44
44
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
45
45
  const pluginModule = (0, import_fresh_1.default)(pluginPath);
46
46
  return {
47
- plugin: pluginModule?.default ?? pluginModule,
47
+ plugin: pluginModule.default ?? pluginModule,
48
48
  options: pluginConfig[1],
49
49
  pluginModule: {
50
50
  path: pluginModuleImport,
@@ -8,11 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadPlugins = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const utils_1 = require("@docusaurus/utils");
12
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const utils_1 = require("@docusaurus/utils");
13
14
  const init_1 = require("./init");
14
15
  const synthetic_1 = require("./synthetic");
15
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
16
16
  const translations_1 = require("../translations/translations");
17
17
  const routeConfig_1 = require("./routeConfig");
18
18
  /**
@@ -33,7 +33,7 @@ async function loadPlugins(context) {
33
33
  // translation files that the plugin declares.
34
34
  const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
35
35
  const content = await plugin.loadContent?.();
36
- const rawTranslationFiles = (await plugin?.getTranslationFiles?.({ content })) ?? [];
36
+ const rawTranslationFiles = (await plugin.getTranslationFiles?.({ content })) ?? [];
37
37
  const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
38
38
  locale: context.i18n.currentLocale,
39
39
  siteDir: context.siteDir,
@@ -11,15 +11,15 @@ const tslib_1 = require("tslib");
11
11
  const module_1 = require("module");
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
+ const utils_validation_1 = require("@docusaurus/utils-validation");
14
15
  const siteMetadata_1 = require("../siteMetadata");
15
16
  const pluginIds_1 = require("./pluginIds");
16
- const utils_validation_1 = require("@docusaurus/utils-validation");
17
17
  const configs_1 = require("./configs");
18
18
  function getOptionValidationFunction(normalizedPluginConfig) {
19
19
  if (normalizedPluginConfig.pluginModule) {
20
20
  // Support both CommonJS and ES modules
21
- return (normalizedPluginConfig.pluginModule.module?.default?.validateOptions ??
22
- normalizedPluginConfig.pluginModule.module?.validateOptions);
21
+ return (normalizedPluginConfig.pluginModule.module.default?.validateOptions ??
22
+ normalizedPluginConfig.pluginModule.module.validateOptions);
23
23
  }
24
24
  return normalizedPluginConfig.plugin.validateOptions;
25
25
  }
@@ -42,7 +42,7 @@ async function initPlugins(context) {
42
42
  const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
43
43
  async function doGetPluginVersion(normalizedPluginConfig) {
44
44
  if (normalizedPluginConfig.pluginModule?.path) {
45
- const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
45
+ const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule.path);
46
46
  return (0, siteMetadata_1.getPluginVersion)(pluginPath, context.siteDir);
47
47
  }
48
48
  return { type: 'local' };
@@ -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 type { RouteConfig } from '@docusaurus/types';
8
7
  import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
8
+ import type { RouteConfig } from '@docusaurus/types';
9
9
  /** Recursively applies trailing slash config to all nested routes. */
10
10
  export declare function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
11
11
  export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
@@ -38,8 +38,8 @@ function sortConfig(routeConfigs, baseUrl = '/') {
38
38
  }
39
39
  // Higher priority get placed first.
40
40
  if (a.priority || b.priority) {
41
- const priorityA = a.priority || 0;
42
- const priorityB = b.priority || 0;
41
+ const priorityA = a.priority ?? 0;
42
+ const priorityB = b.priority ?? 0;
43
43
  const score = priorityB - priorityA;
44
44
  if (score !== 0) {
45
45
  return score;
@@ -74,7 +74,7 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
74
74
  // processed by content plugins mdx loaders. This works, but a bit
75
75
  // hacky... Not sure there's a way to handle that differently in webpack
76
76
  function getMDXFallbackExcludedPaths() {
77
- const rules = config?.module?.rules;
77
+ const rules = config.module?.rules;
78
78
  return rules.flatMap((rule) => {
79
79
  const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
80
80
  return isMDXRule ? rule.include : [];