@mui/x-codemod 6.0.0-alpha.11 → 6.0.0-alpha.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "6.0.0-alpha.11",
3
+ "version": "6.0.0-alpha.13",
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.2",
35
- "@babel/runtime": "^7.20.1",
36
- "@babel/traverse": "^7.20.1",
34
+ "@babel/core": "^7.20.5",
35
+ "@babel/runtime": "^7.20.6",
36
+ "@babel/traverse": "^7.20.5",
37
37
  "jscodeshift": "0.13.1",
38
38
  "jscodeshift-add-imports": "^1.0.10",
39
39
  "yargs": "^17.6.2"
@@ -7,10 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = transformer;
8
8
  var _localizationProviderRenameLocale = _interopRequireDefault(require("../localization-provider-rename-locale"));
9
9
  var _textPropsToLocaleText = _interopRequireDefault(require("../text-props-to-localeText"));
10
+ var _viewComponentsRename = _interopRequireDefault(require("../view-components-rename"));
10
11
  function transformer(file, api, options) {
11
12
  file.source = (0, _localizationProviderRenameLocale.default)(file, api, options);
12
13
 
13
14
  // Should be run before the renaming of components such as `ClockPicker` to `TimeClock`.
14
15
  file.source = (0, _textPropsToLocaleText.default)(file, api, options);
16
+ file.source = (0, _viewComponentsRename.default)(file, api, options);
15
17
  return file.source;
16
18
  }
@@ -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
+ }