@atlaskit/codemod-cli 0.25.1 → 0.25.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 -0
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +19 -2
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +32 -9
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +12 -5
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +13 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +17 -3
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +28 -10
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +11 -4
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +19 -3
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +32 -10
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +11 -4
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +10 -3
- package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +2 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +10 -3
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.25.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#123131](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/123131)
|
|
8
|
+
[`862fb8cdd4b71`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/862fb8cdd4b71) -
|
|
9
|
+
Codemod includes new migration pathways for legacy button
|
|
10
|
+
|
|
3
11
|
## 0.25.1
|
|
4
12
|
|
|
5
13
|
### 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.25.
|
|
308
|
+
_process$env$_PACKAGE = "0.25.2", _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-link-button-to-link.js
CHANGED
|
@@ -6,10 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _utils = require("@hypermod/utils");
|
|
9
|
+
var _codemodUtils = require("@atlaskit/codemod-utils");
|
|
9
10
|
var _constants = require("../utils/constants");
|
|
10
|
-
var _moveIconValueFromLinkButtonToLinkChildren = _interopRequireDefault(require("../utils/move-icon-value-from-link-button-to-link-children"));
|
|
11
11
|
var _findAttributeWithValue = require("../utils/find-attribute-with-value");
|
|
12
12
|
var _generateLinkElement = require("../utils/generate-link-element");
|
|
13
|
+
var _moveIconValueFromLinkButtonToLinkChildren = _interopRequireDefault(require("../utils/move-icon-value-from-link-button-to-link-children"));
|
|
14
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
15
|
+
|
|
13
16
|
function transformer(file, api) {
|
|
14
17
|
var j = api.jscodeshift;
|
|
15
18
|
var source = j(file.source);
|
|
@@ -47,10 +50,24 @@ function transformer(file, api) {
|
|
|
47
50
|
}).forEach(function (path) {
|
|
48
51
|
var hasSpacingNone = (0, _findAttributeWithValue.findJSXAttributeWithValue)(path.value.openingElement, 'spacing', 'none');
|
|
49
52
|
if (!hasSpacingNone) {
|
|
53
|
+
var oldAppearanceValue;
|
|
50
54
|
j(path).find(j.JSXAttribute).filter(function (path) {
|
|
51
55
|
var _path$node$value;
|
|
52
|
-
|
|
56
|
+
if (path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link')) {
|
|
57
|
+
oldAppearanceValue = path.node.value.value;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
53
61
|
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
62
|
+
if (oldAppearanceValue) {
|
|
63
|
+
var _path$value$openingEl;
|
|
64
|
+
var attribute = (_path$value$openingEl = path.value.openingElement.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.find(function (node) {
|
|
65
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
66
|
+
});
|
|
67
|
+
if (attribute) {
|
|
68
|
+
(0, _codemodUtils.addCommentBefore)(j, j(attribute), oldAppearanceValue === 'link' ? _constants.migrateButtonToSubtleLinkButton : _constants.migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
54
71
|
}
|
|
55
72
|
if (hasSpacingNone) {
|
|
56
73
|
var attributes = path.node.openingElement.attributes;
|
package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -6,21 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _codemodUtils = require("@atlaskit/codemod-utils");
|
|
10
9
|
var _utils = require("@hypermod/utils");
|
|
10
|
+
var _codemodUtils = require("@atlaskit/codemod-utils");
|
|
11
|
+
var _addCommentForCustomThemeButtons = require("../utils/add-comment-for-custom-theme-buttons");
|
|
12
|
+
var _addCommentForOverlayProp = require("../utils/add-comment-for-overlay-prop");
|
|
11
13
|
var _constants = require("../utils/constants");
|
|
14
|
+
var _findAttributeWithValue = require("../utils/find-attribute-with-value");
|
|
15
|
+
var _generateLinkElement = require("../utils/generate-link-element");
|
|
16
|
+
var _generateNewButtonElement = require("../utils/generate-new-button-element");
|
|
12
17
|
var _getDefaultImports = _interopRequireDefault(require("../utils/get-default-imports"));
|
|
13
18
|
var _getSpecifierNames = _interopRequireDefault(require("../utils/get-specifier-names"));
|
|
14
|
-
var _generateNewButtonElement = require("../utils/generate-new-button-element");
|
|
15
|
-
var _generateLinkElement = require("../utils/generate-link-element");
|
|
16
19
|
var _hasUnsupportedProps = require("../utils/has-unsupported-props");
|
|
17
20
|
var _ifVariantAlreadyImported = require("../utils/if-variant-already-imported");
|
|
18
|
-
var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
|
|
19
|
-
var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
|
|
20
21
|
var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
|
|
23
|
+
var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
|
|
24
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
25
|
+
|
|
24
26
|
var transformer = function transformer(file, api) {
|
|
25
27
|
var j = api.jscodeshift;
|
|
26
28
|
var fileSource = j(file.source);
|
|
@@ -111,8 +113,22 @@ var transformer = function transformer(file, api) {
|
|
|
111
113
|
j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
112
114
|
}
|
|
113
115
|
if (isLinkButton && !isLoadingButton) {
|
|
116
|
+
var _element$node$attribu;
|
|
114
117
|
hasVariant.linkButton = true;
|
|
115
118
|
j(element).replaceWith((0, _generateNewButtonElement.generateNewElement)(_constants.NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
119
|
+
var attribute = (_element$node$attribu = element.node.attributes) === null || _element$node$attribu === void 0 ? void 0 : _element$node$attribu.find(function (node) {
|
|
120
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
121
|
+
});
|
|
122
|
+
if (attribute) {
|
|
123
|
+
var _linkAppearanceAttrib;
|
|
124
|
+
if ((linkAppearanceAttribute === null || linkAppearanceAttribute === void 0 ? void 0 : linkAppearanceAttribute.type) === 'JSXAttribute' && ((_linkAppearanceAttrib = linkAppearanceAttribute.value) === null || _linkAppearanceAttrib === void 0 ? void 0 : _linkAppearanceAttrib.type) === 'StringLiteral') {
|
|
125
|
+
if (linkAppearanceAttribute.value.value === 'link') {
|
|
126
|
+
(0, _codemodUtils.addCommentBefore)(j, j(attribute), _constants.migrateButtonToSubtleLinkButton, 'line');
|
|
127
|
+
} else if (linkAppearanceAttribute.value.value === 'subtle-link') {
|
|
128
|
+
(0, _codemodUtils.addCommentBefore)(j, j(attribute), _constants.migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
116
132
|
}
|
|
117
133
|
if (isLink && !isLoadingButton) {
|
|
118
134
|
hasVariant.link = true;
|
|
@@ -166,7 +182,14 @@ var transformer = function transformer(file, api) {
|
|
|
166
182
|
}), 'block');
|
|
167
183
|
}
|
|
168
184
|
} else if (!hasHref && linkAppearanceAttribute) {
|
|
169
|
-
|
|
185
|
+
var _element$node$attribu2;
|
|
186
|
+
(0, _generateNewButtonElement.modifyButtonAttributes)(element.node, j, hasSpacingNone);
|
|
187
|
+
var _attribute = (_element$node$attribu2 = element.node.attributes) === null || _element$node$attribu2 === void 0 ? void 0 : _element$node$attribu2.find(function (node) {
|
|
188
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
189
|
+
});
|
|
190
|
+
if (_attribute) {
|
|
191
|
+
(0, _codemodUtils.addCommentBefore)(j, j(_attribute), hasSpacingNone ? _constants.noSpacinglinkButtonMissingHrefComment : _constants.linkButtonMissingHrefComment, 'line');
|
|
192
|
+
}
|
|
170
193
|
}
|
|
171
194
|
});
|
|
172
195
|
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.unsupportedProps = exports.overlayPropComment = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
|
|
6
|
+
exports.unsupportedProps = exports.overlayPropComment = exports.noSpacinglinkButtonMissingHrefComment = exports.migrateSubtleButtonToSubtleLinkButton = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.migrateButtonToSubtleLinkButton = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
|
|
7
7
|
var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
|
|
8
8
|
quote: 'single'
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* NEW button *
|
|
13
|
+
*/
|
|
12
14
|
var NEW_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
13
15
|
var NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_VARIANTS = {
|
|
14
16
|
default: 'Button',
|
|
@@ -17,7 +19,9 @@ var NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_VARIANTS = {
|
|
|
17
19
|
linkIcon: 'LinkIconButton'
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* OLD button *
|
|
24
|
+
*/
|
|
21
25
|
var OLD_BUTTON_ENTRY_POINT = exports.OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
22
26
|
var OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_VARIANTS = {
|
|
23
27
|
loading: 'LoadingButton'
|
|
@@ -35,7 +39,8 @@ var UNSAFE_SIZE_PROPS_MAP = exports.UNSAFE_SIZE_PROPS_MAP = {
|
|
|
35
39
|
UNSAFE_iconBefore_size: 'iconBefore'
|
|
36
40
|
};
|
|
37
41
|
var unsupportedProps = exports.unsupportedProps = ['component', 'css', 'style'];
|
|
38
|
-
var linkButtonMissingHrefComment = exports.linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are
|
|
42
|
+
var linkButtonMissingHrefComment = exports.linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\".";
|
|
43
|
+
var noSpacinglinkButtonMissingHrefComment = exports.noSpacinglinkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\", or provide a href prop then migrate to Link.";
|
|
39
44
|
var buttonPropsNoLongerSupportedComment = exports.buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
40
45
|
var migrateFitContainerButtonToDefaultButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
41
46
|
var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
@@ -45,4 +50,6 @@ var loadingButtonComment = exports.loadingButtonComment = function loadingButton
|
|
|
45
50
|
var hasLinkAppearance = _ref.hasLinkAppearance,
|
|
46
51
|
hasHref = _ref.hasHref;
|
|
47
52
|
return "This should be migrated to a new Button with a `isLoading` prop. ".concat(hasLinkAppearance ? "\"link\" and \"subtle-link\" appearances are not available for new loading buttons.\"" : '').concat(hasHref ? "The `href` attribute it not compatible with new loading buttons, because links should not need loading states." : '', " Please reconsider the design or change the appearance of the button.");
|
|
48
|
-
};
|
|
53
|
+
};
|
|
54
|
+
var migrateButtonToSubtleLinkButton = exports.migrateButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"default\" appearance.";
|
|
55
|
+
var migrateSubtleButtonToSubtleLinkButton = exports.migrateSubtleButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"subtle\" appearance.";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.handleIconAttributes = exports.getIconElement = exports.getIconAttributes = exports.generateNewElement = void 0;
|
|
6
|
+
exports.modifyButtonAttributes = exports.handleIconAttributes = exports.getIconElement = exports.getIconAttributes = exports.generateNewElement = void 0;
|
|
7
7
|
var _constants = require("../utils/constants");
|
|
8
8
|
var getIconAttributes = exports.getIconAttributes = function getIconAttributes(attributes) {
|
|
9
9
|
var iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
|
|
@@ -145,4 +145,16 @@ var generateNewElement = exports.generateNewElement = function generateNewElemen
|
|
|
145
145
|
closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
|
|
146
146
|
children: element.children
|
|
147
147
|
});
|
|
148
|
+
};
|
|
149
|
+
var modifyButtonAttributes = exports.modifyButtonAttributes = function modifyButtonAttributes(element, j, hasSpacingNone) {
|
|
150
|
+
j(element).find(j.JSXAttribute).filter(function (path) {
|
|
151
|
+
var _path$node$value2;
|
|
152
|
+
return path.node.name.name === 'appearance' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
|
|
153
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
154
|
+
if (hasSpacingNone) {
|
|
155
|
+
j(element).find(j.JSXAttribute).filter(function (path) {
|
|
156
|
+
var _path$node$value3;
|
|
157
|
+
return path.node.name.name === 'spacing' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
158
|
+
}).remove();
|
|
159
|
+
}
|
|
148
160
|
};
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
1
2
|
import { getImportDeclaration } from '@hypermod/utils';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, PRINT_SETTINGS } from '../utils/constants';
|
|
4
5
|
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
5
6
|
import { modifyLinkAttributes } from '../utils/generate-link-element';
|
|
7
|
+
import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
|
|
6
8
|
function transformer(file, api) {
|
|
7
9
|
const j = api.jscodeshift;
|
|
8
10
|
const source = j(file.source);
|
|
@@ -36,10 +38,22 @@ function transformer(file, api) {
|
|
|
36
38
|
allLinkButtons.filter(path => findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'link') || findJSXAttributeWithValue(path.value.openingElement, 'appearance', 'subtle-link')).forEach(path => {
|
|
37
39
|
const hasSpacingNone = findJSXAttributeWithValue(path.value.openingElement, 'spacing', 'none');
|
|
38
40
|
if (!hasSpacingNone) {
|
|
41
|
+
let oldAppearanceValue;
|
|
39
42
|
j(path).find(j.JSXAttribute).filter(path => {
|
|
40
43
|
var _path$node$value;
|
|
41
|
-
|
|
44
|
+
if (path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link')) {
|
|
45
|
+
oldAppearanceValue = path.node.value.value;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
42
49
|
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
50
|
+
if (oldAppearanceValue) {
|
|
51
|
+
var _path$value$openingEl;
|
|
52
|
+
const attribute = (_path$value$openingEl = path.value.openingElement.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.find(node => node.type === 'JSXAttribute' && node.name.name === 'appearance');
|
|
53
|
+
if (attribute) {
|
|
54
|
+
addCommentBefore(j, j(attribute), oldAppearanceValue === 'link' ? migrateButtonToSubtleLinkButton : migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
43
57
|
}
|
|
44
58
|
if (hasSpacingNone) {
|
|
45
59
|
const {
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
2
|
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
5
|
+
import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
|
|
6
|
+
import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
|
|
7
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
8
|
+
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
9
|
+
import { generateNewElement, handleIconAttributes, modifyButtonAttributes } from '../utils/generate-new-button-element';
|
|
4
10
|
import getDefaultImports from '../utils/get-default-imports';
|
|
5
11
|
import getSpecifierNames from '../utils/get-specifier-names';
|
|
6
|
-
import { generateNewElement, handleIconAttributes } from '../utils/generate-new-button-element';
|
|
7
|
-
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
8
12
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
9
13
|
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
10
|
-
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
11
|
-
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
12
14
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
15
|
+
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
16
|
+
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
16
17
|
const transformer = (file, api) => {
|
|
17
18
|
const j = api.jscodeshift;
|
|
18
19
|
const fileSource = j(file.source);
|
|
@@ -97,8 +98,20 @@ const transformer = (file, api) => {
|
|
|
97
98
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
98
99
|
}
|
|
99
100
|
if (isLinkButton && !isLoadingButton) {
|
|
101
|
+
var _element$node$attribu;
|
|
100
102
|
hasVariant.linkButton = true;
|
|
101
103
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
104
|
+
const attribute = (_element$node$attribu = element.node.attributes) === null || _element$node$attribu === void 0 ? void 0 : _element$node$attribu.find(node => node.type === 'JSXAttribute' && node.name.name === 'appearance');
|
|
105
|
+
if (attribute) {
|
|
106
|
+
var _linkAppearanceAttrib;
|
|
107
|
+
if ((linkAppearanceAttribute === null || linkAppearanceAttribute === void 0 ? void 0 : linkAppearanceAttribute.type) === 'JSXAttribute' && ((_linkAppearanceAttrib = linkAppearanceAttribute.value) === null || _linkAppearanceAttrib === void 0 ? void 0 : _linkAppearanceAttrib.type) === 'StringLiteral') {
|
|
108
|
+
if (linkAppearanceAttribute.value.value === 'link') {
|
|
109
|
+
addCommentBefore(j, j(attribute), migrateButtonToSubtleLinkButton, 'line');
|
|
110
|
+
} else if (linkAppearanceAttribute.value.value === 'subtle-link') {
|
|
111
|
+
addCommentBefore(j, j(attribute), migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
102
115
|
}
|
|
103
116
|
if (isLink && !isLoadingButton) {
|
|
104
117
|
hasVariant.link = true;
|
|
@@ -148,7 +161,12 @@ const transformer = (file, api) => {
|
|
|
148
161
|
}), 'block');
|
|
149
162
|
}
|
|
150
163
|
} else if (!hasHref && linkAppearanceAttribute) {
|
|
151
|
-
|
|
164
|
+
var _element$node$attribu2;
|
|
165
|
+
modifyButtonAttributes(element.node, j, hasSpacingNone);
|
|
166
|
+
const attribute = (_element$node$attribu2 = element.node.attributes) === null || _element$node$attribu2 === void 0 ? void 0 : _element$node$attribu2.find(node => node.type === 'JSXAttribute' && node.name.name === 'appearance');
|
|
167
|
+
if (attribute) {
|
|
168
|
+
addCommentBefore(j, j(attribute), hasSpacingNone ? noSpacinglinkButtonMissingHrefComment : linkButtonMissingHrefComment, 'line');
|
|
169
|
+
}
|
|
152
170
|
}
|
|
153
171
|
});
|
|
154
172
|
|
|
@@ -2,7 +2,9 @@ export const PRINT_SETTINGS = {
|
|
|
2
2
|
quote: 'single'
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* NEW button *
|
|
7
|
+
*/
|
|
6
8
|
export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
7
9
|
export const NEW_BUTTON_VARIANTS = {
|
|
8
10
|
default: 'Button',
|
|
@@ -11,7 +13,9 @@ export const NEW_BUTTON_VARIANTS = {
|
|
|
11
13
|
linkIcon: 'LinkIconButton'
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* OLD button *
|
|
18
|
+
*/
|
|
15
19
|
export const OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
16
20
|
export const OLD_BUTTON_VARIANTS = {
|
|
17
21
|
loading: 'LoadingButton'
|
|
@@ -29,7 +33,8 @@ export const UNSAFE_SIZE_PROPS_MAP = {
|
|
|
29
33
|
UNSAFE_iconBefore_size: 'iconBefore'
|
|
30
34
|
};
|
|
31
35
|
export const unsupportedProps = ['component', 'css', 'style'];
|
|
32
|
-
export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are
|
|
36
|
+
export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are not available in the new Button, appearance should be "subtle" or "default".`;
|
|
37
|
+
export const noSpacinglinkButtonMissingHrefComment = `"link" and "subtle-link" appearances are not available in the new Button, appearance should be "subtle" or "default", or provide a href prop then migrate to Link.`;
|
|
33
38
|
export const buttonPropsNoLongerSupportedComment = `Buttons with "component", "css" or "style" prop can't be automatically migrated with codemods. Please migrate it manually.`;
|
|
34
39
|
export const migrateFitContainerButtonToDefaultButtonComment = `Migrated to a default button with text which is from the icon label.`;
|
|
35
40
|
export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
|
|
@@ -40,4 +45,6 @@ export const loadingButtonComment = ({
|
|
|
40
45
|
hasHref
|
|
41
46
|
}) => {
|
|
42
47
|
return `This should be migrated to a new Button with a \`isLoading\` prop. ${hasLinkAppearance ? `"link" and "subtle-link" appearances are not available for new loading buttons."` : ''}${hasHref ? `The \`href\` attribute it not compatible with new loading buttons, because links should not need loading states.` : ''} Please reconsider the design or change the appearance of the button.`;
|
|
43
|
-
};
|
|
48
|
+
};
|
|
49
|
+
export const migrateButtonToSubtleLinkButton = `"link" and "subtle-link" appearances are not available in the new Button. Appearance should be migrated to "subtle" or "default" for Link Button, or use Link with "default" appearance.`;
|
|
50
|
+
export const migrateSubtleButtonToSubtleLinkButton = `"link" and "subtle-link" appearances are not available in the new Button. Appearance should be migrated to "subtle" or "default" for Link Button, or use Link with "subtle" appearance.`;
|
|
@@ -128,4 +128,16 @@ export const generateNewElement = (variant, element, j) => {
|
|
|
128
128
|
closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
|
|
129
129
|
children: element.children
|
|
130
130
|
});
|
|
131
|
+
};
|
|
132
|
+
export const modifyButtonAttributes = (element, j, hasSpacingNone) => {
|
|
133
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
134
|
+
var _path$node$value2;
|
|
135
|
+
return path.node.name.name === 'appearance' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
|
|
136
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
137
|
+
if (hasSpacingNone) {
|
|
138
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
139
|
+
var _path$node$value3;
|
|
140
|
+
return path.node.name.name === 'spacing' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
141
|
+
}).remove();
|
|
142
|
+
}
|
|
131
143
|
};
|
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.25.
|
|
301
|
+
_process$env$_PACKAGE = "0.25.2", _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-link-button-to-link.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
1
2
|
import { getImportDeclaration } from '@hypermod/utils';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, PRINT_SETTINGS } from '../utils/constants';
|
|
4
5
|
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
5
6
|
import { modifyLinkAttributes } from '../utils/generate-link-element';
|
|
7
|
+
import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
|
|
6
8
|
function transformer(file, api) {
|
|
7
9
|
var j = api.jscodeshift;
|
|
8
10
|
var source = j(file.source);
|
|
@@ -40,10 +42,24 @@ function transformer(file, api) {
|
|
|
40
42
|
}).forEach(function (path) {
|
|
41
43
|
var hasSpacingNone = findJSXAttributeWithValue(path.value.openingElement, 'spacing', 'none');
|
|
42
44
|
if (!hasSpacingNone) {
|
|
45
|
+
var oldAppearanceValue;
|
|
43
46
|
j(path).find(j.JSXAttribute).filter(function (path) {
|
|
44
47
|
var _path$node$value;
|
|
45
|
-
|
|
48
|
+
if (path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link')) {
|
|
49
|
+
oldAppearanceValue = path.node.value.value;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
46
53
|
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
54
|
+
if (oldAppearanceValue) {
|
|
55
|
+
var _path$value$openingEl;
|
|
56
|
+
var attribute = (_path$value$openingEl = path.value.openingElement.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.find(function (node) {
|
|
57
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
58
|
+
});
|
|
59
|
+
if (attribute) {
|
|
60
|
+
addCommentBefore(j, j(attribute), oldAppearanceValue === 'link' ? migrateButtonToSubtleLinkButton : migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
47
63
|
}
|
|
48
64
|
if (hasSpacingNone) {
|
|
49
65
|
var attributes = path.node.openingElement.attributes;
|
package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
|
|
2
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
3
3
|
import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
5
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
6
|
+
import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
|
|
7
|
+
import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
|
|
8
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
9
|
+
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
10
|
+
import { generateNewElement, handleIconAttributes, modifyButtonAttributes } from '../utils/generate-new-button-element';
|
|
5
11
|
import getDefaultImports from '../utils/get-default-imports';
|
|
6
12
|
import getSpecifierNames from '../utils/get-specifier-names';
|
|
7
|
-
import { generateNewElement, handleIconAttributes } from '../utils/generate-new-button-element';
|
|
8
|
-
import { generateLinkComponent } from '../utils/generate-link-element';
|
|
9
13
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
10
14
|
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
11
|
-
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
12
|
-
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
13
15
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
16
|
+
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
17
|
+
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
17
18
|
var transformer = function transformer(file, api) {
|
|
18
19
|
var j = api.jscodeshift;
|
|
19
20
|
var fileSource = j(file.source);
|
|
@@ -104,8 +105,22 @@ var transformer = function transformer(file, api) {
|
|
|
104
105
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon, element.value, j));
|
|
105
106
|
}
|
|
106
107
|
if (isLinkButton && !isLoadingButton) {
|
|
108
|
+
var _element$node$attribu;
|
|
107
109
|
hasVariant.linkButton = true;
|
|
108
110
|
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link, element.value, j));
|
|
111
|
+
var attribute = (_element$node$attribu = element.node.attributes) === null || _element$node$attribu === void 0 ? void 0 : _element$node$attribu.find(function (node) {
|
|
112
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
113
|
+
});
|
|
114
|
+
if (attribute) {
|
|
115
|
+
var _linkAppearanceAttrib;
|
|
116
|
+
if ((linkAppearanceAttribute === null || linkAppearanceAttribute === void 0 ? void 0 : linkAppearanceAttribute.type) === 'JSXAttribute' && ((_linkAppearanceAttrib = linkAppearanceAttribute.value) === null || _linkAppearanceAttrib === void 0 ? void 0 : _linkAppearanceAttrib.type) === 'StringLiteral') {
|
|
117
|
+
if (linkAppearanceAttribute.value.value === 'link') {
|
|
118
|
+
addCommentBefore(j, j(attribute), migrateButtonToSubtleLinkButton, 'line');
|
|
119
|
+
} else if (linkAppearanceAttribute.value.value === 'subtle-link') {
|
|
120
|
+
addCommentBefore(j, j(attribute), migrateSubtleButtonToSubtleLinkButton, 'line');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
109
124
|
}
|
|
110
125
|
if (isLink && !isLoadingButton) {
|
|
111
126
|
hasVariant.link = true;
|
|
@@ -159,7 +174,14 @@ var transformer = function transformer(file, api) {
|
|
|
159
174
|
}), 'block');
|
|
160
175
|
}
|
|
161
176
|
} else if (!hasHref && linkAppearanceAttribute) {
|
|
162
|
-
|
|
177
|
+
var _element$node$attribu2;
|
|
178
|
+
modifyButtonAttributes(element.node, j, hasSpacingNone);
|
|
179
|
+
var _attribute = (_element$node$attribu2 = element.node.attributes) === null || _element$node$attribu2 === void 0 ? void 0 : _element$node$attribu2.find(function (node) {
|
|
180
|
+
return node.type === 'JSXAttribute' && node.name.name === 'appearance';
|
|
181
|
+
});
|
|
182
|
+
if (_attribute) {
|
|
183
|
+
addCommentBefore(j, j(_attribute), hasSpacingNone ? noSpacinglinkButtonMissingHrefComment : linkButtonMissingHrefComment, 'line');
|
|
184
|
+
}
|
|
163
185
|
}
|
|
164
186
|
});
|
|
165
187
|
|
|
@@ -2,7 +2,9 @@ export var PRINT_SETTINGS = {
|
|
|
2
2
|
quote: 'single'
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* NEW button *
|
|
7
|
+
*/
|
|
6
8
|
export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/new';
|
|
7
9
|
export var NEW_BUTTON_VARIANTS = {
|
|
8
10
|
default: 'Button',
|
|
@@ -11,7 +13,9 @@ export var NEW_BUTTON_VARIANTS = {
|
|
|
11
13
|
linkIcon: 'LinkIconButton'
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* OLD button *
|
|
18
|
+
*/
|
|
15
19
|
export var OLD_BUTTON_ENTRY_POINT = '@atlaskit/button';
|
|
16
20
|
export var OLD_BUTTON_VARIANTS = {
|
|
17
21
|
loading: 'LoadingButton'
|
|
@@ -29,7 +33,8 @@ export var UNSAFE_SIZE_PROPS_MAP = {
|
|
|
29
33
|
UNSAFE_iconBefore_size: 'iconBefore'
|
|
30
34
|
};
|
|
31
35
|
export var unsupportedProps = ['component', 'css', 'style'];
|
|
32
|
-
export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are
|
|
36
|
+
export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\".";
|
|
37
|
+
export var noSpacinglinkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\", or provide a href prop then migrate to Link.";
|
|
33
38
|
export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
34
39
|
export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
35
40
|
export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
@@ -39,4 +44,6 @@ export var loadingButtonComment = function loadingButtonComment(_ref) {
|
|
|
39
44
|
var hasLinkAppearance = _ref.hasLinkAppearance,
|
|
40
45
|
hasHref = _ref.hasHref;
|
|
41
46
|
return "This should be migrated to a new Button with a `isLoading` prop. ".concat(hasLinkAppearance ? "\"link\" and \"subtle-link\" appearances are not available for new loading buttons.\"" : '').concat(hasHref ? "The `href` attribute it not compatible with new loading buttons, because links should not need loading states." : '', " Please reconsider the design or change the appearance of the button.");
|
|
42
|
-
};
|
|
47
|
+
};
|
|
48
|
+
export var migrateButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"default\" appearance.";
|
|
49
|
+
export var migrateSubtleButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"subtle\" appearance.";
|
|
@@ -139,4 +139,16 @@ export var generateNewElement = function generateNewElement(variant, element, j)
|
|
|
139
139
|
closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
|
|
140
140
|
children: element.children
|
|
141
141
|
});
|
|
142
|
+
};
|
|
143
|
+
export var modifyButtonAttributes = function modifyButtonAttributes(element, j, hasSpacingNone) {
|
|
144
|
+
j(element).find(j.JSXAttribute).filter(function (path) {
|
|
145
|
+
var _path$node$value2;
|
|
146
|
+
return path.node.name.name === 'appearance' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
|
|
147
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
148
|
+
if (hasSpacingNone) {
|
|
149
|
+
j(element).find(j.JSXAttribute).filter(function (path) {
|
|
150
|
+
var _path$node$value3;
|
|
151
|
+
return path.node.name.name === 'spacing' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
152
|
+
}).remove();
|
|
153
|
+
}
|
|
142
154
|
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export declare const PRINT_SETTINGS: {
|
|
2
2
|
quote: "single";
|
|
3
3
|
};
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* NEW button *
|
|
6
|
+
*/
|
|
5
7
|
export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
|
|
6
8
|
export declare const NEW_BUTTON_VARIANTS: {
|
|
7
9
|
[key: string]: string;
|
|
8
10
|
};
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* OLD button *
|
|
13
|
+
*/
|
|
10
14
|
export declare const OLD_BUTTON_ENTRY_POINT = "@atlaskit/button";
|
|
11
15
|
export declare const OLD_BUTTON_VARIANTS: {
|
|
12
16
|
[key: string]: string;
|
|
@@ -17,7 +21,8 @@ export declare const entryPointsMapping: {
|
|
|
17
21
|
export declare const BUTTON_TYPES: string[];
|
|
18
22
|
export declare const UNSAFE_SIZE_PROPS_MAP: Record<string, string>;
|
|
19
23
|
export declare const unsupportedProps: string[];
|
|
20
|
-
export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are
|
|
24
|
+
export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\".";
|
|
25
|
+
export declare const noSpacinglinkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\", or provide a href prop then migrate to Link.";
|
|
21
26
|
export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
22
27
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
23
28
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
@@ -27,3 +32,5 @@ export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
|
|
|
27
32
|
hasLinkAppearance: boolean;
|
|
28
33
|
hasHref: boolean;
|
|
29
34
|
}) => string;
|
|
35
|
+
export declare const migrateButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"default\" appearance.";
|
|
36
|
+
export declare const migrateSubtleButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"subtle\" appearance.";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type API, type
|
|
1
|
+
import { type API, type JSXAttribute, type JSXElement, type JSXSpreadAttribute } from 'jscodeshift';
|
|
2
2
|
import { NEW_BUTTON_VARIANTS } from '../utils/constants';
|
|
3
3
|
export declare const getIconAttributes: (attributes: (JSXAttribute | JSXSpreadAttribute)[]) => JSXAttribute[] | null;
|
|
4
4
|
export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | null;
|
|
@@ -17,3 +17,4 @@ export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | nu
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const handleIconAttributes: (element: JSXElement, j: API['jscodeshift'], iconRenamed?: boolean) => void;
|
|
19
19
|
export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS], element: JSXElement, j: API['jscodeshift']) => JSXElement;
|
|
20
|
+
export declare const modifyButtonAttributes: (element: JSXElement, j: API['jscodeshift'], hasSpacingNone: boolean) => void;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export declare const PRINT_SETTINGS: {
|
|
2
2
|
quote: "single";
|
|
3
3
|
};
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* NEW button *
|
|
6
|
+
*/
|
|
5
7
|
export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/new";
|
|
6
8
|
export declare const NEW_BUTTON_VARIANTS: {
|
|
7
9
|
[key: string]: string;
|
|
8
10
|
};
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* OLD button *
|
|
13
|
+
*/
|
|
10
14
|
export declare const OLD_BUTTON_ENTRY_POINT = "@atlaskit/button";
|
|
11
15
|
export declare const OLD_BUTTON_VARIANTS: {
|
|
12
16
|
[key: string]: string;
|
|
@@ -17,7 +21,8 @@ export declare const entryPointsMapping: {
|
|
|
17
21
|
export declare const BUTTON_TYPES: string[];
|
|
18
22
|
export declare const UNSAFE_SIZE_PROPS_MAP: Record<string, string>;
|
|
19
23
|
export declare const unsupportedProps: string[];
|
|
20
|
-
export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are
|
|
24
|
+
export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\".";
|
|
25
|
+
export declare const noSpacinglinkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are not available in the new Button, appearance should be \"subtle\" or \"default\", or provide a href prop then migrate to Link.";
|
|
21
26
|
export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
22
27
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
23
28
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
@@ -27,3 +32,5 @@ export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
|
|
|
27
32
|
hasLinkAppearance: boolean;
|
|
28
33
|
hasHref: boolean;
|
|
29
34
|
}) => string;
|
|
35
|
+
export declare const migrateButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"default\" appearance.";
|
|
36
|
+
export declare const migrateSubtleButtonToSubtleLinkButton = "\"link\" and \"subtle-link\" appearances are not available in the new Button. Appearance should be migrated to \"subtle\" or \"default\" for Link Button, or use Link with \"subtle\" appearance.";
|
package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type API, type
|
|
1
|
+
import { type API, type JSXAttribute, type JSXElement, type JSXSpreadAttribute } from 'jscodeshift';
|
|
2
2
|
import { NEW_BUTTON_VARIANTS } from '../utils/constants';
|
|
3
3
|
export declare const getIconAttributes: (attributes: (JSXAttribute | JSXSpreadAttribute)[]) => JSXAttribute[] | null;
|
|
4
4
|
export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | null;
|
|
@@ -17,3 +17,4 @@ export declare const getIconElement: (iconAttr: JSXAttribute) => JSXElement | nu
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const handleIconAttributes: (element: JSXElement, j: API['jscodeshift'], iconRenamed?: boolean) => void;
|
|
19
19
|
export declare const generateNewElement: (variant: (typeof NEW_BUTTON_VARIANTS)[keyof typeof NEW_BUTTON_VARIANTS], element: JSXElement, j: API['jscodeshift']) => JSXElement;
|
|
20
|
+
export declare const modifyButtonAttributes: (element: JSXElement, j: API['jscodeshift'], hasSpacingNone: boolean) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/codemod-cli",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.2",
|
|
4
4
|
"description": "A cli for distributing codemods for atlassian-frontend components and services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"bin": "./bin/codemod-cli.js",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
43
|
-
"@atlaskit/tokens": "^1.
|
|
43
|
+
"@atlaskit/tokens": "^1.56.0",
|
|
44
44
|
"@babel/runtime": "^7.0.0",
|
|
45
45
|
"@codeshift/utils": "^0.2.4",
|
|
46
46
|
"@hypermod/utils": "^0.4.2",
|