@mui/codemod 5.2.0 → 5.4.1

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
@@ -39,7 +39,7 @@ Examples:
39
39
  npx @mui/codemod v5.0.0/preset-safe src --parser=flow
40
40
  ```
41
41
 
42
- #### jscodeshift options
42
+ ### jscodeshift options
43
43
 
44
44
  To pass more options directly to jscodeshift, use `--jscodeshift="..."`. For example:
45
45
 
@@ -49,7 +49,7 @@ npx @mui/codemod --jscodeshift="--run-in-band --verbose=2"
49
49
 
50
50
  See all available options [here](https://github.com/facebook/jscodeshift#usage-cli).
51
51
 
52
- #### Recast Options
52
+ ### Recast Options
53
53
 
54
54
  Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
55
55
  through jscodeshift's `printOptions` command line argument
@@ -1073,7 +1073,7 @@ You can find more details about this breaking change in [the migration guide](ht
1073
1073
 
1074
1074
  #### `mui-replace`
1075
1075
 
1076
- Replace every occurrence of `material-ui` related package with the new package names (listed below) except these packages (`@material-ui/pickers`, `@material-ui/data-grid`, `@material-ui/x-grid` & `@material-ui/x-grid-data-generator`). [More details about why package names are changed](https://github.com/mui-org/material-ui/issues/27666)
1076
+ Replace every occurrence of `material-ui` related package with the new package names (listed below) except these packages (`@material-ui/pickers`, `@material-ui/data-grid`, `@material-ui/x-grid` & `@material-ui/x-grid-data-generator`). [More details about why package names are changed](https://github.com/mui/material-ui/issues/27666)
1077
1077
 
1078
1078
  **Material Design components**
1079
1079
 
@@ -1247,13 +1247,13 @@ npx @mui/codemod v1.0.0/color-imports <path>
1247
1247
 
1248
1248
  <!-- #default-branch-switch -->
1249
1249
 
1250
- ```
1250
+ ```sh
1251
1251
  npx @mui/codemod v1.0.0/color-imports <path> -- --importPath='mui/styles/colors' --targetPath='mui/colors'
1252
1252
  ```
1253
1253
 
1254
1254
  #### `svg-icon-imports`
1255
1255
 
1256
- Updates the `svg-icons` import paths from `material-ui/svg-icons/<category>/<icon-name>` to `@material-ui/icons/<IconName>`, to use the new [`@material-ui/icons`](https://github.com/mui-org/material-ui/tree/next/packages/mui-material-icons) package.
1256
+ Updates the `svg-icons` import paths from `material-ui/svg-icons/<category>/<icon-name>` to `@material-ui/icons/<IconName>`, to use the new `@material-ui/icons` package.
1257
1257
  The diff should look like this:
1258
1258
 
1259
1259
  ```diff
package/codemod.js CHANGED
File without changes
@@ -9,6 +9,7 @@ function propsToObject({
9
9
  j,
10
10
  root,
11
11
  componentName,
12
+ aliasName,
12
13
  propName,
13
14
  props
14
15
  }) {
@@ -20,30 +21,41 @@ function propsToObject({
20
21
  return value;
21
22
  }
22
23
 
23
- return root.findJSXElements(componentName).forEach(path => {
24
- let propValue = [];
25
- const attributes = path.node.openingElement.attributes;
26
- attributes.forEach((node, index) => {
27
- // Only transform whitelisted props
28
- if (node.type === 'JSXAttribute' && props.includes(node.name.name)) {
29
- propValue = buildObject(node, propValue);
30
- delete attributes[index];
24
+ const result = aliasName ? root.find(j.JSXElement, {
25
+ openingElement: {
26
+ name: {
27
+ property: {
28
+ name: componentName
29
+ }
31
30
  }
32
- });
31
+ }
32
+ }) : root.findJSXElements(componentName);
33
+ return result.forEach(path => {
34
+ if (!aliasName || aliasName && path.node.openingElement.name.object.name === aliasName) {
35
+ let propValue = [];
36
+ const attributes = path.node.openingElement.attributes;
37
+ attributes.forEach((node, index) => {
38
+ // Only transform whitelisted props
39
+ if (node.type === 'JSXAttribute' && props.includes(node.name.name)) {
40
+ propValue = buildObject(node, propValue);
41
+ delete attributes[index];
42
+ }
43
+ });
33
44
 
34
- if (propValue.length > 0) {
35
- const propNameAttr = attributes.find(attr => {
36
- var _attr$name;
45
+ if (propValue.length > 0) {
46
+ const propNameAttr = attributes.find(attr => {
47
+ var _attr$name;
37
48
 
38
- return (attr == null ? void 0 : (_attr$name = attr.name) == null ? void 0 : _attr$name.name) === propName;
39
- });
49
+ return (attr == null ? void 0 : (_attr$name = attr.name) == null ? void 0 : _attr$name.name) === propName;
50
+ });
40
51
 
41
- if (propNameAttr) {
42
- var _propNameAttr$value$e;
52
+ if (propNameAttr) {
53
+ var _propNameAttr$value$e;
43
54
 
44
- (((_propNameAttr$value$e = propNameAttr.value.expression) == null ? void 0 : _propNameAttr$value$e.properties) || []).push(...j.objectExpression(propValue).properties);
45
- } else {
46
- attributes.push(j.jsxAttribute(j.jsxIdentifier(propName), j.jsxExpressionContainer(j.objectExpression(propValue))));
55
+ (((_propNameAttr$value$e = propNameAttr.value.expression) == null ? void 0 : _propNameAttr$value$e.properties) || []).push(...j.objectExpression(propValue).properties);
56
+ } else {
57
+ attributes.push(j.jsxAttribute(j.jsxIdentifier(propName), j.jsxExpressionContainer(j.objectExpression(propValue))));
58
+ }
47
59
  }
48
60
  }
49
61
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  // This codemod attempts to fix the color imports breaking change introduced in
4
- // https://github.com/mui-org/material-ui/releases/tag/v1.0.0-alpha.21
4
+ // https://github.com/mui/material-ui/releases/tag/v1.0.0-alpha.21
5
5
  // List of colors that are in the `common` module
6
6
  const commonColors = ['black', 'white', 'transparent', 'fullBlack', 'darkBlack', 'lightBlack', 'minBlack', 'faintBlack', 'fullWhite', 'darkWhite', 'lightWhite'];
7
7
  /**
@@ -21,7 +21,6 @@ function pascalize(iconName) {
21
21
  * Update all `svg-icons` import references to use `@material-ui/icons` package.
22
22
  * Find and replace string literal AST nodes to ensure all svg-icon paths get updated, regardless
23
23
  * of being in an import declaration, or a require() call, etc.
24
- * https://github.com/mui-org/material-ui/tree/next/packages/@material-ui/icons
25
24
  * @param {jscodeshift_api_object} j
26
25
  * @param {jscodeshift_ast_object} root
27
26
  */
@@ -21,9 +21,20 @@ function transformer(file, api, options) {
21
21
  const printOptions = options.printOptions || {
22
22
  quote: 'single'
23
23
  };
24
+ let aliasName;
25
+ root.find(j.ImportDeclaration).forEach(path => {
26
+ if (path.node.source.value.match(/^(@mui\/material|@material-ui\/core)$/)) {
27
+ var _path$node$specifiers;
28
+
29
+ if (((_path$node$specifiers = path.node.specifiers[0]) == null ? void 0 : _path$node$specifiers.type) === 'ImportNamespaceSpecifier') {
30
+ aliasName = path.node.specifiers[0].local.name;
31
+ }
32
+ }
33
+ });
24
34
  return (0, _propsToObject.default)({
25
35
  j,
26
36
  root,
37
+ aliasName,
27
38
  componentName: 'Box',
28
39
  propName: 'sx',
29
40
  props
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var UI = _interopRequireWildcard(require("@material-ui/core"));
4
+
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+
7
+ var _UI$Box;
8
+
9
+ 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); }
10
+
11
+ 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; }
12
+
13
+ const Foo = () => _UI$Box || (_UI$Box = /*#__PURE__*/(0, _jsxRuntime.jsx)(UI.Box, {
14
+ px: 2
15
+ }));
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var UI = _interopRequireWildcard(require("@material-ui/core"));
4
+
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+
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
+
9
+ 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; }
10
+
11
+ const Foo = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(UI.Box, {
12
+ sx: {
13
+ px: 2
14
+ }
15
+ });
@@ -79,14 +79,14 @@ function SellHero() {
79
79
  align: "center",
80
80
  variant: "h3",
81
81
  color: "textSecondary",
82
- children: 'Build your React themes business on the official MUI store.'
82
+ children: 'Build your React themes business on the official MUI Store.'
83
83
  })), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
84
84
  className: classes.actions,
85
85
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button2.default, {
86
86
  variant: "contained",
87
87
  component: _Link.default,
88
88
  naked: true,
89
- to: "https://material-ui.zendesk.com/hc/en-us/articles/360008775380-How-do-I-apply-to-be-a-contributor-",
89
+ to: "https://support.mui.com/hc/en-us/articles/360008775380-How-do-I-apply-to-be-a-contributor-",
90
90
  target: "_blank",
91
91
  rel: "noopener",
92
92
  className: classes.apply,
@@ -88,14 +88,14 @@ function SellHero() {
88
88
  align: "center",
89
89
  variant: "h3",
90
90
  color: "textSecondary",
91
- children: 'Build your React themes business on the official MUI store.'
91
+ children: 'Build your React themes business on the official MUI Store.'
92
92
  })), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
93
93
  className: classes.actions,
94
94
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button2.default, {
95
95
  variant: "contained",
96
96
  component: _Link.default,
97
97
  naked: true,
98
- to: "https://material-ui.zendesk.com/hc/en-us/articles/360008775380-How-do-I-apply-to-be-a-contributor-",
98
+ to: "https://support.mui.com/hc/en-us/articles/360008775380-How-do-I-apply-to-be-a-contributor-",
99
99
  target: "_blank",
100
100
  rel: "noopener",
101
101
  className: classes.apply,
@@ -208,7 +208,7 @@ class AppAppBar extends _react.default.Component {
208
208
  }), essential ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
209
209
  className: classes.item,
210
210
  component: _Link.default,
211
- to: "https://material-ui.zendesk.com/hc/en-us",
211
+ to: "https://support.mui.com/hc/en-us",
212
212
  target: "_blank",
213
213
  children: 'Help'
214
214
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_NoSsr.default, {
@@ -223,7 +223,7 @@ class AppAppBar extends _react.default.Component {
223
223
  }), essential ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
224
224
  className: classes.item,
225
225
  component: _Link.default,
226
- to: "https://material-ui.zendesk.com/hc/en-us",
226
+ to: "https://support.mui.com/hc/en-us",
227
227
  target: "_blank",
228
228
  children: 'Help'
229
229
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_NoSsr.default, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.2.0",
3
+ "version": "5.4.1",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -20,18 +20,22 @@
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/mui-org/material-ui.git",
23
+ "url": "https://github.com/mui/material-ui.git",
24
24
  "directory": "packages/mui-codemod"
25
25
  },
26
26
  "license": "MIT",
27
- "homepage": "https://github.com/mui-org/material-ui/tree/master/packages/mui-codemod",
27
+ "homepage": "https://github.com/mui/material-ui/tree/master/packages/mui-codemod",
28
+ "funding": {
29
+ "type": "opencollective",
30
+ "url": "https://opencollective.com/mui"
31
+ },
28
32
  "dependencies": {
29
- "@babel/core": "^7.16.0",
30
- "@babel/runtime": "^7.16.3",
31
- "@babel/traverse": "^7.16.3",
32
- "jscodeshift": "^0.13.0",
33
+ "@babel/core": "^7.17.0",
34
+ "@babel/runtime": "^7.17.0",
35
+ "@babel/traverse": "^7.17.0",
36
+ "jscodeshift": "^0.13.1",
33
37
  "jscodeshift-add-imports": "^1.0.10",
34
- "yargs": "^17.2.1"
38
+ "yargs": "^17.3.1"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@types/jscodeshift": "0.11.3"