@atlaskit/codemod-cli 0.23.1 → 0.24.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 (30) hide show
  1. package/CHANGELOG.md +16 -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 +2 -0
  4. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +121 -0
  5. package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +33 -0
  7. package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +8 -2
  8. package/dist/cjs/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +26 -1
  9. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +2 -0
  10. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +94 -0
  11. package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  12. package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +23 -0
  13. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +7 -1
  14. package/dist/es2019/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +24 -1
  15. package/dist/esm/main.js +1 -1
  16. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +2 -0
  17. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +115 -0
  18. package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  19. package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +27 -0
  20. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +7 -1
  21. package/dist/esm/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +26 -1
  22. package/dist/types/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -0
  23. package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +2 -0
  24. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +2 -0
  25. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  26. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -0
  27. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +2 -0
  28. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +2 -0
  29. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  30. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.24.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#100948](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100948)
8
+ [`28061857f2cd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/28061857f2cd) -
9
+ Prevent migration of buttons where icon component might be wrapped.
10
+
11
+ ## 0.24.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#99062](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99062)
16
+ [`b8cd8340331d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b8cd8340331d) -
17
+ Add transform to move away for UNSAFE button APIs.
18
+
3
19
  ## 0.23.1
4
20
 
5
21
  ### 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.23.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.24.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) {
@@ -13,9 +13,11 @@ var _ifVariantAlreadyImported = require("../utils/if-variant-already-imported");
13
13
  var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
14
14
  var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
15
15
  var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
16
+ var _addCommentForCustomThemeButtons = require("../utils/add-comment-for-custom-theme-buttons");
16
17
  var transformer = function transformer(file, api) {
17
18
  var j = api.jscodeshift;
18
19
  var fileSource = j(file.source);
20
+ (0, _addCommentForCustomThemeButtons.addCommentForCustomThemeButtons)(fileSource, j);
19
21
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
20
22
  return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
21
23
  });
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _utils = require("@hypermod/utils");
8
+ var _constants = require("../utils/constants");
9
+ function _default(file, api) {
10
+ var j = api.jscodeshift;
11
+ var source = j(file.source);
12
+
13
+ // Find all new button imports
14
+ var newButtonImportDeclarations = (0, _utils.getImportDeclaration)(j, source, _constants.NEW_BUTTON_ENTRY_POINT);
15
+
16
+ // No imports for new button found, exit early
17
+ if (!newButtonImportDeclarations.length) {
18
+ return source.toSource();
19
+ }
20
+
21
+ // Get all the specifyier names
22
+ // eg ['Button', 'IconButton', 'LinkButton', 'LinkIconButton']
23
+ var newButtonSpecifiers = [];
24
+ newButtonImportDeclarations.forEach(function (newButtonImport) {
25
+ if (!newButtonImport.value.specifiers) {
26
+ return;
27
+ }
28
+ newButtonImport.value.specifiers.map(function (specifier) {
29
+ if (specifier.local && specifier.local.name) {
30
+ newButtonSpecifiers.push(specifier.local.name);
31
+ }
32
+ });
33
+ });
34
+
35
+ // Find all new button JSX elements with an UNSAFE size prop
36
+ var newButtonJXSElements = source.find(j.JSXElement)
37
+ // is a new button?
38
+ .filter(function (path) {
39
+ return path.value.openingElement.name.type === 'JSXIdentifier' && newButtonSpecifiers.includes(path.value.openingElement.name.name);
40
+ })
41
+ // has an usafe size prop?
42
+ .filter(function (path) {
43
+ return Object.keys(_constants.UNSAFE_SIZE_PROPS_MAP).some(function (unsafeSizeProp) {
44
+ return (0, _utils.hasJSXAttributes)(j, path, unsafeSizeProp);
45
+ });
46
+ });
47
+ newButtonJXSElements.forEach(function (newButtonJXSElement) {
48
+ var _loop = function _loop(unsafeSizeProp) {
49
+ var _newButtonJXSElement$;
50
+ var iconProp = _constants.UNSAFE_SIZE_PROPS_MAP[unsafeSizeProp];
51
+
52
+ // Get all icon attributes
53
+ // eg. ['iconBefore', 'iconAfter', 'icon']
54
+ var iconAttributes = (_newButtonJXSElement$ = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$ === void 0 ? void 0 : _newButtonJXSElement$.filter(function (attribute) {
55
+ return attribute.type === 'JSXAttribute' && attribute.name.name === iconProp;
56
+ });
57
+ if (!iconAttributes) {
58
+ return {
59
+ v: void 0
60
+ };
61
+ }
62
+
63
+ // Check if render prop or bounded API
64
+ iconAttributes.forEach(function (iconAttribute) {
65
+ var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
66
+ var unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(function (attribute) {
67
+ return attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp;
68
+ });
69
+ if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
70
+ return;
71
+ }
72
+ var safeSizeAttribute = j.jsxAttribute.from({
73
+ name: j.jsxIdentifier('size'),
74
+ value: unsafeSizeAttribute.value
75
+ });
76
+ switch (iconAttribute.value.expression.type) {
77
+ // We have a render prop, move the UNSAFE prop to the render prop
78
+ case 'ArrowFunctionExpression':
79
+ // Prefer existing size on icon over UNSAFE size on button
80
+ if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(function (attribute) {
81
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
82
+ }))) {
83
+ var _iconAttribute$value$2;
84
+ (_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 || _iconAttribute$value$2.push(safeSizeAttribute);
85
+ }
86
+ break;
87
+
88
+ // We have a bounded API, move to render prop
89
+ case 'Identifier':
90
+ var iconName = iconAttribute.value.expression.name;
91
+
92
+ // Create new arrow function (renderProp)
93
+ iconAttribute.value = j.jsxExpressionContainer(j.arrowFunctionExpression.from({
94
+ params: [j.identifier('iconProps')],
95
+ body: j.jsxElement.from({
96
+ openingElement: j.jsxOpeningElement.from({
97
+ name: j.jsxIdentifier(iconName),
98
+ selfClosing: true,
99
+ attributes: [j.jsxSpreadAttribute.from({
100
+ argument: j.identifier('iconProps')
101
+ }), safeSizeAttribute]
102
+ })
103
+ })
104
+ }));
105
+ break;
106
+ }
107
+
108
+ // Remove the UNSAFE icon attribute
109
+ j(newButtonJXSElement.value.openingElement).find(j.JSXAttribute).filter(function (attribute) {
110
+ return attribute.value.name.name === unsafeSizeProp;
111
+ }).remove();
112
+ });
113
+ },
114
+ _ret;
115
+ for (var unsafeSizeProp in _constants.UNSAFE_SIZE_PROPS_MAP) {
116
+ _ret = _loop(unsafeSizeProp);
117
+ if (_ret) return _ret.v;
118
+ }
119
+ });
120
+ return source.toSource(_constants.PRINT_SETTINGS);
121
+ }
@@ -10,6 +10,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
11
  var _nextSplitImports = _interopRequireDefault(require("./codemods/next-split-imports"));
12
12
  var _nextMigrateToNewButtonVariants = _interopRequireDefault(require("./codemods/next-migrate-to-new-button-variants"));
13
+ var _nextRemoveUnsafeSize = _interopRequireDefault(require("./codemods/next-remove-unsafe-size"));
13
14
  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
15
  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
16
  function transformer(_x, _x2) {
@@ -21,7 +22,7 @@ function _transformer() {
21
22
  return _regenerator.default.wrap(function _callee$(_context) {
22
23
  while (1) switch (_context.prev = _context.next) {
23
24
  case 0:
24
- transformers = [_nextSplitImports.default, _nextMigrateToNewButtonVariants.default];
25
+ transformers = [_nextSplitImports.default, _nextMigrateToNewButtonVariants.default, _nextRemoveUnsafeSize.default];
25
26
  src = file.source;
26
27
  transformers.forEach(function (transformer) {
27
28
  if (typeof src === 'undefined') {
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addCommentForCustomThemeButtons = void 0;
7
+ var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var _constants = require("./constants");
9
+ var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
10
+ var _fileSource$find$filt;
11
+ var customThemeButtonImportName;
12
+ (_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(function (path) {
13
+ return path.node.source.value === _constants.entryPointsMapping.CustomThemeButton;
14
+ })) === null || _fileSource$find$filt === void 0 || _fileSource$find$filt.forEach(function (path) {
15
+ var _path$node$specifiers;
16
+ (_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 || _path$node$specifiers.forEach(function (specifier) {
17
+ if (specifier.type === 'ImportDefaultSpecifier') {
18
+ var _specifier$local;
19
+ customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
20
+ }
21
+ });
22
+ });
23
+ if (!customThemeButtonImportName) {
24
+ return;
25
+ }
26
+ var customThemeButtonElement = fileSource.find(j.JSXElement).filter(function (path) {
27
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName;
28
+ });
29
+ if (!customThemeButtonElement.length) {
30
+ return;
31
+ }
32
+ (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'line');
33
+ };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.buttonPropsNoLongerSupportedComment = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
6
+ exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = 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
  };
@@ -21,8 +21,14 @@ var entryPointsMapping = exports.entryPointsMapping = {
21
21
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
22
22
  };
23
23
  var BUTTON_TYPES = exports.BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
24
+ var UNSAFE_SIZE_PROPS_MAP = exports.UNSAFE_SIZE_PROPS_MAP = {
25
+ UNSAFE_size: 'icon',
26
+ UNSAFE_iconAfter_size: 'iconAfter',
27
+ UNSAFE_iconBefore_size: 'iconBefore'
28
+ };
24
29
  var unsupportedProps = exports.unsupportedProps = ['component', 'css', 'style'];
25
30
  var linkButtonMissingHrefComment = exports.linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
26
31
  var buttonPropsNoLongerSupportedComment = exports.buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
27
32
  var migrateFitContainerButtonToDefaultButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
28
- var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
33
+ var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
34
+ var customThemeButtonComment = exports.customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
@@ -6,7 +6,32 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.ifHasUnsupportedProps = void 0;
7
7
  var _constants = require("./constants");
8
8
  var ifHasUnsupportedProps = exports.ifHasUnsupportedProps = function ifHasUnsupportedProps(attributes) {
9
- return Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
9
+ var hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
10
10
  return node.type === 'JSXAttribute' && _constants.unsupportedProps.includes(String(node.name.name));
11
11
  })));
12
+ var hasUnmigratableIcon = function hasUnmigratableIcon() {
13
+ var oldIconProps = ['iconBefore', 'iconAfter'];
14
+ var hasUnmigratableIcon = false;
15
+ if (!(attributes !== null && attributes !== void 0 && attributes.some(function (attribute) {
16
+ return attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name);
17
+ }))) {
18
+ return hasUnmigratableIcon;
19
+ }
20
+ oldIconProps.forEach(function (oldIconProp) {
21
+ var _iconAttribute$value;
22
+ var iconAttribute = attributes.find(function (attribute) {
23
+ return attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp;
24
+ });
25
+ if (!iconAttribute) {
26
+ return;
27
+ }
28
+
29
+ // check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
30
+ if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
31
+ hasUnmigratableIcon = true;
32
+ }
33
+ });
34
+ return hasUnmigratableIcon;
35
+ };
36
+ return hasUnsupportedProps || hasUnmigratableIcon();
12
37
  };
@@ -7,9 +7,11 @@ import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-impor
7
7
  import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
8
8
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
9
9
  import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
10
+ import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
10
11
  const transformer = (file, api) => {
11
12
  const j = api.jscodeshift;
12
13
  const fileSource = j(file.source);
14
+ addCommentForCustomThemeButtons(fileSource, j);
13
15
  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);
14
16
  if (!buttonImports.length) {
15
17
  return fileSource.toSource();
@@ -0,0 +1,94 @@
1
+ import { getImportDeclaration, hasJSXAttributes } from '@hypermod/utils';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_ENTRY_POINT, UNSAFE_SIZE_PROPS_MAP } from '../utils/constants';
3
+ export default function (file, api) {
4
+ const j = api.jscodeshift;
5
+ const source = j(file.source);
6
+
7
+ // Find all new button imports
8
+ const newButtonImportDeclarations = getImportDeclaration(j, source, NEW_BUTTON_ENTRY_POINT);
9
+
10
+ // No imports for new button found, exit early
11
+ if (!newButtonImportDeclarations.length) {
12
+ return source.toSource();
13
+ }
14
+
15
+ // Get all the specifyier names
16
+ // eg ['Button', 'IconButton', 'LinkButton', 'LinkIconButton']
17
+ const newButtonSpecifiers = [];
18
+ newButtonImportDeclarations.forEach(newButtonImport => {
19
+ if (!newButtonImport.value.specifiers) {
20
+ return;
21
+ }
22
+ newButtonImport.value.specifiers.map(specifier => {
23
+ if (specifier.local && specifier.local.name) {
24
+ newButtonSpecifiers.push(specifier.local.name);
25
+ }
26
+ });
27
+ });
28
+
29
+ // Find all new button JSX elements with an UNSAFE size prop
30
+ const newButtonJXSElements = source.find(j.JSXElement)
31
+ // is a new button?
32
+ .filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && newButtonSpecifiers.includes(path.value.openingElement.name.name))
33
+ // has an usafe size prop?
34
+ .filter(path => Object.keys(UNSAFE_SIZE_PROPS_MAP).some(unsafeSizeProp => hasJSXAttributes(j, path, unsafeSizeProp)));
35
+ newButtonJXSElements.forEach(newButtonJXSElement => {
36
+ for (const unsafeSizeProp in UNSAFE_SIZE_PROPS_MAP) {
37
+ var _newButtonJXSElement$;
38
+ const iconProp = UNSAFE_SIZE_PROPS_MAP[unsafeSizeProp];
39
+
40
+ // Get all icon attributes
41
+ // eg. ['iconBefore', 'iconAfter', 'icon']
42
+ const iconAttributes = (_newButtonJXSElement$ = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$ === void 0 ? void 0 : _newButtonJXSElement$.filter(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === iconProp);
43
+ if (!iconAttributes) {
44
+ return;
45
+ }
46
+
47
+ // Check if render prop or bounded API
48
+ iconAttributes.forEach(iconAttribute => {
49
+ var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
50
+ const unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp);
51
+ if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
52
+ return;
53
+ }
54
+ const safeSizeAttribute = j.jsxAttribute.from({
55
+ name: j.jsxIdentifier('size'),
56
+ value: unsafeSizeAttribute.value
57
+ });
58
+ switch (iconAttribute.value.expression.type) {
59
+ // We have a render prop, move the UNSAFE prop to the render prop
60
+ case 'ArrowFunctionExpression':
61
+ // Prefer existing size on icon over UNSAFE size on button
62
+ if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'size'))) {
63
+ var _iconAttribute$value$2;
64
+ (_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 ? void 0 : _iconAttribute$value$2.push(safeSizeAttribute);
65
+ }
66
+ break;
67
+
68
+ // We have a bounded API, move to render prop
69
+ case 'Identifier':
70
+ const iconName = iconAttribute.value.expression.name;
71
+
72
+ // Create new arrow function (renderProp)
73
+ iconAttribute.value = j.jsxExpressionContainer(j.arrowFunctionExpression.from({
74
+ params: [j.identifier('iconProps')],
75
+ body: j.jsxElement.from({
76
+ openingElement: j.jsxOpeningElement.from({
77
+ name: j.jsxIdentifier(iconName),
78
+ selfClosing: true,
79
+ attributes: [j.jsxSpreadAttribute.from({
80
+ argument: j.identifier('iconProps')
81
+ }), safeSizeAttribute]
82
+ })
83
+ })
84
+ }));
85
+ break;
86
+ }
87
+
88
+ // Remove the UNSAFE icon attribute
89
+ j(newButtonJXSElement.value.openingElement).find(j.JSXAttribute).filter(attribute => attribute.value.name.name === unsafeSizeProp).remove();
90
+ });
91
+ }
92
+ });
93
+ return source.toSource(PRINT_SETTINGS);
94
+ }
@@ -1,7 +1,8 @@
1
1
  import splitImportsTransformer from './codemods/next-split-imports';
2
2
  import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
3
+ import removeUnsafeSizeTransformer from './codemods/next-remove-unsafe-size';
3
4
  export default async function transformer(file, api) {
4
- const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
5
+ const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer];
5
6
  let src = file.source;
6
7
  transformers.forEach(transformer => {
7
8
  if (typeof src === 'undefined') {
@@ -0,0 +1,23 @@
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { entryPointsMapping, customThemeButtonComment } from './constants';
3
+ export const addCommentForCustomThemeButtons = (fileSource, j) => {
4
+ var _fileSource$find$filt;
5
+ let customThemeButtonImportName;
6
+ (_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.CustomThemeButton)) === null || _fileSource$find$filt === void 0 ? void 0 : _fileSource$find$filt.forEach(path => {
7
+ var _path$node$specifiers;
8
+ (_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 ? void 0 : _path$node$specifiers.forEach(specifier => {
9
+ if (specifier.type === 'ImportDefaultSpecifier') {
10
+ var _specifier$local;
11
+ customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
12
+ }
13
+ });
14
+ });
15
+ if (!customThemeButtonImportName) {
16
+ return;
17
+ }
18
+ const customThemeButtonElement = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName);
19
+ if (!customThemeButtonElement.length) {
20
+ return;
21
+ }
22
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
23
+ };
@@ -15,8 +15,14 @@ export const entryPointsMapping = {
15
15
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
16
16
  };
17
17
  export const BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
18
+ export const UNSAFE_SIZE_PROPS_MAP = {
19
+ UNSAFE_size: 'icon',
20
+ UNSAFE_iconAfter_size: 'iconAfter',
21
+ UNSAFE_iconBefore_size: 'iconBefore'
22
+ };
18
23
  export const unsupportedProps = ['component', 'css', 'style'];
19
24
  export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.`;
20
25
  export const buttonPropsNoLongerSupportedComment = `Buttons with "component", "css" or "style" prop can't be automatically migrated with codemods. Please migrate it manually.`;
21
26
  export const migrateFitContainerButtonToDefaultButtonComment = `Migrated to a default button with text which is from the icon label.`;
22
- export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
27
+ export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
28
+ export const customThemeButtonComment = `CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.`;
@@ -1,2 +1,25 @@
1
1
  import { unsupportedProps } from './constants';
2
- export const ifHasUnsupportedProps = attributes => Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(node => node.type === 'JSXAttribute' && unsupportedProps.includes(String(node.name.name)))));
2
+ export const ifHasUnsupportedProps = attributes => {
3
+ let hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(node => node.type === 'JSXAttribute' && unsupportedProps.includes(String(node.name.name)))));
4
+ const hasUnmigratableIcon = () => {
5
+ const oldIconProps = ['iconBefore', 'iconAfter'];
6
+ let hasUnmigratableIcon = false;
7
+ if (!(attributes !== null && attributes !== void 0 && attributes.some(attribute => attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name)))) {
8
+ return hasUnmigratableIcon;
9
+ }
10
+ oldIconProps.forEach(oldIconProp => {
11
+ var _iconAttribute$value;
12
+ const iconAttribute = attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp);
13
+ if (!iconAttribute) {
14
+ return;
15
+ }
16
+
17
+ // check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
18
+ if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
19
+ hasUnmigratableIcon = true;
20
+ }
21
+ });
22
+ return hasUnmigratableIcon;
23
+ };
24
+ return hasUnsupportedProps || hasUnmigratableIcon();
25
+ };
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.23.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.24.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) {
@@ -7,9 +7,11 @@ import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-impor
7
7
  import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
8
8
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
9
9
  import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
10
+ import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
10
11
  var transformer = function transformer(file, api) {
11
12
  var j = api.jscodeshift;
12
13
  var fileSource = j(file.source);
14
+ addCommentForCustomThemeButtons(fileSource, j);
13
15
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
14
16
  return path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
15
17
  });
@@ -0,0 +1,115 @@
1
+ import { getImportDeclaration, hasJSXAttributes } from '@hypermod/utils';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_ENTRY_POINT, UNSAFE_SIZE_PROPS_MAP } from '../utils/constants';
3
+ export default function (file, api) {
4
+ var j = api.jscodeshift;
5
+ var source = j(file.source);
6
+
7
+ // Find all new button imports
8
+ var newButtonImportDeclarations = getImportDeclaration(j, source, NEW_BUTTON_ENTRY_POINT);
9
+
10
+ // No imports for new button found, exit early
11
+ if (!newButtonImportDeclarations.length) {
12
+ return source.toSource();
13
+ }
14
+
15
+ // Get all the specifyier names
16
+ // eg ['Button', 'IconButton', 'LinkButton', 'LinkIconButton']
17
+ var newButtonSpecifiers = [];
18
+ newButtonImportDeclarations.forEach(function (newButtonImport) {
19
+ if (!newButtonImport.value.specifiers) {
20
+ return;
21
+ }
22
+ newButtonImport.value.specifiers.map(function (specifier) {
23
+ if (specifier.local && specifier.local.name) {
24
+ newButtonSpecifiers.push(specifier.local.name);
25
+ }
26
+ });
27
+ });
28
+
29
+ // Find all new button JSX elements with an UNSAFE size prop
30
+ var newButtonJXSElements = source.find(j.JSXElement)
31
+ // is a new button?
32
+ .filter(function (path) {
33
+ return path.value.openingElement.name.type === 'JSXIdentifier' && newButtonSpecifiers.includes(path.value.openingElement.name.name);
34
+ })
35
+ // has an usafe size prop?
36
+ .filter(function (path) {
37
+ return Object.keys(UNSAFE_SIZE_PROPS_MAP).some(function (unsafeSizeProp) {
38
+ return hasJSXAttributes(j, path, unsafeSizeProp);
39
+ });
40
+ });
41
+ newButtonJXSElements.forEach(function (newButtonJXSElement) {
42
+ var _loop = function _loop(unsafeSizeProp) {
43
+ var _newButtonJXSElement$;
44
+ var iconProp = UNSAFE_SIZE_PROPS_MAP[unsafeSizeProp];
45
+
46
+ // Get all icon attributes
47
+ // eg. ['iconBefore', 'iconAfter', 'icon']
48
+ var iconAttributes = (_newButtonJXSElement$ = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$ === void 0 ? void 0 : _newButtonJXSElement$.filter(function (attribute) {
49
+ return attribute.type === 'JSXAttribute' && attribute.name.name === iconProp;
50
+ });
51
+ if (!iconAttributes) {
52
+ return {
53
+ v: void 0
54
+ };
55
+ }
56
+
57
+ // Check if render prop or bounded API
58
+ iconAttributes.forEach(function (iconAttribute) {
59
+ var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
60
+ var unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(function (attribute) {
61
+ return attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp;
62
+ });
63
+ if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
64
+ return;
65
+ }
66
+ var safeSizeAttribute = j.jsxAttribute.from({
67
+ name: j.jsxIdentifier('size'),
68
+ value: unsafeSizeAttribute.value
69
+ });
70
+ switch (iconAttribute.value.expression.type) {
71
+ // We have a render prop, move the UNSAFE prop to the render prop
72
+ case 'ArrowFunctionExpression':
73
+ // Prefer existing size on icon over UNSAFE size on button
74
+ if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(function (attribute) {
75
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
76
+ }))) {
77
+ var _iconAttribute$value$2;
78
+ (_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 || _iconAttribute$value$2.push(safeSizeAttribute);
79
+ }
80
+ break;
81
+
82
+ // We have a bounded API, move to render prop
83
+ case 'Identifier':
84
+ var iconName = iconAttribute.value.expression.name;
85
+
86
+ // Create new arrow function (renderProp)
87
+ iconAttribute.value = j.jsxExpressionContainer(j.arrowFunctionExpression.from({
88
+ params: [j.identifier('iconProps')],
89
+ body: j.jsxElement.from({
90
+ openingElement: j.jsxOpeningElement.from({
91
+ name: j.jsxIdentifier(iconName),
92
+ selfClosing: true,
93
+ attributes: [j.jsxSpreadAttribute.from({
94
+ argument: j.identifier('iconProps')
95
+ }), safeSizeAttribute]
96
+ })
97
+ })
98
+ }));
99
+ break;
100
+ }
101
+
102
+ // Remove the UNSAFE icon attribute
103
+ j(newButtonJXSElement.value.openingElement).find(j.JSXAttribute).filter(function (attribute) {
104
+ return attribute.value.name.name === unsafeSizeProp;
105
+ }).remove();
106
+ });
107
+ },
108
+ _ret;
109
+ for (var unsafeSizeProp in UNSAFE_SIZE_PROPS_MAP) {
110
+ _ret = _loop(unsafeSizeProp);
111
+ if (_ret) return _ret.v;
112
+ }
113
+ });
114
+ return source.toSource(PRINT_SETTINGS);
115
+ }
@@ -5,6 +5,7 @@ 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
+ import removeUnsafeSizeTransformer from './codemods/next-remove-unsafe-size';
8
9
  export default function transformer(_x, _x2) {
9
10
  return _transformer.apply(this, arguments);
10
11
  }
@@ -14,7 +15,7 @@ function _transformer() {
14
15
  return _regeneratorRuntime.wrap(function _callee$(_context) {
15
16
  while (1) switch (_context.prev = _context.next) {
16
17
  case 0:
17
- transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
18
+ transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer];
18
19
  src = file.source;
19
20
  transformers.forEach(function (transformer) {
20
21
  if (typeof src === 'undefined') {
@@ -0,0 +1,27 @@
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { entryPointsMapping, customThemeButtonComment } from './constants';
3
+ export var addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
4
+ var _fileSource$find$filt;
5
+ var customThemeButtonImportName;
6
+ (_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(function (path) {
7
+ return path.node.source.value === entryPointsMapping.CustomThemeButton;
8
+ })) === null || _fileSource$find$filt === void 0 || _fileSource$find$filt.forEach(function (path) {
9
+ var _path$node$specifiers;
10
+ (_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 || _path$node$specifiers.forEach(function (specifier) {
11
+ if (specifier.type === 'ImportDefaultSpecifier') {
12
+ var _specifier$local;
13
+ customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
14
+ }
15
+ });
16
+ });
17
+ if (!customThemeButtonImportName) {
18
+ return;
19
+ }
20
+ var customThemeButtonElement = fileSource.find(j.JSXElement).filter(function (path) {
21
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName;
22
+ });
23
+ if (!customThemeButtonElement.length) {
24
+ return;
25
+ }
26
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
27
+ };
@@ -15,8 +15,14 @@ export var entryPointsMapping = {
15
15
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
16
16
  };
17
17
  export var BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
18
+ export var UNSAFE_SIZE_PROPS_MAP = {
19
+ UNSAFE_size: 'icon',
20
+ UNSAFE_iconAfter_size: 'iconAfter',
21
+ UNSAFE_iconBefore_size: 'iconBefore'
22
+ };
18
23
  export var unsupportedProps = ['component', 'css', 'style'];
19
24
  export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
20
25
  export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
21
26
  export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
22
- export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
27
+ export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
28
+ export var customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
@@ -1,6 +1,31 @@
1
1
  import { unsupportedProps } from './constants';
2
2
  export var ifHasUnsupportedProps = function ifHasUnsupportedProps(attributes) {
3
- return Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
3
+ var hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
4
4
  return node.type === 'JSXAttribute' && unsupportedProps.includes(String(node.name.name));
5
5
  })));
6
+ var hasUnmigratableIcon = function hasUnmigratableIcon() {
7
+ var oldIconProps = ['iconBefore', 'iconAfter'];
8
+ var hasUnmigratableIcon = false;
9
+ if (!(attributes !== null && attributes !== void 0 && attributes.some(function (attribute) {
10
+ return attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name);
11
+ }))) {
12
+ return hasUnmigratableIcon;
13
+ }
14
+ oldIconProps.forEach(function (oldIconProp) {
15
+ var _iconAttribute$value;
16
+ var iconAttribute = attributes.find(function (attribute) {
17
+ return attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp;
18
+ });
19
+ if (!iconAttribute) {
20
+ return;
21
+ }
22
+
23
+ // check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
24
+ if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
25
+ hasUnmigratableIcon = true;
26
+ }
27
+ });
28
+ return hasUnmigratableIcon;
29
+ };
30
+ return hasUnsupportedProps || hasUnmigratableIcon();
6
31
  };
@@ -0,0 +1,2 @@
1
+ import { type API, type FileInfo } from 'jscodeshift';
2
+ export default function (file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, Collection } from 'jscodeshift';
2
+ export declare const addCommentForCustomThemeButtons: (fileSource: Collection<any>, j: API['jscodeshift']) => void;
@@ -9,8 +9,10 @@ export declare const entryPointsMapping: {
9
9
  [key: string]: string;
10
10
  };
11
11
  export declare const BUTTON_TYPES: string[];
12
+ export declare const UNSAFE_SIZE_PROPS_MAP: Record<string, string>;
12
13
  export declare const unsupportedProps: string[];
13
14
  export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
14
15
  export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
15
16
  export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
16
17
  export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
18
+ export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
@@ -1,4 +1,4 @@
1
- import { API, JSXElement, JSXAttribute, JSXSpreadAttribute } from 'jscodeshift';
1
+ import { type API, type JSXElement, type JSXAttribute, type JSXSpreadAttribute } from 'jscodeshift';
2
2
  import { NEW_BUTTON_VARIANTS } from '../utils/constants';
3
3
  export declare const getIconAttributes: (attributes: (JSXAttribute | JSXSpreadAttribute)[]) => JSXAttribute[] | null;
4
4
  export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | null;
@@ -0,0 +1,2 @@
1
+ import { type API, type FileInfo } from 'jscodeshift';
2
+ export default function (file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, Collection } from 'jscodeshift';
2
+ export declare const addCommentForCustomThemeButtons: (fileSource: Collection<any>, j: API['jscodeshift']) => void;
@@ -9,8 +9,10 @@ export declare const entryPointsMapping: {
9
9
  [key: string]: string;
10
10
  };
11
11
  export declare const BUTTON_TYPES: string[];
12
+ export declare const UNSAFE_SIZE_PROPS_MAP: Record<string, string>;
12
13
  export declare const unsupportedProps: string[];
13
14
  export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
14
15
  export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
15
16
  export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
16
17
  export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
18
+ export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
@@ -1,4 +1,4 @@
1
- import { API, JSXElement, JSXAttribute, JSXSpreadAttribute } from 'jscodeshift';
1
+ import { type API, type JSXElement, type JSXAttribute, type JSXSpreadAttribute } from 'jscodeshift';
2
2
  import { NEW_BUTTON_VARIANTS } from '../utils/constants';
3
3
  export declare const getIconAttributes: (attributes: (JSXAttribute | JSXSpreadAttribute)[]) => JSXAttribute[] | null;
4
4
  export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.23.1",
3
+ "version": "0.24.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,7 +40,7 @@
40
40
  "bin": "./bin/codemod-cli.js",
41
41
  "dependencies": {
42
42
  "@atlaskit/codemod-utils": "^4.2.0",
43
- "@atlaskit/tokens": "^1.45.0",
43
+ "@atlaskit/tokens": "^1.48.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codeshift/utils": "^0.2.4",
46
46
  "@hypermod/utils": "^0.4.2",