@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18

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 (200) hide show
  1. package/bin/beforeCli.mjs +133 -0
  2. package/bin/docusaurus.mjs +279 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +31 -43
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +23 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +7 -11
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
  14. package/lib/client/SiteMetadataDefaults.js +19 -0
  15. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  16. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  17. package/lib/client/browserContext.d.ts +11 -0
  18. package/lib/client/browserContext.js +22 -0
  19. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  20. package/lib/client/client-lifecycles-dispatcher.js +6 -10
  21. package/lib/client/clientEntry.js +13 -7
  22. package/lib/client/docusaurus.d.ts +6 -0
  23. package/lib/client/docusaurus.js +16 -25
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +2 -3
  27. package/lib/client/exports/BrowserOnly.js +14 -7
  28. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  29. package/lib/client/exports/ComponentCreator.js +40 -19
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +35 -0
  32. package/lib/client/exports/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -26
  36. package/lib/client/exports/Link.d.ts +11 -5
  37. package/lib/client/exports/Link.js +31 -20
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +8 -5
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +4 -8
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +4 -2
  56. package/lib/client/flat.js +9 -13
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +2 -7
  59. package/lib/client/nprogress.css +2 -2
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +4 -6
  62. package/lib/client/preload.d.ts +3 -2
  63. package/lib/client/preload.js +5 -10
  64. package/lib/client/routeContext.d.ts +13 -0
  65. package/lib/client/routeContext.js +31 -0
  66. package/lib/client/serverEntry.d.ts +10 -0
  67. package/lib/client/serverEntry.js +90 -142
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +43 -0
  70. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  71. package/lib/client/theme-fallback/Layout/index.js +2 -26
  72. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  73. package/lib/client/theme-fallback/Loading/index.js +47 -115
  74. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  75. package/lib/client/theme-fallback/NotFound/index.js +17 -18
  76. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  77. package/lib/client/theme-fallback/Root/index.js +2 -6
  78. package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +1 -1
  81. package/lib/commands/build.js +50 -54
  82. package/lib/commands/clear.d.ts +6 -0
  83. package/lib/commands/clear.js +30 -19
  84. package/lib/commands/commandUtils.d.ts +7 -1
  85. package/lib/commands/commandUtils.js +7 -7
  86. package/lib/commands/deploy.d.ts +1 -1
  87. package/lib/commands/deploy.js +83 -66
  88. package/lib/commands/external.d.ts +2 -2
  89. package/lib/commands/external.js +4 -8
  90. package/lib/commands/serve.d.ts +1 -1
  91. package/lib/commands/serve.js +25 -12
  92. package/lib/commands/start.d.ts +1 -1
  93. package/lib/commands/start.js +96 -87
  94. package/lib/commands/swizzle/actions.d.ts +23 -0
  95. package/lib/commands/swizzle/actions.js +101 -0
  96. package/lib/commands/swizzle/common.d.ts +33 -0
  97. package/lib/commands/swizzle/common.js +56 -0
  98. package/lib/commands/swizzle/components.d.ts +29 -0
  99. package/lib/commands/swizzle/components.js +162 -0
  100. package/lib/commands/swizzle/config.d.ts +10 -0
  101. package/lib/commands/swizzle/config.js +80 -0
  102. package/lib/commands/swizzle/context.d.ts +8 -0
  103. package/lib/commands/swizzle/context.js +28 -0
  104. package/lib/commands/swizzle/index.d.ts +8 -0
  105. package/lib/commands/swizzle/index.js +115 -0
  106. package/lib/commands/swizzle/prompts.d.ts +12 -0
  107. package/lib/commands/swizzle/prompts.js +110 -0
  108. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  109. package/lib/commands/swizzle/tables.js +113 -0
  110. package/lib/commands/swizzle/themes.d.ts +20 -0
  111. package/lib/commands/swizzle/themes.js +106 -0
  112. package/lib/commands/writeHeadingIds.d.ts +2 -6
  113. package/lib/commands/writeHeadingIds.js +19 -76
  114. package/lib/commands/writeTranslations.d.ts +2 -2
  115. package/lib/commands/writeTranslations.js +37 -17
  116. package/lib/index.d.ts +10 -9
  117. package/lib/index.js +20 -19
  118. package/lib/server/brokenLinks.d.ts +4 -17
  119. package/lib/server/brokenLinks.js +64 -52
  120. package/lib/server/client-modules/index.d.ts +2 -2
  121. package/lib/server/client-modules/index.js +4 -3
  122. package/lib/server/config.d.ts +2 -2
  123. package/lib/server/config.js +8 -5
  124. package/lib/server/configValidation.d.ts +4 -2
  125. package/lib/server/configValidation.js +93 -37
  126. package/lib/server/duplicateRoutes.d.ts +1 -3
  127. package/lib/server/duplicateRoutes.js +17 -13
  128. package/lib/server/html-tags/htmlTags.js +7 -8
  129. package/lib/server/html-tags/index.d.ts +2 -3
  130. package/lib/server/html-tags/index.js +3 -4
  131. package/lib/server/i18n.d.ts +2 -3
  132. package/lib/server/i18n.js +27 -48
  133. package/lib/server/index.d.ts +9 -2
  134. package/lib/server/index.js +175 -96
  135. package/lib/server/moduleShorthand.d.ts +9 -0
  136. package/lib/server/moduleShorthand.js +46 -0
  137. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
  138. package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
  139. package/lib/server/plugins/index.d.ts +4 -5
  140. package/lib/server/plugins/index.js +69 -45
  141. package/lib/server/plugins/init.d.ts +15 -5
  142. package/lib/server/plugins/init.js +68 -81
  143. package/lib/server/plugins/pluginIds.d.ts +2 -2
  144. package/lib/server/plugins/pluginIds.js +8 -5
  145. package/lib/server/presets/index.d.ts +3 -3
  146. package/lib/server/presets/index.js +16 -23
  147. package/lib/server/routes.d.ts +3 -5
  148. package/lib/server/routes.js +68 -36
  149. package/lib/server/themes/alias.d.ts +3 -2
  150. package/lib/server/themes/alias.js +24 -13
  151. package/lib/server/themes/index.d.ts +6 -2
  152. package/lib/server/themes/index.js +36 -24
  153. package/lib/server/translations/translations.d.ts +21 -17
  154. package/lib/server/translations/translations.js +33 -54
  155. package/lib/server/translations/translationsExtractor.d.ts +12 -5
  156. package/lib/server/translations/translationsExtractor.js +159 -121
  157. package/lib/server/utils.d.ts +9 -3
  158. package/lib/server/utils.js +7 -9
  159. package/lib/server/versions/index.d.ts +3 -4
  160. package/lib/server/versions/index.js +22 -24
  161. package/lib/webpack/base.d.ts +6 -4
  162. package/lib/webpack/base.js +51 -36
  163. package/lib/webpack/client.d.ts +3 -3
  164. package/lib/webpack/client.js +12 -19
  165. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  166. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  167. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  168. package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
  169. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  170. package/lib/webpack/plugins/LogPlugin.js +4 -5
  171. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  172. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  173. package/lib/webpack/server.d.ts +3 -3
  174. package/lib/webpack/server.js +14 -7
  175. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  176. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  177. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  178. package/lib/webpack/utils.d.ts +15 -30
  179. package/lib/webpack/utils.js +57 -175
  180. package/package.json +77 -70
  181. package/bin/docusaurus.js +0 -326
  182. package/lib/.tsbuildinfo +0 -5732
  183. package/lib/client/.tsbuildinfo +0 -4171
  184. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  185. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  186. package/lib/commands/swizzle.d.ts +0 -9
  187. package/lib/commands/swizzle.js +0 -245
  188. package/lib/constants.d.ts +0 -18
  189. package/lib/constants.js +0 -23
  190. package/lib/server/loadSetup.js +0 -25
  191. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  192. package/lib/server/versions/__fixtures__/package.json +0 -3
  193. package/lib/server/versions/__tests/index.test.js +0 -25
  194. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  195. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  196. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  197. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  198. package/lib/webpack/sharedModuleAliases.js +0 -18
  199. package/tsconfig.client.json +0 -13
  200. package/tsconfig.json +0 -13
package/lib/index.js CHANGED
@@ -6,22 +6,23 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.writeHeadingIds = exports.writeTranslations = exports.clear = exports.serve = exports.externalCommand = exports.deploy = exports.swizzle = exports.start = exports.build = void 0;
10
- var build_1 = require("./commands/build");
11
- Object.defineProperty(exports, "build", { enumerable: true, get: function () { return __importDefault(build_1).default; } });
12
- var start_1 = require("./commands/start");
13
- Object.defineProperty(exports, "start", { enumerable: true, get: function () { return __importDefault(start_1).default; } });
14
- var swizzle_1 = require("./commands/swizzle");
15
- Object.defineProperty(exports, "swizzle", { enumerable: true, get: function () { return __importDefault(swizzle_1).default; } });
16
- var deploy_1 = require("./commands/deploy");
17
- Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return __importDefault(deploy_1).default; } });
18
- var external_1 = require("./commands/external");
19
- Object.defineProperty(exports, "externalCommand", { enumerable: true, get: function () { return __importDefault(external_1).default; } });
20
- var serve_1 = require("./commands/serve");
21
- Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return __importDefault(serve_1).default; } });
22
- var clear_1 = require("./commands/clear");
23
- Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return __importDefault(clear_1).default; } });
24
- var writeTranslations_1 = require("./commands/writeTranslations");
25
- Object.defineProperty(exports, "writeTranslations", { enumerable: true, get: function () { return __importDefault(writeTranslations_1).default; } });
26
- var writeHeadingIds_1 = require("./commands/writeHeadingIds");
27
- Object.defineProperty(exports, "writeHeadingIds", { enumerable: true, get: function () { return __importDefault(writeHeadingIds_1).default; } });
9
+ exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const build_1 = tslib_1.__importDefault(require("./commands/build"));
12
+ exports.build = build_1.default;
13
+ const clear_1 = tslib_1.__importDefault(require("./commands/clear"));
14
+ exports.clear = clear_1.default;
15
+ const deploy_1 = tslib_1.__importDefault(require("./commands/deploy"));
16
+ exports.deploy = deploy_1.default;
17
+ const external_1 = tslib_1.__importDefault(require("./commands/external"));
18
+ exports.externalCommand = external_1.default;
19
+ const serve_1 = tslib_1.__importDefault(require("./commands/serve"));
20
+ exports.serve = serve_1.default;
21
+ const start_1 = tslib_1.__importDefault(require("./commands/start"));
22
+ exports.start = start_1.default;
23
+ const swizzle_1 = tslib_1.__importDefault(require("./commands/swizzle"));
24
+ exports.swizzle = swizzle_1.default;
25
+ const writeHeadingIds_1 = tslib_1.__importDefault(require("./commands/writeHeadingIds"));
26
+ exports.writeHeadingIds = writeHeadingIds_1.default;
27
+ const writeTranslations_1 = tslib_1.__importDefault(require("./commands/writeTranslations"));
28
+ exports.writeTranslations = writeTranslations_1.default;
@@ -4,26 +4,13 @@
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';
8
- declare type BrokenLink = {
9
- link: string;
10
- resolvedLink: string;
11
- };
12
- export declare function getAllBrokenLinks({ allCollectedLinks, routes, }: {
13
- allCollectedLinks: Record<string, string[]>;
14
- routes: RouteConfig[];
15
- }): Record<string, BrokenLink[]>;
16
- export declare function getBrokenLinksErrorMessage(allBrokenLinks: Record<string, BrokenLink[]>): string | undefined;
17
- export declare function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }: {
18
- baseUrl: string;
19
- outDir: string;
20
- allCollectedLinks: Record<string, string[]>;
21
- }): Promise<Record<string, string[]>>;
7
+ import type { RouteConfig, ReportingSeverity } from '@docusaurus/types';
22
8
  export declare function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }: {
23
- allCollectedLinks: Record<string, string[]>;
9
+ allCollectedLinks: {
10
+ [location: string]: string[];
11
+ };
24
12
  onBrokenLinks: ReportingSeverity;
25
13
  routes: RouteConfig[];
26
14
  baseUrl: string;
27
15
  outDir: string;
28
16
  }): Promise<void>;
29
- export {};
@@ -6,57 +6,55 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenLinksErrorMessage = exports.getAllBrokenLinks = void 0;
9
+ exports.handleBrokenLinks = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const react_router_config_1 = require("react-router-config");
12
- const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
13
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
- const lodash_1 = require("lodash");
13
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
15
14
  const utils_1 = require("@docusaurus/utils");
16
15
  const utils_2 = require("./utils");
17
16
  const path_1 = tslib_1.__importDefault(require("path"));
18
- function toReactRouterRoutes(routes) {
19
- // @ts-expect-error: types incompatible???
20
- return routes;
21
- }
17
+ const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
18
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
22
19
  // matchRoutes does not support qs/anchors, so we remove it!
23
20
  function onlyPathname(link) {
24
21
  return link.split('#')[0].split('?')[0];
25
22
  }
26
23
  function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
27
- // ReactRouter is able to support links like ./../somePath
28
- // but matchRoutes does not do this resolving internally
29
- // we must resolve the links before using matchRoutes
30
- // resolvePathname is used internally by ReactRouter
24
+ // ReactRouter is able to support links like ./../somePath but `matchRoutes`
25
+ // does not do this resolution internally. We must resolve the links before
26
+ // using `matchRoutes`. `resolvePathname` is used internally by React Router
31
27
  function resolveLink(link) {
32
- const resolvedLink = resolve_pathname_1.default(onlyPathname(link), pagePath);
28
+ const resolvedLink = (0, utils_1.resolvePathname)(onlyPathname(link), pagePath);
33
29
  return { link, resolvedLink };
34
30
  }
35
31
  function isBrokenLink(link) {
36
32
  const matchedRoutes = [link, decodeURI(link)]
37
- .map((l) => react_router_config_1.matchRoutes(toReactRouterRoutes(routes), l))
33
+ // @ts-expect-error: React router types RouteConfig with an actual React
34
+ // component, but we load route components with string paths.
35
+ // We don't actually access component here, so it's fine.
36
+ .map((l) => (0, react_router_config_1.matchRoutes)(routes, l))
38
37
  .reduce((prev, cur) => prev.concat(cur));
39
38
  return matchedRoutes.length === 0;
40
39
  }
41
40
  return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
42
41
  }
43
- // The route defs can be recursive, and have a parent match-all route
44
- // We don't want to match broken links like /docs/brokenLink against /docs/*
45
- // For this reason, we only consider the "final routes", that do not have subroutes
46
- // We also need to remove the match all 404 route
42
+ /**
43
+ * The route defs can be recursive, and have a parent match-all route. We don't
44
+ * want to match broken links like /docs/brokenLink against /docs/*. For this
45
+ * reason, we only consider the "final routes" that do not have subroutes.
46
+ * We also need to remove the match-all 404 route
47
+ */
47
48
  function filterIntermediateRoutes(routesInput) {
48
49
  const routesWithout404 = routesInput.filter((route) => route.path !== '*');
49
- return utils_2.getAllFinalRoutes(routesWithout404);
50
+ return (0, utils_2.getAllFinalRoutes)(routesWithout404);
50
51
  }
51
52
  function getAllBrokenLinks({ allCollectedLinks, routes, }) {
52
53
  const filteredRoutes = filterIntermediateRoutes(routes);
53
- const allBrokenLinks = lodash_1.mapValues(allCollectedLinks, (pageLinks, pagePath) => {
54
- return getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes });
55
- });
54
+ const allBrokenLinks = lodash_1.default.mapValues(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
56
55
  // remove pages without any broken link
57
- return lodash_1.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
56
+ return lodash_1.default.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
58
57
  }
59
- exports.getAllBrokenLinks = getAllBrokenLinks;
60
58
  function getBrokenLinksErrorMessage(allBrokenLinks) {
61
59
  if (Object.keys(allBrokenLinks).length === 0) {
62
60
  return undefined;
@@ -66,16 +64,20 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
66
64
  return `${brokenLink.link}${showResolvedLink ? ` (resolved as: ${brokenLink.resolvedLink})` : ''}`;
67
65
  }
68
66
  function pageBrokenLinksMessage(pagePath, brokenLinks) {
69
- return `\n- On source page path = ${pagePath}:\n -> linking to ${brokenLinks
67
+ return `
68
+ - On source page path = ${pagePath}:
69
+ -> linking to ${brokenLinks
70
70
  .map(brokenLinkMessage)
71
71
  .join('\n -> linking to ')}`;
72
72
  }
73
- // If there's a broken link appearing very often, it is probably a broken link on the layout!
74
- // Add an additional message in such case to help user figure this out.
75
- // see https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
73
+ /**
74
+ * If there's a broken link appearing very often, it is probably a broken link
75
+ * on the layout. Add an additional message in such case to help user figure
76
+ * this out. See https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
77
+ */
76
78
  function getLayoutBrokenLinksHelpMessage() {
77
- const flatList = lodash_1.flatten(Object.entries(allBrokenLinks).map(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink }))));
78
- const countedBrokenLinks = lodash_1.countBy(flatList, (item) => item.brokenLink.link);
79
+ const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
80
+ const countedBrokenLinks = lodash_1.default.countBy(flatList, (item) => item.brokenLink.link);
79
81
  const FrequencyThreshold = 5; // Is this a good value?
80
82
  const frequentLinks = Object.entries(countedBrokenLinks)
81
83
  .filter(([, count]) => count >= FrequencyThreshold)
@@ -83,51 +85,61 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
83
85
  if (frequentLinks.length === 0) {
84
86
  return '';
85
87
  }
86
- return `\n\nIt looks like some of the broken links we found appear in many pages of your site.\nMaybe those broken links appear on all pages through your site layout?\nWe recommend that you check your theme configuration for such links (particularly, theme navbar and footer).\nFrequent broken links are linking to:\n- ${frequentLinks.join(`\n- `)}\n`;
88
+ return logger_1.default.interpolate `
89
+
90
+ It looks like some of the broken links we found appear in many pages of your site.
91
+ Maybe those broken links appear on all pages through your site layout?
92
+ We recommend that you check your theme configuration for such links (particularly, theme navbar and footer).
93
+ Frequent broken links are linking to:${frequentLinks}`;
87
94
  }
88
- return (`Docusaurus found broken links!\n\nPlease check the pages of your site in the list below, and make sure you don't reference any path that does not exist.\nNote: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}` +
89
- `\n\nExhaustive list of all broken links found:\n${Object.entries(allBrokenLinks)
90
- .map(([pagePath, brokenLinks]) => pageBrokenLinksMessage(pagePath, brokenLinks))
91
- .join('\n')}
92
- `);
95
+ return `Docusaurus found broken links!
96
+
97
+ Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
98
+ Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}
99
+
100
+ Exhaustive list of all broken links found:
101
+ ${Object.entries(allBrokenLinks)
102
+ .map(([pagePath, brokenLinks]) => pageBrokenLinksMessage(pagePath, brokenLinks))
103
+ .join('\n')}
104
+ `;
93
105
  }
94
- exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
95
- function isExistingFile(filePath) {
106
+ async function isExistingFile(filePath) {
96
107
  try {
97
- return fs_extra_1.default.statSync(filePath).isFile();
108
+ return (await fs_extra_1.default.stat(filePath)).isFile();
98
109
  }
99
- catch (e) {
110
+ catch {
100
111
  return false;
101
112
  }
102
113
  }
103
114
  // If a file actually exist on the file system, we know the link is valid
104
115
  // even if docusaurus does not know about this file, so we don't report it
105
116
  async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
106
- // not easy to make this async :'(
107
- function linkFileExists(link) {
117
+ async function linkFileExists(link) {
108
118
  // /baseUrl/javadoc/ -> /outDir/javadoc
109
- const baseFilePath = utils_1.removeSuffix(`${outDir}/${utils_1.removePrefix(link, baseUrl)}`, '/');
119
+ const baseFilePath = onlyPathname((0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/'));
110
120
  // -> /outDir/javadoc
111
121
  // -> /outDir/javadoc.html
112
122
  // -> /outDir/javadoc/index.html
113
123
  const filePathsToTry = [baseFilePath];
114
124
  if (!path_1.default.extname(baseFilePath)) {
115
- filePathsToTry.push(`${baseFilePath}.html`);
116
- filePathsToTry.push(path_1.default.join(baseFilePath, 'index.html'));
125
+ filePathsToTry.push(`${baseFilePath}.html`, path_1.default.join(baseFilePath, 'index.html'));
117
126
  }
118
- return filePathsToTry.some(isExistingFile);
127
+ for (const file of filePathsToTry) {
128
+ if (await isExistingFile(file)) {
129
+ return true;
130
+ }
131
+ }
132
+ return false;
119
133
  }
120
- return lodash_1.mapValues(allCollectedLinks, (links) => {
121
- return links.filter((link) => !linkFileExists(link));
122
- });
134
+ return (0, combine_promises_1.default)(lodash_1.default.mapValues(allCollectedLinks, async (links) => (await Promise.all(links.map(async (link) => ((await linkFileExists(link)) ? '' : link)))).filter(Boolean)));
123
135
  }
124
- exports.filterExistingFileLinks = filterExistingFileLinks;
125
136
  async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
126
137
  if (onBrokenLinks === 'ignore') {
127
138
  return;
128
139
  }
129
- // If we link to a file like /myFile.zip, and the file actually exist for the file system
130
- // it is not a broken link, it may simply be a link to an existing static file...
140
+ // If we link to a file like /myFile.zip, and the file actually exist for the
141
+ // file system. It is not a broken link, it may simply be a link to an
142
+ // existing static file...
131
143
  const allCollectedLinksFiltered = await filterExistingFileLinks({
132
144
  allCollectedLinks,
133
145
  baseUrl,
@@ -139,7 +151,7 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
139
151
  });
140
152
  const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
141
153
  if (errorMessage) {
142
- utils_1.reportMessage(errorMessage, onBrokenLinks);
154
+ (0, utils_1.reportMessage)(errorMessage, onBrokenLinks);
143
155
  }
144
156
  }
145
157
  exports.handleBrokenLinks = handleBrokenLinks;
@@ -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 { Plugin } from '@docusaurus/types';
8
- export default function loadClientModules(plugins: Plugin<unknown>[]): string[];
7
+ import type { LoadedPlugin } from '@docusaurus/types';
8
+ export default function loadClientModules(plugins: LoadedPlugin<unknown>[]): string[];
@@ -6,9 +6,10 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ const tslib_1 = require("tslib");
10
+ const path_1 = tslib_1.__importDefault(require("path"));
9
11
  function loadClientModules(plugins) {
10
- return [].concat(...plugins
11
- .map((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; })
12
- .filter(Boolean));
12
+ return plugins.flatMap((plugin) => plugin.getClientModules?.().map((p) => path_1.default.resolve(plugin.path, p)) ??
13
+ []);
13
14
  }
14
15
  exports.default = loadClientModules;
@@ -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 { DocusaurusConfig } from '@docusaurus/types';
8
- export default function loadConfig(configPath: string): DocusaurusConfig;
7
+ import type { DocusaurusConfig } from '@docusaurus/types';
8
+ export default function loadConfig(configPath: string): Promise<DocusaurusConfig>;
@@ -10,11 +10,14 @@ const tslib_1 = require("tslib");
10
10
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
11
  const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
12
12
  const configValidation_1 = require("./configValidation");
13
- function loadConfig(configPath) {
14
- if (!fs_extra_1.default.existsSync(configPath)) {
15
- throw new Error(`Config file "${configPath}" not found`);
13
+ async function loadConfig(configPath) {
14
+ if (!(await fs_extra_1.default.pathExists(configPath))) {
15
+ throw new Error(`Config file at "${configPath}" not found.`);
16
16
  }
17
- const loadedConfig = import_fresh_1.default(configPath);
18
- return configValidation_1.validateConfig(loadedConfig);
17
+ const importedConfig = (0, import_fresh_1.default)(configPath);
18
+ const loadedConfig = typeof importedConfig === 'function'
19
+ ? await importedConfig()
20
+ : await importedConfig;
21
+ return (0, configValidation_1.validateConfig)(loadedConfig);
19
22
  }
20
23
  exports.default = loadConfig;
@@ -4,7 +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 { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
7
+ import type { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
8
+ import { Joi } from '@docusaurus/utils-validation';
8
9
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
9
- export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner'>;
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>;
10
12
  export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
@@ -6,8 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.validateConfig = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
- const constants_1 = require("../constants");
9
+ exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
+ const utils_1 = require("@docusaurus/utils");
11
11
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
12
  const DEFAULT_I18N_LOCALE = 'en';
13
13
  exports.DEFAULT_I18N_CONFIG = {
@@ -23,23 +23,39 @@ exports.DEFAULT_CONFIG = {
23
23
  plugins: [],
24
24
  themes: [],
25
25
  presets: [],
26
+ stylesheets: [],
27
+ scripts: [],
28
+ clientModules: [],
26
29
  customFields: {},
27
30
  themeConfig: {},
28
31
  titleDelimiter: '|',
29
32
  noIndex: false,
33
+ tagline: '',
30
34
  baseUrlIssueBanner: true,
35
+ staticDirectories: [utils_1.DEFAULT_STATIC_DIR_NAME],
31
36
  };
32
- const PluginSchema = utils_validation_1.Joi.alternatives()
33
- .try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array().ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required()), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
34
- .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
35
- .length(2), utils_validation_1.Joi.bool().equal(false))
36
- // TODO isn't there a simpler way to customize the default Joi error message???
37
- // Not sure why Joi makes it complicated to add a custom error message...
38
- // See https://stackoverflow.com/a/54657686/82609
39
- .error((errors) => {
40
- errors.forEach((error) => {
41
- error.message = ` => Bad Docusaurus plugin value as path [${error.path}].
42
- Example valid plugin config:
37
+ function createPluginSchema(theme) {
38
+ return (utils_validation_1.Joi.alternatives()
39
+ .try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array()
40
+ .ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required())
41
+ .length(2), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
42
+ .ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
43
+ .length(2), utils_validation_1.Joi.bool().equal(false))
44
+ // @ts-expect-error: bad lib def, doesn't recognize an array of reports
45
+ .error((errors) => {
46
+ errors.forEach((error) => {
47
+ const validConfigExample = theme
48
+ ? `Example valid theme config:
49
+ {
50
+ themes: [
51
+ ["@docusaurus/theme-classic",options],
52
+ "./myTheme",
53
+ ["./myTheme",{someOption: 42}],
54
+ function myTheme() { },
55
+ [function myTheme() { },options]
56
+ ],
57
+ };`
58
+ : `Example valid plugin config:
43
59
  {
44
60
  plugins: [
45
61
  ["@docusaurus/plugin-content-docs",options],
@@ -48,15 +64,28 @@ Example valid plugin config:
48
64
  function myPlugin() { },
49
65
  [function myPlugin() { },options]
50
66
  ],
51
- };
67
+ };`;
68
+ error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
69
+ ${validConfigExample}
52
70
  `;
53
- });
54
- return errors;
71
+ });
72
+ return errors;
73
+ }));
74
+ }
75
+ const PluginSchema = createPluginSchema(false);
76
+ const ThemeSchema = createPluginSchema(true);
77
+ const PresetSchema = utils_validation_1.Joi.alternatives()
78
+ .try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
79
+ .items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
80
+ .length(2))
81
+ .messages({
82
+ 'alternatives.types': `{#label} does not look like a valid preset config. A preset config entry should be one of:
83
+ - A tuple of [presetName, options], like \`["classic", \\{ blog: false \\}]\`, or
84
+ - A simple string, like \`"classic"\``,
55
85
  });
56
- const ThemeSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required()).length(2));
57
- const PresetSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required()).length(2));
58
86
  const LocaleConfigSchema = utils_validation_1.Joi.object({
59
87
  label: utils_validation_1.Joi.string(),
88
+ htmlLang: utils_validation_1.Joi.string(),
60
89
  direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
61
90
  });
62
91
  const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
@@ -68,16 +97,29 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
68
97
  })
69
98
  .optional()
70
99
  .default(exports.DEFAULT_I18N_CONFIG);
100
+ const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, helpers) => {
101
+ try {
102
+ const { pathname } = new URL(value);
103
+ if (pathname !== '/') {
104
+ helpers.warn('docusaurus.configValidationWarning', {
105
+ warningMessage: `the url is not supposed to contain a sub-path like '${pathname}', please use the baseUrl field for sub-paths`,
106
+ });
107
+ }
108
+ }
109
+ catch { }
110
+ return value;
111
+ }, 'siteUrlCustomValidation');
71
112
  // TODO move to @docusaurus/utils-validation
72
- const ConfigSchema = utils_validation_1.Joi.object({
113
+ exports.ConfigSchema = utils_validation_1.Joi.object({
73
114
  baseUrl: utils_validation_1.Joi.string()
74
115
  .required()
75
- .regex(new RegExp('/$', 'm'))
76
- .message('{{#label}} must be a string with a trailing `/`'),
116
+ .regex(/\/$/m)
117
+ .message('{{#label}} must be a string with a trailing slash.'),
77
118
  baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
78
- favicon: utils_validation_1.Joi.string().required(),
119
+ favicon: utils_validation_1.Joi.string().optional(),
79
120
  title: utils_validation_1.Joi.string().required(),
80
- url: utils_validation_1.URISchema.required(),
121
+ url: SiteUrlSchema,
122
+ trailingSlash: utils_validation_1.Joi.boolean(),
81
123
  i18n: I18N_CONFIG_SCHEMA,
82
124
  onBrokenLinks: utils_validation_1.Joi.string()
83
125
  .equal('ignore', 'log', 'warn', 'error', 'throw')
@@ -89,27 +131,43 @@ const ConfigSchema = utils_validation_1.Joi.object({
89
131
  .equal('ignore', 'log', 'warn', 'error', 'throw')
90
132
  .default(exports.DEFAULT_CONFIG.onDuplicateRoutes),
91
133
  organizationName: utils_validation_1.Joi.string().allow(''),
134
+ staticDirectories: utils_validation_1.Joi.array()
135
+ .items(utils_validation_1.Joi.string())
136
+ .default(exports.DEFAULT_CONFIG.staticDirectories),
92
137
  projectName: utils_validation_1.Joi.string().allow(''),
138
+ deploymentBranch: utils_validation_1.Joi.string().optional(),
93
139
  customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
94
140
  githubHost: utils_validation_1.Joi.string(),
95
141
  plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
96
142
  themes: utils_validation_1.Joi.array().items(ThemeSchema).default(exports.DEFAULT_CONFIG.themes),
97
143
  presets: utils_validation_1.Joi.array().items(PresetSchema).default(exports.DEFAULT_CONFIG.presets),
98
144
  themeConfig: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.themeConfig),
99
- scripts: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
145
+ scripts: utils_validation_1.Joi.array()
146
+ .items(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
100
147
  src: utils_validation_1.Joi.string().required(),
101
148
  async: utils_validation_1.Joi.bool(),
102
149
  defer: utils_validation_1.Joi.bool(),
103
150
  })
104
151
  // See https://github.com/facebook/docusaurus/issues/3378
105
- .unknown()),
152
+ .unknown())
153
+ .messages({
154
+ 'array.includes': '{#label} is invalid. A script must be a plain string (the src), or an object with at least a "src" property.',
155
+ })
156
+ .default(exports.DEFAULT_CONFIG.scripts),
106
157
  ssrTemplate: utils_validation_1.Joi.string(),
107
- stylesheets: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
158
+ stylesheets: utils_validation_1.Joi.array()
159
+ .items(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
108
160
  href: utils_validation_1.Joi.string().required(),
109
- type: utils_validation_1.Joi.string().required(),
110
- }).unknown()),
111
- clientModules: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
112
- tagline: utils_validation_1.Joi.string().allow(''),
161
+ type: utils_validation_1.Joi.string(),
162
+ }).unknown())
163
+ .messages({
164
+ 'array.includes': '{#label} is invalid. A stylesheet must be a plain string (the href), or an object with at least a "href" property.',
165
+ })
166
+ .default(exports.DEFAULT_CONFIG.stylesheets),
167
+ clientModules: utils_validation_1.Joi.array()
168
+ .items(utils_validation_1.Joi.string())
169
+ .default(exports.DEFAULT_CONFIG.clientModules),
170
+ tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
113
171
  titleDelimiter: utils_validation_1.Joi.string().default('|'),
114
172
  noIndex: utils_validation_1.Joi.bool().default(false),
115
173
  webpack: utils_validation_1.Joi.object({
@@ -117,18 +175,16 @@ const ConfigSchema = utils_validation_1.Joi.object({
117
175
  .try(utils_validation_1.Joi.string().equal('babel'), utils_validation_1.Joi.function())
118
176
  .optional(),
119
177
  }).optional(),
178
+ }).messages({
179
+ 'docusaurus.configValidationWarning': 'Docusaurus config validation warning. Field {#label}: {#warningMessage}',
120
180
  });
121
181
  // TODO move to @docusaurus/utils-validation
122
182
  function validateConfig(config) {
123
- const { error, value } = ConfigSchema.validate(config, {
183
+ const { error, warning, value } = exports.ConfigSchema.validate(config, {
124
184
  abortEarly: false,
125
185
  });
186
+ (0, utils_validation_1.printWarning)(warning);
126
187
  if (error) {
127
- utils_validation_1.logValidationBugReportHint();
128
- if (utils_validation_1.isValidationDisabledEscapeHatch) {
129
- console.error(error);
130
- return config;
131
- }
132
188
  const unknownFields = error.details.reduce((formattedError, err) => {
133
189
  if (err.type === 'object.unknown') {
134
190
  return `${formattedError}"${err.path}",`;
@@ -139,7 +195,7 @@ function validateConfig(config) {
139
195
  ? `${accumulatedErr}${err.message}\n`
140
196
  : accumulatedErr, '');
141
197
  formattedError = unknownFields
142
- ? `${formattedError}These field(s) [${unknownFields}] are not recognized in ${constants_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the 'customFields' attribute.\nSee https://docusaurus.io/docs/docusaurus.config.js/#customfields`
198
+ ? `${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/docusaurus.config.js/#customfields`
143
199
  : formattedError;
144
200
  throw new Error(formattedError);
145
201
  }
@@ -4,7 +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 { ReportingSeverity, RouteConfig } from '@docusaurus/types';
8
- export declare function getAllDuplicateRoutes(pluginsRouteConfigs: RouteConfig[]): string[];
9
- export declare function getDuplicateRoutesMessage(allDuplicateRoutes: string[]): string;
7
+ import type { ReportingSeverity, RouteConfig } from '@docusaurus/types';
10
8
  export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
@@ -1,29 +1,31 @@
1
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
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getAllDuplicateRoutes = void 0;
9
+ exports.handleDuplicateRoutes = void 0;
4
10
  const utils_1 = require("@docusaurus/utils");
5
11
  const utils_2 = require("./utils");
6
12
  function getAllDuplicateRoutes(pluginsRouteConfigs) {
7
- const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
8
- const seenRoutes = {};
13
+ const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
14
+ const seenRoutes = new Set();
9
15
  return allRoutes.filter((route) => {
10
- if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
16
+ if (seenRoutes.has(route)) {
11
17
  return true;
12
18
  }
13
- else {
14
- seenRoutes[route] = true;
15
- return false;
16
- }
19
+ seenRoutes.add(route);
20
+ return false;
17
21
  });
18
22
  }
19
- exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
20
23
  function getDuplicateRoutesMessage(allDuplicateRoutes) {
21
24
  const message = allDuplicateRoutes
22
- .map((duplicateRoute) => `Attempting to create page at ${duplicateRoute}, but a page already exists at this route`)
25
+ .map((duplicateRoute) => `- Attempting to create page at ${duplicateRoute}, but a page already exists at this route.`)
23
26
  .join('\n');
24
27
  return message;
25
28
  }
26
- exports.getDuplicateRoutesMessage = getDuplicateRoutesMessage;
27
29
  function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
28
30
  if (onDuplicateRoutes === 'ignore') {
29
31
  return;
@@ -31,8 +33,10 @@ function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
31
33
  const duplicatePaths = getAllDuplicateRoutes(pluginsRouteConfigs);
32
34
  const message = getDuplicateRoutesMessage(duplicatePaths);
33
35
  if (message) {
34
- const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
35
- utils_1.reportMessage(finalMessage, onDuplicateRoutes);
36
+ const finalMessage = `Duplicate routes found!
37
+ ${message}
38
+ This could lead to non-deterministic routing behavior.`;
39
+ (0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
36
40
  }
37
41
  }
38
42
  exports.handleDuplicateRoutes = handleDuplicateRoutes;