@atlaskit/codemod-cli 0.17.6 → 0.17.8

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 (19) hide show
  1. package/CHANGELOG.md +13 -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 +5 -5
  4. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -1
  5. package/dist/cjs/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +5 -2
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  7. package/dist/cjs/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +10 -38
  8. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -5
  9. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +4 -1
  10. package/dist/es2019/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +5 -2
  11. package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  12. package/dist/es2019/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +9 -36
  13. package/dist/esm/main.js +1 -1
  14. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -5
  15. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -1
  16. package/dist/esm/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +5 -2
  17. package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
  18. package/dist/esm/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +11 -39
  19. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.17.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#62539](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/62539) [`4055341131ca`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4055341131ca) - Update button codemod to add type keywork for type imports
8
+
9
+ ## 0.17.7
10
+
11
+ ### Patch Changes
12
+
13
+ - [#61900](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61900) [`101b5d5ef72a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/101b5d5ef72a) - Small changes in mixin migration - Use `token` instead of `theamed` to avoid migration to depricated code
14
+ - [#62187](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/62187) [`03bb58064010`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/03bb58064010) - Added a small bug-fix in button codemods: add TODO comment on default buttons with "link" or "subtle-link" appearance but without `href`
15
+
3
16
  ## 0.17.6
4
17
 
5
18
  ### 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.6", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.17.8", _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) {
@@ -75,12 +75,12 @@ var transformer = function transformer(file, api) {
75
75
  hasLinkButton = true;
76
76
  j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
77
77
  }
78
- if (!hasHref && attributes.find(function (node) {
78
+ var linkAppearanceAttribute = attributes.find(function (node) {
79
79
  var _node$value, _node$name, _node$value2, _node$value3;
80
- return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' && (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');
81
- })) {
82
- // @ts-ignore
83
- (0, _codemodUtils.addCommentBefore)(j, [element], _constants.linkButtonMissingHrefComment);
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');
81
+ });
82
+ if (!hasHref && linkAppearanceAttribute) {
83
+ (0, _codemodUtils.addCommentBefore)(j, j(linkAppearanceAttribute), _constants.linkButtonMissingHrefComment, 'line');
84
84
  }
85
85
  });
86
86
 
@@ -50,7 +50,8 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
50
50
  attributes === null || attributes === void 0 || attributes.push(labelAttribute);
51
51
  }
52
52
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
53
- return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
53
+ var _attribute$value, _attribute$value2;
54
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
54
55
  });
55
56
  if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
56
57
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
@@ -31,9 +31,12 @@ var importTypesFromNewEntryPoint = exports.importTypesFromNewEntryPoint = functi
31
31
  });
32
32
  if (appearanceAndSpacingTypeSpecifier.length) {
33
33
  appearanceAndSpacingTypeSpecifier.forEach(function (specifier) {
34
- specifiers.push(specifier.node);
35
- j(specifier).remove();
34
+ // @ts-ignore
35
+ specifier.node.importKind = 'type'; // make sure all type imports are prefixed with the `type` keyword
36
+ specifiers.push(specifier.node); // add new Appearance and Spacing types to the new entrypoint
37
+ j(specifier).remove(); // remove old one
36
38
  });
37
39
  }
40
+
38
41
  return specifiers;
39
42
  };
@@ -16,7 +16,7 @@ var migrateFitContainerIconButton = exports.migrateFitContainerIconButton = func
16
16
  return path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby');
17
17
  }));
18
18
  var migratedToIconButton;
19
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'Literal' && typeof labelAttribute.value.value === 'string') {
19
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
20
20
  migratedToIconButton = false;
21
21
  var label = labelAttribute.value.value;
22
22
  var formattedLabel = "".concat(label.charAt(0).toUpperCase()).concat(label.slice(1)).split('-').join(' ');
@@ -16,15 +16,10 @@ function insertTokenImport(j, source) {
16
16
  var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
17
17
  source.get().node.program.body.unshift(newImport);
18
18
  }
19
- function insertThemedImport(j, source) {
20
- if ((0, _utils.hasImportSpecifier)(j, source, 'themed', '@atlaskit/theme/components')) {
21
- return;
22
- }
23
- var newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
24
- source.get().node.program.body.unshift(newImport);
25
- }
26
- function buildToken(j, tokenId, node) {
27
- var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
19
+ function buildToken(j) {
20
+ var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
21
+ var node = arguments.length > 2 ? arguments[2] : undefined;
22
+ var callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
28
23
  return callExpr;
29
24
  }
30
25
  function isDecendantOfTokenMethod(j, path) {
@@ -37,12 +32,6 @@ function isDecendantOfTokenMethod(j, path) {
37
32
  var isDeprecatedApi = function isDeprecatedApi(identifierName) {
38
33
  return Object.keys(_replacements.colorReplacements).includes(identifierName);
39
34
  };
40
- function buildThemedNode(j) {
41
- var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
42
- var fallbackLight = arguments.length > 2 ? arguments[2] : undefined;
43
- var fallbackDark = arguments.length > 3 ? arguments[3] : undefined;
44
- return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
45
- }
46
35
  function replaceIdentifiers(j, source, specifier) {
47
36
  var importSpecifierLocal = specifier.value.local.name;
48
37
  var importSpecifierImported = specifier.value.imported.name;
@@ -67,22 +56,13 @@ function replaceIdentifiers(j, source, specifier) {
67
56
  var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
68
57
  insertTokenImport(j, source);
69
58
  (0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
70
-
71
- // Requires themed function
72
59
  if (isDynamicReplacement) {
73
- var themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
74
- insertThemedImport(j, source);
75
- (0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
76
- if (isDecendantOfToken && isDecendantOfCallExpression) {
77
- var callExpression = identifier.parent;
78
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
79
- return;
80
- }
60
+ var token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
81
61
  if (isDecendantOfToken) {
82
- tokenParentNode.replace(themedNode);
62
+ tokenParentNode.replace(token);
83
63
  return;
84
64
  }
85
- identifier.replace(themedNode);
65
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
86
66
  return;
87
67
  }
88
68
  if (!isDecendantOfToken && replacement.tokenId) {
@@ -115,21 +95,13 @@ function replaceMemberExpressions(j, source, specifier) {
115
95
  }).get();
116
96
  var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
117
97
  insertTokenImport(j, source);
118
-
119
- // Requires themed function
120
98
  if (isDynamicReplacement) {
121
- var themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
122
- insertThemedImport(j, source);
123
- if (isDecendantOfToken && isDecendantOfCallExpression) {
124
- var callExpression = identifier.parent.parent;
125
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
126
- return;
127
- }
99
+ var token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
128
100
  if (isDecendantOfToken) {
129
- tokenParentNode.replace(themedNode);
101
+ tokenParentNode.replace(token);
130
102
  return;
131
103
  }
132
- memberExpression.replace(themedNode);
104
+ (isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
133
105
  return;
134
106
  }
135
107
  if (!isDecendantOfToken && replacement.tokenId) {
@@ -61,12 +61,12 @@ const transformer = (file, api) => {
61
61
  hasLinkButton = true;
62
62
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
63
63
  }
64
- if (!hasHref && attributes.find(node => {
64
+ const linkAppearanceAttribute = attributes.find(node => {
65
65
  var _node$value, _node$name, _node$value2, _node$value3;
66
- return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' && (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');
67
- })) {
68
- // @ts-ignore
69
- addCommentBefore(j, [element], linkButtonMissingHrefComment);
66
+ 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');
67
+ });
68
+ if (!hasHref && linkAppearanceAttribute) {
69
+ addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
70
70
  }
71
71
  });
72
72
 
@@ -38,7 +38,10 @@ export const moveSizeAndLabelAttributes = (element, j, iconRenamed = false) => {
38
38
  if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
39
39
  attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
40
40
  }
41
- const sizeAttribute = iconJSXElementAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'size');
41
+ const sizeAttribute = iconJSXElementAttributes.find(attribute => {
42
+ var _attribute$value, _attribute$value2;
43
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
44
+ });
42
45
  if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
43
46
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : `UNSAFE_${iconAttr.name.name}_size`;
44
47
  attributes === null || attributes === void 0 ? void 0 : attributes.push(sizeAttribute);
@@ -19,9 +19,12 @@ export const importTypesFromNewEntryPoint = (buttonImports, specifiers, j, fileS
19
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
20
  if (appearanceAndSpacingTypeSpecifier.length) {
21
21
  appearanceAndSpacingTypeSpecifier.forEach(specifier => {
22
- specifiers.push(specifier.node);
23
- j(specifier).remove();
22
+ // @ts-ignore
23
+ specifier.node.importKind = 'type'; // make sure all type imports are prefixed with the `type` keyword
24
+ specifiers.push(specifier.node); // add new Appearance and Spacing types to the new entrypoint
25
+ j(specifier).remove(); // remove old one
24
26
  });
25
27
  }
28
+
26
29
  return specifiers;
27
30
  };
@@ -10,7 +10,7 @@ export const migrateFitContainerIconButton = (element, j) => {
10
10
  const iconElement = iconAttrs && iconAttrs[0] && getIconElement(iconAttrs[0]);
11
11
  const labelAttribute = iconElement && Array.isArray(iconElement.openingElement.attributes) && ((_iconElement$openingE = iconElement.openingElement) === null || _iconElement$openingE === void 0 ? void 0 : _iconElement$openingE.attributes.find(path => path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby')));
12
12
  let migratedToIconButton;
13
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'Literal' && typeof labelAttribute.value.value === 'string') {
13
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
14
14
  migratedToIconButton = false;
15
15
  const label = labelAttribute.value.value;
16
16
  const formattedLabel = `${label.charAt(0).toUpperCase()}${label.slice(1)}`.split('-').join(' ');
@@ -1,4 +1,4 @@
1
- import { hasImportDeclaration, hasImportSpecifier, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
1
+ import { hasImportDeclaration, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
2
2
  import { colorReplacements } from './utils/replacements';
3
3
  function isDecendantOfType(j, path, type) {
4
4
  return j(path).closest(type).length > 0;
@@ -10,15 +10,8 @@ function insertTokenImport(j, source) {
10
10
  const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
11
11
  source.get().node.program.body.unshift(newImport);
12
12
  }
13
- function insertThemedImport(j, source) {
14
- if (hasImportSpecifier(j, source, 'themed', '@atlaskit/theme/components')) {
15
- return;
16
- }
17
- const newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
18
- source.get().node.program.body.unshift(newImport);
19
- }
20
- function buildToken(j, tokenId, node) {
21
- const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
13
+ function buildToken(j, tokenId = '', node) {
14
+ const callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
22
15
  return callExpr;
23
16
  }
24
17
  function isDecendantOfTokenMethod(j, path) {
@@ -29,9 +22,6 @@ function isDecendantOfTokenMethod(j, path) {
29
22
  }).length > 0;
30
23
  }
31
24
  const isDeprecatedApi = identifierName => Object.keys(colorReplacements).includes(identifierName);
32
- function buildThemedNode(j, tokenId = '', fallbackLight, fallbackDark) {
33
- return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
34
- }
35
25
  function replaceIdentifiers(j, source, specifier) {
36
26
  const importSpecifierLocal = specifier.value.local.name;
37
27
  const importSpecifierImported = specifier.value.imported.name;
@@ -50,22 +40,13 @@ function replaceIdentifiers(j, source, specifier) {
50
40
  const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
51
41
  insertTokenImport(j, source);
52
42
  insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
53
-
54
- // Requires themed function
55
43
  if (isDynamicReplacement) {
56
- const themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
57
- insertThemedImport(j, source);
58
- insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
59
- if (isDecendantOfToken && isDecendantOfCallExpression) {
60
- const callExpression = identifier.parent;
61
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
62
- return;
63
- }
44
+ const token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
64
45
  if (isDecendantOfToken) {
65
- tokenParentNode.replace(themedNode);
46
+ tokenParentNode.replace(token);
66
47
  return;
67
48
  }
68
- identifier.replace(themedNode);
49
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
69
50
  return;
70
51
  }
71
52
  if (!isDecendantOfToken && replacement.tokenId) {
@@ -96,21 +77,13 @@ function replaceMemberExpressions(j, source, specifier) {
96
77
  }).get();
97
78
  const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
98
79
  insertTokenImport(j, source);
99
-
100
- // Requires themed function
101
80
  if (isDynamicReplacement) {
102
- const themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
103
- insertThemedImport(j, source);
104
- if (isDecendantOfToken && isDecendantOfCallExpression) {
105
- const callExpression = identifier.parent.parent;
106
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
107
- return;
108
- }
81
+ const token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
109
82
  if (isDecendantOfToken) {
110
- tokenParentNode.replace(themedNode);
83
+ tokenParentNode.replace(token);
111
84
  return;
112
85
  }
113
- memberExpression.replace(themedNode);
86
+ (isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
114
87
  return;
115
88
  }
116
89
  if (!isDecendantOfToken && replacement.tokenId) {
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.6", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.17.8", _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) {
@@ -69,12 +69,12 @@ var transformer = function transformer(file, api) {
69
69
  hasLinkButton = true;
70
70
  j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
71
71
  }
72
- if (!hasHref && attributes.find(function (node) {
72
+ var linkAppearanceAttribute = attributes.find(function (node) {
73
73
  var _node$value, _node$name, _node$value2, _node$value3;
74
- return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' && (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');
75
- })) {
76
- // @ts-ignore
77
- addCommentBefore(j, [element], linkButtonMissingHrefComment);
74
+ 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');
75
+ });
76
+ if (!hasHref && linkAppearanceAttribute) {
77
+ addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
78
78
  }
79
79
  });
80
80
 
@@ -44,7 +44,8 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
44
44
  attributes === null || attributes === void 0 || attributes.push(labelAttribute);
45
45
  }
46
46
  var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
47
- return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
47
+ var _attribute$value, _attribute$value2;
48
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
48
49
  });
49
50
  if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
50
51
  sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
@@ -25,9 +25,12 @@ export var importTypesFromNewEntryPoint = function importTypesFromNewEntryPoint(
25
25
  });
26
26
  if (appearanceAndSpacingTypeSpecifier.length) {
27
27
  appearanceAndSpacingTypeSpecifier.forEach(function (specifier) {
28
- specifiers.push(specifier.node);
29
- j(specifier).remove();
28
+ // @ts-ignore
29
+ specifier.node.importKind = 'type'; // make sure all type imports are prefixed with the `type` keyword
30
+ specifiers.push(specifier.node); // add new Appearance and Spacing types to the new entrypoint
31
+ j(specifier).remove(); // remove old one
30
32
  });
31
33
  }
34
+
32
35
  return specifiers;
33
36
  };
@@ -10,7 +10,7 @@ export var migrateFitContainerIconButton = function migrateFitContainerIconButto
10
10
  return path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby');
11
11
  }));
12
12
  var migratedToIconButton;
13
- if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'Literal' && typeof labelAttribute.value.value === 'string') {
13
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
14
14
  migratedToIconButton = false;
15
15
  var label = labelAttribute.value.value;
16
16
  var formattedLabel = "".concat(label.charAt(0).toUpperCase()).concat(label.slice(1)).split('-').join(' ');
@@ -1,4 +1,4 @@
1
- import { hasImportDeclaration, hasImportSpecifier, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
1
+ import { hasImportDeclaration, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
2
2
  import { colorReplacements } from './utils/replacements';
3
3
  function isDecendantOfType(j, path, type) {
4
4
  return j(path).closest(type).length > 0;
@@ -10,15 +10,10 @@ function insertTokenImport(j, source) {
10
10
  var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
11
11
  source.get().node.program.body.unshift(newImport);
12
12
  }
13
- function insertThemedImport(j, source) {
14
- if (hasImportSpecifier(j, source, 'themed', '@atlaskit/theme/components')) {
15
- return;
16
- }
17
- var newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
18
- source.get().node.program.body.unshift(newImport);
19
- }
20
- function buildToken(j, tokenId, node) {
21
- var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
13
+ function buildToken(j) {
14
+ var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
15
+ var node = arguments.length > 2 ? arguments[2] : undefined;
16
+ var callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
22
17
  return callExpr;
23
18
  }
24
19
  function isDecendantOfTokenMethod(j, path) {
@@ -31,12 +26,6 @@ function isDecendantOfTokenMethod(j, path) {
31
26
  var isDeprecatedApi = function isDeprecatedApi(identifierName) {
32
27
  return Object.keys(colorReplacements).includes(identifierName);
33
28
  };
34
- function buildThemedNode(j) {
35
- var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
36
- var fallbackLight = arguments.length > 2 ? arguments[2] : undefined;
37
- var fallbackDark = arguments.length > 3 ? arguments[3] : undefined;
38
- return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
39
- }
40
29
  function replaceIdentifiers(j, source, specifier) {
41
30
  var importSpecifierLocal = specifier.value.local.name;
42
31
  var importSpecifierImported = specifier.value.imported.name;
@@ -61,22 +50,13 @@ function replaceIdentifiers(j, source, specifier) {
61
50
  var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
62
51
  insertTokenImport(j, source);
63
52
  insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
64
-
65
- // Requires themed function
66
53
  if (isDynamicReplacement) {
67
- var themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
68
- insertThemedImport(j, source);
69
- insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
70
- if (isDecendantOfToken && isDecendantOfCallExpression) {
71
- var callExpression = identifier.parent;
72
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
73
- return;
74
- }
54
+ var token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
75
55
  if (isDecendantOfToken) {
76
- tokenParentNode.replace(themedNode);
56
+ tokenParentNode.replace(token);
77
57
  return;
78
58
  }
79
- identifier.replace(themedNode);
59
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
80
60
  return;
81
61
  }
82
62
  if (!isDecendantOfToken && replacement.tokenId) {
@@ -109,21 +89,13 @@ function replaceMemberExpressions(j, source, specifier) {
109
89
  }).get();
110
90
  var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
111
91
  insertTokenImport(j, source);
112
-
113
- // Requires themed function
114
92
  if (isDynamicReplacement) {
115
- var themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
116
- insertThemedImport(j, source);
117
- if (isDecendantOfToken && isDecendantOfCallExpression) {
118
- var callExpression = identifier.parent.parent;
119
- tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
120
- return;
121
- }
93
+ var token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
122
94
  if (isDecendantOfToken) {
123
- tokenParentNode.replace(themedNode);
95
+ tokenParentNode.replace(token);
124
96
  return;
125
97
  }
126
- memberExpression.replace(themedNode);
98
+ (isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
127
99
  return;
128
100
  }
129
101
  if (!isDecendantOfToken && replacement.tokenId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.17.6",
3
+ "version": "0.17.8",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"