@mui/x-codemod 8.0.0-alpha.0 → 8.0.0-alpha.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
|
@@ -39,9 +39,10 @@ Examples:
|
|
|
39
39
|
To pass more options directly to jscodeshift, use `--jscodeshift=...`. For example:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
|
|
42
|
+
# single option
|
|
43
43
|
npx @mui/x-codemod@next --jscodeshift=--run-in-band
|
|
44
|
-
|
|
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
|
|
|
@@ -135,6 +136,7 @@ The list includes these transformers
|
|
|
135
136
|
|
|
136
137
|
- [`rename-legend-to-slots-legend`](#rename-legend-to-slots-legend)
|
|
137
138
|
- [`rename-responsive-chart-container`](#rename-responsive-chart-container)
|
|
139
|
+
- [`rename-label-and-tick-font-size`](#rename-label-and-tick-font-size)
|
|
138
140
|
|
|
139
141
|
#### `rename-legend-to-slots-legend`
|
|
140
142
|
|
|
@@ -174,6 +176,23 @@ Verify the git diff to remove the duplicate.
|
|
|
174
176
|
|
|
175
177
|
:::
|
|
176
178
|
|
|
179
|
+
#### `rename-label-and-tick-font-size`
|
|
180
|
+
|
|
181
|
+
Renames `labelFontSize` and `tickFontSize` props to the corresponding `xxxStyle` prop.
|
|
182
|
+
|
|
183
|
+
```diff
|
|
184
|
+
<ChartsXAxis
|
|
185
|
+
- labelFontSize={18}
|
|
186
|
+
+ labelStyle={{
|
|
187
|
+
+ fontSize: 18
|
|
188
|
+
+ }}
|
|
189
|
+
- tickFontSize={20}
|
|
190
|
+
+ tickStyle={{
|
|
191
|
+
+ fontSize: 20
|
|
192
|
+
+ }}
|
|
193
|
+
/>
|
|
194
|
+
```
|
|
195
|
+
|
|
177
196
|
## v7.0.0
|
|
178
197
|
|
|
179
198
|
### 🚀 `preset-safe` for v7.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.2",
|
|
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.
|
|
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 _renameAndMoveFieldValueType = _interopRequireDefault(require("../rename-and-move-field-value-type"));
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
file.source = (0, _renameAndMoveFieldValueType.default)(file, api, options);
|
|
11
|
+
return file.source;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
var _renameImports = require("../../../util/renameImports");
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
const j = api.jscodeshift;
|
|
10
|
+
const root = j(file.source);
|
|
11
|
+
const printOptions = options.printOptions || {
|
|
12
|
+
quote: 'single',
|
|
13
|
+
trailingComma: true
|
|
14
|
+
};
|
|
15
|
+
(0, _renameImports.renameImports)({
|
|
16
|
+
j,
|
|
17
|
+
root,
|
|
18
|
+
packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
|
|
19
|
+
imports: [{
|
|
20
|
+
oldEndpoint: 'models',
|
|
21
|
+
importsMapping: {
|
|
22
|
+
FieldValueType: 'PickerValueType'
|
|
23
|
+
}
|
|
24
|
+
}]
|
|
25
|
+
});
|
|
26
|
+
return root.toSource(printOptions);
|
|
27
|
+
}
|