@atlaskit/button 17.17.2 → 17.17.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/__perf__/button.tsx +6 -6
  3. package/__perf__/custom.tsx +6 -6
  4. package/__perf__/customised.tsx +1 -3
  5. package/__perf__/utils/example-runner.tsx +32 -36
  6. package/__perf__/utils/interaction-tasks.tsx +65 -86
  7. package/codemods/15.0.0-lite-mode.tsx +32 -36
  8. package/codemods/15.1.1-data-testid.tsx +136 -142
  9. package/codemods/__tests__/15.0.0-lite-mode/optimistic.tsx +121 -121
  10. package/codemods/__tests__/15.0.0-lite-mode/safe.tsx +54 -54
  11. package/codemods/__tests__/15.0.0-lite-mode/shared.tsx +96 -97
  12. package/codemods/__tests__/15.1.1-data-testid/rename-data-testid.tsx +32 -32
  13. package/codemods/__tests__/_framework.tsx +32 -32
  14. package/codemods/helpers/15.0.0-runner.tsx +135 -137
  15. package/codemods/helpers/helpers-generic.tsx +524 -556
  16. package/codemods/optimistic-15.0.0-lite-mode.tsx +208 -231
  17. package/dist/cjs/old-button/shared/button-base.js +1 -1
  18. package/dist/es2019/new-button/variants/default/link.js +2 -2
  19. package/dist/es2019/new-button/variants/icon/link.js +3 -3
  20. package/dist/es2019/old-button/shared/button-base.js +1 -1
  21. package/dist/esm/new-button/variants/default/link.js +2 -2
  22. package/dist/esm/new-button/variants/icon/link.js +3 -3
  23. package/dist/esm/old-button/shared/button-base.js +1 -1
  24. package/dist/types/entry-points/loading-button.d.ts +1 -1
  25. package/dist/types/entry-points/new.d.ts +3 -3
  26. package/dist/types/entry-points/types.d.ts +2 -2
  27. package/dist/types/index.d.ts +3 -3
  28. package/dist/types/new.d.ts +3 -3
  29. package/dist/types-ts4.5/entry-points/loading-button.d.ts +1 -1
  30. package/dist/types-ts4.5/entry-points/new.d.ts +3 -3
  31. package/dist/types-ts4.5/entry-points/types.d.ts +2 -2
  32. package/dist/types-ts4.5/index.d.ts +3 -3
  33. package/dist/types-ts4.5/new.d.ts +3 -3
  34. package/extract-react-types/custom-theme-button-props.tsx +2 -4
  35. package/extract-react-types/legacy-button/custom-theme-button-props.tsx +2 -4
  36. package/extract-react-types/legacy-button/loading-button-props.tsx +1 -1
  37. package/extract-react-types/legacy-button/shared-props.tsx +1 -1
  38. package/extract-react-types/loading-button-props.tsx +1 -1
  39. package/extract-react-types/new-button/containers/split-button/split-button-props.tsx +1 -1
  40. package/extract-react-types/new-button/variants/default/button-props.tsx +1 -1
  41. package/extract-react-types/new-button/variants/default/common-default-button-props.tsx +4 -4
  42. package/extract-react-types/new-button/variants/default/link-button-props.tsx +4 -4
  43. package/extract-react-types/new-button/variants/icon-button/common-icon-button-props.tsx +4 -4
  44. package/extract-react-types/new-button/variants/icon-button/icon-button-props.tsx +1 -1
  45. package/extract-react-types/new-button/variants/icon-button/link-icon-button-props.tsx +2 -4
  46. package/extract-react-types/shared-props.tsx +1 -1
  47. package/package.json +2 -2
  48. package/report.api.md +78 -96
@@ -2,169 +2,163 @@ import type { API, default as core, FileInfo, Options } from 'jscodeshift';
2
2
  import { type Collection } from 'jscodeshift/src/Collection';
3
3
 
4
4
  import {
5
- addCommentToStartOfFile,
6
- getDefaultSpecifierName,
7
- getJSXAttributesByName,
8
- hasImportDeclaration,
9
- type Nullable,
5
+ addCommentToStartOfFile,
6
+ getDefaultSpecifierName,
7
+ getJSXAttributesByName,
8
+ hasImportDeclaration,
9
+ type Nullable,
10
10
  } from './helpers/helpers-generic';
11
11
  const relevantEntryPoints = [
12
- '@atlaskit/button',
13
- '@atlaskit/button/standard-button',
14
- '@atlaskit/button/loading-button',
15
- '@atlaskit/button/custom-theme-button',
12
+ '@atlaskit/button',
13
+ '@atlaskit/button/standard-button',
14
+ '@atlaskit/button/loading-button',
15
+ '@atlaskit/button/custom-theme-button',
16
16
  ];
17
17
 
18
18
  function isRelevant(j: core.JSCodeshift, source: string): boolean {
19
- return relevantEntryPoints.some((entryPoint) =>
20
- hasImportDeclaration(j, source, entryPoint),
21
- );
19
+ return relevantEntryPoints.some((entryPoint) => hasImportDeclaration(j, source, entryPoint));
22
20
  }
23
21
 
24
22
  function renameProp({
25
- j,
26
- base,
27
- component,
28
- attributeFrom,
29
- attributeTo,
23
+ j,
24
+ base,
25
+ component,
26
+ attributeFrom,
27
+ attributeTo,
30
28
  }: {
31
- j: core.JSCodeshift;
32
- base: Collection<any>;
33
- component: string;
34
- attributeFrom: string;
35
- attributeTo: string;
29
+ j: core.JSCodeshift;
30
+ base: Collection<any>;
31
+ component: string;
32
+ attributeFrom: string;
33
+ attributeTo: string;
36
34
  }) {
37
- base.findJSXElements(component).forEach((element) => {
38
- const first = getJSXAttributesByName({
39
- j,
40
- element: element.value,
41
- attributeName: attributeFrom,
42
- });
43
-
44
- // not using attribute
45
- if (!first.length) {
46
- return;
47
- }
48
-
49
- // let's check to see if they are using the to attribute
50
- const second = getJSXAttributesByName({
51
- j,
52
- element: element.value,
53
- attributeName: attributeTo,
54
- });
55
-
56
- // if the attribute we are moving to already exists we are in trouble
57
- if (second.length) {
58
- addCommentToStartOfFile({
59
- j,
60
- base,
61
- message: `
35
+ base.findJSXElements(component).forEach((element) => {
36
+ const first = getJSXAttributesByName({
37
+ j,
38
+ element: element.value,
39
+ attributeName: attributeFrom,
40
+ });
41
+
42
+ // not using attribute
43
+ if (!first.length) {
44
+ return;
45
+ }
46
+
47
+ // let's check to see if they are using the to attribute
48
+ const second = getJSXAttributesByName({
49
+ j,
50
+ element: element.value,
51
+ attributeName: attributeTo,
52
+ });
53
+
54
+ // if the attribute we are moving to already exists we are in trouble
55
+ if (second.length) {
56
+ addCommentToStartOfFile({
57
+ j,
58
+ base,
59
+ message: `
62
60
  Cannot rename ${attributeFrom} to ${attributeTo} on ${component}.
63
61
  A ${component} was detected with both ${attributeFrom} and ${attributeTo} props.
64
62
  Please remove the ${attributeFrom} prop and check your tests`,
65
- });
66
- return;
67
- }
63
+ });
64
+ return;
65
+ }
68
66
 
69
- first.find(j.JSXIdentifier).replaceWith(j.jsxIdentifier(attributeTo));
70
- });
67
+ first.find(j.JSXIdentifier).replaceWith(j.jsxIdentifier(attributeTo));
68
+ });
71
69
  }
72
70
 
73
71
  export function getNamedImportName({
74
- j,
75
- base,
76
- importPath,
77
- originalName,
72
+ j,
73
+ base,
74
+ importPath,
75
+ originalName,
78
76
  }: {
79
- j: core.JSCodeshift;
80
- base: Collection<any>;
81
- originalName: string;
82
- importPath: string;
77
+ j: core.JSCodeshift;
78
+ base: Collection<any>;
79
+ originalName: string;
80
+ importPath: string;
83
81
  }): Nullable<string> {
84
- const name: Nullable<string> =
85
- base
86
- .find(j.ImportDeclaration)
87
- .filter((path) => path.node.source.value === importPath)
88
- .find(j.ImportSpecifier)
89
- .nodes()
90
- .map((specifier): Nullable<string> => {
91
- if (specifier.imported.name === originalName) {
92
- // aliased
93
- if (specifier.local) {
94
- return specifier.local.name;
95
- }
96
- // not aliased
97
- return originalName;
98
- }
99
-
100
- return null;
101
- })
102
- .filter(Boolean)[0] || null;
103
- return name;
82
+ const name: Nullable<string> =
83
+ base
84
+ .find(j.ImportDeclaration)
85
+ .filter((path) => path.node.source.value === importPath)
86
+ .find(j.ImportSpecifier)
87
+ .nodes()
88
+ .map((specifier): Nullable<string> => {
89
+ if (specifier.imported.name === originalName) {
90
+ // aliased
91
+ if (specifier.local) {
92
+ return specifier.local.name;
93
+ }
94
+ // not aliased
95
+ return originalName;
96
+ }
97
+
98
+ return null;
99
+ })
100
+ .filter(Boolean)[0] || null;
101
+ return name;
104
102
  }
105
103
 
106
- export default function transformer(
107
- file: FileInfo,
108
- { jscodeshift: j }: API,
109
- options: Options,
110
- ) {
111
- if (!isRelevant(j, file.source)) {
112
- return file.source;
113
- }
114
-
115
- const base: Collection<any> = j(file.source);
116
-
117
- // renaming default imports for entry points
118
- relevantEntryPoints.forEach((importPath) => {
119
- const defaultName: Nullable<string> = getDefaultSpecifierName({
120
- j,
121
- base,
122
- packageName: importPath,
123
- });
124
-
125
- if (defaultName != null) {
126
- renameProp({
127
- j,
128
- base,
129
- component: defaultName,
130
- attributeFrom: 'data-testid',
131
- attributeTo: 'testId',
132
- });
133
- }
134
- });
135
-
136
- // named imports
137
- const standard = getNamedImportName({
138
- j,
139
- base,
140
- importPath: '@atlaskit/button',
141
- originalName: 'StandardButton',
142
- });
143
- const loading = getNamedImportName({
144
- j,
145
- base,
146
- importPath: '@atlaskit/button',
147
- originalName: 'LoadingButton',
148
- });
149
- const customTheme = getNamedImportName({
150
- j,
151
- base,
152
- importPath: '@atlaskit/button',
153
- originalName: 'CustomThemeButton',
154
- });
155
- [standard, loading, customTheme].forEach((name) => {
156
- if (name != null) {
157
- renameProp({
158
- j,
159
- base,
160
- component: name,
161
- attributeFrom: 'data-testid',
162
- attributeTo: 'testId',
163
- });
164
- }
165
- });
166
-
167
- return base.toSource({ quote: 'single' });
104
+ export default function transformer(file: FileInfo, { jscodeshift: j }: API, options: Options) {
105
+ if (!isRelevant(j, file.source)) {
106
+ return file.source;
107
+ }
108
+
109
+ const base: Collection<any> = j(file.source);
110
+
111
+ // renaming default imports for entry points
112
+ relevantEntryPoints.forEach((importPath) => {
113
+ const defaultName: Nullable<string> = getDefaultSpecifierName({
114
+ j,
115
+ base,
116
+ packageName: importPath,
117
+ });
118
+
119
+ if (defaultName != null) {
120
+ renameProp({
121
+ j,
122
+ base,
123
+ component: defaultName,
124
+ attributeFrom: 'data-testid',
125
+ attributeTo: 'testId',
126
+ });
127
+ }
128
+ });
129
+
130
+ // named imports
131
+ const standard = getNamedImportName({
132
+ j,
133
+ base,
134
+ importPath: '@atlaskit/button',
135
+ originalName: 'StandardButton',
136
+ });
137
+ const loading = getNamedImportName({
138
+ j,
139
+ base,
140
+ importPath: '@atlaskit/button',
141
+ originalName: 'LoadingButton',
142
+ });
143
+ const customTheme = getNamedImportName({
144
+ j,
145
+ base,
146
+ importPath: '@atlaskit/button',
147
+ originalName: 'CustomThemeButton',
148
+ });
149
+ [standard, loading, customTheme].forEach((name) => {
150
+ if (name != null) {
151
+ renameProp({
152
+ j,
153
+ base,
154
+ component: name,
155
+ attributeFrom: 'data-testid',
156
+ attributeTo: 'testId',
157
+ });
158
+ }
159
+ });
160
+
161
+ return base.toSource({ quote: 'single' });
168
162
  }
169
163
 
170
164
  // Note: not exporting a 'parser' because doing so