@mui/x-codemod 6.0.0-beta.1 → 6.0.0-beta.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 +40 -0
- package/codemod.js +1 -1
- package/package.json +1 -1
- package/util/addComponentsSlots.js +5 -5
- package/util/renameNestedProps.js +25 -0
- package/v6.0.0/pickers/preset-safe/index.js +4 -0
- package/v6.0.0/pickers/rename-default-toolbar-title-localeText/index.js +31 -0
- package/v6.0.0/pickers/rename-inputFormat-prop/index.js +39 -0
package/README.md
CHANGED
|
@@ -95,6 +95,8 @@ The list includes these transformers
|
|
|
95
95
|
- [`migrate-to-components-componentsProps`](#migrate-to-components-componentsProps)
|
|
96
96
|
- [`replace-arrows-button-slot`](#replace-arrows-button-slot)
|
|
97
97
|
- [`rename-should-disable-time`](#rename-should-disable-time)
|
|
98
|
+
- [`rename-inputFormat-prop`](#rename-inputFormat-prop)
|
|
99
|
+
- [`rename-default-toolbar-title-localeText`](#rename-default-toolbar-title-localeText)
|
|
98
100
|
|
|
99
101
|
#### `adapter-change-import`
|
|
100
102
|
|
|
@@ -341,6 +343,44 @@ Replace `shouldDisableTime` by `shouldDisableClock`.
|
|
|
341
343
|
npx @mui/x-codemod v6.0.0/pickers/rename-should-disable-time <path>
|
|
342
344
|
```
|
|
343
345
|
|
|
346
|
+
#### `rename-inputFormat-prop`
|
|
347
|
+
|
|
348
|
+
Replace `inputFormat` prop with `format`.
|
|
349
|
+
|
|
350
|
+
```diff
|
|
351
|
+
<DatePicker
|
|
352
|
+
- inputFormat="YYYY"
|
|
353
|
+
+ format="YYYY"
|
|
354
|
+
/>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
```sh
|
|
358
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-inputFormat-prop <path>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### `rename-default-toolbar-title-localeText`
|
|
362
|
+
|
|
363
|
+
Rename toolbar related translation keys, removing `Default` part from them to better fit their usage.
|
|
364
|
+
|
|
365
|
+
```diff
|
|
366
|
+
<LocalizationProvider
|
|
367
|
+
localeText={{
|
|
368
|
+
- datePickerDefaultToolbarTitle: 'Date Picker',
|
|
369
|
+
+ datePickerToolbarTitle: 'Date Picker',
|
|
370
|
+
- timePickerDefaultToolbarTitle: 'Time Picker',
|
|
371
|
+
+ timePickerToolbarTitle: 'Time Picker',
|
|
372
|
+
- dateTimePickerDefaultToolbarTitle: 'Date Time Picker',
|
|
373
|
+
+ dateTimePickerToolbarTitle: 'Date Time Picker',
|
|
374
|
+
- dateRangePickerDefaultToolbarTitle: 'Date Range Picker',
|
|
375
|
+
+ dateRangePickerToolbarTitle: 'Date Range Picker',
|
|
376
|
+
}}
|
|
377
|
+
/>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
```sh
|
|
381
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-default-toolbar-title-localeText <path>
|
|
382
|
+
```
|
|
383
|
+
|
|
344
384
|
#### `rename-components-to-slots`
|
|
345
385
|
|
|
346
386
|
Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
|
package/codemod.js
CHANGED
|
@@ -77,4 +77,4 @@ _yargs.default.command({
|
|
|
77
77
|
},
|
|
78
78
|
// @ts-expect-error
|
|
79
79
|
handler: run
|
|
80
|
-
}).scriptName('npx @mui/x-codemod').example('$0 v6.0.0/
|
|
80
|
+
}).scriptName('npx @mui/x-codemod').example('$0 v6.0.0/preset-safe src', 'Run "preset-safe" codemod on "src" path').example('$0 v6.0.0/component-rename-prop src -- --component=DataGrid --from=prop --to=newProp', 'Run "component-rename-prop" codemod in "src" path on "DataGrid" component with custom "from" and "to" arguments').help().parse();
|
package/package.json
CHANGED
|
@@ -5,24 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformNestedProp = exports.addItemToObject = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Recursive function that:
|
|
9
9
|
* Return a jscodeshift object with `value` associated to path.
|
|
10
10
|
* The path can be such as 'tabs.hidden' which will return `{ tabs: { hidden: value } }`.
|
|
11
11
|
* If object is not null, path/value will be added respecting the other properties of the object.
|
|
12
12
|
*/
|
|
13
13
|
const addItemToObject = (path, value, object, j) => {
|
|
14
|
-
const
|
|
14
|
+
const splittedPath = path.split('.');
|
|
15
15
|
|
|
16
16
|
// Final case where we have to add the property to the object.
|
|
17
|
-
if (
|
|
17
|
+
if (splittedPath.length === 1) {
|
|
18
18
|
const propertyToAdd = j.objectProperty(j.identifier(path), value);
|
|
19
19
|
if (object === null) {
|
|
20
20
|
return j.objectExpression([propertyToAdd]);
|
|
21
21
|
}
|
|
22
22
|
return j.objectExpression([...(object.properties ?? []).filter(property => property.key.name !== path), propertyToAdd]);
|
|
23
23
|
}
|
|
24
|
-
const remainingPath =
|
|
25
|
-
const targetKey =
|
|
24
|
+
const remainingPath = splittedPath.slice(1).join('.');
|
|
25
|
+
const targetKey = splittedPath[0];
|
|
26
26
|
if (object === null) {
|
|
27
27
|
// Simplest case, no object to take into consideration
|
|
28
28
|
const propertyToAdd = j.objectProperty(j.identifier(targetKey), addItemToObject(remainingPath, value, null, j));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = renameNestedProps;
|
|
7
|
+
function renameNestedProps({
|
|
8
|
+
root,
|
|
9
|
+
componentNames,
|
|
10
|
+
nestedProps,
|
|
11
|
+
j
|
|
12
|
+
}) {
|
|
13
|
+
return root.find(j.JSXElement).filter(path => componentNames.includes(path.value.openingElement.name.name)).find(j.JSXAttribute).filter(attribute => Object.keys(nestedProps).includes(attribute.node.name.name)).forEach(attribute => {
|
|
14
|
+
Object.entries(nestedProps).forEach(([rootPropName, props]) => {
|
|
15
|
+
if (attribute.node.name.name === rootPropName && attribute.node.value?.type === 'JSXExpressionContainer' && attribute.node.value?.expression.type === 'ObjectExpression') {
|
|
16
|
+
const existingProperties = attribute.node.value.expression.properties;
|
|
17
|
+
existingProperties.forEach(property => {
|
|
18
|
+
if (property.type === 'Property' && property.key.type === 'Identifier' && props[property.key.name]) {
|
|
19
|
+
property.key.name = props[property.key.name];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -15,6 +15,8 @@ var _replaceToolbarPropsBySlot = _interopRequireDefault(require("../replace-tool
|
|
|
15
15
|
var _migrateToComponentsComponentsProps = _interopRequireDefault(require("../migrate-to-components-componentsProps"));
|
|
16
16
|
var _replaceArrowsButtonSlot = _interopRequireDefault(require("../replace-arrows-button-slot"));
|
|
17
17
|
var _renameShouldDisableTime = _interopRequireDefault(require("../rename-should-disable-time"));
|
|
18
|
+
var _renameInputFormatProp = _interopRequireDefault(require("../rename-inputFormat-prop"));
|
|
19
|
+
var _renameDefaultToolbarTitleLocaleText = _interopRequireDefault(require("../rename-default-toolbar-title-localeText"));
|
|
18
20
|
function transformer(file, api, options) {
|
|
19
21
|
file.source = (0, _localizationProviderRenameLocale.default)(file, api, options);
|
|
20
22
|
|
|
@@ -28,5 +30,7 @@ function transformer(file, api, options) {
|
|
|
28
30
|
file.source = (0, _migrateToComponentsComponentsProps.default)(file, api, options);
|
|
29
31
|
file.source = (0, _replaceArrowsButtonSlot.default)(file, api, options);
|
|
30
32
|
file.source = (0, _renameShouldDisableTime.default)(file, api, options);
|
|
33
|
+
file.source = (0, _renameInputFormatProp.default)(file, api, options);
|
|
34
|
+
file.source = (0, _renameDefaultToolbarTitleLocaleText.default)(file, api, options);
|
|
31
35
|
return file.source;
|
|
32
36
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 _renameNestedProps = _interopRequireDefault(require("../../../util/renameNestedProps"));
|
|
9
|
+
const propsToRename = {
|
|
10
|
+
localeText: {
|
|
11
|
+
datePickerDefaultToolbarTitle: 'datePickerToolbarTitle',
|
|
12
|
+
timePickerDefaultToolbarTitle: 'timePickerToolbarTitle',
|
|
13
|
+
dateTimePickerDefaultToolbarTitle: 'dateTimePickerToolbarTitle',
|
|
14
|
+
dateRangePickerDefaultToolbarTitle: 'dateRangePickerToolbarTitle'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function transformer(file, api, options) {
|
|
18
|
+
const j = api.jscodeshift;
|
|
19
|
+
const root = j(file.source);
|
|
20
|
+
const printOptions = options.printOptions || {
|
|
21
|
+
quote: 'single',
|
|
22
|
+
trailingComma: true
|
|
23
|
+
};
|
|
24
|
+
(0, _renameNestedProps.default)({
|
|
25
|
+
root,
|
|
26
|
+
componentNames: ['LocalizationProvider'],
|
|
27
|
+
nestedProps: propsToRename,
|
|
28
|
+
j
|
|
29
|
+
});
|
|
30
|
+
return root.toSource(printOptions);
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 node.source.value.startsWith('@mui/x-date-pickers');
|
|
19
|
+
}).forEach(path => {
|
|
20
|
+
path.node.specifiers.forEach(node => {
|
|
21
|
+
// Process only date-pickers components
|
|
22
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
23
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
elementPath.node.openingElement.attributes.forEach(elementNode => {
|
|
27
|
+
if (elementNode.type !== 'JSXAttribute') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (elementNode.name.name === 'inputFormat') {
|
|
31
|
+
elementNode.name.name = 'format';
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const transformed = root.findJSXElements();
|
|
38
|
+
return transformed.toSource(printOptions);
|
|
39
|
+
}
|