@docusaurus/core 2.0.0-beta.8bda3b2db → 2.0.0-beta.9

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 (91) hide show
  1. package/bin/beforeCli.js +125 -0
  2. package/bin/docusaurus.js +36 -105
  3. package/lib/.tsbuildinfo +1 -1
  4. package/lib/babel/preset.js +1 -1
  5. package/lib/choosePort.js +10 -11
  6. package/lib/client/.tsbuildinfo +1 -1
  7. package/lib/client/App.js +8 -22
  8. package/lib/client/PendingNavigation.d.ts +24 -1
  9. package/lib/client/PendingNavigation.js +1 -1
  10. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +1 -0
  11. package/lib/client/docusaurus.js +0 -1
  12. package/lib/client/exports/BrowserOnly.js +5 -3
  13. package/lib/client/exports/Interpolate.js +4 -0
  14. package/lib/client/exports/Link.js +11 -11
  15. package/lib/client/exports/Translate.d.ts +2 -2
  16. package/lib/client/exports/Translate.js +13 -9
  17. package/lib/client/exports/browserContext.d.ts +11 -0
  18. package/lib/client/exports/browserContext.js +21 -0
  19. package/lib/client/exports/constants.js +1 -11
  20. package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
  21. package/lib/client/exports/docusaurusContext.js +25 -0
  22. package/lib/client/exports/useBaseUrl.js +1 -1
  23. package/lib/client/exports/useDocusaurusContext.js +2 -7
  24. package/lib/client/exports/useGlobalData.js +1 -5
  25. package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
  26. package/lib/client/exports/useIsBrowser.js +11 -0
  27. package/lib/client/normalizeLocation.d.ts +1 -3
  28. package/lib/client/prefetch.js +0 -1
  29. package/lib/client/serverEntry.js +11 -27
  30. package/lib/commands/build.js +26 -23
  31. package/lib/commands/clear.js +2 -2
  32. package/lib/commands/commandUtils.js +2 -2
  33. package/lib/commands/deploy.js +24 -14
  34. package/lib/commands/external.js +4 -4
  35. package/lib/commands/serve.js +13 -13
  36. package/lib/commands/start.js +74 -72
  37. package/lib/commands/swizzle.js +33 -33
  38. package/lib/commands/writeHeadingIds.d.ts +8 -5
  39. package/lib/commands/writeHeadingIds.js +32 -31
  40. package/lib/commands/writeTranslations.js +25 -11
  41. package/lib/constants.d.ts +1 -0
  42. package/lib/constants.js +4 -1
  43. package/lib/server/brokenLinks.js +13 -13
  44. package/lib/server/config.js +4 -4
  45. package/lib/server/configValidation.js +4 -3
  46. package/lib/server/duplicateRoutes.js +2 -2
  47. package/lib/server/html-tags/htmlTags.js +5 -5
  48. package/lib/server/html-tags/index.d.ts +2 -2
  49. package/lib/server/html-tags/index.js +3 -3
  50. package/lib/server/i18n.js +4 -4
  51. package/lib/server/index.js +99 -62
  52. package/lib/server/loadSetup.js +3 -3
  53. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -1
  54. package/lib/server/plugins/applyRouteTrailingSlash.js +3 -3
  55. package/lib/server/plugins/index.d.ts +3 -4
  56. package/lib/server/plugins/index.js +41 -27
  57. package/lib/server/plugins/init.d.ts +2 -6
  58. package/lib/server/plugins/init.js +7 -10
  59. package/lib/server/plugins/pluginIds.d.ts +2 -2
  60. package/lib/server/plugins/pluginIds.js +2 -2
  61. package/lib/server/presets/index.js +4 -7
  62. package/lib/server/routes.js +41 -23
  63. package/lib/server/themes/alias.d.ts +3 -2
  64. package/lib/server/themes/alias.js +24 -12
  65. package/lib/server/themes/index.d.ts +6 -2
  66. package/lib/server/themes/index.js +19 -9
  67. package/lib/server/translations/translations.d.ts +4 -5
  68. package/lib/server/translations/translations.js +9 -9
  69. package/lib/server/translations/translationsExtractor.d.ts +2 -3
  70. package/lib/server/translations/translationsExtractor.js +58 -47
  71. package/lib/server/utils.d.ts +8 -2
  72. package/lib/server/utils.js +8 -10
  73. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  74. package/lib/server/versions/__tests/index.test.js +5 -5
  75. package/lib/server/versions/index.js +6 -6
  76. package/lib/webpack/base.js +28 -19
  77. package/lib/webpack/client.js +8 -17
  78. package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -5
  79. package/lib/webpack/plugins/LogPlugin.js +3 -4
  80. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  81. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.d.ts +2 -0
  82. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.d.ts +5 -0
  83. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +1 -1
  84. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.d.ts +1 -0
  85. package/lib/webpack/server.js +11 -7
  86. package/lib/webpack/sharedModuleAliases.js +1 -1
  87. package/lib/webpack/utils.d.ts +2 -1
  88. package/lib/webpack/utils.js +28 -25
  89. package/package.json +45 -39
  90. package/tsconfig.client.json +1 -2
  91. package/tsconfig.json +5 -4
@@ -9,12 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenLinksErrorMessage = exports.getAllBrokenLinks = 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
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathname"));
13
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
14
14
  const lodash_1 = require("lodash");
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const utils_2 = require("./utils");
17
- const path_1 = tslib_1.__importDefault(require("path"));
17
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
18
18
  function toReactRouterRoutes(routes) {
19
19
  // @ts-expect-error: types incompatible???
20
20
  return routes;
@@ -29,12 +29,12 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
29
29
  // we must resolve the links before using matchRoutes
30
30
  // resolvePathname is used internally by ReactRouter
31
31
  function resolveLink(link) {
32
- const resolvedLink = resolve_pathname_1.default(onlyPathname(link), pagePath);
32
+ const resolvedLink = (0, resolve_pathname_1.default)(onlyPathname(link), pagePath);
33
33
  return { link, resolvedLink };
34
34
  }
35
35
  function isBrokenLink(link) {
36
36
  const matchedRoutes = [link, decodeURI(link)]
37
- .map((l) => react_router_config_1.matchRoutes(toReactRouterRoutes(routes), l))
37
+ .map((l) => (0, react_router_config_1.matchRoutes)(toReactRouterRoutes(routes), l))
38
38
  .reduce((prev, cur) => prev.concat(cur));
39
39
  return matchedRoutes.length === 0;
40
40
  }
@@ -46,15 +46,15 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
46
46
  // We also need to remove the match all 404 route
47
47
  function filterIntermediateRoutes(routesInput) {
48
48
  const routesWithout404 = routesInput.filter((route) => route.path !== '*');
49
- return utils_2.getAllFinalRoutes(routesWithout404);
49
+ return (0, utils_2.getAllFinalRoutes)(routesWithout404);
50
50
  }
51
51
  function getAllBrokenLinks({ allCollectedLinks, routes, }) {
52
52
  const filteredRoutes = filterIntermediateRoutes(routes);
53
- const allBrokenLinks = lodash_1.mapValues(allCollectedLinks, (pageLinks, pagePath) => {
53
+ const allBrokenLinks = (0, lodash_1.mapValues)(allCollectedLinks, (pageLinks, pagePath) => {
54
54
  return getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes });
55
55
  });
56
56
  // remove pages without any broken link
57
- return lodash_1.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
57
+ return (0, lodash_1.pickBy)(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
58
58
  }
59
59
  exports.getAllBrokenLinks = getAllBrokenLinks;
60
60
  function getBrokenLinksErrorMessage(allBrokenLinks) {
@@ -74,8 +74,8 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
74
74
  // Add an additional message in such case to help user figure this out.
75
75
  // see https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
76
76
  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);
77
+ const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
78
+ const countedBrokenLinks = (0, lodash_1.countBy)(flatList, (item) => item.brokenLink.link);
79
79
  const FrequencyThreshold = 5; // Is this a good value?
80
80
  const frequentLinks = Object.entries(countedBrokenLinks)
81
81
  .filter(([, count]) => count >= FrequencyThreshold)
@@ -106,7 +106,7 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
106
106
  // not easy to make this async :'(
107
107
  function linkFileExists(link) {
108
108
  // /baseUrl/javadoc/ -> /outDir/javadoc
109
- const baseFilePath = utils_1.removeSuffix(`${outDir}/${utils_1.removePrefix(link, baseUrl)}`, '/');
109
+ const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
110
110
  // -> /outDir/javadoc
111
111
  // -> /outDir/javadoc.html
112
112
  // -> /outDir/javadoc/index.html
@@ -117,7 +117,7 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
117
117
  }
118
118
  return filePathsToTry.some(isExistingFile);
119
119
  }
120
- return lodash_1.mapValues(allCollectedLinks, (links) => {
120
+ return (0, lodash_1.mapValues)(allCollectedLinks, (links) => {
121
121
  return links.filter((link) => !linkFileExists(link));
122
122
  });
123
123
  }
@@ -139,7 +139,7 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
139
139
  });
140
140
  const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
141
141
  if (errorMessage) {
142
- utils_1.reportMessage(errorMessage, onBrokenLinks);
142
+ (0, utils_1.reportMessage)(errorMessage, onBrokenLinks);
143
143
  }
144
144
  }
145
145
  exports.handleBrokenLinks = handleBrokenLinks;
@@ -7,14 +7,14 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
- const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
10
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
+ const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const configValidation_1 = require("./configValidation");
13
13
  function loadConfig(configPath) {
14
14
  if (!fs_extra_1.default.existsSync(configPath)) {
15
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 loadedConfig = (0, import_fresh_1.default)(configPath);
18
+ return (0, configValidation_1.validateConfig)(loadedConfig);
19
19
  }
20
20
  exports.default = loadConfig;
@@ -87,7 +87,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
87
87
  .regex(new RegExp('/$', 'm'))
88
88
  .message('{{#label}} must be a string with a trailing slash.'),
89
89
  baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
90
- favicon: utils_validation_1.Joi.string().required(),
90
+ favicon: utils_validation_1.Joi.string().optional(),
91
91
  title: utils_validation_1.Joi.string().required(),
92
92
  url: SiteUrlSchema,
93
93
  trailingSlash: utils_validation_1.Joi.boolean(),
@@ -103,6 +103,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
103
103
  .default(exports.DEFAULT_CONFIG.onDuplicateRoutes),
104
104
  organizationName: utils_validation_1.Joi.string().allow(''),
105
105
  projectName: utils_validation_1.Joi.string().allow(''),
106
+ deploymentBranch: utils_validation_1.Joi.string().optional(),
106
107
  customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
107
108
  githubHost: utils_validation_1.Joi.string(),
108
109
  plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
@@ -138,9 +139,9 @@ function validateConfig(config) {
138
139
  const { error, warning, value } = exports.ConfigSchema.validate(config, {
139
140
  abortEarly: false,
140
141
  });
141
- utils_validation_1.printWarning(warning);
142
+ (0, utils_validation_1.printWarning)(warning);
142
143
  if (error) {
143
- utils_validation_1.logValidationBugReportHint();
144
+ (0, utils_validation_1.logValidationBugReportHint)();
144
145
  if (utils_validation_1.isValidationDisabledEscapeHatch) {
145
146
  console.error(error);
146
147
  return config;
@@ -4,7 +4,7 @@ exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getA
4
4
  const utils_1 = require("@docusaurus/utils");
5
5
  const utils_2 = require("./utils");
6
6
  function getAllDuplicateRoutes(pluginsRouteConfigs) {
7
- const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
7
+ const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
8
8
  const seenRoutes = {};
9
9
  return allRoutes.filter((route) => {
10
10
  if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
@@ -32,7 +32,7 @@ function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
32
32
  const message = getDuplicateRoutesMessage(duplicatePaths);
33
33
  if (message) {
34
34
  const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
35
- utils_1.reportMessage(finalMessage, onDuplicateRoutes);
35
+ (0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
36
36
  }
37
37
  }
38
38
  exports.handleDuplicateRoutes = handleDuplicateRoutes;
@@ -8,11 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const lodash_1 = require("lodash");
11
- const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
12
- const void_1 = tslib_1.__importDefault(require("html-tags/void"));
13
- const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
11
+ const html_tags_1 = (0, tslib_1.__importDefault)(require("html-tags"));
12
+ const void_1 = (0, tslib_1.__importDefault)(require("html-tags/void"));
13
+ const escape_html_1 = (0, tslib_1.__importDefault)(require("escape-html"));
14
14
  function assertIsHtmlTagObject(val) {
15
- if (!lodash_1.isPlainObject(val)) {
15
+ if (!(0, lodash_1.isPlainObject)(val)) {
16
16
  throw new Error(`"${val}" is not a valid HTML tag object.`);
17
17
  }
18
18
  // @ts-expect-error: If tagName doesn't exist, it will throw.
@@ -33,7 +33,7 @@ function htmlTagObjectToString(tagDefinition) {
33
33
  if (tagAttributes[attributeName] === true) {
34
34
  return attributeName;
35
35
  }
36
- return `${attributeName}="${escape_html_1.default(tagAttributes[attributeName])}"`;
36
+ return `${attributeName}="${(0, escape_html_1.default)(tagAttributes[attributeName])}"`;
37
37
  });
38
38
  return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${(!isVoidTag && tagDefinition.innerHTML) || ''}${isVoidTag ? '' : `</${tagDefinition.tagName}>`}`;
39
39
  }
@@ -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 { Plugin, InjectedHtmlTags, HtmlTags } from '@docusaurus/types';
7
+ import { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
8
8
  export declare function createHtmlTagsString(tags: HtmlTags): string;
9
- export declare function loadHtmlTags(plugins: Plugin<unknown>[]): InjectedHtmlTags;
9
+ export declare function loadHtmlTags(plugins: LoadedPlugin[]): InjectedHtmlTags;
@@ -8,9 +8,9 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadHtmlTags = exports.createHtmlTagsString = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const htmlTags_1 = tslib_1.__importDefault(require("./htmlTags"));
11
+ const htmlTags_1 = (0, tslib_1.__importDefault)(require("./htmlTags"));
12
12
  function toString(val) {
13
- return typeof val === 'string' ? val : htmlTags_1.default(val);
13
+ return typeof val === 'string' ? val : (0, htmlTags_1.default)(val);
14
14
  }
15
15
  function createHtmlTagsString(tags) {
16
16
  return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
@@ -21,7 +21,7 @@ function loadHtmlTags(plugins) {
21
21
  if (!plugin.injectHtmlTags) {
22
22
  return acc;
23
23
  }
24
- const { headTags, preBodyTags, postBodyTags } = plugin.injectHtmlTags() || {};
24
+ const { headTags, preBodyTags, postBodyTags } = plugin.injectHtmlTags({ content: plugin.content }) || {};
25
25
  return {
26
26
  headTags: headTags
27
27
  ? `${acc.headTags}\n${createHtmlTagsString(headTags)}`
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.localizePath = exports.loadI18n = exports.shouldWarnAboutNodeVersion = exports.getDefaultLocaleConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
5
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
6
  const utils_1 = require("@docusaurus/utils");
7
7
  const rtl_detect_1 = require("rtl-detect");
8
8
  const constants_1 = require("../constants");
9
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
10
10
  function getDefaultLocaleLabel(locale) {
11
11
  // Intl.DisplayNames is ES2021 - Node14+
12
12
  // https://v8.dev/features/intl-displaynames
@@ -20,7 +20,7 @@ function getDefaultLocaleLabel(locale) {
20
20
  function getDefaultLocaleConfig(locale) {
21
21
  return {
22
22
  label: getDefaultLocaleLabel(locale),
23
- direction: rtl_detect_1.getLangDir(locale),
23
+ direction: (0, rtl_detect_1.getLangDir)(locale),
24
24
  };
25
25
  }
26
26
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
@@ -73,7 +73,7 @@ function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
73
73
  }
74
74
  // Url paths
75
75
  else if (pathType === 'url') {
76
- return utils_1.normalizeUrl([originalPath, '/', i18n.currentLocale, '/']);
76
+ return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
77
77
  }
78
78
  // should never happen
79
79
  else {
@@ -9,28 +9,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.load = exports.loadPluginConfigs = exports.loadContext = exports.loadSiteConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
- const path_1 = tslib_1.__importStar(require("path"));
13
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
14
- const ssr_html_template_1 = tslib_1.__importDefault(require("../client/templates/ssr.html.template"));
12
+ const path_1 = (0, tslib_1.__importStar)(require("path"));
13
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
14
+ const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
15
15
  const constants_1 = require("../constants");
16
- const client_modules_1 = tslib_1.__importDefault(require("./client-modules"));
17
- const config_1 = tslib_1.__importDefault(require("./config"));
16
+ const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
17
+ const config_1 = (0, tslib_1.__importDefault)(require("./config"));
18
18
  const plugins_1 = require("./plugins");
19
- const presets_1 = tslib_1.__importDefault(require("./presets"));
20
- const routes_1 = tslib_1.__importDefault(require("./routes"));
21
- const themes_1 = tslib_1.__importDefault(require("./themes"));
19
+ const presets_1 = (0, tslib_1.__importDefault)(require("./presets"));
20
+ const routes_1 = (0, tslib_1.__importDefault)(require("./routes"));
22
21
  const html_tags_1 = require("./html-tags");
23
22
  const versions_1 = require("./versions");
24
23
  const duplicateRoutes_1 = require("./duplicateRoutes");
25
24
  const i18n_1 = require("./i18n");
26
25
  const translations_1 = require("./translations/translations");
27
26
  const lodash_1 = require("lodash");
27
+ const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
28
28
  async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
29
29
  const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : constants_1.DEFAULT_CONFIG_FILE_NAME;
30
30
  const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
31
31
  ? siteConfigPathUnresolved
32
32
  : path_1.default.resolve(siteDir, siteConfigPathUnresolved);
33
- const siteConfig = await config_1.default(siteConfigPath);
33
+ const siteConfig = await (0, config_1.default)(siteConfigPath);
34
34
  return { siteConfig, siteConfigPath };
35
35
  }
36
36
  exports.loadSiteConfig = loadSiteConfig;
@@ -48,26 +48,26 @@ async function loadContext(siteDir, options = {}) {
48
48
  const baseOutDir = customOutDir
49
49
  ? path_1.default.resolve(customOutDir)
50
50
  : path_1.default.resolve(siteDir, constants_1.DEFAULT_BUILD_DIR_NAME);
51
- const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
52
- const baseUrl = i18n_1.localizePath({
51
+ const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
52
+ const baseUrl = (0, i18n_1.localizePath)({
53
53
  path: initialSiteConfig.baseUrl,
54
54
  i18n,
55
55
  options,
56
56
  pathType: 'url',
57
57
  });
58
- const outDir = i18n_1.localizePath({
58
+ const outDir = (0, i18n_1.localizePath)({
59
59
  path: baseOutDir,
60
60
  i18n,
61
61
  options,
62
62
  pathType: 'fs',
63
63
  });
64
64
  const siteConfig = { ...initialSiteConfig, baseUrl };
65
- const codeTranslationFileContent = (_a = (await translations_1.readCodeTranslationFileContent({
65
+ const codeTranslationFileContent = (_a = (await (0, translations_1.readCodeTranslationFileContent)({
66
66
  siteDir,
67
67
  locale: i18n.currentLocale,
68
68
  }))) !== null && _a !== void 0 ? _a : {};
69
69
  // We only need key->message for code translations
70
- const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
70
+ const codeTranslations = (0, lodash_1.mapValues)(codeTranslationFileContent, (value) => value.message);
71
71
  return {
72
72
  siteDir,
73
73
  generatedFilesDir,
@@ -82,7 +82,7 @@ async function loadContext(siteDir, options = {}) {
82
82
  }
83
83
  exports.loadContext = loadContext;
84
84
  function loadPluginConfigs(context) {
85
- const { plugins: presetPlugins, themes: presetThemes } = presets_1.default(context);
85
+ const { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
86
86
  const { siteConfig } = context;
87
87
  return [
88
88
  ...presetPlugins,
@@ -93,45 +93,19 @@ function loadPluginConfigs(context) {
93
93
  ];
94
94
  }
95
95
  exports.loadPluginConfigs = loadPluginConfigs;
96
- async function load(siteDir, options = {}) {
97
- // Context.
98
- const context = await loadContext(siteDir, options);
99
- const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
100
- // Plugins.
101
- const pluginConfigs = loadPluginConfigs(context);
102
- const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
103
- pluginConfigs,
104
- context,
105
- });
106
- // Side-effect to replace the untranslated themeConfig by the translated one
107
- context.siteConfig.themeConfig = themeConfigTranslated;
108
- duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
109
- // Site config must be generated after plugins
110
- // We want the generated config to have been normalized by the plugins!
111
- const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
112
- // Themes.
113
- const fallbackTheme = path_1.default.resolve(__dirname, '../client/theme-fallback');
114
- const pluginThemes = plugins
115
- .map((plugin) => plugin.getThemePath && plugin.getThemePath())
116
- .filter((x) => Boolean(x));
117
- const userTheme = path_1.default.resolve(siteDir, constants_1.THEME_PATH);
118
- const alias = themes_1.default([fallbackTheme, ...pluginThemes], [userTheme]);
119
- // Make a fake plugin to:
120
- // - Resolve aliased theme components
121
- // - Inject scripts/stylesheets
96
+ // Make a fake plugin to:
97
+ // - Resolve aliased theme components
98
+ // - Inject scripts/stylesheets
99
+ function createBootstrapPlugin({ siteConfig, }) {
122
100
  const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
123
- plugins.push({
101
+ return {
124
102
  name: 'docusaurus-bootstrap-plugin',
103
+ content: null,
125
104
  options: {},
126
105
  version: { type: 'synthetic' },
127
106
  getClientModules() {
128
107
  return siteConfigClientModules;
129
108
  },
130
- configureWebpack: () => ({
131
- resolve: {
132
- alias,
133
- },
134
- }),
135
109
  injectHtmlTags: () => {
136
110
  const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
137
111
  ? `<link rel="stylesheet" href="${source}">`
@@ -154,39 +128,102 @@ async function load(siteDir, options = {}) {
154
128
  headTags: [...stylesheetsTags, ...scriptsTags],
155
129
  };
156
130
  },
157
- });
131
+ };
132
+ }
133
+ // Configurer Webpack fallback mdx loader for md/mdx files out of content-plugin folders
134
+ // Adds a "fallback" mdx loader for mdx files that are not processed by content plugins
135
+ // This allows to do things such as importing repo/README.md as a partial from another doc
136
+ // Not ideal solution though, but good enough for now
137
+ function createMDXFallbackPlugin({ siteDir }) {
138
+ return {
139
+ name: 'docusaurus-mdx-fallback-plugin',
140
+ content: null,
141
+ options: {},
142
+ version: { type: 'synthetic' },
143
+ configureWebpack(config, isServer, { getJSLoader }) {
144
+ // We need the mdx fallback loader to exclude files that were already processed by content plugins mdx loaders
145
+ // This works, but a bit hacky...
146
+ // Not sure there's a way to handle that differently in webpack :s
147
+ function getMDXFallbackExcludedPaths() {
148
+ var _a;
149
+ const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
150
+ return rules.flatMap((rule) => {
151
+ const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
152
+ return isMDXRule ? rule.include : [];
153
+ });
154
+ }
155
+ return {
156
+ module: {
157
+ rules: [
158
+ {
159
+ test: /(\.mdx?)$/,
160
+ exclude: getMDXFallbackExcludedPaths(),
161
+ use: [
162
+ getJSLoader({ isServer }),
163
+ {
164
+ loader: require.resolve('@docusaurus/mdx-loader'),
165
+ options: {
166
+ staticDir: path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
167
+ isMDXPartial: (_filename) => true,
168
+ isMDXPartialFrontMatterWarningDisabled: true,
169
+ remarkPlugins: [remark_admonitions_1.default],
170
+ },
171
+ },
172
+ ],
173
+ },
174
+ ],
175
+ },
176
+ };
177
+ },
178
+ };
179
+ }
180
+ async function load(siteDir, options = {}) {
181
+ // Context.
182
+ const context = await loadContext(siteDir, options);
183
+ const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
184
+ // Plugins.
185
+ const pluginConfigs = loadPluginConfigs(context);
186
+ const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated } = await (0, plugins_1.loadPlugins)({ pluginConfigs, context });
187
+ // Side-effect to replace the untranslated themeConfig by the translated one
188
+ context.siteConfig.themeConfig = themeConfigTranslated;
189
+ (0, duplicateRoutes_1.handleDuplicateRoutes)(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
190
+ // Site config must be generated after plugins
191
+ // We want the generated config to have been normalized by the plugins!
192
+ const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
193
+ plugins.push(createBootstrapPlugin({ siteConfig }));
194
+ plugins.push(createMDXFallbackPlugin({ siteDir }));
158
195
  // Load client modules.
159
- const clientModules = client_modules_1.default(plugins);
160
- const genClientModules = utils_1.generate(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
196
+ const clientModules = (0, client_modules_1.default)(plugins);
197
+ const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [\n${clientModules
161
198
  // import() is async so we use require() because client modules can have
162
199
  // CSS and the order matters for loading CSS.
163
200
  // We need to JSON.stringify so that if its on windows, backslash are escaped.
164
201
  .map((module) => ` require(${JSON.stringify(module)}),`)
165
202
  .join('\n')}\n];\n`);
166
203
  // Load extra head & body html tags.
167
- const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
204
+ const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
168
205
  // Routing.
169
- const { registry, routesChunkNames, routesConfig, routesPaths, } = await routes_1.default(pluginsRouteConfigs, baseUrl);
170
- const genRegistry = utils_1.generate(generatedFilesDir, 'registry.js', `export default {
206
+ const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.default)(pluginsRouteConfigs, baseUrl);
207
+ const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
171
208
  ${Object.keys(registry)
172
209
  .sort()
173
210
  .map((key) =>
174
211
  // We need to JSON.stringify so that if its on windows, backslash are escaped.
175
212
  ` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
176
213
  .join('\n')}};\n`);
177
- const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
178
- const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
179
- const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
180
- const genI18n = utils_1.generate(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
214
+ const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
215
+ const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
216
+ const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
217
+ const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
181
218
  const codeTranslationsWithFallbacks = {
182
- ...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
219
+ ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
183
220
  ...codeTranslations,
184
221
  };
185
- const genCodeTranslations = utils_1.generate(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
222
+ const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
186
223
  // Version metadata.
187
224
  const siteMetadata = {
188
- docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
189
- siteVersion: versions_1.getPackageJsonVersion(path_1.join(siteDir, 'package.json')),
225
+ docusaurusVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(__dirname, '../../package.json')),
226
+ siteVersion: (0, versions_1.getPackageJsonVersion)((0, path_1.join)(siteDir, 'package.json')),
190
227
  pluginVersions: {},
191
228
  };
192
229
  plugins
@@ -195,7 +232,7 @@ ${Object.keys(registry)
195
232
  siteMetadata.pluginVersions[name] = version;
196
233
  });
197
234
  checkDocusaurusPackagesVersion(siteMetadata);
198
- const genSiteMetadata = utils_1.generate(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
235
+ const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
199
236
  await Promise.all([
200
237
  genClientModules,
201
238
  genSiteConfig,
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
10
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
11
  const index_1 = require("./index");
12
12
  // Helper methods to setup dummy/fake projects.
13
13
  const loadSetup = async (name) => {
@@ -16,10 +16,10 @@ const loadSetup = async (name) => {
16
16
  const customSite = path_1.default.join(fixtures, 'custom-site');
17
17
  switch (name) {
18
18
  case 'custom':
19
- return index_1.load(customSite);
19
+ return (0, index_1.load)(customSite);
20
20
  case 'simple':
21
21
  default:
22
- return index_1.load(simpleSite);
22
+ return (0, index_1.load)(simpleSite);
23
23
  }
24
24
  };
25
25
  exports.default = loadSetup;
@@ -5,4 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { RouteConfig } from '@docusaurus/types';
8
- export default function applyRouteTrailingSlash(route: RouteConfig, trailingSlash: boolean | undefined): any;
8
+ import { ApplyTrailingSlashParams } from '@docusaurus/utils-common';
9
+ export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
@@ -7,12 +7,12 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const utils_common_1 = require("@docusaurus/utils-common");
10
- function applyRouteTrailingSlash(route, trailingSlash) {
10
+ function applyRouteTrailingSlash(route, params) {
11
11
  return {
12
12
  ...route,
13
- path: utils_common_1.applyTrailingSlash(route.path, trailingSlash),
13
+ path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
14
14
  ...(route.routes && {
15
- routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, trailingSlash)),
15
+ routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
16
16
  }),
17
17
  };
18
18
  }
@@ -4,14 +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 { LoadContext, PluginConfig, RouteConfig, ThemeConfig } from '@docusaurus/types';
8
- import { InitPlugin } from './init';
9
- export declare function sortConfig(routeConfigs: RouteConfig[]): void;
7
+ import { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
+ export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
10
9
  export declare function loadPlugins({ pluginConfigs, context, }: {
11
10
  pluginConfigs: PluginConfig[];
12
11
  context: LoadContext;
13
12
  }): Promise<{
14
- plugins: InitPlugin[];
13
+ plugins: LoadedPlugin[];
15
14
  pluginsRouteConfigs: RouteConfig[];
16
15
  globalData: unknown;
17
16
  themeConfigTranslated: ThemeConfig;