@atlaskit/codemod-cli 0.17.0 → 0.17.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/main.js +1 -1
  3. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +23 -21
  4. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +8 -1
  5. package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +3 -3
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +3 -2
  7. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +60 -0
  8. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +22 -22
  9. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +6 -2
  10. package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -2
  11. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +2 -1
  12. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +52 -0
  13. package/dist/esm/main.js +1 -1
  14. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +24 -22
  15. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +8 -2
  16. package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +3 -3
  17. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +2 -1
  18. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +54 -0
  19. package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +2 -2
  20. package/dist/types/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -2
  21. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  22. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +4 -0
  23. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +2 -2
  24. package/dist/types-ts4.5/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -2
  25. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  26. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +4 -0
  27. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#43812](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43812) [`15c0e36ba0f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/15c0e36ba0f) - Update button codemods to adapt new API changes for IconButton.
8
+
3
9
  ## 0.17.0
4
10
 
5
11
  ### Minor Changes
package/dist/cjs/main.js CHANGED
@@ -305,7 +305,7 @@ function _main() {
305
305
  case 4:
306
306
  _yield$parseArgs = _context5.sent;
307
307
  packages = _yield$parseArgs.packages;
308
- _process$env$_PACKAGE = "0.17.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.17.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _codemodUtils = require("@atlaskit/codemod-utils");
7
8
  var _constants = require("../utils/constants");
8
- var transformer = function transformer(file, api) {
9
+ var _generateNewButtonElement = require("../utils/generate-new-button-element");
10
+ var transformer = function transformer(file, api, options) {
9
11
  var j = api.jscodeshift;
10
12
  var fileSource = j(file.source);
11
13
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -40,20 +42,6 @@ var transformer = function transformer(file, api) {
40
42
  return path.node.imported.name === variant;
41
43
  }).length > 0;
42
44
  };
43
- var generateNewElement = function generateNewElement(variant, element) {
44
- var attributes = element.openingElement.attributes;
45
- if (variant === _constants.NEW_BUTTON_VARIANTS.icon.as) {
46
- var attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
47
- return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
48
- });
49
- if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
50
- attr[0].name.name = 'icon';
51
- }
52
- }
53
- // self closing if it's an icon button or icon link button
54
- var isSelfClosing = variant === _constants.NEW_BUTTON_VARIANTS.icon.as || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon.as;
55
- return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
56
- };
57
45
  var hasLinkIconButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.linkIcon.import);
58
46
  var hasLinkButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.link.import);
59
47
  var hasIconButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.icon.import);
@@ -73,18 +61,27 @@ var transformer = function transformer(file, api) {
73
61
  var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
74
62
  var isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
75
63
  var isLinkButton = hasHref && !isLinkIconButton;
64
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
65
+ // and don't migrate these buttons.
76
66
  var isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
67
+ var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && hasIcon;
68
+
69
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
70
+ // and don't migrate these buttons.
71
+ if (isDefaultButtonWithAnIcon) {
72
+ (0, _generateNewButtonElement.moveSizeAndLabelAttributes)(element.value, j);
73
+ }
77
74
  if (isLinkIconButton) {
78
75
  hasLinkIconButton = true;
79
- j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
76
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
80
77
  }
81
78
  if (isIconButton) {
82
79
  hasIconButton = true;
83
- j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.icon.as, element.value));
80
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.icon.as, element.value, j));
84
81
  }
85
82
  if (isLinkButton) {
86
83
  hasLinkButton = true;
87
- j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.link.as, element.value));
84
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link.as, element.value, j));
88
85
  }
89
86
  });
90
87
  var specifiers = [];
@@ -100,18 +97,23 @@ var transformer = function transformer(file, api) {
100
97
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
101
98
  return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button;
102
99
  });
103
- var leftButtons = fileSource.find(j.JSXElement).filter(function (path) {
100
+ var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
104
101
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
105
102
  }).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
106
103
  return path.node.arguments.map(function (argument) {
107
104
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
108
105
  }).includes(specifierIdentifier);
109
106
  }).length > 0;
110
- if (specifiers.length || leftButtons) {
111
- if (leftButtons) {
107
+ if (specifiers.length || remainingDefaultButtons) {
108
+ if (remainingDefaultButtons) {
112
109
  specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
113
110
  }
114
111
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(_constants.NEW_BUTTON_ENTRY_POINT)));
112
+ if (_constants.NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
113
+ (0, _codemodUtils.addCommentBefore)(j, fileSource.find(j.ImportDeclaration).filter(function (path) {
114
+ return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
115
+ }), _constants.eslintDisableComment, 'line', '');
116
+ }
115
117
  }
116
118
  return fileSource.toSource(_constants.PRINT_SETTINGS);
117
119
  };
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
9
  var _constants = require("../utils/constants");
8
10
  var transformer = function transformer(file, api) {
9
11
  var j = api.jscodeshift;
@@ -18,7 +20,12 @@ var transformer = function transformer(file, api) {
18
20
  return fileSource.toSource(_constants.PRINT_SETTINGS);
19
21
  }
20
22
  buttonImports.forEach(function (node) {
21
- var specifiers = node.node.specifiers;
23
+ var _node$node = node.node,
24
+ specifiers = _node$node.specifiers,
25
+ source = _node$node.source;
26
+ if ([].concat((0, _toConsumableArray2.default)(Object.values(_constants.entryPointsMapping)), [_constants.NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types']).includes(source.value)) {
27
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
28
+ }
22
29
  var defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(function (specifier) {
23
30
  return specifier.type === 'ImportDefaultSpecifier';
24
31
  });
@@ -12,11 +12,11 @@ var _nextSplitImports = _interopRequireDefault(require("./codemods/next-split-im
12
12
  var _nextMigrateToNewButtonVariants = _interopRequireDefault(require("./codemods/next-migrate-to-new-button-variants"));
13
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
- function transformer(_x, _x2) {
15
+ function transformer(_x, _x2, _x3) {
16
16
  return _transformer.apply(this, arguments);
17
17
  }
18
18
  function _transformer() {
19
- _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
19
+ _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api, options) {
20
20
  var transformers, src;
21
21
  return _regenerator.default.wrap(function _callee$(_context) {
22
22
  while (1) switch (_context.prev = _context.next) {
@@ -29,7 +29,7 @@ function _transformer() {
29
29
  }
30
30
  var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
31
31
  source: src
32
- }), api);
32
+ }), api, options);
33
33
  if (nextSrc) {
34
34
  src = nextSrc;
35
35
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.entryPointsMapping = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
6
+ exports.eslintDisableComment = exports.entryPointsMapping = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
7
7
  var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
8
8
  quote: 'single'
9
9
  };
@@ -32,4 +32,5 @@ var entryPointsMapping = exports.entryPointsMapping = {
32
32
  ButtonGroup: '@atlaskit/button/button-group',
33
33
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
34
34
  };
35
- var BUTTON_TYPES = exports.BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
35
+ var BUTTON_TYPES = exports.BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
36
+ var eslintDisableComment = exports.eslintDisableComment = 'eslint-disable-next-line @atlaskit/design-system/no-banned-imports';
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.moveSizeAndLabelAttributes = exports.generateNewElement = void 0;
7
+ var _constants = require("../utils/constants");
8
+ var getIconAttribute = function getIconAttribute(attributes) {
9
+ var iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
10
+ return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
11
+ });
12
+ if (attributes && iconAttr !== null && iconAttr !== void 0 && iconAttr.length && iconAttr[0].type === 'JSXAttribute') {
13
+ return iconAttr[0];
14
+ }
15
+ return null;
16
+ };
17
+ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(element, j) {
18
+ var _iconAttr$value;
19
+ var attributes = element.openingElement.attributes;
20
+ var iconAttr = attributes && getIconAttribute(attributes);
21
+ if (iconAttr && ((_iconAttr$value = iconAttr.value) === null || _iconAttr$value === void 0 ? void 0 : _iconAttr$value.type) === 'JSXExpressionContainer' && iconAttr.value.expression.type === 'JSXElement') {
22
+ var iconElement = iconAttr.value.expression;
23
+ var iconJSXElementAttributes = iconElement.openingElement.attributes;
24
+ if (Array.isArray(iconJSXElementAttributes)) {
25
+ // move label and size attributes from icon to the root Button prop
26
+ var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
27
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
28
+ });
29
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute') {
30
+ attributes === null || attributes === void 0 || attributes.push(labelAttribute);
31
+ }
32
+ var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
33
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
34
+ });
35
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
36
+ sizeAttribute.name.name = "UNSAFE_size";
37
+ attributes === null || attributes === void 0 || attributes.push(sizeAttribute);
38
+ }
39
+ }
40
+
41
+ // replace JSXElement with identifier {<MoreIcon />} => {MoreIcon}
42
+ if (iconElement.openingElement.name.type === 'JSXIdentifier') {
43
+ iconAttr.value.expression = j.identifier(iconElement.openingElement.name.name);
44
+ }
45
+ }
46
+ };
47
+ var generateNewElement = exports.generateNewElement = function generateNewElement(variant, element, j) {
48
+ var attributes = element.openingElement.attributes;
49
+ var iconAttr = attributes && getIconAttribute(attributes);
50
+ if (variant === _constants.NEW_BUTTON_VARIANTS.icon.as && iconAttr && attributes) {
51
+ moveSizeAndLabelAttributes(element, j);
52
+
53
+ // rename iconBefore/iconAfter to icon
54
+ iconAttr.name.name = 'icon';
55
+ }
56
+
57
+ // self closing if it's an icon button or icon link button
58
+ var isSelfClosing = variant === _constants.NEW_BUTTON_VARIANTS.icon.as || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon.as;
59
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
60
+ };
@@ -1,5 +1,7 @@
1
- import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
- const transformer = (file, api) => {
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, eslintDisableComment } from '../utils/constants';
3
+ import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
+ const transformer = (file, api, options) => {
3
5
  const j = api.jscodeshift;
4
6
  const fileSource = j(file.source);
5
7
  const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
@@ -18,20 +20,6 @@ const transformer = (file, api) => {
18
20
  return fileSource.toSource(PRINT_SETTINGS);
19
21
  }
20
22
  const checkIfVariantAlreadyImported = variant => fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT).find(j.ImportSpecifier).filter(path => path.node.imported.name === variant).length > 0;
21
- const generateNewElement = (variant, element) => {
22
- const {
23
- attributes
24
- } = element.openingElement;
25
- if (variant === NEW_BUTTON_VARIANTS.icon.as) {
26
- const attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter'));
27
- if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
28
- attr[0].name.name = 'icon';
29
- }
30
- }
31
- // self closing if it's an icon button or icon link button
32
- const isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
33
- return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
34
- };
35
23
  let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import);
36
24
  let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import);
37
25
  let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import);
@@ -49,18 +37,27 @@ const transformer = (file, api) => {
49
37
  const hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
50
38
  const isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
51
39
  const isLinkButton = hasHref && !isLinkIconButton;
40
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
41
+ // and don't migrate these buttons.
52
42
  const isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
43
+ const isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && hasIcon;
44
+
45
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
46
+ // and don't migrate these buttons.
47
+ if (isDefaultButtonWithAnIcon) {
48
+ moveSizeAndLabelAttributes(element.value, j);
49
+ }
53
50
  if (isLinkIconButton) {
54
51
  hasLinkIconButton = true;
55
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
52
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
56
53
  }
57
54
  if (isIconButton) {
58
55
  hasIconButton = true;
59
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value));
56
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value, j));
60
57
  }
61
58
  if (isLinkButton) {
62
59
  hasLinkButton = true;
63
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value));
60
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value, j));
64
61
  }
65
62
  });
66
63
  const specifiers = [];
@@ -74,12 +71,15 @@ const transformer = (file, api) => {
74
71
  specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.linkIcon.import), j.identifier(NEW_BUTTON_VARIANTS.linkIcon.as)));
75
72
  }
76
73
  const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
77
- const leftButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).length > 0 || fileSource.find(j.CallExpression).filter(path => path.node.arguments.map(argument => argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name)).includes(specifierIdentifier)).length > 0;
78
- if (specifiers.length || leftButtons) {
79
- if (leftButtons) {
74
+ const remainingDefaultButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).length > 0 || fileSource.find(j.CallExpression).filter(path => path.node.arguments.map(argument => argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name)).includes(specifierIdentifier)).length > 0;
75
+ if (specifiers.length || remainingDefaultButtons) {
76
+ if (remainingDefaultButtons) {
80
77
  specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
81
78
  }
82
79
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
80
+ if (NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
81
+ addCommentBefore(j, fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT), eslintDisableComment, 'line', '');
82
+ }
83
83
  }
84
84
  return fileSource.toSource(PRINT_SETTINGS);
85
85
  };
@@ -1,4 +1,4 @@
1
- import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES } from '../utils/constants';
1
+ import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
2
  const transformer = (file, api) => {
3
3
  const j = api.jscodeshift;
4
4
  const fileSource = j(file.source);
@@ -11,8 +11,12 @@ const transformer = (file, api) => {
11
11
  }
12
12
  buttonImports.forEach(node => {
13
13
  const {
14
- specifiers
14
+ specifiers,
15
+ source
15
16
  } = node.node;
17
+ if ([...Object.values(entryPointsMapping), NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types'].includes(source.value)) {
18
+ return fileSource.toSource(PRINT_SETTINGS);
19
+ }
16
20
  const defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier');
17
21
  if (defaultSpecifier && defaultSpecifier.local) {
18
22
  const defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
@@ -1,6 +1,6 @@
1
1
  import splitImportsTransformer from './codemods/next-split-imports';
2
2
  import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
3
- export default async function transformer(file, api) {
3
+ export default async function transformer(file, api, options) {
4
4
  const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
5
5
  let src = file.source;
6
6
  transformers.forEach(transformer => {
@@ -10,7 +10,7 @@ export default async function transformer(file, api) {
10
10
  const nextSrc = transformer({
11
11
  ...file,
12
12
  source: src
13
- }, api);
13
+ }, api, options);
14
14
  if (nextSrc) {
15
15
  src = nextSrc;
16
16
  }
@@ -26,4 +26,5 @@ export const entryPointsMapping = {
26
26
  ButtonGroup: '@atlaskit/button/button-group',
27
27
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
28
  };
29
- export const BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
29
+ export const BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
30
+ export const eslintDisableComment = 'eslint-disable-next-line @atlaskit/design-system/no-banned-imports';
@@ -0,0 +1,52 @@
1
+ import { NEW_BUTTON_VARIANTS } from '../utils/constants';
2
+ const getIconAttribute = attributes => {
3
+ const iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter'));
4
+ if (attributes && iconAttr !== null && iconAttr !== void 0 && iconAttr.length && iconAttr[0].type === 'JSXAttribute') {
5
+ return iconAttr[0];
6
+ }
7
+ return null;
8
+ };
9
+ export const moveSizeAndLabelAttributes = (element, j) => {
10
+ var _iconAttr$value;
11
+ const {
12
+ attributes
13
+ } = element.openingElement;
14
+ const iconAttr = attributes && getIconAttribute(attributes);
15
+ if (iconAttr && ((_iconAttr$value = iconAttr.value) === null || _iconAttr$value === void 0 ? void 0 : _iconAttr$value.type) === 'JSXExpressionContainer' && iconAttr.value.expression.type === 'JSXElement') {
16
+ const iconElement = iconAttr.value.expression;
17
+ const iconJSXElementAttributes = iconElement.openingElement.attributes;
18
+ if (Array.isArray(iconJSXElementAttributes)) {
19
+ // move label and size attributes from icon to the root Button prop
20
+ const labelAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
21
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute') {
22
+ attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
23
+ }
24
+ const sizeAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'size');
25
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
26
+ sizeAttribute.name.name = `UNSAFE_size`;
27
+ attributes === null || attributes === void 0 ? void 0 : attributes.push(sizeAttribute);
28
+ }
29
+ }
30
+
31
+ // replace JSXElement with identifier {<MoreIcon />} => {MoreIcon}
32
+ if (iconElement.openingElement.name.type === 'JSXIdentifier') {
33
+ iconAttr.value.expression = j.identifier(iconElement.openingElement.name.name);
34
+ }
35
+ }
36
+ };
37
+ export const generateNewElement = (variant, element, j) => {
38
+ const {
39
+ attributes
40
+ } = element.openingElement;
41
+ const iconAttr = attributes && getIconAttribute(attributes);
42
+ if (variant === NEW_BUTTON_VARIANTS.icon.as && iconAttr && attributes) {
43
+ moveSizeAndLabelAttributes(element, j);
44
+
45
+ // rename iconBefore/iconAfter to icon
46
+ iconAttr.name.name = 'icon';
47
+ }
48
+
49
+ // self closing if it's an icon button or icon link button
50
+ const isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
51
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
52
+ };
package/dist/esm/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.17.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.17.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -1,5 +1,7 @@
1
- import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
- var transformer = function transformer(file, api) {
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, eslintDisableComment } from '../utils/constants';
3
+ import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
+ var transformer = function transformer(file, api, options) {
3
5
  var j = api.jscodeshift;
4
6
  var fileSource = j(file.source);
5
7
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -34,20 +36,6 @@ var transformer = function transformer(file, api) {
34
36
  return path.node.imported.name === variant;
35
37
  }).length > 0;
36
38
  };
37
- var generateNewElement = function generateNewElement(variant, element) {
38
- var attributes = element.openingElement.attributes;
39
- if (variant === NEW_BUTTON_VARIANTS.icon.as) {
40
- var attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
41
- return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
42
- });
43
- if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
44
- attr[0].name.name = 'icon';
45
- }
46
- }
47
- // self closing if it's an icon button or icon link button
48
- var isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
49
- return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
50
- };
51
39
  var hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import);
52
40
  var hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import);
53
41
  var hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import);
@@ -67,18 +55,27 @@ var transformer = function transformer(file, api) {
67
55
  var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
68
56
  var isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
69
57
  var isLinkButton = hasHref && !isLinkIconButton;
58
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
59
+ // and don't migrate these buttons.
70
60
  var isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
61
+ var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && hasIcon;
62
+
63
+ // TODO: add checks for unsupported icon props except label and size, e.g. primaryColor, testId, or spread props
64
+ // and don't migrate these buttons.
65
+ if (isDefaultButtonWithAnIcon) {
66
+ moveSizeAndLabelAttributes(element.value, j);
67
+ }
71
68
  if (isLinkIconButton) {
72
69
  hasLinkIconButton = true;
73
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
70
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
74
71
  }
75
72
  if (isIconButton) {
76
73
  hasIconButton = true;
77
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value));
74
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value, j));
78
75
  }
79
76
  if (isLinkButton) {
80
77
  hasLinkButton = true;
81
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value));
78
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value, j));
82
79
  }
83
80
  });
84
81
  var specifiers = [];
@@ -94,18 +91,23 @@ var transformer = function transformer(file, api) {
94
91
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
95
92
  return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button;
96
93
  });
97
- var leftButtons = fileSource.find(j.JSXElement).filter(function (path) {
94
+ var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
98
95
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
99
96
  }).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
100
97
  return path.node.arguments.map(function (argument) {
101
98
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
102
99
  }).includes(specifierIdentifier);
103
100
  }).length > 0;
104
- if (specifiers.length || leftButtons) {
105
- if (leftButtons) {
101
+ if (specifiers.length || remainingDefaultButtons) {
102
+ if (remainingDefaultButtons) {
106
103
  specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
107
104
  }
108
105
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
106
+ if (NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
107
+ addCommentBefore(j, fileSource.find(j.ImportDeclaration).filter(function (path) {
108
+ return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
109
+ }), eslintDisableComment, 'line', '');
110
+ }
109
111
  }
110
112
  return fileSource.toSource(PRINT_SETTINGS);
111
113
  };
@@ -1,4 +1,5 @@
1
- import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES } from '../utils/constants';
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
3
  var transformer = function transformer(file, api) {
3
4
  var j = api.jscodeshift;
4
5
  var fileSource = j(file.source);
@@ -12,7 +13,12 @@ var transformer = function transformer(file, api) {
12
13
  return fileSource.toSource(PRINT_SETTINGS);
13
14
  }
14
15
  buttonImports.forEach(function (node) {
15
- var specifiers = node.node.specifiers;
16
+ var _node$node = node.node,
17
+ specifiers = _node$node.specifiers,
18
+ source = _node$node.source;
19
+ if ([].concat(_toConsumableArray(Object.values(entryPointsMapping)), [NEW_BUTTON_ENTRY_POINT, '@atlaskit/button/types']).includes(source.value)) {
20
+ return fileSource.toSource(PRINT_SETTINGS);
21
+ }
16
22
  var defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(function (specifier) {
17
23
  return specifier.type === 'ImportDefaultSpecifier';
18
24
  });
@@ -5,11 +5,11 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  import splitImportsTransformer from './codemods/next-split-imports';
7
7
  import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
8
- export default function transformer(_x, _x2) {
8
+ export default function transformer(_x, _x2, _x3) {
9
9
  return _transformer.apply(this, arguments);
10
10
  }
11
11
  function _transformer() {
12
- _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api) {
12
+ _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api, options) {
13
13
  var transformers, src;
14
14
  return _regeneratorRuntime.wrap(function _callee$(_context) {
15
15
  while (1) switch (_context.prev = _context.next) {
@@ -22,7 +22,7 @@ function _transformer() {
22
22
  }
23
23
  var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
24
24
  source: src
25
- }), api);
25
+ }), api, options);
26
26
  if (nextSrc) {
27
27
  src = nextSrc;
28
28
  }
@@ -26,4 +26,5 @@ export var entryPointsMapping = {
26
26
  ButtonGroup: '@atlaskit/button/button-group',
27
27
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
28
  };
29
- export var BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
29
+ export var BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
30
+ export var eslintDisableComment = 'eslint-disable-next-line @atlaskit/design-system/no-banned-imports';
@@ -0,0 +1,54 @@
1
+ import { NEW_BUTTON_VARIANTS } from '../utils/constants';
2
+ var getIconAttribute = function getIconAttribute(attributes) {
3
+ var iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
4
+ return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
5
+ });
6
+ if (attributes && iconAttr !== null && iconAttr !== void 0 && iconAttr.length && iconAttr[0].type === 'JSXAttribute') {
7
+ return iconAttr[0];
8
+ }
9
+ return null;
10
+ };
11
+ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(element, j) {
12
+ var _iconAttr$value;
13
+ var attributes = element.openingElement.attributes;
14
+ var iconAttr = attributes && getIconAttribute(attributes);
15
+ if (iconAttr && ((_iconAttr$value = iconAttr.value) === null || _iconAttr$value === void 0 ? void 0 : _iconAttr$value.type) === 'JSXExpressionContainer' && iconAttr.value.expression.type === 'JSXElement') {
16
+ var iconElement = iconAttr.value.expression;
17
+ var iconJSXElementAttributes = iconElement.openingElement.attributes;
18
+ if (Array.isArray(iconJSXElementAttributes)) {
19
+ // move label and size attributes from icon to the root Button prop
20
+ var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
21
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
22
+ });
23
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute') {
24
+ attributes === null || attributes === void 0 || attributes.push(labelAttribute);
25
+ }
26
+ var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
27
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
28
+ });
29
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
30
+ sizeAttribute.name.name = "UNSAFE_size";
31
+ attributes === null || attributes === void 0 || attributes.push(sizeAttribute);
32
+ }
33
+ }
34
+
35
+ // replace JSXElement with identifier {<MoreIcon />} => {MoreIcon}
36
+ if (iconElement.openingElement.name.type === 'JSXIdentifier') {
37
+ iconAttr.value.expression = j.identifier(iconElement.openingElement.name.name);
38
+ }
39
+ }
40
+ };
41
+ export var generateNewElement = function generateNewElement(variant, element, j) {
42
+ var attributes = element.openingElement.attributes;
43
+ var iconAttr = attributes && getIconAttribute(attributes);
44
+ if (variant === NEW_BUTTON_VARIANTS.icon.as && iconAttr && attributes) {
45
+ moveSizeAndLabelAttributes(element, j);
46
+
47
+ // rename iconBefore/iconAfter to icon
48
+ iconAttr.name.name = 'icon';
49
+ }
50
+
51
+ // self closing if it's an icon button or icon link button
52
+ var isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
53
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
54
+ };
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo } from 'jscodeshift';
2
- declare const transformer: (file: FileInfo, api: API) => string;
1
+ import type { API, FileInfo, Options } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API, options: Options) => string;
3
3
  export default transformer;
@@ -1,2 +1,2 @@
1
- import type { API, FileInfo } from 'jscodeshift';
2
- export default function transformer(file: FileInfo, api: API): Promise<string>;
1
+ import type { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): Promise<string>;
@@ -12,3 +12,4 @@ export declare const entryPointsMapping: {
12
12
  [key: string]: string;
13
13
  };
14
14
  export declare const BUTTON_TYPES: string[];
15
+ export declare const eslintDisableComment = "eslint-disable-next-line @atlaskit/design-system/no-banned-imports";
@@ -0,0 +1,4 @@
1
+ import type { API, JSXElement } from 'jscodeshift';
2
+ import { NEW_BUTTON_VARIANTS } from '../utils/constants';
3
+ export declare const moveSizeAndLabelAttributes: (element: JSXElement, j: API['jscodeshift']) => void;
4
+ export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS]['as'], element: JSXElement, j: API['jscodeshift']) => JSXElement;
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo } from 'jscodeshift';
2
- declare const transformer: (file: FileInfo, api: API) => string;
1
+ import type { API, FileInfo, Options } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API, options: Options) => string;
3
3
  export default transformer;
@@ -1,2 +1,2 @@
1
- import type { API, FileInfo } from 'jscodeshift';
2
- export default function transformer(file: FileInfo, api: API): Promise<string>;
1
+ import type { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): Promise<string>;
@@ -12,3 +12,4 @@ export declare const entryPointsMapping: {
12
12
  [key: string]: string;
13
13
  };
14
14
  export declare const BUTTON_TYPES: string[];
15
+ export declare const eslintDisableComment = "eslint-disable-next-line @atlaskit/design-system/no-banned-imports";
@@ -0,0 +1,4 @@
1
+ import type { API, JSXElement } from 'jscodeshift';
2
+ import { NEW_BUTTON_VARIANTS } from '../utils/constants';
3
+ export declare const moveSizeAndLabelAttributes: (element: JSXElement, j: API['jscodeshift']) => void;
4
+ export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS]['as'], element: JSXElement, j: API['jscodeshift']) => JSXElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,6 +32,7 @@
32
32
  "codemod-cli": "./bin/codemod-cli.js"
33
33
  },
34
34
  "dependencies": {
35
+ "@atlaskit/codemod-utils": "^4.2.0",
35
36
  "@atlaskit/tokens": "^1.29.0",
36
37
  "@babel/runtime": "^7.0.0",
37
38
  "@codeshift/utils": "^0.2.4",