@atlaskit/codemod-cli 0.17.4 → 0.17.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -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 +22 -25
  4. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +7 -7
  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 +7 -21
  7. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -3
  8. package/dist/cjs/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +39 -0
  9. package/dist/cjs/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  10. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +22 -23
  11. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +5 -5
  12. package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -2
  13. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +6 -20
  14. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -3
  15. package/dist/es2019/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +27 -0
  16. package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  17. package/dist/esm/main.js +1 -1
  18. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +23 -26
  19. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +7 -7
  20. package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +3 -3
  21. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +6 -20
  22. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -3
  23. package/dist/esm/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +33 -0
  24. package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  25. package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +2 -2
  26. package/dist/types/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -2
  27. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +2 -7
  28. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  29. package/dist/types/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts +2 -0
  30. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +2 -2
  31. package/dist/types-ts4.5/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -2
  32. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +2 -7
  33. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  34. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts +2 -0
  35. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.17.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#61943](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61943) [`dfdb42df4b4c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dfdb42df4b4c) - Now building the `@atlaskit/tokens` package when during `"prestart"` as tokens is required to be built for some of the patterns to run.
8
+
9
+ ## 0.17.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#59501](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/59501) [`2c30839b5156`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2c30839b5156) - Button migration codemods- updated import path to the new entry point "@atlaskit/button/new"
14
+
3
15
  ## 0.17.4
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.17.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.17.6", _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) {
@@ -11,7 +11,8 @@ var _hasUnsupportedProps = require("../utils/has-unsupported-props");
11
11
  var _ifVariantAlreadyImported = require("../utils/if-variant-already-imported");
12
12
  var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
13
13
  var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
14
- var transformer = function transformer(file, api, options) {
14
+ var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
15
+ var transformer = function transformer(file, api) {
15
16
  var j = api.jscodeshift;
16
17
  var fileSource = j(file.source);
17
18
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -27,9 +28,9 @@ var transformer = function transformer(file, api, options) {
27
28
  return fileSource.toSource();
28
29
  }
29
30
  var specifierIdentifier = defaultButtonImport.get(0).node.local.name;
30
- var hasLinkIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.linkIcon.import, fileSource, j);
31
- var hasLinkButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.link.import, fileSource, j);
32
- var hasIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.icon.import, fileSource, j);
31
+ var hasLinkIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
32
+ var hasLinkButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.link, fileSource, j);
33
+ var hasIconButton = (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.icon, fileSource, j);
33
34
  var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
34
35
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
35
36
  });
@@ -64,15 +65,15 @@ var transformer = function transformer(file, api, options) {
64
65
  }
65
66
  if (isLinkIconButton) {
66
67
  hasLinkIconButton = true;
67
- j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
68
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.linkIcon, element.value, j));
68
69
  }
69
70
  if (isIconButton) {
70
71
  hasIconButton = true;
71
- j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.icon.as, element.value, j));
72
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.icon, element.value, j));
72
73
  }
73
74
  if (isLinkButton) {
74
75
  hasLinkButton = true;
75
- j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link.as, element.value, j));
76
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
76
77
  }
77
78
  if (!hasHref && attributes.find(function (node) {
78
79
  var _node$value, _node$name, _node$value2, _node$value3;
@@ -82,10 +83,12 @@ var transformer = function transformer(file, api, options) {
82
83
  (0, _codemodUtils.addCommentBefore)(j, [element], _constants.linkButtonMissingHrefComment);
83
84
  }
84
85
  });
86
+
87
+ // modify import declarations
85
88
  var specifiers = [];
86
89
  [hasLinkButton ? 'link' : null, hasIconButton ? 'icon' : null, hasLinkIconButton ? 'linkIcon' : null].forEach(function (variant) {
87
90
  if (variant) {
88
- specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS[variant].import), j.identifier(_constants.NEW_BUTTON_VARIANTS[variant].as)));
91
+ specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS[variant])));
89
92
  }
90
93
  });
91
94
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -99,8 +102,11 @@ var transformer = function transformer(file, api, options) {
99
102
  }).includes(specifierIdentifier);
100
103
  }).length > 0;
101
104
  if (remainingDefaultButtons) {
102
- specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
105
+ specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
103
106
  }
107
+
108
+ // update import path for types imports
109
+ specifiers = (0, _importTypesFromNewEntryPoint.importTypesFromNewEntryPoint)(buttonImports, specifiers, j, fileSource);
104
110
  var buttonsWithUnsupportedProps = allButtons.filter(function (path) {
105
111
  return (0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
106
112
  });
@@ -118,28 +124,19 @@ var transformer = function transformer(file, api, options) {
118
124
 
119
125
  // rename all buttons with unsupported props to LegacyButton if default new button is imported
120
126
  if (specifiers.find(function (specifier) {
121
- return specifier.imported.name === _constants.NEW_BUTTON_VARIANTS.default.import;
127
+ return specifier.type === 'ImportDefaultSpecifier';
122
128
  })) {
123
129
  (0, _renameDefaultButtonToLegacyButton.renameDefaultButtonToLegacyButtonImport)(oldButtonImport, buttonsWithUnsupportedProps, j);
124
130
  }
125
131
  }
126
- if (specifiers.length || remainingDefaultButtons) {
127
- // split the type imports into a separate import
128
- var typeSpecifier = buttonImports.find(j.ImportSpecifier).filter(function (path) {
129
- return path.node.imported.name === _constants.ButtonPropsTypeName;
130
- });
131
- if (typeSpecifier.length > 0) {
132
- oldButtonImport.insertBefore(j.importDeclaration([j.importSpecifier(j.identifier(_constants.ButtonPropsTypeName), j.identifier(typeSpecifier.get(0).node.local.name))], j.stringLiteral(_constants.entryPointsMapping.Button), 'type'));
133
- }
132
+ if (specifiers.length) {
134
133
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(_constants.NEW_BUTTON_ENTRY_POINT)));
135
-
136
- // add eslint-disable-next-line @atlaskit/design-system/no-banned-imports comment if unsafe import is allowed in custom options
137
- if (_constants.NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
138
- (0, _codemodUtils.addCommentBefore)(j, fileSource.find(j.ImportDeclaration).filter(function (path) {
139
- return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
140
- }), _constants.eslintDisableComment, 'line', '');
141
- }
142
134
  }
135
+
136
+ // remove empty import declarations
137
+ fileSource.find(j.ImportDeclaration).filter(function (path) {
138
+ return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
139
+ }).remove();
143
140
  return fileSource.toSource(_constants.PRINT_SETTINGS);
144
141
  };
145
142
  var _default = exports.default = transformer;
@@ -33,19 +33,19 @@ var transformer = function transformer(file, api) {
33
33
  var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(_constants.entryPointsMapping.Button));
34
34
  j(node).insertAfter(defaultButtonImport);
35
35
  }
36
- var defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
37
- return specifier.importKind === 'type';
38
- });
39
- if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
40
- var typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
41
- j(node).insertAfter(typeImport);
42
- }
43
36
  var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
44
37
  return specifier.type === 'ImportSpecifier';
45
38
  });
39
+ var newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
40
+ return specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing');
41
+ });
46
42
  var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
47
43
  return _constants.BUTTON_TYPES.includes(specifier.imported.name);
48
44
  });
45
+ if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
46
+ var typeImport = j.importDeclaration(newTypeSpecifier, j.stringLiteral('@atlaskit/button/types'));
47
+ j(node).insertAfter(typeImport);
48
+ }
49
49
  if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
50
50
  var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
51
51
  j(node).insertAfter(_typeImport);
@@ -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, _x3) {
15
+ function transformer(_x, _x2) {
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, options) {
19
+ _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
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, options);
32
+ }), api);
33
33
  if (nextSrc) {
34
34
  src = nextSrc;
35
35
  }
@@ -3,38 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.iconPropsNoLongerSupportedComment = exports.eslintDisableComment = exports.entryPointsMapping = exports.buttonPropsNoLongerSupportedComment = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.ButtonPropsTypeName = exports.BUTTON_TYPES = void 0;
6
+ exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.iconPropsNoLongerSupportedComment = exports.entryPointsMapping = exports.buttonPropsNoLongerSupportedComment = 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
  };
10
10
  var NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_VARIANTS = {
11
- default: {
12
- import: 'UNSAFE_BUTTON',
13
- as: 'Button'
14
- },
15
- link: {
16
- import: 'UNSAFE_LINK_BUTTON',
17
- as: 'LinkButton'
18
- },
19
- icon: {
20
- import: 'UNSAFE_ICON_BUTTON',
21
- as: 'IconButton'
22
- },
23
- linkIcon: {
24
- import: 'UNSAFE_LINK_ICON_BUTTON',
25
- as: 'LinkIconButton'
26
- }
11
+ default: 'Button',
12
+ link: 'LinkButton',
13
+ icon: 'IconButton',
14
+ linkIcon: 'LinkIconButton'
27
15
  };
28
- var NEW_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
16
+ var NEW_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
29
17
  var entryPointsMapping = exports.entryPointsMapping = {
30
18
  Button: '@atlaskit/button/standard-button',
31
19
  LoadingButton: '@atlaskit/button/loading-button',
32
20
  ButtonGroup: '@atlaskit/button/button-group',
33
21
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
34
22
  };
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';
37
- var ButtonPropsTypeName = exports.ButtonPropsTypeName = 'ButtonProps';
23
+ var BUTTON_TYPES = exports.BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
38
24
  var unsupportedProps = exports.unsupportedProps = ['component', 'css', 'style'];
39
25
  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.";
40
26
  var iconPropsNoLongerSupportedComment = exports.iconPropsNoLongerSupportedComment = "\"glyph\", \"primaryColor\", \"secondaryColor\" and \"testId\" are no longer supported in button icons, please refactor the code and/or revisit the UI.";
@@ -35,7 +35,6 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
35
35
  var iconJSXElementAttributes = iconElement.openingElement.attributes;
36
36
  // add inlined comment to the icon if it has any attributes other than label and size
37
37
  if (Array.isArray(iconJSXElementAttributes)) {
38
- var _sizeAttribute$value;
39
38
  var ifIconAttributeEitherLabelOrSize = iconJSXElementAttributes === null || iconJSXElementAttributes === void 0 ? void 0 : iconJSXElementAttributes.every(function (attribute) {
40
39
  return attribute.type === 'JSXAttribute' && typeof attribute.name.name === 'string' && (attribute.name.name === 'size' || attribute.name.name === 'label');
41
40
  });
@@ -53,7 +52,7 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
53
52
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
54
53
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
55
54
  });
56
- if (sizeAttribute && sizeAttribute.type === 'JSXAttribute' && ((_sizeAttribute$value = sizeAttribute.value) === null || _sizeAttribute$value === void 0 ? void 0 : _sizeAttribute$value.type) === 'Literal' && sizeAttribute.value.value !== 'medium') {
55
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
57
56
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
58
57
  attributes === null || attributes === void 0 || attributes.push(sizeAttribute);
59
58
  }
@@ -68,7 +67,7 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
68
67
  var generateNewElement = exports.generateNewElement = function generateNewElement(variant, element, j) {
69
68
  var attributes = element.openingElement.attributes;
70
69
  var iconAttrs = attributes && getIconAttributes(attributes);
71
- var isIconOrLinkIcon = variant === _constants.NEW_BUTTON_VARIANTS.icon.as || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon.as;
70
+ var isIconOrLinkIcon = variant === _constants.NEW_BUTTON_VARIANTS.icon || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon;
72
71
  if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
73
72
  moveSizeAndLabelAttributes(element, j, true);
74
73
 
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.importTypesFromNewEntryPoint = void 0;
7
+ var _constants = require("./constants");
8
+ var importTypesFromNewEntryPoint = exports.importTypesFromNewEntryPoint = function importTypesFromNewEntryPoint(buttonImports, specifiers, j, fileSource) {
9
+ var buttonPropsTypeSpecifier = buttonImports.find(j.ImportSpecifier).filter(function (path) {
10
+ return path.node.imported.name === 'ButtonProps';
11
+ });
12
+ if (buttonPropsTypeSpecifier.length > 0) {
13
+ var typeSpecifier;
14
+ specifiers.forEach(function (specifier) {
15
+ if (specifier.type === 'ImportDefaultSpecifier') {
16
+ typeSpecifier = j.importSpecifier(j.identifier("".concat(_constants.NEW_BUTTON_VARIANTS.default, "Props")), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
17
+ } else {
18
+ typeSpecifier = j.importSpecifier(j.identifier("".concat(specifier.imported.name, "Props")), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
19
+ }
20
+ });
21
+ if (typeSpecifier) {
22
+ // @ts-ignore
23
+ typeSpecifier.importKind = 'type';
24
+ specifiers.push(typeSpecifier);
25
+ }
26
+ }
27
+ var appearanceAndSpacingTypeSpecifier = fileSource.find(j.ImportDeclaration).filter(function (path) {
28
+ return path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types';
29
+ }).find(j.ImportSpecifier).filter(function (path) {
30
+ return path.node.imported.name === 'Appearance' || path.node.imported.name === 'Spacing';
31
+ });
32
+ if (appearanceAndSpacingTypeSpecifier.length) {
33
+ appearanceAndSpacingTypeSpecifier.forEach(function (specifier) {
34
+ specifiers.push(specifier.node);
35
+ j(specifier).remove();
36
+ });
37
+ }
38
+ return specifiers;
39
+ };
@@ -23,7 +23,7 @@ var migrateFitContainerIconButton = exports.migrateFitContainerIconButton = func
23
23
  j(element).find(j.JSXAttribute).filter(function (path) {
24
24
  return path.node.name.name === 'iconBefore' || path.node.name.name === 'iconAfter';
25
25
  }).remove();
26
- var newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(_constants.NEW_BUTTON_VARIANTS.default.as), attributes), j.jsxClosingElement(j.jsxIdentifier(_constants.NEW_BUTTON_VARIANTS.default.as)), [j.jsxText(formattedLabel)]);
26
+ var newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(_constants.NEW_BUTTON_VARIANTS.default), attributes), j.jsxClosingElement(j.jsxIdentifier(_constants.NEW_BUTTON_VARIANTS.default)), [j.jsxText(formattedLabel)]);
27
27
  j(element).replaceWith(newButton);
28
28
  (0, _codemodUtils.addCommentBefore)(j, j(newButton).find(j.JSXAttribute).filter(function (path) {
29
29
  return path.node.name.name === 'shouldFitContainer';
@@ -1,11 +1,12 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
- import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, eslintDisableComment, ButtonPropsTypeName, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
3
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
4
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
5
5
  import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
6
6
  import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
7
7
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
8
- const transformer = (file, api, options) => {
8
+ import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
9
+ const transformer = (file, api) => {
9
10
  const j = api.jscodeshift;
10
11
  const fileSource = j(file.source);
11
12
  const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
@@ -17,9 +18,9 @@ const transformer = (file, api, options) => {
17
18
  return fileSource.toSource();
18
19
  }
19
20
  const specifierIdentifier = defaultButtonImport.get(0).node.local.name;
20
- let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import, fileSource, j);
21
- let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import, fileSource, j);
22
- let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import, fileSource, j);
21
+ let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
22
+ let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, fileSource, j);
23
+ let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
23
24
  const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
24
25
  const buttonsWithoutUnsupportedProps = allButtons.filter(path => !ifHasUnsupportedProps(path.value.openingElement.attributes));
25
26
  buttonsWithoutUnsupportedProps.forEach(element => {
@@ -50,15 +51,15 @@ const transformer = (file, api, options) => {
50
51
  }
51
52
  if (isLinkIconButton) {
52
53
  hasLinkIconButton = true;
53
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
54
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon, element.value, j));
54
55
  }
55
56
  if (isIconButton) {
56
57
  hasIconButton = true;
57
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value, j));
58
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
58
59
  }
59
60
  if (isLinkButton) {
60
61
  hasLinkButton = true;
61
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value, j));
62
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
62
63
  }
63
64
  if (!hasHref && attributes.find(node => {
64
65
  var _node$value, _node$name, _node$value2, _node$value3;
@@ -68,17 +69,22 @@ const transformer = (file, api, options) => {
68
69
  addCommentBefore(j, [element], linkButtonMissingHrefComment);
69
70
  }
70
71
  });
71
- const specifiers = [];
72
+
73
+ // modify import declarations
74
+ let specifiers = [];
72
75
  [hasLinkButton ? 'link' : null, hasIconButton ? 'icon' : null, hasLinkIconButton ? 'linkIcon' : null].forEach(variant => {
73
76
  if (variant) {
74
- specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant].import), j.identifier(NEW_BUTTON_VARIANTS[variant].as)));
77
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
75
78
  }
76
79
  });
77
80
  const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
78
81
  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;
79
82
  if (remainingDefaultButtons) {
80
- specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
83
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
81
84
  }
85
+
86
+ // update import path for types imports
87
+ specifiers = importTypesFromNewEntryPoint(buttonImports, specifiers, j, fileSource);
82
88
  const buttonsWithUnsupportedProps = allButtons.filter(path => ifHasUnsupportedProps(path.value.openingElement.attributes));
83
89
  if (buttonsWithUnsupportedProps.length) {
84
90
  // add comment to all buttons with unsupported props: "component", "style", "css"
@@ -91,23 +97,16 @@ const transformer = (file, api, options) => {
91
97
  });
92
98
 
93
99
  // rename all buttons with unsupported props to LegacyButton if default new button is imported
94
- if (specifiers.find(specifier => specifier.imported.name === NEW_BUTTON_VARIANTS.default.import)) {
100
+ if (specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier')) {
95
101
  renameDefaultButtonToLegacyButtonImport(oldButtonImport, buttonsWithUnsupportedProps, j);
96
102
  }
97
103
  }
98
- if (specifiers.length || remainingDefaultButtons) {
99
- // split the type imports into a separate import
100
- const typeSpecifier = buttonImports.find(j.ImportSpecifier).filter(path => path.node.imported.name === ButtonPropsTypeName);
101
- if (typeSpecifier.length > 0) {
102
- oldButtonImport.insertBefore(j.importDeclaration([j.importSpecifier(j.identifier(ButtonPropsTypeName), j.identifier(typeSpecifier.get(0).node.local.name))], j.stringLiteral(entryPointsMapping.Button), 'type'));
103
- }
104
+ if (specifiers.length) {
104
105
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
105
-
106
- // add eslint-disable-next-line @atlaskit/design-system/no-banned-imports comment if unsafe import is allowed in custom options
107
- if (NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
108
- addCommentBefore(j, fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT), eslintDisableComment, 'line', '');
109
- }
110
106
  }
107
+
108
+ // remove empty import declarations
109
+ fileSource.find(j.ImportDeclaration).filter(path => (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0).remove();
111
110
  return fileSource.toSource(PRINT_SETTINGS);
112
111
  };
113
112
  export default transformer;
@@ -22,13 +22,13 @@ const transformer = (file, api) => {
22
22
  const defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
23
23
  j(node).insertAfter(defaultButtonImport);
24
24
  }
25
- const defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.importKind === 'type');
26
- if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
27
- const typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
28
- j(node).insertAfter(typeImport);
29
- }
30
25
  const valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.type === 'ImportSpecifier');
26
+ const newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing'));
31
27
  const otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => BUTTON_TYPES.includes(specifier.imported.name));
28
+ if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
29
+ const typeImport = j.importDeclaration(newTypeSpecifier, j.stringLiteral('@atlaskit/button/types'));
30
+ j(node).insertAfter(typeImport);
31
+ }
32
32
  if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
33
33
  const typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
34
34
  j(node).insertAfter(typeImport);
@@ -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, options) {
3
+ export default async function transformer(file, api) {
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, options) {
10
10
  const nextSrc = transformer({
11
11
  ...file,
12
12
  source: src
13
- }, api, options);
13
+ }, api);
14
14
  if (nextSrc) {
15
15
  src = nextSrc;
16
16
  }
@@ -2,33 +2,19 @@ export const PRINT_SETTINGS = {
2
2
  quote: 'single'
3
3
  };
4
4
  export const NEW_BUTTON_VARIANTS = {
5
- default: {
6
- import: 'UNSAFE_BUTTON',
7
- as: 'Button'
8
- },
9
- link: {
10
- import: 'UNSAFE_LINK_BUTTON',
11
- as: 'LinkButton'
12
- },
13
- icon: {
14
- import: 'UNSAFE_ICON_BUTTON',
15
- as: 'IconButton'
16
- },
17
- linkIcon: {
18
- import: 'UNSAFE_LINK_ICON_BUTTON',
19
- as: 'LinkIconButton'
20
- }
5
+ default: 'Button',
6
+ link: 'LinkButton',
7
+ icon: 'IconButton',
8
+ linkIcon: 'LinkIconButton'
21
9
  };
22
- export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
10
+ export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
23
11
  export const entryPointsMapping = {
24
12
  Button: '@atlaskit/button/standard-button',
25
13
  LoadingButton: '@atlaskit/button/loading-button',
26
14
  ButtonGroup: '@atlaskit/button/button-group',
27
15
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
16
  };
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';
31
- export const ButtonPropsTypeName = 'ButtonProps';
17
+ export const BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
32
18
  export const unsupportedProps = ['component', 'css', 'style'];
33
19
  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.`;
34
20
  export const iconPropsNoLongerSupportedComment = `"glyph", "primaryColor", "secondaryColor" and "testId" are no longer supported in button icons, please refactor the code and/or revisit the UI.`;
@@ -28,7 +28,6 @@ export const moveSizeAndLabelAttributes = (element, j, iconRenamed = false) => {
28
28
  const iconJSXElementAttributes = iconElement.openingElement.attributes;
29
29
  // add inlined comment to the icon if it has any attributes other than label and size
30
30
  if (Array.isArray(iconJSXElementAttributes)) {
31
- var _sizeAttribute$value;
32
31
  const ifIconAttributeEitherLabelOrSize = iconJSXElementAttributes === null || iconJSXElementAttributes === void 0 ? void 0 : iconJSXElementAttributes.every(attribute => attribute.type === 'JSXAttribute' && typeof attribute.name.name === 'string' && (attribute.name.name === 'size' || attribute.name.name === 'label'));
33
32
  if (!ifIconAttributeEitherLabelOrSize) {
34
33
  addCommentBefore(j, j(iconAttr), iconPropsNoLongerSupportedComment, 'line');
@@ -40,7 +39,7 @@ export const moveSizeAndLabelAttributes = (element, j, iconRenamed = false) => {
40
39
  attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
41
40
  }
42
41
  const sizeAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'size');
43
- if (sizeAttribute && sizeAttribute.type === 'JSXAttribute' && ((_sizeAttribute$value = sizeAttribute.value) === null || _sizeAttribute$value === void 0 ? void 0 : _sizeAttribute$value.type) === 'Literal' && sizeAttribute.value.value !== 'medium') {
42
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
44
43
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : `UNSAFE_${iconAttr.name.name}_size`;
45
44
  attributes === null || attributes === void 0 ? void 0 : attributes.push(sizeAttribute);
46
45
  }
@@ -57,7 +56,7 @@ export const generateNewElement = (variant, element, j) => {
57
56
  attributes
58
57
  } = element.openingElement;
59
58
  const iconAttrs = attributes && getIconAttributes(attributes);
60
- const isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
59
+ const isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon || variant === NEW_BUTTON_VARIANTS.linkIcon;
61
60
  if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
62
61
  moveSizeAndLabelAttributes(element, j, true);
63
62
 
@@ -0,0 +1,27 @@
1
+ import { NEW_BUTTON_VARIANTS } from './constants';
2
+ export const importTypesFromNewEntryPoint = (buttonImports, specifiers, j, fileSource) => {
3
+ const buttonPropsTypeSpecifier = buttonImports.find(j.ImportSpecifier).filter(path => path.node.imported.name === 'ButtonProps');
4
+ if (buttonPropsTypeSpecifier.length > 0) {
5
+ let typeSpecifier;
6
+ specifiers.forEach(specifier => {
7
+ if (specifier.type === 'ImportDefaultSpecifier') {
8
+ typeSpecifier = j.importSpecifier(j.identifier(`${NEW_BUTTON_VARIANTS.default}Props`), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
9
+ } else {
10
+ typeSpecifier = j.importSpecifier(j.identifier(`${specifier.imported.name}Props`), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
11
+ }
12
+ });
13
+ if (typeSpecifier) {
14
+ // @ts-ignore
15
+ typeSpecifier.importKind = 'type';
16
+ specifiers.push(typeSpecifier);
17
+ }
18
+ }
19
+ const appearanceAndSpacingTypeSpecifier = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types').find(j.ImportSpecifier).filter(path => path.node.imported.name === 'Appearance' || path.node.imported.name === 'Spacing');
20
+ if (appearanceAndSpacingTypeSpecifier.length) {
21
+ appearanceAndSpacingTypeSpecifier.forEach(specifier => {
22
+ specifiers.push(specifier.node);
23
+ j(specifier).remove();
24
+ });
25
+ }
26
+ return specifiers;
27
+ };
@@ -15,7 +15,7 @@ export const migrateFitContainerIconButton = (element, j) => {
15
15
  const label = labelAttribute.value.value;
16
16
  const formattedLabel = `${label.charAt(0).toUpperCase()}${label.slice(1)}`.split('-').join(' ');
17
17
  j(element).find(j.JSXAttribute).filter(path => path.node.name.name === 'iconBefore' || path.node.name.name === 'iconAfter').remove();
18
- const newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default.as), attributes), j.jsxClosingElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default.as)), [j.jsxText(formattedLabel)]);
18
+ const newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default), attributes), j.jsxClosingElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default)), [j.jsxText(formattedLabel)]);
19
19
  j(element).replaceWith(newButton);
20
20
  addCommentBefore(j, j(newButton).find(j.JSXAttribute).filter(path => path.node.name.name === 'shouldFitContainer'), migrateFitContainerButtonToDefaultButtonComment, 'line');
21
21
  } else {
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.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.17.6", _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,11 +1,12 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
- import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, eslintDisableComment, ButtonPropsTypeName, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
3
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
4
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
5
5
  import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
6
6
  import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
7
7
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
8
- var transformer = function transformer(file, api, options) {
8
+ import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
9
+ var transformer = function transformer(file, api) {
9
10
  var j = api.jscodeshift;
10
11
  var fileSource = j(file.source);
11
12
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -21,9 +22,9 @@ var transformer = function transformer(file, api, options) {
21
22
  return fileSource.toSource();
22
23
  }
23
24
  var specifierIdentifier = defaultButtonImport.get(0).node.local.name;
24
- var hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import, fileSource, j);
25
- var hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import, fileSource, j);
26
- var hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import, fileSource, j);
25
+ var hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, fileSource, j);
26
+ var hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, fileSource, j);
27
+ var hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
27
28
  var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
28
29
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
29
30
  });
@@ -58,15 +59,15 @@ var transformer = function transformer(file, api, options) {
58
59
  }
59
60
  if (isLinkIconButton) {
60
61
  hasLinkIconButton = true;
61
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value, j));
62
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon, element.value, j));
62
63
  }
63
64
  if (isIconButton) {
64
65
  hasIconButton = true;
65
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value, j));
66
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
66
67
  }
67
68
  if (isLinkButton) {
68
69
  hasLinkButton = true;
69
- j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value, j));
70
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
70
71
  }
71
72
  if (!hasHref && attributes.find(function (node) {
72
73
  var _node$value, _node$name, _node$value2, _node$value3;
@@ -76,10 +77,12 @@ var transformer = function transformer(file, api, options) {
76
77
  addCommentBefore(j, [element], linkButtonMissingHrefComment);
77
78
  }
78
79
  });
80
+
81
+ // modify import declarations
79
82
  var specifiers = [];
80
83
  [hasLinkButton ? 'link' : null, hasIconButton ? 'icon' : null, hasLinkIconButton ? 'linkIcon' : null].forEach(function (variant) {
81
84
  if (variant) {
82
- specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant].import), j.identifier(NEW_BUTTON_VARIANTS[variant].as)));
85
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
83
86
  }
84
87
  });
85
88
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
@@ -93,8 +96,11 @@ var transformer = function transformer(file, api, options) {
93
96
  }).includes(specifierIdentifier);
94
97
  }).length > 0;
95
98
  if (remainingDefaultButtons) {
96
- specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
99
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
97
100
  }
101
+
102
+ // update import path for types imports
103
+ specifiers = importTypesFromNewEntryPoint(buttonImports, specifiers, j, fileSource);
98
104
  var buttonsWithUnsupportedProps = allButtons.filter(function (path) {
99
105
  return ifHasUnsupportedProps(path.value.openingElement.attributes);
100
106
  });
@@ -112,28 +118,19 @@ var transformer = function transformer(file, api, options) {
112
118
 
113
119
  // rename all buttons with unsupported props to LegacyButton if default new button is imported
114
120
  if (specifiers.find(function (specifier) {
115
- return specifier.imported.name === NEW_BUTTON_VARIANTS.default.import;
121
+ return specifier.type === 'ImportDefaultSpecifier';
116
122
  })) {
117
123
  renameDefaultButtonToLegacyButtonImport(oldButtonImport, buttonsWithUnsupportedProps, j);
118
124
  }
119
125
  }
120
- if (specifiers.length || remainingDefaultButtons) {
121
- // split the type imports into a separate import
122
- var typeSpecifier = buttonImports.find(j.ImportSpecifier).filter(function (path) {
123
- return path.node.imported.name === ButtonPropsTypeName;
124
- });
125
- if (typeSpecifier.length > 0) {
126
- oldButtonImport.insertBefore(j.importDeclaration([j.importSpecifier(j.identifier(ButtonPropsTypeName), j.identifier(typeSpecifier.get(0).node.local.name))], j.stringLiteral(entryPointsMapping.Button), 'type'));
127
- }
126
+ if (specifiers.length) {
128
127
  oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
129
-
130
- // add eslint-disable-next-line @atlaskit/design-system/no-banned-imports comment if unsafe import is allowed in custom options
131
- if (NEW_BUTTON_ENTRY_POINT.includes('unsafe') && (options === null || options === void 0 ? void 0 : options.allowUnsafeImport) === true) {
132
- addCommentBefore(j, fileSource.find(j.ImportDeclaration).filter(function (path) {
133
- return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
134
- }), eslintDisableComment, 'line', '');
135
- }
136
128
  }
129
+
130
+ // remove empty import declarations
131
+ fileSource.find(j.ImportDeclaration).filter(function (path) {
132
+ return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
133
+ }).remove();
137
134
  return fileSource.toSource(PRINT_SETTINGS);
138
135
  };
139
136
  export default transformer;
@@ -26,19 +26,19 @@ var transformer = function transformer(file, api) {
26
26
  var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
27
27
  j(node).insertAfter(defaultButtonImport);
28
28
  }
29
- var defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
30
- return specifier.importKind === 'type';
31
- });
32
- if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
33
- var typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
34
- j(node).insertAfter(typeImport);
35
- }
36
29
  var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
37
30
  return specifier.type === 'ImportSpecifier';
38
31
  });
32
+ var newTypeSpecifier = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
33
+ return specifier.type === 'ImportSpecifier' && (specifier.imported.name === 'Appearance' || specifier.imported.name === 'Spacing');
34
+ });
39
35
  var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
40
36
  return BUTTON_TYPES.includes(specifier.imported.name);
41
37
  });
38
+ if (newTypeSpecifier !== null && newTypeSpecifier !== void 0 && newTypeSpecifier.length) {
39
+ var typeImport = j.importDeclaration(newTypeSpecifier, j.stringLiteral('@atlaskit/button/types'));
40
+ j(node).insertAfter(typeImport);
41
+ }
42
42
  if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
43
43
  var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
44
44
  j(node).insertAfter(_typeImport);
@@ -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, _x3) {
8
+ export default function transformer(_x, _x2) {
9
9
  return _transformer.apply(this, arguments);
10
10
  }
11
11
  function _transformer() {
12
- _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api, options) {
12
+ _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api) {
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, options);
25
+ }), api);
26
26
  if (nextSrc) {
27
27
  src = nextSrc;
28
28
  }
@@ -2,33 +2,19 @@ export var PRINT_SETTINGS = {
2
2
  quote: 'single'
3
3
  };
4
4
  export var NEW_BUTTON_VARIANTS = {
5
- default: {
6
- import: 'UNSAFE_BUTTON',
7
- as: 'Button'
8
- },
9
- link: {
10
- import: 'UNSAFE_LINK_BUTTON',
11
- as: 'LinkButton'
12
- },
13
- icon: {
14
- import: 'UNSAFE_ICON_BUTTON',
15
- as: 'IconButton'
16
- },
17
- linkIcon: {
18
- import: 'UNSAFE_LINK_ICON_BUTTON',
19
- as: 'LinkIconButton'
20
- }
5
+ default: 'Button',
6
+ link: 'LinkButton',
7
+ icon: 'IconButton',
8
+ linkIcon: 'LinkIconButton'
21
9
  };
22
- export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
10
+ export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
23
11
  export var entryPointsMapping = {
24
12
  Button: '@atlaskit/button/standard-button',
25
13
  LoadingButton: '@atlaskit/button/loading-button',
26
14
  ButtonGroup: '@atlaskit/button/button-group',
27
15
  CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
16
  };
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';
31
- export var ButtonPropsTypeName = 'ButtonProps';
17
+ export var BUTTON_TYPES = ['BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
32
18
  export var unsupportedProps = ['component', 'css', 'style'];
33
19
  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.";
34
20
  export var iconPropsNoLongerSupportedComment = "\"glyph\", \"primaryColor\", \"secondaryColor\" and \"testId\" are no longer supported in button icons, please refactor the code and/or revisit the UI.";
@@ -29,7 +29,6 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
29
29
  var iconJSXElementAttributes = iconElement.openingElement.attributes;
30
30
  // add inlined comment to the icon if it has any attributes other than label and size
31
31
  if (Array.isArray(iconJSXElementAttributes)) {
32
- var _sizeAttribute$value;
33
32
  var ifIconAttributeEitherLabelOrSize = iconJSXElementAttributes === null || iconJSXElementAttributes === void 0 ? void 0 : iconJSXElementAttributes.every(function (attribute) {
34
33
  return attribute.type === 'JSXAttribute' && typeof attribute.name.name === 'string' && (attribute.name.name === 'size' || attribute.name.name === 'label');
35
34
  });
@@ -47,7 +46,7 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
47
46
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
48
47
  return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
49
48
  });
50
- if (sizeAttribute && sizeAttribute.type === 'JSXAttribute' && ((_sizeAttribute$value = sizeAttribute.value) === null || _sizeAttribute$value === void 0 ? void 0 : _sizeAttribute$value.type) === 'Literal' && sizeAttribute.value.value !== 'medium') {
49
+ if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
51
50
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
52
51
  attributes === null || attributes === void 0 || attributes.push(sizeAttribute);
53
52
  }
@@ -62,7 +61,7 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
62
61
  export var generateNewElement = function generateNewElement(variant, element, j) {
63
62
  var attributes = element.openingElement.attributes;
64
63
  var iconAttrs = attributes && getIconAttributes(attributes);
65
- var isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
64
+ var isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon || variant === NEW_BUTTON_VARIANTS.linkIcon;
66
65
  if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
67
66
  moveSizeAndLabelAttributes(element, j, true);
68
67
 
@@ -0,0 +1,33 @@
1
+ import { NEW_BUTTON_VARIANTS } from './constants';
2
+ export var importTypesFromNewEntryPoint = function importTypesFromNewEntryPoint(buttonImports, specifiers, j, fileSource) {
3
+ var buttonPropsTypeSpecifier = buttonImports.find(j.ImportSpecifier).filter(function (path) {
4
+ return path.node.imported.name === 'ButtonProps';
5
+ });
6
+ if (buttonPropsTypeSpecifier.length > 0) {
7
+ var typeSpecifier;
8
+ specifiers.forEach(function (specifier) {
9
+ if (specifier.type === 'ImportDefaultSpecifier') {
10
+ typeSpecifier = j.importSpecifier(j.identifier("".concat(NEW_BUTTON_VARIANTS.default, "Props")), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
11
+ } else {
12
+ typeSpecifier = j.importSpecifier(j.identifier("".concat(specifier.imported.name, "Props")), j.identifier(buttonPropsTypeSpecifier.get(0).node.local.name));
13
+ }
14
+ });
15
+ if (typeSpecifier) {
16
+ // @ts-ignore
17
+ typeSpecifier.importKind = 'type';
18
+ specifiers.push(typeSpecifier);
19
+ }
20
+ }
21
+ var appearanceAndSpacingTypeSpecifier = fileSource.find(j.ImportDeclaration).filter(function (path) {
22
+ return path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types';
23
+ }).find(j.ImportSpecifier).filter(function (path) {
24
+ return path.node.imported.name === 'Appearance' || path.node.imported.name === 'Spacing';
25
+ });
26
+ if (appearanceAndSpacingTypeSpecifier.length) {
27
+ appearanceAndSpacingTypeSpecifier.forEach(function (specifier) {
28
+ specifiers.push(specifier.node);
29
+ j(specifier).remove();
30
+ });
31
+ }
32
+ return specifiers;
33
+ };
@@ -17,7 +17,7 @@ export var migrateFitContainerIconButton = function migrateFitContainerIconButto
17
17
  j(element).find(j.JSXAttribute).filter(function (path) {
18
18
  return path.node.name.name === 'iconBefore' || path.node.name.name === 'iconAfter';
19
19
  }).remove();
20
- var newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default.as), attributes), j.jsxClosingElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default.as)), [j.jsxText(formattedLabel)]);
20
+ var newButton = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default), attributes), j.jsxClosingElement(j.jsxIdentifier(NEW_BUTTON_VARIANTS.default)), [j.jsxText(formattedLabel)]);
21
21
  j(element).replaceWith(newButton);
22
22
  addCommentBefore(j, j(newButton).find(j.JSXAttribute).filter(function (path) {
23
23
  return path.node.name.name === 'shouldFitContainer';
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo, Options } from 'jscodeshift';
2
- declare const transformer: (file: FileInfo, api: API, options: Options) => string;
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
3
  export default transformer;
@@ -1,2 +1,2 @@
1
- import type { API, FileInfo, Options } from 'jscodeshift';
2
- export default function transformer(file: FileInfo, api: API, options: Options): Promise<string>;
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
@@ -2,18 +2,13 @@ export declare const PRINT_SETTINGS: {
2
2
  quote: "single";
3
3
  };
4
4
  export declare const NEW_BUTTON_VARIANTS: {
5
- [key: string]: {
6
- import: string;
7
- as: string;
8
- };
5
+ [key: string]: string;
9
6
  };
10
- export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/unsafe";
7
+ export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
11
8
  export declare const entryPointsMapping: {
12
9
  [key: string]: string;
13
10
  };
14
11
  export declare const BUTTON_TYPES: string[];
15
- export declare const eslintDisableComment = "eslint-disable-next-line @atlaskit/design-system/no-banned-imports";
16
- export declare const ButtonPropsTypeName = "ButtonProps";
17
12
  export declare const unsupportedProps: string[];
18
13
  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.";
19
14
  export declare const iconPropsNoLongerSupportedComment = "\"glyph\", \"primaryColor\", \"secondaryColor\" and \"testId\" are no longer supported in button icons, please refactor the code and/or revisit the UI.";
@@ -3,4 +3,4 @@ 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;
5
5
  export declare const moveSizeAndLabelAttributes: (element: JSXElement, j: API['jscodeshift'], iconRenamed?: boolean) => void;
6
- export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS]['as'], element: JSXElement, j: API['jscodeshift']) => JSXElement;
6
+ export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS], element: JSXElement, j: API['jscodeshift']) => JSXElement;
@@ -0,0 +1,2 @@
1
+ import type { ImportDefaultSpecifier, ImportSpecifier, JSCodeshift, Collection, ImportDeclaration } from 'jscodeshift';
2
+ export declare const importTypesFromNewEntryPoint: (buttonImports: Collection<ImportDeclaration>, specifiers: (ImportDefaultSpecifier | ImportSpecifier)[], j: JSCodeshift, fileSource: Collection<any>) => (ImportDefaultSpecifier | ImportSpecifier)[];
@@ -1,3 +1,3 @@
1
- import type { API, FileInfo, Options } from 'jscodeshift';
2
- declare const transformer: (file: FileInfo, api: API, options: Options) => string;
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
3
  export default transformer;
@@ -1,2 +1,2 @@
1
- import type { API, FileInfo, Options } from 'jscodeshift';
2
- export default function transformer(file: FileInfo, api: API, options: Options): Promise<string>;
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
@@ -2,18 +2,13 @@ export declare const PRINT_SETTINGS: {
2
2
  quote: "single";
3
3
  };
4
4
  export declare const NEW_BUTTON_VARIANTS: {
5
- [key: string]: {
6
- import: string;
7
- as: string;
8
- };
5
+ [key: string]: string;
9
6
  };
10
- export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/unsafe";
7
+ export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
11
8
  export declare const entryPointsMapping: {
12
9
  [key: string]: string;
13
10
  };
14
11
  export declare const BUTTON_TYPES: string[];
15
- export declare const eslintDisableComment = "eslint-disable-next-line @atlaskit/design-system/no-banned-imports";
16
- export declare const ButtonPropsTypeName = "ButtonProps";
17
12
  export declare const unsupportedProps: string[];
18
13
  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.";
19
14
  export declare const iconPropsNoLongerSupportedComment = "\"glyph\", \"primaryColor\", \"secondaryColor\" and \"testId\" are no longer supported in button icons, please refactor the code and/or revisit the UI.";
@@ -3,4 +3,4 @@ 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;
5
5
  export declare const moveSizeAndLabelAttributes: (element: JSXElement, j: API['jscodeshift'], iconRenamed?: boolean) => void;
6
- export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS]['as'], element: JSXElement, j: API['jscodeshift']) => JSXElement;
6
+ export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS], element: JSXElement, j: API['jscodeshift']) => JSXElement;
@@ -0,0 +1,2 @@
1
+ import type { ImportDefaultSpecifier, ImportSpecifier, JSCodeshift, Collection, ImportDeclaration } from 'jscodeshift';
2
+ export declare const importTypesFromNewEntryPoint: (buttonImports: Collection<ImportDeclaration>, specifiers: (ImportDefaultSpecifier | ImportSpecifier)[], j: JSCodeshift, fileSource: Collection<any>) => (ImportDefaultSpecifier | ImportSpecifier)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.17.4",
3
+ "version": "0.17.6",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,7 +25,7 @@
25
25
  "releaseModel": "continuous"
26
26
  },
27
27
  "scripts": {
28
- "prestart": "cd ../../ && yarn build @atlaskit/codemod-utils",
28
+ "prestart": "cd ../../ && yarn build @atlaskit/codemod-utils tokens",
29
29
  "start": "./bin/codemod-cli.js"
30
30
  },
31
31
  "bin": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/codemod-utils": "^4.2.0",
36
- "@atlaskit/tokens": "^1.29.0",
36
+ "@atlaskit/tokens": "^1.30.0",
37
37
  "@babel/runtime": "^7.0.0",
38
38
  "@codeshift/utils": "^0.2.4",
39
39
  "@types/jscodeshift": "^0.11.0",