@atlaskit/codemod-cli 0.25.0 → 0.25.2
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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +111 -0
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +58 -15
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +4 -3
- package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +12 -5
- package/dist/cjs/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +17 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-link-element.js +40 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +19 -2
- package/dist/cjs/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +30 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +95 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +54 -16
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +3 -2
- package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +11 -4
- package/dist/es2019/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +11 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-link-element.js +36 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +18 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +24 -0
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +103 -0
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +58 -16
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +3 -2
- package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +11 -4
- package/dist/esm/presets/migrate-to-new-buttons/utils/find-attribute-with-value.js +11 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-link-element.js +34 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +18 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.js +24 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +10 -3
- package/dist/types/presets/migrate-to-new-buttons/utils/find-attribute-with-value.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +2 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.d.ts +2 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +10 -3
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/find-attribute-with-value.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +2 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +3 -0
- package/package.json +2 -2
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
2
|
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
5
|
+
import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
|
|
6
|
+
import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
|
|
7
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
8
|
+
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
9
|
+
import { generateNewElement, handleIconAttributes, modifyButtonAttributes } from '../utils/generate-new-button-element';
|
|
4
10
|
import getDefaultImports from '../utils/get-default-imports';
|
|
5
11
|
import getSpecifierNames from '../utils/get-specifier-names';
|
|
6
|
-
import { generateNewElement, handleIconAttributes } from '../utils/generate-new-button-element';
|
|
7
12
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
8
13
|
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
9
|
-
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
10
|
-
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
11
14
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
15
|
+
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
16
|
+
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
14
17
|
const transformer = (file, api) => {
|
|
15
18
|
const j = api.jscodeshift;
|
|
16
19
|
const fileSource = j(file.source);
|
|
@@ -40,7 +43,8 @@ const transformer = (file, api) => {
|
|
|
40
43
|
defaultButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.default, NEW_BUTTON_ENTRY_POINT, fileSource, j, true),
|
|
41
44
|
linkButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
42
45
|
iconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
43
|
-
linkIconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, NEW_BUTTON_ENTRY_POINT, fileSource, j)
|
|
46
|
+
linkIconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
47
|
+
link: checkIfVariantAlreadyImported('link', '@atlaskit/link', fileSource, j)
|
|
44
48
|
};
|
|
45
49
|
const oldButtonElements = fileSource.find(j.JSXElement).filter(path => {
|
|
46
50
|
return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
|
|
@@ -59,18 +63,24 @@ const transformer = (file, api) => {
|
|
|
59
63
|
const hasHref = buttonAttributes.includes('href');
|
|
60
64
|
const hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
|
|
61
65
|
const hasNoChildren = ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
|
|
66
|
+
const hasSpacing = attributes.find(attr => {
|
|
67
|
+
var _attr$value;
|
|
68
|
+
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';
|
|
69
|
+
}) || !buttonAttributes.includes('spacing');
|
|
70
|
+
const hasSpacingNone = findJSXAttributeWithValue(element.value.openingElement, 'spacing', 'none');
|
|
62
71
|
const isFitContainerIconButton = hasIcon && hasNoChildren && buttonAttributes.includes('shouldFitContainer');
|
|
63
|
-
const isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
64
|
-
const isLinkButton = hasHref && !isLinkIconButton;
|
|
65
|
-
let isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
66
|
-
const isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton;
|
|
67
|
-
const isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
|
|
68
|
-
const isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
|
|
69
72
|
const linkAppearanceAttribute = attributes.find(node => {
|
|
70
73
|
var _node$value, _node$name, _node$value2, _node$value3;
|
|
71
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 ? 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');
|
|
72
75
|
});
|
|
73
|
-
|
|
76
|
+
const isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
77
|
+
const isLinkButton = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacing;
|
|
78
|
+
const isLink = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacingNone && linkAppearanceAttribute;
|
|
79
|
+
let isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton && !isLink;
|
|
80
|
+
const isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton && !isLink;
|
|
81
|
+
const isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon && !isLink;
|
|
82
|
+
const isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
|
|
83
|
+
if (isDefaultVariantWithAnIcon && !isLink) {
|
|
74
84
|
handleIconAttributes(element.value, j);
|
|
75
85
|
}
|
|
76
86
|
if (isFitContainerIconButton) {
|
|
@@ -88,8 +98,24 @@ const transformer = (file, api) => {
|
|
|
88
98
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
89
99
|
}
|
|
90
100
|
if (isLinkButton && !isLoadingButton) {
|
|
101
|
+
var _element$node$attribu;
|
|
91
102
|
hasVariant.linkButton = true;
|
|
92
103
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
104
|
+
const attribute = (_element$node$attribu = element.node.attributes) === null || _element$node$attribu === void 0 ? void 0 : _element$node$attribu.find(node => node.type === 'JSXAttribute' && node.name.name === 'appearance');
|
|
105
|
+
if (attribute) {
|
|
106
|
+
var _linkAppearanceAttrib;
|
|
107
|
+
if ((linkAppearanceAttribute === null || linkAppearanceAttribute === void 0 ? void 0 : linkAppearanceAttribute.type) === 'JSXAttribute' && ((_linkAppearanceAttrib = linkAppearanceAttribute.value) === null || _linkAppearanceAttrib === void 0 ? void 0 : _linkAppearanceAttrib.type) === 'StringLiteral') {
|
|
108
|
+
if (linkAppearanceAttribute.value.value === 'link') {
|
|
109
|
+
addCommentBefore(j, j(attribute), migrateButtonToSubtleLinkButton, 'line');
|
|
110
|
+
} else if (linkAppearanceAttribute.value.value === 'subtle-link') {
|
|
111
|
+
addCommentBefore(j, j(attribute), migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (isLink && !isLoadingButton) {
|
|
117
|
+
hasVariant.link = true;
|
|
118
|
+
j(element).replaceWith(generateLinkComponent(element.node, j));
|
|
93
119
|
}
|
|
94
120
|
if (isDefaultButton && !isLoadingButton) {
|
|
95
121
|
hasVariant.defaultButton = true;
|
|
@@ -135,7 +161,12 @@ const transformer = (file, api) => {
|
|
|
135
161
|
}), 'block');
|
|
136
162
|
}
|
|
137
163
|
} else if (!hasHref && linkAppearanceAttribute) {
|
|
138
|
-
|
|
164
|
+
var _element$node$attribu2;
|
|
165
|
+
modifyButtonAttributes(element.node, j, hasSpacingNone);
|
|
166
|
+
const attribute = (_element$node$attribu2 = element.node.attributes) === null || _element$node$attribu2 === void 0 ? void 0 : _element$node$attribu2.find(node => node.type === 'JSXAttribute' && node.name.name === 'appearance');
|
|
167
|
+
if (attribute) {
|
|
168
|
+
addCommentBefore(j, j(attribute), hasSpacingNone ? noSpacinglinkButtonMissingHrefComment : linkButtonMissingHrefComment, 'line');
|
|
169
|
+
}
|
|
139
170
|
}
|
|
140
171
|
});
|
|
141
172
|
|
|
@@ -182,6 +213,13 @@ const transformer = (file, api) => {
|
|
|
182
213
|
renameDefaultButtonToLegacyButtonImport(oldButtonImports, oldButtonsWithUnsupportedProps, j);
|
|
183
214
|
}
|
|
184
215
|
}
|
|
216
|
+
if (hasVariant.link) {
|
|
217
|
+
const linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
|
|
218
|
+
oldButtonImports.at(0).insertBefore(linkImport);
|
|
219
|
+
if (!remainingDefaultButtons && !oldButtonsWithUnsupportedProps.length) {
|
|
220
|
+
oldButtonImports.at(0).remove();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
185
223
|
if (specifiers.length) {
|
|
186
224
|
const existingNewButtonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT);
|
|
187
225
|
let newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getImportDeclaration, hasJSXAttributes } from '@hypermod/utils';
|
|
2
2
|
import { PRINT_SETTINGS, NEW_BUTTON_ENTRY_POINT, UNSAFE_SIZE_PROPS_MAP } from '../utils/constants';
|
|
3
|
-
|
|
3
|
+
function transformer(file, api) {
|
|
4
4
|
const j = api.jscodeshift;
|
|
5
5
|
const source = j(file.source);
|
|
6
6
|
|
|
@@ -91,4 +91,5 @@ export default function (file, api) {
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
return source.toSource(PRINT_SETTINGS);
|
|
94
|
-
}
|
|
94
|
+
}
|
|
95
|
+
export default transformer;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import splitImportsTransformer from './codemods/next-split-imports';
|
|
2
2
|
import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
|
|
3
3
|
import removeUnsafeSizeTransformer from './codemods/next-remove-unsafe-size';
|
|
4
|
+
import migrateLinkButtonToLinkTransformer from './codemods/next-migrate-link-button-to-link';
|
|
4
5
|
export default async function transformer(file, api) {
|
|
5
|
-
const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer];
|
|
6
|
+
const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer, migrateLinkButtonToLinkTransformer];
|
|
6
7
|
let src = file.source;
|
|
7
8
|
transformers.forEach(transformer => {
|
|
8
9
|
if (typeof src === 'undefined') {
|
|
@@ -2,7 +2,9 @@ export const PRINT_SETTINGS = {
|
|
|
2
2
|
quote: 'single'
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* NEW button *
|
|
7
|
+
*/
|
|
6
8
|
export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
7
9
|
export const NEW_BUTTON_VARIANTS = {
|
|
8
10
|
default: 'Button',
|
|
@@ -11,7 +13,9 @@ export const NEW_BUTTON_VARIANTS = {
|
|
|
11
13
|
linkIcon: 'LinkIconButton'
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* OLD button *
|
|
18
|
+
*/
|
|
15
19
|
export const OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
16
20
|
export const OLD_BUTTON_VARIANTS = {
|
|
17
21
|
loading: 'LoadingButton'
|
|
@@ -29,7 +33,8 @@ export const UNSAFE_SIZE_PROPS_MAP = {
|
|
|
29
33
|
UNSAFE_iconBefore_size: 'iconBefore'
|
|
30
34
|
};
|
|
31
35
|
export const unsupportedProps = ['component', 'css', 'style'];
|
|
32
|
-
export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are
|
|
36
|
+
export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are not available in the new Button, appearance should be "subtle" or "default".`;
|
|
37
|
+
export const noSpacinglinkButtonMissingHrefComment = `"link" and "subtle-link" appearances are not available in the new Button, appearance should be "subtle" or "default", or provide a href prop then migrate to Link.`;
|
|
33
38
|
export const buttonPropsNoLongerSupportedComment = `Buttons with "component", "css" or "style" prop can't be automatically migrated with codemods. Please migrate it manually.`;
|
|
34
39
|
export const migrateFitContainerButtonToDefaultButtonComment = `Migrated to a default button with text which is from the icon label.`;
|
|
35
40
|
export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
|
|
@@ -40,4 +45,6 @@ export const loadingButtonComment = ({
|
|
|
40
45
|
hasHref
|
|
41
46
|
}) => {
|
|
42
47
|
return `This should be migrated to a new Button with a \`isLoading\` prop. ${hasLinkAppearance ? `"link" and "subtle-link" appearances are not available for new loading buttons."` : ''}${hasHref ? `The \`href\` attribute it not compatible with new loading buttons, because links should not need loading states.` : ''} Please reconsider the design or change the appearance of the button.`;
|
|
43
|
-
};
|
|
48
|
+
};
|
|
49
|
+
export const migrateButtonToSubtleLinkButton = `"link" and "subtle-link" appearances are not available in the new Button. Appearance should be migrated to "subtle" or "default" for Link Button, or use Link with "default" appearance.`;
|
|
50
|
+
export const migrateSubtleButtonToSubtleLinkButton = `"link" and "subtle-link" appearances are not available in the new Button. Appearance should be migrated to "subtle" or "default" for Link Button, or use Link with "subtle" appearance.`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const findJSXAttributeWithValue = (path, attributeName, attributeValue) => {
|
|
2
|
+
var _path$attributes;
|
|
3
|
+
if (!path || path.type === 'JSXSpreadAttribute') {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const attribute = path === null || path === void 0 ? void 0 : (_path$attributes = path.attributes) === null || _path$attributes === void 0 ? void 0 : _path$attributes.find(attribute => {
|
|
7
|
+
var _attribute$value;
|
|
8
|
+
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;
|
|
9
|
+
});
|
|
10
|
+
return Boolean(attribute);
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const modifyLinkAttributes = (element, j) => {
|
|
2
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
3
|
+
var _path$node$value, _path$node$value2;
|
|
4
|
+
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';
|
|
5
|
+
}).remove();
|
|
6
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
7
|
+
var _path$node$value3;
|
|
8
|
+
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';
|
|
9
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
10
|
+
};
|
|
11
|
+
export const generateLinkComponent = (element, j) => {
|
|
12
|
+
const {
|
|
13
|
+
attributes
|
|
14
|
+
} = element.openingElement;
|
|
15
|
+
if (!element.children) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
modifyLinkAttributes(element, j);
|
|
19
|
+
j(element).find(j.JSXAttribute).filter(attribute => {
|
|
20
|
+
var _attribute$node$value;
|
|
21
|
+
const isIconAttribute = attribute.node.name.name === 'iconBefore' || attribute.node.name.name === 'iconAfter';
|
|
22
|
+
if (((_attribute$node$value = attribute.node.value) === null || _attribute$node$value === void 0 ? void 0 : _attribute$node$value.type) === 'JSXExpressionContainer' && isIconAttribute) {
|
|
23
|
+
const iconNode = attribute.node.value;
|
|
24
|
+
if (iconNode && iconNode.type === 'JSXExpressionContainer' && iconNode.expression.type === 'JSXElement' && element.children) {
|
|
25
|
+
const icon = iconNode.expression;
|
|
26
|
+
attribute.node.name.name === 'iconBefore' ? element.children.unshift(icon) : element.children.push(icon);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return isIconAttribute;
|
|
30
|
+
}).remove();
|
|
31
|
+
return j.jsxElement.from({
|
|
32
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier('Link'), attributes, false),
|
|
33
|
+
closingElement: j.jsxClosingElement(j.jsxIdentifier('Link')),
|
|
34
|
+
children: element.children
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -31,7 +31,6 @@ export const handleIconAttributes = (element, j, iconRenamed = false) => {
|
|
|
31
31
|
const {
|
|
32
32
|
attributes: buttonAttributes
|
|
33
33
|
} = element.openingElement;
|
|
34
|
-
|
|
35
34
|
// Get iconBefore and iconAfter attributes
|
|
36
35
|
const buttonIconAttributes = buttonAttributes && getIconAttributes(buttonAttributes);
|
|
37
36
|
buttonIconAttributes === null || buttonIconAttributes === void 0 ? void 0 : buttonIconAttributes.forEach(iconAttribute => {
|
|
@@ -100,6 +99,12 @@ export const generateNewElement = (variant, element, j) => {
|
|
|
100
99
|
} = element.openingElement;
|
|
101
100
|
const iconAttrs = attributes && getIconAttributes(attributes);
|
|
102
101
|
const isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon || variant === NEW_BUTTON_VARIANTS.linkIcon;
|
|
102
|
+
if (variant === NEW_BUTTON_VARIANTS.link) {
|
|
103
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
104
|
+
var _path$node$value;
|
|
105
|
+
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');
|
|
106
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
107
|
+
}
|
|
103
108
|
if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
|
|
104
109
|
handleIconAttributes(element, j, true);
|
|
105
110
|
|
|
@@ -123,4 +128,16 @@ export const generateNewElement = (variant, element, j) => {
|
|
|
123
128
|
closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
|
|
124
129
|
children: element.children
|
|
125
130
|
});
|
|
131
|
+
};
|
|
132
|
+
export const modifyButtonAttributes = (element, j, hasSpacingNone) => {
|
|
133
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
134
|
+
var _path$node$value2;
|
|
135
|
+
return path.node.name.name === 'appearance' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
|
|
136
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
137
|
+
if (hasSpacingNone) {
|
|
138
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
139
|
+
var _path$node$value3;
|
|
140
|
+
return path.node.name.name === 'spacing' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
141
|
+
}).remove();
|
|
142
|
+
}
|
|
126
143
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const moveIcon = (j, path, iconNode, beforeOrAfter) => {
|
|
2
|
+
let element;
|
|
3
|
+
if (!iconNode) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (iconNode.type === 'JSXExpressionContainer') {
|
|
7
|
+
// when iconBefore={(iconProps) => <AddIcon {...iconProps} />}
|
|
8
|
+
if (iconNode.expression.type === 'ArrowFunctionExpression' && iconNode.expression.body.type === 'JSXElement') {
|
|
9
|
+
// remove {...iconProps} spread attribute
|
|
10
|
+
element = iconNode.expression.body;
|
|
11
|
+
j(element).find(j.JSXSpreadAttribute).remove();
|
|
12
|
+
j(element).find(j.JSXAttribute).insertBefore(j.jsxAttribute(j.jsxIdentifier('label'), j.stringLiteral('')));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// when iconBefore={AddIcon}
|
|
16
|
+
if (iconNode.expression.type === 'Identifier') {
|
|
17
|
+
element = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(iconNode.expression.name), [j.jsxAttribute(j.jsxIdentifier('label'), j.stringLiteral(''))], true));
|
|
18
|
+
}
|
|
19
|
+
if (element && path.node.children) {
|
|
20
|
+
beforeOrAfter === 'iconBefore' ? path.node.children.unshift(element) : path.node.children.push(element);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export default moveIcon;
|
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.25.
|
|
301
|
+
_process$env$_PACKAGE = "0.25.2", _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) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
import { getImportDeclaration } from '@hypermod/utils';
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, PRINT_SETTINGS } from '../utils/constants';
|
|
5
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
6
|
+
import { modifyLinkAttributes } from '../utils/generate-link-element';
|
|
7
|
+
import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
|
|
8
|
+
function transformer(file, api) {
|
|
9
|
+
var j = api.jscodeshift;
|
|
10
|
+
var source = j(file.source);
|
|
11
|
+
|
|
12
|
+
// Find all new button imports
|
|
13
|
+
var newButtonImportDeclarations = getImportDeclaration(j, source, NEW_BUTTON_ENTRY_POINT);
|
|
14
|
+
|
|
15
|
+
// No imports for new button found, exit early
|
|
16
|
+
if (!newButtonImportDeclarations.length) {
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
19
|
+
var linkButtonSpecifier = '';
|
|
20
|
+
var linkButtonDeclaration;
|
|
21
|
+
newButtonImportDeclarations.forEach(function (newButtonImport) {
|
|
22
|
+
if (!newButtonImport.value.specifiers) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
newButtonImport.value.specifiers.map(function (specifier) {
|
|
26
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported && specifier.imported.name === NEW_BUTTON_VARIANTS['link']) {
|
|
27
|
+
var _specifier$local;
|
|
28
|
+
linkButtonDeclaration = newButtonImport;
|
|
29
|
+
linkButtonSpecifier = ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || '';
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
if (!linkButtonSpecifier) {
|
|
34
|
+
return source.toSource();
|
|
35
|
+
}
|
|
36
|
+
var hasLink = false;
|
|
37
|
+
var allLinkButtons = source.find(j.JSXElement).filter(function (path) {
|
|
38
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier;
|
|
39
|
+
});
|
|
40
|
+
allLinkButtons.filter(function (path) {
|
|
41
|
+
return findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'link') || findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'subtle-link');
|
|
42
|
+
}).forEach(function (path) {
|
|
43
|
+
var hasSpacingNone = findJSXAttributeWithValue(path.value.openingElement, 'spacing', 'none');
|
|
44
|
+
if (!hasSpacingNone) {
|
|
45
|
+
var oldAppearanceValue;
|
|
46
|
+
j(path).find(j.JSXAttribute).filter(function (path) {
|
|
47
|
+
var _path$node$value;
|
|
48
|
+
if (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')) {
|
|
49
|
+
oldAppearanceValue = path.node.value.value;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
54
|
+
if (oldAppearanceValue) {
|
|
55
|
+
var _path$value$openingEl;
|
|
56
|
+
var attribute = (_path$value$openingEl = path.value.openingElement.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.find(function (node) {
|
|
57
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
58
|
+
});
|
|
59
|
+
if (attribute) {
|
|
60
|
+
addCommentBefore(j, j(attribute), oldAppearanceValue === 'link' ? migrateButtonToSubtleLinkButton : migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (hasSpacingNone) {
|
|
65
|
+
var attributes = path.node.openingElement.attributes;
|
|
66
|
+
modifyLinkAttributes(path.node, j);
|
|
67
|
+
j(path).find(j.JSXAttribute).filter(function (attribute) {
|
|
68
|
+
var _attribute$node$value;
|
|
69
|
+
var isIconAttribute = attribute.node.name.name === 'iconBefore' || attribute.node.name.name === 'iconAfter';
|
|
70
|
+
if (((_attribute$node$value = attribute.node.value) === null || _attribute$node$value === void 0 ? void 0 : _attribute$node$value.type) === 'JSXExpressionContainer' && isIconAttribute) {
|
|
71
|
+
moveIconValueFromLinkButtonPropsToLinkChildren(j, path, attribute.node.value, attribute.node.name.name);
|
|
72
|
+
}
|
|
73
|
+
return isIconAttribute;
|
|
74
|
+
}).remove();
|
|
75
|
+
hasLink = true;
|
|
76
|
+
j(path).replaceWith(j.jsxElement.from({
|
|
77
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier('Link'), attributes, false),
|
|
78
|
+
closingElement: j.jsxClosingElement(j.jsxIdentifier('Link')),
|
|
79
|
+
children: path.node.children
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// add link import and remove link button import if no link button is found
|
|
85
|
+
if (hasLink && linkButtonDeclaration) {
|
|
86
|
+
var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
|
|
87
|
+
j(linkButtonDeclaration).insertAfter(linkImport);
|
|
88
|
+
var remainingLinkButton = source.find(j.JSXElement).filter(function (path) {
|
|
89
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === linkButtonSpecifier;
|
|
90
|
+
});
|
|
91
|
+
if (!remainingLinkButton.length) {
|
|
92
|
+
var _value$specifiers;
|
|
93
|
+
j(linkButtonDeclaration).find(j.ImportSpecifier).filter(function (path) {
|
|
94
|
+
return path.node.imported.name === NEW_BUTTON_VARIANTS['link'];
|
|
95
|
+
}).remove();
|
|
96
|
+
if (((_value$specifiers = linkButtonDeclaration.value.specifiers) === null || _value$specifiers === void 0 ? void 0 : _value$specifiers.length) === 0) {
|
|
97
|
+
j(linkButtonDeclaration).remove();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return source.toSource(PRINT_SETTINGS);
|
|
102
|
+
}
|
|
103
|
+
export default transformer;
|
package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
|
|
2
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
3
3
|
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
5
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
6
|
+
import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
|
|
7
|
+
import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
|
|
8
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
9
|
+
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
10
|
+
import { generateNewElement, handleIconAttributes, modifyButtonAttributes } from '../utils/generate-new-button-element';
|
|
5
11
|
import getDefaultImports from '../utils/get-default-imports';
|
|
6
12
|
import getSpecifierNames from '../utils/get-specifier-names';
|
|
7
|
-
import { generateNewElement, handleIconAttributes } from '../utils/generate-new-button-element';
|
|
8
13
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
9
14
|
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
10
|
-
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
11
|
-
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
12
15
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
16
|
+
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
17
|
+
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
15
18
|
var transformer = function transformer(file, api) {
|
|
16
19
|
var j = api.jscodeshift;
|
|
17
20
|
var fileSource = j(file.source);
|
|
@@ -45,7 +48,8 @@ var transformer = function transformer(file, api) {
|
|
|
45
48
|
defaultButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.default, NEW_BUTTON_ENTRY_POINT, fileSource, j, true),
|
|
46
49
|
linkButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
47
50
|
iconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
48
|
-
linkIconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, NEW_BUTTON_ENTRY_POINT, fileSource, j)
|
|
51
|
+
linkIconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
52
|
+
link: checkIfVariantAlreadyImported('link', '@atlaskit/link', fileSource, j)
|
|
49
53
|
};
|
|
50
54
|
var oldButtonElements = fileSource.find(j.JSXElement).filter(function (path) {
|
|
51
55
|
return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
|
|
@@ -66,18 +70,24 @@ var transformer = function transformer(file, api) {
|
|
|
66
70
|
var hasHref = buttonAttributes.includes('href');
|
|
67
71
|
var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
|
|
68
72
|
var hasNoChildren = ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
|
|
73
|
+
var hasSpacing = attributes.find(function (attr) {
|
|
74
|
+
var _attr$value;
|
|
75
|
+
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';
|
|
76
|
+
}) || !buttonAttributes.includes('spacing');
|
|
77
|
+
var hasSpacingNone = findJSXAttributeWithValue(element.value.openingElement, 'spacing', 'none');
|
|
69
78
|
var isFitContainerIconButton = hasIcon && hasNoChildren && buttonAttributes.includes('shouldFitContainer');
|
|
70
|
-
var isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
71
|
-
var isLinkButton = hasHref && !isLinkIconButton;
|
|
72
|
-
var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
73
|
-
var isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton;
|
|
74
|
-
var isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
|
|
75
|
-
var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
|
|
76
79
|
var linkAppearanceAttribute = attributes.find(function (node) {
|
|
77
80
|
var _node$value, _node$name, _node$value2, _node$value3;
|
|
78
81
|
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');
|
|
79
82
|
});
|
|
80
|
-
|
|
83
|
+
var isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
84
|
+
var isLinkButton = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacing;
|
|
85
|
+
var isLink = hasHref && !isLinkIconButton && !hasNoChildren && hasSpacingNone && linkAppearanceAttribute;
|
|
86
|
+
var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton && !isLink;
|
|
87
|
+
var isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton && !isLink;
|
|
88
|
+
var isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon && !isLink;
|
|
89
|
+
var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
|
|
90
|
+
if (isDefaultVariantWithAnIcon && !isLink) {
|
|
81
91
|
handleIconAttributes(element.value, j);
|
|
82
92
|
}
|
|
83
93
|
if (isFitContainerIconButton) {
|
|
@@ -95,8 +105,26 @@ var transformer = function transformer(file, api) {
|
|
|
95
105
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
96
106
|
}
|
|
97
107
|
if (isLinkButton && !isLoadingButton) {
|
|
108
|
+
var _element$node$attribu;
|
|
98
109
|
hasVariant.linkButton = true;
|
|
99
110
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
111
|
+
var attribute = (_element$node$attribu = element.node.attributes) === null || _element$node$attribu === void 0 ? void 0 : _element$node$attribu.find(function (node) {
|
|
112
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
113
|
+
});
|
|
114
|
+
if (attribute) {
|
|
115
|
+
var _linkAppearanceAttrib;
|
|
116
|
+
if ((linkAppearanceAttribute === null || linkAppearanceAttribute === void 0 ? void 0 : linkAppearanceAttribute.type) === 'JSXAttribute' && ((_linkAppearanceAttrib = linkAppearanceAttribute.value) === null || _linkAppearanceAttrib === void 0 ? void 0 : _linkAppearanceAttrib.type) === 'StringLiteral') {
|
|
117
|
+
if (linkAppearanceAttribute.value.value === 'link') {
|
|
118
|
+
addCommentBefore(j, j(attribute), migrateButtonToSubtleLinkButton, 'line');
|
|
119
|
+
} else if (linkAppearanceAttribute.value.value === 'subtle-link') {
|
|
120
|
+
addCommentBefore(j, j(attribute), migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (isLink && !isLoadingButton) {
|
|
126
|
+
hasVariant.link = true;
|
|
127
|
+
j(element).replaceWith(generateLinkComponent(element.node, j));
|
|
100
128
|
}
|
|
101
129
|
if (isDefaultButton && !isLoadingButton) {
|
|
102
130
|
hasVariant.defaultButton = true;
|
|
@@ -146,7 +174,14 @@ var transformer = function transformer(file, api) {
|
|
|
146
174
|
}), 'block');
|
|
147
175
|
}
|
|
148
176
|
} else if (!hasHref && linkAppearanceAttribute) {
|
|
149
|
-
|
|
177
|
+
var _element$node$attribu2;
|
|
178
|
+
modifyButtonAttributes(element.node, j, hasSpacingNone);
|
|
179
|
+
var _attribute = (_element$node$attribu2 = element.node.attributes) === null || _element$node$attribu2 === void 0 ? void 0 : _element$node$attribu2.find(function (node) {
|
|
180
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
181
|
+
});
|
|
182
|
+
if (_attribute) {
|
|
183
|
+
addCommentBefore(j, j(_attribute), hasSpacingNone ? noSpacinglinkButtonMissingHrefComment : linkButtonMissingHrefComment, 'line');
|
|
184
|
+
}
|
|
150
185
|
}
|
|
151
186
|
});
|
|
152
187
|
|
|
@@ -209,6 +244,13 @@ var transformer = function transformer(file, api) {
|
|
|
209
244
|
renameDefaultButtonToLegacyButtonImport(oldButtonImports, oldButtonsWithUnsupportedProps, j);
|
|
210
245
|
}
|
|
211
246
|
}
|
|
247
|
+
if (hasVariant.link) {
|
|
248
|
+
var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Link'))], j.stringLiteral('@atlaskit/link'));
|
|
249
|
+
oldButtonImports.at(0).insertBefore(linkImport);
|
|
250
|
+
if (!remainingDefaultButtons && !oldButtonsWithUnsupportedProps.length) {
|
|
251
|
+
oldButtonImports.at(0).remove();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
212
254
|
if (specifiers.length) {
|
|
213
255
|
var existingNewButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
214
256
|
return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getImportDeclaration, hasJSXAttributes } from '@hypermod/utils';
|
|
2
2
|
import { PRINT_SETTINGS, NEW_BUTTON_ENTRY_POINT, UNSAFE_SIZE_PROPS_MAP } from '../utils/constants';
|
|
3
|
-
|
|
3
|
+
function transformer(file, api) {
|
|
4
4
|
var j = api.jscodeshift;
|
|
5
5
|
var source = j(file.source);
|
|
6
6
|
|
|
@@ -112,4 +112,5 @@ export default function (file, api) {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
return source.toSource(PRINT_SETTINGS);
|
|
115
|
-
}
|
|
115
|
+
}
|
|
116
|
+
export default transformer;
|
|
@@ -6,6 +6,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
6
6
|
import splitImportsTransformer from './codemods/next-split-imports';
|
|
7
7
|
import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
|
|
8
8
|
import removeUnsafeSizeTransformer from './codemods/next-remove-unsafe-size';
|
|
9
|
+
import migrateLinkButtonToLinkTransformer from './codemods/next-migrate-link-button-to-link';
|
|
9
10
|
export default function transformer(_x, _x2) {
|
|
10
11
|
return _transformer.apply(this, arguments);
|
|
11
12
|
}
|
|
@@ -15,7 +16,7 @@ function _transformer() {
|
|
|
15
16
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
16
17
|
while (1) switch (_context.prev = _context.next) {
|
|
17
18
|
case 0:
|
|
18
|
-
transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer];
|
|
19
|
+
transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer, removeUnsafeSizeTransformer, migrateLinkButtonToLinkTransformer];
|
|
19
20
|
src = file.source;
|
|
20
21
|
transformers.forEach(function (transformer) {
|
|
21
22
|
if (typeof src === 'undefined') {
|
|
@@ -2,7 +2,9 @@ export var PRINT_SETTINGS = {
|
|
|
2
2
|
quote: 'single'
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* NEW button *
|
|
7
|
+
*/
|
|
6
8
|
export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
7
9
|
export var NEW_BUTTON_VARIANTS = {
|
|
8
10
|
default: 'Button',
|
|
@@ -11,7 +13,9 @@ export var NEW_BUTTON_VARIANTS = {
|
|
|
11
13
|
linkIcon: 'LinkIconButton'
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* OLD button *
|
|
18
|
+
*/
|
|
15
19
|
export var OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
16
20
|
export var OLD_BUTTON_VARIANTS = {
|
|
17
21
|
loading: 'LoadingButton'
|
|
@@ -29,7 +33,8 @@ export var UNSAFE_SIZE_PROPS_MAP = {
|
|
|
29
33
|
UNSAFE_iconBefore_size: 'iconBefore'
|
|
30
34
|
};
|
|
31
35
|
export var unsupportedProps = ['component', 'css', 'style'];
|
|
32
|
-
export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are
|
|
36
|
+
export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\".";
|
|
37
|
+
export var noSpacinglinkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\", or provide a href prop then migrate to Link.";
|
|
33
38
|
export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
34
39
|
export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
35
40
|
export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
@@ -39,4 +44,6 @@ export var loadingButtonComment = function loadingButtonComment(_ref) {
|
|
|
39
44
|
var hasLinkAppearance = _ref.hasLinkAppearance,
|
|
40
45
|
hasHref = _ref.hasHref;
|
|
41
46
|
return "This should be migrated to a new Button with a `isLoading` prop. ".concat(hasLinkAppearance ? "\"link\" and \"subtle-link\" appearances are not available for new loading buttons.\"" : '').concat(hasHref ? "The `href` attribute it not compatible with new loading buttons, because links should not need loading states." : '', " Please reconsider the design or change the appearance of the button.");
|
|
42
|
-
};
|
|
47
|
+
};
|
|
48
|
+
export var migrateButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"default\" appearance.";
|
|
49
|
+
export var migrateSubtleButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"subtle\" appearance.";
|