@atlaskit/codemod-cli 0.24.2 → 0.24.4
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 +338 -323
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +154 -56
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +18 -4
- package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +16 -3
- package/dist/cjs/presets/migrate-to-new-buttons/utils/get-default-imports.js +14 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/get-specifier-names.js +14 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/if-variant-already-imported.js +15 -7
- package/dist/cjs/presets/migrate-to-new-buttons/utils/rename-elements.js +18 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +143 -52
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +18 -4
- package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +16 -2
- package/dist/es2019/presets/migrate-to-new-buttons/utils/get-default-imports.js +6 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/get-specifier-names.js +6 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/if-variant-already-imported.js +9 -3
- package/dist/es2019/presets/migrate-to-new-buttons/utils/rename-elements.js +12 -0
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +154 -57
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +18 -4
- package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +15 -2
- package/dist/esm/presets/migrate-to-new-buttons/utils/get-default-imports.js +8 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/get-specifier-names.js +8 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/if-variant-already-imported.js +14 -6
- package/dist/esm/presets/migrate-to-new-buttons/utils/rename-elements.js +12 -0
- package/dist/types/main.d.ts +1 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +11 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/get-default-imports.d.ts +5 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/get-specifier-names.d.ts +5 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/if-variant-already-imported.d.ts +2 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.d.ts +1 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/rename-elements.d.ts +2 -0
- package/dist/types/presets/styled-to-emotion/styled-to-emotion.d.ts +1 -1
- package/dist/types/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.d.ts +1 -1
- package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +1 -1
- package/dist/types/sinceRef.d.ts +1 -1
- package/dist/types/transforms.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/main.d.ts +1 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +11 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-default-imports.d.ts +5 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-specifier-names.d.ts +5 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/if-variant-already-imported.d.ts +2 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.d.ts +1 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/rename-elements.d.ts +2 -0
- package/dist/types-ts4.5/presets/styled-to-emotion/styled-to-emotion.d.ts +1 -1
- package/dist/types-ts4.5/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.d.ts +1 -1
- package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +1 -1
- package/dist/types-ts4.5/sinceRef.d.ts +1 -1
- package/dist/types-ts4.5/transforms.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +2 -4
package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
2
3
|
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
3
|
-
import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps } from '../utils/constants';
|
|
4
|
+
import { PRINT_SETTINGS, OLD_BUTTON_VARIANTS, NEW_BUTTON_VARIANTS, entryPointsMapping, OLD_BUTTON_ENTRY_POINT, NEW_BUTTON_ENTRY_POINT, linkButtonMissingHrefComment, buttonPropsNoLongerSupportedComment, unsupportedProps, loadingButtonComment } from '../utils/constants';
|
|
5
|
+
import getDefaultImports from '../utils/get-default-imports';
|
|
6
|
+
import getSpecifierNames from '../utils/get-specifier-names';
|
|
4
7
|
import { generateNewElement, handleIconAttributes } from '../utils/generate-new-button-element';
|
|
5
8
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
6
9
|
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
@@ -12,31 +15,44 @@ var transformer = function transformer(file, api) {
|
|
|
12
15
|
var j = api.jscodeshift;
|
|
13
16
|
var fileSource = j(file.source);
|
|
14
17
|
addCommentForCustomThemeButtons(fileSource, j);
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
// Find old buttons
|
|
20
|
+
var oldButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
21
|
+
return path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === OLD_BUTTON_ENTRY_POINT;
|
|
17
22
|
});
|
|
18
|
-
if (!
|
|
23
|
+
if (!oldButtonImports.length) {
|
|
19
24
|
return fileSource.toSource();
|
|
20
25
|
}
|
|
21
|
-
var
|
|
22
|
-
|
|
26
|
+
var oldDefaultDefaultImports = getDefaultImports(oldButtonImports, j);
|
|
27
|
+
var oldDefaultImportSpecifiers = getSpecifierNames(oldDefaultDefaultImports);
|
|
28
|
+
|
|
29
|
+
// Find new buttons
|
|
30
|
+
var newButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
31
|
+
return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
|
|
23
32
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
var newDefaultDefaultImports = getDefaultImports(newButtonImports, j);
|
|
34
|
+
var newDefaultImportSpecifiers = getSpecifierNames(newDefaultDefaultImports);
|
|
35
|
+
var loadingButtonDirectImportName = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.LoadingButton);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Which variants should be in this file?
|
|
39
|
+
*
|
|
40
|
+
* Any variants enabled here will be added to the final import statement.
|
|
41
|
+
* Initial values check if the variant is already imported in the file.
|
|
42
|
+
*/
|
|
43
|
+
var hasVariant = {
|
|
44
|
+
defaultButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.default, NEW_BUTTON_ENTRY_POINT, fileSource, j, true),
|
|
45
|
+
linkButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
46
|
+
iconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon, NEW_BUTTON_ENTRY_POINT, fileSource, j),
|
|
47
|
+
linkIconButton: checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon, NEW_BUTTON_ENTRY_POINT, fileSource, j)
|
|
48
|
+
};
|
|
49
|
+
var oldButtonElements = fileSource.find(j.JSXElement).filter(function (path) {
|
|
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));
|
|
34
51
|
});
|
|
35
|
-
var
|
|
52
|
+
var oldButtonsWithoutUnsupportedProps = oldButtonElements.filter(function (path) {
|
|
36
53
|
return !ifHasUnsupportedProps(path.value.openingElement.attributes);
|
|
37
54
|
});
|
|
38
|
-
|
|
39
|
-
buttonsWithoutUnsupportedProps.forEach(function (element) {
|
|
55
|
+
oldButtonsWithoutUnsupportedProps.forEach(function (element) {
|
|
40
56
|
var _element$value$childr;
|
|
41
57
|
var attributes = element.value.openingElement.attributes;
|
|
42
58
|
if (!attributes) {
|
|
@@ -52,9 +68,14 @@ var transformer = function transformer(file, api) {
|
|
|
52
68
|
var isLinkIconButton = hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
53
69
|
var isLinkButton = hasHref && !isLinkIconButton;
|
|
54
70
|
var isIconButton = !hasHref && hasIcon && hasNoChildren && !isFitContainerIconButton;
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
|
|
71
|
+
var isDefaultButton = !isLinkButton && !isLinkIconButton && !isIconButton && !isFitContainerIconButton;
|
|
72
|
+
var isDefaultVariantWithAnIcon = !isLinkIconButton && !isIconButton && !isFitContainerIconButton && hasIcon;
|
|
73
|
+
var isLoadingButton = element.value.openingElement.name.type === 'JSXIdentifier' && element.value.openingElement.name.name === loadingButtonDirectImportName;
|
|
74
|
+
var linkAppearanceAttribute = attributes.find(function (node) {
|
|
75
|
+
var _node$value, _node$name, _node$value2, _node$value3;
|
|
76
|
+
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');
|
|
77
|
+
});
|
|
78
|
+
if (isDefaultVariantWithAnIcon) {
|
|
58
79
|
handleIconAttributes(element.value, j);
|
|
59
80
|
}
|
|
60
81
|
if (isFitContainerIconButton) {
|
|
@@ -63,78 +84,113 @@ var transformer = function transformer(file, api) {
|
|
|
63
84
|
isIconButton = true;
|
|
64
85
|
}
|
|
65
86
|
}
|
|
66
|
-
if (isLinkIconButton) {
|
|
67
|
-
|
|
87
|
+
if (isLinkIconButton && !isLoadingButton) {
|
|
88
|
+
hasVariant.linkIconButton = true;
|
|
68
89
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon, element.value, j));
|
|
69
90
|
}
|
|
70
|
-
if (isIconButton) {
|
|
71
|
-
|
|
91
|
+
if (isIconButton && !isLoadingButton) {
|
|
92
|
+
hasVariant.iconButton = true;
|
|
72
93
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
73
94
|
}
|
|
74
|
-
if (isLinkButton) {
|
|
75
|
-
|
|
95
|
+
if (isLinkButton && !isLoadingButton) {
|
|
96
|
+
hasVariant.linkButton = true;
|
|
76
97
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
77
98
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
j(element).replaceWith(generateNewElement(
|
|
99
|
+
if (isDefaultButton && !isLoadingButton) {
|
|
100
|
+
hasVariant.defaultButton = true;
|
|
101
|
+
j(element).replaceWith(generateNewElement(newDefaultImportSpecifiers !== null && newDefaultImportSpecifiers !== void 0 && newDefaultImportSpecifiers.length ?
|
|
102
|
+
// If new button already has a default import, use that incase it's aliased
|
|
103
|
+
newDefaultImportSpecifiers[0] : NEW_BUTTON_VARIANTS.default, element.value, j));
|
|
81
104
|
}
|
|
82
|
-
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
if (isLoadingButton) {
|
|
106
|
+
var newElement = generateNewElement(NEW_BUTTON_VARIANTS[isIconButton || isLinkIconButton ? 'icon' : 'default'], element.value, j);
|
|
107
|
+
if (isIconButton || isLinkIconButton) {
|
|
108
|
+
hasVariant.iconButton = true;
|
|
109
|
+
} else {
|
|
110
|
+
hasVariant.defaultButton = true;
|
|
111
|
+
|
|
112
|
+
// rename existing Button to LegacyButton
|
|
113
|
+
var existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(function (path) {
|
|
114
|
+
var _path$value$local;
|
|
115
|
+
return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === NEW_BUTTON_VARIANTS.default;
|
|
116
|
+
});
|
|
117
|
+
if (existingDefaultButtonSpecifier.length > 0) {
|
|
118
|
+
fileSource.find(j.JSXElement).filter(function (path) {
|
|
119
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === NEW_BUTTON_VARIANTS.default;
|
|
120
|
+
}).forEach(function (element) {
|
|
121
|
+
var _element$value$childr2, _element$value$childr3;
|
|
122
|
+
// find all default <Button> JSX elements and replace with <LegacyButton>
|
|
123
|
+
j(element).replaceWith(j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('LegacyButton'), element.value.openingElement.attributes, ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0), ((_element$value$childr3 = element.value.children) === null || _element$value$childr3 === void 0 ? void 0 : _element$value$childr3.length) === 0 ? null : j.jsxClosingElement(j.jsxIdentifier('LegacyButton')), element.value.children));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
|
|
127
|
+
fileSource.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
|
|
128
|
+
if (path.node.name === NEW_BUTTON_VARIANTS.default) {
|
|
129
|
+
path.node.name = 'LegacyButton';
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// rename Button to LegacyButton in import declaration
|
|
134
|
+
existingDefaultButtonSpecifier.forEach(function (specifier) {
|
|
135
|
+
return j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton')));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
j(element).replaceWith(newElement);
|
|
140
|
+
if (hasHref || linkAppearanceAttribute) {
|
|
141
|
+
addCommentBefore(j, j(newElement), loadingButtonComment({
|
|
142
|
+
hasHref: hasHref,
|
|
143
|
+
hasLinkAppearance: Boolean(linkAppearanceAttribute)
|
|
144
|
+
}), 'block');
|
|
145
|
+
}
|
|
146
|
+
} else if (!hasHref && linkAppearanceAttribute) {
|
|
87
147
|
addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
|
|
88
148
|
}
|
|
89
149
|
});
|
|
90
150
|
|
|
91
151
|
// modify import declarations
|
|
92
152
|
var specifiers = [];
|
|
93
|
-
[
|
|
153
|
+
[hasVariant.linkButton ? 'link' : null, hasVariant.iconButton ? 'icon' : null, hasVariant.linkIconButton ? 'linkIcon' : null].forEach(function (variant) {
|
|
94
154
|
if (variant) {
|
|
95
155
|
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
|
|
96
156
|
}
|
|
97
157
|
});
|
|
98
|
-
var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
99
|
-
return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton;
|
|
100
|
-
});
|
|
101
158
|
var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
|
|
102
|
-
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name
|
|
159
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && Boolean(oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) && !ifHasUnsupportedProps(path.value.openingElement.attributes);
|
|
103
160
|
}).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
|
|
104
161
|
return path.node.arguments.map(function (argument) {
|
|
105
162
|
return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
|
|
106
|
-
}).
|
|
163
|
+
}).some(function (name) {
|
|
164
|
+
return name && (oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(name));
|
|
165
|
+
});
|
|
107
166
|
}).length > 0;
|
|
108
167
|
|
|
109
168
|
// Loading buttons map back to default imports
|
|
110
|
-
if (
|
|
169
|
+
if (loadingButtonDirectImportName && oldDefaultImportSpecifiers !== null && oldDefaultImportSpecifiers !== void 0 && oldDefaultImportSpecifiers.includes(loadingButtonDirectImportName)) {
|
|
111
170
|
fileSource
|
|
112
171
|
// rename LoadingButton to Button in all call expressions i.e. render(LoadingButton), find(LoadingButton)
|
|
113
172
|
.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
|
|
114
|
-
if (path.node.name ===
|
|
173
|
+
if (path.node.name === loadingButtonDirectImportName) {
|
|
115
174
|
path.node.name = NEW_BUTTON_VARIANTS.default;
|
|
116
175
|
}
|
|
117
176
|
});
|
|
118
|
-
|
|
119
|
-
// Only add the Button import if we found a default button, not icon only
|
|
120
|
-
if (hasDefaultLoadingButton) {
|
|
121
|
-
specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
|
|
122
|
-
}
|
|
123
177
|
}
|
|
124
|
-
|
|
178
|
+
|
|
179
|
+
// Only add the Button import if we found a default button, not icon only
|
|
180
|
+
if (hasVariant.defaultButton || !specifiers.find(function (specifier) {
|
|
125
181
|
return specifier.type === 'ImportDefaultSpecifier';
|
|
126
182
|
}) && remainingDefaultButtons) {
|
|
127
183
|
specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
|
|
128
184
|
}
|
|
129
185
|
|
|
130
186
|
// update import path for types imports
|
|
131
|
-
specifiers = importTypesFromNewEntryPoint(
|
|
132
|
-
var
|
|
187
|
+
specifiers = importTypesFromNewEntryPoint(oldButtonImports, specifiers, j, fileSource);
|
|
188
|
+
var oldButtonsWithUnsupportedProps = oldButtonElements.filter(function (path) {
|
|
133
189
|
return ifHasUnsupportedProps(path.value.openingElement.attributes);
|
|
134
190
|
});
|
|
135
|
-
if (
|
|
191
|
+
if (oldButtonsWithUnsupportedProps.length) {
|
|
136
192
|
// add comment to all buttons with unsupported props: "component", "style", "css"
|
|
137
|
-
|
|
193
|
+
oldButtonsWithUnsupportedProps.forEach(function (element) {
|
|
138
194
|
var _element$value$openin;
|
|
139
195
|
var attribute = (_element$value$openin = element.value.openingElement.attributes) === null || _element$value$openin === void 0 ? void 0 : _element$value$openin.find(function (node) {
|
|
140
196
|
return node.type === 'JSXAttribute' && typeof node.name.name === 'string' && unsupportedProps.includes(node.name.name);
|
|
@@ -148,22 +204,63 @@ var transformer = function transformer(file, api) {
|
|
|
148
204
|
if (specifiers.find(function (specifier) {
|
|
149
205
|
return specifier.type === 'ImportDefaultSpecifier';
|
|
150
206
|
})) {
|
|
151
|
-
renameDefaultButtonToLegacyButtonImport(
|
|
207
|
+
renameDefaultButtonToLegacyButtonImport(oldButtonImports, oldButtonsWithUnsupportedProps, j);
|
|
152
208
|
}
|
|
153
209
|
}
|
|
154
210
|
if (specifiers.length) {
|
|
211
|
+
var existingNewButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
212
|
+
return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
|
|
213
|
+
});
|
|
155
214
|
var newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
|
|
156
|
-
|
|
215
|
+
oldButtonImports.forEach(function (path) {
|
|
157
216
|
var _path$node;
|
|
158
217
|
newButtonImport.comments = path !== null && path !== void 0 && (_path$node = path.node) !== null && _path$node !== void 0 && _path$node.comments ? path.node.comments : undefined;
|
|
159
218
|
});
|
|
160
|
-
|
|
219
|
+
if (existingNewButtonImports.length) {
|
|
220
|
+
existingNewButtonImports.forEach(function (path) {
|
|
221
|
+
// Merge specifiers from existing new button import with added specifiers
|
|
222
|
+
var mergedSpecifiers = [].concat(_toConsumableArray(specifiers.filter(function (specifier) {
|
|
223
|
+
var _path$node$specifiers;
|
|
224
|
+
if (specifier.type !== 'ImportDefaultSpecifier') {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Ensure we don't add a duplicate default specifier if one is already imported
|
|
229
|
+
return !((_path$node$specifiers = path.node.specifiers) !== null && _path$node$specifiers !== void 0 && _path$node$specifiers.find(function (s) {
|
|
230
|
+
return s.type === 'ImportDefaultSpecifier';
|
|
231
|
+
}));
|
|
232
|
+
})), _toConsumableArray(path.node.specifiers ? path.node.specifiers : [])) // Filter duplicates
|
|
233
|
+
.filter(function (specifier) {
|
|
234
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
var isAlreadyImported = specifiers.find(function (s) {
|
|
238
|
+
var _specifier$local;
|
|
239
|
+
return s.type === 'ImportSpecifier' && s.imported.name === ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name);
|
|
240
|
+
});
|
|
241
|
+
return !isAlreadyImported;
|
|
242
|
+
});
|
|
243
|
+
newButtonImport = j.importDeclaration(mergedSpecifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
|
|
244
|
+
});
|
|
245
|
+
oldButtonImports.remove();
|
|
246
|
+
existingNewButtonImports.replaceWith(newButtonImport);
|
|
247
|
+
} else {
|
|
248
|
+
oldButtonImports.replaceWith(function (_, index) {
|
|
249
|
+
// Only replace the first import
|
|
250
|
+
if (index === 0) {
|
|
251
|
+
return newButtonImport;
|
|
252
|
+
}
|
|
253
|
+
// Remove the rest
|
|
254
|
+
return null;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
161
257
|
}
|
|
162
258
|
|
|
163
259
|
// remove empty import declarations
|
|
164
260
|
fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
165
261
|
return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
|
|
166
262
|
}).remove();
|
|
263
|
+
addCommentForCustomThemeButtons(fileSource, j);
|
|
167
264
|
return fileSource.toSource(PRINT_SETTINGS);
|
|
168
265
|
};
|
|
169
266
|
export default transformer;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
|
|
3
|
+
import renameElements from '../utils/rename-elements';
|
|
4
|
+
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
3
5
|
var transformer = function transformer(file, api) {
|
|
4
6
|
var j = api.jscodeshift;
|
|
5
7
|
var fileSource = j(file.source);
|
|
@@ -25,8 +27,14 @@ var transformer = function transformer(file, api) {
|
|
|
25
27
|
return specifier.type === 'ImportDefaultSpecifier';
|
|
26
28
|
});
|
|
27
29
|
if (defaultSpecifier && defaultSpecifier.local) {
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
+
var existingSpecifier = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping.Button);
|
|
31
|
+
if (existingSpecifier) {
|
|
32
|
+
var _defaultSpecifier$loc;
|
|
33
|
+
renameElements((_defaultSpecifier$loc = defaultSpecifier.local) === null || _defaultSpecifier$loc === void 0 ? void 0 : _defaultSpecifier$loc.name, existingSpecifier, fileSource, j);
|
|
34
|
+
} else {
|
|
35
|
+
var newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
|
|
36
|
+
j(node).insertAfter(newImport);
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
39
|
var namedSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
|
|
32
40
|
return specifier.type === 'ImportSpecifier';
|
|
@@ -48,8 +56,14 @@ var transformer = function transformer(file, api) {
|
|
|
48
56
|
if (namedSpecifiers !== null && namedSpecifiers !== void 0 && namedSpecifiers.length) {
|
|
49
57
|
namedSpecifiers.forEach(function (specifier) {
|
|
50
58
|
if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
|
|
51
|
-
var
|
|
52
|
-
|
|
59
|
+
var _existingSpecifier = getDefaultImportSpecifierName(j, fileSource, entryPointsMapping[specifier.imported.name]);
|
|
60
|
+
if (_existingSpecifier) {
|
|
61
|
+
var _specifier$local;
|
|
62
|
+
renameElements((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name, _existingSpecifier, fileSource, j);
|
|
63
|
+
} else {
|
|
64
|
+
var _newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
|
|
65
|
+
j(node).insertAfter(_newImport);
|
|
66
|
+
}
|
|
53
67
|
}
|
|
54
68
|
});
|
|
55
69
|
}
|
package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js
CHANGED
|
@@ -23,5 +23,5 @@ export var addCommentForCustomThemeButtons = function addCommentForCustomThemeBu
|
|
|
23
23
|
if (!customThemeButtonElement.length) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, '
|
|
26
|
+
addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'block');
|
|
27
27
|
};
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
export var PRINT_SETTINGS = {
|
|
2
2
|
quote: 'single'
|
|
3
3
|
};
|
|
4
|
+
|
|
5
|
+
/** NEW button **/
|
|
6
|
+
export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
4
7
|
export var NEW_BUTTON_VARIANTS = {
|
|
5
8
|
default: 'Button',
|
|
6
9
|
link: 'LinkButton',
|
|
7
10
|
icon: 'IconButton',
|
|
8
11
|
linkIcon: 'LinkIconButton'
|
|
9
12
|
};
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
/** OLD button **/
|
|
15
|
+
export var OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
16
|
+
export var OLD_BUTTON_VARIANTS = {
|
|
17
|
+
loading: 'LoadingButton'
|
|
18
|
+
};
|
|
11
19
|
export var entryPointsMapping = {
|
|
12
20
|
Button: '@atlaskit/button/standard-button',
|
|
13
21
|
LoadingButton: '@atlaskit/button/loading-button',
|
|
@@ -25,4 +33,9 @@ export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearan
|
|
|
25
33
|
export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
26
34
|
export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
27
35
|
export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
28
|
-
export var customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
36
|
+
export var customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
37
|
+
export var loadingButtonComment = function loadingButtonComment(_ref) {
|
|
38
|
+
var hasLinkAppearance = _ref.hasLinkAppearance,
|
|
39
|
+
hasHref = _ref.hasHref;
|
|
40
|
+
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.");
|
|
41
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns default import specifiers from the given import declarations.
|
|
3
|
+
*/
|
|
4
|
+
export default function getDefaultImports(importDeclarations, j) {
|
|
5
|
+
return importDeclarations.find(j.Specifier).filter(function (path) {
|
|
6
|
+
return path.node.type === 'ImportDefaultSpecifier';
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return path.node.source.value ===
|
|
5
|
-
})
|
|
1
|
+
export var findVariantAlreadyImported = function findVariantAlreadyImported(variant, entryPoint, fileSource, j) {
|
|
2
|
+
var isDefaultSpecifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
3
|
+
var imports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
4
|
+
return path.node.source.value === entryPoint;
|
|
5
|
+
});
|
|
6
|
+
if (isDefaultSpecifier) {
|
|
7
|
+
return imports.find(j.ImportDefaultSpecifier);
|
|
8
|
+
}
|
|
9
|
+
return imports.find(j.ImportSpecifier).filter(function (path) {
|
|
6
10
|
return path.node.imported.name === variant;
|
|
7
|
-
})
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export var checkIfVariantAlreadyImported = function checkIfVariantAlreadyImported(variant, entryPoint, fileSource, j) {
|
|
14
|
+
var isDefaultSpecifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
15
|
+
return findVariantAlreadyImported(variant, entryPoint, fileSource, j, isDefaultSpecifier).length > 0;
|
|
8
16
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default function renameElements(elementName, newElementName, fileSource, j) {
|
|
2
|
+
var oldElements = fileSource.find(j.JSXElement).filter(function (path) {
|
|
3
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === elementName;
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
// Rename elements to match existing import name
|
|
7
|
+
oldElements.forEach(function (element) {
|
|
8
|
+
var _element$value$childr, _element$value$childr2;
|
|
9
|
+
var newElement = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(newElementName), element.value.openingElement.attributes, ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0), ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0 ? null : j.jsxClosingElement(j.jsxIdentifier(newElementName)), element.value.children);
|
|
10
|
+
j(element).replaceWith(newElement);
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/types/main.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export declare const PRINT_SETTINGS: {
|
|
2
2
|
quote: "single";
|
|
3
3
|
};
|
|
4
|
+
/** NEW button **/
|
|
5
|
+
export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
|
|
4
6
|
export declare const NEW_BUTTON_VARIANTS: {
|
|
5
7
|
[key: string]: string;
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
/** OLD button **/
|
|
10
|
+
export declare const OLD_BUTTON_ENTRY_POINT = "@atlaskit/button";
|
|
11
|
+
export declare const OLD_BUTTON_VARIANTS: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
8
14
|
export declare const entryPointsMapping: {
|
|
9
15
|
[key: string]: string;
|
|
10
16
|
};
|
|
@@ -16,3 +22,7 @@ export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"compo
|
|
|
16
22
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
17
23
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
18
24
|
export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
25
|
+
export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
|
|
26
|
+
hasLinkAppearance: boolean;
|
|
27
|
+
hasHref: boolean;
|
|
28
|
+
}) => string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type API, type Collection, type ImportDeclaration, type Specifier } from 'jscodeshift';
|
|
2
|
+
/**
|
|
3
|
+
* Returns default import specifiers from the given import declarations.
|
|
4
|
+
*/
|
|
5
|
+
export default function getDefaultImports(importDeclarations: Collection<ImportDeclaration>, j: API['jscodeshift']): Collection<Specifier>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { API, Collection } from 'jscodeshift';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const findVariantAlreadyImported: (variant: string, entryPoint: string, fileSource: Collection<any>, j: API['jscodeshift'], isDefaultSpecifier?: boolean) => Collection<any>;
|
|
3
|
+
export declare const checkIfVariantAlreadyImported: (variant: string, entryPoint: string, fileSource: Collection<any>, j: API['jscodeshift'], isDefaultSpecifier?: boolean) => boolean;
|
package/dist/types/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { API, FileInfo } from 'jscodeshift';
|
|
1
|
+
import type { API, FileInfo } from 'jscodeshift';
|
|
2
2
|
export default function transformer(file: FileInfo, api: API): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FileInfo, API } from 'jscodeshift';
|
|
1
|
+
import { type FileInfo, type API } from 'jscodeshift';
|
|
2
2
|
export default function transformer(file: FileInfo, api: API): string;
|
package/dist/types/sinceRef.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import path, { ParsedPath } from 'path';
|
|
3
|
-
import { ParsedPkg } from './types';
|
|
2
|
+
import path, { type ParsedPath } from 'path';
|
|
3
|
+
import { type ParsedPkg } from './types';
|
|
4
4
|
export declare const hasTransform: (transformPath: string) => boolean;
|
|
5
5
|
/** Retrieves transforms for `packages` if provided, otherwise all transforms including presets */
|
|
6
6
|
export declare const getTransforms: (packages?: ParsedPkg[]) => ParsedPath[];
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export declare const PRINT_SETTINGS: {
|
|
2
2
|
quote: "single";
|
|
3
3
|
};
|
|
4
|
+
/** NEW button **/
|
|
5
|
+
export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
|
|
4
6
|
export declare const NEW_BUTTON_VARIANTS: {
|
|
5
7
|
[key: string]: string;
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
/** OLD button **/
|
|
10
|
+
export declare const OLD_BUTTON_ENTRY_POINT = "@atlaskit/button";
|
|
11
|
+
export declare const OLD_BUTTON_VARIANTS: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
8
14
|
export declare const entryPointsMapping: {
|
|
9
15
|
[key: string]: string;
|
|
10
16
|
};
|
|
@@ -16,3 +22,7 @@ export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"compo
|
|
|
16
22
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
17
23
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
18
24
|
export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
25
|
+
export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
|
|
26
|
+
hasLinkAppearance: boolean;
|
|
27
|
+
hasHref: boolean;
|
|
28
|
+
}) => string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type API, type Collection, type ImportDeclaration, type Specifier } from 'jscodeshift';
|
|
2
|
+
/**
|
|
3
|
+
* Returns default import specifiers from the given import declarations.
|
|
4
|
+
*/
|
|
5
|
+
export default function getDefaultImports(importDeclarations: Collection<ImportDeclaration>, j: API['jscodeshift']): Collection<Specifier>;
|
package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/if-variant-already-imported.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { API, Collection } from 'jscodeshift';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const findVariantAlreadyImported: (variant: string, entryPoint: string, fileSource: Collection<any>, j: API['jscodeshift'], isDefaultSpecifier?: boolean) => Collection<any>;
|
|
3
|
+
export declare const checkIfVariantAlreadyImported: (variant: string, entryPoint: string, fileSource: Collection<any>, j: API['jscodeshift'], isDefaultSpecifier?: boolean) => boolean;
|