@atlaskit/codemod-cli 0.24.0 → 0.24.1
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-to-new-button-variants.js +2 -0
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +13 -6
- package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +33 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +3 -2
- package/dist/cjs/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +26 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +2 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +11 -6
- package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +23 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +2 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +24 -1
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +2 -0
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +13 -6
- package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +27 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/has-unsupported-props.js +26 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.24.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#100948](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100948)
|
|
8
|
+
[`28061857f2cd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/28061857f2cd) -
|
|
9
|
+
Prevent migration of buttons where icon component might be wrapped.
|
|
10
|
+
|
|
3
11
|
## 0.24.0
|
|
4
12
|
|
|
5
13
|
### Minor 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.24.
|
|
308
|
+
_process$env$_PACKAGE = "0.24.1", _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
|
@@ -13,9 +13,11 @@ var _ifVariantAlreadyImported = require("../utils/if-variant-already-imported");
|
|
|
13
13
|
var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button-to-legacy-button");
|
|
14
14
|
var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
|
|
15
15
|
var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
|
|
16
|
+
var _addCommentForCustomThemeButtons = require("../utils/add-comment-for-custom-theme-buttons");
|
|
16
17
|
var transformer = function transformer(file, api) {
|
|
17
18
|
var j = api.jscodeshift;
|
|
18
19
|
var fileSource = j(file.source);
|
|
20
|
+
(0, _addCommentForCustomThemeButtons.addCommentForCustomThemeButtons)(fileSource, j);
|
|
19
21
|
var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
20
22
|
return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.entryPointsMapping.LoadingButton || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
|
|
21
23
|
});
|
|
@@ -62,17 +62,27 @@ function _default(file, api) {
|
|
|
62
62
|
|
|
63
63
|
// Check if render prop or bounded API
|
|
64
64
|
iconAttributes.forEach(function (iconAttribute) {
|
|
65
|
-
var _newButtonJXSElement$2, _iconAttribute$value
|
|
65
|
+
var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
|
|
66
66
|
var unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(function (attribute) {
|
|
67
67
|
return attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp;
|
|
68
68
|
});
|
|
69
69
|
if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
+
var safeSizeAttribute = j.jsxAttribute.from({
|
|
73
|
+
name: j.jsxIdentifier('size'),
|
|
74
|
+
value: unsafeSizeAttribute.value
|
|
75
|
+
});
|
|
72
76
|
switch (iconAttribute.value.expression.type) {
|
|
73
77
|
// We have a render prop, move the UNSAFE prop to the render prop
|
|
74
78
|
case 'ArrowFunctionExpression':
|
|
75
|
-
//
|
|
79
|
+
// Prefer existing size on icon over UNSAFE size on button
|
|
80
|
+
if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(function (attribute) {
|
|
81
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
|
|
82
|
+
}))) {
|
|
83
|
+
var _iconAttribute$value$2;
|
|
84
|
+
(_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 || _iconAttribute$value$2.push(safeSizeAttribute);
|
|
85
|
+
}
|
|
76
86
|
break;
|
|
77
87
|
|
|
78
88
|
// We have a bounded API, move to render prop
|
|
@@ -88,10 +98,7 @@ function _default(file, api) {
|
|
|
88
98
|
selfClosing: true,
|
|
89
99
|
attributes: [j.jsxSpreadAttribute.from({
|
|
90
100
|
argument: j.identifier('iconProps')
|
|
91
|
-
}),
|
|
92
|
-
name: j.jsxIdentifier('size'),
|
|
93
|
-
value: unsafeSizeAttribute.value
|
|
94
|
-
})]
|
|
101
|
+
}), safeSizeAttribute]
|
|
95
102
|
})
|
|
96
103
|
})
|
|
97
104
|
}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addCommentForCustomThemeButtons = void 0;
|
|
7
|
+
var _codemodUtils = require("@atlaskit/codemod-utils");
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
|
|
10
|
+
var _fileSource$find$filt;
|
|
11
|
+
var customThemeButtonImportName;
|
|
12
|
+
(_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
13
|
+
return path.node.source.value === _constants.entryPointsMapping.CustomThemeButton;
|
|
14
|
+
})) === null || _fileSource$find$filt === void 0 || _fileSource$find$filt.forEach(function (path) {
|
|
15
|
+
var _path$node$specifiers;
|
|
16
|
+
(_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 || _path$node$specifiers.forEach(function (specifier) {
|
|
17
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
18
|
+
var _specifier$local;
|
|
19
|
+
customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
if (!customThemeButtonImportName) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var customThemeButtonElement = fileSource.find(j.JSXElement).filter(function (path) {
|
|
27
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName;
|
|
28
|
+
});
|
|
29
|
+
if (!customThemeButtonElement.length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
(0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'line');
|
|
33
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
|
|
6
|
+
exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = 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
|
};
|
|
@@ -30,4 +30,5 @@ var unsupportedProps = exports.unsupportedProps = ['component', 'css', 'style'];
|
|
|
30
30
|
var linkButtonMissingHrefComment = exports.linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
|
|
31
31
|
var buttonPropsNoLongerSupportedComment = exports.buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
32
32
|
var migrateFitContainerButtonToDefaultButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
33
|
-
var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
33
|
+
var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
34
|
+
var customThemeButtonComment = exports.customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
@@ -6,7 +6,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ifHasUnsupportedProps = void 0;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
8
|
var ifHasUnsupportedProps = exports.ifHasUnsupportedProps = function ifHasUnsupportedProps(attributes) {
|
|
9
|
-
|
|
9
|
+
var hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
|
|
10
10
|
return node.type === 'JSXAttribute' && _constants.unsupportedProps.includes(String(node.name.name));
|
|
11
11
|
})));
|
|
12
|
+
var hasUnmigratableIcon = function hasUnmigratableIcon() {
|
|
13
|
+
var oldIconProps = ['iconBefore', 'iconAfter'];
|
|
14
|
+
var hasUnmigratableIcon = false;
|
|
15
|
+
if (!(attributes !== null && attributes !== void 0 && attributes.some(function (attribute) {
|
|
16
|
+
return attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name);
|
|
17
|
+
}))) {
|
|
18
|
+
return hasUnmigratableIcon;
|
|
19
|
+
}
|
|
20
|
+
oldIconProps.forEach(function (oldIconProp) {
|
|
21
|
+
var _iconAttribute$value;
|
|
22
|
+
var iconAttribute = attributes.find(function (attribute) {
|
|
23
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp;
|
|
24
|
+
});
|
|
25
|
+
if (!iconAttribute) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
|
|
30
|
+
if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
|
|
31
|
+
hasUnmigratableIcon = true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return hasUnmigratableIcon;
|
|
35
|
+
};
|
|
36
|
+
return hasUnsupportedProps || hasUnmigratableIcon();
|
|
12
37
|
};
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -7,9 +7,11 @@ import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-impor
|
|
|
7
7
|
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
8
8
|
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
9
9
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
10
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
10
11
|
const transformer = (file, api) => {
|
|
11
12
|
const j = api.jscodeshift;
|
|
12
13
|
const fileSource = j(file.source);
|
|
14
|
+
addCommentForCustomThemeButtons(fileSource, j);
|
|
13
15
|
const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
|
|
14
16
|
if (!buttonImports.length) {
|
|
15
17
|
return fileSource.toSource();
|
|
@@ -46,15 +46,23 @@ export default function (file, api) {
|
|
|
46
46
|
|
|
47
47
|
// Check if render prop or bounded API
|
|
48
48
|
iconAttributes.forEach(iconAttribute => {
|
|
49
|
-
var _newButtonJXSElement$2, _iconAttribute$value
|
|
49
|
+
var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
|
|
50
50
|
const unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp);
|
|
51
51
|
if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
+
const safeSizeAttribute = j.jsxAttribute.from({
|
|
55
|
+
name: j.jsxIdentifier('size'),
|
|
56
|
+
value: unsafeSizeAttribute.value
|
|
57
|
+
});
|
|
54
58
|
switch (iconAttribute.value.expression.type) {
|
|
55
59
|
// We have a render prop, move the UNSAFE prop to the render prop
|
|
56
60
|
case 'ArrowFunctionExpression':
|
|
57
|
-
//
|
|
61
|
+
// Prefer existing size on icon over UNSAFE size on button
|
|
62
|
+
if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'size'))) {
|
|
63
|
+
var _iconAttribute$value$2;
|
|
64
|
+
(_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 ? void 0 : _iconAttribute$value$2.push(safeSizeAttribute);
|
|
65
|
+
}
|
|
58
66
|
break;
|
|
59
67
|
|
|
60
68
|
// We have a bounded API, move to render prop
|
|
@@ -70,10 +78,7 @@ export default function (file, api) {
|
|
|
70
78
|
selfClosing: true,
|
|
71
79
|
attributes: [j.jsxSpreadAttribute.from({
|
|
72
80
|
argument: j.identifier('iconProps')
|
|
73
|
-
}),
|
|
74
|
-
name: j.jsxIdentifier('size'),
|
|
75
|
-
value: unsafeSizeAttribute.value
|
|
76
|
-
})]
|
|
81
|
+
}), safeSizeAttribute]
|
|
77
82
|
})
|
|
78
83
|
})
|
|
79
84
|
}));
|
package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
2
|
+
import { entryPointsMapping, customThemeButtonComment } from './constants';
|
|
3
|
+
export const addCommentForCustomThemeButtons = (fileSource, j) => {
|
|
4
|
+
var _fileSource$find$filt;
|
|
5
|
+
let customThemeButtonImportName;
|
|
6
|
+
(_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.CustomThemeButton)) === null || _fileSource$find$filt === void 0 ? void 0 : _fileSource$find$filt.forEach(path => {
|
|
7
|
+
var _path$node$specifiers;
|
|
8
|
+
(_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 ? void 0 : _path$node$specifiers.forEach(specifier => {
|
|
9
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
10
|
+
var _specifier$local;
|
|
11
|
+
customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
if (!customThemeButtonImportName) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const customThemeButtonElement = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName);
|
|
19
|
+
if (!customThemeButtonElement.length) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
|
|
23
|
+
};
|
|
@@ -24,4 +24,5 @@ export const unsupportedProps = ['component', 'css', 'style'];
|
|
|
24
24
|
export const linkButtonMissingHrefComment = `"link" and "subtle-link" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.`;
|
|
25
25
|
export const buttonPropsNoLongerSupportedComment = `Buttons with "component", "css" or "style" prop can't be automatically migrated with codemods. Please migrate it manually.`;
|
|
26
26
|
export const migrateFitContainerButtonToDefaultButtonComment = `Migrated to a default button with text which is from the icon label.`;
|
|
27
|
-
export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
|
|
27
|
+
export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
|
|
28
|
+
export const customThemeButtonComment = `CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.`;
|
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
import { unsupportedProps } from './constants';
|
|
2
|
-
export const ifHasUnsupportedProps = attributes =>
|
|
2
|
+
export const ifHasUnsupportedProps = attributes => {
|
|
3
|
+
let hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(node => node.type === 'JSXAttribute' && unsupportedProps.includes(String(node.name.name)))));
|
|
4
|
+
const hasUnmigratableIcon = () => {
|
|
5
|
+
const oldIconProps = ['iconBefore', 'iconAfter'];
|
|
6
|
+
let hasUnmigratableIcon = false;
|
|
7
|
+
if (!(attributes !== null && attributes !== void 0 && attributes.some(attribute => attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name)))) {
|
|
8
|
+
return hasUnmigratableIcon;
|
|
9
|
+
}
|
|
10
|
+
oldIconProps.forEach(oldIconProp => {
|
|
11
|
+
var _iconAttribute$value;
|
|
12
|
+
const iconAttribute = attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp);
|
|
13
|
+
if (!iconAttribute) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
|
|
18
|
+
if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
|
|
19
|
+
hasUnmigratableIcon = true;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return hasUnmigratableIcon;
|
|
23
|
+
};
|
|
24
|
+
return hasUnsupportedProps || hasUnmigratableIcon();
|
|
25
|
+
};
|
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.24.
|
|
301
|
+
_process$env$_PACKAGE = "0.24.1", _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
|
@@ -7,9 +7,11 @@ import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-impor
|
|
|
7
7
|
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
8
8
|
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
9
9
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
10
|
+
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
10
11
|
var transformer = function transformer(file, api) {
|
|
11
12
|
var j = api.jscodeshift;
|
|
12
13
|
var fileSource = j(file.source);
|
|
14
|
+
addCommentForCustomThemeButtons(fileSource, j);
|
|
13
15
|
var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
14
16
|
return path.node.source.value === entryPointsMapping.Button || path.node.source.value === entryPointsMapping.LoadingButton || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
|
|
15
17
|
});
|
|
@@ -56,17 +56,27 @@ export default function (file, api) {
|
|
|
56
56
|
|
|
57
57
|
// Check if render prop or bounded API
|
|
58
58
|
iconAttributes.forEach(function (iconAttribute) {
|
|
59
|
-
var _newButtonJXSElement$2, _iconAttribute$value
|
|
59
|
+
var _newButtonJXSElement$2, _iconAttribute$value, _iconAttribute$value$;
|
|
60
60
|
var unsafeSizeAttribute = (_newButtonJXSElement$2 = newButtonJXSElement.value.openingElement.attributes) === null || _newButtonJXSElement$2 === void 0 ? void 0 : _newButtonJXSElement$2.find(function (attribute) {
|
|
61
61
|
return attribute.type === 'JSXAttribute' && attribute.name.name === unsafeSizeProp;
|
|
62
62
|
});
|
|
63
63
|
if (iconAttribute.type !== 'JSXAttribute' || ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) !== 'JSXExpressionContainer' || !unsafeSizeAttribute || unsafeSizeAttribute.type !== 'JSXAttribute') {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
+
var safeSizeAttribute = j.jsxAttribute.from({
|
|
67
|
+
name: j.jsxIdentifier('size'),
|
|
68
|
+
value: unsafeSizeAttribute.value
|
|
69
|
+
});
|
|
66
70
|
switch (iconAttribute.value.expression.type) {
|
|
67
71
|
// We have a render prop, move the UNSAFE prop to the render prop
|
|
68
72
|
case 'ArrowFunctionExpression':
|
|
69
|
-
//
|
|
73
|
+
// Prefer existing size on icon over UNSAFE size on button
|
|
74
|
+
if (iconAttribute.value.expression.body.type === 'JSXElement' && !((_iconAttribute$value$ = iconAttribute.value.expression.body.openingElement.attributes) !== null && _iconAttribute$value$ !== void 0 && _iconAttribute$value$.some(function (attribute) {
|
|
75
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === 'size';
|
|
76
|
+
}))) {
|
|
77
|
+
var _iconAttribute$value$2;
|
|
78
|
+
(_iconAttribute$value$2 = iconAttribute.value.expression.body.openingElement.attributes) === null || _iconAttribute$value$2 === void 0 || _iconAttribute$value$2.push(safeSizeAttribute);
|
|
79
|
+
}
|
|
70
80
|
break;
|
|
71
81
|
|
|
72
82
|
// We have a bounded API, move to render prop
|
|
@@ -82,10 +92,7 @@ export default function (file, api) {
|
|
|
82
92
|
selfClosing: true,
|
|
83
93
|
attributes: [j.jsxSpreadAttribute.from({
|
|
84
94
|
argument: j.identifier('iconProps')
|
|
85
|
-
}),
|
|
86
|
-
name: j.jsxIdentifier('size'),
|
|
87
|
-
value: unsafeSizeAttribute.value
|
|
88
|
-
})]
|
|
95
|
+
}), safeSizeAttribute]
|
|
89
96
|
})
|
|
90
97
|
})
|
|
91
98
|
}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
2
|
+
import { entryPointsMapping, customThemeButtonComment } from './constants';
|
|
3
|
+
export var addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
|
|
4
|
+
var _fileSource$find$filt;
|
|
5
|
+
var customThemeButtonImportName;
|
|
6
|
+
(_fileSource$find$filt = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
7
|
+
return path.node.source.value === entryPointsMapping.CustomThemeButton;
|
|
8
|
+
})) === null || _fileSource$find$filt === void 0 || _fileSource$find$filt.forEach(function (path) {
|
|
9
|
+
var _path$node$specifiers;
|
|
10
|
+
(_path$node$specifiers = path.node.specifiers) === null || _path$node$specifiers === void 0 || _path$node$specifiers.forEach(function (specifier) {
|
|
11
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
12
|
+
var _specifier$local;
|
|
13
|
+
customThemeButtonImportName = (_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
if (!customThemeButtonImportName) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var customThemeButtonElement = fileSource.find(j.JSXElement).filter(function (path) {
|
|
21
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === customThemeButtonImportName;
|
|
22
|
+
});
|
|
23
|
+
if (!customThemeButtonElement.length) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
|
|
27
|
+
};
|
|
@@ -24,4 +24,5 @@ export var unsupportedProps = ['component', 'css', 'style'];
|
|
|
24
24
|
export var linkButtonMissingHrefComment = "\"link\" and \"subtle-link\" appearances are only available in LinkButton, please either provide a href prop then migrate to LinkButton, or remove the appearance from the default button.";
|
|
25
25
|
export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
26
26
|
export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
27
|
-
export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
27
|
+
export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
28
|
+
export var customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { unsupportedProps } from './constants';
|
|
2
2
|
export var ifHasUnsupportedProps = function ifHasUnsupportedProps(attributes) {
|
|
3
|
-
|
|
3
|
+
var hasUnsupportedProps = Boolean(attributes && (attributes === null || attributes === void 0 ? void 0 : attributes.some(function (node) {
|
|
4
4
|
return node.type === 'JSXAttribute' && unsupportedProps.includes(String(node.name.name));
|
|
5
5
|
})));
|
|
6
|
+
var hasUnmigratableIcon = function hasUnmigratableIcon() {
|
|
7
|
+
var oldIconProps = ['iconBefore', 'iconAfter'];
|
|
8
|
+
var hasUnmigratableIcon = false;
|
|
9
|
+
if (!(attributes !== null && attributes !== void 0 && attributes.some(function (attribute) {
|
|
10
|
+
return attribute.type === 'JSXAttribute' && attribute.name.type === 'JSXIdentifier' && oldIconProps.includes(attribute.name.name);
|
|
11
|
+
}))) {
|
|
12
|
+
return hasUnmigratableIcon;
|
|
13
|
+
}
|
|
14
|
+
oldIconProps.forEach(function (oldIconProp) {
|
|
15
|
+
var _iconAttribute$value;
|
|
16
|
+
var iconAttribute = attributes.find(function (attribute) {
|
|
17
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === oldIconProp;
|
|
18
|
+
});
|
|
19
|
+
if (!iconAttribute) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// check to see if the element is self closing, otherwise assume it's not an icon (may contain wrapper)
|
|
24
|
+
if (iconAttribute.type === 'JSXAttribute' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'JSXExpressionContainer' && iconAttribute.value.expression.type === 'JSXElement' && !iconAttribute.value.expression.openingElement.selfClosing) {
|
|
25
|
+
hasUnmigratableIcon = true;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return hasUnmigratableIcon;
|
|
29
|
+
};
|
|
30
|
+
return hasUnsupportedProps || hasUnmigratableIcon();
|
|
6
31
|
};
|
|
@@ -15,3 +15,4 @@ export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\
|
|
|
15
15
|
export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
16
16
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
17
17
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
18
|
+
export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
|
@@ -15,3 +15,4 @@ export declare const linkButtonMissingHrefComment = "\"link\" and \"subtle-link\
|
|
|
15
15
|
export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"css\" or \"style\" prop can't be automatically migrated with codemods. Please migrate it manually.";
|
|
16
16
|
export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
|
|
17
17
|
export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
|
|
18
|
+
export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
|
package/package.json
CHANGED