@atlaskit/button 20.4.1 → 20.4.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 +8 -58
- package/dist/cjs/old-button/shared/button-base.js +1 -1
- package/dist/es2019/old-button/shared/button-base.js +1 -1
- package/dist/esm/old-button/shared/button-base.js +1 -1
- package/package.json +1 -3
- package/codemods/15.0.0-lite-mode.tsx +0 -45
- package/codemods/__tests__/15.0.0-lite-mode/optimistic.tsx +0 -638
- package/codemods/__tests__/15.0.0-lite-mode/safe.tsx +0 -223
- package/codemods/__tests__/15.0.0-lite-mode/shared.tsx +0 -255
- package/codemods/helpers/15.0.0-runner.tsx +0 -167
- package/codemods/optimistic-15.0.0-lite-mode.tsx +0 -263
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { type NodePath } from 'ast-types/lib/node-path';
|
|
2
|
-
import type { API, default as core, FileInfo, JSXElement, Node, Options } from 'jscodeshift';
|
|
3
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
4
|
-
|
|
5
|
-
import { convertButtonType, transformButton } from './helpers/15.0.0-runner';
|
|
6
|
-
import {
|
|
7
|
-
addCommentBefore,
|
|
8
|
-
addCommentToStartOfFile,
|
|
9
|
-
addToImport,
|
|
10
|
-
changeImportFor,
|
|
11
|
-
getDefaultSpecifierName,
|
|
12
|
-
getSafeImportName,
|
|
13
|
-
isOnlyUsingNameForJSX,
|
|
14
|
-
isUsingProp,
|
|
15
|
-
isUsingSupportedSpread,
|
|
16
|
-
type Nullable,
|
|
17
|
-
tryCreateImport,
|
|
18
|
-
} from './helpers/helpers-generic';
|
|
19
|
-
|
|
20
|
-
function changeUsage({
|
|
21
|
-
j,
|
|
22
|
-
base,
|
|
23
|
-
packageName,
|
|
24
|
-
}: {
|
|
25
|
-
j: core.JSCodeshift;
|
|
26
|
-
base: Collection<Node>;
|
|
27
|
-
packageName: string;
|
|
28
|
-
}): void {
|
|
29
|
-
// 1. Are we using the default export?
|
|
30
|
-
// If not: we can exit early!
|
|
31
|
-
const defaultName: Nullable<string> = getDefaultSpecifierName({
|
|
32
|
-
j,
|
|
33
|
-
base,
|
|
34
|
-
packageName,
|
|
35
|
-
});
|
|
36
|
-
if (defaultName == null) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Only supporting cases where default identifier is only used in JSX
|
|
41
|
-
const isSupported: boolean = isOnlyUsingNameForJSX({
|
|
42
|
-
j,
|
|
43
|
-
base,
|
|
44
|
-
name: defaultName,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!isSupported) {
|
|
48
|
-
tryCreateImport({
|
|
49
|
-
j,
|
|
50
|
-
base,
|
|
51
|
-
relativeToPackage: '@atlaskit/button',
|
|
52
|
-
packageName: '@atlaskit/button/standard-button',
|
|
53
|
-
});
|
|
54
|
-
addToImport({
|
|
55
|
-
j,
|
|
56
|
-
base,
|
|
57
|
-
// we can safely use the default name, because it was being used before
|
|
58
|
-
importSpecifier: j.importDefaultSpecifier(j.identifier(defaultName)),
|
|
59
|
-
packageName: '@atlaskit/button/standard-button',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
addCommentBefore({
|
|
63
|
-
j,
|
|
64
|
-
target: base
|
|
65
|
-
.find(j.ImportDeclaration)
|
|
66
|
-
.filter(
|
|
67
|
-
(declaration) => declaration.value.source.value === '@atlaskit/button/standard-button',
|
|
68
|
-
),
|
|
69
|
-
message: `
|
|
70
|
-
This file does not exclusively use Button in JSX.
|
|
71
|
-
The codemod is unable to know which button variant, so it is using
|
|
72
|
-
the standard button: "@atlaskit/button/standard-button".
|
|
73
|
-
|
|
74
|
-
Please validate this decision.
|
|
75
|
-
You might need to change the usage of Button to either LoadingButton or CustomThemeButton
|
|
76
|
-
`,
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Find usages of the Button component
|
|
82
|
-
// There are three possible import statements:
|
|
83
|
-
// 1. import Button from '@atlaskit/button/standard';
|
|
84
|
-
// 2. import LoadingButton from '@atlaskit/button/loading-button';
|
|
85
|
-
// 3. import CustomThemeButton from '@atlaskit/button/custom-theme-button';
|
|
86
|
-
|
|
87
|
-
// What to do if any of the names clash?
|
|
88
|
-
// - In the case of clash: prefix with 'DS' (eg import DSLoadingButton from '@atlaskit/button/loading-button';)
|
|
89
|
-
|
|
90
|
-
// What to do if old Button was aliased? eg "AkButton"
|
|
91
|
-
// - We cannot use that existing alias as we might have three different Button imports in the file
|
|
92
|
-
// - We automatically will be be swapping to the standard names with 'DS' prefix for all imports
|
|
93
|
-
|
|
94
|
-
type Groups = {
|
|
95
|
-
standard: NodePath<JSXElement, JSXElement>[];
|
|
96
|
-
loading: NodePath<JSXElement, JSXElement>[];
|
|
97
|
-
customTheme: NodePath<JSXElement, JSXElement>[];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const groups: Groups = {
|
|
101
|
-
standard: [],
|
|
102
|
-
loading: [],
|
|
103
|
-
customTheme: [],
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
base.findJSXElements(defaultName).forEach((path) => {
|
|
107
|
-
const hasThemeProp: boolean = isUsingProp({
|
|
108
|
-
j,
|
|
109
|
-
base,
|
|
110
|
-
element: path,
|
|
111
|
-
propName: 'theme',
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (hasThemeProp) {
|
|
115
|
-
groups.customTheme.push(path);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!isUsingSupportedSpread({ j, base, element: path })) {
|
|
120
|
-
addCommentToStartOfFile({
|
|
121
|
-
j,
|
|
122
|
-
base,
|
|
123
|
-
message: `
|
|
124
|
-
Detected spreading props (<Button {...props} />) that was too complex for our codemod to understand
|
|
125
|
-
Our codemod will only look at inline objects, or objects defined in the same file (ObjectExpression's)
|
|
126
|
-
We have opted for our safest upgrade component in this file: '<CustomThemeButton />'
|
|
127
|
-
`,
|
|
128
|
-
});
|
|
129
|
-
groups.customTheme.push(path);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const isUsingThemeInFile: boolean =
|
|
134
|
-
base
|
|
135
|
-
.find(j.ImportDeclaration)
|
|
136
|
-
.filter(
|
|
137
|
-
(declaration) =>
|
|
138
|
-
declaration.value.source.value === '@atlaskit/button/custom-theme-button',
|
|
139
|
-
)
|
|
140
|
-
.find(j.ImportSpecifier)
|
|
141
|
-
.filter((specifier) => specifier.value.imported.name === 'Theme').length > 0;
|
|
142
|
-
|
|
143
|
-
if (isUsingThemeInFile) {
|
|
144
|
-
addCommentToStartOfFile({
|
|
145
|
-
j,
|
|
146
|
-
base,
|
|
147
|
-
message: `
|
|
148
|
-
Using "import { Theme } from '@atlaskit/button/custom-theme-button" in a file
|
|
149
|
-
will cause all buttons in that file to be safely converted to a <CustomThemeButton/>
|
|
150
|
-
`,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
groups.customTheme.push(path);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const hasIsLoadingProp: boolean = isUsingProp({
|
|
158
|
-
j,
|
|
159
|
-
base,
|
|
160
|
-
element: path,
|
|
161
|
-
propName: 'isLoading',
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (hasIsLoadingProp) {
|
|
165
|
-
groups.loading.push(path);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
groups.standard.push(path);
|
|
170
|
-
return;
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
convertButtonType({
|
|
174
|
-
j,
|
|
175
|
-
base,
|
|
176
|
-
elements: groups.standard,
|
|
177
|
-
name: getSafeImportName({
|
|
178
|
-
j,
|
|
179
|
-
base,
|
|
180
|
-
currentDefaultSpecifierName: defaultName,
|
|
181
|
-
desiredName: 'Button',
|
|
182
|
-
fallbackName: 'DSButton',
|
|
183
|
-
}),
|
|
184
|
-
newPackageName: '@atlaskit/button/standard-button',
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
convertButtonType({
|
|
188
|
-
j,
|
|
189
|
-
base,
|
|
190
|
-
elements: groups.loading,
|
|
191
|
-
newPackageName: '@atlaskit/button/loading-button',
|
|
192
|
-
name: getSafeImportName({
|
|
193
|
-
j,
|
|
194
|
-
base,
|
|
195
|
-
desiredName: 'LoadingButton',
|
|
196
|
-
fallbackName: 'DSLoadingButton',
|
|
197
|
-
currentDefaultSpecifierName: defaultName,
|
|
198
|
-
}),
|
|
199
|
-
});
|
|
200
|
-
convertButtonType({
|
|
201
|
-
j,
|
|
202
|
-
base,
|
|
203
|
-
elements: groups.customTheme,
|
|
204
|
-
newPackageName: '@atlaskit/button/custom-theme-button',
|
|
205
|
-
name: getSafeImportName({
|
|
206
|
-
j,
|
|
207
|
-
base,
|
|
208
|
-
currentDefaultSpecifierName: defaultName,
|
|
209
|
-
desiredName: 'CustomThemeButton',
|
|
210
|
-
fallbackName: 'DSCustomThemeButton',
|
|
211
|
-
}),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export default function transformer(file: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
216
|
-
return transformButton({
|
|
217
|
-
j,
|
|
218
|
-
file,
|
|
219
|
-
custom: (base: Collection<any>) => {
|
|
220
|
-
changeImportFor({
|
|
221
|
-
j,
|
|
222
|
-
base,
|
|
223
|
-
option: {
|
|
224
|
-
type: 'keep-name',
|
|
225
|
-
name: 'ButtonProps',
|
|
226
|
-
behaviour: 'keep-as-named-import',
|
|
227
|
-
},
|
|
228
|
-
oldPackagePath: '@atlaskit/button',
|
|
229
|
-
newPackagePath: '@atlaskit/button/types',
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const isUsingButtonPropsType: boolean =
|
|
233
|
-
base
|
|
234
|
-
.find(j.ImportDeclaration)
|
|
235
|
-
.filter((declaration) => declaration.value.source.value === '@atlaskit/button/types')
|
|
236
|
-
.find(j.ImportSpecifier)
|
|
237
|
-
.filter((specifier) => specifier.value.imported.name === 'ButtonProps').length > 0;
|
|
238
|
-
|
|
239
|
-
if (isUsingButtonPropsType) {
|
|
240
|
-
const target = base
|
|
241
|
-
.find(j.ImportDeclaration)
|
|
242
|
-
.filter((declaration) => declaration.value.source.value === '@atlaskit/button/types');
|
|
243
|
-
addCommentBefore({
|
|
244
|
-
j,
|
|
245
|
-
target,
|
|
246
|
-
message: `
|
|
247
|
-
Verify ButtonProps is the right prop type
|
|
248
|
-
You might need the LoadingButtonProps, CustomButtonProps types which can be imported from '@atlaskit/button/types'
|
|
249
|
-
`,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
changeUsage({
|
|
254
|
-
j,
|
|
255
|
-
base,
|
|
256
|
-
packageName: '@atlaskit/button',
|
|
257
|
-
});
|
|
258
|
-
},
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Note: not exporting a 'parser' because doing so
|
|
263
|
-
// will prevent consumers overriding it
|