@mui/x-codemod 6.0.0-alpha.9 → 6.0.0-beta.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 +163 -4
- package/package.json +4 -4
- package/util/removeProps.js +18 -0
- package/util/renameProps.js +7 -8
- package/v6.0.0/component-rename-prop/index.js +3 -2
- package/v6.0.0/data-grid/column-menu-components-rename/index.js +49 -0
- package/v6.0.0/data-grid/preset-safe/index.js +14 -0
- package/v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop/index.js +24 -0
- package/v6.0.0/pickers/adapter-change-import/index.js +56 -0
- package/v6.0.0/{localization-provider-rename-locale → pickers/localization-provider-rename-locale}/index.js +4 -3
- package/v6.0.0/pickers/preset-safe/index.js +22 -0
- package/v6.0.0/pickers/text-props-to-localeText/index.js +101 -0
- package/v6.0.0/pickers/view-components-rename/index.js +83 -0
- package/v6.0.0/pickers/view-components-rename-value-prop/index.js +22 -0
- package/v6.0.0/preset-safe/index.js +4 -2
package/README.md
CHANGED
|
@@ -62,19 +62,89 @@ npx @mui/x-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":
|
|
|
62
62
|
|
|
63
63
|
#### 🚀 `preset-safe`
|
|
64
64
|
|
|
65
|
-
A combination of all important transformers for migrating v5 to v6. ⚠️ This codemod should be run only once.
|
|
65
|
+
A combination of all important transformers for migrating v5 to v6. ⚠️ This codemod should be run only once. It runs codemods for both Data Grid and Date and Time Pickers packages. To run codemods for a specific package, refer to the respective section.
|
|
66
66
|
|
|
67
67
|
```sh
|
|
68
68
|
npx @mui/x-codemod v6.0.0/preset-safe <path|folder>
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
The corresponding sub-sections are listed below
|
|
72
|
+
|
|
73
|
+
- [`preset-safe-for-pickers`](#preset-safe-for-pickers)
|
|
74
|
+
- [`preset-safe-for-data-grid`](#preset-safe-for-data-grid)
|
|
75
|
+
|
|
76
|
+
### Pickers codemods
|
|
77
|
+
|
|
78
|
+
#### `preset-safe` for pickers
|
|
79
|
+
|
|
80
|
+
The `preset-safe` codemods for pickers.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npx @mui/x-codemod v6.0.0/pickers/preset-safe <path|folder>
|
|
84
|
+
```
|
|
85
|
+
|
|
71
86
|
The list includes these transformers
|
|
72
87
|
|
|
88
|
+
- [`adapter-change-import`](#adapter-change-import)
|
|
89
|
+
- [`view-components-rename`](#view-components-rename)
|
|
90
|
+
- [`view-components-rename-value-prop`](#view-components-rename)
|
|
73
91
|
- [`localization-provider-rename-locale`](#localization-provider-rename-locale)
|
|
92
|
+
- [`text-props-to-localeText`](#text-props-to-localeText)
|
|
93
|
+
|
|
94
|
+
#### `adapter-change-import`
|
|
95
|
+
|
|
96
|
+
Import the adapters from `@mui/x-date-pickers` instead of `@date-io`.
|
|
97
|
+
|
|
98
|
+
```diff
|
|
99
|
+
-import AdapterJalaali from '@date-io/jalaali';
|
|
100
|
+
+import { AdapterMomentJalaali } from '@mui/x-date-pickers/AdapterMomentJalaali';
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### `view-components-rename`
|
|
104
|
+
|
|
105
|
+
Renames the view components.
|
|
106
|
+
|
|
107
|
+
```diff
|
|
108
|
+
-<CalendarPicker {...props} />
|
|
109
|
+
+<DateCalendar {...props} />
|
|
110
|
+
|
|
111
|
+
-<DayPicker {...props} />
|
|
112
|
+
+<DayCalendar {...props} />
|
|
113
|
+
|
|
114
|
+
-<CalendarPickerSkeleton {...props} />
|
|
115
|
+
+<DayCalendarSkeleton {...props} />
|
|
116
|
+
|
|
117
|
+
-<MonthPicker {...props} />
|
|
118
|
+
+<MonthCalendar {...props} />
|
|
119
|
+
|
|
120
|
+
-<YearPicker {...props} />
|
|
121
|
+
+<YearCalendar {...props} />
|
|
122
|
+
|
|
123
|
+
-<ClockPicker {...props} />
|
|
124
|
+
+<TimeClock {...props} />
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `view-components-rename-value-prop`
|
|
128
|
+
|
|
129
|
+
Renames the `date` prop of the view components into `value`.
|
|
130
|
+
|
|
131
|
+
```diff
|
|
132
|
+
-<MonthPicker date={dayjs()} />
|
|
133
|
+
+<MonthCalendar value={dayjs()} />
|
|
134
|
+
|
|
135
|
+
-<YearPicker date={dayjs()} />
|
|
136
|
+
+<YearCalendar value={dayjs()} />
|
|
137
|
+
|
|
138
|
+
-<ClockPicker date={dayjs()} />
|
|
139
|
+
+<TimeClock value={dayjs()} />
|
|
140
|
+
|
|
141
|
+
-<CalendarPicker date={dayjs()} />
|
|
142
|
+
+<DateCalendar value={dayjs()} />
|
|
143
|
+
```
|
|
74
144
|
|
|
75
145
|
#### `localization-provider-rename-locale`
|
|
76
146
|
|
|
77
|
-
Renames `locale`
|
|
147
|
+
Renames the `locale` prop of the `LocalizationProvider` component into `adapterLocale`.
|
|
78
148
|
|
|
79
149
|
```diff
|
|
80
150
|
<LocalizationProvider
|
|
@@ -88,7 +158,96 @@ Renames `locale` into `adapterLocale` (or `LocalizationProvider`)
|
|
|
88
158
|
```
|
|
89
159
|
|
|
90
160
|
```sh
|
|
91
|
-
npx @mui/x-codemod v6.0.0/localization-provider-rename-locale <path>
|
|
161
|
+
npx @mui/x-codemod v6.0.0/pickers/localization-provider-rename-locale <path>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### `text-props-to-localeText`
|
|
165
|
+
|
|
166
|
+
Replace props used for localization such as `cancelText` to their corresponding `localeText` key on all the Date and Time Pickers components.
|
|
167
|
+
|
|
168
|
+
```diff
|
|
169
|
+
<DatePicker
|
|
170
|
+
- cancelText="Cancelar"
|
|
171
|
+
+ localeText={{
|
|
172
|
+
+ cancelButtonLabel: "Cancelar"
|
|
173
|
+
+ }}
|
|
174
|
+
/>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
npx @mui/x-codemod v6.0.0/pickers/text-props-to-localeText <path>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
If you were always using the same text value in all your components, consider moving those translation from the component to the `LocalizationProvider` by hand.
|
|
182
|
+
|
|
183
|
+
```diff
|
|
184
|
+
<LocalizationProvider
|
|
185
|
+
dateAdapter={AdapterDayjs}
|
|
186
|
+
+ localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
187
|
+
>
|
|
188
|
+
<DatePicker
|
|
189
|
+
- localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
190
|
+
/>
|
|
191
|
+
<DateTimePicker
|
|
192
|
+
- localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
193
|
+
/>
|
|
194
|
+
</LocalizationProvider>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
You can find more details about Date and Time breaking changes in [the migration guide](https://next.mui.com/x/migration/migration-pickers-v5/).
|
|
198
|
+
|
|
199
|
+
### Data grid codemods
|
|
200
|
+
|
|
201
|
+
#### `preset-safe` for data grid
|
|
202
|
+
|
|
203
|
+
The `preset-safe` codemods for data grid.
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
npx @mui/x-codemod v6.0.0/data-grid/preset-safe <path|folder>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The list includes these transformers
|
|
210
|
+
|
|
211
|
+
- [`column-menu-components-rename`](#column-menu-components-rename)
|
|
212
|
+
- [`remove-disableExtendRowFullWidth-prop`](#remove-disableExtendRowFullWidth-prop)
|
|
213
|
+
|
|
214
|
+
#### `column-menu-components-rename`
|
|
215
|
+
|
|
216
|
+
Replace column menu items that have been renamed.
|
|
217
|
+
|
|
218
|
+
```diff
|
|
219
|
+
<CustomColumnMenu>
|
|
220
|
+
- <GridFilterMenuItem column={column} onClick={hideMenu} />
|
|
221
|
+
+ <GridColumnMenuFilterItem colDef={column} onClick={hideMenu} />
|
|
222
|
+
- <HideGridColMenuItem column={column} onClick={hideMenu} />
|
|
223
|
+
+ <GridColumnMenuHideItem colDef={column} onClick={hideMenu} />
|
|
224
|
+
- <GridColumnsMenuItem column={column} onClick={hideMenu} />
|
|
225
|
+
+ <GridColumnMenuColumnsItem colDef={column} onClick={hideMenu} />
|
|
226
|
+
- <SortGridMenuItems column={column} onClick={hideMenu} />
|
|
227
|
+
+ <GridColumnMenuSortItem colDef={column} onClick={hideMenu} />
|
|
228
|
+
- <GridColumnPinningMenuItems column={column} onClick={hideMenu} />
|
|
229
|
+
+ <GridColumnMenuPinningItem colDef={column} onClick={hideMenu} />
|
|
230
|
+
</CustomColumnMenu>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
npx @mui/x-codemod v6.0.0/data-grid/column-menu-components-rename <path>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
If you are using `GridRowGroupingColumnMenuItems` and `GridRowGroupableColumnMenuItems` for grouping, consider fixing them manually as these imports are replaced by `GridColumnMenuGroupingItem` and may require some extra work to port.
|
|
238
|
+
|
|
239
|
+
#### `remove-disableExtendRowFullWidth-prop`
|
|
240
|
+
|
|
241
|
+
Remove `disableExtendRowFullWidth` prop which is no longer supported.
|
|
242
|
+
|
|
243
|
+
```diff
|
|
244
|
+
<DataGrid
|
|
245
|
+
- disableExtendRowFullWidth
|
|
246
|
+
/>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
```sh
|
|
250
|
+
npx @mui/x-codemod v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop <path>
|
|
92
251
|
```
|
|
93
252
|
|
|
94
|
-
You can find more details about
|
|
253
|
+
You can find more details about Data Grid breaking change in [the migration guide](https://next.mui.com/x/migration/migration-data-grid-v5/).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-beta.0",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"url": "https://opencollective.com/mui"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@babel/core": "^7.20.
|
|
35
|
-
"@babel/runtime": "^7.20.
|
|
36
|
-
"@babel/traverse": "^7.20.
|
|
34
|
+
"@babel/core": "^7.20.12",
|
|
35
|
+
"@babel/runtime": "^7.20.7",
|
|
36
|
+
"@babel/traverse": "^7.20.12",
|
|
37
37
|
"jscodeshift": "0.13.1",
|
|
38
38
|
"jscodeshift-add-imports": "^1.0.10",
|
|
39
39
|
"yargs": "^17.6.2"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = removeProps;
|
|
7
|
+
function removeProps({
|
|
8
|
+
root,
|
|
9
|
+
componentNames,
|
|
10
|
+
props,
|
|
11
|
+
j
|
|
12
|
+
}) {
|
|
13
|
+
return root.find(j.JSXElement).filter(path => {
|
|
14
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
15
|
+
}).find(j.JSXAttribute).filter(attribute => props.includes(attribute.node.name.name)).forEach(attribute => {
|
|
16
|
+
j(attribute).remove();
|
|
17
|
+
});
|
|
18
|
+
}
|
package/util/renameProps.js
CHANGED
|
@@ -6,14 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = renameProps;
|
|
7
7
|
function renameProps({
|
|
8
8
|
root,
|
|
9
|
-
|
|
10
|
-
props
|
|
9
|
+
componentNames,
|
|
10
|
+
props,
|
|
11
|
+
j
|
|
11
12
|
}) {
|
|
12
|
-
return root.
|
|
13
|
-
path.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
});
|
|
13
|
+
return root.find(j.JSXElement).filter(path => {
|
|
14
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
15
|
+
}).find(j.JSXAttribute).filter(attribute => Object.keys(props).includes(attribute.node.name.name)).forEach(attribute => {
|
|
16
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), attribute.node.value));
|
|
18
17
|
});
|
|
19
18
|
}
|
|
@@ -12,9 +12,10 @@ function transformer(file, api, options) {
|
|
|
12
12
|
const printOptions = options.printOptions;
|
|
13
13
|
return (0, _renameProps.default)({
|
|
14
14
|
root,
|
|
15
|
-
|
|
15
|
+
componentNames: [options.component],
|
|
16
16
|
props: {
|
|
17
17
|
[options.from]: options.to
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
j
|
|
19
20
|
}).toSource(printOptions);
|
|
20
21
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
|
+
const VARIABLES = {
|
|
10
|
+
GridFilterMenuItem: 'GridColumnMenuFilterItem',
|
|
11
|
+
HideGridColMenuItem: 'GridColumnMenuHideItem',
|
|
12
|
+
GridColumnsMenuItem: 'GridColumnMenuColumnsItem',
|
|
13
|
+
SortGridMenuItems: 'GridColumnMenuSortItem',
|
|
14
|
+
GridColumnPinningMenuItems: 'GridColumnMenuPinningItem',
|
|
15
|
+
GridAggregationColumnMenuItem: 'GridColumnMenuAggregationItem'
|
|
16
|
+
};
|
|
17
|
+
const PACKAGE_REGEXP = /@mui\/x-data-grid(-pro|-premium)(\/(.*)|)/;
|
|
18
|
+
const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
|
|
19
|
+
function transformer(file, api, options) {
|
|
20
|
+
const j = api.jscodeshift;
|
|
21
|
+
const root = j(file.source);
|
|
22
|
+
const printOptions = options.printOptions || {
|
|
23
|
+
quote: 'single',
|
|
24
|
+
trailingComma: true
|
|
25
|
+
};
|
|
26
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
|
|
27
|
+
|
|
28
|
+
// Rename the import specifiers
|
|
29
|
+
// - import { GridFilterMenuItem } from '@mui/x-data-grid'
|
|
30
|
+
// + import { GridColumnMenuFilterItem } from '@mui/x-data-grid'
|
|
31
|
+
matchingImports.find(j.ImportSpecifier).filter(path => !!VARIABLES[path.node.imported.name]).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name])));
|
|
32
|
+
|
|
33
|
+
// Rename the import usage
|
|
34
|
+
// - <GridFilterMenuItem />
|
|
35
|
+
// + <GridColumnMenuFilterItem />
|
|
36
|
+
root.find(j.Identifier).filter(path => !!VARIABLES[path.node.name]).replaceWith(path => j.identifier(VARIABLES[path.node.name]));
|
|
37
|
+
|
|
38
|
+
// Rename `column` prop to `colDef`
|
|
39
|
+
// - <GridFilterMenuItem column={col} onClick={onClick} />
|
|
40
|
+
// + <GridFilterMenuItem colDef={col} onClick={onClick} />
|
|
41
|
+
return (0, _renameProps.default)({
|
|
42
|
+
root,
|
|
43
|
+
componentNames: Object.values(VARIABLES),
|
|
44
|
+
props: {
|
|
45
|
+
column: 'colDef'
|
|
46
|
+
},
|
|
47
|
+
j
|
|
48
|
+
}).toSource(printOptions);
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 _columnMenuComponentsRename = _interopRequireDefault(require("../column-menu-components-rename"));
|
|
9
|
+
var _removeDisableExtendRowFullWidthProp = _interopRequireDefault(require("../remove-disableExtendRowFullWidth-prop"));
|
|
10
|
+
function transformer(file, api, options) {
|
|
11
|
+
file.source = (0, _columnMenuComponentsRename.default)(file, api, options);
|
|
12
|
+
file.source = (0, _removeDisableExtendRowFullWidthProp.default)(file, api, options);
|
|
13
|
+
return file.source;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 _removeProps = _interopRequireDefault(require("packages/x-codemod/src/util/removeProps"));
|
|
9
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const props = ['disableExtendRowFullWidth'];
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const root = j(file.source);
|
|
14
|
+
const printOptions = options.printOptions || {
|
|
15
|
+
quote: 'single',
|
|
16
|
+
trailingComma: true
|
|
17
|
+
};
|
|
18
|
+
return (0, _removeProps.default)({
|
|
19
|
+
root,
|
|
20
|
+
j,
|
|
21
|
+
props,
|
|
22
|
+
componentNames
|
|
23
|
+
}).toSource(printOptions);
|
|
24
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
const adapters = {
|
|
8
|
+
'date-fns': 'AdapterDateFns',
|
|
9
|
+
'date-fns-jalali': 'AdapterDateFnsJalali',
|
|
10
|
+
dayjs: 'AdapterDayjs',
|
|
11
|
+
luxon: 'AdapterLuxon',
|
|
12
|
+
moment: 'AdapterMoment',
|
|
13
|
+
hijri: 'AdapterMomentHijri',
|
|
14
|
+
jalaali: 'AdapterMomentJalaali'
|
|
15
|
+
};
|
|
16
|
+
const getDateIoSubPackage = path => (path.node.source.value?.toString() ?? '').match(/@date-io\/(.*)/)?.[1];
|
|
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
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => {
|
|
25
|
+
const subPackage = getDateIoSubPackage(path);
|
|
26
|
+
return !!subPackage && !!adapters[subPackage];
|
|
27
|
+
});
|
|
28
|
+
const adapterVariableNames = {};
|
|
29
|
+
|
|
30
|
+
// Replace the default import specifier by an import specifiers
|
|
31
|
+
// - import WhateverDateFns from '@mui/x-date-pickers/MonthPicker'
|
|
32
|
+
// + import { AdapterDateFns } from '@mui/x-date-pickers/MonthPicker'
|
|
33
|
+
matchingImports.find(j.ImportDefaultSpecifier).replaceWith(path => {
|
|
34
|
+
const subPackage = getDateIoSubPackage(path.parentPath.parentPath);
|
|
35
|
+
const adapterVariableName = path.value.local?.name ?? '';
|
|
36
|
+
adapterVariableNames[adapterVariableName] = adapters[subPackage];
|
|
37
|
+
return j.importSpecifier(j.identifier(adapters[subPackage]));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Rename the import declarations
|
|
41
|
+
// - import {} from '@date-io/date-fns'
|
|
42
|
+
// + import {} from '@mui/x-date-pickers/AdapterDateFns'
|
|
43
|
+
matchingImports.replaceWith(path => {
|
|
44
|
+
const subPackage = getDateIoSubPackage(path);
|
|
45
|
+
return j.importDeclaration(path.node.specifiers,
|
|
46
|
+
// copy over the existing import specifiers
|
|
47
|
+
j.stringLiteral(`@mui/x-date-pickers/${adapters[subPackage]}`) // Replace the source with our new source
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Rename the import usage
|
|
52
|
+
// - <LocalizationProvider dateAdapter={WhateverDateFns} />
|
|
53
|
+
// + <LocalizationProvider dateAdapter={AdapterDateFns} />
|
|
54
|
+
root.find(j.Identifier).filter(path => !!adapterVariableNames[path.node.name]).replaceWith(path => j.identifier(adapterVariableNames[path.node.name]));
|
|
55
|
+
return root.toSource(printOptions);
|
|
56
|
+
}
|
|
@@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
|
-
var _renameProps = _interopRequireDefault(require("
|
|
8
|
+
var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
10
|
const j = api.jscodeshift;
|
|
11
11
|
const root = j(file.source);
|
|
12
12
|
const printOptions = options.printOptions;
|
|
13
13
|
return (0, _renameProps.default)({
|
|
14
14
|
root,
|
|
15
|
-
|
|
15
|
+
componentNames: ['LocalizationProvider'],
|
|
16
16
|
props: {
|
|
17
17
|
locale: 'adapterLocale'
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
j
|
|
19
20
|
}).toSource(printOptions);
|
|
20
21
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 _localizationProviderRenameLocale = _interopRequireDefault(require("../localization-provider-rename-locale"));
|
|
9
|
+
var _textPropsToLocaleText = _interopRequireDefault(require("../text-props-to-localeText"));
|
|
10
|
+
var _viewComponentsRename = _interopRequireDefault(require("../view-components-rename"));
|
|
11
|
+
var _viewComponentsRenameValueProp = _interopRequireDefault(require("../view-components-rename-value-prop"));
|
|
12
|
+
var _adapterChangeImport = _interopRequireDefault(require("../adapter-change-import"));
|
|
13
|
+
function transformer(file, api, options) {
|
|
14
|
+
file.source = (0, _localizationProviderRenameLocale.default)(file, api, options);
|
|
15
|
+
|
|
16
|
+
// All the codemods impacting the view components should be run before renaming these components
|
|
17
|
+
file.source = (0, _textPropsToLocaleText.default)(file, api, options);
|
|
18
|
+
file.source = (0, _viewComponentsRenameValueProp.default)(file, api, options);
|
|
19
|
+
file.source = (0, _viewComponentsRename.default)(file, api, options);
|
|
20
|
+
file.source = (0, _adapterChangeImport.default)(file, api, options);
|
|
21
|
+
return file.source;
|
|
22
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
const defaultPropsToKey = {
|
|
10
|
+
cancelText: ['cancelButtonLabel'],
|
|
11
|
+
okText: ['okButtonLabel'],
|
|
12
|
+
todayText: ['todayButtonLabel'],
|
|
13
|
+
clearText: ['clearButtonLabel'],
|
|
14
|
+
endText: ['end'],
|
|
15
|
+
getClockLabelText: ['clockLabelText'],
|
|
16
|
+
getHoursClockNumberText: ['hoursClockNumberText'],
|
|
17
|
+
getMinutesClockNumberText: ['minutesClockNumberText'],
|
|
18
|
+
getSecondsClockNumberText: ['secondsClockNumberText'],
|
|
19
|
+
getViewSwitchingButtonText: ['calendarViewSwitchingButtonAriaLabel'],
|
|
20
|
+
startText: ['start']
|
|
21
|
+
};
|
|
22
|
+
const isMonthSwitchComponent = {
|
|
23
|
+
DatePicker: true,
|
|
24
|
+
StaticDatePicker: true,
|
|
25
|
+
MobileDatePicker: true,
|
|
26
|
+
DesktopDatePicker: true,
|
|
27
|
+
DateRangePicker: true,
|
|
28
|
+
StaticDateRangePicker: true,
|
|
29
|
+
MobileDateRangePicker: true,
|
|
30
|
+
DesktopDateRangePicker: true,
|
|
31
|
+
CalendarPicker: true,
|
|
32
|
+
// Special cases of DateTimePickers present in both
|
|
33
|
+
DateTimePicker: true,
|
|
34
|
+
StaticDateTimePicker: true,
|
|
35
|
+
MobileDateTimePicker: true,
|
|
36
|
+
DesktopDateTimePicker: true
|
|
37
|
+
};
|
|
38
|
+
const isViewSwitchComponent = {
|
|
39
|
+
TimePicker: true,
|
|
40
|
+
StaticTimePicker: true,
|
|
41
|
+
MobileTimePicker: true,
|
|
42
|
+
DesktopTimePicker: true,
|
|
43
|
+
DateTimePicker: true,
|
|
44
|
+
ClockPicker: true,
|
|
45
|
+
// Special cases of DateTimePickers present in both
|
|
46
|
+
StaticDateTimePicker: true,
|
|
47
|
+
MobileDateTimePicker: true,
|
|
48
|
+
DesktopDateTimePicker: true
|
|
49
|
+
};
|
|
50
|
+
const needsWrapper = {
|
|
51
|
+
ClockPicker: true,
|
|
52
|
+
CalendarPicker: true
|
|
53
|
+
};
|
|
54
|
+
const impactedComponents = ['DateRangePicker', 'CalendarPicker', 'ClockPicker', 'DatePicker', 'DateRangePicker', 'DateRangePickerDay', 'DateTimePicker', 'DesktopDatePicker', 'DesktopDateRangePicker', 'DesktopDateTimePicker', 'DesktopTimePicker', 'MobileDatePicker', 'MobileDateRangePicker', 'MobileDateTimePicker', 'MobileTimePicker', 'StaticDatePicker', 'StaticDateRangePicker', 'StaticDateTimePicker', 'StaticTimePicker', 'TimePicker'];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
58
|
+
* @param {import('jscodeshift').API} api
|
|
59
|
+
*/
|
|
60
|
+
function transformer(file, api, options) {
|
|
61
|
+
const j = api.jscodeshift;
|
|
62
|
+
const printOptions = options.printOptions;
|
|
63
|
+
const root = j(file.source);
|
|
64
|
+
impactedComponents.forEach(componentName => {
|
|
65
|
+
const propsToKey = (0, _extends2.default)({}, defaultPropsToKey, {
|
|
66
|
+
leftArrowButtonText: [...(isViewSwitchComponent[componentName] ? ['openPreviousView'] : []), ...(isMonthSwitchComponent[componentName] ? ['previousMonth'] : [])],
|
|
67
|
+
rightArrowButtonText: [...(isViewSwitchComponent[componentName] ? ['openNextView'] : []), ...(isMonthSwitchComponent[componentName] ? ['nextMonth'] : [])]
|
|
68
|
+
});
|
|
69
|
+
root.findJSXElements(componentName).forEach(path => {
|
|
70
|
+
const newLocaleText = [];
|
|
71
|
+
const attributes = path.node.openingElement.attributes;
|
|
72
|
+
attributes.forEach((node, index) => {
|
|
73
|
+
if (node.type === 'JSXAttribute' && propsToKey[node.name.name] !== undefined) {
|
|
74
|
+
const newNames = propsToKey[node.name.name];
|
|
75
|
+
newNames.forEach(newName => {
|
|
76
|
+
const property = j.objectProperty(j.identifier(newName), node.value.expression ? node.value.expression : j.literal(node.value.value));
|
|
77
|
+
property.shorthand = node.value.expression && node.value.expression.name === newName;
|
|
78
|
+
newLocaleText.push(property);
|
|
79
|
+
});
|
|
80
|
+
delete attributes[index];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (newLocaleText.length > 0) {
|
|
84
|
+
if (needsWrapper[componentName]) {
|
|
85
|
+
// From : https://www.codeshiftcommunity.com/docs/react/#wrapping-components
|
|
86
|
+
|
|
87
|
+
// Create a new JSXElement called "LocalizationProvider" and use the original component as children
|
|
88
|
+
const wrappedComponent = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('LocalizationProvider'), [
|
|
89
|
+
// Add the new localeText prop
|
|
90
|
+
j.jsxAttribute(j.jsxIdentifier('localeText'), j.jsxExpressionContainer(j.objectExpression(newLocaleText)))]), j.jsxClosingElement(j.jsxIdentifier('LocalizationProvider')), [path.value] // Pass in the original component as children
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
j(path).replaceWith(wrappedComponent);
|
|
94
|
+
} else {
|
|
95
|
+
attributes.push(j.jsxAttribute(j.jsxIdentifier('localeText'), j.jsxExpressionContainer(j.objectExpression(newLocaleText))));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return root.toSource(printOptions);
|
|
101
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
const SUB_PACKAGES = {
|
|
8
|
+
CalendarPicker: 'DateCalendar',
|
|
9
|
+
CalendarPickerSkeleton: 'DayCalendarSkeleton',
|
|
10
|
+
MonthPicker: 'MonthCalendar',
|
|
11
|
+
YearPicker: 'YearCalendar',
|
|
12
|
+
ClockPicker: 'TimeClock'
|
|
13
|
+
};
|
|
14
|
+
const VARIABLES = {
|
|
15
|
+
// Date Calendar
|
|
16
|
+
CalendarPicker: 'DateCalendar',
|
|
17
|
+
CalendarPickerProps: 'DateCalendarProps',
|
|
18
|
+
CalendarPickerSlotsComponent: 'DateCalendarSlotsComponent',
|
|
19
|
+
CalendarPickerSlotsComponentsProps: 'DateCalendarSlotsComponentsProps',
|
|
20
|
+
CalendarPickerClasses: 'DateCalendarClasses',
|
|
21
|
+
CalendarPickerClassKey: 'DateCalendarClassKey',
|
|
22
|
+
calendarPickerClasses: 'dateCalendarClasses',
|
|
23
|
+
getCalendarPickerUtilityClass: 'getDateCalendarUtilityClass',
|
|
24
|
+
// Month Calendar
|
|
25
|
+
MonthPicker: 'MonthCalendar',
|
|
26
|
+
MonthPickerProps: 'MonthCalendarProps',
|
|
27
|
+
MonthPickerClasses: 'MonthCalendarClasses',
|
|
28
|
+
MonthPickerClassKey: 'MonthCalendarClassKey',
|
|
29
|
+
monthPickerClasses: 'monthCalendarClasses',
|
|
30
|
+
getMonthPickerUtilityClass: 'getMonthCalendarUtilityClass',
|
|
31
|
+
YearPicker: 'YearCalendar',
|
|
32
|
+
YearPickerProps: 'YearCalendarProps',
|
|
33
|
+
YearPickerClasses: 'YearCalendarClasses',
|
|
34
|
+
YearPickerClassKey: 'YearCalendarClassKey',
|
|
35
|
+
yearPickerClasses: 'yearCalendarClasses',
|
|
36
|
+
getYearPickerUtilityClass: 'getYearCalendarUtilityClass',
|
|
37
|
+
ClockPicker: 'TimeClock',
|
|
38
|
+
ClockPickerProps: 'TimeClockProps',
|
|
39
|
+
ClockPickerClasses: 'TimeClockClasses',
|
|
40
|
+
ClockPickerClassKey: 'TimeClockClassKey',
|
|
41
|
+
clockPickerClasses: 'timeClockClasses',
|
|
42
|
+
getClockPickerUtilityClass: 'getTimeClockUtilityClass',
|
|
43
|
+
CalendarPickerSkeleton: 'DayCalendarSkeleton',
|
|
44
|
+
CalendarPickerSkeletonProps: 'DayCalendarSkeletonProps',
|
|
45
|
+
CalendarPickerSkeletonClasses: 'DayCalendarSkeletonClasses',
|
|
46
|
+
CalendarPickerSkeletonClassKey: 'DayCalendarSkeletonClassKey',
|
|
47
|
+
calendarPickerSkeletonClasses: 'dayCalendarSkeletonClasses',
|
|
48
|
+
getCalendarPickerSkeletonUtilityClass: 'getDayCalendarSkeletonUtilityClass'
|
|
49
|
+
};
|
|
50
|
+
const PACKAGE_REGEXP = /@mui\/x-date-pickers(-pro|)(\/(.*)|)/;
|
|
51
|
+
const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
|
|
52
|
+
function transformer(file, api, options) {
|
|
53
|
+
const j = api.jscodeshift;
|
|
54
|
+
const root = j(file.source);
|
|
55
|
+
const printOptions = options.printOptions || {
|
|
56
|
+
quote: 'single',
|
|
57
|
+
trailingComma: true
|
|
58
|
+
};
|
|
59
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
|
|
60
|
+
|
|
61
|
+
// Rename the import specifiers
|
|
62
|
+
// - import { MonthPicker } from '@mui/x-date-pickers/MonthPicker'
|
|
63
|
+
// + import { MonthCalendar } from '@mui/x-date-pickers/MonthPicker'
|
|
64
|
+
matchingImports.find(j.ImportSpecifier).filter(path => !!VARIABLES[path.node.imported.name]).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name])));
|
|
65
|
+
|
|
66
|
+
// Rename the nested import declarations
|
|
67
|
+
// - import {} from '@mui/x-date-pickers/MonthPicker'
|
|
68
|
+
// + import {} from '@mui/x-date-pickers/MonthCalendar'
|
|
69
|
+
matchingImports.filter(path => !!SUB_PACKAGES[matchImport(path)?.[3] ?? '']).replaceWith(path => {
|
|
70
|
+
const subPackage = matchImport(path)[3];
|
|
71
|
+
const importPath = path.node.source.value?.toString() ?? '';
|
|
72
|
+
return j.importDeclaration(path.node.specifiers,
|
|
73
|
+
// copy over the existing import specifiers
|
|
74
|
+
j.stringLiteral(importPath.replace(subPackage, SUB_PACKAGES[subPackage])) // Replace the source with our new source
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Rename the import usage
|
|
79
|
+
// - <CalendarPicker />
|
|
80
|
+
// + <DateCalendar />
|
|
81
|
+
root.find(j.Identifier).filter(path => !!VARIABLES[path.node.name]).replaceWith(path => j.identifier(VARIABLES[path.node.name]));
|
|
82
|
+
return root.toSource(printOptions);
|
|
83
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
const j = api.jscodeshift;
|
|
11
|
+
const root = j(file.source);
|
|
12
|
+
const printOptions = options.printOptions;
|
|
13
|
+
const result = (0, _renameProps.default)({
|
|
14
|
+
root,
|
|
15
|
+
componentNames: ['MonthPicker', 'YearPicker', 'CalendarPicker', 'ClockPicker'],
|
|
16
|
+
props: {
|
|
17
|
+
date: 'value'
|
|
18
|
+
},
|
|
19
|
+
j
|
|
20
|
+
});
|
|
21
|
+
return result.toSource(printOptions);
|
|
22
|
+
}
|
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
|
-
var
|
|
8
|
+
var _presetSafe = _interopRequireDefault(require("../pickers/preset-safe"));
|
|
9
|
+
var _presetSafe2 = _interopRequireDefault(require("../data-grid/preset-safe"));
|
|
9
10
|
function transformer(file, api, options) {
|
|
10
|
-
file.source = (0,
|
|
11
|
+
file.source = (0, _presetSafe.default)(file, api, options);
|
|
12
|
+
file.source = (0, _presetSafe2.default)(file, api, options);
|
|
11
13
|
return file.source;
|
|
12
14
|
}
|