@mui/codemod 5.14.4 → 5.14.6

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
@@ -266,12 +266,20 @@ The associated breaking change was done in [#34997](https://github.com/mui/mater
266
266
 
267
267
  #### `date-pickers-moved-to-x`
268
268
 
269
- Rename the imports of date and time pickers from `@mui/lab` to `@mui/x-date-pickers` and `@mui/x-date-pickers-pro`.
269
+ Rename the imports of Date and Time Pickers from `@mui/lab` to `@mui/x-date-pickers` and `@mui/x-date-pickers-pro`.
270
270
 
271
271
  ```bash
272
272
  npx @mui/codemod v5.0.0/date-pickers-moved-to-x <path>
273
273
  ```
274
274
 
275
+ #### `tree-view-moved-to-x`
276
+
277
+ Rename the imports of Tree View from `@mui/lab` to `@mui/x-tree-view`.
278
+
279
+ ```bash
280
+ npx @mui/codemod v5.0.0/tree-view-moved-to-x <path>
281
+ ```
282
+
275
283
  #### 🚀 `preset-safe`
276
284
 
277
285
  A combination of all important transformers for migrating v4 to v5. ⚠️ This codemod should be run only once.
package/codemod.js CHANGED
File without changes
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ const _exports = {
8
+ TreeView: {
9
+ default: 'TreeView',
10
+ named: ['treeViewClasses', 'TreeViewClasses', 'TreeViewClassKey', 'getTreeViewUtilityClass', 'TreeViewPropsBase', 'TreeViewProps', 'SingleSelectTreeViewProps', 'MultiSelectTreeViewProps']
11
+ },
12
+ TreeItem: {
13
+ default: 'TreeItem',
14
+ named: ['useTreeItem', 'treeItemClasses', 'TreeItemClasses', 'TreeItemClassKey', 'getTreeItemUtilityClass', 'TreeItemProps', 'TreeItemContentProps']
15
+ }
16
+ };
17
+ const buildLookup = () => {
18
+ return Object.fromEntries(Object.entries(_exports).flatMap(([entryPoint, entryPointData]) => [entryPointData.default, ...entryPointData.named].map(exportName => [exportName, {
19
+ entryPoint
20
+ }])));
21
+ };
22
+
23
+ /**
24
+ * @param {import('jscodeshift').FileInfo} file
25
+ * @param {import('jscodeshift').API} api
26
+ */
27
+ function transformer(fileInfo, api, options) {
28
+ const j = api.jscodeshift;
29
+ const printOptions = options.printOptions || {
30
+ quote: 'single'
31
+ };
32
+ const lookup = buildLookup();
33
+ const root = j(fileInfo.source);
34
+ root.find(j.ImportDeclaration).forEach(path => {
35
+ const importSource = path.node.source.value;
36
+ const subPackageImportMatch = importSource.match(/@mui\/lab\/(.*)/);
37
+ if (subPackageImportMatch !== null) {
38
+ const subModule = subPackageImportMatch[1];
39
+ if (subModule.startsWith('internal')) {
40
+ console.warn('Imports from `@mui/lab/internal` are not supported');
41
+ return;
42
+ }
43
+ if (_exports[subModule]) {
44
+ /**
45
+ * @type {import('jscodeshift').ASTPath}
46
+ */
47
+ const sourcePath = path.get('source');
48
+ const targetPackage = '@mui/x-tree-view';
49
+ const targetImportPath = `${targetPackage}/${subModule}`;
50
+ sourcePath.replace(j.stringLiteral(targetImportPath));
51
+ const importDeclaration = path.value;
52
+ importDeclaration.specifiers = importDeclaration.specifiers.map(specifier => {
53
+ if (specifier.type === 'ImportDefaultSpecifier') {
54
+ const localName = specifier.local.name;
55
+ return j.importSpecifier(j.identifier(subModule), j.identifier(localName));
56
+ }
57
+ return specifier;
58
+ });
59
+ }
60
+ } else if (importSource === '@mui/lab') {
61
+ // Sieve import specifiers into /core and /lab
62
+ const xImportSpecifiers = [];
63
+ const labImportSpecifiers = [];
64
+ path.node.specifiers.forEach(specifier => {
65
+ if (specifier.type === 'ImportSpecifier') {
66
+ const lookupValue = lookup[specifier.imported.name];
67
+ if (lookupValue) {
68
+ xImportSpecifiers.push(specifier);
69
+ } else {
70
+ labImportSpecifiers.push(specifier);
71
+ }
72
+ } else {
73
+ // `import Lab from '@material-ui/lab'`
74
+ // `import * as Lab from '@material-ui/lab'`
75
+ // These imports would require scope analysis.
76
+ console.warn(`Can't handle ${specifier.type}`);
77
+ }
78
+ });
79
+ if (xImportSpecifiers.length > 0) {
80
+ const targetPackage = '@mui/x-tree-view';
81
+ path.replace(j.importDeclaration(xImportSpecifiers, j.stringLiteral(targetPackage)), j.importDeclaration(labImportSpecifiers, j.stringLiteral('@mui/lab')));
82
+ }
83
+ }
84
+ }).toSource(printOptions);
85
+ return root.toSource(printOptions);
86
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ var _lab = require("@mui/lab");
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _TreeView = _interopRequireWildcard(require("@mui/lab/TreeView"));
5
+ var _TreeItem = _interopRequireWildcard(require("@mui/lab/TreeItem"));
6
+ var _Timeline = _interopRequireDefault(require("@mui/lab/Timeline"));
7
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ var _xTreeView = require("@mui/x-tree-view");
4
+ var _lab = require("@mui/lab");
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _TreeView = require("@mui/x-tree-view/TreeView");
5
+ var _TreeItem = require("@mui/x-tree-view/TreeItem");
6
+ var _Timeline = _interopRequireDefault(require("@mui/lab/Timeline"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.14.4",
3
+ "version": "5.14.6",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -30,9 +30,9 @@
30
30
  "url": "https://opencollective.com/mui"
31
31
  },
32
32
  "dependencies": {
33
- "@babel/core": "^7.22.9",
34
- "@babel/runtime": "^7.22.6",
35
- "@babel/traverse": "^7.22.8",
33
+ "@babel/core": "^7.22.10",
34
+ "@babel/runtime": "^7.22.10",
35
+ "@babel/traverse": "^7.22.10",
36
36
  "jscodeshift": "^0.13.1",
37
37
  "jscodeshift-add-imports": "^1.0.10",
38
38
  "yargs": "^17.7.2"