@mui/x-codemod 7.20.0 → 8.0.0-alpha.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 CHANGED
@@ -13,7 +13,7 @@ This repository contains a collection of codemod scripts based for use with
13
13
  <!-- #default-branch-switch -->
14
14
 
15
15
  ```bash
16
- npx @mui/x-codemod@latest <codemod> <paths...>
16
+ npx @mui/x-codemod@next <codemod> <paths...>
17
17
 
18
18
  Applies a `@mui/x-codemod` to the specified paths
19
19
 
@@ -29,8 +29,8 @@ Options:
29
29
  --jscodeshift Pass options directly to jscodeshift [array]
30
30
 
31
31
  Examples:
32
- npx @mui/x-codemod@latest v7.0.0/preset-safe src
33
- npx @mui/x-codemod@latest v6.0.0/component-rename-prop src --
32
+ npx @mui/x-codemod@next v7.0.0/preset-safe src
33
+ npx @mui/x-codemod@next v6.0.0/component-rename-prop src --
34
34
  --component=DataGrid --from=prop --to=newProp
35
35
  ```
36
36
 
@@ -40,9 +40,9 @@ To pass more options directly to jscodeshift, use `--jscodeshift=...`. For examp
40
40
 
41
41
  ```bash
42
42
  // single option
43
- npx @mui/x-codemod@latest --jscodeshift=--run-in-band
43
+ npx @mui/x-codemod@next --jscodeshift=--run-in-band
44
44
  // multiple options
45
- npx @mui/x-codemod@latest --jscodeshift=--cpus=1 --jscodeshift=--print --jscodeshift=--dry --jscodeshift=--verbose=2
45
+ npx @mui/x-codemod@next --jscodeshift=--cpus=1 --jscodeshift=--print --jscodeshift=--dry --jscodeshift=--verbose=2
46
46
  ```
47
47
 
48
48
  See all available options [here](https://github.com/facebook/jscodeshift#usage-cli).
@@ -53,9 +53,127 @@ Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
53
53
  through jscodeshift's `printOptions` command line argument
54
54
 
55
55
  ```bash
56
- npx @mui/x-codemod@latest <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
56
+ npx @mui/x-codemod@next <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
57
57
  ```
58
58
 
59
+ ## v8.0.0
60
+
61
+ ### 🚀 `preset-safe` for v8.0.0
62
+
63
+ A combination of all important transformers for migrating v7 to v8.
64
+ ⚠️ This codemod should be run only once.
65
+ It runs codemods for all MUI X packages (Data Grid, Date and Time Pickers, Tree View, and Charts).
66
+ To run codemods for a specific package, refer to the respective section.
67
+
68
+ ```bash
69
+ npx @mui/x-codemod@latest v8.0.0/preset-safe <path|folder>
70
+ ```
71
+
72
+ The corresponding sub-sections are listed below
73
+
74
+ - [`preset-safe-for-tree-view`](#preset-safe-for-tree-view-v800)
75
+ - [`preset-safe-for-charts`](#preset-safe-for-charts-v800)
76
+
77
+ ### Tree View codemods
78
+
79
+ #### `preset-safe` for tree view v8.0.0
80
+
81
+ The `preset-safe` codemods for tree view.
82
+
83
+ ```bash
84
+ npx @mui/x-codemod@latest v8.0.0/tree-view/preset-safe <path|folder>
85
+ ```
86
+
87
+ The list includes these transformers
88
+
89
+ - [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view)
90
+ - [`rename-tree-item-2`](#rename-tree-item-2)
91
+
92
+ #### `rename-tree-view-simple-tree-view`
93
+
94
+ Renames the Tree View component to Simple Tree View
95
+
96
+ ```diff
97
+ -import { TreeView } from '@mui/x-tree-view';
98
+ +import { SimpleTreeView } from '@mui/x-tree-view';
99
+
100
+ -import { TreeView } from '@mui/x-tree-view/TreeView';
101
+ +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
102
+
103
+ return (
104
+ - <TreeView>
105
+ + <SimpleTreeView>
106
+ <TreeItem itemId="1" label="First item" />
107
+ - </TreeView>
108
+ + </SimpleTreeView>
109
+ );
110
+ ```
111
+
112
+ #### `rename-tree-item-2`
113
+
114
+ Renames the `TreeItem2` component to `TreeItem` (same for any subcomponents or utils like `useTreeItem2` or `TreeItem2Icon`).
115
+
116
+ ```diff
117
+ -import { TreeItem2 } from '@mui/x-tree-view';
118
+ +import { TreeItem } from '@mui/x-tree-view';
119
+
120
+ -import { TreeItem2 } from '@mui/x-tree-view/TreeItem2';
121
+ +import { TreeItem } from '@mui/x-tree-view/TreeItem';
122
+ ```
123
+
124
+ ### Charts codemods
125
+
126
+ #### `preset-safe` for charts v8.0.0
127
+
128
+ The `preset-safe` codemods for charts.
129
+
130
+ ```bash
131
+ npx @mui/x-codemod@latest v8.0.0/charts/preset-safe <path|folder>
132
+ ```
133
+
134
+ The list includes these transformers
135
+
136
+ - [`rename-legend-to-slots-legend`](#rename-legend-to-slots-legend)
137
+ - [`rename-responsive-chart-container`](#rename-responsive-chart-container)
138
+
139
+ #### `rename-legend-to-slots-legend`
140
+
141
+ Renames legend props to the corresponding slotProps.
142
+
143
+ ```diff
144
+ <LineChart
145
+ - legend={{ hiden: true}}
146
+ + slotProps={{ legend: { hiden: true} }}
147
+ />
148
+ ```
149
+
150
+ #### `rename-responsive-chart-container`
151
+
152
+ Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartContainer` and `ChartContainerPro` which have the same behavior in v8.
153
+
154
+ ```diff
155
+ - import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
156
+ + import { ChartContainer } from '@mui/x-charts/ChartContainer';
157
+
158
+ - <ResponsiveChartContainer>
159
+ + <ChartContainer>
160
+ <BarPlot />
161
+ - </ResponsiveChartContainer>
162
+ + </ChartContainer>
163
+ ```
164
+
165
+ :::warning
166
+ If you imported both `ResponsiveChartContainer` and `ChartContainer` in the same file, you might end up with duplicated import.
167
+ Verify the git diff to remove the duplicate.
168
+
169
+ ```diff
170
+ import { ChartContainer } from '@mui/x-charts/ChartContainer';
171
+ - import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
172
+ + import { ChartContainer } from '@mui/x-charts/ChartContainer';
173
+ ```
174
+
175
+ :::
176
+
59
177
  ## v7.0.0
60
178
 
61
179
  ### 🚀 `preset-safe` for v7.0.0
@@ -227,9 +345,9 @@ npx @mui/x-codemod@latest v7.0.0/data-grid/remove-stabilized-experimentalFeature
227
345
 
228
346
  ### Tree View codemods
229
347
 
230
- #### `preset-safe` for tree view v7.0.0
348
+ #### `preset-safe` for Tree View v7.0.0
231
349
 
232
- The `preset-safe` codemods for tree view.
350
+ The `preset-safe` codemods for Tree View.
233
351
 
234
352
  ```bash
235
353
  npx @mui/x-codemod@latest v7.0.0/tree-view/preset-safe <path|folder>
@@ -237,7 +355,7 @@ npx @mui/x-codemod@latest v7.0.0/tree-view/preset-safe <path|folder>
237
355
 
238
356
  The list includes these transformers
239
357
 
240
- - [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view)
358
+ - [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view-1)
241
359
  - [`rename-use-tree-item`](#rename-use-tree-item)
242
360
  - [`rename-expansion-props`](#rename-expansion-props)
243
361
  - [`rename-selection-props`](#rename-selection-props)
@@ -247,7 +365,7 @@ The list includes these transformers
247
365
 
248
366
  #### `rename-tree-view-simple-tree-view`
249
367
 
250
- Renames the `TreeView` component to `SimpleTreeView`
368
+ Renames the Tree View component to Simple Tree View
251
369
 
252
370
  ```diff
253
371
  -import { TreeView } from '@mui/x-tree-view';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "7.20.0",
3
+ "version": "8.0.0-alpha.0",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -25,16 +25,17 @@
25
25
  "url": "https://opencollective.com/mui-org"
26
26
  },
27
27
  "dependencies": {
28
- "@babel/core": "^7.25.7",
29
- "@babel/runtime": "^7.25.7",
30
- "@babel/traverse": "^7.25.7",
31
- "jscodeshift": "17.0.0",
32
- "yargs": "^17.7.2"
28
+ "@babel/core": "^7.26.0",
29
+ "@babel/runtime": "^7.26.0",
30
+ "@babel/traverse": "^7.25.9",
31
+ "jscodeshift": "17.1.1",
32
+ "yargs": "^17.7.2",
33
+ "@mui/x-internals": "8.0.0-alpha.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/jscodeshift": "^0.12.0",
36
- "dayjs": "^1.11.11",
37
- "moment-timezone": "^0.5.45",
37
+ "dayjs": "^1.11.13",
38
+ "moment-timezone": "^0.5.46",
38
39
  "rimraf": "^6.0.1"
39
40
  },
40
41
  "sideEffects": false,
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renameImports = renameImports;
7
+ const getPathStrFromPath = path => {
8
+ let cleanPath;
9
+ if (path.get('type').value === 'ImportDeclaration') {
10
+ cleanPath = path;
11
+ } else {
12
+ cleanPath = path.parentPath.parentPath;
13
+ }
14
+ return cleanPath.node.source.value?.toString() ?? '';
15
+ };
16
+ const getRelativeEndpointFromPathStr = (pathStr, packageNames) => {
17
+ return pathStr.replace(new RegExp(`^(${packageNames.join('|')})/`), '');
18
+ };
19
+ const getMatchingNestedImport = (path, parameters) => {
20
+ const pathStr = getPathStrFromPath(path);
21
+ const relativeEndpoint = getRelativeEndpointFromPathStr(pathStr, parameters.packageNames);
22
+ return parameters.imports.find(importConfig => importConfig.oldEndpoint === relativeEndpoint);
23
+ };
24
+ const getMatchingRootImport = (path, parameters) => {
25
+ return parameters.imports.find(importConfig => {
26
+ return !importConfig.skipRoot && importConfig.importsMapping.hasOwnProperty(path.node.imported.name);
27
+ });
28
+ };
29
+ function renameImports(parameters) {
30
+ const {
31
+ j,
32
+ root
33
+ } = parameters;
34
+ const renamedIdentifiersMap = {};
35
+ const importDeclarations = root
36
+ // Find all the import declarations (import { ... } from '...')
37
+ .find(j.ImportDeclaration);
38
+
39
+ // Rename the nested imports specifiers
40
+ // - import { A } from '@mui/x-date-pickers/A'
41
+ // + import { B } from '@mui/x-date-pickers/A'
42
+ const nestedImportRegExp = new RegExp(`^(${parameters.packageNames.join('|')})/(.*)$`);
43
+ importDeclarations
44
+ // Filter out the declarations that are not nested endpoints of the matching packages or that don't have any update to apply
45
+ .filter(path => {
46
+ const pathStr = getPathStrFromPath(path);
47
+ if (!pathStr.match(nestedImportRegExp)) {
48
+ return false;
49
+ }
50
+ return !!getMatchingNestedImport(path, parameters);
51
+ })
52
+ // Find all the import specifiers (extract A in import { A } from '...')
53
+ .find(j.ImportSpecifier)
54
+ // Filter out the specifiers that don't need to be updated
55
+ .filter(path => {
56
+ return getMatchingNestedImport(path, parameters).importsMapping.hasOwnProperty(path.node.imported.name);
57
+ })
58
+ // Rename the import specifiers
59
+ .replaceWith(path => {
60
+ const newName = getMatchingNestedImport(path, parameters).importsMapping[path.node.imported.name];
61
+
62
+ // If the import is alias, we keep the alias and don't rename the variable usage
63
+ const hasAlias = path.node.local?.name !== path.node.imported.name;
64
+ if (hasAlias) {
65
+ return j.importSpecifier(j.identifier(newName), j.identifier(path.node.local.name));
66
+ }
67
+ renamedIdentifiersMap[path.node.imported.name] = newName;
68
+ return j.importSpecifier(j.identifier(newName));
69
+ });
70
+
71
+ // Rename the root imports specifiers
72
+ // - import { A } from '@mui/x-date-pickers'
73
+ // + import { B } from '@mui/x-date-pickers'
74
+ const rootImportRegExp = new RegExp(`^(${parameters.packageNames.join('|')})$`);
75
+ importDeclarations
76
+ // Filter out the declarations that are not root endpoint of the matching packages
77
+ .filter(path => {
78
+ const pathStr = getPathStrFromPath(path);
79
+ return !!pathStr.match(rootImportRegExp);
80
+ }).find(j.ImportSpecifier).filter(path => {
81
+ return !!getMatchingRootImport(path, parameters);
82
+ })
83
+ // Rename the import specifiers
84
+ .replaceWith(path => {
85
+ const newName = getMatchingRootImport(path, parameters).importsMapping[path.node.imported.name];
86
+
87
+ // If the import is alias, we keep the alias and don't rename the variable usage
88
+ const hasAlias = path.node.local?.name !== path.node.imported.name;
89
+ if (hasAlias) {
90
+ return j.importSpecifier(j.identifier(newName), j.identifier(path.node.local.name));
91
+ }
92
+ renamedIdentifiersMap[path.node.imported.name] = newName;
93
+ return j.importSpecifier(j.identifier(newName));
94
+ });
95
+
96
+ // Rename the nested import declarations
97
+ // - import { B } from '@mui/x-date-pickers/A'
98
+ // + import { B } from '@mui/x-date-pickers/B'
99
+ importDeclarations
100
+ // Filter out the declarations that are not nested endpoints of the matching packages or that don't have any update to apply
101
+ .filter(path => {
102
+ const pathStr = getPathStrFromPath(path);
103
+ if (!pathStr.match(nestedImportRegExp)) {
104
+ return false;
105
+ }
106
+ return !!getMatchingNestedImport(path, parameters)?.newEndpoint;
107
+ }).replaceWith(path => {
108
+ const pathStr = getPathStrFromPath(path);
109
+ const oldEndpoint = getRelativeEndpointFromPathStr(pathStr, parameters.packageNames);
110
+ const newEndpoint = getMatchingNestedImport(path, parameters).newEndpoint;
111
+ const newPathStr = pathStr.replace(oldEndpoint, newEndpoint);
112
+ return j.importDeclaration(
113
+ // Copy over the existing import specifiers
114
+ path.node.specifiers,
115
+ // Replace the source with our new source
116
+ j.stringLiteral(newPathStr));
117
+ });
118
+
119
+ // Rename the import usage
120
+ // - <A />
121
+ // + <B />
122
+ root.find(j.Identifier).filter(path => {
123
+ return renamedIdentifiersMap.hasOwnProperty(path.node.name);
124
+ }).replaceWith(path => {
125
+ const newName = renamedIdentifiersMap[path.node.name];
126
+ return j.identifier(newName);
127
+ });
128
+ return root;
129
+ }
@@ -4,51 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
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);
7
+ var _renameImports = require("../../../util/renameImports");
52
8
  function transformer(file, api, options) {
53
9
  const j = api.jscodeshift;
54
10
  const root = j(file.source);
@@ -56,28 +12,68 @@ function transformer(file, api, options) {
56
12
  quote: 'single',
57
13
  trailingComma: true
58
14
  };
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.hasOwnProperty(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.hasOwnProperty(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
- );
15
+ (0, _renameImports.renameImports)({
16
+ j,
17
+ root,
18
+ packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'],
19
+ imports: [{
20
+ oldEndpoint: 'CalendarPicker',
21
+ newEndpoint: 'DateCalendar',
22
+ importsMapping: {
23
+ CalendarPicker: 'DateCalendar',
24
+ CalendarPickerProps: 'DateCalendarProps',
25
+ CalendarPickerSlotsComponent: 'DateCalendarSlotsComponent',
26
+ CalendarPickerSlotsComponentsProps: 'DateCalendarSlotsComponentsProps',
27
+ CalendarPickerClasses: 'DateCalendarClasses',
28
+ CalendarPickerClassKey: 'DateCalendarClassKey',
29
+ calendarPickerClasses: 'dateCalendarClasses',
30
+ getCalendarPickerUtilityClass: 'getDateCalendarUtilityClass'
31
+ }
32
+ }, {
33
+ oldEndpoint: 'MonthPicker',
34
+ newEndpoint: 'MonthCalendar',
35
+ importsMapping: {
36
+ MonthPicker: 'MonthCalendar',
37
+ MonthPickerProps: 'MonthCalendarProps',
38
+ MonthPickerClasses: 'MonthCalendarClasses',
39
+ MonthPickerClassKey: 'MonthCalendarClassKey',
40
+ monthPickerClasses: 'monthCalendarClasses',
41
+ getMonthPickerUtilityClass: 'getMonthCalendarUtilityClass'
42
+ }
43
+ }, {
44
+ oldEndpoint: 'YearPicker',
45
+ newEndpoint: 'YearCalendar',
46
+ importsMapping: {
47
+ YearPicker: 'YearCalendar',
48
+ YearPickerProps: 'YearCalendarProps',
49
+ YearPickerClasses: 'YearCalendarClasses',
50
+ YearPickerClassKey: 'YearCalendarClassKey',
51
+ yearPickerClasses: 'yearCalendarClasses',
52
+ getYearPickerUtilityClass: 'getYearCalendarUtilityClass'
53
+ }
54
+ }, {
55
+ oldEndpoint: 'ClockPicker',
56
+ newEndpoint: 'TimeClock',
57
+ importsMapping: {
58
+ ClockPicker: 'TimeClock',
59
+ ClockPickerProps: 'TimeClockProps',
60
+ ClockPickerClasses: 'TimeClockClasses',
61
+ ClockPickerClassKey: 'TimeClockClassKey',
62
+ clockPickerClasses: 'timeClockClasses',
63
+ getClockPickerUtilityClass: 'getTimeClockUtilityClass'
64
+ }
65
+ }, {
66
+ oldEndpoint: 'CalendarPickerSkeleton',
67
+ newEndpoint: 'DayCalendarSkeleton',
68
+ importsMapping: {
69
+ CalendarPickerSkeleton: 'DayCalendarSkeleton',
70
+ CalendarPickerSkeletonProps: 'DayCalendarSkeletonProps',
71
+ CalendarPickerSkeletonClasses: 'DayCalendarSkeletonClasses',
72
+ CalendarPickerSkeletonClassKey: 'DayCalendarSkeletonClassKey',
73
+ calendarPickerSkeletonClasses: 'dayCalendarSkeletonClasses',
74
+ getCalendarPickerSkeletonUtilityClass: 'getDayCalendarSkeletonUtilityClass'
75
+ }
76
+ }]
76
77
  });
77
-
78
- // Rename the import usage
79
- // - <CalendarPicker />
80
- // + <DateCalendar />
81
- root.find(j.Identifier).filter(path => VARIABLES.hasOwnProperty(path.node.name)).replaceWith(path => j.identifier(VARIABLES[path.node.name]));
82
78
  return root.toSource(printOptions);
83
79
  }
@@ -4,16 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = transformer;
7
- const VARIABLES = {
8
- TreeView: 'SimpleTreeView',
9
- TreeViewProps: 'SimpleTreeViewProps',
10
- TreeViewClasses: 'SimpleTreeViewClasses',
11
- TreeViewClassKey: 'SimpleTreeViewClassKey',
12
- treeViewClasses: 'simpleTreeViewClasses',
13
- getTreeViewUtilityClass: 'getSimpleTreeViewUtilityClass'
14
- };
15
- const PACKAGE_REGEXP = /@mui\/x-tree-view(\/(.*)|)/;
16
- const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
7
+ var _renameImports = require("../../../util/renameImports");
17
8
  function transformer(file, api, options) {
18
9
  const j = api.jscodeshift;
19
10
  const root = j(file.source);
@@ -21,27 +12,22 @@ function transformer(file, api, options) {
21
12
  quote: 'single',
22
13
  trailingComma: true
23
14
  };
24
- const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
25
-
26
- // Rename the import specifiers
27
- // - import { TreeView } from '@mui/x-tree-view/TreeView'
28
- // + import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'
29
- matchingImports.find(j.ImportSpecifier).filter(path => VARIABLES.hasOwnProperty(path.node.imported.name)).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name])));
30
-
31
- // Rename the nested import declarations
32
- // - import {} from '@mui/x-tree-view/TreeView'
33
- // + import {} from '@mui/x-tree-view/SimpleTreeView'
34
- matchingImports.filter(path => matchImport(path)?.[2] === 'TreeView').replaceWith(path => {
35
- const importPath = path.node.source.value?.toString() ?? '';
36
- return j.importDeclaration(path.node.specifiers,
37
- // copy over the existing import specifiers
38
- j.stringLiteral(importPath.replace('TreeView', 'SimpleTreeView')) // Replace the source with our new source
39
- );
15
+ (0, _renameImports.renameImports)({
16
+ j,
17
+ root,
18
+ packageNames: ['@mui/x-tree-view'],
19
+ imports: [{
20
+ oldEndpoint: 'TreeView',
21
+ newEndpoint: 'SimpleTreeView',
22
+ importsMapping: {
23
+ TreeView: 'SimpleTreeView',
24
+ TreeViewProps: 'SimpleTreeViewProps',
25
+ TreeViewClasses: 'SimpleTreeViewClasses',
26
+ TreeViewClassKey: 'SimpleTreeViewClassKey',
27
+ treeViewClasses: 'simpleTreeViewClasses',
28
+ getTreeViewUtilityClass: 'getSimpleTreeViewUtilityClass'
29
+ }
30
+ }]
40
31
  });
41
-
42
- // Rename the import usage
43
- // - <TreeView />
44
- // + <SimpleTreeView />
45
- root.find(j.Identifier).filter(path => VARIABLES.hasOwnProperty(path.node.name)).replaceWith(path => j.identifier(VARIABLES[path.node.name]));
46
32
  return root.toSource(printOptions);
47
33
  }
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = transformer;
7
- const PACKAGE_REGEXP = /@mui\/x-tree-view(\/TreeItem|)/;
8
- const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
7
+ var _renameImports = require("../../../util/renameImports");
9
8
  function transformer(file, api, options) {
10
9
  const j = api.jscodeshift;
11
10
  const root = j(file.source);
@@ -13,16 +12,16 @@ function transformer(file, api, options) {
13
12
  quote: 'single',
14
13
  trailingComma: true
15
14
  };
16
- const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
17
-
18
- // Rename the import specifiers
19
- // - import { useTreeItem } from '@mui/x-tree-view/TreeItem'
20
- // + import { useTreeItemState } from '@mui/x-tree-view/TreeItem'
21
- matchingImports.find(j.ImportSpecifier).filter(path => path.node.imported.name === 'useTreeItem').replaceWith(j.importSpecifier(j.identifier('useTreeItemState')));
22
-
23
- // Rename the import usage
24
- // - useTreeItem(nodeId);
25
- // + useTreeItemState(nodeId)
26
- root.find(j.Identifier).filter(path => path.node.name === 'useTreeItem').replaceWith(j.identifier('useTreeItemState'));
15
+ (0, _renameImports.renameImports)({
16
+ j,
17
+ root,
18
+ packageNames: ['@mui/x-tree-view'],
19
+ imports: [{
20
+ oldEndpoint: 'TreeItem',
21
+ importsMapping: {
22
+ useTreeItem: 'useTreeItemState'
23
+ }
24
+ }]
25
+ });
27
26
  return root.toSource(printOptions);
28
27
  }
@@ -0,0 +1,14 @@
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 _renameLegendToSlotsLegend = _interopRequireDefault(require("../rename-legend-to-slots-legend"));
9
+ var _renameResponsiveChartContainer = _interopRequireDefault(require("../rename-responsive-chart-container"));
10
+ function transformer(file, api, options) {
11
+ file.source = (0, _renameLegendToSlotsLegend.default)(file, api, options);
12
+ file.source = (0, _renameResponsiveChartContainer.default)(file, api, options);
13
+ return file.source;
14
+ }
@@ -0,0 +1,52 @@
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
+ const legendProps = elementPath.node.openingElement.attributes?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === 'legend');
27
+ if (!legendProps) {
28
+ // No legend props to manage
29
+ return;
30
+ }
31
+ const slotProps = elementPath.node.openingElement.attributes?.find(elementNode => elementNode.type === 'JSXAttribute' && elementNode.name.name === 'slotProps');
32
+ if (slotProps === null) {
33
+ // We create a new slotProps object
34
+ elementPath.node.openingElement.attributes?.push(j.jsxAttribute(j.jsxIdentifier('slotProps'), j.jsxExpressionContainer(j.objectExpression([
35
+ // @ts-ignore legend receives an object.
36
+ j.objectProperty(j.identifier('legend'), legendProps.value.expression)]))));
37
+ } else {
38
+ (0, _addComponentsSlots.transformNestedProp)(elementPath, 'slotProps', 'legend',
39
+ // @ts-ignore legend receives an object.
40
+ legendProps.value.expression, j);
41
+ }
42
+
43
+ // Remove the legend prop
44
+ j(elementPath).find(j.JSXAttribute).filter(a => a.value.name.name === 'legend').forEach(pathToRemove => {
45
+ j(pathToRemove).remove();
46
+ });
47
+ });
48
+ });
49
+ });
50
+ const transformed = root.findJSXElements();
51
+ return transformed.toSource(printOptions);
52
+ }
@@ -0,0 +1,35 @@
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
+ wrapColumn: 40
15
+ };
16
+ (0, _renameImports.renameImports)({
17
+ j,
18
+ root,
19
+ packageNames: ['@mui/x-charts', '@mui/x-charts-pro'],
20
+ imports: [{
21
+ oldEndpoint: 'ResponsiveChartContainer',
22
+ newEndpoint: 'ChartContainer',
23
+ importsMapping: {
24
+ ResponsiveChartContainer: 'ChartContainer'
25
+ }
26
+ }, {
27
+ oldEndpoint: 'ResponsiveChartContainerPro',
28
+ newEndpoint: 'ChartContainerPro',
29
+ importsMapping: {
30
+ ResponsiveChartContainerPro: 'ChartContainerPro'
31
+ }
32
+ }]
33
+ });
34
+ return root.toSource(printOptions);
35
+ }
@@ -0,0 +1,14 @@
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 _presetSafe = _interopRequireDefault(require("../tree-view/preset-safe"));
9
+ var _presetSafe2 = _interopRequireDefault(require("../charts/preset-safe"));
10
+ function transformer(file, api, options) {
11
+ file.source = (0, _presetSafe.default)(file, api, options);
12
+ file.source = (0, _presetSafe2.default)(file, api, options);
13
+ return file.source;
14
+ }
@@ -0,0 +1,14 @@
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 _renameTreeViewSimpleTreeView = _interopRequireDefault(require("../rename-tree-view-simple-tree-view"));
9
+ var _renameTreeItem = _interopRequireDefault(require("../rename-tree-item-2"));
10
+ function transformer(file, api, options) {
11
+ file.source = (0, _renameTreeViewSimpleTreeView.default)(file, api, options);
12
+ file.source = (0, _renameTreeItem.default)(file, api, options);
13
+ return file.source;
14
+ }
@@ -0,0 +1,91 @@
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
+ wrapColumn: 40
15
+ };
16
+ (0, _renameImports.renameImports)({
17
+ j,
18
+ root,
19
+ packageNames: ['@mui/x-tree-view', '@mui/x-tree-view-pro'],
20
+ imports: [{
21
+ oldEndpoint: 'TreeItem2',
22
+ newEndpoint: 'TreeItem',
23
+ importsMapping: {
24
+ TreeItem2: 'TreeItem',
25
+ TreeItem2Root: 'TreeItemRoot',
26
+ TreeItem2Content: 'TreeItemContent',
27
+ TreeItem2IconContainer: 'TreeItemIconContainer',
28
+ TreeItem2GroupTransition: 'TreeItemGroupTransition',
29
+ TreeItem2Checkbox: 'TreeItemCheckbox',
30
+ TreeItem2Label: 'TreeItemLabel',
31
+ TreeItem2Props: 'TreeItemProps',
32
+ TreeItem2Slots: 'TreeItemSlots',
33
+ TreeItem2SlotProps: 'TreeItemSlotProps'
34
+ }
35
+ }, {
36
+ oldEndpoint: 'useTreeItem2',
37
+ newEndpoint: 'useTreeItem',
38
+ importsMapping: {
39
+ useTreeItem2: 'useTreeItem',
40
+ unstable_useTreeItem2: 'useTreeItem',
41
+ UseTreeItem2Parameters: 'UseTreeItemParameters',
42
+ UseTreeItem2ReturnValue: 'UseTreeItemReturnValue',
43
+ UseTreeItem2Status: 'UseTreeItemStatus',
44
+ UseTreeItem2RootSlotOwnProps: 'UseTreeItemRootSlotOwnProps',
45
+ UseTreeItem2ContentSlotOwnProps: 'UseTreeItemContentSlotOwnProps',
46
+ UseTreeItem2LabelInputSlotOwnProps: 'UseTreeItemLabelInputSlotOwnProps',
47
+ UseTreeItem2LabelSlotOwnProps: 'UseTreeItemLabelSlotOwnProps',
48
+ UseTreeItem2CheckboxSlotOwnProps: 'UseTreeItemCheckboxSlotOwnProps',
49
+ UseTreeItem2IconContainerSlotOwnProps: 'UseTreeItemIconContainerSlotOwnProps',
50
+ UseTreeItem2GroupTransitionSlotOwnProps: 'UseTreeItemGroupTransitionSlotOwnProps',
51
+ UseTreeItem2DragAndDropOverlaySlotOwnProps: 'UseTreeItemDragAndDropOverlaySlotOwnProps'
52
+ }
53
+ }, {
54
+ oldEndpoint: 'TreeItem2Provider',
55
+ newEndpoint: 'TreeItemProvider',
56
+ importsMapping: {
57
+ TreeItem2Provider: 'TreeItemProvider',
58
+ TreeItem2ProviderProps: 'TreeItemProviderProps'
59
+ }
60
+ }, {
61
+ oldEndpoint: 'TreeItem2Icon',
62
+ newEndpoint: 'TreeItemIcon',
63
+ importsMapping: {
64
+ TreeItem2Icon: 'TreeItemIcon',
65
+ TreeItem2IconProps: 'TreeItemIconProps',
66
+ TreeItem2IconSlots: 'TreeItemIconSlots',
67
+ TreeItem2IconSlotProps: 'TreeItemIconSlotProps'
68
+ }
69
+ }, {
70
+ oldEndpoint: 'TreeItem2DragAndDropOverlay',
71
+ newEndpoint: 'TreeItemDragAndDropOverlay',
72
+ importsMapping: {
73
+ TreeItem2DragAndDropOverlay: 'TreeItemDragAndDropOverlay',
74
+ TreeItem2DragAndDropOverlayProps: 'TreeItemDragAndDropOverlayProps'
75
+ }
76
+ }, {
77
+ oldEndpoint: 'TreeItem2LabelInput',
78
+ newEndpoint: 'TreeItemLabelInput',
79
+ importsMapping: {
80
+ TreeItem2LabelInput: 'TreeItemLabelInput',
81
+ TreeItem2LabelInputProps: 'TreeItemLabelInputProps'
82
+ }
83
+ }, {
84
+ oldEndpoint: 'hooks',
85
+ importsMapping: {
86
+ useTreeItem2Utils: 'useTreeItemUtils'
87
+ }
88
+ }]
89
+ });
90
+ return root.toSource(printOptions);
91
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _renameTreeViewSimpleTreeView.default;
11
+ }
12
+ });
13
+ var _renameTreeViewSimpleTreeView = _interopRequireDefault(require("../../../v7.0.0/tree-view/rename-tree-view-simple-tree-view"));
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _path = _interopRequireDefault(require("path"));
5
- var _chai = require("chai");
6
- var _jscodeshift = _interopRequireDefault(require("jscodeshift"));
7
- var _ = _interopRequireDefault(require("."));
8
- var _readFile = _interopRequireDefault(require("../../../util/readFile"));
9
- function read(fileName) {
10
- return (0, _readFile.default)(_path.default.join(__dirname, fileName));
11
- }
12
- const TEST_FILES = ['nested-imports', 'root-imports'];
13
- describe('v7.0.0/tree-view', () => {
14
- describe('rename-tree-view-simple-tree-view', () => {
15
- TEST_FILES.forEach(testFile => {
16
- const actualPath = `./actual-${testFile}.spec.tsx`;
17
- const expectedPath = `./expected-${testFile}.spec.tsx`;
18
- describe(`${testFile.replace(/-/g, ' ')}`, () => {
19
- it('transforms imports as needed', () => {
20
- const actual = (0, _.default)({
21
- source: read(actualPath)
22
- }, {
23
- jscodeshift: _jscodeshift.default.withParser('tsx')
24
- }, {});
25
- const expected = read(expectedPath);
26
- (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
27
- });
28
- it('should be idempotent', () => {
29
- const actual = (0, _.default)({
30
- source: read(expectedPath)
31
- }, {
32
- jscodeshift: _jscodeshift.default.withParser('tsx')
33
- }, {});
34
- const expected = read(expectedPath);
35
- (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
36
- });
37
- });
38
- });
39
- });
40
- });
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _path = _interopRequireDefault(require("path"));
5
- var _chai = require("chai");
6
- var _jscodeshift = _interopRequireDefault(require("jscodeshift"));
7
- var _ = _interopRequireDefault(require("."));
8
- var _readFile = _interopRequireDefault(require("../../../util/readFile"));
9
- function read(fileName) {
10
- return (0, _readFile.default)(_path.default.join(__dirname, fileName));
11
- }
12
- const TEST_FILES = ['nested-imports', 'root-imports'];
13
- describe('v7.0.0/tree-view', () => {
14
- describe('rename-use-tree-item', () => {
15
- TEST_FILES.forEach(testFile => {
16
- const actualPath = `./actual-${testFile}.spec.tsx`;
17
- const expectedPath = `./expected-${testFile}.spec.tsx`;
18
- describe(`${testFile.replace(/-/g, ' ')}`, () => {
19
- it('transforms imports as needed', () => {
20
- const actual = (0, _.default)({
21
- source: read(actualPath)
22
- }, {
23
- jscodeshift: _jscodeshift.default.withParser('tsx')
24
- }, {});
25
- const expected = read(expectedPath);
26
- (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
27
- });
28
- it('should be idempotent', () => {
29
- const actual = (0, _.default)({
30
- source: read(expectedPath)
31
- }, {
32
- jscodeshift: _jscodeshift.default.withParser('tsx')
33
- }, {});
34
- const expected = read(expectedPath);
35
- (0, _chai.expect)(actual).to.equal(expected, 'The transformed version should be correct');
36
- });
37
- });
38
- });
39
- });
40
- });