@atlaskit/codemod-cli 0.20.0 → 0.21.0

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 (28) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/cli/package.json +1 -1
  3. package/dist/cjs/main.js +1 -1
  4. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +13 -2
  5. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  7. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +0 -1
  8. package/dist/cjs/types.js +1 -1
  9. package/dist/es2019/main.js +0 -1
  10. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +13 -2
  11. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +8 -0
  12. package/dist/es2019/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  13. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +0 -1
  14. package/dist/esm/main.js +1 -1
  15. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +13 -2
  16. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
  17. package/dist/esm/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  18. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +0 -1
  19. package/dist/esm/types.js +1 -1
  20. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  21. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  22. package/filepath/package.json +1 -1
  23. package/main/package.json +1 -1
  24. package/package.json +5 -4
  25. package/sinceRef/package.json +1 -1
  26. package/transforms/package.json +1 -1
  27. package/types/package.json +1 -1
  28. package/utils/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#87074](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87074) [`92be609ad553`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/92be609ad553) - Adds migration support for LoadingButtons
8
+
9
+ ## 0.20.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#83116](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83116) [`8d4e99057fe0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8d4e99057fe0) - Upgrade Typescript from `4.9.5` to `5.4.2`
14
+
3
15
  ## 0.20.0
4
16
 
5
17
  ### Minor Changes
package/cli/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/cli.js",
6
6
  "types": "../dist/types/cli.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/cli.d.ts"
11
11
  ]
package/dist/cjs/main.js CHANGED
@@ -305,7 +305,7 @@ function _main() {
305
305
  case 4:
306
306
  _yield$parseArgs = _context5.sent;
307
307
  packages = _yield$parseArgs.packages;
308
- _process$env$_PACKAGE = "0.20.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.21.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var _utils = require("@hypermod/utils");
8
9
  var _constants = require("../utils/constants");
9
10
  var _generateNewButtonElement = require("../utils/generate-new-button-element");
10
11
  var _hasUnsupportedProps = require("../utils/has-unsupported-props");
@@ -16,7 +17,7 @@ var transformer = function transformer(file, api) {
16
17
  var j = api.jscodeshift;
17
18
  var fileSource = j(file.source);
18
19
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
19
- return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
20
+ return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
20
21
  });
21
22
  if (!buttonImports.length) {
22
23
  return fileSource.toSource();
@@ -37,6 +38,7 @@ var transformer = function transformer(file, api) {
37
38
  var buttonsWithoutUnsupportedProps = allButtons.filter(function (path) {
38
39
  return !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
39
40
  });
41
+ var loadingButtonImportName = (0, _utils.getDefaultImportSpecifierName)(j, fileSource, _constants.entryPointsMapping.LoadingButton);
40
42
  buttonsWithoutUnsupportedProps.forEach(function (element) {
41
43
  var _element$value$childr;
42
44
  var attributes = element.value.openingElement.attributes;
@@ -54,6 +56,7 @@ var transformer = function transformer(file, api) {
54
56
  var isLinkButton = hasHref && !isLinkIconButton;
55
57
  var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
56
58
  var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
59
+ var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
57
60
  if (isDefaultButtonWithAnIcon) {
58
61
  (0, _generateNewButtonElement.moveSizeAndLabelAttributes)(element.value, j);
59
62
  }
@@ -75,6 +78,9 @@ var transformer = function transformer(file, api) {
75
78
  hasLinkButton = true;
76
79
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
77
80
  }
81
+ if (isLoadingButton) {
82
+ j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.default, element.value, j));
83
+ }
78
84
  var linkAppearanceAttribute = attributes.find(function (node) {
79
85
  var _node$value, _node$name, _node$value2, _node$value3;
80
86
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 || (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 || (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 || (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -92,7 +98,7 @@ var transformer = function transformer(file, api) {
92
98
  }
93
99
  });
94
100
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
95
- return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button;
101
+ return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton;
96
102
  });
97
103
  var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
98
104
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
@@ -101,6 +107,11 @@ var transformer = function transformer(file, api) {
101
107
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
102
108
  }).includes(specifierIdentifier);
103
109
  }).length > 0;
110
+
111
+ // Loading buttons map back to default imports
112
+ if (specifierIdentifier === loadingButtonImportName) {
113
+ specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
114
+ }
104
115
  if (remainingDefaultButtons) {
105
116
  specifiers.push(j.importDefaultSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default)));
106
117
  }
@@ -74,6 +74,18 @@ var generateNewElement = exports.generateNewElement = function generateNewElemen
74
74
 
75
75
  // rename iconBefore/iconAfter to icon
76
76
  iconAttrs[0].name.name = 'icon';
77
+ var ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(function (attribute) {
78
+ return attribute.node.name.name === 'aria-label';
79
+ });
80
+ if (ariaLabelAttr.length) {
81
+ var hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(function (attribute) {
82
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
83
+ }));
84
+ if (hasNoLabelProp && attributes) {
85
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
86
+ }
87
+ ariaLabelAttr.remove();
88
+ }
77
89
  }
78
90
  return j.jsxElement(
79
91
  // self closing if it's an icon button or icon link button
@@ -37,6 +37,5 @@ var importTypesFromNewEntryPoint = exports.importTypesFromNewEntryPoint = functi
37
37
  j(specifier).remove(); // remove old one
38
38
  });
39
39
  }
40
-
41
40
  return specifiers;
42
41
  };
@@ -25,7 +25,6 @@ var importMap = {
25
25
  // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
26
26
  // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
27
27
  };
28
-
29
28
  function updateSafeImports(file, api) {
30
29
  var j = api.jscodeshift;
31
30
  var root = j(file.source);
package/dist/cjs/types.js CHANGED
@@ -12,7 +12,7 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
12
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
13
  var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
14
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
16
  /** Converts required args to optional if they have a default
17
17
  * Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
18
18
  */
@@ -60,7 +60,6 @@ const resolveTransform = async (flags, transforms) => {
60
60
  return transform; // Return only if transform found.
61
61
  }
62
62
  }
63
-
64
63
  if (flags.transform && hasTransform(flags.transform)) {
65
64
  return parseTransformPath(flags.transform);
66
65
  }
@@ -1,4 +1,5 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { getDefaultImportSpecifierName } from '@hypermod/utils';
2
3
  import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
4
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
5
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
@@ -9,7 +10,7 @@ import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-ent
9
10
  const transformer = (file, api) => {
10
11
  const j = api.jscodeshift;
11
12
  const fileSource = j(file.source);
12
- const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
13
+ const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
13
14
  if (!buttonImports.length) {
14
15
  return fileSource.toSource();
15
16
  }
@@ -23,6 +24,7 @@ const transformer = (file, api) => {
23
24
  let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, fileSource, j);
24
25
  const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
25
26
  const buttonsWithoutUnsupportedProps = allButtons.filter(path => !ifHasUnsupportedProps(path.value.openingElement.attributes));
27
+ const loadingButtonImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
26
28
  buttonsWithoutUnsupportedProps.forEach(element => {
27
29
  var _element$value$childr;
28
30
  const {
@@ -40,6 +42,7 @@ const transformer = (file, api) => {
40
42
  const isLinkButton = hasHref && !isLinkIconButton;
41
43
  let isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
42
44
  const isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
45
+ const isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
43
46
  if (isDefaultButtonWithAnIcon) {
44
47
  moveSizeAndLabelAttributes(element.value, j);
45
48
  }
@@ -61,6 +64,9 @@ const transformer = (file, api) => {
61
64
  hasLinkButton = true;
62
65
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
63
66
  }
67
+ if (isLoadingButton) {
68
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
69
+ }
64
70
  const linkAppearanceAttribute = attributes.find(node => {
65
71
  var _node$value, _node$name, _node$value2, _node$value3;
66
72
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 ? void 0 : (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 ? void 0 : (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 ? void 0 : (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -77,8 +83,13 @@ const transformer = (file, api) => {
77
83
  specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
78
84
  }
79
85
  });
80
- const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
86
+ const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton);
81
87
  const remainingDefaultButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !ifHasUnsupportedProps(path.value.openingElement.attributes)).length > 0 || fileSource.find(j.CallExpression).filter(path => path.node.arguments.map(argument => argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name)).includes(specifierIdentifier)).length > 0;
88
+
89
+ // Loading buttons map back to default imports
90
+ if (specifierIdentifier === loadingButtonImportName) {
91
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
92
+ }
82
93
  if (remainingDefaultButtons) {
83
94
  specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
84
95
  }
@@ -65,6 +65,14 @@ export const generateNewElement = (variant, element, j) => {
65
65
 
66
66
  // rename iconBefore/iconAfter to icon
67
67
  iconAttrs[0].name.name = 'icon';
68
+ const ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(attribute => attribute.node.name.name === 'aria-label');
69
+ if (ariaLabelAttr.length) {
70
+ const hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label'));
71
+ if (hasNoLabelProp && attributes) {
72
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
73
+ }
74
+ ariaLabelAttr.remove();
75
+ }
68
76
  }
69
77
  return j.jsxElement(
70
78
  // self closing if it's an icon button or icon link button
@@ -25,6 +25,5 @@ export const importTypesFromNewEntryPoint = (buttonImports, specifiers, j, fileS
25
25
  j(specifier).remove(); // remove old one
26
26
  });
27
27
  }
28
-
29
28
  return specifiers;
30
29
  };
@@ -19,7 +19,6 @@ const importMap = {
19
19
  // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
20
20
  // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
21
21
  };
22
-
23
22
  export function updateSafeImports(file, api) {
24
23
  const j = api.jscodeshift;
25
24
  const root = j(file.source);
package/dist/esm/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.20.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.21.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -1,4 +1,5 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { getDefaultImportSpecifierName } from '@hypermod/utils';
2
3
  import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
3
4
  import { generateNewElement, moveSizeAndLabelAttributes } from '../utils/generate-new-button-element';
4
5
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
@@ -10,7 +11,7 @@ var transformer = function transformer(file, api) {
10
11
  var j = api.jscodeshift;
11
12
  var fileSource = j(file.source);
12
13
  var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
13
- return path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
14
+ return path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
14
15
  });
15
16
  if (!buttonImports.length) {
16
17
  return fileSource.toSource();
@@ -31,6 +32,7 @@ var transformer = function transformer(file, api) {
31
32
  var buttonsWithoutUnsupportedProps = allButtons.filter(function (path) {
32
33
  return !ifHasUnsupportedProps(path.value.openingElement.attributes);
33
34
  });
35
+ var loadingButtonImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
34
36
  buttonsWithoutUnsupportedProps.forEach(function (element) {
35
37
  var _element$value$childr;
36
38
  var attributes = element.value.openingElement.attributes;
@@ -48,6 +50,7 @@ var transformer = function transformer(file, api) {
48
50
  var isLinkButton = hasHref && !isLinkIconButton;
49
51
  var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
50
52
  var isDefaultButtonWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
53
+ var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonImportName;
51
54
  if (isDefaultButtonWithAnIcon) {
52
55
  moveSizeAndLabelAttributes(element.value, j);
53
56
  }
@@ -69,6 +72,9 @@ var transformer = function transformer(file, api) {
69
72
  hasLinkButton = true;
70
73
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
71
74
  }
75
+ if (isLoadingButton) {
76
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.default, element.value, j));
77
+ }
72
78
  var linkAppearanceAttribute = attributes.find(function (node) {
73
79
  var _node$value, _node$name, _node$value2, _node$value3;
74
80
  return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 || (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 || (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 || (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
@@ -86,7 +92,7 @@ var transformer = function transformer(file, api) {
86
92
  }
87
93
  });
88
94
  var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
89
- return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button;
95
+ return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton;
90
96
  });
91
97
  var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
92
98
  return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier && !ifHasUnsupportedProps(path.value.openingElement.attributes);
@@ -95,6 +101,11 @@ var transformer = function transformer(file, api) {
95
101
  return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
96
102
  }).includes(specifierIdentifier);
97
103
  }).length > 0;
104
+
105
+ // Loading buttons map back to default imports
106
+ if (specifierIdentifier === loadingButtonImportName) {
107
+ specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
108
+ }
98
109
  if (remainingDefaultButtons) {
99
110
  specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
100
111
  }
@@ -68,6 +68,18 @@ export var generateNewElement = function generateNewElement(variant, element, j)
68
68
 
69
69
  // rename iconBefore/iconAfter to icon
70
70
  iconAttrs[0].name.name = 'icon';
71
+ var ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(function (attribute) {
72
+ return attribute.node.name.name === 'aria-label';
73
+ });
74
+ if (ariaLabelAttr.length) {
75
+ var hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(function (attribute) {
76
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
77
+ }));
78
+ if (hasNoLabelProp && attributes) {
79
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
80
+ }
81
+ ariaLabelAttr.remove();
82
+ }
71
83
  }
72
84
  return j.jsxElement(
73
85
  // self closing if it's an icon button or icon link button
@@ -31,6 +31,5 @@ export var importTypesFromNewEntryPoint = function importTypesFromNewEntryPoint(
31
31
  j(specifier).remove(); // remove old one
32
32
  });
33
33
  }
34
-
35
34
  return specifiers;
36
35
  };
@@ -19,7 +19,6 @@ var importMap = {
19
19
  // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
20
20
  // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
21
21
  };
22
-
23
22
  export function updateSafeImports(file, api) {
24
23
  var j = api.jscodeshift;
25
24
  var root = j(file.source);
package/dist/esm/types.js CHANGED
@@ -5,7 +5,7 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
6
  import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
7
7
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
8
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
9
  /** Converts required args to optional if they have a default
10
10
  * Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
11
11
  */
@@ -1,4 +1,4 @@
1
- import type { API, JSXElement, JSXAttribute, JSXSpreadAttribute } from 'jscodeshift';
1
+ import { API, JSXElement, JSXAttribute, 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;
@@ -1,4 +1,4 @@
1
- import type { API, JSXElement, JSXAttribute, JSXSpreadAttribute } from 'jscodeshift';
1
+ import { API, JSXElement, JSXAttribute, 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;
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/filepath.js",
6
6
  "types": "../dist/types/filepath.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/filepath.d.ts"
11
11
  ]
package/main/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/main.js",
6
6
  "types": "../dist/types/main.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/main.d.ts"
11
11
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -40,9 +40,10 @@
40
40
  "bin": "./bin/codemod-cli.js",
41
41
  "dependencies": {
42
42
  "@atlaskit/codemod-utils": "^4.2.0",
43
- "@atlaskit/tokens": "^1.38.0",
43
+ "@atlaskit/tokens": "^1.42.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codeshift/utils": "^0.2.4",
46
+ "@hypermod/utils": "^0.4.2",
46
47
  "@types/jscodeshift": "^0.11.0",
47
48
  "chalk": "^4.1.2",
48
49
  "enquirer": "^2.3.4",
@@ -57,8 +58,8 @@
57
58
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
58
59
  "prettier": "^2.8.0",
59
60
  "ts-node": "^10.9.1",
60
- "typescript": "~4.9.5"
61
+ "typescript": "~5.4.2"
61
62
  },
62
63
  "homepage": "https://atlaskit.atlassian.com/packages/monorepo-tooling/codemod-cli",
63
64
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
64
- }
65
+ }
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/sinceRef.js",
6
6
  "types": "../dist/types/sinceRef.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/sinceRef.d.ts"
11
11
  ]
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/transforms.js",
6
6
  "types": "../dist/types/transforms.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/transforms.d.ts"
11
11
  ]
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/types.js",
6
6
  "types": "../dist/types/types.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/types.d.ts"
11
11
  ]
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/utils.js",
6
6
  "types": "../dist/types/utils.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/utils.d.ts"
11
11
  ]