@mui/codemod 5.11.14 → 5.12.2

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/README.md CHANGED
@@ -62,6 +62,21 @@ npx @mui/codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"
62
62
 
63
63
  ### v5.0.0
64
64
 
65
+ #### `base-remove-component-prop`
66
+
67
+ Remove `component` prop from all Base UI components by transferring its value into `slots.root`.
68
+
69
+ This change only affects Base UI components.
70
+
71
+ ```diff
72
+ - <Input component={CustomRoot} />
73
+ + <Input slots={{ root: CustomRoot }} />
74
+ ```
75
+
76
+ ```sh
77
+ npx @mui/codemod v5.0.0/base-remove-component-prop <path>
78
+ ```
79
+
65
80
  #### `rename-css-variables`
66
81
 
67
82
  Updates the names of the CSS variables of the Joy UI components to adapt to the new naming standards of the CSS variables for components.
@@ -79,7 +94,7 @@ npx @mui/codemod v5.0.0/rename-css-variables <path>
79
94
 
80
95
  #### `base-hook-imports`
81
96
 
82
- Updates the sources of the imports of the MUI Base hooks to adapt to the new directories of the hooks.
97
+ Updates the sources of the imports of the Base UI hooks to adapt to the new directories of the hooks.
83
98
 
84
99
  ```diff
85
100
  - import { useBadge } from '@mui/base/BadgeUnstyled';
@@ -397,7 +412,7 @@ You can find more details about this breaking change in [the migration guide](ht
397
412
  Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
398
413
  Also, changes `slots`' fields names to camelCase.
399
414
 
400
- This change only affects MUI Base components.
415
+ This change only affects Base UI components.
401
416
 
402
417
  ```diff
403
418
  <BadgeUnstyled
package/codemod.js CHANGED
File without changes
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ /**
8
+ * @param {import('jscodeshift').FileInfo} file
9
+ * @param {import('jscodeshift').API} api
10
+ */
11
+ function transformer(file, api, options) {
12
+ const j = api.jscodeshift;
13
+ const root = j(file.source);
14
+ const printOptions = options.printOptions;
15
+ const transformed = root.find(j.ImportDeclaration)
16
+ // Process only Base UI components
17
+ .filter(({
18
+ node
19
+ }) => node.source.value.startsWith('@mui/base')).forEach(path => {
20
+ path.node.specifiers.forEach(elementNode => {
21
+ root.findJSXElements(elementNode.local.name).forEach(elementPath => {
22
+ if (elementPath.node.type !== 'JSXElement') {
23
+ return;
24
+ }
25
+ const attributeNodes = [];
26
+ let slotPropNodeInserted = false;
27
+ let slotsPropNode;
28
+ elementPath.node.openingElement.attributes.forEach(attributeNode => {
29
+ if (attributeNode.type !== 'JSXAttribute' && attributeNode.type !== 'JSXSpreadAttribute') {
30
+ return;
31
+ }
32
+ if (attributeNode.type === 'JSXSpreadAttribute') {
33
+ attributeNodes.push(attributeNode);
34
+ return;
35
+ }
36
+ const attributeName = attributeNode.name.name;
37
+ if (attributeName !== 'component' && attributeName !== 'slots') {
38
+ attributeNodes.push(attributeNode);
39
+ return;
40
+ }
41
+ if (attributeName === 'component') {
42
+ const valueNode = attributeNode.value.expression || attributeNode.value;
43
+ const rootObject = j.objectProperty(j.identifier('root'), valueNode);
44
+ if (slotsPropNode && slotsPropNode.value.expression) {
45
+ slotsPropNode.value.expression.properties.push(rootObject);
46
+ } else {
47
+ slotsPropNode = j.jsxAttribute(j.jsxIdentifier('slots'), j.jsxExpressionContainer(j.objectExpression([rootObject])));
48
+ if (!slotPropNodeInserted) {
49
+ slotPropNodeInserted = true;
50
+ attributeNodes.push(slotsPropNode);
51
+ }
52
+ }
53
+ if (file.path.endsWith('.ts') || file.path.endsWith('.tsx')) {
54
+ if (valueNode.type === 'Literal' && valueNode.value && valueNode.raw) {
55
+ elementPath.node.openingElement.name.name += `<${valueNode.raw}>`;
56
+ } else if (valueNode.type === 'Identifier' && valueNode.name) {
57
+ elementPath.node.openingElement.name.name += `<typeof ${valueNode.name}>`;
58
+ }
59
+ }
60
+ }
61
+ if (attributeName === 'slots') {
62
+ if (slotsPropNode && slotsPropNode.value.expression && attributeNode.value.expression) {
63
+ slotsPropNode.value.expression.properties = [...slotsPropNode.value.expression.properties, ...attributeNode.value.expression.properties];
64
+ } else {
65
+ slotsPropNode = attributeNode;
66
+ }
67
+ if (!slotPropNodeInserted) {
68
+ slotPropNodeInserted = true;
69
+ attributeNodes.push(slotsPropNode);
70
+ }
71
+ }
72
+ });
73
+ elementPath.node.openingElement.attributes = attributeNodes;
74
+ });
75
+ });
76
+ });
77
+ return transformed.toSource(printOptions);
78
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
+ var _Input = _interopRequireDefault(require("@mui/material/Input"));
6
+ var _Input2 = _interopRequireDefault(require("@mui/base/Input"));
7
+ var _Switch = _interopRequireDefault(require("@mui/base/Switch"));
8
+ var _Badge = _interopRequireDefault(require("@mui/base/Badge"));
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ // @ts-nocheck
11
+
12
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input.default, {
13
+ component: CustomRoot
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, {
16
+ component: CustomRoot
17
+ });
18
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, (0, _extends2.default)({
19
+ component: CustomRoot
20
+ }, others));
21
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Switch.default, {
22
+ component: CustomRoot,
23
+ randomProp: "1",
24
+ randomProp2: "2",
25
+ randomProp3: "3",
26
+ slotProps: {
27
+ root: {
28
+ className: 'root'
29
+ }
30
+ }
31
+ });
32
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Badge.default, {
33
+ slots: {
34
+ badge: CustomBadge
35
+ },
36
+ component: CustomRoot,
37
+ randomProp: "1",
38
+ randomProp2: "2",
39
+ randomProp3: "3",
40
+ slotProps: {
41
+ badge: {
42
+ className: 'badge'
43
+ }
44
+ }
45
+ });
46
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, {
47
+ component: "a",
48
+ href: "url"
49
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
+ var _Input = _interopRequireDefault(require("@mui/material/Input"));
6
+ var _Input2 = _interopRequireDefault(require("@mui/base/Input"));
7
+ var _Switch = _interopRequireDefault(require("@mui/base/Switch"));
8
+ var _Badge = _interopRequireDefault(require("@mui/base/Badge"));
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ // @ts-nocheck
11
+
12
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input.default, {
13
+ component: CustomRoot
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, {
16
+ slots: {
17
+ root: CustomRoot
18
+ }
19
+ });
20
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, (0, _extends2.default)({
21
+ slots: {
22
+ root: CustomRoot
23
+ }
24
+ }, others));
25
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Switch.default, {
26
+ slots: {
27
+ root: CustomRoot
28
+ },
29
+ randomProp: "1",
30
+ randomProp2: "2",
31
+ randomProp3: "3",
32
+ slotProps: {
33
+ root: {
34
+ className: 'root'
35
+ }
36
+ }
37
+ });
38
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Badge.default, {
39
+ slots: {
40
+ badge: CustomBadge,
41
+ root: CustomRoot
42
+ },
43
+ randomProp: "1",
44
+ randomProp2: "2",
45
+ randomProp3: "3",
46
+ slotProps: {
47
+ badge: {
48
+ className: 'badge'
49
+ }
50
+ }
51
+ });
52
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Input2.default, {
53
+ slots: {
54
+ root: 'a'
55
+ },
56
+ href: "url"
57
+ });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ /**
8
+ * @param {import('jscodeshift').FileInfo} file
9
+ * @param {import('jscodeshift').API} api
10
+ */
11
+ function transformer(file, api) {
12
+ const j = api.jscodeshift;
13
+ const root = j(file.source);
14
+ const transformed = root.find(j.ImportDeclaration).filter(({
15
+ node
16
+ }) => {
17
+ const sourceVal = node.source.value;
18
+ if (sourceVal.startsWith('@mui/base')) {
19
+ node.source.value = sourceVal.replace(/unstyled/im, '');
20
+ node.source.raw = sourceVal.replace(/unstyled/im, '');
21
+ }
22
+ return sourceVal.startsWith('@mui/base');
23
+ }).forEach(path => {
24
+ const specifiers = [];
25
+ path.node.specifiers.forEach(elementNode => {
26
+ var _elementNode$imported;
27
+ const importedName = ((_elementNode$imported = elementNode.imported) == null ? void 0 : _elementNode$imported.name) || '';
28
+ if (elementNode.type === 'ImportSpecifier' && importedName.match(/unstyled/im)) {
29
+ elementNode.imported.name = importedName.replace(/unstyled/im, '');
30
+ if (elementNode.local.name === importedName) {
31
+ // specifier must be newly created to add "as";
32
+ // e.g., import { SwitchUnstyled } to import { Switch as SwitchUnstyled}
33
+ specifiers.push(j.importSpecifier(elementNode.imported, elementNode.local));
34
+ return;
35
+ }
36
+ }
37
+ specifiers.push(elementNode);
38
+ });
39
+ path.node.specifiers = specifiers;
40
+ }).toSource();
41
+ return transformed;
42
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _ButtonUnstyled2 = _interopRequireWildcard(require("@mui/base/ButtonUnstyled"));
5
+ var _base = require("@mui/base");
6
+ var _Slider = _interopRequireDefault(require("@mui/base/Slider"));
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _ButtonUnstyled, _SwitchUnstyled, _BaseInput, _BaseSlider;
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ function App() {
12
+ return;
13
+ /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
14
+ children: [_ButtonUnstyled || (_ButtonUnstyled = /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonUnstyled2.default, {})), ";", _SwitchUnstyled || (_SwitchUnstyled = /*#__PURE__*/(0, _jsxRuntime.jsx)(_base.SwitchUnstyled, {})), ";", _BaseInput || (_BaseInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_base.InputUnstyled, {})), ";", _BaseSlider || (_BaseSlider = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Slider.default, {})), ";"]
15
+ });
16
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Button = _interopRequireWildcard(require("@mui/base/Button"));
5
+ var _base = require("@mui/base");
6
+ var _Slider = _interopRequireDefault(require("@mui/base/Slider"));
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _ButtonUnstyled, _SwitchUnstyled, _BaseInput, _BaseSlider;
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ function App() {
12
+ return;
13
+ /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
14
+ children: [_ButtonUnstyled || (_ButtonUnstyled = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {})), ";", _SwitchUnstyled || (_SwitchUnstyled = /*#__PURE__*/(0, _jsxRuntime.jsx)(_base.Switch, {})), ";", _BaseInput || (_BaseInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_base.Input, {})), ";", _BaseSlider || (_BaseSlider = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Slider.default, {})), ";"]
15
+ });
16
+ }
@@ -30,7 +30,7 @@ function transformer(file, api, options) {
30
30
  if (node.imported.name === 'Theme') {
31
31
  hasTheme = true;
32
32
  }
33
- if (node.imported.name === 'ThemeProvider' || node.imported.nmae === 'MuiThemeProvider') {
33
+ if (node.imported.name === 'ThemeProvider' || node.imported.name === 'MuiThemeProvider') {
34
34
  isRootFile = true;
35
35
  }
36
36
  });
@@ -186,7 +186,7 @@ const NewStartScreen = () => {
186
186
  }, category.name))
187
187
  });
188
188
  };
189
- function DocSearcHit(props) {
189
+ function DocSearchHit(props) {
190
190
  const {
191
191
  children,
192
192
  hit
@@ -205,7 +205,7 @@ function DocSearcHit(props) {
205
205
  text = 'Joy UI';
206
206
  }
207
207
  if (pathname.startsWith('/base/')) {
208
- text = 'MUI Base';
208
+ text = 'Base UI';
209
209
  }
210
210
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
211
211
  label: text,
@@ -238,7 +238,7 @@ function DocSearcHit(props) {
238
238
  children: children
239
239
  });
240
240
  }
241
- process.env.NODE_ENV !== "production" ? DocSearcHit.propTypes = {
241
+ process.env.NODE_ENV !== "production" ? DocSearchHit.propTypes = {
242
242
  children: _propTypes.default.node,
243
243
  hit: _propTypes.default.object.isRequired
244
244
  } : void 0;
@@ -358,7 +358,7 @@ function AppSearch() {
358
358
  });
359
359
  });
360
360
  },
361
- hitComponent: DocSearcHit,
361
+ hitComponent: DocSearchHit,
362
362
  initialScrollY: typeof window !== 'undefined' ? window.scrollY : undefined,
363
363
  onClose: onClose,
364
364
  navigator: keyboardNavigator
@@ -186,7 +186,7 @@ const NewStartScreen = () => {
186
186
  }, category.name))
187
187
  });
188
188
  };
189
- function DocSearcHit(props) {
189
+ function DocSearchHit(props) {
190
190
  const {
191
191
  children,
192
192
  hit
@@ -205,7 +205,7 @@ function DocSearcHit(props) {
205
205
  text = 'Joy UI';
206
206
  }
207
207
  if (pathname.startsWith('/base/')) {
208
- text = 'MUI Base';
208
+ text = 'Base UI';
209
209
  }
210
210
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
211
211
  label: text,
@@ -238,7 +238,7 @@ function DocSearcHit(props) {
238
238
  children: children
239
239
  });
240
240
  }
241
- process.env.NODE_ENV !== "production" ? DocSearcHit.propTypes = {
241
+ process.env.NODE_ENV !== "production" ? DocSearchHit.propTypes = {
242
242
  children: _propTypes.default.node,
243
243
  hit: _propTypes.default.object.isRequired
244
244
  } : void 0;
@@ -358,7 +358,7 @@ function AppSearch() {
358
358
  });
359
359
  });
360
360
  },
361
- hitComponent: DocSearcHit,
361
+ hitComponent: DocSearchHit,
362
362
  initialScrollY: typeof window !== 'undefined' ? window.scrollY : undefined,
363
363
  onClose: onClose,
364
364
  navigator: keyboardNavigator
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.11.14",
3
+ "version": "5.12.2",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",