@atlaskit/codemod-cli 0.24.4 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +19 -9
  3. package/bin/codemod-cli.js +10 -10
  4. package/dist/cjs/main.js +1 -1
  5. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +94 -0
  6. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +30 -8
  7. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +4 -3
  8. package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  9. package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +2 -0
  10. package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +15 -0
  11. package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +2 -1
  12. package/dist/cjs/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +17 -0
  13. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-link-element.js +40 -0
  14. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +6 -1
  15. package/dist/cjs/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +30 -0
  16. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +81 -0
  17. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +30 -8
  18. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +3 -2
  19. package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  20. package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +2 -0
  21. package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +7 -0
  22. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +1 -0
  23. package/dist/es2019/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +11 -0
  24. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-link-element.js +36 -0
  25. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +6 -1
  26. package/dist/es2019/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +24 -0
  27. package/dist/esm/main.js +1 -1
  28. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +87 -0
  29. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +30 -8
  30. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +3 -2
  31. package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
  32. package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +2 -0
  33. package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +9 -0
  34. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +1 -0
  35. package/dist/esm/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +11 -0
  36. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-link-element.js +34 -0
  37. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +6 -1
  38. package/dist/esm/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +24 -0
  39. package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.d.ts +3 -0
  40. package/dist/types/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -1
  41. package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +2 -0
  42. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  43. package/dist/types/presets/migrate-to-new-buttons/utils/find-attribute-with-value.d.ts +2 -0
  44. package/dist/types/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +3 -0
  45. package/dist/types/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +3 -0
  46. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.d.ts +3 -0
  47. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -1
  48. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +2 -0
  49. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  50. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/find-attribute-with-value.d.ts +2 -0
  51. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +3 -0
  52. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +3 -0
  53. package/index.js +6 -6
  54. package/package.json +63 -63
  55. package/report.api.md +29 -28
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.25.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#120049](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/120049)
8
+ [`77504ff274f72`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/77504ff274f72) -
9
+ DSP-19576: Assign names to anonymous default exports
10
+
11
+ ## 0.25.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#111403](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111403)
16
+ [`cc57d517bca2a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cc57d517bca2a) -
17
+ Migrate to new buttons codemod now adds comment for deprecated `overlay` props.
18
+
3
19
  ## 0.24.4
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Codemods
2
2
 
3
- To easily download and run codemods associated with atlassian-frontend components and services, we provide a CLI tool called `@atlaskit/codemod-cli`.
3
+ To easily download and run codemods associated with atlassian-frontend components and services, we
4
+ provide a CLI tool called `@atlaskit/codemod-cli`.
4
5
 
5
- The idea is that upgrading major versions can be **assisted** by codemods, reducing upgrade-pain, improving adoption and giving component authors the flexibility to improve API and component design.
6
+ The idea is that upgrading major versions can be **assisted** by codemods, reducing upgrade-pain,
7
+ improving adoption and giving component authors the flexibility to improve API and component design.
6
8
 
7
- **Note:** Codemods will be designed to do the heavy lifting, but they'll often not be perfect so some manual work may still be required in order to successfully migrate.
9
+ **Note:** Codemods will be designed to do the heavy lifting, but they'll often not be perfect so
10
+ some manual work may still be required in order to successfully migrate.
8
11
 
9
12
  ---
10
13
 
@@ -16,7 +19,8 @@ The idea is that upgrading major versions can be **assisted** by codemods, reduc
16
19
 
17
20
  ### --preset, -n
18
21
 
19
- Select which transform to run from existing transform list by providing the preset name. This will allow you run the transfrom without any interaction.
22
+ Select which transform to run from existing transform list by providing the preset name. This will
23
+ allow you run the transfrom without any interaction.
20
24
 
21
25
  **example:**
22
26
 
@@ -33,7 +37,8 @@ The transform to run, transforms can be either a single file or directory with a
33
37
 
34
38
  ### --since-ref <git-ref>
35
39
 
36
- Determines changed packages since the specified git ref and runs all codemods for them. The automatic version of `--packages`. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
40
+ Determines changed packages since the specified git ref and runs all codemods for them. The
41
+ automatic version of `--packages`. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
37
42
 
38
43
  **example:**
39
44
 
@@ -42,7 +47,8 @@ Determines changed packages since the specified git ref and runs all codemods fo
42
47
 
43
48
  ### --packages
44
49
 
45
- Runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version
50
+ Runs transforms for the specified comma separated list of packages, optionally include a version for
51
+ each package to run all transforms since that version
46
52
 
47
53
  **example:**
48
54
 
@@ -85,7 +91,9 @@ Ignore files that match a provided glob expression
85
91
 
86
92
  ### --no-filter-paths
87
93
 
88
- The codemod CLI filters supplied file paths by default, improving runtime by preventing codemods from running in non-dependent packages. Add this flag if there are problems with the filtering logic.
94
+ The codemod CLI filters supplied file paths by default, improving runtime by preventing codemods
95
+ from running in non-dependent packages. Add this flag if there are problems with the filtering
96
+ logic.
89
97
 
90
98
  **example:**
91
99
 
@@ -110,7 +118,8 @@ Print all help text to the command line
110
118
 
111
119
  ### Custom options
112
120
 
113
- All options are passed to the transformer, which means you can supply custom options that are not listed here.
121
+ All options are passed to the transformer, which means you can supply custom options that are not
122
+ listed here.
114
123
 
115
124
  **examples:**
116
125
 
@@ -132,4 +141,5 @@ For a list of commands run it with `-h` or refer to the documentation above.
132
141
 
133
142
  ## For internal Atlassians
134
143
 
135
- _Internal Atlassians can access [additional documentation on Confluence](https://hello.atlassian.net/wiki/spaces/AF/pages/2627171992/Codemods)._
144
+ _Internal Atlassians can access
145
+ [additional documentation on Confluence](https://hello.atlassian.net/wiki/spaces/AF/pages/2627171992/Codemods)._
@@ -8,16 +8,16 @@ const project = path.join(__dirname, '../tsconfig.json');
8
8
  const dev = fs.existsSync(project);
9
9
 
10
10
  if (dev && !require.extensions['.ts']) {
11
- // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
12
- require('ts-node').register({ project });
11
+ // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
12
+ require('ts-node').register({ project });
13
13
  }
14
14
 
15
15
  require(path.join('..', dev ? 'src/cli' : 'dist/cjs/cli'))
16
- .run()
17
- .catch((error) => {
18
- if (typeof error === 'number') {
19
- process.exit(error);
20
- }
21
- console.error(error);
22
- process.exit(1);
23
- });
16
+ .run()
17
+ .catch((error) => {
18
+ if (typeof error === 'number') {
19
+ process.exit(error);
20
+ }
21
+ console.error(error);
22
+ process.exit(1);
23
+ });
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.24.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.25.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _utils = require("@hypermod/utils");
9
+ var _constants = require("../utils/constants");
10
+ var _moveIconValueFromLinkButtonToLinkChildren = _interopRequireDefault(require("../utils/move-icon-value-from-link-button-to-link-children"));
11
+ var _findAttributeWithValue = require("../utils/find-attribute-with-value");
12
+ var _generateLinkElement = require("../utils/generate-link-element");
13
+ function transformer(file, api) {
14
+ var j = api.jscodeshift;
15
+ var source = j(file.source);
16
+
17
+ // Find all new button imports
18
+ var newButtonImportDeclarations = (0, _utils.getImportDeclaration)(j, source, _constants.NEW_BUTTON_ENTRY_POINT);
19
+
20
+ // No imports for new button found, exit early
21
+ if (!newButtonImportDeclarations.length) {
22
+ return source.toSource();
23
+ }
24
+ var linkButtonSpecifier = '';
25
+ var linkButtonDeclaration;
26
+ newButtonImportDeclarations.forEach(function (newButtonImport) {
27
+ if (!newButtonImport.value.specifiers) {
28
+ return;
29
+ }
30
+ newButtonImport.value.specifiers.map(function (specifier) {
31
+ if (specifier.type === 'ImportSpecifier' && specifier.imported && specifier.imported.name === _constants.NEW_BUTTON_VARIANTS['link']) {
32
+ var _specifier$local;
33
+ linkButtonDeclaration = newButtonImport;
34
+ linkButtonSpecifier = ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || '';
35
+ }
36
+ });
37
+ });
38
+ if (!linkButtonSpecifier) {
39
+ return source.toSource();
40
+ }
41
+ var hasLink = false;
42
+ var allLinkButtons = source.find(j.JSXElement).filter(function (path) {
43
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier;
44
+ });
45
+ allLinkButtons.filter(function (path) {
46
+ return (0, _findAttributeWithValue.findJSXAttributeWithValue)(path.value.openingElement, 'appearance', 'link') || (0, _findAttributeWithValue.findJSXAttributeWithValue)(path.value.openingElement, 'appearance', 'subtle-link');
47
+ }).forEach(function (path) {
48
+ var hasSpacingNone = (0, _findAttributeWithValue.findJSXAttributeWithValue)(path.value.openingElement, 'spacing', 'none');
49
+ if (!hasSpacingNone) {
50
+ j(path).find(j.JSXAttribute).filter(function (path) {
51
+ var _path$node$value;
52
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link');
53
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
54
+ }
55
+ if (hasSpacingNone) {
56
+ var attributes = path.node.openingElement.attributes;
57
+ (0, _generateLinkElement.modifyLinkAttributes)(path.node, j);
58
+ j(path).find(j.JSXAttribute).filter(function (attribute) {
59
+ var _attribute$node$value;
60
+ var isIconAttribute = attribute.node.name.name === 'iconBefore' || attribute.node.name.name === 'iconAfter';
61
+ if (((_attribute$node$value = attribute.node.value) === null || _attribute$node$value === void 0 ? void 0 : _attribute$node$value.type) === 'JSXExpressionContainer' && isIconAttribute) {
62
+ (0, _moveIconValueFromLinkButtonToLinkChildren.default)(j, path, attribute.node.value, attribute.node.name.name);
63
+ }
64
+ return isIconAttribute;
65
+ }).remove();
66
+ hasLink = true;
67
+ j(path).replaceWith(j.jsxElement.from({
68
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier('Link'), attributes, false),
69
+ closingElement: j.jsxClosingElement(j.jsxIdentifier('Link')),
70
+ children: path.node.children
71
+ }));
72
+ }
73
+ });
74
+
75
+ // add link import and remove link button import if no link button is found
76
+ if (hasLink && linkButtonDeclaration) {
77
+ var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
78
+ j(linkButtonDeclaration).insertAfter(linkImport);
79
+ var remainingLinkButton = source.find(j.JSXElement).filter(function (path) {
80
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier;
81
+ });
82
+ if (!remainingLinkButton.length) {
83
+ var _value$specifiers;
84
+ j(linkButtonDeclaration).find(j.ImportSpecifier).filter(function (path) {
85
+ return path.node.imported.name === _constants.NEW_BUTTON_VARIANTS['link'];
86
+ }).remove();
87
+ if (((_value$specifiers = linkButtonDeclaration.value.specifiers) === null || _value$specifiers === void 0 ? void 0 : _value$specifiers.length) === 0) {
88
+ j(linkButtonDeclaration).remove();
89
+ }
90
+ }
91
+ }
92
+ return source.toSource(_constants.PRINT_SETTINGS);
93
+ }
94
+ var _default = exports.default = transformer;
@@ -12,12 +12,15 @@ var _constants = require("../utils/constants");
12
12
  var _getDefaultImports = _interopRequireDefault(require("../utils/get-default-imports"));
13
13
  var _getSpecifierNames = _interopRequireDefault(require("../utils/get-specifier-names"));
14
14
  var _generateNewButtonElement = require("../utils/generate-new-button-element");
15
+ var _generateLinkElement = require("../utils/generate-link-element");
15
16
  var _hasUnsupportedProps = require("../utils/has-unsupported-props");
16
17
  var _ifVariantAlreadyImported = require("../utils/if-variant-already-imported");
17
18
  var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
18
19
  var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
19
20
  var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
20
21
  var _addCommentForCustomThemeButtons = require("../utils/add-comment-for-custom-theme-buttons");
22
+ var _addCommentForOverlayProp = require("../utils/add-comment-for-overlay-prop");
23
+ var _findAttributeWithValue = require("../utils/find-attribute-with-value");
21
24
  var transformer = function transformer(file, api) {
22
25
  var j = api.jscodeshift;
23
26
  var fileSource = j(file.source);
@@ -51,11 +54,13 @@ var transformer = function transformer(file, api) {
51
54
  defaultButton: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.default, _constants.NEW_BUTTON_ENTRY_POINT, fileSource, j, true),
52
55
  linkButton: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.link, _constants.NEW_BUTTON_ENTRY_POINT, fileSource, j),
53
56
  iconButton: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.icon, _constants.NEW_BUTTON_ENTRY_POINT, fileSource, j),
54
- linkIconButton: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.linkIcon, _constants.NEW_BUTTON_ENTRY_POINT, fileSource, j)
57
+ linkIconButton: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)(_constants.NEW_BUTTON_VARIANTS.linkIcon, _constants.NEW_BUTTON_ENTRY_POINT, fileSource, j),
58
+ link: (0, _ifVariantAlreadyImported.checkIfVariantAlreadyImported)('link', '@atlaskit/link', fileSource, j)
55
59
  };
56
60
  var oldButtonElements = fileSource.find(j.JSXElement).filter(function (path) {
57
61
  return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(_constants.OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
58
62
  });
63
+ (0, _addCommentForOverlayProp.addCommentForOverlayProp)(oldButtonElements, j);
59
64
  var oldButtonsWithoutUnsupportedProps = oldButtonElements.filter(function (path) {
60
65
  return !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
61
66
  });
@@ -71,18 +76,24 @@ var transformer = function transformer(file, api) {
71
76
  var hasHref = buttonAttributes.includes('href');
72
77
  var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
73
78
  var hasNoChildren = ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
79
+ var hasSpacing = attributes.find(function (attr) {
80
+ var _attr$value;
81
+ return attr.type === 'JSXAttribute' && attr.name.name === 'spacing' && ((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral' && attr.value.value !== 'none';
82
+ }) || !buttonAttributes.includes('spacing');
83
+ var hasSpacingNone = (0, _findAttributeWithValue.findJSXAttributeWithValue)(element.value.openingElement, 'spacing', 'none');
74
84
  var isFitContainerIconButton = hasIcon && hasNoChildren && buttonAttributes.includes('shouldFitContainer');
75
- var isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
76
- var isLinkButton = hasHref && !isLinkIconButton;
77
- var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
78
- var isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton;
79
- var isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
80
- var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
81
85
  var linkAppearanceAttribute = attributes.find(function (node) {
82
86
  var _node$value, _node$name, _node$value2, _node$value3;
83
87
  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');
84
88
  });
85
- if (isDefaultVariantWithAnIcon) {
89
+ var isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
90
+ var isLinkButton = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacing;
91
+ var isLink = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacingNone && linkAppearanceAttribute;
92
+ var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton && !isLink;
93
+ var isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton && !isLink;
94
+ var isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon && !isLink;
95
+ var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
96
+ if (isDefaultVariantWithAnIcon && !isLink) {
86
97
  (0, _generateNewButtonElement.handleIconAttributes)(element.value, j);
87
98
  }
88
99
  if (isFitContainerIconButton) {
@@ -103,6 +114,10 @@ var transformer = function transformer(file, api) {
103
114
  hasVariant.linkButton = true;
104
115
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
105
116
  }
117
+ if (isLink && !isLoadingButton) {
118
+ hasVariant.link = true;
119
+ j(element).replaceWith((0, _generateLinkElement.generateLinkComponent)(element.node, j));
120
+ }
106
121
  if (isDefaultButton && !isLoadingButton) {
107
122
  hasVariant.defaultButton = true;
108
123
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(newDefaultImportSpecifiers !== null && newDefaultImportSpecifiers !== void 0 && newDefaultImportSpecifiers.length ?
@@ -214,6 +229,13 @@ var transformer = function transformer(file, api) {
214
229
  (0, _renameDefaultButtonToLegacyButton.renameDefaultButtonToLegacyButtonImport)(oldButtonImports, oldButtonsWithUnsupportedProps, j);
215
230
  }
216
231
  }
232
+ if (hasVariant.link) {
233
+ var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
234
+ oldButtonImports.at(0).insertBefore(linkImport);
235
+ if (!remainingDefaultButtons && !oldButtonsWithUnsupportedProps.length) {
236
+ oldButtonImports.at(0).remove();
237
+ }
238
+ }
217
239
  if (specifiers.length) {
218
240
  var existingNewButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
219
241
  return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = _default;
6
+ exports.default = void 0;
7
7
  var _utils = require("@hypermod/utils");
8
8
  var _constants = require("../utils/constants");
9
- function _default(file, api) {
9
+ function transformer(file, api) {
10
10
  var j = api.jscodeshift;
11
11
  var source = j(file.source);
12
12
 
@@ -118,4 +118,5 @@ function _default(file, api) {
118
118
  }
119
119
  });
120
120
  return source.toSource(_constants.PRINT_SETTINGS);
121
- }
121
+ }
122
+ var _default = exports.default = transformer;
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
11
11
  var _nextSplitImports = _interopRequireDefault(require("./codemods/next-split-imports"));
12
12
  var _nextMigrateToNewButtonVariants = _interopRequireDefault(require("./codemods/next-migrate-to-new-button-variants"));
13
13
  var _nextRemoveUnsafeSize = _interopRequireDefault(require("./codemods/next-remove-unsafe-size"));
14
+ var _nextMigrateLinkButtonToLink = _interopRequireDefault(require("./codemods/next-migrate-link-button-to-link"));
14
15
  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; }
15
16
  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; }
16
17
  function transformer(_x, _x2) {
@@ -22,7 +23,7 @@ function _transformer() {
22
23
  return _regenerator.default.wrap(function _callee$(_context) {
23
24
  while (1) switch (_context.prev = _context.next) {
24
25
  case 0:
25
- transformers = [_nextSplitImports.default, _nextMigrateToNewButtonVariants.default, _nextRemoveUnsafeSize.default];
26
+ transformers = [_nextSplitImports.default, _nextMigrateToNewButtonVariants.default, _nextRemoveUnsafeSize.default, _nextMigrateLinkButtonToLink.default];
26
27
  src = file.source;
27
28
  transformers.forEach(function (transformer) {
28
29
  if (typeof src === 'undefined') {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.addCommentForCustomThemeButtons = void 0;
7
7
  var _codemodUtils = require("@atlaskit/codemod-utils");
8
8
  var _constants = require("./constants");
9
+ var _addCommentForOverlayProp = require("./add-comment-for-overlay-prop");
9
10
  var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
10
11
  var _fileSource$find$filt;
11
12
  var customThemeButtonImportName;
@@ -29,5 +30,6 @@ var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons =
29
30
  if (!customThemeButtonElement.length) {
30
31
  return;
31
32
  }
33
+ (0, _addCommentForOverlayProp.addCommentForOverlayProp)(customThemeButtonElement, j);
32
34
  (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'block');
33
35
  };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addCommentForOverlayProp = void 0;
7
+ var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var _constants = require("./constants");
9
+ var addCommentForOverlayProp = exports.addCommentForOverlayProp = function addCommentForOverlayProp(oldButtons, j) {
10
+ oldButtons.find(j.JSXAttribute).filter(function (attribute) {
11
+ return attribute.node.name.name === 'overlay';
12
+ }).forEach(function (attribute) {
13
+ (0, _codemodUtils.addCommentBefore)(j, j(attribute), _constants.overlayPropComment, 'block');
14
+ });
15
+ };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
6
+ exports.unsupportedProps = exports.overlayPropComment = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = 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
  };
@@ -40,6 +40,7 @@ var buttonPropsNoLongerSupportedComment = exports.buttonPropsNoLongerSupportedCo
40
40
  var migrateFitContainerButtonToDefaultButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
41
41
  var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
42
42
  var customThemeButtonComment = exports.customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
43
+ var overlayPropComment = exports.overlayPropComment = "The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the `isLoading` prop. Please remove the `overlay` prop and consider using the new `isLoading` prop.";
43
44
  var loadingButtonComment = exports.loadingButtonComment = function loadingButtonComment(_ref) {
44
45
  var hasLinkAppearance = _ref.hasLinkAppearance,
45
46
  hasHref = _ref.hasHref;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findJSXAttributeWithValue = void 0;
7
+ var findJSXAttributeWithValue = exports.findJSXAttributeWithValue = function findJSXAttributeWithValue(path, attributeName, attributeValue) {
8
+ var _path$attributes;
9
+ if (!path || path.type === 'JSXSpreadAttribute') {
10
+ return false;
11
+ }
12
+ var attribute = path === null || path === void 0 || (_path$attributes = path.attributes) === null || _path$attributes === void 0 ? void 0 : _path$attributes.find(function (attribute) {
13
+ var _attribute$value;
14
+ return attribute.type === 'JSXAttribute' && attribute.name.name === attributeName && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && attribute.value.value === attributeValue;
15
+ });
16
+ return Boolean(attribute);
17
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.modifyLinkAttributes = exports.generateLinkComponent = void 0;
7
+ var modifyLinkAttributes = exports.modifyLinkAttributes = function modifyLinkAttributes(element, j) {
8
+ j(element).find(j.JSXAttribute).filter(function (path) {
9
+ var _path$node$value, _path$node$value2;
10
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && path.node.value.value === 'link' || path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
11
+ }).remove();
12
+ j(element).find(j.JSXAttribute).filter(function (path) {
13
+ var _path$node$value3;
14
+ return path.node.name.name === 'appearance' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'subtle-link';
15
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
16
+ };
17
+ var generateLinkComponent = exports.generateLinkComponent = function generateLinkComponent(element, j) {
18
+ var attributes = element.openingElement.attributes;
19
+ if (!element.children) {
20
+ return;
21
+ }
22
+ modifyLinkAttributes(element, j);
23
+ j(element).find(j.JSXAttribute).filter(function (attribute) {
24
+ var _attribute$node$value;
25
+ var isIconAttribute = attribute.node.name.name === 'iconBefore' || attribute.node.name.name === 'iconAfter';
26
+ if (((_attribute$node$value = attribute.node.value) === null || _attribute$node$value === void 0 ? void 0 : _attribute$node$value.type) === 'JSXExpressionContainer' && isIconAttribute) {
27
+ var iconNode = attribute.node.value;
28
+ if (iconNode && iconNode.type === 'JSXExpressionContainer' && iconNode.expression.type === 'JSXElement' && element.children) {
29
+ var icon = iconNode.expression;
30
+ attribute.node.name.name === 'iconBefore' ? element.children.unshift(icon) : element.children.push(icon);
31
+ }
32
+ }
33
+ return isIconAttribute;
34
+ }).remove();
35
+ return j.jsxElement.from({
36
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier('Link'), attributes, false),
37
+ closingElement: j.jsxClosingElement(j.jsxIdentifier('Link')),
38
+ children: element.children
39
+ });
40
+ };
@@ -38,7 +38,6 @@ var getIconElement = exports.getIconElement = function getIconElement(iconAttr)
38
38
  var handleIconAttributes = exports.handleIconAttributes = function handleIconAttributes(element, j) {
39
39
  var iconRenamed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
40
40
  var buttonAttributes = element.openingElement.attributes;
41
-
42
41
  // Get iconBefore and iconAfter attributes
43
42
  var buttonIconAttributes = buttonAttributes && getIconAttributes(buttonAttributes);
44
43
  buttonIconAttributes === null || buttonIconAttributes === void 0 || buttonIconAttributes.forEach(function (iconAttribute) {
@@ -113,6 +112,12 @@ var generateNewElement = exports.generateNewElement = function generateNewElemen
113
112
  var attributes = element.openingElement.attributes;
114
113
  var iconAttrs = attributes && getIconAttributes(attributes);
115
114
  var isIconOrLinkIcon = variant === _constants.NEW_BUTTON_VARIANTS.icon || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon;
115
+ if (variant === _constants.NEW_BUTTON_VARIANTS.link) {
116
+ j(element).find(j.JSXAttribute).filter(function (path) {
117
+ var _path$node$value;
118
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link');
119
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
120
+ }
116
121
  if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
117
122
  handleIconAttributes(element, j, true);
118
123
 
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var moveIcon = function moveIcon(j, path, iconNode, beforeOrAfter) {
8
+ var element;
9
+ if (!iconNode) {
10
+ return;
11
+ }
12
+ if (iconNode.type === 'JSXExpressionContainer') {
13
+ // when iconBefore={(iconProps) => <AddIcon {...iconProps} />}
14
+ if (iconNode.expression.type === 'ArrowFunctionExpression' && iconNode.expression.body.type === 'JSXElement') {
15
+ // remove {...iconProps} spread attribute
16
+ element = iconNode.expression.body;
17
+ j(element).find(j.JSXSpreadAttribute).remove();
18
+ j(element).find(j.JSXAttribute).insertBefore(j.jsxAttribute(j.jsxIdentifier('label'), j.stringLiteral('')));
19
+ }
20
+
21
+ // when iconBefore={AddIcon}
22
+ if (iconNode.expression.type === 'Identifier') {
23
+ element = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(iconNode.expression.name), [j.jsxAttribute(j.jsxIdentifier('label'), j.stringLiteral(''))], true));
24
+ }
25
+ if (element && path.node.children) {
26
+ beforeOrAfter === 'iconBefore' ? path.node.children.unshift(element) : path.node.children.push(element);
27
+ }
28
+ }
29
+ };
30
+ var _default = exports.default = moveIcon;
@@ -0,0 +1,81 @@
1
+ import { getImportDeclaration } from '@hypermod/utils';
2
+ import { PRINT_SETTINGS, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS } from '../utils/constants';
3
+ import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
4
+ import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
5
+ import { modifyLinkAttributes } from '../utils/generate-link-element';
6
+ function transformer(file, api) {
7
+ const j = api.jscodeshift;
8
+ const source = j(file.source);
9
+
10
+ // Find all new button imports
11
+ const newButtonImportDeclarations = getImportDeclaration(j, source, NEW_BUTTON_ENTRY_POINT);
12
+
13
+ // No imports for new button found, exit early
14
+ if (!newButtonImportDeclarations.length) {
15
+ return source.toSource();
16
+ }
17
+ let linkButtonSpecifier = '';
18
+ let linkButtonDeclaration;
19
+ newButtonImportDeclarations.forEach(newButtonImport => {
20
+ if (!newButtonImport.value.specifiers) {
21
+ return;
22
+ }
23
+ newButtonImport.value.specifiers.map(specifier => {
24
+ if (specifier.type === 'ImportSpecifier' && specifier.imported && specifier.imported.name === NEW_BUTTON_VARIANTS['link']) {
25
+ var _specifier$local;
26
+ linkButtonDeclaration = newButtonImport;
27
+ linkButtonSpecifier = ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || '';
28
+ }
29
+ });
30
+ });
31
+ if (!linkButtonSpecifier) {
32
+ return source.toSource();
33
+ }
34
+ let hasLink = false;
35
+ const allLinkButtons = source.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier);
36
+ allLinkButtons.filter(path => findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'link') || findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'subtle-link')).forEach(path => {
37
+ const hasSpacingNone = findJSXAttributeWithValue(path.value.openingElement, 'spacing', 'none');
38
+ if (!hasSpacingNone) {
39
+ j(path).find(j.JSXAttribute).filter(path => {
40
+ var _path$node$value;
41
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link');
42
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
43
+ }
44
+ if (hasSpacingNone) {
45
+ const {
46
+ attributes
47
+ } = path.node.openingElement;
48
+ modifyLinkAttributes(path.node, j);
49
+ j(path).find(j.JSXAttribute).filter(attribute => {
50
+ var _attribute$node$value;
51
+ const isIconAttribute = attribute.node.name.name === 'iconBefore' || attribute.node.name.name === 'iconAfter';
52
+ if (((_attribute$node$value = attribute.node.value) === null || _attribute$node$value === void 0 ? void 0 : _attribute$node$value.type) === 'JSXExpressionContainer' && isIconAttribute) {
53
+ moveIconValueFromLinkButtonPropsToLinkChildren(j, path, attribute.node.value, attribute.node.name.name);
54
+ }
55
+ return isIconAttribute;
56
+ }).remove();
57
+ hasLink = true;
58
+ j(path).replaceWith(j.jsxElement.from({
59
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier('Link'), attributes, false),
60
+ closingElement: j.jsxClosingElement(j.jsxIdentifier('Link')),
61
+ children: path.node.children
62
+ }));
63
+ }
64
+ });
65
+
66
+ // add link import and remove link button import if no link button is found
67
+ if (hasLink && linkButtonDeclaration) {
68
+ const linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
69
+ j(linkButtonDeclaration).insertAfter(linkImport);
70
+ const remainingLinkButton = source.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier);
71
+ if (!remainingLinkButton.length) {
72
+ var _value$specifiers;
73
+ j(linkButtonDeclaration).find(j.ImportSpecifier).filter(path => path.node.imported.name === NEW_BUTTON_VARIANTS['link']).remove();
74
+ if (((_value$specifiers = linkButtonDeclaration.value.specifiers) === null || _value$specifiers === void 0 ? void 0 : _value$specifiers.length) === 0) {
75
+ j(linkButtonDeclaration).remove();
76
+ }
77
+ }
78
+ }
79
+ return source.toSource(PRINT_SETTINGS);
80
+ }
81
+ export default transformer;