@docusaurus/core 2.0.0-beta.2 → 2.0.0-beta.22

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 (223) hide show
  1. package/README.md +1 -0
  2. package/bin/beforeCli.mjs +140 -0
  3. package/bin/docusaurus.mjs +221 -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 -8
  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/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -49
  36. package/lib/client/exports/Link.d.ts +4 -10
  37. package/lib/client/exports/Link.js +40 -40
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +11 -14
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +6 -13
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/client/exports/useRouteContext.d.ts +8 -0
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +12 -2
  56. package/lib/client/flat.js +19 -15
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +14 -10
  59. package/lib/client/prefetch.d.ts +1 -2
  60. package/lib/client/prefetch.js +12 -32
  61. package/lib/client/preload.d.ts +3 -4
  62. package/lib/client/preload.js +5 -12
  63. package/lib/client/routeContext.d.ts +13 -0
  64. package/lib/client/routeContext.js +31 -0
  65. package/lib/client/serverEntry.d.ts +10 -0
  66. package/lib/client/serverEntry.js +108 -146
  67. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  68. package/lib/client/theme-fallback/Error/index.js +45 -0
  69. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  70. package/lib/client/theme-fallback/Layout/index.js +2 -26
  71. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  72. package/lib/client/theme-fallback/Loading/index.js +50 -116
  73. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  74. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  75. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  76. package/lib/client/theme-fallback/Root/index.js +2 -6
  77. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  78. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  79. package/lib/commands/build.d.ts +6 -2
  80. package/lib/commands/build.js +81 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +34 -21
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +104 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +9 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +29 -28
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +109 -101
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +101 -0
  93. package/lib/commands/swizzle/common.d.ts +33 -0
  94. package/lib/commands/swizzle/common.js +56 -0
  95. package/lib/commands/swizzle/components.d.ts +29 -0
  96. package/lib/commands/swizzle/components.js +200 -0
  97. package/lib/commands/swizzle/config.d.ts +10 -0
  98. package/lib/commands/swizzle/config.js +84 -0
  99. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  100. package/lib/commands/swizzle/context.js +24 -0
  101. package/lib/commands/swizzle/index.d.ts +8 -0
  102. package/lib/commands/swizzle/index.js +118 -0
  103. package/lib/commands/swizzle/prompts.d.ts +12 -0
  104. package/lib/commands/swizzle/prompts.js +110 -0
  105. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  106. package/lib/commands/swizzle/tables.js +113 -0
  107. package/lib/commands/swizzle/themes.d.ts +20 -0
  108. package/lib/commands/swizzle/themes.js +106 -0
  109. package/lib/commands/writeHeadingIds.d.ts +2 -6
  110. package/lib/commands/writeHeadingIds.js +22 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +46 -25
  113. package/lib/index.d.ts +9 -9
  114. package/lib/index.js +14 -14
  115. package/lib/server/brokenLinks.d.ts +4 -17
  116. package/lib/server/brokenLinks.js +67 -56
  117. package/lib/server/clientModules.d.ts +12 -0
  118. package/lib/server/clientModules.js +20 -0
  119. package/lib/server/config.d.ts +5 -2
  120. package/lib/server/config.js +29 -6
  121. package/lib/server/configValidation.d.ts +4 -4
  122. package/lib/server/configValidation.js +86 -41
  123. package/lib/server/getHostPort.d.ts +14 -0
  124. package/lib/server/getHostPort.js +79 -0
  125. package/lib/server/htmlTags.d.ts +12 -0
  126. package/lib/server/htmlTags.js +62 -0
  127. package/lib/server/i18n.d.ts +3 -13
  128. package/lib/server/i18n.js +21 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +83 -165
  131. package/lib/server/plugins/configs.d.ts +51 -0
  132. package/lib/server/plugins/configs.js +101 -0
  133. package/lib/server/plugins/index.d.ts +9 -8
  134. package/lib/server/plugins/index.js +73 -134
  135. package/lib/server/plugins/init.d.ts +6 -5
  136. package/lib/server/plugins/init.js +44 -109
  137. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  138. package/lib/server/plugins/moduleShorthand.js +46 -0
  139. package/lib/server/plugins/pluginIds.d.ts +5 -1
  140. package/lib/server/plugins/pluginIds.js +12 -7
  141. package/lib/server/plugins/presets.d.ts +12 -0
  142. package/lib/server/plugins/presets.js +49 -0
  143. package/lib/server/plugins/routeConfig.d.ts +11 -0
  144. package/lib/server/plugins/routeConfig.js +54 -0
  145. package/lib/server/plugins/synthetic.d.ts +20 -0
  146. package/lib/server/plugins/synthetic.js +111 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +182 -95
  149. package/lib/server/siteMetadata.d.ts +12 -0
  150. package/lib/server/siteMetadata.js +81 -0
  151. package/lib/server/translations/translations.d.ts +14 -19
  152. package/lib/server/translations/translations.js +40 -72
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  154. package/lib/server/translations/translationsExtractor.js +158 -122
  155. package/lib/server/utils.d.ts +9 -3
  156. package/lib/server/utils.js +7 -9
  157. package/lib/webpack/aliases/index.d.ts +34 -0
  158. package/lib/webpack/aliases/index.js +106 -0
  159. package/lib/webpack/base.d.ts +3 -4
  160. package/lib/webpack/base.js +45 -57
  161. package/lib/webpack/client.d.ts +3 -3
  162. package/lib/webpack/client.js +12 -19
  163. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  164. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  165. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  166. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  167. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  168. package/lib/webpack/plugins/LogPlugin.js +4 -5
  169. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  170. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  171. package/lib/webpack/server.d.ts +5 -5
  172. package/lib/webpack/server.js +22 -9
  173. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  174. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  175. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +61 -182
  178. package/package.json +81 -77
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.eslintrc.js +0 -29
  183. package/lib/client/.tsbuildinfo +0 -1
  184. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  185. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  186. package/lib/client/nprogress.css +0 -36
  187. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  188. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  189. package/lib/commands/commandUtils.d.ts +0 -3
  190. package/lib/commands/commandUtils.js +0 -21
  191. package/lib/commands/swizzle.d.ts +0 -9
  192. package/lib/commands/swizzle.js +0 -245
  193. package/lib/constants.d.ts +0 -18
  194. package/lib/constants.js +0 -23
  195. package/lib/server/client-modules/index.js +0 -14
  196. package/lib/server/duplicateRoutes.d.ts +0 -10
  197. package/lib/server/duplicateRoutes.js +0 -38
  198. package/lib/server/html-tags/htmlTags.js +0 -40
  199. package/lib/server/html-tags/index.d.ts +0 -9
  200. package/lib/server/html-tags/index.js +0 -43
  201. package/lib/server/loadSetup.d.ts +0 -9
  202. package/lib/server/loadSetup.js +0 -25
  203. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
  204. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  205. package/lib/server/presets/index.d.ts +0 -11
  206. package/lib/server/presets/index.js +0 -48
  207. package/lib/server/themes/alias.d.ts +0 -8
  208. package/lib/server/themes/alias.js +0 -40
  209. package/lib/server/themes/index.d.ts +0 -12
  210. package/lib/server/themes/index.js +0 -47
  211. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  212. package/lib/server/versions/__fixtures__/package.json +0 -3
  213. package/lib/server/versions/__tests/index.test.js +0 -25
  214. package/lib/server/versions/index.d.ts +0 -10
  215. package/lib/server/versions/index.js +0 -50
  216. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  217. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  218. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  219. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  220. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  221. package/lib/webpack/sharedModuleAliases.js +0 -18
  222. package/tsconfig.client.json +0 -13
  223. package/tsconfig.json +0 -13
@@ -1,40 +0,0 @@
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
- const tslib_1 = require("tslib");
10
- const globby_1 = tslib_1.__importDefault(require("globby"));
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const path_1 = tslib_1.__importDefault(require("path"));
13
- const utils_1 = require("@docusaurus/utils");
14
- const lodash_1 = require("lodash");
15
- // TODO make async
16
- function themeAlias(themePath, addOriginalAlias) {
17
- if (!fs_extra_1.default.pathExistsSync(themePath)) {
18
- return {};
19
- }
20
- const themeComponentFiles = globby_1.default.sync(['**/*.{js,jsx,ts,tsx}'], {
21
- cwd: themePath,
22
- });
23
- // See https://github.com/facebook/docusaurus/pull/3922
24
- // ensure @theme/NavbarItem alias is created after @theme/NavbarItem/LocaleDropdown
25
- const sortedThemeComponentFiles = lodash_1.sortBy(themeComponentFiles, (file) => file.endsWith('/index.js'));
26
- const aliases = {};
27
- sortedThemeComponentFiles.forEach((relativeSource) => {
28
- const filePath = path_1.default.join(themePath, relativeSource);
29
- const fileName = utils_1.fileToPath(relativeSource);
30
- const aliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme', fileName]).replace(/\/$/, ''));
31
- aliases[aliasName] = filePath;
32
- if (addOriginalAlias) {
33
- // For swizzled components to access the original.
34
- const originalAliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme-original', fileName]).replace(/\/$/, ''));
35
- aliases[originalAliasName] = filePath;
36
- }
37
- });
38
- return aliases;
39
- }
40
- exports.default = themeAlias;
@@ -1,12 +0,0 @@
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 { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
8
- export declare function loadThemeAliases(themePaths: string[], userThemePaths?: string[]): ThemeAliases;
9
- export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
10
- siteDir: string;
11
- plugins: LoadedPlugin[];
12
- }): ThemeAliases;
@@ -1,47 +0,0 @@
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.loadPluginsThemeAliases = exports.loadThemeAliases = void 0;
10
- const tslib_1 = require("tslib");
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const constants_1 = require("../../constants");
13
- const alias_1 = tslib_1.__importDefault(require("./alias"));
14
- const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
15
- function buildThemeAliases(themeAliases, aliases = {}) {
16
- Object.keys(themeAliases).forEach((aliasKey) => {
17
- if (aliasKey in aliases) {
18
- const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
19
- // eslint-disable-next-line no-param-reassign
20
- aliases[`@theme-init/${componentName}`] = aliases[aliasKey];
21
- }
22
- // eslint-disable-next-line no-param-reassign
23
- aliases[aliasKey] = themeAliases[aliasKey];
24
- });
25
- return aliases;
26
- }
27
- function loadThemeAliases(themePaths, userThemePaths = []) {
28
- let aliases = {}; // TODO refactor, inelegant side-effect
29
- themePaths.forEach((themePath) => {
30
- const themeAliases = alias_1.default(themePath, true);
31
- aliases = { ...aliases, ...buildThemeAliases(themeAliases, aliases) };
32
- });
33
- userThemePaths.forEach((themePath) => {
34
- const userThemeAliases = alias_1.default(themePath, false);
35
- aliases = { ...aliases, ...buildThemeAliases(userThemeAliases, aliases) };
36
- });
37
- return aliases;
38
- }
39
- exports.loadThemeAliases = loadThemeAliases;
40
- function loadPluginsThemeAliases({ siteDir, plugins, }) {
41
- const pluginThemes = plugins
42
- .map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
43
- .filter((x) => Boolean(x));
44
- const userTheme = path_1.default.resolve(siteDir, constants_1.THEME_PATH);
45
- return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
46
- }
47
- exports.loadPluginsThemeAliases = loadPluginsThemeAliases;
File without changes
@@ -1,3 +0,0 @@
1
- {
2
- "version": "random-version"
3
- }
@@ -1,25 +0,0 @@
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
- const __1 = require("..");
10
- const path_1 = require("path");
11
- describe('getPluginVersion', () => {
12
- it('Can detect external packages plugins versions of correctly.', () => {
13
- expect(__1.getPluginVersion(path_1.join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
14
- // Make the plugin appear external.
15
- path_1.join(__dirname, '..', '..', '..', '..', '..', '..', 'website'))).toEqual({ type: 'package', version: 'random-version' });
16
- });
17
- it('Can detect project plugins versions correctly.', () => {
18
- expect(__1.getPluginVersion(path_1.join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
19
- // Make the plugin appear project local.
20
- path_1.join(__dirname, '..', '__fixtures__'))).toEqual({ type: 'project' });
21
- });
22
- it('Can detect local packages versions correctly.', () => {
23
- expect(__1.getPluginVersion('/', '/')).toEqual({ type: 'local' });
24
- });
25
- });
@@ -1,10 +0,0 @@
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 { DocusaurusPluginVersionInformation } from '@docusaurus/types';
8
- export declare function getPackageJsonVersion(packageJsonPath: string): string | undefined;
9
- export declare function getPackageJsonName(packageJsonPath: string): string | undefined;
10
- export declare function getPluginVersion(pluginPath: string, siteDir: string): DocusaurusPluginVersionInformation;
@@ -1,50 +0,0 @@
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.getPluginVersion = exports.getPackageJsonName = exports.getPackageJsonVersion = void 0;
10
- const fs_extra_1 = require("fs-extra");
11
- const path_1 = require("path");
12
- function getPackageJsonVersion(packageJsonPath) {
13
- if (fs_extra_1.existsSync(packageJsonPath)) {
14
- // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
15
- const { version } = require(packageJsonPath);
16
- return typeof version === 'string' ? version : undefined;
17
- }
18
- return undefined;
19
- }
20
- exports.getPackageJsonVersion = getPackageJsonVersion;
21
- function getPackageJsonName(packageJsonPath) {
22
- if (fs_extra_1.existsSync(packageJsonPath)) {
23
- // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
24
- const { name } = require(packageJsonPath);
25
- return typeof name === 'string' ? name : undefined;
26
- }
27
- return undefined;
28
- }
29
- exports.getPackageJsonName = getPackageJsonName;
30
- function getPluginVersion(pluginPath, siteDir) {
31
- let potentialPluginPackageJsonDirectory = path_1.dirname(pluginPath);
32
- while (potentialPluginPackageJsonDirectory !== '/') {
33
- const packageJsonPath = path_1.join(potentialPluginPackageJsonDirectory, 'package.json');
34
- if (fs_extra_1.existsSync(packageJsonPath) && fs_extra_1.lstatSync(packageJsonPath).isFile()) {
35
- if (potentialPluginPackageJsonDirectory === siteDir) {
36
- // If the plugin belongs to the same docusaurus project, we classify it as local plugin.
37
- return { type: 'project' };
38
- }
39
- return {
40
- type: 'package',
41
- name: getPackageJsonName(packageJsonPath),
42
- version: getPackageJsonVersion(packageJsonPath),
43
- };
44
- }
45
- potentialPluginPackageJsonDirectory = path_1.dirname(potentialPluginPackageJsonDirectory);
46
- }
47
- // In rare cases where a plugin is a path where no parent directory contains package.json, we can only classify it as local.
48
- return { type: 'local' };
49
- }
50
- exports.getPluginVersion = getPluginVersion;
@@ -1,11 +0,0 @@
1
- This is a temporary copy of
2
-
3
- CRA / react-dev-utils does not support Webpack 5 yet
4
-
5
- https://github.com/facebook/create-react-app/issues/9994
6
-
7
- This folder is a temporary copy of some react-dev-utils code to which we made some changes to support Webpack 5 without warnings
8
-
9
- TODO remove this folder once Webpack 5 is supported (https://github.com/facebook/create-react-app/issues/9994)
10
-
11
- The comment `// modified for Docusaurus` is added near the modified elements
@@ -1,57 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
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
- /* eslint-disable */
8
- /*
9
- * THIS FILE IS MODIFIED FOR DOCUSAURUS
10
- * the above copyright header must be preserved for license compliance.
11
- */
12
-
13
- /*
14
- Implementation based on comment: https://github.com/facebook/create-react-app/issues/9994#issuecomment-811289191
15
- */
16
-
17
- function base64SourceMap(source) {
18
- const base64 = Buffer.from(JSON.stringify(source.map()), 'utf8').toString(
19
- 'base64',
20
- );
21
- return `data:application/json;charset=utf-8;base64,${base64}`;
22
- }
23
-
24
- // modified for Docusaurus => remove webpack 5 deprecation warnings
25
- // See https://github.com/facebook/create-react-app/issues/9994#issuecomment-811289191
26
- function getSourceById(server, id) {
27
- const module = Array.from(server._stats.compilation.modules).find(
28
- (m) => server._stats.compilation.chunkGraph.getModuleId(m) == id,
29
- );
30
- return module.originalSource();
31
- }
32
-
33
- /*
34
- * Middleware responsible for retrieving a generated source
35
- * Receives a webpack internal url: "webpack-internal:///<module-id>"
36
- * Returns a generated source: "<source-text><sourceMappingURL><sourceURL>"
37
- *
38
- * Based on EvalSourceMapDevToolModuleTemplatePlugin.js
39
- */
40
- module.exports = function createEvalSourceMapMiddleware(server) {
41
- return function handleWebpackInternalMiddleware(req, res, next) {
42
- if (req.url.startsWith('/__get-internal-source')) {
43
- const fileName = req.query.fileName;
44
- const id = fileName.match(/webpack-internal:\/\/\/(.+)/)[1];
45
- if (!id || !server._stats) {
46
- next();
47
- }
48
-
49
- const source = getSourceById(server, id);
50
- const sourceMapURL = `//# sourceMappingURL=${base64SourceMap(source)}`;
51
- const sourceURL = `//# sourceURL=webpack-internal:///${module.id}`;
52
- res.end(`${source.source()}\n${sourceMapURL}\n${sourceURL}`);
53
- } else {
54
- next();
55
- }
56
- };
57
- };
@@ -1,138 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
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
- /* eslint-disable */
8
- /*
9
- * THIS FILE IS MODIFIED FOR DOCUSAURUS
10
- * the above copyright header must be preserved for license compliance.
11
- */
12
-
13
- /*
14
- Implementation has been copied from https://github.com/facebook/create-react-app/pull/10656
15
- */
16
-
17
- const friendlySyntaxErrorLabel = 'Syntax error:';
18
-
19
- function isLikelyASyntaxError(message) {
20
- return message.indexOf(friendlySyntaxErrorLabel) !== -1;
21
- }
22
-
23
- // Cleans up webpack error messages.
24
- function formatMessage(message) {
25
- let lines = [];
26
-
27
- // modified for Docusaurus => see https://github.com/facebook/create-react-app/pull/10656
28
- if (typeof message === 'string') {
29
- lines = message.split('\n');
30
- } else if ('message' in message) {
31
- lines = message['message'].split('\n');
32
- } else if (Array.isArray(message)) {
33
- message.forEach((message) => {
34
- if ('message' in message) {
35
- lines = message['message'].split('\n');
36
- }
37
- });
38
- }
39
-
40
- // Strip webpack-added headers off errors/warnings
41
- // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
42
- lines = lines.filter((line) => !/Module [A-z ]+\(from/.test(line));
43
-
44
- // Transform parsing error into syntax error
45
- // TODO: move this to our ESLint formatter?
46
- lines = lines.map((line) => {
47
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
48
- line,
49
- );
50
- if (!parsingError) {
51
- return line;
52
- }
53
- const [, errorLine, errorColumn, errorMessage] = parsingError;
54
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
55
- });
56
-
57
- message = lines.join('\n');
58
- // Smoosh syntax errors (commonly found in CSS)
59
- message = message.replace(
60
- /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
61
- `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`,
62
- );
63
- // Clean up export errors
64
- message = message.replace(
65
- /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
66
- `Attempted import error: '$1' is not exported from '$2'.`,
67
- );
68
- message = message.replace(
69
- /^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
70
- `Attempted import error: '$2' does not contain a default export (imported as '$1').`,
71
- );
72
- message = message.replace(
73
- /^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
74
- `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`,
75
- );
76
- lines = message.split('\n');
77
-
78
- // Remove leading newline
79
- if (lines.length > 2 && lines[1].trim() === '') {
80
- lines.splice(1, 1);
81
- }
82
- // Clean up file name
83
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
84
-
85
- // Cleans up verbose "module not found" messages for files and packages.
86
- if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
87
- lines = [
88
- lines[0],
89
- lines[1]
90
- .replace('Error: ', '')
91
- .replace('Module not found: Cannot find file:', 'Cannot find file:'),
92
- ];
93
- }
94
-
95
- // Add helpful message for users trying to use Sass for the first time
96
- if (lines[1] && lines[1].match(/Cannot find module.+node-sass/)) {
97
- lines[1] = 'To import Sass files, you first need to install node-sass.\n';
98
- lines[1] +=
99
- 'Run `npm install node-sass` or `yarn add node-sass` inside your workspace.';
100
- }
101
-
102
- message = lines.join('\n');
103
- // Internal stacks are generally useless so we strip them... with the
104
- // exception of stacks containing `webpack:` because they're normally
105
- // from user code generated by webpack. For more information see
106
- // https://github.com/facebook/create-react-app/pull/1050
107
- message = message.replace(
108
- /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
109
- '',
110
- ); // at ... ...:x:y
111
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
112
- lines = message.split('\n');
113
-
114
- // Remove duplicated newlines
115
- lines = lines.filter(
116
- (line, index, arr) =>
117
- index === 0 ||
118
- line.trim() !== '' ||
119
- line.trim() !== arr[index - 1].trim(),
120
- );
121
-
122
- // Reassemble the message
123
- message = lines.join('\n');
124
- return message.trim();
125
- }
126
-
127
- function formatWebpackMessages(json) {
128
- const formattedErrors = json.errors.map(formatMessage);
129
- const formattedWarnings = json.warnings.map(formatMessage);
130
- const result = {errors: formattedErrors, warnings: formattedWarnings};
131
- if (result.errors.some(isLikelyASyntaxError)) {
132
- // If there are any syntax errors, show just them.
133
- result.errors = result.errors.filter(isLikelyASyntaxError);
134
- }
135
- return result;
136
- }
137
-
138
- module.exports = formatWebpackMessages;