@mui/x-codemod 8.0.0 → 8.2.0
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
|
@@ -10,7 +10,7 @@ This repository contains a collection of codemod scripts based for use with
|
|
|
10
10
|
|
|
11
11
|
## Setup & run
|
|
12
12
|
|
|
13
|
-
<!-- #
|
|
13
|
+
<!-- #npm-tag-reference -->
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npx @mui/x-codemod@latest <codemod> <paths...>
|
|
@@ -40,10 +40,10 @@ To pass more options directly to jscodeshift, use `--jscodeshift=...`. For examp
|
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
# single option
|
|
43
|
-
npx @mui/x-codemod
|
|
43
|
+
npx @mui/x-codemod --jscodeshift=--run-in-band
|
|
44
44
|
|
|
45
45
|
# multiple options
|
|
46
|
-
npx @mui/x-codemod
|
|
46
|
+
npx @mui/x-codemod --jscodeshift=--cpus=1 --jscodeshift=--print --jscodeshift=--dry --jscodeshift=--verbose=2
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
See all available options [here](https://github.com/facebook/jscodeshift#usage-cli).
|
|
@@ -54,7 +54,7 @@ Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
|
|
|
54
54
|
through jscodeshift's `printOptions` command line argument
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
npx @mui/x-codemod
|
|
57
|
+
npx @mui/x-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## v8.0.0
|
|
@@ -66,7 +66,7 @@ A combination of all important transformers for migrating v7 to v8.
|
|
|
66
66
|
It runs codemods for all MUI X packages (Data Grid, Date and Time Pickers, Tree View, and Charts).
|
|
67
67
|
To run codemods for a specific package, refer to the respective section.
|
|
68
68
|
|
|
69
|
-
<!-- #
|
|
69
|
+
<!-- #npm-tag-reference -->
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
72
|
npx @mui/x-codemod@latest v8.0.0/preset-safe <path|folder>
|
|
@@ -85,7 +85,7 @@ The corresponding sub-sections are listed below
|
|
|
85
85
|
|
|
86
86
|
The `preset-safe` codemods for Tree View.
|
|
87
87
|
|
|
88
|
-
<!-- #
|
|
88
|
+
<!-- #npm-tag-reference -->
|
|
89
89
|
|
|
90
90
|
```bash
|
|
91
91
|
npx @mui/x-codemod@latest v8.0.0/tree-view/preset-safe <path|folder>
|
|
@@ -134,7 +134,7 @@ Renames the `TreeItem2` component to `TreeItem` (same for any subcomponents or u
|
|
|
134
134
|
|
|
135
135
|
The `preset-safe` codemods for Charts.
|
|
136
136
|
|
|
137
|
-
<!-- #
|
|
137
|
+
<!-- #npm-tag-reference -->
|
|
138
138
|
|
|
139
139
|
```bash
|
|
140
140
|
npx @mui/x-codemod@latest v8.0.0/charts/preset-safe <path|folder>
|
|
@@ -315,7 +315,7 @@ If there are cases that the codemod cannot handle, you should see a comment with
|
|
|
315
315
|
|
|
316
316
|
The `preset-safe` codemods for Data Grid.
|
|
317
317
|
|
|
318
|
-
<!-- #
|
|
318
|
+
<!-- #npm-tag-reference -->
|
|
319
319
|
|
|
320
320
|
```bash
|
|
321
321
|
npx @mui/x-codemod@latest v8.0.0/data-grid/preset-safe <path|folder>
|
|
@@ -343,7 +343,7 @@ Remove feature flags for stabilized `experimentalFeatures`.
|
|
|
343
343
|
/>
|
|
344
344
|
```
|
|
345
345
|
|
|
346
|
-
<!-- #
|
|
346
|
+
<!-- #npm-tag-reference -->
|
|
347
347
|
|
|
348
348
|
```bash
|
|
349
349
|
npx @mui/x-codemod@latest v8.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
|
|
@@ -367,7 +367,7 @@ The list includes these props:
|
|
|
367
367
|
/>
|
|
368
368
|
```
|
|
369
369
|
|
|
370
|
-
<!-- #
|
|
370
|
+
<!-- #npm-tag-reference -->
|
|
371
371
|
|
|
372
372
|
```bash
|
|
373
373
|
npx @mui/x-codemod@latest v8.0.0/data-grid/remove-props <path>
|
|
@@ -409,7 +409,7 @@ The list includes these props:
|
|
|
409
409
|
/>
|
|
410
410
|
```
|
|
411
411
|
|
|
412
|
-
<!-- #
|
|
412
|
+
<!-- #npm-tag-reference -->
|
|
413
413
|
|
|
414
414
|
```bash
|
|
415
415
|
npx @mui/x-codemod@latest v8.0.0/data-grid/rename-props <path>
|
|
@@ -427,7 +427,7 @@ This codemod renames the imports of the Data Grid components. The list includes
|
|
|
427
427
|
+import { gridRowSelectionIdsSelector, gridRowSelectionCountSelector } from '@mui/x-data-grid';
|
|
428
428
|
```
|
|
429
429
|
|
|
430
|
-
<!-- #
|
|
430
|
+
<!-- #npm-tag-reference -->
|
|
431
431
|
|
|
432
432
|
```bash
|
|
433
433
|
npx @mui/x-codemod@latest v8.0.0/data-grid/rename-imports <path>
|
|
@@ -450,7 +450,7 @@ Reforms the controlled `rowSelectionModel` prop value to the new one.
|
|
|
450
450
|
/>
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
<!-- #
|
|
453
|
+
<!-- #npm-tag-reference -->
|
|
454
454
|
|
|
455
455
|
```bash
|
|
456
456
|
npx @mui/x-codemod@latest v8.0.0/data-grid/reform-row-selection-model <path>
|
|
@@ -465,7 +465,7 @@ Reorganizes the imports moved from `@mui/x-data-grid-pro` and `@mui/x-data-grid-
|
|
|
465
465
|
+import { LicenseInfo } from '@mui/x-license';
|
|
466
466
|
```
|
|
467
467
|
|
|
468
|
-
<!-- #
|
|
468
|
+
<!-- #npm-tag-reference -->
|
|
469
469
|
|
|
470
470
|
```bash
|
|
471
471
|
npx @mui/x-codemod@latest v8.0.0/data-grid/rename-package <path>
|
|
@@ -484,7 +484,7 @@ Adds the `showToolbar` prop to the Data Grid components that are using `slots.to
|
|
|
484
484
|
/>
|
|
485
485
|
```
|
|
486
486
|
|
|
487
|
-
<!-- #
|
|
487
|
+
<!-- #npm-tag-reference -->
|
|
488
488
|
|
|
489
489
|
```bash
|
|
490
490
|
npx @mui/x-codemod@latest v8.0.0/data-grid/add-showToolbar-prop <path>
|
|
@@ -496,7 +496,7 @@ npx @mui/x-codemod@latest v8.0.0/data-grid/add-showToolbar-prop <path>
|
|
|
496
496
|
|
|
497
497
|
The `preset-safe` codemods for Pickers.
|
|
498
498
|
|
|
499
|
-
<!-- #
|
|
499
|
+
<!-- #npm-tag-reference -->
|
|
500
500
|
|
|
501
501
|
```bash
|
|
502
502
|
npx @mui/x-codemod@latest v8.0.0/pickers/preset-safe <path|folder>
|
|
@@ -531,7 +531,7 @@ The list includes these transformers
|
|
|
531
531
|
+import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali';
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
<!-- #
|
|
534
|
+
<!-- #npm-tag-reference -->
|
|
535
535
|
|
|
536
536
|
```bash
|
|
537
537
|
npx @mui/x-codemod@latest v8.0.0/pickers/rename-adapter-date-fns-imports <path>
|
|
@@ -565,7 +565,7 @@ Renames:
|
|
|
565
565
|
}
|
|
566
566
|
```
|
|
567
567
|
|
|
568
|
-
<!-- #
|
|
568
|
+
<!-- #npm-tag-reference -->
|
|
569
569
|
|
|
570
570
|
```bash
|
|
571
571
|
npx @mui/x-codemod@latest v8.0.0/pickers/rename-type-imports <path>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/traverse": "^7.27.0",
|
|
31
31
|
"jscodeshift": "17.1.2",
|
|
32
32
|
"yargs": "^17.7.2",
|
|
33
|
-
"@mui/x-internals": "8.
|
|
33
|
+
"@mui/x-internals": "8.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jscodeshift": "^0.12.0",
|
|
@@ -14,6 +14,7 @@ var _removeExperimentalMarkRendering = _interopRequireDefault(require("../remove
|
|
|
14
14
|
var _renameLegendPositionType = _interopRequireDefault(require("../rename-legend-position-type"));
|
|
15
15
|
var _removeOnAxisClickHandler = _interopRequireDefault(require("../remove-on-axis-click-handler"));
|
|
16
16
|
var _renameUnstableUseSeries = _interopRequireDefault(require("../rename-unstable-use-series"));
|
|
17
|
+
var _replaceLegendHiddenSlotProp = _interopRequireDefault(require("../replace-legend-hidden-slot-prop"));
|
|
17
18
|
function transformer(file, api, options) {
|
|
18
19
|
file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
|
|
19
20
|
file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
|
|
@@ -24,5 +25,6 @@ function transformer(file, api, options) {
|
|
|
24
25
|
file.source = (0, _renameLegendPositionType.default)(file, api, options);
|
|
25
26
|
file.source = (0, _removeOnAxisClickHandler.default)(file, api, options);
|
|
26
27
|
file.source = (0, _renameUnstableUseSeries.default)(file, api, options);
|
|
28
|
+
file.source = (0, _replaceLegendHiddenSlotProp.default)(file, api, options);
|
|
27
29
|
return file.source;
|
|
28
30
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 printOptions = options.printOptions;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
|
|
19
|
+
}).forEach(path => {
|
|
20
|
+
path.node.specifiers?.forEach(node => {
|
|
21
|
+
root.findJSXElements(node.local?.name).forEach(elementPath => {
|
|
22
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let chartProps = elementPath.value.openingElement.attributes;
|
|
26
|
+
const slotProps = chartProps?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === 'slotProps');
|
|
27
|
+
if (slotProps === null) {
|
|
28
|
+
// No slotProps to manage
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const legendSlotProps = slotProps?.value?.expression?.properties?.find(v =>
|
|
32
|
+
// @ts-expect-error
|
|
33
|
+
v?.key?.name === 'legend'
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
)?.value;
|
|
36
|
+
const hiddenIndex = legendSlotProps?.properties?.findIndex(v => v?.key?.name === 'hidden');
|
|
37
|
+
if (hiddenIndex === undefined || hiddenIndex === -1) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const hidden = legendSlotProps?.properties?.[hiddenIndex]?.value;
|
|
41
|
+
if (!hidden) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
legendSlotProps.properties.splice(hiddenIndex, 1);
|
|
45
|
+
if (slotProps.value?.type === 'JSXExpressionContainer' && legendSlotProps.properties.length === 0) {
|
|
46
|
+
const slotPropsObject = slotProps.value?.expression;
|
|
47
|
+
if (slotPropsObject.type === 'ObjectExpression') {
|
|
48
|
+
slotPropsObject.properties = slotPropsObject.properties.filter(prop => prop.type !== 'ObjectProperty' || prop.key.type !== 'Identifier' || prop.key.name !== 'legend');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (slotProps.value?.type === 'JSXExpressionContainer' && slotProps.value.expression.type === 'ObjectExpression' && slotProps.value.expression.properties.length === 0) {
|
|
52
|
+
chartProps = chartProps?.filter(attr => attr.type !== 'JSXAttribute' || attr.name.name !== 'slotProps');
|
|
53
|
+
}
|
|
54
|
+
chartProps?.push(j.jsxAttribute(j.jsxIdentifier('hideLegend'), j.jsxExpressionContainer(hidden)));
|
|
55
|
+
elementPath.value.openingElement.attributes = chartProps;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
const transformed = root.findJSXElements();
|
|
60
|
+
return transformed.toSource(printOptions);
|
|
61
|
+
}
|