@docusaurus/core 2.0.0-beta.ff31de0ff → 2.0.1

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 (222) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/docusaurus.mjs +223 -0
  4. package/lib/babel/preset.d.ts +8 -3
  5. package/lib/babel/preset.js +10 -8
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +47 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  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 +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -7
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +37 -0
  32. package/lib/client/exports/ExecutionEnvironment.js +7 -8
  33. package/lib/client/exports/Head.d.ts +2 -3
  34. package/lib/client/exports/Head.js +3 -4
  35. package/lib/client/exports/Interpolate.d.ts +2 -2
  36. package/lib/client/exports/Interpolate.js +20 -49
  37. package/lib/client/exports/Link.d.ts +4 -10
  38. package/lib/client/exports/Link.js +44 -38
  39. package/lib/client/exports/Translate.d.ts +1 -1
  40. package/lib/client/exports/Translate.js +14 -9
  41. package/lib/client/exports/constants.js +1 -11
  42. package/lib/client/exports/isInternalUrl.js +1 -1
  43. package/lib/client/exports/renderRoutes.d.ts +1 -2
  44. package/lib/client/exports/renderRoutes.js +1 -2
  45. package/lib/client/exports/router.d.ts +1 -1
  46. package/lib/client/exports/router.js +1 -1
  47. package/lib/client/exports/useBaseUrl.js +11 -14
  48. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  49. package/lib/client/exports/useDocusaurusContext.js +3 -9
  50. package/lib/client/exports/useGlobalData.d.ts +4 -3
  51. package/lib/client/exports/useGlobalData.js +8 -15
  52. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  53. package/lib/client/exports/useIsBrowser.js +11 -0
  54. package/lib/client/exports/useRouteContext.d.ts +8 -0
  55. package/lib/client/exports/useRouteContext.js +15 -0
  56. package/lib/client/flat.d.ts +12 -2
  57. package/lib/client/flat.js +19 -15
  58. package/lib/client/normalizeLocation.d.ts +2 -5
  59. package/lib/client/normalizeLocation.js +14 -10
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +12 -32
  62. package/lib/client/preload.d.ts +3 -4
  63. package/lib/client/preload.js +5 -12
  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 +109 -136
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +45 -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 +50 -116
  74. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  75. package/lib/client/theme-fallback/NotFound/index.js +19 -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/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +6 -2
  81. package/lib/commands/build.js +81 -64
  82. package/lib/commands/clear.d.ts +7 -1
  83. package/lib/commands/clear.js +34 -21
  84. package/lib/commands/deploy.d.ts +5 -2
  85. package/lib/commands/deploy.js +102 -81
  86. package/lib/commands/external.d.ts +2 -2
  87. package/lib/commands/external.js +9 -11
  88. package/lib/commands/serve.d.ts +8 -2
  89. package/lib/commands/serve.js +40 -20
  90. package/lib/commands/start.d.ts +9 -2
  91. package/lib/commands/start.js +111 -101
  92. package/lib/commands/swizzle/actions.d.ts +23 -0
  93. package/lib/commands/swizzle/actions.js +106 -0
  94. package/lib/commands/swizzle/common.d.ts +33 -0
  95. package/lib/commands/swizzle/common.js +56 -0
  96. package/lib/commands/swizzle/components.d.ts +29 -0
  97. package/lib/commands/swizzle/components.js +200 -0
  98. package/lib/commands/swizzle/config.d.ts +10 -0
  99. package/lib/commands/swizzle/config.js +84 -0
  100. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  101. package/lib/commands/swizzle/context.js +24 -0
  102. package/lib/commands/swizzle/index.d.ts +8 -0
  103. package/lib/commands/swizzle/index.js +119 -0
  104. package/lib/commands/swizzle/prompts.d.ts +12 -0
  105. package/lib/commands/swizzle/prompts.js +110 -0
  106. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  107. package/lib/commands/swizzle/tables.js +113 -0
  108. package/lib/commands/swizzle/themes.d.ts +20 -0
  109. package/lib/commands/swizzle/themes.js +106 -0
  110. package/lib/commands/writeHeadingIds.d.ts +2 -6
  111. package/lib/commands/writeHeadingIds.js +22 -81
  112. package/lib/commands/writeTranslations.d.ts +4 -5
  113. package/lib/commands/writeTranslations.js +48 -28
  114. package/lib/index.d.ts +9 -9
  115. package/lib/index.js +14 -14
  116. package/lib/server/brokenLinks.d.ts +4 -17
  117. package/lib/server/brokenLinks.js +67 -56
  118. package/lib/server/clientModules.d.ts +12 -0
  119. package/lib/server/clientModules.js +20 -0
  120. package/lib/server/config.d.ts +5 -2
  121. package/lib/server/config.js +29 -6
  122. package/lib/server/configValidation.d.ts +5 -3
  123. package/lib/server/configValidation.js +105 -44
  124. package/lib/server/getHostPort.d.ts +14 -0
  125. package/lib/server/getHostPort.js +79 -0
  126. package/lib/server/htmlTags.d.ts +12 -0
  127. package/lib/server/htmlTags.js +62 -0
  128. package/lib/server/i18n.d.ts +3 -13
  129. package/lib/server/i18n.js +21 -55
  130. package/lib/server/index.d.ts +28 -6
  131. package/lib/server/index.js +86 -173
  132. package/lib/server/plugins/configs.d.ts +51 -0
  133. package/lib/server/plugins/configs.js +101 -0
  134. package/lib/server/plugins/index.d.ts +10 -10
  135. package/lib/server/plugins/index.js +76 -128
  136. package/lib/server/plugins/init.d.ts +6 -9
  137. package/lib/server/plugins/init.js +44 -109
  138. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  139. package/lib/server/plugins/moduleShorthand.js +46 -0
  140. package/lib/server/plugins/pluginIds.d.ts +6 -2
  141. package/lib/server/plugins/pluginIds.js +12 -7
  142. package/lib/server/plugins/presets.d.ts +12 -0
  143. package/lib/server/plugins/presets.js +49 -0
  144. package/lib/server/plugins/routeConfig.d.ts +11 -0
  145. package/lib/server/plugins/routeConfig.js +54 -0
  146. package/lib/server/plugins/synthetic.d.ts +20 -0
  147. package/lib/server/plugins/synthetic.js +111 -0
  148. package/lib/server/routes.d.ts +39 -7
  149. package/lib/server/routes.js +182 -95
  150. package/lib/server/siteMetadata.d.ts +12 -0
  151. package/lib/server/siteMetadata.js +81 -0
  152. package/lib/server/translations/translations.d.ts +16 -22
  153. package/lib/server/translations/translations.js +41 -73
  154. package/lib/server/translations/translationsExtractor.d.ts +10 -5
  155. package/lib/server/translations/translationsExtractor.js +158 -122
  156. package/lib/server/utils.d.ts +9 -3
  157. package/lib/server/utils.js +7 -9
  158. package/lib/webpack/aliases/index.d.ts +34 -0
  159. package/lib/webpack/aliases/index.js +106 -0
  160. package/lib/webpack/base.d.ts +3 -4
  161. package/lib/webpack/base.js +56 -58
  162. package/lib/webpack/client.d.ts +3 -3
  163. package/lib/webpack/client.js +12 -19
  164. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  165. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  166. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  167. package/lib/webpack/plugins/CleanWebpackPlugin.js +34 -18
  168. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  169. package/lib/webpack/plugins/LogPlugin.js +4 -5
  170. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  171. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  172. package/lib/webpack/server.d.ts +5 -5
  173. package/lib/webpack/server.js +23 -8
  174. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  175. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  176. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  177. package/lib/webpack/utils.d.ts +16 -31
  178. package/lib/webpack/utils.js +63 -183
  179. package/package.json +83 -77
  180. package/bin/docusaurus.js +0 -326
  181. package/lib/.tsbuildinfo +0 -5682
  182. package/lib/choosePort.js +0 -105
  183. package/lib/client/.eslintrc.js +0 -29
  184. package/lib/client/.tsbuildinfo +0 -4127
  185. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  186. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  187. package/lib/client/nprogress.css +0 -36
  188. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  189. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  190. package/lib/commands/commandUtils.d.ts +0 -3
  191. package/lib/commands/commandUtils.js +0 -21
  192. package/lib/commands/swizzle.d.ts +0 -9
  193. package/lib/commands/swizzle.js +0 -245
  194. package/lib/constants.d.ts +0 -18
  195. package/lib/constants.js +0 -23
  196. package/lib/server/client-modules/index.js +0 -14
  197. package/lib/server/duplicateRoutes.d.ts +0 -10
  198. package/lib/server/duplicateRoutes.js +0 -38
  199. package/lib/server/html-tags/htmlTags.js +0 -39
  200. package/lib/server/html-tags/index.d.ts +0 -9
  201. package/lib/server/html-tags/index.js +0 -43
  202. package/lib/server/loadSetup.d.ts +0 -9
  203. package/lib/server/loadSetup.js +0 -25
  204. package/lib/server/presets/index.d.ts +0 -11
  205. package/lib/server/presets/index.js +0 -48
  206. package/lib/server/themes/alias.d.ts +0 -8
  207. package/lib/server/themes/alias.js +0 -39
  208. package/lib/server/themes/index.d.ts +0 -8
  209. package/lib/server/themes/index.js +0 -35
  210. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  211. package/lib/server/versions/__fixtures__/package.json +0 -3
  212. package/lib/server/versions/__tests/index.test.js +0 -25
  213. package/lib/server/versions/index.d.ts +0 -10
  214. package/lib/server/versions/index.js +0 -50
  215. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  216. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  217. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  218. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  219. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  220. package/lib/webpack/sharedModuleAliases.js +0 -18
  221. package/tsconfig.client.json +0 -13
  222. package/tsconfig.json +0 -13
@@ -1,23 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeGlobby = exports.getAllFinalRoutes = void 0;
4
- const tslib_1 = require("tslib");
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
11
- const lodash_1 = require("lodash");
12
- const globby_1 = tslib_1.__importDefault(require("globby"));
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.safeGlobby = exports.getAllFinalRoutes = void 0;
10
+ const tslib_1 = require("tslib");
13
11
  const path_1 = tslib_1.__importDefault(require("path"));
14
12
  const utils_1 = require("@docusaurus/utils");
15
13
  // Recursively get the final routes (routes with no subroutes)
16
14
  function getAllFinalRoutes(routeConfig) {
17
15
  function getFinalRoutes(route) {
18
- return route.routes ? lodash_1.flatMap(route.routes, getFinalRoutes) : [route];
16
+ return route.routes ? route.routes.flatMap(getFinalRoutes) : [route];
19
17
  }
20
- return lodash_1.flatMap(routeConfig, getFinalRoutes);
18
+ return routeConfig.flatMap(getFinalRoutes);
21
19
  }
22
20
  exports.getAllFinalRoutes = getAllFinalRoutes;
23
21
  // Globby that fix Windows path patterns
@@ -25,7 +23,7 @@ exports.getAllFinalRoutes = getAllFinalRoutes;
25
23
  async function safeGlobby(patterns, options) {
26
24
  // Required for Windows support, as paths using \ should not be used by globby
27
25
  // (also using the windows hard drive prefix like c: is not a good idea)
28
- const globPaths = patterns.map((dirPath) => utils_1.posixPath(path_1.default.relative(process.cwd(), dirPath)));
29
- return globby_1.default(globPaths, options);
26
+ const globPaths = patterns.map((dirPath) => (0, utils_1.posixPath)(path_1.default.relative(process.cwd(), dirPath)));
27
+ return (0, utils_1.Globby)(globPaths, options);
30
28
  }
31
29
  exports.safeGlobby = safeGlobby;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { LoadedPlugin } from '@docusaurus/types';
8
+ /**
9
+ * Aliases used for Webpack resolution (useful for implementing swizzling)
10
+ */
11
+ declare type ThemeAliases = {
12
+ [alias: string]: string;
13
+ };
14
+ /**
15
+ * Order of Webpack aliases is important because one alias can shadow another.
16
+ * This ensures `@theme/NavbarItem` alias is after
17
+ * `@theme/NavbarItem/LocaleDropdown`.
18
+ *
19
+ * @see https://github.com/facebook/docusaurus/pull/3922
20
+ * @see https://github.com/facebook/docusaurus/issues/5382
21
+ */
22
+ export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
23
+ export declare function createAliasesForTheme(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
24
+ export declare function loadThemeAliases({ siteDir, plugins, }: {
25
+ siteDir: string;
26
+ plugins: LoadedPlugin[];
27
+ }): Promise<ThemeAliases>;
28
+ /**
29
+ * Note: a `@docusaurus` alias would also catch `@docusaurus/theme-common`, so
30
+ * instead of naively aliasing this to `client/exports`, we use fine-grained
31
+ * aliases instead.
32
+ */
33
+ export declare function loadDocusaurusAliases(): Promise<ThemeAliases>;
34
+ export {};
@@ -0,0 +1,106 @@
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
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.loadDocusaurusAliases = exports.loadThemeAliases = exports.createAliasesForTheme = exports.sortAliases = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const ThemeFallbackDir = path_1.default.join(__dirname, '../../client/theme-fallback');
16
+ /**
17
+ * Order of Webpack aliases is important because one alias can shadow another.
18
+ * This ensures `@theme/NavbarItem` alias is after
19
+ * `@theme/NavbarItem/LocaleDropdown`.
20
+ *
21
+ * @see https://github.com/facebook/docusaurus/pull/3922
22
+ * @see https://github.com/facebook/docusaurus/issues/5382
23
+ */
24
+ function sortAliases(aliases) {
25
+ // Alphabetical order by default
26
+ const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
27
+ // @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
28
+ entries.sort(([alias1], [alias2]) =>
29
+ // eslint-disable-next-line no-nested-ternary
30
+ alias1.includes(`${alias2}/`) ? -1 : alias2.includes(`${alias1}/`) ? 1 : 0);
31
+ return Object.fromEntries(entries);
32
+ }
33
+ exports.sortAliases = sortAliases;
34
+ async function createAliasesForTheme(themePath, addOriginalAlias) {
35
+ if (!(await fs_extra_1.default.pathExists(themePath))) {
36
+ return {};
37
+ }
38
+ const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
39
+ cwd: themePath,
40
+ });
41
+ const aliases = {};
42
+ themeComponentFiles.forEach((relativeSource) => {
43
+ const filePath = path_1.default.join(themePath, relativeSource);
44
+ const fileName = (0, utils_1.fileToPath)(relativeSource);
45
+ const aliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme', fileName]).replace(/\/$/, ''));
46
+ aliases[aliasName] = filePath;
47
+ if (addOriginalAlias) {
48
+ // For swizzled components to access the original.
49
+ const originalAliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme-original', fileName]).replace(/\/$/, ''));
50
+ aliases[originalAliasName] = filePath;
51
+ }
52
+ });
53
+ return sortAliases(aliases);
54
+ }
55
+ exports.createAliasesForTheme = createAliasesForTheme;
56
+ async function createThemeAliases(themePaths, userThemePaths) {
57
+ const aliases = {};
58
+ for (const themePath of themePaths) {
59
+ const themeAliases = await createAliasesForTheme(themePath, true);
60
+ Object.entries(themeAliases).forEach(([aliasKey, alias]) => {
61
+ // If this alias shadows a previous one, use @theme-init to preserve the
62
+ // initial one. @theme-init is only applied once: to the initial theme
63
+ // that provided this component
64
+ if (aliasKey in aliases) {
65
+ const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
66
+ const initAlias = `@theme-init/${componentName}`;
67
+ if (!(initAlias in aliases)) {
68
+ aliases[initAlias] = aliases[aliasKey];
69
+ }
70
+ }
71
+ aliases[aliasKey] = alias;
72
+ });
73
+ }
74
+ for (const themePath of userThemePaths) {
75
+ const userThemeAliases = await createAliasesForTheme(themePath, false);
76
+ Object.assign(aliases, userThemeAliases);
77
+ }
78
+ return sortAliases(aliases);
79
+ }
80
+ function loadThemeAliases({ siteDir, plugins, }) {
81
+ const pluginThemes = plugins
82
+ .map((plugin) => plugin.getThemePath && path_1.default.resolve(plugin.path, plugin.getThemePath()))
83
+ .filter((x) => Boolean(x));
84
+ const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
85
+ return createThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
86
+ }
87
+ exports.loadThemeAliases = loadThemeAliases;
88
+ /**
89
+ * Note: a `@docusaurus` alias would also catch `@docusaurus/theme-common`, so
90
+ * instead of naively aliasing this to `client/exports`, we use fine-grained
91
+ * aliases instead.
92
+ */
93
+ async function loadDocusaurusAliases() {
94
+ const dirPath = path_1.default.resolve(__dirname, '../../client/exports');
95
+ const extensions = ['.js', '.ts', '.tsx'];
96
+ const aliases = {};
97
+ (await fs_extra_1.default.readdir(dirPath))
98
+ .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
99
+ .forEach((fileName) => {
100
+ const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
101
+ const aliasName = `@docusaurus/${fileNameWithoutExtension}`;
102
+ aliases[aliasName] = path_1.default.resolve(dirPath, fileName);
103
+ });
104
+ return aliases;
105
+ }
106
+ exports.loadDocusaurusAliases = loadDocusaurusAliases;
@@ -4,9 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
7
+ import type { Configuration } from 'webpack';
8
+ import type { Props } from '@docusaurus/types';
9
9
  export declare const clientDir: string;
10
10
  export declare function excludeJS(modulePath: string): boolean;
11
- export declare function getDocusaurusAliases(): Record<string, string>;
12
- export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Configuration;
11
+ export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
@@ -6,74 +6,69 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createBaseConfig = exports.getDocusaurusAliases = exports.excludeJS = exports.clientDir = void 0;
9
+ exports.createBaseConfig = exports.excludeJS = exports.clientDir = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
13
12
  const path_1 = tslib_1.__importDefault(require("path"));
14
- const utils_1 = require("./utils");
15
- const constants_1 = require("../constants");
16
- const sharedModuleAliases_1 = tslib_1.__importDefault(require("./sharedModuleAliases"));
17
- const CSS_REGEX = /\.css$/;
18
- const CSS_MODULE_REGEX = /\.module\.css$/;
13
+ const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const utils_2 = require("./utils");
16
+ const aliases_1 = require("./aliases");
17
+ const CSS_REGEX = /\.css$/i;
18
+ const CSS_MODULE_REGEX = /\.module\.css$/i;
19
19
  exports.clientDir = path_1.default.join(__dirname, '..', 'client');
20
20
  const LibrariesToTranspile = [
21
- 'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
21
+ 'copy-text-to-clipboard', // Contains optional catch binding, incompatible with recent versions of Edge
22
22
  ];
23
23
  const LibrariesToTranspileRegex = new RegExp(LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'));
24
24
  function excludeJS(modulePath) {
25
- // always transpile client dir
25
+ // Always transpile client dir
26
26
  if (modulePath.startsWith(exports.clientDir)) {
27
27
  return false;
28
28
  }
29
29
  // Don't transpile node_modules except any docusaurus npm package
30
- return (/node_modules/.test(modulePath) &&
31
- !/(docusaurus)((?!node_modules).)*\.jsx?$/.test(modulePath) &&
30
+ return (modulePath.includes('node_modules') &&
31
+ !/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
32
32
  !LibrariesToTranspileRegex.test(modulePath));
33
33
  }
34
34
  exports.excludeJS = excludeJS;
35
- function getDocusaurusAliases() {
36
- const dirPath = path_1.default.resolve(__dirname, '../client/exports');
37
- const extensions = ['.js', '.ts', '.tsx'];
38
- const aliases = {};
39
- fs_extra_1.default.readdirSync(dirPath)
40
- .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
41
- .forEach((fileName) => {
42
- const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
43
- const aliasName = `@docusaurus/${fileNameWithoutExtension}`;
44
- aliases[aliasName] = path_1.default.resolve(dirPath, fileName);
45
- });
46
- return aliases;
47
- }
48
- exports.getDocusaurusAliases = getDocusaurusAliases;
49
- function createBaseConfig(props, isServer, minify = true) {
50
- var _a;
51
- const { outDir, siteDir, siteConfig, baseUrl, generatedFilesDir, routesPaths, siteMetadata, } = props;
35
+ async function createBaseConfig(props, isServer, minify = true) {
36
+ const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
52
37
  const totalPages = routesPaths.length;
53
38
  const isProd = process.env.NODE_ENV === 'production';
54
39
  const minimizeEnabled = minify && isProd && !isServer;
55
40
  const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
56
- const fileLoaderUtils = utils_1.getFileLoaderUtils();
41
+ const fileLoaderUtils = (0, utils_1.getFileLoaderUtils)();
57
42
  const name = isServer ? 'server' : 'client';
58
43
  const mode = isProd ? 'production' : 'development';
44
+ const themeAliases = await (0, aliases_1.loadThemeAliases)({ siteDir, plugins });
59
45
  return {
60
46
  mode,
61
47
  name,
62
48
  cache: {
63
- // TODO temporary env variable to reduce risk of Webpack 5 release
64
- // maybe expose an official api, once this is solved? https://github.com/webpack/webpack/issues/13034
65
- type: process.env.DOCUSAURUS_WEBPACK_CACHE_TYPE ||
66
- 'filesystem',
49
+ type: 'filesystem',
67
50
  // Can we share the same cache across locales?
68
51
  // Exploring that question at https://github.com/webpack/webpack/issues/13034
69
52
  // name: `${name}-${mode}`,
70
53
  name: `${name}-${mode}-${props.i18n.currentLocale}`,
71
- version: siteMetadata.docusaurusVersion,
54
+ // When version string changes, cache is evicted
55
+ version: [
56
+ siteMetadata.docusaurusVersion,
57
+ // Webpack does not evict the cache correctly on alias/swizzle change,
58
+ // so we force eviction.
59
+ // See https://github.com/webpack/webpack/issues/13627
60
+ (0, utils_1.md5Hash)(JSON.stringify(themeAliases)),
61
+ ].join('-'),
62
+ // When one of those modules/dependencies change (including transitive
63
+ // deps), cache is invalidated
72
64
  buildDependencies: {
73
- // When one of dependencies change, cache is invalidated
74
65
  config: [
75
66
  __filename,
76
67
  path_1.default.join(__dirname, isServer ? 'server.js' : 'client.js'),
68
+ // Docusaurus config changes can affect MDX/JSX compilation, so we'd
69
+ // rather evict the cache.
70
+ // See https://github.com/questdb/questdb.io/issues/493
71
+ siteConfigPath,
77
72
  ],
78
73
  },
79
74
  },
@@ -85,6 +80,7 @@ function createBaseConfig(props, isServer, minify = true) {
85
80
  ? 'assets/js/[name].[contenthash:8].js'
86
81
  : '[name].js',
87
82
  publicPath: baseUrl,
83
+ hashFunction: 'xxhash64',
88
84
  },
89
85
  // Don't throw warning when asset created is over 250kb
90
86
  performance: {
@@ -99,27 +95,25 @@ function createBaseConfig(props, isServer, minify = true) {
99
95
  // Allow resolution of url("/fonts/xyz.ttf") by webpack
100
96
  // See https://webpack.js.org/configuration/resolve/#resolveroots
101
97
  // See https://github.com/webpack-contrib/css-loader/issues/1256
102
- path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
98
+ ...siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
103
99
  siteDir,
104
100
  process.cwd(),
105
101
  ],
106
102
  alias: {
107
- ...sharedModuleAliases_1.default,
108
103
  '@site': siteDir,
109
104
  '@generated': generatedFilesDir,
110
- // Note: a @docusaurus alias would also catch @docusaurus/theme-common,
111
- // so we use fine-grained aliases instead
112
- // '@docusaurus': path.resolve(__dirname, '../client/exports'),
113
- ...getDocusaurusAliases(),
105
+ ...(await (0, aliases_1.loadDocusaurusAliases)()),
106
+ ...themeAliases,
114
107
  },
115
- // This allows you to set a fallback for where Webpack should look for modules.
116
- // We want `@docusaurus/core` own dependencies/`node_modules` to "win" if there is conflict
117
- // Example: if there is core-js@3 in user's own node_modules, but core depends on
118
- // core-js@2, we should use core-js@2.
108
+ // This allows you to set a fallback for where Webpack should look for
109
+ // modules. We want `@docusaurus/core` own dependencies/`node_modules` to
110
+ // "win" if there is conflict. Example: if there is core-js@3 in user's
111
+ // own node_modules, but core depends on core-js@2, we should use
112
+ // core-js@2.
119
113
  modules: [
120
114
  path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
121
115
  'node_modules',
122
- path_1.default.resolve(fs_extra_1.default.realpathSync(process.cwd()), 'node_modules'),
116
+ path_1.default.resolve(await fs_extra_1.default.realpath(process.cwd()), 'node_modules'),
123
117
  ],
124
118
  },
125
119
  resolveLoader: {
@@ -127,18 +121,21 @@ function createBaseConfig(props, isServer, minify = true) {
127
121
  },
128
122
  optimization: {
129
123
  removeAvailableModules: false,
130
- // Only minimize client bundle in production because server bundle is only used for static site generation
124
+ // Only minimize client bundle in production because server bundle is only
125
+ // used for static site generation
131
126
  minimize: minimizeEnabled,
132
127
  minimizer: minimizeEnabled
133
- ? utils_1.getMinimizer(useSimpleCssMinifier)
128
+ ? (0, utils_2.getMinimizer)(useSimpleCssMinifier)
134
129
  : undefined,
135
130
  splitChunks: isServer
136
131
  ? false
137
132
  : {
138
- // Since the chunk name includes all origin chunk names it's recommended for production builds with long term caching to NOT include [name] in the filenames
133
+ // Since the chunk name includes all origin chunk names it's
134
+ // recommended for production builds with long term caching to NOT
135
+ // include [name] in the filenames
139
136
  name: false,
140
137
  cacheGroups: {
141
- // disable the built-in cacheGroups
138
+ // Disable the built-in cacheGroups
142
139
  default: false,
143
140
  common: {
144
141
  name: 'common',
@@ -167,19 +164,19 @@ function createBaseConfig(props, isServer, minify = true) {
167
164
  fileLoaderUtils.rules.svg(),
168
165
  fileLoaderUtils.rules.otherAssets(),
169
166
  {
170
- test: /\.(j|t)sx?$/,
167
+ test: /\.[jt]sx?$/i,
171
168
  exclude: excludeJS,
172
169
  use: [
173
- utils_1.getCustomizableJSLoader((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
170
+ (0, utils_2.getCustomizableJSLoader)(siteConfig.webpack?.jsLoader)({
174
171
  isServer,
175
- babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
172
+ babelOptions: await (0, utils_2.getCustomBabelConfigFilePath)(siteDir),
176
173
  }),
177
174
  ],
178
175
  },
179
176
  {
180
177
  test: CSS_REGEX,
181
178
  exclude: CSS_MODULE_REGEX,
182
- use: utils_1.getStyleLoaders(isServer, {
179
+ use: (0, utils_2.getStyleLoaders)(isServer, {
183
180
  importLoaders: 1,
184
181
  sourceMap: !isProd,
185
182
  }),
@@ -188,11 +185,11 @@ function createBaseConfig(props, isServer, minify = true) {
188
185
  // using the extension .module.css
189
186
  {
190
187
  test: CSS_MODULE_REGEX,
191
- use: utils_1.getStyleLoaders(isServer, {
188
+ use: (0, utils_2.getStyleLoaders)(isServer, {
192
189
  modules: {
193
190
  localIdentName: isProd
194
191
  ? `[local]_[contenthash:base64:4]`
195
- : `[local]_[path]`,
192
+ : `[local]_[path][name]`,
196
193
  exportOnlyLocals: isServer,
197
194
  },
198
195
  importLoaders: 1,
@@ -209,8 +206,9 @@ function createBaseConfig(props, isServer, minify = true) {
209
206
  chunkFilename: isProd
210
207
  ? 'assets/css/[name].[contenthash:8].css'
211
208
  : '[name].css',
212
- // remove css order warnings if css imports are not sorted alphabetically
213
- // see https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422 for more reasoning
209
+ // Remove css order warnings if css imports are not sorted
210
+ // alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
211
+ // for more reasoning
214
212
  ignoreOrder: true,
215
213
  }),
216
214
  ],
@@ -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 { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
9
- export default function createClientConfig(props: Props, minify?: boolean): Configuration;
7
+ import type { Props } from '@docusaurus/types';
8
+ import type { Configuration } from 'webpack';
9
+ export default function createClientConfig(props: Props, minify?: boolean): Promise<Configuration>;
@@ -7,28 +7,20 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
11
10
  const path_1 = tslib_1.__importDefault(require("path"));
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
12
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
13
13
  const base_1 = require("./base");
14
14
  const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
15
15
  const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
16
- function createClientConfig(props, minify = true) {
17
- var _a;
18
- const isProd = process.env.NODE_ENV === 'production';
16
+ async function createClientConfig(props, minify = true) {
19
17
  const isBuilding = process.argv[2] === 'build';
20
- const config = base_1.createBaseConfig(props, false, minify);
21
- const clientConfig = webpack_merge_1.default(config, {
22
- // target: 'browserslist', // useless, disabled on purpose (errors on existing sites with no browserslist cfg)
23
- entry: [
24
- // Instead of the default WebpackDevServer client, we use a custom one
25
- // like CRA to bring better experience.
26
- // note: the one in ./dev is modified to work with Docusaurus
27
- // !isProd && require.resolve('react-dev-utils/hotDevServer.js'),
28
- !isProd &&
29
- require.resolve('./react-dev-utils-webpack5/webpackHotDevClient.js'),
30
- path_1.default.resolve(__dirname, '../client/clientEntry.js'),
31
- ].filter(Boolean),
18
+ const config = await (0, base_1.createBaseConfig)(props, false, minify);
19
+ const clientConfig = (0, webpack_merge_1.default)(config, {
20
+ // Useless, disabled on purpose (errors on existing sites with no
21
+ // browserslist config)
22
+ // target: 'browserslist',
23
+ entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
32
24
  optimization: {
33
25
  // Keep the runtime chunk separated to enable long term caching
34
26
  // https://twitter.com/wSokra/status/969679223278505985
@@ -42,13 +34,14 @@ function createClientConfig(props, minify = true) {
42
34
  }),
43
35
  ],
44
36
  });
45
- // When building include the plugin to force terminate building if errors happened in the client bundle.
37
+ // When building, include the plugin to force terminate building if errors
38
+ // happened in the client bundle.
46
39
  if (isBuilding) {
47
- (_a = clientConfig.plugins) === null || _a === void 0 ? void 0 : _a.push({
40
+ clientConfig.plugins?.push({
48
41
  apply: (compiler) => {
49
42
  compiler.hooks.done.tap('client:done', (stats) => {
50
43
  if (stats.hasErrors()) {
51
- console.log(chalk_1.default.red('Client bundle compiled with errors therefore further build is impossible.'));
44
+ logger_1.default.error('Client bundle compiled with errors therefore further build is impossible.');
52
45
  process.exit(1);
53
46
  }
54
47
  });
@@ -4,8 +4,18 @@
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 { Compiler } from 'webpack';
8
- declare class ChunkAssetPlugin {
7
+ import { type Compiler } from 'webpack';
8
+ /**
9
+ * We modify webpack runtime to add an extra function called
10
+ * "__webpack_require__.gca" that will allow us to get the corresponding chunk
11
+ * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
12
+ * For example: if you have a chunk named "my-chunk-name" that will map to
13
+ * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
14
+ * __webpack_require__.gca("my-chunk-name") will return
15
+ * "/publicPath/0a84b5e7.c8e35c7a.js"
16
+ *
17
+ * "gca" stands for "get chunk asset"
18
+ */
19
+ export default class ChunkAssetPlugin {
9
20
  apply(compiler: Compiler): void;
10
21
  }
11
- export default ChunkAssetPlugin;
@@ -6,37 +6,44 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const webpack_1 = require("webpack");
9
+ const tslib_1 = require("tslib");
10
+ const webpack_1 = tslib_1.__importDefault(require("webpack"));
10
11
  const pluginName = 'chunk-asset-plugin';
12
+ /**
13
+ * We modify webpack runtime to add an extra function called
14
+ * "__webpack_require__.gca" that will allow us to get the corresponding chunk
15
+ * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
16
+ * For example: if you have a chunk named "my-chunk-name" that will map to
17
+ * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
18
+ * __webpack_require__.gca("my-chunk-name") will return
19
+ * "/publicPath/0a84b5e7.c8e35c7a.js"
20
+ *
21
+ * "gca" stands for "get chunk asset"
22
+ */
11
23
  class ChunkAssetPlugin {
12
24
  apply(compiler) {
13
25
  compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
14
- /* We modify webpack runtime to add an extra function called "__webpack_require__.gca"
15
- that will allow us to get the corresponding chunk asset for a webpack chunk.
16
- Pass it the chunkName or chunkId you want to load.
17
- For example: if you have a chunk named "my-chunk-name" that will map to "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
18
- __webpack_require__.gca("my-chunk-name") will return "/publicPath/0a84b5e7.c8e35c7a.js"
19
- "gca" stands for "get chunk asset"
20
- */
21
26
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
22
27
  const chunkIdToName = chunk.getChunkMaps(false).name;
23
- const chunkNameToId = Object.create(null);
24
- Object.keys(chunkIdToName).forEach((chunkId) => {
25
- const chunkName = chunkIdToName[chunkId];
26
- chunkNameToId[chunkName] = chunkId;
27
- });
28
+ const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
29
+ chunkName,
30
+ chunkId,
31
+ ]));
28
32
  const buf = [source];
29
33
  buf.push('// function to get chunk asset');
30
34
  buf.push(
31
35
  // If chunkName is passed, we convert it to chunk asset url
32
36
  // .p => public path url ("/" or "/baseUrl/")
33
- // .u(chunkId) => chunk asset url ("assets/js/x63b64xd.contentHash.js")
34
- // not sure where this is documented, but this link was helpful: https://programmer.help/blogs/5d68849083e1a.html
37
+ // .u(chunkId) =>
38
+ // chunk asset url ("assets/js/x63b64xd.contentHash.js")
39
+ // not sure where this is documented, but this link was helpful:
40
+ // https://programmer.help/blogs/5d68849083e1a.html
35
41
  //
36
- // Note: __webpack_require__.gca() is called in docusaurus.ts for prefetching
42
+ // Note: __webpack_require__.gca() is called in docusaurus.ts for
43
+ // prefetching
37
44
  // Note: we previously used jsonpScriptSrc (Webpack 4)
38
45
  `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
39
- return webpack_1.Template.asString(buf);
46
+ return webpack_1.default.Template.asString(buf);
40
47
  });
41
48
  });
42
49
  }
@@ -4,27 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- /**
8
- * The MIT License (MIT)
9
- * Copyright (c) 2015 John Agan
10
- * Permission is hereby granted, free of charge, to any person obtaining a copy
11
- * of this software and associated documentation files (the "Software"), to deal
12
- * in the Software without restriction, including without limitation the rights
13
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- * copies of the Software, and to permit persons to whom the Software is
15
- * furnished to do so, subject to the following conditions:
16
- * The above copyright notice and this permission notice shall be included in all
17
- * copies or substantial portions of the Software.
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- */
26
- import { Compiler, Stats } from 'webpack';
27
- export interface Options {
7
+ import type { Compiler, Stats } from 'webpack';
8
+ export declare type Options = {
28
9
  /**
29
10
  * Write Logs to Console
30
11
  * (Always enabled when dry is true)
@@ -53,8 +34,8 @@ export interface Options {
53
34
  * default: ['**\/*']
54
35
  */
55
36
  cleanOnceBeforeBuildPatterns?: string[];
56
- }
57
- declare class CleanWebpackPlugin {
37
+ };
38
+ export default class CleanWebpackPlugin {
58
39
  private readonly verbose;
59
40
  private readonly cleanStaleWebpackAssets;
60
41
  private readonly protectWebpackAssets;
@@ -69,10 +50,10 @@ declare class CleanWebpackPlugin {
69
50
  *
70
51
  * Only happens once.
71
52
  *
72
- * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.
53
+ * Warning: It is recommended to initially clean your build directory outside
54
+ * of webpack to minimize unexpected behavior.
73
55
  */
74
56
  handleInitial(): void;
75
57
  handleDone(stats: Stats): void;
76
58
  removeFiles(patterns: string[]): void;
77
59
  }
78
- export default CleanWebpackPlugin;