@docusaurus/core 0.0.0-4898 → 0.0.0-4902
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.
|
@@ -4,17 +4,26 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import { matchRoutes } from 'react-router-config';
|
|
8
|
+
import routes from '@generated/routes';
|
|
7
9
|
// Memoize previously normalized pathnames.
|
|
8
|
-
const pathnames =
|
|
10
|
+
const pathnames = new Map();
|
|
9
11
|
export default function normalizeLocation(location) {
|
|
10
|
-
if (pathnames
|
|
12
|
+
if (pathnames.has(location.pathname)) {
|
|
11
13
|
return {
|
|
12
14
|
...location,
|
|
13
|
-
pathname: pathnames
|
|
15
|
+
pathname: pathnames.get(location.pathname),
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
// If the location was registered with an `.html` extension, we don't strip it
|
|
19
|
+
// away, or it will render to a 404 page.
|
|
20
|
+
const matchedRoutes = matchRoutes(routes, location.pathname);
|
|
21
|
+
if (matchedRoutes.some(({ route }) => route.exact === true)) {
|
|
22
|
+
pathnames.set(location.pathname, location.pathname);
|
|
23
|
+
return location;
|
|
24
|
+
}
|
|
25
|
+
const pathname = location.pathname.trim().replace(/(?:\/index)?\.html$/, '') || '/';
|
|
26
|
+
pathnames.set(location.pathname, pathname);
|
|
18
27
|
return {
|
|
19
28
|
...location,
|
|
20
29
|
pathname,
|
|
@@ -18,6 +18,25 @@ const common_1 = require("./common");
|
|
|
18
18
|
const tables_1 = require("./tables");
|
|
19
19
|
const actions_1 = require("./actions");
|
|
20
20
|
const formatComponentName = (componentName) => componentName.replace(/[/\\]index\.[jt]sx?/, '').replace(/\.[jt]sx?/, '');
|
|
21
|
+
function sortComponentNames(componentNames) {
|
|
22
|
+
return componentNames.sort(); // Algo may change?
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Expand a list of components to include and return parent folders.
|
|
26
|
+
* If a folder is not directly a component (no Folder/index.tsx file),
|
|
27
|
+
* we still want to be able to swizzle --eject that folder.
|
|
28
|
+
* See https://github.com/facebook/docusaurus/pull/7175#issuecomment-1103757218
|
|
29
|
+
*
|
|
30
|
+
* @param componentNames the original list of component names
|
|
31
|
+
*/
|
|
32
|
+
function getMissingIntermediateComponentFolderNames(componentNames) {
|
|
33
|
+
function getAllIntermediatePaths(componentName) {
|
|
34
|
+
const paths = componentName.split('/');
|
|
35
|
+
return lodash_1.default.range(1, paths.length + 1).map((i) => paths.slice(0, i).join('/'));
|
|
36
|
+
}
|
|
37
|
+
const expandedComponentNames = lodash_1.default.uniq(componentNames.flatMap((componentName) => getAllIntermediatePaths(componentName)));
|
|
38
|
+
return lodash_1.default.difference(expandedComponentNames, componentNames);
|
|
39
|
+
}
|
|
21
40
|
const skipReadDirNames = ['__test__', '__tests__', '__mocks__', '__fixtures__'];
|
|
22
41
|
async function readComponentNames(themePath) {
|
|
23
42
|
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
@@ -48,8 +67,8 @@ async function readComponentNames(themePath) {
|
|
|
48
67
|
}))).flat();
|
|
49
68
|
}
|
|
50
69
|
const componentFiles = await walk(themePath);
|
|
51
|
-
const
|
|
52
|
-
return
|
|
70
|
+
const componentNames = componentFiles.map((f) => f.componentName);
|
|
71
|
+
return sortComponentNames(componentNames);
|
|
53
72
|
}
|
|
54
73
|
exports.readComponentNames = readComponentNames;
|
|
55
74
|
function listComponentNames(themeComponents) {
|
|
@@ -72,11 +91,30 @@ async function getThemeComponents({ themeName, themePath, swizzleConfig, }) {
|
|
|
72
91
|
},
|
|
73
92
|
description: FallbackSwizzleComponentDescription,
|
|
74
93
|
};
|
|
75
|
-
const
|
|
94
|
+
const FallbackIntermediateFolderSwizzleComponentConfig = {
|
|
95
|
+
actions: {
|
|
96
|
+
// It doesn't make sense to wrap an intermediate folder
|
|
97
|
+
// because it has not any index component
|
|
98
|
+
wrap: 'forbidden',
|
|
99
|
+
eject: FallbackSwizzleActionStatus,
|
|
100
|
+
},
|
|
101
|
+
description: FallbackSwizzleComponentDescription,
|
|
102
|
+
};
|
|
103
|
+
const allInitialComponents = await readComponentNames(themePath);
|
|
104
|
+
const missingIntermediateComponentFolderNames = getMissingIntermediateComponentFolderNames(allInitialComponents);
|
|
105
|
+
const allComponents = sortComponentNames(allInitialComponents.concat(missingIntermediateComponentFolderNames));
|
|
76
106
|
function getConfig(component) {
|
|
77
107
|
if (!allComponents.includes(component)) {
|
|
78
108
|
throw new Error(`Can't get component config: component doesn't exist: ${component}`);
|
|
79
109
|
}
|
|
110
|
+
const config = swizzleConfig.components[component];
|
|
111
|
+
if (config) {
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
const isIntermediateFolder = missingIntermediateComponentFolderNames.includes(component);
|
|
115
|
+
if (isIntermediateFolder) {
|
|
116
|
+
return FallbackIntermediateFolderSwizzleComponentConfig;
|
|
117
|
+
}
|
|
80
118
|
return (swizzleConfig.components[component] ?? FallbackSwizzleComponentConfig);
|
|
81
119
|
}
|
|
82
120
|
function getDescription(component) {
|
|
@@ -36,20 +36,23 @@ function getModuleSwizzleConfig(swizzlePlugin) {
|
|
|
36
36
|
}
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const result =
|
|
39
|
+
const SwizzleConfigSchema = utils_validation_1.Joi.object({
|
|
40
|
+
components: utils_validation_1.Joi.object()
|
|
41
|
+
.pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
42
|
+
actions: utils_validation_1.Joi.object().pattern(utils_validation_1.Joi.string().valid(...common_1.SwizzleActions), utils_validation_1.Joi.string().valid(...common_1.SwizzleActionsStatuses)),
|
|
43
|
+
description: utils_validation_1.Joi.string(),
|
|
44
|
+
}))
|
|
45
|
+
.required(),
|
|
46
|
+
});
|
|
47
|
+
function validateSwizzleConfig(unsafeSwizzleConfig) {
|
|
48
|
+
const result = SwizzleConfigSchema.validate(unsafeSwizzleConfig);
|
|
49
49
|
if (result.error) {
|
|
50
50
|
throw new Error(`Swizzle config does not match expected schema: ${result.error.message}`);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
return result.value;
|
|
53
|
+
}
|
|
54
|
+
function normalizeSwizzleConfig(unsafeSwizzleConfig) {
|
|
55
|
+
const swizzleConfig = validateSwizzleConfig(unsafeSwizzleConfig);
|
|
53
56
|
// Ensure all components always declare all actions
|
|
54
57
|
Object.values(swizzleConfig.components).forEach((componentConfig) => {
|
|
55
58
|
common_1.SwizzleActions.forEach((action) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-4902",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"@babel/runtime": "^7.17.9",
|
|
42
42
|
"@babel/runtime-corejs3": "^7.17.9",
|
|
43
43
|
"@babel/traverse": "^7.17.9",
|
|
44
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
45
|
-
"@docusaurus/logger": "0.0.0-
|
|
46
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
44
|
+
"@docusaurus/cssnano-preset": "0.0.0-4902",
|
|
45
|
+
"@docusaurus/logger": "0.0.0-4902",
|
|
46
|
+
"@docusaurus/mdx-loader": "0.0.0-4902",
|
|
47
47
|
"@docusaurus/react-loadable": "5.5.2",
|
|
48
|
-
"@docusaurus/utils": "0.0.0-
|
|
49
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
50
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
48
|
+
"@docusaurus/utils": "0.0.0-4902",
|
|
49
|
+
"@docusaurus/utils-common": "0.0.0-4902",
|
|
50
|
+
"@docusaurus/utils-validation": "0.0.0-4902",
|
|
51
51
|
"@slorber/static-site-generator-webpack-plugin": "^4.0.4",
|
|
52
52
|
"@svgr/webpack": "^6.2.1",
|
|
53
53
|
"autoprefixer": "^10.4.4",
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"webpackbar": "^5.0.2"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
109
|
-
"@docusaurus/types": "0.0.0-
|
|
108
|
+
"@docusaurus/module-type-aliases": "0.0.0-4902",
|
|
109
|
+
"@docusaurus/types": "0.0.0-4902",
|
|
110
110
|
"@types/detect-port": "^1.3.2",
|
|
111
111
|
"@types/nprogress": "^0.2.0",
|
|
112
112
|
"@types/react-dom": "^18.0.1",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"engines": {
|
|
128
128
|
"node": ">=14"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "c713763cd9b8851a02dad9b8ee50ad6c5a1cc50c"
|
|
131
131
|
}
|