@docusaurus/core 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21

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/bin/beforeCli.mjs +140 -0
  2. package/bin/docusaurus.mjs +236 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +10 -8
  5. package/lib/client/.eslintrc.js +2 -4
  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} +24 -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 +41 -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 +36 -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 +38 -38
  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 +105 -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 +80 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +32 -20
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +93 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +6 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +26 -27
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +106 -92
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +100 -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 +116 -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 +21 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +39 -20
  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 +80 -38
  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 +19 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +79 -163
  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 +72 -135
  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 +112 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +185 -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 +11 -14
  152. package/lib/server/translations/translations.js +36 -60
  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 +16 -12
  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 +82 -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/.tsbuildinfo +0 -1
  183. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  184. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  185. package/lib/client/nprogress.css +0 -36
  186. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  187. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  188. package/lib/commands/commandUtils.d.ts +0 -3
  189. package/lib/commands/commandUtils.js +0 -21
  190. package/lib/commands/swizzle.d.ts +0 -9
  191. package/lib/commands/swizzle.js +0 -245
  192. package/lib/constants.d.ts +0 -18
  193. package/lib/constants.js +0 -23
  194. package/lib/server/client-modules/index.js +0 -14
  195. package/lib/server/duplicateRoutes.d.ts +0 -10
  196. package/lib/server/duplicateRoutes.js +0 -38
  197. package/lib/server/html-tags/htmlTags.js +0 -40
  198. package/lib/server/html-tags/index.d.ts +0 -9
  199. package/lib/server/html-tags/index.js +0 -43
  200. package/lib/server/loadSetup.d.ts +0 -9
  201. package/lib/server/loadSetup.js +0 -25
  202. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
  203. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  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 -40
  208. package/lib/server/themes/index.d.ts +0 -12
  209. package/lib/server/themes/index.js +0 -47
  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,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCLIOptionPort = exports.getCLIOptionHost = void 0;
4
- const tslib_1 = require("tslib");
5
- /**
6
- * Copyright (c) Facebook, Inc. and its affiliates.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */
11
- const choosePort_1 = tslib_1.__importDefault(require("../choosePort"));
12
- const constants_1 = require("../constants");
13
- function getCLIOptionHost(hostOption) {
14
- return hostOption || 'localhost';
15
- }
16
- exports.getCLIOptionHost = getCLIOptionHost;
17
- async function getCLIOptionPort(portOption, host) {
18
- const basePort = portOption ? parseInt(portOption, 10) : constants_1.DEFAULT_PORT;
19
- return choosePort_1.default(host, basePort);
20
- }
21
- exports.getCLIOptionPort = getCLIOptionPort;
@@ -1,9 +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 { PluginConfig } from '@docusaurus/types';
8
- export declare function getPluginNames(plugins: PluginConfig[]): string[];
9
- export default function swizzle(siteDir: string, themeName?: string, componentName?: string, typescript?: boolean, danger?: boolean): Promise<void>;
@@ -1,245 +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.getPluginNames = void 0;
10
- const tslib_1 = require("tslib");
11
- const chalk = require("chalk");
12
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
- const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
14
- const path_1 = tslib_1.__importDefault(require("path"));
15
- const leven_1 = tslib_1.__importDefault(require("leven"));
16
- const lodash_1 = require("lodash");
17
- const constants_1 = require("../constants");
18
- const server_1 = require("../server");
19
- const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
20
- const utils_validation_1 = require("@docusaurus/utils-validation");
21
- function getPluginNames(plugins) {
22
- return plugins
23
- .filter((plugin) => typeof plugin === 'string' ||
24
- (Array.isArray(plugin) && typeof plugin[0] === 'string'))
25
- .map((plugin) => {
26
- const pluginPath = Array.isArray(plugin) ? plugin[0] : plugin;
27
- if (typeof pluginPath === 'string') {
28
- let packagePath = path_1.default.dirname(pluginPath);
29
- while (packagePath) {
30
- if (fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'package.json'))) {
31
- break;
32
- }
33
- else {
34
- packagePath = path_1.default.dirname(packagePath);
35
- }
36
- }
37
- if (packagePath === '.') {
38
- return pluginPath;
39
- }
40
- return import_fresh_1.default(path_1.default.join(packagePath, 'package.json')).name;
41
- }
42
- return '';
43
- })
44
- .filter((plugin) => plugin !== '');
45
- }
46
- exports.getPluginNames = getPluginNames;
47
- const formatComponentName = (componentName) => componentName
48
- .replace(/(\/|\\)index.(js|tsx|ts|jsx)/, '')
49
- .replace(/.(js|tsx|ts|jsx)/, '');
50
- function readComponent(themePath) {
51
- function walk(dir) {
52
- let results = [];
53
- const list = fs_extra_1.default.readdirSync(dir);
54
- list.forEach((file) => {
55
- const fullPath = path_1.default.join(dir, file);
56
- const stat = fs_extra_1.default.statSync(fullPath);
57
- if (stat && stat.isDirectory()) {
58
- results = results.concat(walk(fullPath));
59
- }
60
- else if (!/\.css|\.d\.ts|\.d\.map/.test(fullPath)) {
61
- results.push(fullPath);
62
- }
63
- });
64
- return results;
65
- }
66
- return walk(themePath).map((filePath) => formatComponentName(path_1.default.relative(themePath, filePath)));
67
- }
68
- // load components from theme based on configurations
69
- function getComponentName(themePath, plugin, danger) {
70
- var _a, _b;
71
- // support both commonjs and ES style exports
72
- const getSwizzleComponentList = (_b = (_a = plugin.default) === null || _a === void 0 ? void 0 : _a.getSwizzleComponentList) !== null && _b !== void 0 ? _b : plugin.getSwizzleComponentList;
73
- if (getSwizzleComponentList) {
74
- const allowedComponent = getSwizzleComponentList();
75
- if (danger) {
76
- return readComponent(themePath);
77
- }
78
- return allowedComponent;
79
- }
80
- return readComponent(themePath);
81
- }
82
- function themeComponents(themePath, plugin) {
83
- const components = colorCode(themePath, plugin);
84
- if (components.length === 0) {
85
- return `${chalk.red('No component to swizzle.')}`;
86
- }
87
- return `
88
- ${chalk.cyan('Theme components available for swizzle.')}
89
-
90
- ${chalk.green('green =>')} safe: lower breaking change risk
91
- ${chalk.red('red =>')} unsafe: higher breaking change risk
92
-
93
- ${components.join('\n')}
94
- `;
95
- }
96
- function formattedThemeNames(themeNames) {
97
- return `Themes available for swizzle:\n- ${themeNames.join('\n- ')}`;
98
- }
99
- function colorCode(themePath, plugin) {
100
- var _a, _b;
101
- // support both commonjs and ES style exports
102
- const getSwizzleComponentList = (_b = (_a = plugin.default) === null || _a === void 0 ? void 0 : _a.getSwizzleComponentList) !== null && _b !== void 0 ? _b : plugin.getSwizzleComponentList;
103
- const components = readComponent(themePath);
104
- const allowedComponent = getSwizzleComponentList
105
- ? getSwizzleComponentList()
106
- : [];
107
- const [greenComponents, redComponents] = lodash_1.partition(components, (comp) => allowedComponent.includes(comp));
108
- return [
109
- ...greenComponents.map((component) => chalk.green(`safe: ${component}`)),
110
- ...redComponents.map((component) => chalk.red(`unsafe: ${component}`)),
111
- ];
112
- }
113
- async function swizzle(siteDir, themeName, componentName, typescript, danger) {
114
- var _a, _b, _c, _d, _e;
115
- const context = await server_1.loadContext(siteDir);
116
- const pluginConfigs = server_1.loadPluginConfigs(context);
117
- const pluginNames = getPluginNames(pluginConfigs);
118
- const plugins = init_1.default({
119
- pluginConfigs,
120
- context,
121
- });
122
- const themeNames = pluginNames.filter((_, index) => typescript
123
- ? plugins[index].getTypeScriptThemePath
124
- : plugins[index].getThemePath);
125
- if (!themeName) {
126
- console.log(formattedThemeNames(themeNames));
127
- process.exit(1);
128
- }
129
- let pluginModule;
130
- try {
131
- pluginModule = import_fresh_1.default(themeName);
132
- }
133
- catch {
134
- let suggestion;
135
- themeNames.forEach((name) => {
136
- if (leven_1.default(name, themeName) < 4) {
137
- suggestion = name;
138
- }
139
- });
140
- chalk.red(`Theme ${themeName} not found. ${suggestion
141
- ? `Did you mean "${suggestion}" ?`
142
- : formattedThemeNames(themeNames)}`);
143
- process.exit(1);
144
- }
145
- let pluginOptions = {};
146
- const resolvedThemeName = require.resolve(themeName);
147
- // find the plugin from list of plugin and get options if specified
148
- pluginConfigs.forEach((pluginConfig) => {
149
- // plugin can be a [string], [string,object] or string.
150
- if (Array.isArray(pluginConfig) && typeof pluginConfig[0] === 'string') {
151
- if (require.resolve(pluginConfig[0]) === resolvedThemeName) {
152
- if (pluginConfig.length === 2) {
153
- const [, options] = pluginConfig;
154
- pluginOptions = options;
155
- }
156
- }
157
- }
158
- });
159
- // support both commonjs and ES style exports
160
- const validateOptions = (_b = (_a = pluginModule.default) === null || _a === void 0 ? void 0 : _a.validateOptions) !== null && _b !== void 0 ? _b : pluginModule.validateOptions;
161
- if (validateOptions) {
162
- pluginOptions = validateOptions({
163
- validate: utils_validation_1.normalizePluginOptions,
164
- options: pluginOptions,
165
- });
166
- }
167
- // support both commonjs and ES style exports
168
- const plugin = (_c = pluginModule.default) !== null && _c !== void 0 ? _c : pluginModule;
169
- const pluginInstance = plugin(context, pluginOptions);
170
- const themePath = typescript
171
- ? (_d = pluginInstance.getTypeScriptThemePath) === null || _d === void 0 ? void 0 : _d.call(pluginInstance)
172
- : (_e = pluginInstance.getThemePath) === null || _e === void 0 ? void 0 : _e.call(pluginInstance);
173
- if (!themePath) {
174
- console.warn(chalk.yellow(typescript
175
- ? `${themeName} does not provide TypeScript theme code via "getTypeScriptThemePath()".`
176
- : `${themeName} does not provide any theme code.`));
177
- process.exit(1);
178
- }
179
- if (!componentName) {
180
- console.warn(themeComponents(themePath, pluginModule));
181
- process.exit(1);
182
- }
183
- const components = getComponentName(themePath, pluginModule, Boolean(danger));
184
- const formattedComponentName = formatComponentName(componentName);
185
- const isComponentExists = components.find((component) => component === formattedComponentName);
186
- let mostSuitableComponent = componentName;
187
- if (!isComponentExists) {
188
- let mostSuitableMatch = componentName;
189
- let score = formattedComponentName.length;
190
- components.forEach((component) => {
191
- if (component.toLowerCase() === formattedComponentName.toLowerCase()) {
192
- // may be components with same lowercase key, try to match closest component
193
- const currentScore = leven_1.default(formattedComponentName, component);
194
- if (currentScore < score) {
195
- score = currentScore;
196
- mostSuitableMatch = component;
197
- }
198
- }
199
- });
200
- if (mostSuitableMatch !== componentName) {
201
- mostSuitableComponent = mostSuitableMatch;
202
- console.log(chalk.red(`Component "${componentName}" doesn't exist.`), chalk.yellow(`"${mostSuitableComponent}" is swizzled instead of "${componentName}".`));
203
- }
204
- }
205
- let fromPath = path_1.default.join(themePath, mostSuitableComponent);
206
- let toPath = path_1.default.resolve(siteDir, constants_1.THEME_PATH, mostSuitableComponent);
207
- // Handle single TypeScript/JavaScript file only.
208
- // E.g: if <fromPath> does not exist, we try to swizzle <fromPath>.(ts|tsx|js) instead
209
- if (!fs_extra_1.default.existsSync(fromPath)) {
210
- if (fs_extra_1.default.existsSync(`${fromPath}.ts`)) {
211
- [fromPath, toPath] = [`${fromPath}.ts`, `${toPath}.ts`];
212
- }
213
- else if (fs_extra_1.default.existsSync(`${fromPath}.tsx`)) {
214
- [fromPath, toPath] = [`${fromPath}.tsx`, `${toPath}.tsx`];
215
- }
216
- else if (fs_extra_1.default.existsSync(`${fromPath}.js`)) {
217
- [fromPath, toPath] = [`${fromPath}.js`, `${toPath}.js`];
218
- }
219
- else {
220
- let suggestion;
221
- components.forEach((name) => {
222
- if (leven_1.default(name, mostSuitableComponent) < 3) {
223
- suggestion = name;
224
- }
225
- });
226
- console.warn(chalk.red(`Component ${mostSuitableComponent} not found.`));
227
- console.warn(suggestion
228
- ? `Did you mean "${suggestion}"?`
229
- : `${themeComponents(themePath, pluginModule)}`);
230
- process.exit(1);
231
- }
232
- }
233
- if (!components.includes(mostSuitableComponent) && !danger) {
234
- console.warn(chalk.red(`${mostSuitableComponent} is an internal component and has a higher breaking change probability. If you want to swizzle it, use the "--danger" flag.`));
235
- process.exit(1);
236
- }
237
- await fs_extra_1.default.copy(fromPath, toPath);
238
- const relativeDir = path_1.default.relative(process.cwd(), toPath);
239
- const fromMsg = chalk.blue(mostSuitableComponent
240
- ? `${themeName} ${chalk.yellow(mostSuitableComponent)}`
241
- : themeName);
242
- const toMsg = chalk.cyan(relativeDir);
243
- console.log(`\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`);
244
- }
245
- exports.default = swizzle;
@@ -1,18 +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
- export declare const NODE_MAJOR_VERSION: number;
8
- export declare const NODE_MINOR_VERSION: number;
9
- export declare const DEFAULT_BUILD_DIR_NAME = "build";
10
- export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config.js";
11
- export declare const BABEL_CONFIG_FILE_NAME: string;
12
- export declare const GENERATED_FILES_DIR_NAME: string;
13
- export declare const SRC_DIR_NAME = "src";
14
- export declare const STATIC_DIR_NAME = "static";
15
- export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
16
- export declare const THEME_PATH: string;
17
- export declare const DEFAULT_PORT = 3000;
18
- export declare const DEFAULT_PLUGIN_ID = "default";
package/lib/constants.js DELETED
@@ -1,23 +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.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
- exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
11
- exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
12
- // Can be overridden with cli option --out-dir
13
- exports.DEFAULT_BUILD_DIR_NAME = 'build';
14
- // Can be overridden with cli option --config
15
- exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
16
- exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
17
- exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
18
- exports.SRC_DIR_NAME = 'src';
19
- exports.STATIC_DIR_NAME = 'static';
20
- exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
21
- exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
22
- exports.DEFAULT_PORT = 3000;
23
- exports.DEFAULT_PLUGIN_ID = 'default';
@@ -1,14 +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
- function loadClientModules(plugins) {
10
- return [].concat(...plugins
11
- .map((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; })
12
- .filter(Boolean));
13
- }
14
- exports.default = loadClientModules;
@@ -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 { ReportingSeverity, RouteConfig } from '@docusaurus/types';
8
- export declare function getAllDuplicateRoutes(pluginsRouteConfigs: RouteConfig[]): string[];
9
- export declare function getDuplicateRoutesMessage(allDuplicateRoutes: string[]): string;
10
- export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getAllDuplicateRoutes = void 0;
4
- const utils_1 = require("@docusaurus/utils");
5
- const utils_2 = require("./utils");
6
- function getAllDuplicateRoutes(pluginsRouteConfigs) {
7
- const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
8
- const seenRoutes = {};
9
- return allRoutes.filter((route) => {
10
- if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
11
- return true;
12
- }
13
- else {
14
- seenRoutes[route] = true;
15
- return false;
16
- }
17
- });
18
- }
19
- exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
20
- function getDuplicateRoutesMessage(allDuplicateRoutes) {
21
- const message = allDuplicateRoutes
22
- .map((duplicateRoute) => `Attempting to create page at ${duplicateRoute}, but a page already exists at this route`)
23
- .join('\n');
24
- return message;
25
- }
26
- exports.getDuplicateRoutesMessage = getDuplicateRoutesMessage;
27
- function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
28
- if (onDuplicateRoutes === 'ignore') {
29
- return;
30
- }
31
- const duplicatePaths = getAllDuplicateRoutes(pluginsRouteConfigs);
32
- const message = getDuplicateRoutesMessage(duplicatePaths);
33
- if (message) {
34
- const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
35
- utils_1.reportMessage(finalMessage, onDuplicateRoutes);
36
- }
37
- }
38
- exports.handleDuplicateRoutes = handleDuplicateRoutes;
@@ -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 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"));
14
- function assertIsHtmlTagObject(val) {
15
- if (!lodash_1.isPlainObject(val)) {
16
- throw new Error(`"${val}" is not a valid HTML tag object.`);
17
- }
18
- // @ts-expect-error: If tagName doesn't exist, it will throw.
19
- if (typeof val.tagName !== 'string') {
20
- throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
21
- }
22
- }
23
- function htmlTagObjectToString(tagDefinition) {
24
- assertIsHtmlTagObject(tagDefinition);
25
- if (html_tags_1.default.indexOf(tagDefinition.tagName) === -1) {
26
- throw new Error(`Error loading ${JSON.stringify(tagDefinition)}, "${tagDefinition.tagName}" is not a valid HTML tags.`);
27
- }
28
- const isVoidTag = void_1.default.indexOf(tagDefinition.tagName) !== -1;
29
- const tagAttributes = tagDefinition.attributes || {};
30
- const attributes = Object.keys(tagAttributes)
31
- .filter((attributeName) => tagAttributes[attributeName] !== false)
32
- .map((attributeName) => {
33
- if (tagAttributes[attributeName] === true) {
34
- return attributeName;
35
- }
36
- return `${attributeName}="${escape_html_1.default(tagAttributes[attributeName])}"`;
37
- });
38
- return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${(!isVoidTag && tagDefinition.innerHTML) || ''}${isVoidTag ? '' : `</${tagDefinition.tagName}>`}`;
39
- }
40
- exports.default = htmlTagObjectToString;
@@ -1,9 +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 { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
8
- export declare function createHtmlTagsString(tags: HtmlTags): string;
9
- export declare function loadHtmlTags(plugins: LoadedPlugin[]): InjectedHtmlTags;
@@ -1,43 +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.loadHtmlTags = exports.createHtmlTagsString = void 0;
10
- const tslib_1 = require("tslib");
11
- const htmlTags_1 = tslib_1.__importDefault(require("./htmlTags"));
12
- function toString(val) {
13
- return typeof val === 'string' ? val : htmlTags_1.default(val);
14
- }
15
- function createHtmlTagsString(tags) {
16
- return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
17
- }
18
- exports.createHtmlTagsString = createHtmlTagsString;
19
- function loadHtmlTags(plugins) {
20
- const htmlTags = plugins.reduce((acc, plugin) => {
21
- if (!plugin.injectHtmlTags) {
22
- return acc;
23
- }
24
- const { headTags, preBodyTags, postBodyTags } = plugin.injectHtmlTags({ content: plugin.content }) || {};
25
- return {
26
- headTags: headTags
27
- ? `${acc.headTags}\n${createHtmlTagsString(headTags)}`
28
- : acc.headTags,
29
- preBodyTags: preBodyTags
30
- ? `${acc.preBodyTags}\n${createHtmlTagsString(preBodyTags)}`
31
- : acc.preBodyTags,
32
- postBodyTags: postBodyTags
33
- ? `${acc.postBodyTags}\n${createHtmlTagsString(postBodyTags)}`
34
- : acc.postBodyTags,
35
- };
36
- }, { headTags: '', preBodyTags: '', postBodyTags: '' });
37
- return {
38
- headTags: htmlTags.headTags.trim(),
39
- preBodyTags: htmlTags.preBodyTags.trim(),
40
- postBodyTags: htmlTags.postBodyTags.trim(),
41
- };
42
- }
43
- exports.loadHtmlTags = loadHtmlTags;
@@ -1,9 +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 { Props } from '@docusaurus/types';
8
- declare const loadSetup: (name: string) => Promise<Props>;
9
- export default loadSetup;
@@ -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 tslib_1 = require("tslib");
10
- const path_1 = tslib_1.__importDefault(require("path"));
11
- const index_1 = require("./index");
12
- // Helper methods to setup dummy/fake projects.
13
- const loadSetup = async (name) => {
14
- const fixtures = path_1.default.join(__dirname, '__tests__', '__fixtures__');
15
- const simpleSite = path_1.default.join(fixtures, 'simple-site');
16
- const customSite = path_1.default.join(fixtures, 'custom-site');
17
- switch (name) {
18
- case 'custom':
19
- return index_1.load(customSite);
20
- case 'simple':
21
- default:
22
- return index_1.load(simpleSite);
23
- }
24
- };
25
- exports.default = loadSetup;
@@ -1,9 +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 { RouteConfig } from '@docusaurus/types';
8
- import { ApplyTrailingSlashParams } from '@docusaurus/utils-common';
9
- export default function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
@@ -1,19 +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 utils_common_1 = require("@docusaurus/utils-common");
10
- function applyRouteTrailingSlash(route, params) {
11
- return {
12
- ...route,
13
- path: utils_common_1.applyTrailingSlash(route.path, params),
14
- ...(route.routes && {
15
- routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
16
- }),
17
- };
18
- }
19
- exports.default = applyRouteTrailingSlash;
@@ -1,11 +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 { LoadContext, PluginConfig } from '@docusaurus/types';
8
- export default function loadPresets(context: LoadContext): {
9
- plugins: PluginConfig[];
10
- themes: PluginConfig[];
11
- };
@@ -1,48 +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 module_1 = tslib_1.__importDefault(require("module"));
11
- const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
12
- function loadPresets(context) {
13
- // We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json
14
- // declares the dependency on these plugins.
15
- // We need to fallback to createRequireFromPath since createRequire is only available in node v12.
16
- // See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
17
- const createRequire = module_1.default.createRequire || module_1.default.createRequireFromPath;
18
- const pluginRequire = createRequire(context.siteConfigPath);
19
- const presets = (context.siteConfig || {}).presets || [];
20
- const unflatPlugins = [];
21
- const unflatThemes = [];
22
- presets.forEach((presetItem) => {
23
- let presetModuleImport;
24
- let presetOptions = {};
25
- if (typeof presetItem === 'string') {
26
- presetModuleImport = presetItem;
27
- }
28
- else if (Array.isArray(presetItem)) {
29
- [presetModuleImport, presetOptions = {}] = presetItem;
30
- }
31
- else {
32
- throw new Error('Invalid presets format detected in config.');
33
- }
34
- const presetModule = import_fresh_1.default(pluginRequire.resolve(presetModuleImport));
35
- const preset = (presetModule.default || presetModule)(context, presetOptions);
36
- if (preset.plugins) {
37
- unflatPlugins.push(preset.plugins);
38
- }
39
- if (preset.themes) {
40
- unflatThemes.push(preset.themes);
41
- }
42
- });
43
- return {
44
- plugins: [].concat(...unflatPlugins).filter(Boolean),
45
- themes: [].concat(...unflatThemes).filter(Boolean),
46
- };
47
- }
48
- exports.default = loadPresets;
@@ -1,8 +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 } from '@docusaurus/types';
8
- export default function themeAlias(themePath: string, addOriginalAlias: boolean): ThemeAliases;
@@ -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;