@mui/codemod 6.0.0-alpha.12 → 6.0.0-alpha.14

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
@@ -1759,6 +1759,36 @@ However, it has some **limitations**:
1759
1759
  }));
1760
1760
  ```
1761
1761
 
1762
+ #### `grid-v2-props`
1763
+
1764
+ ```bash
1765
+ npx @mui/codemod@next v6.0.0/grid-v2-props <path>
1766
+ ```
1767
+
1768
+ Updates the usage of the `Unstable_Grid` (Grid v2) component to have the same API as the `PigmentGrid`.
1769
+
1770
+ ```diff
1771
+ <Grid
1772
+ - xs={12}
1773
+ - sm={6}
1774
+ - xsOffset={2}
1775
+ - smOffset={3}
1776
+ + size={{ xs: 12, sm: 6 }}
1777
+ + offset={{ xs: 2, sm: 3 }}
1778
+ />
1779
+ ```
1780
+
1781
+ You can provide the theme breakpoints via options, for example, `--jscodeshift='--muiBreakpoints=mobile,desktop'`, to use your custom breakpoints in the transformation.
1782
+
1783
+ ```bash
1784
+ npx @mui/codemod@next v6.0.0/grid-v2-props <path> --jscodeshift='--muiBreakpoints=mobile,desktop'
1785
+ ```
1786
+
1787
+ ```diff
1788
+ - <Grid mobile={12} mobileOffset={2} desktop={6} desktopOffset={4} >
1789
+ + <Grid size={{ mobile: 12, desktop: 6 }} offset={{ mobile: 2, desktop: 4 }} >
1790
+ ```
1791
+
1762
1792
  ### v5.0.0
1763
1793
 
1764
1794
  #### `base-use-named-exports`
@@ -24,7 +24,7 @@ var _GlobalStyles = _interopRequireDefault(require("@mui/material/GlobalStyles")
24
24
  var _styles = require("@mui/material/styles");
25
25
  var _config = require("docs/config");
26
26
  var _Link = _interopRequireDefault(require("docs/src/modules/components/Link"));
27
- var _i18n = require("docs/src/modules/utils/i18n");
27
+ var _i18n = require("@mui/docs/i18n");
28
28
  var _useLazyCSS = _interopRequireDefault(require("docs/src/modules/utils/useLazyCSS"));
29
29
  var _getUrlProduct = _interopRequireDefault(require("docs/src/modules/utils/getUrlProduct"));
30
30
  var _jsxRuntime = require("react/jsx-runtime");
@@ -24,7 +24,7 @@ var _GlobalStyles = _interopRequireDefault(require("@mui/material/GlobalStyles")
24
24
  var _styles = require("@mui/material/styles");
25
25
  var _config = require("docs/config");
26
26
  var _Link = _interopRequireDefault(require("docs/src/modules/components/Link"));
27
- var _i18n = require("docs/src/modules/utils/i18n");
27
+ var _i18n = require("@mui/docs/i18n");
28
28
  var _useLazyCSS = _interopRequireDefault(require("docs/src/modules/utils/useLazyCSS"));
29
29
  var _getUrlProduct = _interopRequireDefault(require("docs/src/modules/utils/getUrlProduct"));
30
30
  var _jsxRuntime = require("react/jsx-runtime");
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = gridV2Props;
7
+ const possibleDefaultImports = ['@mui/material/Unstable_Grid2', '@mui/system/Unstable_Grid', '@mui/joy/Grid'];
8
+ const possibleNamedImports = {
9
+ '@mui/material': 'Unstable_Grid2',
10
+ '@mui/system': 'Unstable_Grid',
11
+ '@mui/joy': 'Grid'
12
+ };
13
+ const defaultBreakpoints = ['xs', 'sm', 'md', 'lg', 'xl'];
14
+
15
+ /**
16
+ * @param {import('jscodeshift').FileInfo} file
17
+ * @param {import('jscodeshift').API} api
18
+ */
19
+ function gridV2Props(file, api, options) {
20
+ var _file$path, _file$path2, _options$muiBreakpoin;
21
+ if ((_file$path = file.path) != null && _file$path.endsWith('.json') || (_file$path2 = file.path) != null && _file$path2.endsWith('.d.ts')) {
22
+ return file.source;
23
+ }
24
+ const j = api.jscodeshift;
25
+ const root = j(file.source);
26
+ const breakpoints = ((_options$muiBreakpoin = options.muiBreakpoints) == null ? void 0 : _options$muiBreakpoin.split(',')) || defaultBreakpoints;
27
+ const printOptions = options.printOptions;
28
+ const gridLocalNames = [];
29
+ root.find(j.ImportDeclaration, decl => possibleDefaultImports.includes(decl.source.value)).forEach(decl => {
30
+ decl.node.specifiers.forEach(spec => {
31
+ if (spec.type === 'ImportDefaultSpecifier') {
32
+ gridLocalNames.push(spec.local.name);
33
+ }
34
+ });
35
+ });
36
+ root.find(j.ImportDeclaration, decl => Object.keys(possibleNamedImports).includes(decl.source.value)).forEach(decl => {
37
+ decl.node.specifiers.forEach(spec => {
38
+ if (spec.type === 'ImportSpecifier') {
39
+ if (possibleNamedImports[decl.node.source.value] === spec.imported.name) {
40
+ gridLocalNames.push(spec.local.name);
41
+ }
42
+ }
43
+ });
44
+ });
45
+ root.find(j.JSXElement, {
46
+ openingElement: {
47
+ name: {
48
+ name: name => gridLocalNames.includes(name)
49
+ }
50
+ }
51
+ }).forEach(el => {
52
+ const size = j.objectExpression([]);
53
+ const spreadProps = [];
54
+ const attributesToPrune = [];
55
+ el.node.openingElement.attributes.forEach(attr => {
56
+ if (attr.type === 'JSXSpreadAttribute') {
57
+ spreadProps.push(attr);
58
+ }
59
+ });
60
+ const breakpointNodes = j(el).find(j.JSXAttribute).filter(path => path.parent.parent.node === el.node && breakpoints.includes(path.node.name.name));
61
+ breakpointNodes.nodes().forEach(node => {
62
+ const breakpoint = node.name.name;
63
+ const nodeValue = node.value;
64
+ let value;
65
+ if (nodeValue === null) {
66
+ value = j.stringLiteral('grow');
67
+ } else if (nodeValue.type === 'JSXExpressionContainer') {
68
+ if (nodeValue.expression.value === true) {
69
+ value = j.stringLiteral('grow');
70
+ } else {
71
+ value = nodeValue.expression;
72
+ }
73
+ } else {
74
+ value = nodeValue;
75
+ }
76
+ size.properties.push(j.property('init', j.identifier(breakpoint), value));
77
+ });
78
+ spreadProps.forEach(spreadProp => {
79
+ const spreadPropArgument = spreadProp.argument;
80
+ if (spreadPropArgument.type === 'ObjectExpression') {
81
+ const propertiesToPrune = [];
82
+ spreadPropArgument.properties.forEach(property => {
83
+ if (breakpoints.includes(property.key.name)) {
84
+ size.properties.push(j.property('init', property.key, property.value));
85
+ propertiesToPrune.push(property.key.name);
86
+ }
87
+ });
88
+ spreadPropArgument.properties = spreadPropArgument.properties.filter(prop => !propertiesToPrune.includes(prop.key.name));
89
+ if (spreadPropArgument.properties.length === 0) {
90
+ attributesToPrune.push(spreadProp);
91
+ }
92
+ }
93
+ });
94
+ if (size.properties.length) {
95
+ let sizePropValue = size;
96
+ if (size.properties.length === 1 && size.properties[0].key.name === 'xs') {
97
+ sizePropValue = size.properties[0].value;
98
+ }
99
+ if (sizePropValue.type !== 'StringLiteral') {
100
+ sizePropValue = j.jsxExpressionContainer(sizePropValue);
101
+ }
102
+ el.node.openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('size'), sizePropValue));
103
+ }
104
+ el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => {
105
+ var _attr$name;
106
+ return !breakpoints.includes(attr == null || (_attr$name = attr.name) == null ? void 0 : _attr$name.name);
107
+ });
108
+ const offset = j.objectExpression([]);
109
+ const offsetNodes = j(el).find(j.JSXAttribute).filter(path => path.parent.parent.node === el.node && path.node.name.name.endsWith('Offset') && breakpoints.includes(path.node.name.name.replace('Offset', '')));
110
+ offsetNodes.nodes().forEach(node => {
111
+ const breakpoint = node.name.name.replace('Offset', '');
112
+ const value = node.value.type === 'JSXExpressionContainer' ? node.value.expression : node.value;
113
+ offset.properties.push(j.property('init', j.identifier(breakpoint), value));
114
+ });
115
+ spreadProps.forEach(spreadProp => {
116
+ const spreadPropArgument = spreadProp.argument;
117
+ if (spreadPropArgument.type === 'ObjectExpression') {
118
+ const propertiesToPrune = [];
119
+ spreadPropArgument.properties.forEach(property => {
120
+ const breakpoint = property.key.name.replace('Offset', '');
121
+ if (property.key.name.endsWith('Offset') && breakpoints.includes(breakpoint)) {
122
+ offset.properties.push(j.property('init', j.identifier(breakpoint), property.value));
123
+ propertiesToPrune.push(property.key.name);
124
+ }
125
+ });
126
+ spreadPropArgument.properties = spreadPropArgument.properties.filter(prop => !propertiesToPrune.includes(prop.key.name));
127
+ if (spreadPropArgument.properties.length === 0) {
128
+ attributesToPrune.push(spreadProp);
129
+ }
130
+ }
131
+ });
132
+ if (offset.properties.length) {
133
+ let offsetPropValue = offset;
134
+ if (offset.properties.length === 1 && offset.properties[0].key.name === 'xs') {
135
+ offsetPropValue = offset.properties[0].value;
136
+ }
137
+ if (offsetPropValue.type !== 'StringLiteral') {
138
+ offsetPropValue = j.jsxExpressionContainer(offsetPropValue);
139
+ }
140
+ el.node.openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('offset'), offsetPropValue));
141
+ }
142
+ el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => {
143
+ var _attr$name2;
144
+ return !breakpoints.includes(attr == null || (_attr$name2 = attr.name) == null ? void 0 : _attr$name2.name.replace('Offset', ''));
145
+ });
146
+ el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => !attributesToPrune.includes(attr));
147
+ });
148
+ return root.toSource(printOptions);
149
+ }
@@ -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 _gridV2Props.default;
11
+ }
12
+ });
13
+ var _gridV2Props = _interopRequireDefault(require("./grid-v2-props"));
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Unstable_Grid = _interopRequireDefault(require("@mui/material/Unstable_Grid2"));
5
+ var _Unstable_Grid2 = _interopRequireDefault(require("@mui/system/Unstable_Grid"));
6
+ var _Grid = _interopRequireDefault(require("@mui/joy/Grid"));
7
+ var _material = require("@mui/material");
8
+ var _system = require("@mui/system");
9
+ var _joy = require("@mui/joy");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ // Transforms on all the possible imports
12
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
13
+ xs: 2
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid2.default, {
16
+ xs: 2
17
+ });
18
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
19
+ xs: 2
20
+ });
21
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Unstable_Grid2, {
22
+ xs: 2
23
+ });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_system.Unstable_Grid, {
25
+ xs: 2
26
+ });
27
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Grid, {
28
+ xs: 2
29
+ });
30
+
31
+ // Transforms responsive sizes
32
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
33
+ xs: 2,
34
+ sm: 4,
35
+ md: 6,
36
+ lg: 8,
37
+ xl: 10
38
+ });
39
+
40
+ // Transforms all the possible size values
41
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
42
+ xs: true,
43
+ sm: "auto",
44
+ md: 2,
45
+ lg: true,
46
+ xl: false
47
+ });
48
+
49
+ // Doesn't add jsx object expression for single string values
50
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
51
+ xs: "auto"
52
+ });
53
+
54
+ // Transforms offset
55
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
56
+ xsOffset: 2
57
+ });
58
+
59
+ // Transforms responsive offset
60
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
61
+ xsOffset: 2,
62
+ smOffset: 4,
63
+ mdOffset: 6,
64
+ lgOffset: 8,
65
+ xlOffset: 10
66
+ });
67
+
68
+ // Transforms all the possible offset values
69
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
70
+ xsOffset: 2,
71
+ smOffset: "auto"
72
+ });
73
+
74
+ // Transforms spread props
75
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
76
+ xs: 2,
77
+ sm: 4,
78
+ xsOffset: 0,
79
+ smOffset: 2
80
+ });
81
+
82
+ // Doesn't transform Grid v1
83
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Grid, {
84
+ xs: 2
85
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Unstable_Grid = _interopRequireDefault(require("@mui/material/Unstable_Grid2"));
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+ // Transforms custom breakpoints
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
8
+ customXs: 2,
9
+ customSm: 4,
10
+ customMd: 6
11
+ });
12
+
13
+ // Transforms custom breakpoints offset
14
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
15
+ customXsOffset: 2,
16
+ customSmOffset: 4,
17
+ customMdOffset: 6
18
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Unstable_Grid = _interopRequireDefault(require("@mui/material/Unstable_Grid2"));
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+ // Transforms custom breakpoints
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
8
+ size: {
9
+ customXs: 2,
10
+ customSm: 4,
11
+ customMd: 6
12
+ }
13
+ });
14
+
15
+ // Transforms custom breakpoints offset
16
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
17
+ offset: {
18
+ customXs: 2,
19
+ customSm: 4,
20
+ customMd: 6
21
+ }
22
+ });
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Unstable_Grid = _interopRequireDefault(require("@mui/material/Unstable_Grid2"));
5
+ var _Unstable_Grid2 = _interopRequireDefault(require("@mui/system/Unstable_Grid"));
6
+ var _Grid = _interopRequireDefault(require("@mui/joy/Grid"));
7
+ var _material = require("@mui/material");
8
+ var _system = require("@mui/system");
9
+ var _joy = require("@mui/joy");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ // Transforms on all the possible imports
12
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
13
+ size: 2
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid2.default, {
16
+ size: 2
17
+ });
18
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
19
+ size: 2
20
+ });
21
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Unstable_Grid2, {
22
+ size: 2
23
+ });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_system.Unstable_Grid, {
25
+ size: 2
26
+ });
27
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Grid, {
28
+ size: 2
29
+ });
30
+
31
+ // Transforms responsive sizes
32
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
33
+ size: {
34
+ xs: 2,
35
+ sm: 4,
36
+ md: 6,
37
+ lg: 8,
38
+ xl: 10
39
+ }
40
+ });
41
+
42
+ // Transforms all the possible size values
43
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
44
+ size: {
45
+ xs: "grow",
46
+ sm: "auto",
47
+ md: 2,
48
+ lg: "grow",
49
+ xl: false
50
+ }
51
+ });
52
+
53
+ // Doesn't add jsx object expression for single string values
54
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
55
+ size: "auto"
56
+ });
57
+
58
+ // Transforms offset
59
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
60
+ offset: 2
61
+ });
62
+
63
+ // Transforms responsive offset
64
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
65
+ offset: {
66
+ xs: 2,
67
+ sm: 4,
68
+ md: 6,
69
+ lg: 8,
70
+ xl: 10
71
+ }
72
+ });
73
+
74
+ // Transforms all the possible offset values
75
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
76
+ offset: {
77
+ xs: 2,
78
+ sm: "auto"
79
+ }
80
+ });
81
+
82
+ // Transforms spread props
83
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_Grid.default, {
84
+ size: {
85
+ xs: 2,
86
+ sm: 4
87
+ },
88
+ offset: {
89
+ xs: 0,
90
+ sm: 2
91
+ }
92
+ });
93
+
94
+ // Doesn't transform Grid v1
95
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Grid, {
96
+ xs: 2
97
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "6.0.0-alpha.12",
3
+ "version": "6.0.0-alpha.14",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -27,9 +27,9 @@
27
27
  "@babel/core": "^7.24.7",
28
28
  "@babel/runtime": "^7.24.7",
29
29
  "@babel/traverse": "^7.24.7",
30
- "jscodeshift": "^0.16.0",
30
+ "jscodeshift": "^0.16.1",
31
31
  "jscodeshift-add-imports": "^1.0.10",
32
- "postcss": "^8.4.38",
32
+ "postcss": "^8.4.39",
33
33
  "postcss-cli": "^11.0.0",
34
34
  "yargs": "^17.7.2"
35
35
  },