@mui/x-codemod 8.0.0-alpha.1 → 8.0.0-alpha.3

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
@@ -39,9 +39,10 @@ Examples:
39
39
  To pass more options directly to jscodeshift, use `--jscodeshift=...`. For example:
40
40
 
41
41
  ```bash
42
- // single option
42
+ # single option
43
43
  npx @mui/x-codemod@next --jscodeshift=--run-in-band
44
- // multiple options
44
+
45
+ # multiple options
45
46
  npx @mui/x-codemod@next --jscodeshift=--cpus=1 --jscodeshift=--print --jscodeshift=--dry --jscodeshift=--verbose=2
46
47
  ```
47
48
 
@@ -65,23 +66,29 @@ A combination of all important transformers for migrating v7 to v8.
65
66
  It runs codemods for all MUI X packages (Data Grid, Date and Time Pickers, Tree View, and Charts).
66
67
  To run codemods for a specific package, refer to the respective section.
67
68
 
69
+ <!-- #default-branch-switch -->
70
+
68
71
  ```bash
69
- npx @mui/x-codemod@latest v8.0.0/preset-safe <path|folder>
72
+ npx @mui/x-codemod@next v8.0.0/preset-safe <path|folder>
70
73
  ```
71
74
 
72
75
  The corresponding sub-sections are listed below
73
76
 
74
77
  - [`preset-safe-for-tree-view`](#preset-safe-for-tree-view-v800)
75
78
  - [`preset-safe-for-charts`](#preset-safe-for-charts-v800)
79
+ - [`preset-safe-for-data-grid`](#preset-safe-for-data-grid-v800)
80
+ - [`preset-safe-for-pickers`](#preset-safe-for-pickers-v800)
76
81
 
77
82
  ### Tree View codemods
78
83
 
79
- #### `preset-safe` for tree view v8.0.0
84
+ #### `preset-safe` for Tree View v8.0.0
80
85
 
81
- The `preset-safe` codemods for tree view.
86
+ The `preset-safe` codemods for Tree View.
87
+
88
+ <!-- #default-branch-switch -->
82
89
 
83
90
  ```bash
84
- npx @mui/x-codemod@latest v8.0.0/tree-view/preset-safe <path|folder>
91
+ npx @mui/x-codemod@next v8.0.0/tree-view/preset-safe <path|folder>
85
92
  ```
86
93
 
87
94
  The list includes these transformers
@@ -100,13 +107,13 @@ Renames the Tree View component to Simple Tree View
100
107
  -import { TreeView } from '@mui/x-tree-view/TreeView';
101
108
  +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
102
109
 
103
- return (
104
- - <TreeView>
105
- + <SimpleTreeView>
106
- <TreeItem itemId="1" label="First item" />
107
- - </TreeView>
108
- + </SimpleTreeView>
109
- );
110
+ return (
111
+ - <TreeView>
112
+ + <SimpleTreeView>
113
+ <TreeItem itemId="1" label="First item" />
114
+ - </TreeView>
115
+ + </SimpleTreeView>
116
+ );
110
117
  ```
111
118
 
112
119
  #### `rename-tree-item-2`
@@ -123,28 +130,31 @@ Renames the `TreeItem2` component to `TreeItem` (same for any subcomponents or u
123
130
 
124
131
  ### Charts codemods
125
132
 
126
- #### `preset-safe` for charts v8.0.0
133
+ #### `preset-safe` for Charts v8.0.0
127
134
 
128
- The `preset-safe` codemods for charts.
135
+ The `preset-safe` codemods for Charts.
136
+
137
+ <!-- #default-branch-switch -->
129
138
 
130
139
  ```bash
131
- npx @mui/x-codemod@latest v8.0.0/charts/preset-safe <path|folder>
140
+ npx @mui/x-codemod@next v8.0.0/charts/preset-safe <path|folder>
132
141
  ```
133
142
 
134
143
  The list includes these transformers
135
144
 
136
145
  - [`rename-legend-to-slots-legend`](#rename-legend-to-slots-legend)
137
146
  - [`rename-responsive-chart-container`](#rename-responsive-chart-container)
147
+ - [`rename-label-and-tick-font-size`](#rename-label-and-tick-font-size)
138
148
 
139
149
  #### `rename-legend-to-slots-legend`
140
150
 
141
151
  Renames legend props to the corresponding slotProps.
142
152
 
143
153
  ```diff
144
- <LineChart
145
- - legend={{ hiden: true}}
146
- + slotProps={{ legend: { hiden: true} }}
147
- />
154
+ <LineChart
155
+ - legend={{ hiden: true}}
156
+ + slotProps={{ legend: { hiden: true} }}
157
+ />
148
158
  ```
149
159
 
150
160
  #### `rename-responsive-chart-container`
@@ -152,14 +162,14 @@ Renames legend props to the corresponding slotProps.
152
162
  Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartContainer` and `ChartContainerPro` which have the same behavior in v8.
153
163
 
154
164
  ```diff
155
- - import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
156
- + import { ChartContainer } from '@mui/x-charts/ChartContainer';
165
+ -import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
166
+ +import { ChartContainer } from '@mui/x-charts/ChartContainer';
157
167
 
158
- - <ResponsiveChartContainer>
159
- + <ChartContainer>
168
+ -<ResponsiveChartContainer>
169
+ +<ChartContainer>
160
170
  <BarPlot />
161
- - </ResponsiveChartContainer>
162
- + </ChartContainer>
171
+ -</ResponsiveChartContainer>
172
+ +</ChartContainer>
163
173
  ```
164
174
 
165
175
  :::warning
@@ -168,12 +178,101 @@ Verify the git diff to remove the duplicate.
168
178
 
169
179
  ```diff
170
180
  import { ChartContainer } from '@mui/x-charts/ChartContainer';
171
- - import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
172
- + import { ChartContainer } from '@mui/x-charts/ChartContainer';
181
+ -import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
182
+ +import { ChartContainer } from '@mui/x-charts/ChartContainer';
173
183
  ```
174
184
 
175
185
  :::
176
186
 
187
+ #### `rename-label-and-tick-font-size`
188
+
189
+ Renames `labelFontSize` and `tickFontSize` props to the corresponding `xxxStyle` prop.
190
+
191
+ ```diff
192
+ <ChartsXAxis
193
+ - labelFontSize={18}
194
+ + labelStyle={{
195
+ + fontSize: 18
196
+ + }}
197
+ - tickFontSize={20}
198
+ + tickStyle={{
199
+ + fontSize: 20
200
+ + }}
201
+ />
202
+ ```
203
+
204
+ ### Data Grid codemods
205
+
206
+ #### `preset-safe` for Data Grid v8.0.0
207
+
208
+ The `preset-safe` codemods for Data Grid.
209
+
210
+ <!-- #default-branch-switch -->
211
+
212
+ ```bash
213
+ npx @mui/x-codemod@next v8.0.0/data-grid/preset-safe <path|folder>
214
+ ```
215
+
216
+ The list includes these transformers
217
+
218
+ - [`remove-stabilized-v8-experimentalFeatures`](#remove-stabilized-v8-experimentalFeatures)
219
+
220
+ #### `remove-stabilized-v8-experimentalFeatures`
221
+
222
+ Remove feature flags for stabilized `experimentalFeatures`.
223
+
224
+ ```diff
225
+ <DataGridPremium
226
+ - experimentalFeatures={{
227
+ - ariaV8: true,
228
+ - }}
229
+ />
230
+ ```
231
+
232
+ <!-- #default-branch-switch -->
233
+
234
+ ```bash
235
+ npx @mui/x-codemod@next v8.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
236
+ ```
237
+
238
+ ### Pickers codemods
239
+
240
+ #### `preset-safe` for Pickers v8.0.0
241
+
242
+ The `preset-safe` codemods for Pickers.
243
+
244
+ <!-- #default-branch-switch -->
245
+
246
+ ```bash
247
+ npx @mui/x-codemod@next v8.0.0/pickers/preset-safe <path|folder>
248
+ ```
249
+
250
+ The list includes these transformers
251
+
252
+ - [`rename-and-move-field-value-type`](#rename-and-move-field-value-type)
253
+
254
+ #### `rename-and-move-field-value-type`
255
+
256
+ Renames `FieldValueType` to `PickerValueType`.
257
+
258
+ ```diff
259
+ -import { FieldValueType } from '@mui/x-date-pickers';
260
+ +import { PickerValueType } from '@mui/x-date-pickers';
261
+
262
+ interface MyComponentProps {
263
+ - valueType: FieldValueType;
264
+ + valueType: PickerValueType;
265
+ foo: string;
266
+ bar: number;
267
+ }
268
+ ```
269
+
270
+ <!-- #default-branch-switch -->
271
+
272
+ ```bash
273
+ npx @mui/x-codemod@next v8.0.0/pickers/rename-and-move-field-value-type <path>
274
+ ```
275
+
177
276
  ## v7.0.0
178
277
 
179
278
  ### 🚀 `preset-safe` for v7.0.0
@@ -195,9 +294,9 @@ The corresponding sub-sections are listed below
195
294
 
196
295
  ### Pickers codemods
197
296
 
198
- #### `preset-safe` for pickers v7.0.0
297
+ #### `preset-safe` for Pickers v7.0.0
199
298
 
200
- The `preset-safe` codemods for pickers.
299
+ The `preset-safe` codemods for Pickers.
201
300
 
202
301
  ```bash
203
302
  npx @mui/x-codemod@latest v7.0.0/pickers/preset-safe <path|folder>
@@ -374,13 +473,13 @@ Renames the Tree View component to Simple Tree View
374
473
  -import { TreeView } from '@mui/x-tree-view/TreeView';
375
474
  +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
376
475
 
377
- return (
378
- - <TreeView>
379
- + <SimpleTreeView>
380
- <TreeItem itemId="1" label="First item" />
381
- - </TreeView>
382
- + </SimpleTreeView>
383
- );
476
+ return (
477
+ - <TreeView>
478
+ + <SimpleTreeView>
479
+ <TreeItem itemId="1" label="First item" />
480
+ - </TreeView>
481
+ + </SimpleTreeView>
482
+ );
384
483
  ```
385
484
 
386
485
  #### `rename-use-tree-item`
@@ -496,9 +595,9 @@ The corresponding sub-sections are listed below
496
595
 
497
596
  ### Pickers codemods
498
597
 
499
- #### `preset-safe` for pickers v6.0.0
598
+ #### `preset-safe` for Pickers v6.0.0
500
599
 
501
- The `preset-safe` codemods for pickers.
600
+ The `preset-safe` codemods for Pickers.
502
601
 
503
602
  ```bash
504
603
  npx @mui/x-codemod@latest v6.0.0/pickers/preset-safe <path|folder>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "8.0.0-alpha.1",
3
+ "version": "8.0.0-alpha.3",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -30,7 +30,7 @@
30
30
  "@babel/traverse": "^7.25.9",
31
31
  "jscodeshift": "17.1.1",
32
32
  "yargs": "^17.7.2",
33
- "@mui/x-internals": "8.0.0-alpha.1"
33
+ "@mui/x-internals": "8.0.0-alpha.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jscodeshift": "^0.12.0",
@@ -7,8 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = transformer;
8
8
  var _renameLegendToSlotsLegend = _interopRequireDefault(require("../rename-legend-to-slots-legend"));
9
9
  var _renameResponsiveChartContainer = _interopRequireDefault(require("../rename-responsive-chart-container"));
10
+ var _renameLabelAndTickFontSize = _interopRequireDefault(require("../rename-label-and-tick-font-size"));
10
11
  function transformer(file, api, options) {
11
12
  file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
12
13
  file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
14
+ file.source = (0, _renameLabelAndTickFontSize.default)(file, api, options);
13
15
  return file.source;
14
16
  }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ var _addComponentsSlots = require("../../../util/addComponentsSlots");
8
+ /**
9
+ * @param {import('jscodeshift').FileInfo} file
10
+ * @param {import('jscodeshift').API} api
11
+ */
12
+ function transformer(file, api, options) {
13
+ const j = api.jscodeshift;
14
+ const printOptions = options.printOptions;
15
+ const root = j(file.source);
16
+ root.find(j.ImportDeclaration).filter(({
17
+ node
18
+ }) => {
19
+ return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
20
+ }).forEach(path => {
21
+ path.node.specifiers?.forEach(node => {
22
+ root.findJSXElements(node.local?.name).forEach(elementPath => {
23
+ if (elementPath.node.type !== 'JSXElement') {
24
+ return;
25
+ }
26
+ ['label', 'tick'].forEach(attributeName => {
27
+ const attributeValue = elementPath.node.openingElement.attributes?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === `${attributeName}FontSize`);
28
+ if (!attributeValue) {
29
+ return;
30
+ }
31
+ const attributeStyle = elementPath.node.openingElement.attributes?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === `${attributeName}Style`);
32
+
33
+ // @ts-ignore receives an object.
34
+ const styleValue = attributeStyle?.value.expression.properties.find(prop => prop.key.name === 'fontSize');
35
+ if (attributeStyle === null) {
36
+ // We create a new "style" object
37
+ elementPath.node.openingElement.attributes?.push(j.jsxAttribute(j.jsxIdentifier(`${attributeName}Style`), j.jsxExpressionContainer(j.objectExpression([j.objectProperty(j.identifier('fontSize'),
38
+ // @ts-ignore receives an object.
39
+ attributeValue.value.expression)]))));
40
+ } else {
41
+ (0, _addComponentsSlots.transformNestedProp)(elementPath, `${attributeName}Style`, 'fontSize',
42
+ // @ts-ignore receives an object.
43
+ styleValue?.value ?? attributeValue.value.expression, j);
44
+ }
45
+ });
46
+
47
+ // Remove the legend prop
48
+ j(elementPath).find(j.JSXAttribute).filter(a => a.value.name.name === 'labelFontSize' || a.value.name.name === 'tickFontSize').forEach(pathToRemove => {
49
+ j(pathToRemove).remove();
50
+ });
51
+ });
52
+ });
53
+ });
54
+ const transformed = root.findJSXElements();
55
+ return transformed.toSource(printOptions);
56
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _removeStabilizedExperimentalFeatures = _interopRequireDefault(require("../remove-stabilized-experimentalFeatures"));
9
+ function transformer(file, api, options) {
10
+ file.source = (0, _removeStabilizedExperimentalFeatures.default)(file, api, options);
11
+ return file.source;
12
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _removeObjectProperty = _interopRequireDefault(require("../../../util/removeObjectProperty"));
9
+ const componentsNames = ['DataGridPremium'];
10
+ const propName = 'experimentalFeatures';
11
+ const propKeys = ['ariaV8'];
12
+ function transformer(file, api, options) {
13
+ const j = api.jscodeshift;
14
+ const root = j(file.source);
15
+ const printOptions = options.printOptions || {
16
+ quote: 'single',
17
+ trailingComma: true
18
+ };
19
+ propKeys.forEach(propKey => {
20
+ (0, _removeObjectProperty.default)({
21
+ root,
22
+ j,
23
+ propName,
24
+ componentsNames,
25
+ propKey
26
+ });
27
+ });
28
+ return root.toSource(printOptions);
29
+ }
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = transformer;
8
8
  var _presetSafe = _interopRequireDefault(require("../tree-view/preset-safe"));
9
- var _presetSafe2 = _interopRequireDefault(require("../charts/preset-safe"));
9
+ var _presetSafe2 = _interopRequireDefault(require("../pickers/preset-safe"));
10
+ var _presetSafe3 = _interopRequireDefault(require("../charts/preset-safe"));
11
+ var _presetSafe4 = _interopRequireDefault(require("../data-grid/preset-safe"));
10
12
  function transformer(file, api, options) {
11
13
  file.source = (0, _presetSafe.default)(file, api, options);
12
14
  file.source = (0, _presetSafe2.default)(file, api, options);
15
+ file.source = (0, _presetSafe3.default)(file, api, options);
16
+ file.source = (0, _presetSafe4.default)(file, api, options);
13
17
  return file.source;
14
18
  }