@atlaskit/section-message 6.5.2 → 6.5.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 +13 -1
- package/README.md +2 -1
- package/__perf__/default.tsx +1 -3
- package/__perf__/with-actions.tsx +18 -18
- package/__perf__/without-actions.tsx +8 -8
- package/codemods/6.0.0-lite-mode.tsx +5 -8
- package/codemods/__tests__/6.0.0-lite-mode.tsx +49 -49
- package/codemods/__tests__/change-appearance-prop.tsx +63 -63
- package/codemods/__tests__/map-actions-prop.tsx +96 -96
- package/codemods/internal/change-appearance-prop.tsx +75 -95
- package/codemods/internal/constants.tsx +4 -4
- package/codemods/internal/map-actions-prop.tsx +163 -190
- package/codemods/internal/utils.tsx +45 -61
- package/dist/types/entry-points/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types-ts4.5/entry-points/types.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/package.json +94 -94
- package/report.api.md +16 -23
|
@@ -1,215 +1,188 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
type ASTPath,
|
|
3
|
+
type default as core,
|
|
4
|
+
type ImportDeclaration,
|
|
5
|
+
type JSXAttribute,
|
|
6
|
+
type JSXElement,
|
|
7
|
+
type JSXExpressionContainer,
|
|
8
|
+
type VariableDeclaration,
|
|
9
9
|
} from 'jscodeshift';
|
|
10
10
|
import { type Collection } from 'jscodeshift/src/Collection';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
addCommentBefore,
|
|
14
|
+
getDefaultSpecifier,
|
|
15
|
+
getJSXAttributesByName,
|
|
16
16
|
} from '@atlaskit/codemod-utils';
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
ACTIONS_PROP_NAME,
|
|
20
|
+
LINK_COMPONENT_PROP_NAME,
|
|
21
|
+
SECTION_MESSAGE_ACTION_COMPONENT_NAME,
|
|
22
|
+
SECTION_MESSAGE_ACTION_PACKAGE_NAME,
|
|
23
|
+
SECTION_MESSAGE_PACKAGE_NAME,
|
|
24
24
|
} from './constants';
|
|
25
25
|
import { doesIdentifierExist, getDynamicImportName } from './utils';
|
|
26
26
|
|
|
27
27
|
const addSectionMessageActionImportSpecifier = (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
j: core.JSCodeshift,
|
|
29
|
+
source: Collection<Node>,
|
|
30
|
+
name: string,
|
|
31
31
|
) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
j.identifier(name),
|
|
43
|
-
),
|
|
44
|
-
);
|
|
45
|
-
});
|
|
32
|
+
source
|
|
33
|
+
.find(j.ImportDeclaration)
|
|
34
|
+
.filter(
|
|
35
|
+
(path: ASTPath<ImportDeclaration>) => path.node.source.value === SECTION_MESSAGE_PACKAGE_NAME,
|
|
36
|
+
)
|
|
37
|
+
.forEach((path: ASTPath<ImportDeclaration>) => {
|
|
38
|
+
path.value.specifiers?.push(
|
|
39
|
+
j.importSpecifier(j.identifier(SECTION_MESSAGE_ACTION_COMPONENT_NAME), j.identifier(name)),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
46
42
|
};
|
|
47
43
|
|
|
48
44
|
const addSectionMessageActionDynamicImport = (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
j: core.JSCodeshift,
|
|
46
|
+
target: Collection<VariableDeclaration>,
|
|
47
|
+
name: string,
|
|
52
48
|
) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
addCommentBefore(
|
|
72
|
-
j,
|
|
73
|
-
j(node),
|
|
74
|
-
'We have added `React.lazy` here. Feel free to change it to `lazy` or other named import depending upon how you imported.',
|
|
75
|
-
);
|
|
49
|
+
const node = j.variableDeclaration('const', [
|
|
50
|
+
j.variableDeclarator(
|
|
51
|
+
j.identifier(name),
|
|
52
|
+
j.callExpression(j.memberExpression(j.identifier('React'), j.identifier('lazy')), [
|
|
53
|
+
j.arrowFunctionExpression(
|
|
54
|
+
[],
|
|
55
|
+
j.callExpression(j.import(), [j.stringLiteral(SECTION_MESSAGE_ACTION_PACKAGE_NAME)]),
|
|
56
|
+
),
|
|
57
|
+
]),
|
|
58
|
+
),
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
target.insertAfter(node);
|
|
62
|
+
addCommentBefore(
|
|
63
|
+
j,
|
|
64
|
+
j(node),
|
|
65
|
+
'We have added `React.lazy` here. Feel free to change it to `lazy` or other named import depending upon how you imported.',
|
|
66
|
+
);
|
|
76
67
|
};
|
|
77
68
|
|
|
78
|
-
const transferLinkComponentProp = (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
const transferLinkComponentProp = (j: core.JSCodeshift, element: ASTPath<JSXElement>) => {
|
|
70
|
+
const linkComponentAttributeCollection: Collection<JSXAttribute> = getJSXAttributesByName(
|
|
71
|
+
j,
|
|
72
|
+
element,
|
|
73
|
+
LINK_COMPONENT_PROP_NAME,
|
|
74
|
+
);
|
|
75
|
+
const linkComponentAttribute =
|
|
76
|
+
linkComponentAttributeCollection.length === 1
|
|
77
|
+
? linkComponentAttributeCollection.paths()[0]
|
|
78
|
+
: null;
|
|
88
79
|
|
|
89
|
-
|
|
80
|
+
const linkComponentAttributeValue = linkComponentAttribute?.node?.value;
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
if (linkComponentAttribute) {
|
|
83
|
+
j(linkComponentAttribute).remove();
|
|
84
|
+
}
|
|
94
85
|
|
|
95
|
-
|
|
86
|
+
return linkComponentAttributeValue;
|
|
96
87
|
};
|
|
97
88
|
|
|
98
|
-
export const mapActionsProp = (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
addSectionMessageActionDynamicImport(
|
|
198
|
-
j,
|
|
199
|
-
source.find(j.VariableDeclaration).filter((variableDeclarationPath) => {
|
|
200
|
-
return (
|
|
201
|
-
j(variableDeclarationPath)
|
|
202
|
-
.find(j.VariableDeclarator)
|
|
203
|
-
.filter(
|
|
204
|
-
(variableDeclaratorPath) =>
|
|
205
|
-
variableDeclaratorPath.node.id.type === 'Identifier' &&
|
|
206
|
-
variableDeclaratorPath.node.id.name ===
|
|
207
|
-
sectionMessageDynamicImportName,
|
|
208
|
-
).length > 0
|
|
209
|
-
);
|
|
210
|
-
}),
|
|
211
|
-
sectionMessageActionName,
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
89
|
+
export const mapActionsProp = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
90
|
+
const sectionMessageDefaultSpecifierName =
|
|
91
|
+
getDefaultSpecifier(j, source, SECTION_MESSAGE_PACKAGE_NAME) ?? '';
|
|
92
|
+
|
|
93
|
+
const sectionMessageDynamicImportName =
|
|
94
|
+
getDynamicImportName(j, source, SECTION_MESSAGE_PACKAGE_NAME) ?? '';
|
|
95
|
+
|
|
96
|
+
if (!sectionMessageDefaultSpecifierName && !sectionMessageDynamicImportName) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const sectionMessageActionName = doesIdentifierExist({
|
|
101
|
+
j,
|
|
102
|
+
base: source,
|
|
103
|
+
name: SECTION_MESSAGE_ACTION_COMPONENT_NAME,
|
|
104
|
+
})
|
|
105
|
+
? `Atlaskit${SECTION_MESSAGE_ACTION_COMPONENT_NAME}`
|
|
106
|
+
: SECTION_MESSAGE_ACTION_COMPONENT_NAME;
|
|
107
|
+
|
|
108
|
+
let actionsAttributes: Collection<JSXAttribute> | null = null;
|
|
109
|
+
|
|
110
|
+
source
|
|
111
|
+
.findJSXElements(sectionMessageDefaultSpecifierName || sectionMessageDynamicImportName)
|
|
112
|
+
.forEach((element) => {
|
|
113
|
+
const linkComponentAttributeValue = transferLinkComponentProp(j, element);
|
|
114
|
+
actionsAttributes = getJSXAttributesByName(j, element, ACTIONS_PROP_NAME);
|
|
115
|
+
|
|
116
|
+
actionsAttributes?.forEach((attribute: ASTPath<JSXAttribute>) => {
|
|
117
|
+
j(attribute)
|
|
118
|
+
.find(j.JSXExpressionContainer)
|
|
119
|
+
.forEach((expressionContainer: ASTPath<JSXExpressionContainer>) => {
|
|
120
|
+
const { expression } = expressionContainer.node;
|
|
121
|
+
|
|
122
|
+
if (expression.type === 'JSXEmptyExpression') {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const textObjectProperty = j.objectProperty(j.identifier('text'), j.identifier('text'));
|
|
127
|
+
|
|
128
|
+
textObjectProperty.shorthand = true;
|
|
129
|
+
|
|
130
|
+
j(expressionContainer).replaceWith(
|
|
131
|
+
j.jsxExpressionContainer(
|
|
132
|
+
j.callExpression(j.memberExpression(expression, j.identifier('map')), [
|
|
133
|
+
j.arrowFunctionExpression(
|
|
134
|
+
[
|
|
135
|
+
j.objectPattern([
|
|
136
|
+
textObjectProperty,
|
|
137
|
+
j.restProperty(j.identifier('restAction')),
|
|
138
|
+
]),
|
|
139
|
+
],
|
|
140
|
+
j.jsxElement(
|
|
141
|
+
j.jsxOpeningElement(
|
|
142
|
+
j.jsxIdentifier(sectionMessageActionName),
|
|
143
|
+
[
|
|
144
|
+
linkComponentAttributeValue
|
|
145
|
+
? j.jsxAttribute(
|
|
146
|
+
j.jsxIdentifier(LINK_COMPONENT_PROP_NAME),
|
|
147
|
+
linkComponentAttributeValue,
|
|
148
|
+
)
|
|
149
|
+
: null,
|
|
150
|
+
j.jsxSpreadAttribute(j.identifier('restAction')),
|
|
151
|
+
].filter(Boolean) as JSXAttribute[],
|
|
152
|
+
),
|
|
153
|
+
j.jsxClosingElement(j.jsxIdentifier(sectionMessageActionName)),
|
|
154
|
+
[j.jsxExpressionContainer(j.identifier('text'))],
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
]),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
if (actionsAttributes && actionsAttributes.length > 0) {
|
|
166
|
+
if (sectionMessageDefaultSpecifierName) {
|
|
167
|
+
addSectionMessageActionImportSpecifier(j, source, sectionMessageActionName);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (sectionMessageDynamicImportName) {
|
|
171
|
+
addSectionMessageActionDynamicImport(
|
|
172
|
+
j,
|
|
173
|
+
source.find(j.VariableDeclaration).filter((variableDeclarationPath) => {
|
|
174
|
+
return (
|
|
175
|
+
j(variableDeclarationPath)
|
|
176
|
+
.find(j.VariableDeclarator)
|
|
177
|
+
.filter(
|
|
178
|
+
(variableDeclaratorPath) =>
|
|
179
|
+
variableDeclaratorPath.node.id.type === 'Identifier' &&
|
|
180
|
+
variableDeclaratorPath.node.id.name === sectionMessageDynamicImportName,
|
|
181
|
+
).length > 0
|
|
182
|
+
);
|
|
183
|
+
}),
|
|
184
|
+
sectionMessageActionName,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
215
188
|
};
|
|
@@ -2,86 +2,70 @@ import { type CallExpression, type default as core } from 'jscodeshift';
|
|
|
2
2
|
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
3
|
|
|
4
4
|
export function doesIdentifierExist({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
j,
|
|
6
|
+
base,
|
|
7
|
+
name,
|
|
8
8
|
}: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
j: core.JSCodeshift;
|
|
10
|
+
base: Collection<any>;
|
|
11
|
+
name: string;
|
|
12
12
|
}): boolean {
|
|
13
|
-
|
|
14
|
-
base.find(j.Identifier).filter((identifer) => identifer.value.name === name)
|
|
15
|
-
.length > 0
|
|
16
|
-
);
|
|
13
|
+
return base.find(j.Identifier).filter((identifer) => identifer.value.name === name).length > 0;
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
export function hasDynamicImport(
|
|
20
|
-
|
|
21
|
-
source: Collection<any>,
|
|
22
|
-
importPath: string,
|
|
23
|
-
) {
|
|
24
|
-
return !!getDynamicImportName(j, source, importPath);
|
|
16
|
+
export function hasDynamicImport(j: core.JSCodeshift, source: Collection<any>, importPath: string) {
|
|
17
|
+
return !!getDynamicImportName(j, source, importPath);
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
export function getDynamicImportName(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
j: core.JSCodeshift,
|
|
22
|
+
source: Collection<any>,
|
|
23
|
+
importPath: string,
|
|
31
24
|
) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.filter((callExpressionPath) => {
|
|
39
|
-
const { callee, arguments: callExpressionArguments } =
|
|
40
|
-
callExpressionPath.node;
|
|
25
|
+
const dynamicImports = source.find(j.VariableDeclarator).filter((variableDeclaratorPath) => {
|
|
26
|
+
return (
|
|
27
|
+
j(variableDeclaratorPath)
|
|
28
|
+
.find(j.CallExpression)
|
|
29
|
+
.filter((callExpressionPath) => {
|
|
30
|
+
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
importPath,
|
|
51
|
-
)
|
|
52
|
-
);
|
|
53
|
-
}).length > 0
|
|
54
|
-
);
|
|
55
|
-
});
|
|
32
|
+
return !!(
|
|
33
|
+
isCallExpressionCalleeImportType(callee) &&
|
|
34
|
+
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
35
|
+
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
36
|
+
);
|
|
37
|
+
}).length > 0
|
|
38
|
+
);
|
|
39
|
+
});
|
|
56
40
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
if (!dynamicImports.length) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
60
44
|
|
|
61
|
-
|
|
45
|
+
const { id } = dynamicImports.nodes()[0];
|
|
62
46
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
if (id.type !== 'Identifier') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
66
50
|
|
|
67
|
-
|
|
51
|
+
return id.name;
|
|
68
52
|
}
|
|
69
53
|
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
70
|
-
|
|
54
|
+
return callee && callee.type === 'Import';
|
|
71
55
|
}
|
|
72
56
|
function isCallExpressionArgumentStringLiteralType(
|
|
73
|
-
|
|
57
|
+
callExpressionArguments: CallExpression['arguments'],
|
|
74
58
|
) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
return (
|
|
60
|
+
callExpressionArguments &&
|
|
61
|
+
callExpressionArguments.length &&
|
|
62
|
+
callExpressionArguments[0].type === 'StringLiteral'
|
|
63
|
+
);
|
|
80
64
|
}
|
|
81
65
|
function isCallExpressionArgumentValueMatches(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
callExpressionArgument: CallExpression['arguments'][0],
|
|
67
|
+
j: core.JSCodeshift,
|
|
68
|
+
value: string,
|
|
85
69
|
) {
|
|
86
|
-
|
|
70
|
+
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
87
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { Appearance, SectionMessageProps, SectionMessageActionProps
|
|
1
|
+
export type { Appearance, SectionMessageProps, SectionMessageActionProps } from '../types';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './section-message';
|
|
2
2
|
export { default as SectionMessageAction } from './section-message-action';
|
|
3
|
-
export type { Appearance, SectionMessageProps, SectionMessageActionProps
|
|
3
|
+
export type { Appearance, SectionMessageProps, SectionMessageActionProps } from './types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { Appearance, SectionMessageProps, SectionMessageActionProps
|
|
1
|
+
export type { Appearance, SectionMessageProps, SectionMessageActionProps } from '../types';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './section-message';
|
|
2
2
|
export { default as SectionMessageAction } from './section-message-action';
|
|
3
|
-
export type { Appearance, SectionMessageProps, SectionMessageActionProps
|
|
3
|
+
export type { Appearance, SectionMessageProps, SectionMessageActionProps } from './types';
|