@atlaskit/section-message 8.0.0 → 8.0.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 +14 -0
- package/dist/cjs/internal/appearance-icon.js +1 -2
- package/dist/cjs/section-message-action.compiled.css +1 -1
- package/dist/cjs/section-message-action.js +1 -1
- package/dist/cjs/section-message.compiled.css +1 -1
- package/dist/cjs/section-message.js +1 -1
- package/dist/es2019/internal/appearance-icon.js +1 -1
- package/dist/es2019/section-message-action.compiled.css +1 -1
- package/dist/es2019/section-message-action.js +1 -1
- package/dist/es2019/section-message.compiled.css +1 -1
- package/dist/es2019/section-message.js +1 -1
- package/dist/esm/internal/appearance-icon.js +1 -1
- package/dist/esm/section-message-action.compiled.css +1 -1
- package/dist/esm/section-message-action.js +1 -1
- package/dist/esm/section-message.compiled.css +1 -1
- package/dist/esm/section-message.js +1 -1
- package/dist/types/internal/appearance-icon.d.ts +1 -10
- package/dist/types-ts4.5/internal/appearance-icon.d.ts +1 -10
- package/package.json +13 -11
- package/codemods/6.0.0-lite-mode.tsx +0 -18
- package/codemods/__tests__/6.0.0-lite-mode.tsx +0 -320
- package/codemods/__tests__/change-appearance-prop.tsx +0 -405
- package/codemods/__tests__/map-actions-prop.tsx +0 -580
- package/codemods/internal/change-appearance-prop.tsx +0 -101
- package/codemods/internal/constants.tsx +0 -13
- package/codemods/internal/map-actions-prop.tsx +0 -188
- package/codemods/internal/utils.tsx +0 -71
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ASTPath,
|
|
3
|
-
type default as core,
|
|
4
|
-
type ImportDeclaration,
|
|
5
|
-
type JSXAttribute,
|
|
6
|
-
type JSXElement,
|
|
7
|
-
type JSXExpressionContainer,
|
|
8
|
-
type VariableDeclaration,
|
|
9
|
-
} from 'jscodeshift';
|
|
10
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
addCommentBefore,
|
|
14
|
-
getDefaultSpecifier,
|
|
15
|
-
getJSXAttributesByName,
|
|
16
|
-
} from '@atlaskit/codemod-utils';
|
|
17
|
-
|
|
18
|
-
import {
|
|
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
|
-
} from './constants';
|
|
25
|
-
import { doesIdentifierExist, getDynamicImportName } from './utils';
|
|
26
|
-
|
|
27
|
-
const addSectionMessageActionImportSpecifier = (
|
|
28
|
-
j: core.JSCodeshift,
|
|
29
|
-
source: Collection<Node>,
|
|
30
|
-
name: string,
|
|
31
|
-
) => {
|
|
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
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const addSectionMessageActionDynamicImport = (
|
|
45
|
-
j: core.JSCodeshift,
|
|
46
|
-
target: Collection<VariableDeclaration>,
|
|
47
|
-
name: string,
|
|
48
|
-
) => {
|
|
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
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
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;
|
|
79
|
-
|
|
80
|
-
const linkComponentAttributeValue = linkComponentAttribute?.node?.value;
|
|
81
|
-
|
|
82
|
-
if (linkComponentAttribute) {
|
|
83
|
-
j(linkComponentAttribute).remove();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return linkComponentAttributeValue;
|
|
87
|
-
};
|
|
88
|
-
|
|
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
|
-
}
|
|
188
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { type CallExpression, type default as core } from 'jscodeshift';
|
|
2
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
|
-
|
|
4
|
-
export function doesIdentifierExist({
|
|
5
|
-
j,
|
|
6
|
-
base,
|
|
7
|
-
name,
|
|
8
|
-
}: {
|
|
9
|
-
j: core.JSCodeshift;
|
|
10
|
-
base: Collection<any>;
|
|
11
|
-
name: string;
|
|
12
|
-
}): boolean {
|
|
13
|
-
return base.find(j.Identifier).filter((identifer) => identifer.value.name === name).length > 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function hasDynamicImport(j: core.JSCodeshift, source: Collection<any>, importPath: string) {
|
|
17
|
-
return !!getDynamicImportName(j, source, importPath);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getDynamicImportName(
|
|
21
|
-
j: core.JSCodeshift,
|
|
22
|
-
source: Collection<any>,
|
|
23
|
-
importPath: string,
|
|
24
|
-
) {
|
|
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;
|
|
31
|
-
|
|
32
|
-
return !!(
|
|
33
|
-
isCallExpressionCalleeImportType(callee) &&
|
|
34
|
-
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
35
|
-
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
36
|
-
);
|
|
37
|
-
}).length > 0
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (!dynamicImports.length) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { id } = dynamicImports.nodes()[0];
|
|
46
|
-
|
|
47
|
-
if (id.type !== 'Identifier') {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return id.name;
|
|
52
|
-
}
|
|
53
|
-
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
54
|
-
return callee && callee.type === 'Import';
|
|
55
|
-
}
|
|
56
|
-
function isCallExpressionArgumentStringLiteralType(
|
|
57
|
-
callExpressionArguments: CallExpression['arguments'],
|
|
58
|
-
) {
|
|
59
|
-
return (
|
|
60
|
-
callExpressionArguments &&
|
|
61
|
-
callExpressionArguments.length &&
|
|
62
|
-
callExpressionArguments[0].type === 'StringLiteral'
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
function isCallExpressionArgumentValueMatches(
|
|
66
|
-
callExpressionArgument: CallExpression['arguments'][0],
|
|
67
|
-
j: core.JSCodeshift,
|
|
68
|
-
value: string,
|
|
69
|
-
) {
|
|
70
|
-
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
71
|
-
}
|