@atlaskit/codemod-cli 0.17.5 → 0.17.7
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 -0
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -5
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -1
- package/dist/cjs/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
- package/dist/cjs/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +10 -38
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -5
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +4 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
- package/dist/es2019/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +9 -36
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -5
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
- package/dist/esm/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +11 -39
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.17.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#61900](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61900) [`101b5d5ef72a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/101b5d5ef72a) - Small changes in mixin migration - Use `token` instead of `theamed` to avoid migration to depricated code
|
|
8
|
+
- [#62187](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/62187) [`03bb58064010`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/03bb58064010) - Added a small bug-fix in button codemods: add TODO comment on default buttons with "link" or "subtle-link" appearance but without `href`
|
|
9
|
+
|
|
10
|
+
## 0.17.6
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#61943](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61943) [`dfdb42df4b4c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dfdb42df4b4c) - Now building the `@atlaskit/tokens` package when during `"prestart"` as tokens is required to be built for some of the patterns to run.
|
|
15
|
+
|
|
3
16
|
## 0.17.5
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/cjs/main.js
CHANGED
|
@@ -305,7 +305,7 @@ function _main() {
|
|
|
305
305
|
case 4:
|
|
306
306
|
_yield$parseArgs = _context5.sent;
|
|
307
307
|
packages = _yield$parseArgs.packages;
|
|
308
|
-
_process$env$_PACKAGE = "0.17.
|
|
308
|
+
_process$env$_PACKAGE = "0.17.7", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
309
309
|
logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
310
310
|
if (packages && packages.length > 0) {
|
|
311
311
|
logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
|
package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -75,12 +75,12 @@ var transformer = function transformer(file, api) {
|
|
|
75
75
|
hasLinkButton = true;
|
|
76
76
|
j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
var linkAppearanceAttribute = attributes.find(function (node) {
|
|
79
79
|
var _node$value, _node$name, _node$value2, _node$value3;
|
|
80
|
-
return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === '
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
(0, _codemodUtils.addCommentBefore)(j,
|
|
80
|
+
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');
|
|
81
|
+
});
|
|
82
|
+
if (!hasHref && linkAppearanceAttribute) {
|
|
83
|
+
(0, _codemodUtils.addCommentBefore)(j, j(linkAppearanceAttribute), _constants.linkButtonMissingHrefComment, 'line');
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
|
|
@@ -50,7 +50,8 @@ var moveSizeAndLabelAttributes = exports.moveSizeAndLabelAttributes = function m
|
|
|
50
50
|
attributes === null || attributes === void 0 || attributes.push(labelAttribute);
|
|
51
51
|
}
|
|
52
52
|
var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
|
|
53
|
-
|
|
53
|
+
var _attribute$value, _attribute$value2;
|
|
54
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
|
|
54
55
|
});
|
|
55
56
|
if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
|
|
56
57
|
sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
|
|
@@ -16,7 +16,7 @@ var migrateFitContainerIconButton = exports.migrateFitContainerIconButton = func
|
|
|
16
16
|
return path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby');
|
|
17
17
|
}));
|
|
18
18
|
var migratedToIconButton;
|
|
19
|
-
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === '
|
|
19
|
+
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
|
|
20
20
|
migratedToIconButton = false;
|
|
21
21
|
var label = labelAttribute.value.value;
|
|
22
22
|
var formattedLabel = "".concat(label.charAt(0).toUpperCase()).concat(label.slice(1)).split('-').join(' ');
|
|
@@ -16,15 +16,10 @@ function insertTokenImport(j, source) {
|
|
|
16
16
|
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
17
17
|
source.get().node.program.body.unshift(newImport);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
|
|
24
|
-
source.get().node.program.body.unshift(newImport);
|
|
25
|
-
}
|
|
26
|
-
function buildToken(j, tokenId, node) {
|
|
27
|
-
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
19
|
+
function buildToken(j) {
|
|
20
|
+
var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
21
|
+
var node = arguments.length > 2 ? arguments[2] : undefined;
|
|
22
|
+
var callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
|
|
28
23
|
return callExpr;
|
|
29
24
|
}
|
|
30
25
|
function isDecendantOfTokenMethod(j, path) {
|
|
@@ -37,12 +32,6 @@ function isDecendantOfTokenMethod(j, path) {
|
|
|
37
32
|
var isDeprecatedApi = function isDeprecatedApi(identifierName) {
|
|
38
33
|
return Object.keys(_replacements.colorReplacements).includes(identifierName);
|
|
39
34
|
};
|
|
40
|
-
function buildThemedNode(j) {
|
|
41
|
-
var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
-
var fallbackLight = arguments.length > 2 ? arguments[2] : undefined;
|
|
43
|
-
var fallbackDark = arguments.length > 3 ? arguments[3] : undefined;
|
|
44
|
-
return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
|
|
45
|
-
}
|
|
46
35
|
function replaceIdentifiers(j, source, specifier) {
|
|
47
36
|
var importSpecifierLocal = specifier.value.local.name;
|
|
48
37
|
var importSpecifierImported = specifier.value.imported.name;
|
|
@@ -67,22 +56,13 @@ function replaceIdentifiers(j, source, specifier) {
|
|
|
67
56
|
var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
68
57
|
insertTokenImport(j, source);
|
|
69
58
|
(0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
|
|
70
|
-
|
|
71
|
-
// Requires themed function
|
|
72
59
|
if (isDynamicReplacement) {
|
|
73
|
-
var
|
|
74
|
-
insertThemedImport(j, source);
|
|
75
|
-
(0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
|
|
76
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
77
|
-
var callExpression = identifier.parent;
|
|
78
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
60
|
+
var token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
|
|
81
61
|
if (isDecendantOfToken) {
|
|
82
|
-
tokenParentNode.replace(
|
|
62
|
+
tokenParentNode.replace(token);
|
|
83
63
|
return;
|
|
84
64
|
}
|
|
85
|
-
identifier.replace(
|
|
65
|
+
(isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
|
|
86
66
|
return;
|
|
87
67
|
}
|
|
88
68
|
if (!isDecendantOfToken && replacement.tokenId) {
|
|
@@ -115,21 +95,13 @@ function replaceMemberExpressions(j, source, specifier) {
|
|
|
115
95
|
}).get();
|
|
116
96
|
var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
117
97
|
insertTokenImport(j, source);
|
|
118
|
-
|
|
119
|
-
// Requires themed function
|
|
120
98
|
if (isDynamicReplacement) {
|
|
121
|
-
var
|
|
122
|
-
insertThemedImport(j, source);
|
|
123
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
124
|
-
var callExpression = identifier.parent.parent;
|
|
125
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
99
|
+
var token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
|
|
128
100
|
if (isDecendantOfToken) {
|
|
129
|
-
tokenParentNode.replace(
|
|
101
|
+
tokenParentNode.replace(token);
|
|
130
102
|
return;
|
|
131
103
|
}
|
|
132
|
-
memberExpression.replace(
|
|
104
|
+
(isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
|
|
133
105
|
return;
|
|
134
106
|
}
|
|
135
107
|
if (!isDecendantOfToken && replacement.tokenId) {
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -61,12 +61,12 @@ const transformer = (file, api) => {
|
|
|
61
61
|
hasLinkButton = true;
|
|
62
62
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
const linkAppearanceAttribute = attributes.find(node => {
|
|
65
65
|
var _node$value, _node$name, _node$value2, _node$value3;
|
|
66
|
-
return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === '
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
addCommentBefore(j,
|
|
66
|
+
return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'StringLiteral' && (node === null || node === void 0 ? void 0 : (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.name) === 'appearance' && ((node === null || node === void 0 ? void 0 : (_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.value) === 'link' || (node === null || node === void 0 ? void 0 : (_node$value3 = node.value) === null || _node$value3 === void 0 ? void 0 : _node$value3.value) === 'subtle-link');
|
|
67
|
+
});
|
|
68
|
+
if (!hasHref && linkAppearanceAttribute) {
|
|
69
|
+
addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -38,7 +38,10 @@ export const moveSizeAndLabelAttributes = (element, j, iconRenamed = false) => {
|
|
|
38
38
|
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
|
|
39
39
|
attributes === null || attributes === void 0 ? void 0 : attributes.push(labelAttribute);
|
|
40
40
|
}
|
|
41
|
-
const sizeAttribute = iconJSXElementAttributes.find(attribute =>
|
|
41
|
+
const sizeAttribute = iconJSXElementAttributes.find(attribute => {
|
|
42
|
+
var _attribute$value, _attribute$value2;
|
|
43
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
|
|
44
|
+
});
|
|
42
45
|
if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
|
|
43
46
|
sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : `UNSAFE_${iconAttr.name.name}_size`;
|
|
44
47
|
attributes === null || attributes === void 0 ? void 0 : attributes.push(sizeAttribute);
|
package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js
CHANGED
|
@@ -10,7 +10,7 @@ export const migrateFitContainerIconButton = (element, j) => {
|
|
|
10
10
|
const iconElement = iconAttrs && iconAttrs[0] && getIconElement(iconAttrs[0]);
|
|
11
11
|
const labelAttribute = iconElement && Array.isArray(iconElement.openingElement.attributes) && ((_iconElement$openingE = iconElement.openingElement) === null || _iconElement$openingE === void 0 ? void 0 : _iconElement$openingE.attributes.find(path => path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby')));
|
|
12
12
|
let migratedToIconButton;
|
|
13
|
-
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === '
|
|
13
|
+
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
|
|
14
14
|
migratedToIconButton = false;
|
|
15
15
|
const label = labelAttribute.value.value;
|
|
16
16
|
const formattedLabel = `${label.charAt(0).toUpperCase()}${label.slice(1)}`.split('-').join(' ');
|
package/dist/es2019/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasImportDeclaration,
|
|
1
|
+
import { hasImportDeclaration, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
|
|
2
2
|
import { colorReplacements } from './utils/replacements';
|
|
3
3
|
function isDecendantOfType(j, path, type) {
|
|
4
4
|
return j(path).closest(type).length > 0;
|
|
@@ -10,15 +10,8 @@ function insertTokenImport(j, source) {
|
|
|
10
10
|
const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
11
11
|
source.get().node.program.body.unshift(newImport);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
|
|
18
|
-
source.get().node.program.body.unshift(newImport);
|
|
19
|
-
}
|
|
20
|
-
function buildToken(j, tokenId, node) {
|
|
21
|
-
const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
13
|
+
function buildToken(j, tokenId = '', node) {
|
|
14
|
+
const callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
|
|
22
15
|
return callExpr;
|
|
23
16
|
}
|
|
24
17
|
function isDecendantOfTokenMethod(j, path) {
|
|
@@ -29,9 +22,6 @@ function isDecendantOfTokenMethod(j, path) {
|
|
|
29
22
|
}).length > 0;
|
|
30
23
|
}
|
|
31
24
|
const isDeprecatedApi = identifierName => Object.keys(colorReplacements).includes(identifierName);
|
|
32
|
-
function buildThemedNode(j, tokenId = '', fallbackLight, fallbackDark) {
|
|
33
|
-
return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
|
|
34
|
-
}
|
|
35
25
|
function replaceIdentifiers(j, source, specifier) {
|
|
36
26
|
const importSpecifierLocal = specifier.value.local.name;
|
|
37
27
|
const importSpecifierImported = specifier.value.imported.name;
|
|
@@ -50,22 +40,13 @@ function replaceIdentifiers(j, source, specifier) {
|
|
|
50
40
|
const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
51
41
|
insertTokenImport(j, source);
|
|
52
42
|
insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
|
|
53
|
-
|
|
54
|
-
// Requires themed function
|
|
55
43
|
if (isDynamicReplacement) {
|
|
56
|
-
const
|
|
57
|
-
insertThemedImport(j, source);
|
|
58
|
-
insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
|
|
59
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
60
|
-
const callExpression = identifier.parent;
|
|
61
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
44
|
+
const token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
|
|
64
45
|
if (isDecendantOfToken) {
|
|
65
|
-
tokenParentNode.replace(
|
|
46
|
+
tokenParentNode.replace(token);
|
|
66
47
|
return;
|
|
67
48
|
}
|
|
68
|
-
identifier.replace(
|
|
49
|
+
(isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
|
|
69
50
|
return;
|
|
70
51
|
}
|
|
71
52
|
if (!isDecendantOfToken && replacement.tokenId) {
|
|
@@ -96,21 +77,13 @@ function replaceMemberExpressions(j, source, specifier) {
|
|
|
96
77
|
}).get();
|
|
97
78
|
const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
98
79
|
insertTokenImport(j, source);
|
|
99
|
-
|
|
100
|
-
// Requires themed function
|
|
101
80
|
if (isDynamicReplacement) {
|
|
102
|
-
const
|
|
103
|
-
insertThemedImport(j, source);
|
|
104
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
105
|
-
const callExpression = identifier.parent.parent;
|
|
106
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
81
|
+
const token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
|
|
109
82
|
if (isDecendantOfToken) {
|
|
110
|
-
tokenParentNode.replace(
|
|
83
|
+
tokenParentNode.replace(token);
|
|
111
84
|
return;
|
|
112
85
|
}
|
|
113
|
-
memberExpression.replace(
|
|
86
|
+
(isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
|
|
114
87
|
return;
|
|
115
88
|
}
|
|
116
89
|
if (!isDecendantOfToken && replacement.tokenId) {
|
package/dist/esm/main.js
CHANGED
|
@@ -298,7 +298,7 @@ function _main() {
|
|
|
298
298
|
case 4:
|
|
299
299
|
_yield$parseArgs = _context5.sent;
|
|
300
300
|
packages = _yield$parseArgs.packages;
|
|
301
|
-
_process$env$_PACKAGE = "0.17.
|
|
301
|
+
_process$env$_PACKAGE = "0.17.7", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
302
302
|
logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
303
303
|
if (packages && packages.length > 0) {
|
|
304
304
|
logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
|
package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -69,12 +69,12 @@ var transformer = function transformer(file, api) {
|
|
|
69
69
|
hasLinkButton = true;
|
|
70
70
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
var linkAppearanceAttribute = attributes.find(function (node) {
|
|
73
73
|
var _node$value, _node$name, _node$value2, _node$value3;
|
|
74
|
-
return node.type === 'JSXAttribute' && ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === '
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
addCommentBefore(j,
|
|
74
|
+
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');
|
|
75
|
+
});
|
|
76
|
+
if (!hasHref && linkAppearanceAttribute) {
|
|
77
|
+
addCommentBefore(j, j(linkAppearanceAttribute), linkButtonMissingHrefComment, 'line');
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
@@ -44,7 +44,8 @@ export var moveSizeAndLabelAttributes = function moveSizeAndLabelAttributes(elem
|
|
|
44
44
|
attributes === null || attributes === void 0 || attributes.push(labelAttribute);
|
|
45
45
|
}
|
|
46
46
|
var sizeAttribute = iconJSXElementAttributes.find(function (attribute) {
|
|
47
|
-
|
|
47
|
+
var _attribute$value, _attribute$value2;
|
|
48
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === 'size' && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && ((_attribute$value2 = attribute.value) === null || _attribute$value2 === void 0 ? void 0 : _attribute$value2.value) !== 'medium';
|
|
48
49
|
});
|
|
49
50
|
if (sizeAttribute && sizeAttribute.type === 'JSXAttribute') {
|
|
50
51
|
sizeAttribute.name.name = iconRenamed ? 'UNSAFE_size' : "UNSAFE_".concat(iconAttr.name.name, "_size");
|
|
@@ -10,7 +10,7 @@ export var migrateFitContainerIconButton = function migrateFitContainerIconButto
|
|
|
10
10
|
return path.type === 'JSXAttribute' && (path.name.name === 'label' || path.name.name === 'aria-label' || path.name.name === 'aria-labelledby');
|
|
11
11
|
}));
|
|
12
12
|
var migratedToIconButton;
|
|
13
|
-
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === '
|
|
13
|
+
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && ((_labelAttribute$value = labelAttribute.value) === null || _labelAttribute$value === void 0 ? void 0 : _labelAttribute$value.type) === 'StringLiteral' && typeof labelAttribute.value.value === 'string') {
|
|
14
14
|
migratedToIconButton = false;
|
|
15
15
|
var label = labelAttribute.value.value;
|
|
16
16
|
var formattedLabel = "".concat(label.charAt(0).toUpperCase()).concat(label.slice(1)).split('-').join(' ');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasImportDeclaration,
|
|
1
|
+
import { hasImportDeclaration, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
|
|
2
2
|
import { colorReplacements } from './utils/replacements';
|
|
3
3
|
function isDecendantOfType(j, path, type) {
|
|
4
4
|
return j(path).closest(type).length > 0;
|
|
@@ -10,15 +10,10 @@ function insertTokenImport(j, source) {
|
|
|
10
10
|
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
11
11
|
source.get().node.program.body.unshift(newImport);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
|
|
18
|
-
source.get().node.program.body.unshift(newImport);
|
|
19
|
-
}
|
|
20
|
-
function buildToken(j, tokenId, node) {
|
|
21
|
-
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
13
|
+
function buildToken(j) {
|
|
14
|
+
var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
15
|
+
var node = arguments.length > 2 ? arguments[2] : undefined;
|
|
16
|
+
var callExpr = tokenId ? j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean)) : node;
|
|
22
17
|
return callExpr;
|
|
23
18
|
}
|
|
24
19
|
function isDecendantOfTokenMethod(j, path) {
|
|
@@ -31,12 +26,6 @@ function isDecendantOfTokenMethod(j, path) {
|
|
|
31
26
|
var isDeprecatedApi = function isDeprecatedApi(identifierName) {
|
|
32
27
|
return Object.keys(colorReplacements).includes(identifierName);
|
|
33
28
|
};
|
|
34
|
-
function buildThemedNode(j) {
|
|
35
|
-
var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
36
|
-
var fallbackLight = arguments.length > 2 ? arguments[2] : undefined;
|
|
37
|
-
var fallbackDark = arguments.length > 3 ? arguments[3] : undefined;
|
|
38
|
-
return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
|
|
39
|
-
}
|
|
40
29
|
function replaceIdentifiers(j, source, specifier) {
|
|
41
30
|
var importSpecifierLocal = specifier.value.local.name;
|
|
42
31
|
var importSpecifierImported = specifier.value.imported.name;
|
|
@@ -61,22 +50,13 @@ function replaceIdentifiers(j, source, specifier) {
|
|
|
61
50
|
var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
62
51
|
insertTokenImport(j, source);
|
|
63
52
|
insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
|
|
64
|
-
|
|
65
|
-
// Requires themed function
|
|
66
53
|
if (isDynamicReplacement) {
|
|
67
|
-
var
|
|
68
|
-
insertThemedImport(j, source);
|
|
69
|
-
insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
|
|
70
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
71
|
-
var callExpression = identifier.parent;
|
|
72
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
54
|
+
var token = buildToken(j, tokenId, j.identifier(replacement.importSpecifiers[0]));
|
|
75
55
|
if (isDecendantOfToken) {
|
|
76
|
-
tokenParentNode.replace(
|
|
56
|
+
tokenParentNode.replace(token);
|
|
77
57
|
return;
|
|
78
58
|
}
|
|
79
|
-
identifier.replace(
|
|
59
|
+
(isDecendantOfCallExpression ? identifier.parent : identifier).replace(token);
|
|
80
60
|
return;
|
|
81
61
|
}
|
|
82
62
|
if (!isDecendantOfToken && replacement.tokenId) {
|
|
@@ -109,21 +89,13 @@ function replaceMemberExpressions(j, source, specifier) {
|
|
|
109
89
|
}).get();
|
|
110
90
|
var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
|
|
111
91
|
insertTokenImport(j, source);
|
|
112
|
-
|
|
113
|
-
// Requires themed function
|
|
114
92
|
if (isDynamicReplacement) {
|
|
115
|
-
var
|
|
116
|
-
insertThemedImport(j, source);
|
|
117
|
-
if (isDecendantOfToken && isDecendantOfCallExpression) {
|
|
118
|
-
var callExpression = identifier.parent.parent;
|
|
119
|
-
tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
93
|
+
var token = buildToken(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])));
|
|
122
94
|
if (isDecendantOfToken) {
|
|
123
|
-
tokenParentNode.replace(
|
|
95
|
+
tokenParentNode.replace(token);
|
|
124
96
|
return;
|
|
125
97
|
}
|
|
126
|
-
memberExpression.replace(
|
|
98
|
+
(isDecendantOfCallExpression ? memberExpression.parent : memberExpression).replace(token);
|
|
127
99
|
return;
|
|
128
100
|
}
|
|
129
101
|
if (!isDecendantOfToken && replacement.tokenId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/codemod-cli",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.7",
|
|
4
4
|
"description": "A cli for distributing codemods for atlassian-frontend components and services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"releaseModel": "continuous"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"prestart": "cd ../../ && yarn build @atlaskit/codemod-utils",
|
|
28
|
+
"prestart": "cd ../../ && yarn build @atlaskit/codemod-utils tokens",
|
|
29
29
|
"start": "./bin/codemod-cli.js"
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
36
|
-
"@atlaskit/tokens": "^1.
|
|
36
|
+
"@atlaskit/tokens": "^1.30.0",
|
|
37
37
|
"@babel/runtime": "^7.0.0",
|
|
38
38
|
"@codeshift/utils": "^0.2.4",
|
|
39
39
|
"@types/jscodeshift": "^0.11.0",
|