@atlaskit/codemod-cli 0.24.2 → 0.24.3
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 +330 -323
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +126 -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/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 +119 -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/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 +126 -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/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,86 @@ 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
|
+
j(element).replaceWith(newElement);
|
|
113
|
+
if (hasHref || linkAppearanceAttribute) {
|
|
114
|
+
addCommentBefore(j, j(newElement), loadingButtonComment({
|
|
115
|
+
hasHref: hasHref,
|
|
116
|
+
hasLinkAppearance: Boolean(linkAppearanceAttribute)
|
|
117
|
+
}), 'block');
|
|
118
|
+
}
|
|
119
|
+
} else if (!hasHref && linkAppearanceAttribute) {
|
|
87
120
|
addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
|
|
88
121
|
}
|
|
89
122
|
});
|
|
90
123
|
|
|
91
124
|
// modify import declarations
|
|
92
125
|
var specifiers = [];
|
|
93
|
-
[
|
|
126
|
+
[hasVariant.linkButton ? 'link' : null, hasVariant.iconButton ? 'icon' : null, hasVariant.linkIconButton ? 'linkIcon' : null].forEach(function (variant) {
|
|
94
127
|
if (variant) {
|
|
95
128
|
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS[variant])));
|
|
96
129
|
}
|
|
97
130
|
});
|
|
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
131
|
var remainingDefaultButtons = fileSource.find(j.JSXElement).filter(function (path) {
|
|
102
|
-
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name
|
|
132
|
+
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
133
|
}).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
|
|
104
134
|
return path.node.arguments.map(function (argument) {
|
|
105
135
|
return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
|
|
106
|
-
}).
|
|
136
|
+
}).some(function (name) {
|
|
137
|
+
return name && (oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(name));
|
|
138
|
+
});
|
|
107
139
|
}).length > 0;
|
|
108
140
|
|
|
109
141
|
// Loading buttons map back to default imports
|
|
110
|
-
if (
|
|
142
|
+
if (loadingButtonDirectImportName && oldDefaultImportSpecifiers !== null && oldDefaultImportSpecifiers !== void 0 && oldDefaultImportSpecifiers.includes(loadingButtonDirectImportName)) {
|
|
111
143
|
fileSource
|
|
112
144
|
// rename LoadingButton to Button in all call expressions i.e. render(LoadingButton), find(LoadingButton)
|
|
113
145
|
.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
|
|
114
|
-
if (path.node.name ===
|
|
146
|
+
if (path.node.name === loadingButtonDirectImportName) {
|
|
115
147
|
path.node.name = NEW_BUTTON_VARIANTS.default;
|
|
116
148
|
}
|
|
117
149
|
});
|
|
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
150
|
}
|
|
124
|
-
|
|
151
|
+
|
|
152
|
+
// Only add the Button import if we found a default button, not icon only
|
|
153
|
+
if (hasVariant.defaultButton || !specifiers.find(function (specifier) {
|
|
125
154
|
return specifier.type === 'ImportDefaultSpecifier';
|
|
126
155
|
}) && remainingDefaultButtons) {
|
|
127
156
|
specifiers.push(j.importDefaultSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default)));
|
|
128
157
|
}
|
|
129
158
|
|
|
130
159
|
// update import path for types imports
|
|
131
|
-
specifiers = importTypesFromNewEntryPoint(
|
|
132
|
-
var
|
|
160
|
+
specifiers = importTypesFromNewEntryPoint(oldButtonImports, specifiers, j, fileSource);
|
|
161
|
+
var oldButtonsWithUnsupportedProps = oldButtonElements.filter(function (path) {
|
|
133
162
|
return ifHasUnsupportedProps(path.value.openingElement.attributes);
|
|
134
163
|
});
|
|
135
|
-
if (
|
|
164
|
+
if (oldButtonsWithUnsupportedProps.length) {
|
|
136
165
|
// add comment to all buttons with unsupported props: "component", "style", "css"
|
|
137
|
-
|
|
166
|
+
oldButtonsWithUnsupportedProps.forEach(function (element) {
|
|
138
167
|
var _element$value$openin;
|
|
139
168
|
var attribute = (_element$value$openin = element.value.openingElement.attributes) === null || _element$value$openin === void 0 ? void 0 : _element$value$openin.find(function (node) {
|
|
140
169
|
return node.type === 'JSXAttribute' && typeof node.name.name === 'string' && unsupportedProps.includes(node.name.name);
|
|
@@ -148,16 +177,56 @@ var transformer = function transformer(file, api) {
|
|
|
148
177
|
if (specifiers.find(function (specifier) {
|
|
149
178
|
return specifier.type === 'ImportDefaultSpecifier';
|
|
150
179
|
})) {
|
|
151
|
-
renameDefaultButtonToLegacyButtonImport(
|
|
180
|
+
renameDefaultButtonToLegacyButtonImport(oldButtonImports, oldButtonsWithUnsupportedProps, j);
|
|
152
181
|
}
|
|
153
182
|
}
|
|
154
183
|
if (specifiers.length) {
|
|
184
|
+
var existingNewButtonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
185
|
+
return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
|
|
186
|
+
});
|
|
155
187
|
var newButtonImport = j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
|
|
156
|
-
|
|
188
|
+
oldButtonImports.forEach(function (path) {
|
|
157
189
|
var _path$node;
|
|
158
190
|
newButtonImport.comments = path !== null && path !== void 0 && (_path$node = path.node) !== null && _path$node !== void 0 && _path$node.comments ? path.node.comments : undefined;
|
|
159
191
|
});
|
|
160
|
-
|
|
192
|
+
if (existingNewButtonImports.length) {
|
|
193
|
+
existingNewButtonImports.forEach(function (path) {
|
|
194
|
+
// Merge specifiers from existing new button import with added specifiers
|
|
195
|
+
var mergedSpecifiers = [].concat(_toConsumableArray(specifiers.filter(function (specifier) {
|
|
196
|
+
var _path$node$specifiers;
|
|
197
|
+
if (specifier.type !== 'ImportDefaultSpecifier') {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Ensure we don't add a duplicate default specifier if one is already imported
|
|
202
|
+
return !((_path$node$specifiers = path.node.specifiers) !== null && _path$node$specifiers !== void 0 && _path$node$specifiers.find(function (s) {
|
|
203
|
+
return s.type === 'ImportDefaultSpecifier';
|
|
204
|
+
}));
|
|
205
|
+
})), _toConsumableArray(path.node.specifiers ? path.node.specifiers : [])) // Filter duplicates
|
|
206
|
+
.filter(function (specifier) {
|
|
207
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
var isAlreadyImported = specifiers.find(function (s) {
|
|
211
|
+
var _specifier$local;
|
|
212
|
+
return s.type === 'ImportSpecifier' && s.imported.name === ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name);
|
|
213
|
+
});
|
|
214
|
+
return !isAlreadyImported;
|
|
215
|
+
});
|
|
216
|
+
newButtonImport = j.importDeclaration(mergedSpecifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT));
|
|
217
|
+
});
|
|
218
|
+
oldButtonImports.remove();
|
|
219
|
+
existingNewButtonImports.replaceWith(newButtonImport);
|
|
220
|
+
} else {
|
|
221
|
+
oldButtonImports.replaceWith(function (_, index) {
|
|
222
|
+
// Only replace the first import
|
|
223
|
+
if (index === 0) {
|
|
224
|
+
return newButtonImport;
|
|
225
|
+
}
|
|
226
|
+
// Remove the rest
|
|
227
|
+
return null;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
161
230
|
}
|
|
162
231
|
|
|
163
232
|
// remove empty import declarations
|
|
@@ -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
|
}
|
|
@@ -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;
|
package/dist/types-ts4.5/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;
|
|
@@ -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[];
|