@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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.
- package/bin/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/commands/swizzle.js
DELETED
|
@@ -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;
|
package/lib/constants.d.ts
DELETED
|
@@ -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';
|
package/lib/server/loadSetup.js
DELETED
|
@@ -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,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,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;
|