@mui/x-codemod 7.0.0-alpha.0 → 7.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
@@ -56,13 +56,126 @@ through jscodeshift's `printOptions` command line argument
56
56
  npx @mui/x-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
57
57
  ```
58
58
 
59
- ## Included scripts
59
+ ## v7.0.0
60
60
 
61
- ### v6.0.0
61
+ ### 🚀 `preset-safe` for v7.0.0
62
62
 
63
- #### 🚀 `preset-safe`
63
+ A combination of all important transformers for migrating v6 to v7.
64
+ ⚠️ This codemod should be run only once.
65
+ It runs codemods for both Data Grid and Date and Time Pickers packages.
66
+ To run codemods for a specific package, refer to the respective section.
64
67
 
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.
68
+ ```bash
69
+ npx @mui/x-codemod v7.0.0/preset-safe <path|folder>
70
+ ```
71
+
72
+ The corresponding sub-sections are listed below
73
+
74
+ - [`preset-safe-for-pickers`](#preset-safe-for-pickers-v700)
75
+ - [`preset-safe-for-data-grid`](#preset-safe-for-data-grid-v700)
76
+
77
+ ### Pickers codemods
78
+
79
+ #### `preset-safe` for pickers v7.0.0
80
+
81
+ The `preset-safe` codemods for pickers.
82
+
83
+ ```bash
84
+ npx @mui/x-codemod v7.0.0/pickers/preset-safe <path|folder>
85
+ ```
86
+
87
+ The list includes these transformers
88
+
89
+ - [`rename-components-to-slots-pickers`](#rename-components-to-slots-pickers)
90
+ - [`rename-default-calendar-month-to-reference-date`](#rename-default-calendar-month-to-reference-date)
91
+ - [`rename-day-picker-classes`](/rename-day-picker-classes)
92
+
93
+ #### `rename-components-to-slots-pickers`
94
+
95
+ Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
96
+
97
+ This change only affects Date and Time Picker components.
98
+
99
+ ```diff
100
+ <DatePicker
101
+ - components={{ Toolbar: CustomToolbar }}
102
+ + slots={{ toolbar: CustomToolbar }}
103
+ - componentsProps={{ actionBar: { actions: ['clear'] } }}
104
+ + slotProps={{ actionBar: { actions: ['clear'] } }}
105
+ />;
106
+ ```
107
+
108
+ ```bash
109
+ npx @mui/x-codemod v7.0.0/pickers/rename-components-to-slots <path>
110
+ ```
111
+
112
+ #### `rename-default-calendar-month-to-reference-date`
113
+
114
+ Replace the `defaultCalendarMonth` prop with the `referenceDate` prop.
115
+
116
+ ```diff
117
+ - <DateCalendar defaultCalendarMonth={dayjs('2022-04-01')};
118
+ + <DateCalendar referenceDate{dayjs('2022-04-01')} />
119
+ ```
120
+
121
+ ```bash
122
+ npx @mui/x-codemod v7.0.0/pickers/rename-default-calendar-month-to-reference-date <path>
123
+ ```
124
+
125
+ #### `rename-day-picker-classes`
126
+
127
+ Rename the `dayPickerClasses` variable to `dayCalendarClasses`.
128
+
129
+ ```diff
130
+ - import { dayPickerClasses } from '@mui/x-date-pickers/DateCalendar';
131
+ + import { dayCalendarClasses } from '@mui/x-date-pickers/DateCalendar';
132
+ ```
133
+
134
+ ```bash
135
+ npx @mui/x-codemod v7.0.0/pickers/rename-day-picker-classes <path>
136
+ ```
137
+
138
+ ### Data grid codemods
139
+
140
+ #### `preset-safe` for data grid v7.0.0
141
+
142
+ The `preset-safe` codemods for data grid.
143
+
144
+ ```bash
145
+ npx @mui/x-codemod v7.0.0/data-grid/preset-safe <path|folder>
146
+ ```
147
+
148
+ The list includes these transformers
149
+
150
+ - [`rename-components-to-slots-data-grid`](#rename-components-to-slots-data-grid)
151
+
152
+ #### `rename-components-to-slots-data-grid`
153
+
154
+ Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
155
+
156
+ This change only affects Data Grid components.
157
+
158
+ ```diff
159
+ <DataGrid
160
+ - components={{ Toolbar: CustomToolbar }}
161
+ + slots={{ toolbar: CustomToolbar }}
162
+ - componentsProps={{ toolbar: { showQuickFilter: true }}}
163
+ + slotProps={{ toolbar: { showQuickFilter: true }}}
164
+ />;
165
+ ```
166
+
167
+ ```bash
168
+ npx @mui/x-codemod v7.0.0/data-grid/rename-components-to-slots <path>
169
+ ```
170
+
171
+ ## v6.0.0
172
+
173
+ ### 🚀 `preset-safe` for v6.0.0
174
+
175
+ A combination of all important transformers for migrating v5 to v6.
176
+ ⚠️ This codemod should be run only once.
177
+ It runs codemods for both Data Grid and Date and Time Pickers packages.
178
+ To run codemods for a specific package, refer to the respective section.
66
179
 
67
180
  ```bash
68
181
  npx @mui/x-codemod v6.0.0/preset-safe <path|folder>
@@ -70,12 +183,12 @@ npx @mui/x-codemod v6.0.0/preset-safe <path|folder>
70
183
 
71
184
  The corresponding sub-sections are listed below
72
185
 
73
- - [`preset-safe-for-pickers`](#preset-safe-for-pickers)
74
- - [`preset-safe-for-data-grid`](#preset-safe-for-data-grid)
186
+ - [`preset-safe-for-pickers`](#preset-safe-for-pickers-v600)
187
+ - [`preset-safe-for-data-grid`](#preset-safe-for-data-grid-v600)
75
188
 
76
189
  ### Pickers codemods
77
190
 
78
- #### `preset-safe` for pickers
191
+ #### `preset-safe` for pickers v6.0.0
79
192
 
80
193
  The `preset-safe` codemods for pickers.
81
194
 
@@ -385,7 +498,7 @@ npx @mui/x-codemod v6.0.0/pickers/rename-default-toolbar-title-localeText <path>
385
498
 
386
499
  Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
387
500
 
388
- This change only affects pickers components.
501
+ This change only affects Date and Time Pickers components.
389
502
 
390
503
  ```diff
391
504
  <DatePicker
@@ -402,7 +515,7 @@ npx @mui/x-codemod v6.0.0/pickers/rename-components-to-slots <path>
402
515
 
403
516
  ### Data grid codemods
404
517
 
405
- #### `preset-safe` for data grid
518
+ #### `preset-safe` for data grid v6.0.0
406
519
 
407
520
  The `preset-safe` codemods for data grid.
408
521
 
@@ -684,7 +797,7 @@ npx @mui/x-codemod v6.0.0/data-grid/replace-onCellFocusOut-prop <path>
684
797
 
685
798
  Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
686
799
 
687
- This change only affects data grid components.
800
+ This change only affects Data Grid components.
688
801
 
689
802
  ```diff
690
803
  <DataGrid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "7.0.0-alpha.0",
3
+ "version": "7.0.0-alpha.2",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -9,6 +9,7 @@
9
9
  "react",
10
10
  "react-component",
11
11
  "mui",
12
+ "mui-x",
12
13
  "codemod",
13
14
  "jscodeshift"
14
15
  ],
@@ -28,12 +29,12 @@
28
29
  "homepage": "https://github.com/mui/mui-x/tree/master/packages/x-codemod",
29
30
  "funding": {
30
31
  "type": "opencollective",
31
- "url": "https://opencollective.com/mui"
32
+ "url": "https://opencollective.com/mui-org"
32
33
  },
33
34
  "dependencies": {
34
- "@babel/core": "^7.23.2",
35
- "@babel/runtime": "^7.23.2",
36
- "@babel/traverse": "^7.23.2",
35
+ "@babel/core": "^7.23.3",
36
+ "@babel/runtime": "^7.23.4",
37
+ "@babel/traverse": "^7.23.4",
37
38
  "jscodeshift": "0.13.1",
38
39
  "jscodeshift-add-imports": "^1.0.10",
39
40
  "yargs": "^17.7.2"
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _renameComponentsToSlots.default;
11
+ }
12
+ });
13
+ var _renameComponentsToSlots = _interopRequireDefault(require("../../../v6.0.0/data-grid/rename-components-to-slots"));
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
- var _renameComponentsToSlots = _interopRequireDefault(require("../../../v6.0.0/pickers/rename-components-to-slots"));
8
+ var _renameComponentsToSlots = _interopRequireDefault(require("../rename-components-to-slots"));
9
+ var _renameDefaultCalendarMonthToReferenceDate = _interopRequireDefault(require("../rename-default-calendar-month-to-reference-date"));
10
+ var _renameDayPickerClasses = _interopRequireDefault(require("../rename-day-picker-classes"));
9
11
  function transformer(file, api, options) {
10
12
  file.source = (0, _renameComponentsToSlots.default)(file, api, options);
13
+ file.source = (0, _renameDefaultCalendarMonthToReferenceDate.default)(file, api, options);
14
+ file.source = (0, _renameDayPickerClasses.default)(file, api, options);
11
15
  return file.source;
12
16
  }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _renameComponentsToSlots.default;
11
+ }
12
+ });
13
+ var _renameComponentsToSlots = _interopRequireDefault(require("../../../v6.0.0/pickers/rename-components-to-slots"));
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ const PACKAGE_REGEXP = /@mui\/x-date-pickers(-pro|)(\/(.*)|)/;
8
+ const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
9
+ function transformer(file, api, options) {
10
+ const j = api.jscodeshift;
11
+ const root = j(file.source);
12
+ const printOptions = options.printOptions || {
13
+ quote: 'single',
14
+ trailingComma: true
15
+ };
16
+ const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
17
+
18
+ // Rename the import specifiers
19
+ // - import { dayPickerClasses } from '@mui/x-date-pickers'
20
+ // + import { dayCalendarClasses } from '@mui/x-date-pickers'
21
+ matchingImports.find(j.ImportSpecifier).filter(path => path.node.imported.name === 'dayPickerClasses').replaceWith(path => j.importSpecifier(j.identifier('dayCalendarClasses'), path.value.local));
22
+
23
+ // Rename the import usage
24
+ // - dayPickerClasses.root
25
+ // + dayCalendarClasses.root
26
+ root.find(j.Identifier).filter(path => path.node.name === 'dayPickerClasses').replaceWith(() => j.identifier('dayCalendarClasses'));
27
+ return root.toSource(printOptions);
28
+ }
@@ -0,0 +1,21 @@
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
+ return (0, _renameProps.default)({
14
+ root,
15
+ componentNames: ['DateCalendar', 'DatePicker', 'DateRangeCalendar', 'DateRangePicker', 'DateTimePicker', 'DesktopDatePicker', 'DesktopDateRangePicker', 'DesktopDateTimePicker', 'MobileDatePicker', 'MobileDateRangePicker', 'MobileDateTimePicker', 'StaticDatePicker', 'StaticDateRangePicker', 'StaticDateTimePicker'],
16
+ props: {
17
+ defaultCalendarMonth: 'referenceDate'
18
+ },
19
+ j
20
+ }).toSource(printOptions);
21
+ }