@docusaurus/core 2.0.0-beta.8e9b829d9 → 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 (83) hide show
  1. package/bin/beforeCli.js +29 -7
  2. package/bin/docusaurus.js +36 -40
  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/Link.js +9 -9
  14. package/lib/client/exports/Translate.d.ts +2 -2
  15. package/lib/client/exports/Translate.js +10 -10
  16. package/lib/client/exports/browserContext.d.ts +11 -0
  17. package/lib/client/exports/browserContext.js +21 -0
  18. package/lib/client/exports/constants.js +1 -11
  19. package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
  20. package/lib/client/exports/docusaurusContext.js +25 -0
  21. package/lib/client/exports/useBaseUrl.js +1 -1
  22. package/lib/client/exports/useDocusaurusContext.js +2 -7
  23. package/lib/client/exports/useGlobalData.js +1 -5
  24. package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
  25. package/lib/client/exports/useIsBrowser.js +11 -0
  26. package/lib/client/normalizeLocation.d.ts +1 -3
  27. package/lib/client/prefetch.js +0 -1
  28. package/lib/client/serverEntry.js +11 -27
  29. package/lib/commands/build.js +24 -21
  30. package/lib/commands/clear.js +2 -2
  31. package/lib/commands/commandUtils.js +2 -2
  32. package/lib/commands/deploy.js +24 -14
  33. package/lib/commands/external.js +4 -4
  34. package/lib/commands/serve.js +13 -13
  35. package/lib/commands/start.js +69 -70
  36. package/lib/commands/swizzle.js +14 -14
  37. package/lib/commands/writeHeadingIds.d.ts +8 -5
  38. package/lib/commands/writeHeadingIds.js +32 -31
  39. package/lib/commands/writeTranslations.js +25 -11
  40. package/lib/constants.d.ts +1 -0
  41. package/lib/constants.js +4 -1
  42. package/lib/server/brokenLinks.js +13 -13
  43. package/lib/server/config.js +4 -4
  44. package/lib/server/configValidation.js +3 -2
  45. package/lib/server/duplicateRoutes.js +2 -2
  46. package/lib/server/html-tags/htmlTags.js +5 -5
  47. package/lib/server/html-tags/index.js +2 -2
  48. package/lib/server/i18n.js +4 -4
  49. package/lib/server/index.js +98 -49
  50. package/lib/server/loadSetup.js +3 -3
  51. package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
  52. package/lib/server/plugins/index.d.ts +1 -1
  53. package/lib/server/plugins/index.js +20 -13
  54. package/lib/server/plugins/init.js +7 -10
  55. package/lib/server/plugins/pluginIds.js +2 -2
  56. package/lib/server/presets/index.js +4 -7
  57. package/lib/server/routes.js +9 -11
  58. package/lib/server/themes/alias.d.ts +1 -0
  59. package/lib/server/themes/alias.js +22 -10
  60. package/lib/server/themes/index.js +5 -7
  61. package/lib/server/translations/translations.js +9 -9
  62. package/lib/server/translations/translationsExtractor.d.ts +1 -1
  63. package/lib/server/translations/translationsExtractor.js +58 -47
  64. package/lib/server/utils.d.ts +6 -0
  65. package/lib/server/utils.js +8 -9
  66. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  67. package/lib/server/versions/__tests/index.test.js +5 -5
  68. package/lib/server/versions/index.js +6 -6
  69. package/lib/webpack/base.js +12 -13
  70. package/lib/webpack/client.js +8 -17
  71. package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -5
  72. package/lib/webpack/plugins/LogPlugin.js +3 -4
  73. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  74. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.d.ts +2 -0
  75. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.d.ts +5 -0
  76. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +1 -1
  77. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.d.ts +1 -0
  78. package/lib/webpack/server.js +7 -7
  79. package/lib/webpack/sharedModuleAliases.js +1 -1
  80. package/lib/webpack/utils.js +25 -23
  81. package/package.json +44 -38
  82. package/tsconfig.client.json +0 -1
  83. package/tsconfig.json +4 -3
@@ -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;
@@ -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
  }
@@ -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);
@@ -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,27 +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"));
19
+ const presets_1 = (0, tslib_1.__importDefault)(require("./presets"));
20
+ const routes_1 = (0, tslib_1.__importDefault)(require("./routes"));
21
21
  const html_tags_1 = require("./html-tags");
22
22
  const versions_1 = require("./versions");
23
23
  const duplicateRoutes_1 = require("./duplicateRoutes");
24
24
  const i18n_1 = require("./i18n");
25
25
  const translations_1 = require("./translations/translations");
26
26
  const lodash_1 = require("lodash");
27
+ const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
27
28
  async function loadSiteConfig({ siteDir, customConfigFilePath, }) {
28
29
  const siteConfigPathUnresolved = customConfigFilePath !== null && customConfigFilePath !== void 0 ? customConfigFilePath : constants_1.DEFAULT_CONFIG_FILE_NAME;
29
30
  const siteConfigPath = path_1.default.isAbsolute(siteConfigPathUnresolved)
30
31
  ? siteConfigPathUnresolved
31
32
  : path_1.default.resolve(siteDir, siteConfigPathUnresolved);
32
- const siteConfig = await config_1.default(siteConfigPath);
33
+ const siteConfig = await (0, config_1.default)(siteConfigPath);
33
34
  return { siteConfig, siteConfigPath };
34
35
  }
35
36
  exports.loadSiteConfig = loadSiteConfig;
@@ -47,26 +48,26 @@ async function loadContext(siteDir, options = {}) {
47
48
  const baseOutDir = customOutDir
48
49
  ? path_1.default.resolve(customOutDir)
49
50
  : path_1.default.resolve(siteDir, constants_1.DEFAULT_BUILD_DIR_NAME);
50
- const i18n = await i18n_1.loadI18n(initialSiteConfig, { locale });
51
- const baseUrl = i18n_1.localizePath({
51
+ const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
52
+ const baseUrl = (0, i18n_1.localizePath)({
52
53
  path: initialSiteConfig.baseUrl,
53
54
  i18n,
54
55
  options,
55
56
  pathType: 'url',
56
57
  });
57
- const outDir = i18n_1.localizePath({
58
+ const outDir = (0, i18n_1.localizePath)({
58
59
  path: baseOutDir,
59
60
  i18n,
60
61
  options,
61
62
  pathType: 'fs',
62
63
  });
63
64
  const siteConfig = { ...initialSiteConfig, baseUrl };
64
- const codeTranslationFileContent = (_a = (await translations_1.readCodeTranslationFileContent({
65
+ const codeTranslationFileContent = (_a = (await (0, translations_1.readCodeTranslationFileContent)({
65
66
  siteDir,
66
67
  locale: i18n.currentLocale,
67
68
  }))) !== null && _a !== void 0 ? _a : {};
68
69
  // We only need key->message for code translations
69
- const codeTranslations = lodash_1.mapValues(codeTranslationFileContent, (value) => value.message);
70
+ const codeTranslations = (0, lodash_1.mapValues)(codeTranslationFileContent, (value) => value.message);
70
71
  return {
71
72
  siteDir,
72
73
  generatedFilesDir,
@@ -81,7 +82,7 @@ async function loadContext(siteDir, options = {}) {
81
82
  }
82
83
  exports.loadContext = loadContext;
83
84
  function loadPluginConfigs(context) {
84
- const { plugins: presetPlugins, themes: presetThemes } = presets_1.default(context);
85
+ const { plugins: presetPlugins, themes: presetThemes } = (0, presets_1.default)(context);
85
86
  const { siteConfig } = context;
86
87
  return [
87
88
  ...presetPlugins,
@@ -92,27 +93,12 @@ function loadPluginConfigs(context) {
92
93
  ];
93
94
  }
94
95
  exports.loadPluginConfigs = loadPluginConfigs;
95
- async function load(siteDir, options = {}) {
96
- // Context.
97
- const context = await loadContext(siteDir, options);
98
- const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations, } = context;
99
- // Plugins.
100
- const pluginConfigs = loadPluginConfigs(context);
101
- const { plugins, pluginsRouteConfigs, globalData, themeConfigTranslated, } = await plugins_1.loadPlugins({
102
- pluginConfigs,
103
- context,
104
- });
105
- // Side-effect to replace the untranslated themeConfig by the translated one
106
- context.siteConfig.themeConfig = themeConfigTranslated;
107
- duplicateRoutes_1.handleDuplicateRoutes(pluginsRouteConfigs, siteConfig.onDuplicateRoutes);
108
- // Site config must be generated after plugins
109
- // We want the generated config to have been normalized by the plugins!
110
- const genSiteConfig = utils_1.generate(generatedFilesDir, constants_1.DEFAULT_CONFIG_FILE_NAME, `export default ${JSON.stringify(siteConfig, null, 2)};`);
111
- // Make a fake plugin to:
112
- // - Resolve aliased theme components
113
- // - Inject scripts/stylesheets
96
+ // Make a fake plugin to:
97
+ // - Resolve aliased theme components
98
+ // - Inject scripts/stylesheets
99
+ function createBootstrapPlugin({ siteConfig, }) {
114
100
  const { stylesheets = [], scripts = [], clientModules: siteConfigClientModules = [], } = siteConfig;
115
- plugins.push({
101
+ return {
116
102
  name: 'docusaurus-bootstrap-plugin',
117
103
  content: null,
118
104
  options: {},
@@ -142,39 +128,102 @@ async function load(siteDir, options = {}) {
142
128
  headTags: [...stylesheetsTags, ...scriptsTags],
143
129
  };
144
130
  },
145
- });
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 }));
146
195
  // Load client modules.
147
- const clientModules = client_modules_1.default(plugins);
148
- 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
149
198
  // import() is async so we use require() because client modules can have
150
199
  // CSS and the order matters for loading CSS.
151
200
  // We need to JSON.stringify so that if its on windows, backslash are escaped.
152
201
  .map((module) => ` require(${JSON.stringify(module)}),`)
153
202
  .join('\n')}\n];\n`);
154
203
  // Load extra head & body html tags.
155
- const { headTags, preBodyTags, postBodyTags } = html_tags_1.loadHtmlTags(plugins);
204
+ const { headTags, preBodyTags, postBodyTags } = (0, html_tags_1.loadHtmlTags)(plugins);
156
205
  // Routing.
157
- const { registry, routesChunkNames, routesConfig, routesPaths, } = await routes_1.default(pluginsRouteConfigs, baseUrl);
158
- 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 {
159
208
  ${Object.keys(registry)
160
209
  .sort()
161
210
  .map((key) =>
162
211
  // We need to JSON.stringify so that if its on windows, backslash are escaped.
163
212
  ` '${key}': [${registry[key].loader}, ${JSON.stringify(registry[key].modulePath)}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`)
164
213
  .join('\n')}};\n`);
165
- const genRoutesChunkNames = utils_1.generate(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
166
- const genRoutes = utils_1.generate(generatedFilesDir, 'routes.js', routesConfig);
167
- const genGlobalData = utils_1.generate(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
168
- 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));
169
218
  const codeTranslationsWithFallbacks = {
170
- ...(await translations_1.getPluginsDefaultCodeTranslationMessages(plugins)),
219
+ ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
171
220
  ...codeTranslations,
172
221
  };
173
- 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));
174
223
  // Version metadata.
175
224
  const siteMetadata = {
176
- docusaurusVersion: versions_1.getPackageJsonVersion(path_1.join(__dirname, '../../package.json')),
177
- 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')),
178
227
  pluginVersions: {},
179
228
  };
180
229
  plugins
@@ -183,7 +232,7 @@ ${Object.keys(registry)
183
232
  siteMetadata.pluginVersions[name] = version;
184
233
  });
185
234
  checkDocusaurusPackagesVersion(siteMetadata);
186
- 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));
187
236
  await Promise.all([
188
237
  genClientModules,
189
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;
@@ -10,7 +10,7 @@ const utils_common_1 = require("@docusaurus/utils-common");
10
10
  function applyRouteTrailingSlash(route, params) {
11
11
  return {
12
12
  ...route,
13
- path: utils_common_1.applyTrailingSlash(route.path, params),
13
+ path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
14
14
  ...(route.routes && {
15
15
  routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
16
16
  }),
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { LoadContext, PluginConfig, RouteConfig, ThemeConfig, LoadedPlugin } from '@docusaurus/types';
8
- export declare function sortConfig(routeConfigs: RouteConfig[]): void;
8
+ export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
9
9
  export declare function loadPlugins({ pluginConfigs, context, }: {
10
10
  pluginConfigs: PluginConfig[];
11
11
  context: LoadContext;
@@ -9,18 +9,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadPlugins = exports.sortConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
- const path_1 = tslib_1.__importDefault(require("path"));
14
- const init_1 = tslib_1.__importDefault(require("./init"));
15
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
12
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
+ const init_1 = (0, tslib_1.__importDefault)(require("./init"));
15
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
16
16
  const constants_1 = require("../../constants");
17
17
  const lodash_1 = require("lodash");
18
18
  const translations_1 = require("../translations/translations");
19
- const applyRouteTrailingSlash_1 = tslib_1.__importDefault(require("./applyRouteTrailingSlash"));
20
- function sortConfig(routeConfigs) {
19
+ const applyRouteTrailingSlash_1 = (0, tslib_1.__importDefault)(require("./applyRouteTrailingSlash"));
20
+ function sortConfig(routeConfigs, baseUrl = '/') {
21
21
  // Sort the route config. This ensures that route with nested
22
22
  // routes is always placed last.
23
23
  routeConfigs.sort((a, b) => {
24
+ // Root route should get placed last.
25
+ if (a.path === baseUrl && b.path !== baseUrl) {
26
+ return 1;
27
+ }
28
+ if (a.path !== baseUrl && b.path === baseUrl) {
29
+ return -1;
30
+ }
24
31
  if (a.routes && !b.routes) {
25
32
  return 1;
26
33
  }
@@ -46,7 +53,7 @@ function sortConfig(routeConfigs) {
46
53
  exports.sortConfig = sortConfig;
47
54
  async function loadPlugins({ pluginConfigs, context, }) {
48
55
  // 1. Plugin Lifecycle - Initialization/Constructor.
49
- const plugins = init_1.default({
56
+ const plugins = (0, init_1.default)({
50
57
  pluginConfigs,
51
58
  context,
52
59
  });
@@ -63,7 +70,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
63
70
  const translationFiles = (_b = (await ((_a = contentLoadedPlugin === null || contentLoadedPlugin === void 0 ? void 0 : contentLoadedPlugin.getTranslationFiles) === null || _a === void 0 ? void 0 : _a.call(contentLoadedPlugin, {
64
71
  content: contentLoadedPlugin.content,
65
72
  })))) !== null && _b !== void 0 ? _b : [];
66
- const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => translations_1.localizePluginTranslationFile({
73
+ const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
67
74
  locale: context.i18n.currentLocale,
68
75
  siteDir: context.siteDir,
69
76
  translationFile,
@@ -74,10 +81,10 @@ async function loadPlugins({ pluginConfigs, context, }) {
74
81
  translationFiles: localizedTranslationFiles,
75
82
  };
76
83
  }));
77
- const allContent = lodash_1.chain(loadedPlugins)
84
+ const allContent = (0, lodash_1.chain)(loadedPlugins)
78
85
  .groupBy((item) => item.name)
79
86
  .mapValues((nameItems) => {
80
- return lodash_1.chain(nameItems)
87
+ return (0, lodash_1.chain)(nameItems)
81
88
  .groupBy((item) => { var _a; return (_a = item.options.id) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PLUGIN_ID; })
82
89
  .mapValues((idItems) => idItems[0].content)
83
90
  .value();
@@ -97,7 +104,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
97
104
  const dataDir = path_1.default.join(dataDirRoot, pluginId);
98
105
  const addRoute = (initialRouteConfig) => {
99
106
  // Trailing slash behavior is handled in a generic way for all plugins
100
- const finalRouteConfig = applyRouteTrailingSlash_1.default(initialRouteConfig, {
107
+ const finalRouteConfig = (0, applyRouteTrailingSlash_1.default)(initialRouteConfig, {
101
108
  trailingSlash: context.siteConfig.trailingSlash,
102
109
  baseUrl: context.siteConfig.baseUrl,
103
110
  });
@@ -106,7 +113,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
106
113
  const createData = async (name, data) => {
107
114
  const modulePath = path_1.default.join(dataDir, name);
108
115
  await fs_extra_1.default.ensureDir(path_1.default.dirname(modulePath));
109
- await utils_1.generate(dataDir, name, data);
116
+ await (0, utils_1.generate)(dataDir, name, data);
110
117
  return modulePath;
111
118
  };
112
119
  // the plugins global data are namespaced to avoid data conflicts:
@@ -145,7 +152,7 @@ async function loadPlugins({ pluginConfigs, context, }) {
145
152
  }));
146
153
  // Sort the route config. This ensures that route with nested
147
154
  // routes are always placed last.
148
- sortConfig(pluginsRouteConfigs);
155
+ sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
149
156
  // Apply each plugin one after the other to translate the theme config
150
157
  function translateThemeConfig(untranslatedThemeConfig) {
151
158
  return contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
@@ -7,8 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const module_1 = tslib_1.__importDefault(require("module"));
11
- const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
10
+ const module_1 = require("module");
11
+ const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const constants_1 = require("../../constants");
13
13
  const versions_1 = require("../versions");
14
14
  const pluginIds_1 = require("./pluginIds");
@@ -19,7 +19,7 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
19
19
  if (typeof pluginConfig === 'string') {
20
20
  const pluginModuleImport = pluginConfig;
21
21
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
22
- const pluginModule = import_fresh_1.default(pluginPath);
22
+ const pluginModule = (0, import_fresh_1.default)(pluginPath);
23
23
  return {
24
24
  plugin: (_a = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _a !== void 0 ? _a : pluginModule,
25
25
  options: {},
@@ -43,7 +43,7 @@ function normalizePluginConfig(pluginConfig, pluginRequire) {
43
43
  if (typeof pluginConfig[0] === 'string') {
44
44
  const pluginModuleImport = pluginConfig[0];
45
45
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
46
- const pluginModule = import_fresh_1.default(pluginPath);
46
+ const pluginModule = (0, import_fresh_1.default)(pluginPath);
47
47
  return {
48
48
  plugin: (_b = pluginModule === null || pluginModule === void 0 ? void 0 : pluginModule.default) !== null && _b !== void 0 ? _b : pluginModule,
49
49
  options: (_c = pluginConfig[1]) !== null && _c !== void 0 ? _c : {},
@@ -88,16 +88,13 @@ function getThemeValidationFunction(normalizedPluginConfig) {
88
88
  function initPlugins({ pluginConfigs, context, }) {
89
89
  // We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json
90
90
  // declares the dependency on these plugins.
91
- // We need to fallback to createRequireFromPath since createRequire is only available in node v12.
92
- // See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
93
- const createRequire = module_1.default.createRequire || module_1.default.createRequireFromPath;
94
- const pluginRequire = createRequire(context.siteConfigPath);
91
+ const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
95
92
  function doGetPluginVersion(normalizedPluginConfig) {
96
93
  var _a, _b;
97
94
  // get plugin version
98
95
  if ((_a = normalizedPluginConfig.pluginModule) === null || _a === void 0 ? void 0 : _a.path) {
99
96
  const pluginPath = pluginRequire.resolve((_b = normalizedPluginConfig.pluginModule) === null || _b === void 0 ? void 0 : _b.path);
100
- return versions_1.getPluginVersion(pluginPath, context.siteDir);
97
+ return (0, versions_1.getPluginVersion)(pluginPath, context.siteDir);
101
98
  }
102
99
  else {
103
100
  return { type: 'local' };
@@ -154,7 +151,7 @@ function initPlugins({ pluginConfigs, context, }) {
154
151
  };
155
152
  })
156
153
  .filter((item) => Boolean(item));
157
- pluginIds_1.ensureUniquePluginInstanceIds(plugins);
154
+ (0, pluginIds_1.ensureUniquePluginInstanceIds)(plugins);
158
155
  return plugins;
159
156
  }
160
157
  exports.default = initPlugins;