@mui/codemod 5.15.8 → 5.15.10

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
@@ -1,12 +1,12 @@
1
1
  # @mui/codemod
2
2
 
3
- > Codemod scripts for MUI
3
+ > Codemod scripts for Material UI, Base UI, MUI System, Joy UI.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@mui/codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/codemod)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@mui/codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/codemod)
7
7
 
8
8
  This repository contains a collection of codemod scripts based for use with
9
- [jscodeshift](https://github.com/facebook/jscodeshift) that help update MUI APIs.
9
+ [jscodeshift](https://github.com/facebook/jscodeshift) that help update the APIs.
10
10
 
11
11
  ## Setup & run
12
12
 
@@ -80,10 +80,10 @@ A combination of all deprecations.
80
80
 
81
81
  ```diff
82
82
  <Accordion
83
- - TransitionComponent={CustomTransition}
84
- - TransitionProps={{ unmountOnExit: true }}
85
- + slots={{ transition: CustomTransition }}
86
- + slotProps={{ transition: { unmountOnExit: true } }}
83
+ - TransitionComponent={CustomTransition}
84
+ - TransitionProps={{ unmountOnExit: true }}
85
+ + slots={{ transition: CustomTransition }}
86
+ + slotProps={{ transition: { unmountOnExit: true } }}
87
87
  />
88
88
  ```
89
89
 
@@ -91,6 +91,35 @@ A combination of all deprecations.
91
91
  npx @mui/codemod@latest deprecations/accordion-props <path>
92
92
  ```
93
93
 
94
+ #### `avatar-props`
95
+
96
+ ```diff
97
+ <Avatar
98
+ - imgProps={{
99
+ - onError: () => {},
100
+ - onLoad: () => {},
101
+ + slotProps={{
102
+ + img: {
103
+ + onError: () => {},
104
+ + onLoad: () => {},
105
+ + }
106
+ }}
107
+ />;
108
+ ```
109
+
110
+ #### `divider-props`
111
+
112
+ ```diff
113
+ <Divider
114
+ - light
115
+ + sx={{opacity: "0.6"}}
116
+ />
117
+ ```
118
+
119
+ ```bash
120
+ npx @mui/codemod@latest deprecations/divider-props <path>
121
+ ```
122
+
94
123
  ### v5.0.0
95
124
 
96
125
  #### `base-use-named-exports`
@@ -102,10 +131,10 @@ See https://github.com/mui/material-ui/issues/21862 for more context.
102
131
  This codemod updates the import and re-export statements.
103
132
 
104
133
  ```diff
105
- - import BaseButton from '@mui/base/Button';
106
- + import { Button as BaseButton } from '@mui/base/Button';
107
- - export { default as BaseSlider } from '@mui/base/Slider';
108
- + export { Slider as BaseSlider } from '@mui/base/Slider';
134
+ -import BaseButton from '@mui/base/Button';
135
+ -export { default as BaseSlider } from '@mui/base/Slider';
136
+ +import { Button as BaseButton } from '@mui/base/Button';
137
+ +export { Slider as BaseSlider } from '@mui/base/Slider';
109
138
  ```
110
139
 
111
140
  ```bash
@@ -117,8 +146,8 @@ npx @mui/codemod@latest v5.0.0/base-use-named-exports <path>
117
146
  The `Unstyled` suffix has been removed from all Base UI component names, including names of types and other related identifiers.
118
147
 
119
148
  ```diff
120
- - <Input component='a' href='url' />;
121
- + <Input slots={{ root: 'a' }} href='url' />;
149
+ -<Input component='a' href='url' />;
150
+ +<Input slots={{ root: 'a' }} href='url' />;
122
151
  ```
123
152
 
124
153
  ```bash
@@ -132,8 +161,8 @@ Remove `component` prop from all Base UI components by transferring its value i
132
161
  This change only affects Base UI components.
133
162
 
134
163
  ```diff
135
- - <Input component={CustomRoot} />
136
- + <Input slots={{ root: CustomRoot }} />
164
+ -<Input component={CustomRoot} />
165
+ +<Input slots={{ root: CustomRoot }} />
137
166
  ```
138
167
 
139
168
  ```bash
@@ -145,10 +174,10 @@ npx @mui/codemod@latest v5.0.0/base-remove-component-prop <path>
145
174
  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.
146
175
 
147
176
  ```diff
148
- - <List sx={{ py: 'var(--List-divider-gap)' }}>
149
- + <List sx={{ py: 'var(--ListDivider-gap)' }}>
150
- - <Switch sx={{ '--Switch-track-width': '40px' }}>
151
- + <Switch sx={{ '--Switch-trackWidth': '40px' }}>
177
+ -<List sx={{ py: 'var(--List-divider-gap)' }}>
178
+ -<Switch sx={{ '--Switch-track-width': '40px' }}>
179
+ +<List sx={{ py: 'var(--ListDivider-gap)' }}>
180
+ +<Switch sx={{ '--Switch-trackWidth': '40px' }}>
152
181
  ```
153
182
 
154
183
  ```bash
@@ -160,8 +189,8 @@ npx @mui/codemod@latest v5.0.0/rename-css-variables <path>
160
189
  Updates the sources of the imports of the Base UI hooks to adapt to the new directories of the hooks.
161
190
 
162
191
  ```diff
163
- - import { useBadge } from '@mui/base/BadgeUnstyled';
164
- + import useBadge from '@mui/base/useBadge';
192
+ -import { useBadge } from '@mui/base/BadgeUnstyled';
193
+ +import useBadge from '@mui/base/useBadge';
165
194
  ```
166
195
 
167
196
  ```bash
@@ -283,8 +312,8 @@ This change only affects Joy UI components.
283
312
  ```diff
284
313
  <Autocomplete
285
314
  - components={{ listbox: CustomListbox }}
286
- + slots={{ listbox: CustomListbox }}
287
315
  - componentsProps={{ root: { className: 'root' }, listbox: { 'data-testid': 'listbox' } }}
316
+ + slots={{ listbox: CustomListbox }}
288
317
  + slotProps={{ root: { className: 'root' }, listbox: { 'data-testid': 'listbox' } }}
289
318
  />;
290
319
  ```
@@ -488,8 +517,8 @@ This change only affects Base UI components.
488
517
  ```diff
489
518
  <BadgeUnstyled
490
519
  - components={{ Root, Badge: CustomBadge }}
491
- + slots={{ root: Root, badge: CustomBadge }}
492
520
  - componentsProps={{ root: { className: 'root' }, badge: { 'data-testid': 'badge' } }}
521
+ + slots={{ root: Root, badge: CustomBadge }}
493
522
  + slotProps={{ root: { className: 'root' }, badge: { 'data-testid': 'badge' } }}
494
523
  />;
495
524
  ```
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = deprecationsAll;
8
- var _accordionProps = _interopRequireDefault(require("../accordion-props/accordion-props"));
8
+ var _accordionProps = _interopRequireDefault(require("../accordion-props"));
9
+ var _avatarProps = _interopRequireDefault(require("../avatar-props"));
10
+ var _dividerProps = _interopRequireDefault(require("../divider-props"));
9
11
  /**
10
12
  * @param {import('jscodeshift').FileInfo} file
11
13
  * @param {import('jscodeshift').API} api
12
14
  */
13
15
  function deprecationsAll(file, api, options) {
14
16
  file.source = (0, _accordionProps.default)(file, api, options);
17
+ file.source = (0, _avatarProps.default)(file, api, options);
18
+ file.source = (0, _dividerProps.default)(file, api, options);
15
19
  return file.source;
16
20
  }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
9
+ var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
+ var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
11
+ /**
12
+ * @param {import('jscodeshift').FileInfo} file
13
+ * @param {import('jscodeshift').API} api
14
+ */
15
+ function transformer(file, api, options) {
16
+ const j = api.jscodeshift;
17
+ const root = j(file.source);
18
+ const printOptions = options.printOptions;
19
+ (0, _findComponentJSX.default)(j, {
20
+ root,
21
+ componentName: 'Avatar'
22
+ }, elementPath => {
23
+ const index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'imgProps');
24
+ if (index !== -1) {
25
+ const removed = elementPath.node.openingElement.attributes.splice(index, 1);
26
+ let hasNode = false;
27
+ elementPath.node.openingElement.attributes.forEach(attr => {
28
+ var _attr$name;
29
+ if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slotProps') {
30
+ hasNode = true;
31
+ (0, _assignObject.default)(j, {
32
+ target: attr,
33
+ key: 'img',
34
+ expression: removed[0].value.expression
35
+ });
36
+ }
37
+ });
38
+ if (!hasNode) {
39
+ (0, _appendAttribute.default)(j, {
40
+ target: elementPath.node,
41
+ attributeName: 'slotProps',
42
+ expression: j.objectExpression([j.objectProperty(j.identifier('img'), removed[0].value.expression)])
43
+ });
44
+ }
45
+ }
46
+ });
47
+ root.find(j.ObjectProperty, {
48
+ key: {
49
+ name: 'imgProps'
50
+ }
51
+ }).forEach(path => {
52
+ var _path$parent;
53
+ if (((_path$parent = path.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.node.key) == null ? void 0 : _path$parent.name) === 'MuiAvatar') {
54
+ path.replace(j.property('init', j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier('img'), path.node.value)])));
55
+ }
56
+ });
57
+ return root.toSource(printOptions);
58
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _avatarProps.default;
11
+ }
12
+ });
13
+ var _avatarProps = _interopRequireDefault(require("./avatar-props"));
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
8
+ imgProps: {
9
+ onError: () => {},
10
+ onLoad: () => {}
11
+ }
12
+ });
13
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
14
+ imgProps: {
15
+ onError: () => {},
16
+ onLoad: () => {}
17
+ }
18
+ });
19
+
20
+ // should skip non MUI components
21
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
22
+ imgProps: {
23
+ onError: () => {},
24
+ onLoad: () => {}
25
+ }
26
+ });
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
8
+ slotProps: {
9
+ img: {
10
+ onError: () => {},
11
+ onLoad: () => {}
12
+ }
13
+ }
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
16
+ slotProps: {
17
+ img: {
18
+ onError: () => {},
19
+ onLoad: () => {}
20
+ }
21
+ }
22
+ });
23
+
24
+ // should skip non MUI components
25
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
26
+ imgProps: {
27
+ onError: () => {},
28
+ onLoad: () => {}
29
+ }
30
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiAvatar: {
5
+ defaultProps: {
6
+ imgProps: {
7
+ onError: () => {},
8
+ onLoad: () => {}
9
+ }
10
+ }
11
+ }
12
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiAvatar: {
5
+ defaultProps: {
6
+ slotProps: {
7
+ img: {
8
+ onError: () => {},
9
+ onLoad: () => {}
10
+ }
11
+ }
12
+ }
13
+ }
14
+ });
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
9
+ var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
+ var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
11
+ /**
12
+ * @param {import('jscodeshift').FileInfo} file
13
+ * @param {import('jscodeshift').API} api
14
+ */
15
+ function transformer(file, api, options) {
16
+ const j = api.jscodeshift;
17
+ const root = j(file.source);
18
+ const printOptions = options.printOptions;
19
+ (0, _findComponentJSX.default)(j, {
20
+ root,
21
+ componentName: 'Divider'
22
+ }, elementPath => {
23
+ elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter(attr => {
24
+ if (attr.type === 'JSXAttribute' && attr.name.name === 'light') {
25
+ return false;
26
+ }
27
+ return true;
28
+ });
29
+ const sxIndex = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'sx');
30
+ if (sxIndex === -1) {
31
+ (0, _appendAttribute.default)(j, {
32
+ target: elementPath.node,
33
+ attributeName: 'sx',
34
+ expression: j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])
35
+ });
36
+ } else {
37
+ const opacityIndex = elementPath.node.openingElement.attributes[sxIndex].value.expression.properties.findIndex(key => key.key.name === 'opacity');
38
+ if (opacityIndex === -1) {
39
+ (0, _assignObject.default)(j, {
40
+ target: elementPath.node.openingElement.attributes[sxIndex],
41
+ key: 'opacity',
42
+ expression: j.literal('0.6')
43
+ });
44
+ }
45
+ }
46
+ });
47
+ root.find(j.ObjectProperty, {
48
+ key: {
49
+ name: 'MuiDivider'
50
+ }
51
+ }).forEach(path => {
52
+ const defaultPropsObject = path.value.value.properties.find(key => key.key.name === 'defaultProps');
53
+ defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter(prop => {
54
+ var _prop$key;
55
+ return !['light'].includes(prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name);
56
+ });
57
+ const sxIndex = defaultPropsObject.value.properties.findIndex(prop => prop.key.name === 'sx');
58
+ if (sxIndex === -1) {
59
+ defaultPropsObject.value.properties.push(j.objectProperty(j.identifier('sx'), j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])));
60
+ } else {
61
+ const opacityIndex = defaultPropsObject.value.properties[sxIndex].value.properties.findIndex(key => key.key.name === 'opacity');
62
+ if (opacityIndex === -1) {
63
+ defaultPropsObject.value.properties[sxIndex].value.properties.push(j.objectProperty(j.identifier('opacity'), j.literal('0.6')));
64
+ }
65
+ }
66
+ });
67
+ return root.toSource(printOptions);
68
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _dividerProps.default;
11
+ }
12
+ });
13
+ var _dividerProps = _interopRequireDefault(require("./divider-props"));
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
8
+ light: true,
9
+ className: "test"
10
+ });
11
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
12
+ light: true,
13
+ className: "test"
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
16
+ light: false,
17
+ className: "test"
18
+ });
19
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
20
+ light: false,
21
+ className: "test"
22
+ });
23
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
24
+ light: light,
25
+ className: "test"
26
+ });
27
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
28
+ light: light,
29
+ className: "test"
30
+ });
31
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
32
+ light: true,
33
+ sx: {
34
+ opacity: '0.7'
35
+ }
36
+ });
37
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
38
+ light: true,
39
+ sx: {
40
+ bgcolor: 'black'
41
+ }
42
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
8
+ className: "test",
9
+ sx: {
10
+ opacity: "0.6"
11
+ }
12
+ });
13
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
14
+ className: "test",
15
+ sx: {
16
+ opacity: "0.6"
17
+ }
18
+ });
19
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
20
+ className: "test",
21
+ sx: {
22
+ opacity: "0.6"
23
+ }
24
+ });
25
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
26
+ className: "test",
27
+ sx: {
28
+ opacity: "0.6"
29
+ }
30
+ });
31
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
32
+ className: "test",
33
+ sx: {
34
+ opacity: "0.6"
35
+ }
36
+ });
37
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
38
+ className: "test",
39
+ sx: {
40
+ opacity: "0.6"
41
+ }
42
+ });
43
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
44
+ sx: {
45
+ opacity: '0.7'
46
+ }
47
+ });
48
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
49
+ sx: {
50
+ bgcolor: 'black',
51
+ opacity: "0.6"
52
+ }
53
+ });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiDivider: {
5
+ defaultProps: {
6
+ light: true
7
+ }
8
+ }
9
+ });
10
+ fn({
11
+ MuiDivider: {
12
+ defaultProps: {
13
+ light: true,
14
+ className: 'my-class'
15
+ }
16
+ }
17
+ });
18
+ fn({
19
+ MuiDivider: {
20
+ defaultProps: {
21
+ light,
22
+ className: 'my-class'
23
+ }
24
+ }
25
+ });
26
+ fn({
27
+ MuiDivider: {
28
+ defaultProps: {
29
+ light,
30
+ className: 'my-class',
31
+ sx: {
32
+ opacity: '0.7'
33
+ }
34
+ }
35
+ }
36
+ });
37
+ fn({
38
+ MuiDivider: {
39
+ defaultProps: {
40
+ light,
41
+ className: 'my-class',
42
+ sx: {
43
+ bgcolor: 'black'
44
+ }
45
+ }
46
+ }
47
+ });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiDivider: {
5
+ defaultProps: {
6
+ sx: {
7
+ opacity: "0.6"
8
+ }
9
+ }
10
+ }
11
+ });
12
+ fn({
13
+ MuiDivider: {
14
+ defaultProps: {
15
+ className: 'my-class',
16
+ sx: {
17
+ opacity: "0.6"
18
+ }
19
+ }
20
+ }
21
+ });
22
+ fn({
23
+ MuiDivider: {
24
+ defaultProps: {
25
+ className: 'my-class',
26
+ sx: {
27
+ opacity: "0.6"
28
+ }
29
+ }
30
+ }
31
+ });
32
+ fn({
33
+ MuiDivider: {
34
+ defaultProps: {
35
+ className: 'my-class',
36
+ sx: {
37
+ opacity: '0.7'
38
+ }
39
+ }
40
+ }
41
+ });
42
+ fn({
43
+ MuiDivider: {
44
+ defaultProps: {
45
+ className: 'my-class',
46
+ sx: {
47
+ bgcolor: 'black',
48
+ opacity: "0.6"
49
+ }
50
+ }
51
+ }
52
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.15.8",
3
+ "version": "5.15.10",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",