@atlaskit/codemod-cli 0.20.1 → 0.21.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#87918](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87918) [`1de8dc826f8d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1de8dc826f8d) - Fixed the duplicated label issue and the missing JSX pragma comment.
8
+
9
+ ## 0.21.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#87074](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87074) [`92be609ad553`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/92be609ad553) - Adds migration support for LoadingButtons
14
+
3
15
  ## 0.20.1
4
16
 
5
17
  ### Patch 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.20.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.21.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) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var _utils = require("@hypermod/utils");
8
9
  var _constants = require("../utils/constants");
9
10
  var _generateNewButtonElement = require("../utils/generate-new-button-element");
10
11
  var _hasUnsupportedProps = require("../utils/has-unsupported-props");
@@ -16,7 +17,7 @@ var transformer = function transformer(file, api) {
16
17
  var j = api.jscodeshift;
17
18
  var fileSource = j(file.source);
18
19
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
19
- return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
20
+ return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
20
21
  });
21
22
  if (!buttonImports.length) {
22
23
  return fileSource.toSource();
@@ -37,6 +38,7 @@ var transformer = function transformer(file, api) {
37
38
  var buttonsWithoutUnsupportedProps = allButtons.filter(function (path) {
38
39
  return !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
39
40
  });
41
+ var loadingButtonImportName = (0, _utils.getDefaultImportSpecifierName)(j, fileSource, _constants.entryPointsMapping.LoadingButton);
40
42
  buttonsWithoutUnsupportedProps.forEach(function (element) {
41
43
  var _element$value$childr;
42
44
  var attributes = element.value.openingElement.attributes;
@@ -54,6 +56,7 @@ var transformer = function transformer(file, api) {
54
56
  var isLinkButton = hasHref && !isLinkIconButton;
55
57
  var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
56
58
  var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
59
+ var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
57
60
  if (isDefaultButtonWithAnIcon) {
58
61
  (0, _generateNewButtonElement.moveSizeAndLabelAttributes)(element.value, j);
59
62
  }
@@ -75,6 +78,9 @@ var transformer = function transformer(file, api) {
75
78
  hasLinkButton = true;
76
79
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
77
80
  }
81
+ if (isLoadingButton) {
82
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.default, element.value, j));
83
+ }
78
84
  var linkAppearanceAttribute = attributes.find(function (node) {
79
85
  var _node$value, _node$name, _node$value2, _node$value3;
80
86
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 || (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 || (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 || (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -92,7 +98,7 @@ var transformer = function transformer(file, api) {
92
98
  }
93
99
  });
94
100
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
95
- return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button;
101
+ return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton;
96
102
  });
97
103
  var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
98
104
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
@@ -101,6 +107,11 @@ var transformer = function transformer(file, api) {
101
107
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
102
108
  }).includes(specifierIdentifier);
103
109
  }).length > 0;
110
+
111
+ // Loading buttons map back to default imports
112
+ if (specifierIdentifier === loadingButtonImportName) {
113
+ specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
114
+ }
104
115
  if (remainingDefaultButtons) {
105
116
  specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
106
117
  }
@@ -130,7 +141,12 @@ var transformer = function transformer(file, api) {
130
141
  }
131
142
  }
132
143
  if (specifiers.length) {
133
- oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(_constants.NEW_BUTTON_ENTRY_POINT)));
144
+ var newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(_constants.NEW_BUTTON_ENTRY_POINT));
145
+ oldButtonImport.forEach(function (path) {
146
+ var _path$node;
147
+ newButtonImport.comments = path !== null && path !== void 0 && (_path$node = path.node) !== null && _path$node !== void 0 && _path$node.comments ? path.node.comments : undefined;
148
+ });
149
+ oldButtonImport.replaceWith(newButtonImport);
134
150
  }
135
151
 
136
152
  // remove empty import declarations
@@ -43,11 +43,16 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
43
43
  }
44
44
 
45
45
  // move label and size attributes from icon to the root Button prop
46
- var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
46
+ var buttonAlreadyHasLabelProp = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attribute) {
47
47
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
48
48
  });
49
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
50
- attributes === null || attributes === void 0 || attributes.push(labelAttribute);
49
+ if (!buttonAlreadyHasLabelProp) {
50
+ var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
51
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
52
+ });
53
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
54
+ attributes === null || attributes === void 0 || attributes.push(labelAttribute);
55
+ }
51
56
  }
52
57
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
53
58
  var _attribute$value, _attribute$value2;
@@ -1,4 +1,5 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { getDefaultImportSpecifierName } from '@hypermod/utils';
2
3
  import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
4
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
5
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
@@ -9,7 +10,7 @@ import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-ent
9
10
  const transformer = (file, api) => {
10
11
  const j = api.jscodeshift;
11
12
  const fileSource = j(file.source);
12
- const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
13
+ const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
13
14
  if (!buttonImports.length) {
14
15
  return fileSource.toSource();
15
16
  }
@@ -23,6 +24,7 @@ const transformer = (file, api) => {
23
24
  let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
24
25
  const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
25
26
  const buttonsWithoutUnsupportedProps = allButtons.filter(path => !ifHasUnsupportedProps(path.value.openingElement.attributes));
27
+ const loadingButtonImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
26
28
  buttonsWithoutUnsupportedProps.forEach(element => {
27
29
  var _element$value$childr;
28
30
  const {
@@ -40,6 +42,7 @@ const transformer = (file, api) => {
40
42
  const isLinkButton = hasHref && !isLinkIconButton;
41
43
  let isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
42
44
  const isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
45
+ const isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
43
46
  if (isDefaultButtonWithAnIcon) {
44
47
  moveSizeAndLabelAttributes(element.value, j);
45
48
  }
@@ -61,6 +64,9 @@ const transformer = (file, api) => {
61
64
  hasLinkButton = true;
62
65
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
63
66
  }
67
+ if (isLoadingButton) {
68
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
69
+ }
64
70
  const linkAppearanceAttribute = attributes.find(node => {
65
71
  var _node$value, _node$name, _node$value2, _node$value3;
66
72
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 ? void 0 : (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 ? void 0 : (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 ? void 0 : (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -77,8 +83,13 @@ const transformer = (file, api) => {
77
83
  specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
78
84
  }
79
85
  });
80
- const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
86
+ const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton);
81
87
  const remainingDefaultButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !ifHasUnsupportedProps(path.value.openingElement.attributes)).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;
88
+
89
+ // Loading buttons map back to default imports
90
+ if (specifierIdentifier === loadingButtonImportName) {
91
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
92
+ }
82
93
  if (remainingDefaultButtons) {
83
94
  specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
84
95
  }
@@ -102,7 +113,12 @@ const transformer = (file, api) => {
102
113
  }
103
114
  }
104
115
  if (specifiers.length) {
105
- oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
116
+ const newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
117
+ oldButtonImport.forEach(path => {
118
+ var _path$node;
119
+ newButtonImport.comments = path !== null && path !== void 0 && (_path$node = path.node) !== null && _path$node !== void 0 && _path$node.comments ? path.node.comments : undefined;
120
+ });
121
+ oldButtonImport.replaceWith(newButtonImport);
106
122
  }
107
123
 
108
124
  // remove empty import declarations
@@ -34,9 +34,12 @@ export const moveSizeAndLabelAttributes = (element, j, iconRenamed = false) => {
34
34
  }
35
35
 
36
36
  // move label and size attributes from icon to the root Button prop
37
- const labelAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
38
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
39
- attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
37
+ const buttonAlreadyHasLabelProp = attributes === null || attributes === void 0 ? void 0 : attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
38
+ if (!buttonAlreadyHasLabelProp) {
39
+ const labelAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
40
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
41
+ attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
42
+ }
40
43
  }
41
44
  const sizeAttribute = iconJSXElementAttributes.find(attribute => {
42
45
  var _attribute$value, _attribute$value2;
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.20.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.21.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,4 +1,5 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { getDefaultImportSpecifierName } from '@hypermod/utils';
2
3
  import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
4
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
5
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
@@ -10,7 +11,7 @@ var transformer = function transformer(file, api) {
10
11
  var j = api.jscodeshift;
11
12
  var fileSource = j(file.source);
12
13
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
13
- return path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
14
+ return path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
14
15
  });
15
16
  if (!buttonImports.length) {
16
17
  return fileSource.toSource();
@@ -31,6 +32,7 @@ var transformer = function transformer(file, api) {
31
32
  var buttonsWithoutUnsupportedProps = allButtons.filter(function (path) {
32
33
  return !ifHasUnsupportedProps(path.value.openingElement.attributes);
33
34
  });
35
+ var loadingButtonImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
34
36
  buttonsWithoutUnsupportedProps.forEach(function (element) {
35
37
  var _element$value$childr;
36
38
  var attributes = element.value.openingElement.attributes;
@@ -48,6 +50,7 @@ var transformer = function transformer(file, api) {
48
50
  var isLinkButton = hasHref && !isLinkIconButton;
49
51
  var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
50
52
  var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
53
+ var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
51
54
  if (isDefaultButtonWithAnIcon) {
52
55
  moveSizeAndLabelAttributes(element.value, j);
53
56
  }
@@ -69,6 +72,9 @@ var transformer = function transformer(file, api) {
69
72
  hasLinkButton = true;
70
73
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
71
74
  }
75
+ if (isLoadingButton) {
76
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
77
+ }
72
78
  var linkAppearanceAttribute = attributes.find(function (node) {
73
79
  var _node$value, _node$name, _node$value2, _node$value3;
74
80
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 || (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 || (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 || (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -86,7 +92,7 @@ var transformer = function transformer(file, api) {
86
92
  }
87
93
  });
88
94
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
89
- return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button;
95
+ return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton;
90
96
  });
91
97
  var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
92
98
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !ifHasUnsupportedProps(path.value.openingElement.attributes);
@@ -95,6 +101,11 @@ var transformer = function transformer(file, api) {
95
101
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
96
102
  }).includes(specifierIdentifier);
97
103
  }).length > 0;
104
+
105
+ // Loading buttons map back to default imports
106
+ if (specifierIdentifier === loadingButtonImportName) {
107
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
108
+ }
98
109
  if (remainingDefaultButtons) {
99
110
  specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
100
111
  }
@@ -124,7 +135,12 @@ var transformer = function transformer(file, api) {
124
135
  }
125
136
  }
126
137
  if (specifiers.length) {
127
- oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
138
+ var newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
139
+ oldButtonImport.forEach(function (path) {
140
+ var _path$node;
141
+ newButtonImport.comments = path !== null && path !== void 0 && (_path$node = path.node) !== null && _path$node !== void 0 && _path$node.comments ? path.node.comments : undefined;
142
+ });
143
+ oldButtonImport.replaceWith(newButtonImport);
128
144
  }
129
145
 
130
146
  // remove empty import declarations
@@ -37,11 +37,16 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
37
37
  }
38
38
 
39
39
  // move label and size attributes from icon to the root Button prop
40
- var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
40
+ var buttonAlreadyHasLabelProp = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attribute) {
41
41
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
42
42
  });
43
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
44
- attributes === null || attributes === void 0 || attributes.push(labelAttribute);
43
+ if (!buttonAlreadyHasLabelProp) {
44
+ var labelAttribute = iconJSXElementAttributes.find(function (attribute) {
45
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
46
+ });
47
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
48
+ attributes === null || attributes === void 0 || attributes.push(labelAttribute);
49
+ }
45
50
  }
46
51
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
47
52
  var _attribute$value, _attribute$value2;
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo } from 'jscodeshift';
1
+ import { API, FileInfo } from 'jscodeshift';
2
2
  declare const transformer: (file: FileInfo, api: API) => string;
3
3
  export default transformer;
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo } from 'jscodeshift';
1
+ import { API, FileInfo } from 'jscodeshift';
2
2
  declare const transformer: (file: FileInfo, api: API) => string;
3
3
  export default transformer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.20.1",
3
+ "version": "0.21.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/"
@@ -40,9 +40,10 @@
40
40
  "bin": "./bin/codemod-cli.js",
41
41
  "dependencies": {
42
42
  "@atlaskit/codemod-utils": "^4.2.0",
43
- "@atlaskit/tokens": "^1.42.0",
43
+ "@atlaskit/tokens": "^1.43.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codeshift/utils": "^0.2.4",
46
+ "@hypermod/utils": "^0.4.2",
46
47
  "@types/jscodeshift": "^0.11.0",
47
48
  "chalk": "^4.1.2",
48
49
  "enquirer": "^2.3.4",