@docusaurus/core 0.0.0-4895 → 0.0.0-4900

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.
@@ -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 componentFilesOrdered = lodash_1.default.orderBy(componentFiles, [(f) => f.componentName], ['asc']);
52
- return componentFilesOrdered.map((f) => f.componentName);
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 allComponents = await readComponentNames(themePath);
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
- function normalizeSwizzleConfig(unsafeSwizzleConfig) {
40
- const schema = utils_validation_1.Joi.object({
41
- components: utils_validation_1.Joi.object()
42
- .pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
43
- 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)),
44
- description: utils_validation_1.Joi.string(),
45
- }))
46
- .required(),
47
- });
48
- const result = schema.validate(unsafeSwizzleConfig);
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
- const swizzleConfig = result.value;
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-4895",
4
+ "version": "0.0.0-4900",
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-4895",
45
- "@docusaurus/logger": "0.0.0-4895",
46
- "@docusaurus/mdx-loader": "0.0.0-4895",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4900",
45
+ "@docusaurus/logger": "0.0.0-4900",
46
+ "@docusaurus/mdx-loader": "0.0.0-4900",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4895",
49
- "@docusaurus/utils-common": "0.0.0-4895",
50
- "@docusaurus/utils-validation": "0.0.0-4895",
48
+ "@docusaurus/utils": "0.0.0-4900",
49
+ "@docusaurus/utils-common": "0.0.0-4900",
50
+ "@docusaurus/utils-validation": "0.0.0-4900",
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-4895",
109
- "@docusaurus/types": "0.0.0-4895",
108
+ "@docusaurus/module-type-aliases": "0.0.0-4900",
109
+ "@docusaurus/types": "0.0.0-4900",
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": "8845bdf725b98ed6da91b2270a8a3d268bce3fa4"
130
+ "gitHead": "2b685fb483506ef5f6eb97d4a48b8524e3ce3ce9"
131
131
  }