@vkontakte/vkui-codemods 0.0.7 → 1.0.0-beta.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/README.md +69 -21
- package/dist/autoDetectVKUIVersion.js +77 -0
- package/dist/cli.js +86 -30
- package/dist/codemod-helpers.js +76 -4
- package/dist/getAvailableCodemods.js +31 -4
- package/dist/index.js +57 -64
- package/dist/report.js +1 -2
- package/dist/testHelpers/testHelper.js +3 -3
- package/dist/transforms/{accordion.js → v6/accordion.js} +3 -3
- package/dist/transforms/{action-sheet-item.js → v6/action-sheet-item.js} +2 -2
- package/dist/transforms/{action-sheet.js → v6/action-sheet.js} +3 -3
- package/dist/transforms/{alert.js → v6/alert.js} +2 -2
- package/dist/transforms/{appearance-provider.js → v6/appearance-provider.js} +2 -2
- package/dist/transforms/{banner.js → v6/banner.js} +3 -3
- package/dist/transforms/{calendar-range.js → v6/calendar-range.js} +2 -2
- package/dist/transforms/{calendar.js → v6/calendar.js} +2 -2
- package/dist/transforms/{card-scroll.js → v6/card-scroll.js} +2 -2
- package/dist/transforms/{chip.js → v6/chip.js} +2 -2
- package/dist/transforms/{chips-input.js → v6/chips-input.js} +2 -2
- package/dist/transforms/{config-provider.js → v6/config-provider.js} +2 -2
- package/dist/transforms/{content-card.js → v6/content-card.js} +2 -2
- package/dist/transforms/{custom-scroll-view.js → v6/custom-scroll-view.js} +3 -3
- package/dist/transforms/{date-input.js → v6/date-input.js} +2 -2
- package/dist/transforms/{date-range-input.js → v6/date-range-input.js} +2 -2
- package/dist/transforms/{fixed-layout.js → v6/fixed-layout.js} +2 -2
- package/dist/transforms/{forbid-imports.js → v6/forbid-imports.js} +2 -2
- package/dist/transforms/{form-item.js → v6/form-item.js} +2 -2
- package/dist/transforms/{form-layout.js → v6/form-layout.js} +3 -3
- package/dist/transforms/{gallery.js → v6/gallery.js} +2 -2
- package/dist/transforms/{gradient-prop-change.js → v6/gradient-prop-change.js} +3 -3
- package/dist/transforms/{image-base.js → v6/image-base.js} +2 -2
- package/dist/transforms/{modal-card.js → v6/modal-card.js} +3 -3
- package/dist/transforms/{modal-page-header.js → v6/modal-page-header.js} +2 -2
- package/dist/transforms/{pagination.js → v6/pagination.js} +3 -3
- package/dist/transforms/{panel-header-content.js → v6/panel-header-content.js} +3 -3
- package/dist/transforms/{panel-header.js → v6/panel-header.js} +3 -3
- package/dist/transforms/{placeholder.js → v6/placeholder.js} +2 -2
- package/dist/transforms/{popout-wrapper.js → v6/popout-wrapper.js} +3 -3
- package/dist/transforms/{popover.js → v6/popover.js} +2 -2
- package/dist/transforms/{popper.js → v6/popper.js} +2 -2
- package/dist/transforms/{rich-tooltip.js → v6/rich-tooltip.js} +3 -3
- package/dist/transforms/{search.js → v6/search.js} +2 -2
- package/dist/transforms/{select.js → v6/select.js} +2 -2
- package/dist/transforms/{simple-cell.js → v6/simple-cell.js} +3 -3
- package/dist/transforms/{split-col.js → v6/split-col.js} +2 -2
- package/dist/transforms/{tabbar.js → v6/tabbar.js} +2 -2
- package/dist/transforms/{tappable.js → v6/tappable.js} +3 -3
- package/dist/transforms/{text-tooltip.js → v6/text-tooltip.js} +2 -2
- package/dist/transforms/{tooltip-container.js → v6/tooltip-container.js} +2 -2
- package/dist/transforms/{tooltip.js → v6/tooltip.js} +2 -2
- package/dist/transforms/{typography.js → v6/typography.js} +3 -3
- package/dist/transforms/{users-stack.js → v6/users-stack.js} +3 -3
- package/dist/transforms/v7/action-sheet.js +16 -0
- package/dist/transforms/v7/alert.js +16 -0
- package/dist/transforms/v7/appearance-provider.js +35 -0
- package/dist/transforms/v7/appearance.js +45 -0
- package/dist/transforms/v7/banner.js +47 -0
- package/dist/transforms/v7/card-grid.js +16 -0
- package/dist/transforms/v7/card-scroll.js +59 -0
- package/dist/transforms/v7/cell-button.js +49 -0
- package/dist/transforms/v7/cell.js +18 -0
- package/dist/transforms/v7/chips-select.js +20 -0
- package/dist/transforms/v7/common/remapSizePropValue.js +43 -0
- package/dist/transforms/v7/common/swapGapPropElements.js +25 -0
- package/dist/transforms/v7/config-provider.js +136 -0
- package/dist/transforms/v7/content-card.js +21 -0
- package/dist/transforms/v7/custom-scroll-view.js +21 -0
- package/dist/transforms/v7/custom-select.js +20 -0
- package/dist/transforms/v7/flex.js +18 -0
- package/dist/transforms/v7/form-item.js +128 -0
- package/dist/transforms/v7/form-status.js +18 -0
- package/dist/transforms/v7/header.js +28 -0
- package/dist/transforms/v7/horizontal-cell-show-more.js +58 -0
- package/dist/transforms/v7/horizontal-cell.js +16 -0
- package/dist/transforms/v7/horizontal-scroll.js +38 -0
- package/dist/transforms/v7/image-overlay.js +125 -0
- package/dist/transforms/v7/mini-info-cell.js +18 -0
- package/dist/transforms/v7/modal-card.js +29 -0
- package/dist/transforms/v7/onboarding-tooltip.js +16 -0
- package/dist/transforms/v7/panel-header-content.js +16 -0
- package/dist/transforms/v7/placeholder.js +19 -0
- package/dist/transforms/v7/rich-cell.js +20 -0
- package/dist/transforms/v7/screen-spinner.js +61 -0
- package/dist/transforms/v7/scroll-arrow.js +52 -0
- package/dist/transforms/v7/select.js +20 -0
- package/dist/transforms/v7/separator.js +18 -0
- package/dist/transforms/v7/simple-cell.js +18 -0
- package/dist/transforms/v7/simple-grid.js +18 -0
- package/dist/transforms/v7/spacing.js +26 -0
- package/dist/transforms/v7/spinner.js +29 -0
- package/dist/transforms/v7/subnavigation-bar.js +60 -0
- package/dist/transforms/v7/subnavigation-button.js +18 -0
- package/dist/transforms/v7/tabbar-item.js +16 -0
- package/dist/transforms/v7/tooltip.js +16 -0
- package/dist/transforms/v7/typography.js +79 -0
- package/dist/transforms/v7/users-stack.js +50 -0
- package/package.json +7 -7
- package/dist/transforms/{horizontal-cell-show-more.js → v6/horizontal-cell-show-more.js} +1 -1
- package/dist/transforms/{range-slider.js → v6/range-slider.js} +1 -1
- package/dist/transforms/{visually-hidden-input.js → v6/visually-hidden-input.js} +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformUseAccentWeightAttribute;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
exports.parser = 'tsx';
|
|
7
|
+
function isJSXAttribute(attribute) {
|
|
8
|
+
return (attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'JSXAttribute';
|
|
9
|
+
}
|
|
10
|
+
function removeAttribute(attributes, attribute) {
|
|
11
|
+
attributes === null || attributes === void 0 ? void 0 : attributes.splice(attributes === null || attributes === void 0 ? void 0 : attributes.indexOf(attribute), 1);
|
|
12
|
+
}
|
|
13
|
+
var componentsToTransform = [
|
|
14
|
+
'Typography',
|
|
15
|
+
'Caption',
|
|
16
|
+
'DisplayTitle',
|
|
17
|
+
'Footnote',
|
|
18
|
+
'Headline',
|
|
19
|
+
'Paragraph',
|
|
20
|
+
'Subhead',
|
|
21
|
+
'Text',
|
|
22
|
+
'Title',
|
|
23
|
+
];
|
|
24
|
+
function transformUseAccentWeightAttribute(file, api, options) {
|
|
25
|
+
var alias = options.alias;
|
|
26
|
+
var j = api.jscodeshift;
|
|
27
|
+
var source = j(file.source);
|
|
28
|
+
componentsToTransform.forEach(function (componentName) {
|
|
29
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
30
|
+
if (!localName) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
source
|
|
34
|
+
.find(j.JSXOpeningElement)
|
|
35
|
+
.filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
|
|
36
|
+
// useAccentWeight по умолчанию теперь false, поэтому, чтобы
|
|
37
|
+
// пользователи продолжили использовать accent шрифты мы включим accent режим,
|
|
38
|
+
// добавив useAccentWeight, если его нету.
|
|
39
|
+
.forEach(function handleUseAccentWeightAttribute(path) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
var attributes = path.node.attributes;
|
|
42
|
+
if (!attributes) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var accentAttribute = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return isJSXAttribute(attr) && attr.name.name === 'useAccentWeight'; });
|
|
46
|
+
var weightAttribute = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return isJSXAttribute(attr) && attr.name.name === 'weight'; });
|
|
47
|
+
// weight задан и не равен `undefined`
|
|
48
|
+
var hasDefinedWeightAttribute = Boolean(weightAttribute &&
|
|
49
|
+
weightAttribute.type === 'JSXAttribute' &&
|
|
50
|
+
!(((_a = weightAttribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer' &&
|
|
51
|
+
weightAttribute.value.expression.type === 'Identifier' &&
|
|
52
|
+
weightAttribute.value.expression.name === 'undefined'));
|
|
53
|
+
// есть weight и нету useAccentWeight: нужно добавить
|
|
54
|
+
if (!accentAttribute && hasDefinedWeightAttribute) {
|
|
55
|
+
attributes.push(j.jsxAttribute(j.jsxIdentifier('useAccentWeight')));
|
|
56
|
+
}
|
|
57
|
+
if (!isJSXAttribute(accentAttribute)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// weight нету, убираем useAccentWeight
|
|
61
|
+
if (!hasDefinedWeightAttribute) {
|
|
62
|
+
removeAttribute(attributes, accentAttribute);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (((_b = accentAttribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer' &&
|
|
66
|
+
accentAttribute.value.expression.type === 'BooleanLiteral') {
|
|
67
|
+
// useAccentWeight={true} => useAccentWeight
|
|
68
|
+
if (accentAttribute.value.expression.value === true) {
|
|
69
|
+
accentAttribute.value = null;
|
|
70
|
+
// useAccentWeight={false} => совсем убираем
|
|
71
|
+
}
|
|
72
|
+
else if (accentAttribute.value.expression.value === false) {
|
|
73
|
+
removeAttribute(attributes, accentAttribute);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return source.toSource();
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
var report_1 = require("../../report");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'UsersStack', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
var attributeToReplace = 'direction';
|
|
17
|
+
var newAttributeName = 'avatarsPosition';
|
|
18
|
+
var directionToAvatarsPosition = {
|
|
19
|
+
'row': 'inline-start',
|
|
20
|
+
'row-reverse': 'inline-end',
|
|
21
|
+
'column': 'block-start',
|
|
22
|
+
};
|
|
23
|
+
var getValueFromAttribute = function (attribute) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
26
|
+
return attribute.value.value;
|
|
27
|
+
}
|
|
28
|
+
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
29
|
+
var expression = attribute.value.expression;
|
|
30
|
+
if (expression.type === 'StringLiteral') {
|
|
31
|
+
return expression.value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
source
|
|
37
|
+
.find(j.JSXElement, { openingElement: { name: { name: localName } } })
|
|
38
|
+
.find(j.JSXAttribute, { name: { name: attributeToReplace } })
|
|
39
|
+
.forEach(function (path) {
|
|
40
|
+
var avatar = path.node;
|
|
41
|
+
avatar.name.name = newAttributeName;
|
|
42
|
+
var value = getValueFromAttribute(avatar);
|
|
43
|
+
if (!value || !directionToAvatarsPosition[value]) {
|
|
44
|
+
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change direction prop to avatarsPosition."));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
avatar.value = j.stringLiteral(directionToAvatarsPosition[value]);
|
|
48
|
+
});
|
|
49
|
+
return source.toSource();
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/vkui-codemods",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Codemods for automatic VKUI major version upgrade",
|
|
5
5
|
"repository": "https://github.com/VKCOM/VKUI",
|
|
6
6
|
"homepage": "https://vkcom.github.io/VKUI/",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"chalk": "^4.1.2",
|
|
18
18
|
"commander": "^12.1.0",
|
|
19
19
|
"cross-spawn": "^7.0.3",
|
|
20
|
-
"jscodeshift": "^0.
|
|
20
|
+
"jscodeshift": "^17.0.0",
|
|
21
21
|
"prompts": "^2.4.2",
|
|
22
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.6.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@swc/core": "^1.
|
|
25
|
+
"@swc/core": "^1.7.36",
|
|
26
26
|
"@swc/jest": "^0.2.36",
|
|
27
27
|
"@types/cross-spawn": "^6.0.6",
|
|
28
|
-
"@types/jest": "^29.5.
|
|
29
|
-
"@types/jscodeshift": "^0.
|
|
30
|
-
"@types/node": "^
|
|
28
|
+
"@types/jest": "^29.5.13",
|
|
29
|
+
"@types/jscodeshift": "^0.12.0",
|
|
30
|
+
"@types/node": "^22.7.7",
|
|
31
31
|
"@types/prompts": "^2.4.9",
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
33
|
"ts-node": "^10.9.2"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
4
5
|
exports.parser = 'tsx';
|
|
5
6
|
var componentName = 'unstable_HorizontalCellShowMore';
|
|
6
7
|
var componentNameTo = 'HorizontalCellShowMore';
|
|
@@ -19,4 +20,3 @@ function transformer(file, api, options) {
|
|
|
19
20
|
});
|
|
20
21
|
return source.toSource();
|
|
21
22
|
}
|
|
22
|
-
exports.default = transformer;
|
|
@@ -10,6 +10,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.parser = void 0;
|
|
13
|
+
exports.default = transformer;
|
|
13
14
|
exports.parser = 'tsx';
|
|
14
15
|
function transformer(file, api, options) {
|
|
15
16
|
var alias = options.alias;
|
|
@@ -49,4 +50,3 @@ function transformer(file, api, options) {
|
|
|
49
50
|
});
|
|
50
51
|
return source.toSource();
|
|
51
52
|
}
|
|
52
|
-
exports.default = transformer;
|
|
@@ -10,6 +10,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.parser = void 0;
|
|
13
|
+
exports.default = transformer;
|
|
13
14
|
exports.parser = 'tsx';
|
|
14
15
|
function transformer(file, api, options) {
|
|
15
16
|
var alias = options.alias;
|
|
@@ -42,4 +43,3 @@ function transformer(file, api, options) {
|
|
|
42
43
|
});
|
|
43
44
|
return source.toSource();
|
|
44
45
|
}
|
|
45
|
-
exports.default = transformer;
|