@vkontakte/vkui-codemods 1.0.0-beta.1 → 1.0.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/dist/autoDetectVKUIVersion.js +17 -7
- package/dist/codemod-helpers.js +19 -2
- package/dist/getAvailableCodemods.js +17 -7
- package/dist/transforms/v6/forbid-imports.js +2 -1
- package/dist/transforms/v6/range-slider.js +3 -1
- package/dist/transforms/v6/visually-hidden-input.js +3 -1
- package/dist/transforms/v7/banner.js +1 -1
- package/dist/transforms/v7/calendar.js +17 -0
- package/dist/transforms/v7/cell-button.js +2 -14
- package/dist/transforms/v7/cell.js +1 -0
- package/dist/transforms/v7/common/moveFromChildrenToLabel.js +68 -0
- package/dist/transforms/v7/common/removeChildrenFromComponent.js +17 -0
- package/dist/transforms/v7/counter.js +60 -0
- package/dist/transforms/v7/date-picker.js +26 -0
- package/dist/transforms/v7/form-item.js +2 -2
- package/dist/transforms/v7/header.js +46 -0
- package/dist/transforms/v7/panel-header-back.js +18 -0
- package/dist/transforms/v7/panel-header-close.js +18 -0
- package/dist/transforms/v7/panel-header-edit.js +19 -0
- package/dist/transforms/v7/panel-header-submit.js +18 -0
- package/dist/transforms/v7/panel-spinner.js +30 -0
- package/dist/transforms/v7/simple-cell.js +1 -0
- package/dist/transforms/v7/subnavigation-bar.js +2 -16
- package/dist/transforms/v7/users-stack.js +1 -14
- package/package.json +12 -13
|
@@ -26,13 +26,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
26
26
|
}) : function(o, v) {
|
|
27
27
|
o["default"] = v;
|
|
28
28
|
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
36
46
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
47
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
48
|
};
|
package/dist/codemod-helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAttributeManipulator = exports.removeAttribute = exports.removeProps = void 0;
|
|
3
|
+
exports.createAttributeManipulator = exports.getStringValueFromAttribute = exports.removeAttribute = exports.removeProps = void 0;
|
|
4
4
|
exports.getImportInfo = getImportInfo;
|
|
5
5
|
exports.renameImportName = renameImportName;
|
|
6
6
|
exports.renameIdentifier = renameIdentifier;
|
|
@@ -115,7 +115,7 @@ var removeProps = function (j, api, source, componentName, propsNames, createRep
|
|
|
115
115
|
if (attr.type === 'JSXSpreadAttribute') {
|
|
116
116
|
needToShowReport = true;
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return true;
|
|
119
119
|
});
|
|
120
120
|
path.node.openingElement.attributes = newAttributes;
|
|
121
121
|
});
|
|
@@ -128,6 +128,23 @@ var removeAttribute = function (attributes, attribute) {
|
|
|
128
128
|
attributes === null || attributes === void 0 ? void 0 : attributes.splice(attributes === null || attributes === void 0 ? void 0 : attributes.indexOf(attribute), 1);
|
|
129
129
|
};
|
|
130
130
|
exports.removeAttribute = removeAttribute;
|
|
131
|
+
/**
|
|
132
|
+
* @description Функция достает из атрибута строковое значение. Если вернулся null, значит значение не строковое
|
|
133
|
+
*/
|
|
134
|
+
var getStringValueFromAttribute = function (attribute) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
137
|
+
return attribute.value.value;
|
|
138
|
+
}
|
|
139
|
+
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
140
|
+
var expression = attribute.value.expression;
|
|
141
|
+
if (expression.type === 'StringLiteral') {
|
|
142
|
+
return expression.value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
exports.getStringValueFromAttribute = getStringValueFromAttribute;
|
|
131
148
|
var createAttributeManipulator = function (props, api) {
|
|
132
149
|
var map = new Map(Object.entries(props));
|
|
133
150
|
return {
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -17,7 +17,8 @@ function transformer(file, api, options) {
|
|
|
17
17
|
.filter(function (path) { return path.node.source.value === alias; })
|
|
18
18
|
.find(j.ImportSpecifier)
|
|
19
19
|
.forEach(function (path) {
|
|
20
|
-
if (
|
|
20
|
+
if (typeof path.value.imported.name === 'string' &&
|
|
21
|
+
['withInsets', 'useInsets', 'PromoBanner', 'getPlatformClassName'].includes(path.value.imported.name)) {
|
|
21
22
|
(0, report_1.report)(api, ": import of ".concat(chalk_1.default.white.bgBlue(path.value.imported.name), " are forbidden."));
|
|
22
23
|
}
|
|
23
24
|
});
|
|
@@ -30,7 +30,9 @@ function transformer(file, api, options) {
|
|
|
30
30
|
.filter(function (path) { return path.node.source.value === alias; })
|
|
31
31
|
.find(j.ImportSpecifier, { imported: { name: 'Slider' } });
|
|
32
32
|
componentImport.forEach(function (path) {
|
|
33
|
-
if (path.node.local &&
|
|
33
|
+
if (path.node.local &&
|
|
34
|
+
path.node.local.name !== path.node.imported.name &&
|
|
35
|
+
typeof path.node.local.name === 'string') {
|
|
34
36
|
localImportName = path.node.local.name;
|
|
35
37
|
needRename = false;
|
|
36
38
|
}
|
|
@@ -28,7 +28,9 @@ function transformer(file, api, options) {
|
|
|
28
28
|
return source.toSource();
|
|
29
29
|
}
|
|
30
30
|
componentImport.forEach(function (path) {
|
|
31
|
-
if (path.node.local &&
|
|
31
|
+
if (path.node.local &&
|
|
32
|
+
path.node.local.name !== path.node.imported.name &&
|
|
33
|
+
typeof path.node.local.name === 'string') {
|
|
32
34
|
localImportName = path.node.local.name;
|
|
33
35
|
needRename = false;
|
|
34
36
|
}
|
|
@@ -41,7 +41,7 @@ function transformer(file, api, options) {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
(0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"after\" (previously \"asideMode\") prop. Need to change \"expand\" value to \"chevron\""));
|
|
44
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"after\" (previously \"asideMode\") prop. Need to change \"expand\" value to \"chevron\"."));
|
|
45
45
|
});
|
|
46
46
|
return source.toSource();
|
|
47
47
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
exports.parser = 'tsx';
|
|
7
|
+
function transformer(file, api, options) {
|
|
8
|
+
var alias = options.alias;
|
|
9
|
+
var j = api.jscodeshift;
|
|
10
|
+
var source = j(file.source);
|
|
11
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Calendar', alias).localName;
|
|
12
|
+
if (!localName) {
|
|
13
|
+
return source.toSource();
|
|
14
|
+
}
|
|
15
|
+
(0, codemod_helpers_1.renameProp)(j, source, localName, { onClose: 'onDoneButtonClick' });
|
|
16
|
+
return source.toSource();
|
|
17
|
+
}
|
|
@@ -13,32 +13,20 @@ function transformer(file, api, options) {
|
|
|
13
13
|
if (!localName) {
|
|
14
14
|
return source.toSource();
|
|
15
15
|
}
|
|
16
|
+
(0, codemod_helpers_1.renameProp)(j, source, localName, { subhead: 'overTitle', expandable: 'chevron' });
|
|
16
17
|
var attributeToReplace = 'mode';
|
|
17
18
|
var newAttributeName = 'appearance';
|
|
18
19
|
var modeToAppearance = {
|
|
19
20
|
primary: 'accent',
|
|
20
21
|
danger: 'negative',
|
|
21
22
|
};
|
|
22
|
-
var getValueFromAttribute = function (attribute) {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
25
|
-
return attribute.value.value;
|
|
26
|
-
}
|
|
27
|
-
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
28
|
-
var expression = attribute.value.expression;
|
|
29
|
-
if (expression.type === 'StringLiteral') {
|
|
30
|
-
return expression.value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
};
|
|
35
23
|
source
|
|
36
24
|
.find(j.JSXElement, { openingElement: { name: { name: localName } } })
|
|
37
25
|
.find(j.JSXAttribute, { name: { name: attributeToReplace } })
|
|
38
26
|
.forEach(function (path) {
|
|
39
27
|
var component = path.node;
|
|
40
28
|
component.name.name = newAttributeName;
|
|
41
|
-
var value =
|
|
29
|
+
var value = (0, codemod_helpers_1.getStringValueFromAttribute)(component);
|
|
42
30
|
if (!value || !modeToAppearance[value]) {
|
|
43
31
|
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change 'mode' prop to 'appearance'."));
|
|
44
32
|
return;
|
|
@@ -11,6 +11,7 @@ function transformer(file, api, options) {
|
|
|
11
11
|
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Cell', alias).localName;
|
|
12
12
|
if (localName) {
|
|
13
13
|
(0, codemod_helpers_1.renameProp)(j, source, localName, {
|
|
14
|
+
subhead: 'overTitle',
|
|
14
15
|
expandable: 'chevron',
|
|
15
16
|
});
|
|
16
17
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveFromChildrenToLabel = void 0;
|
|
4
|
+
var codemod_helpers_1 = require("../../../codemod-helpers");
|
|
5
|
+
var report_1 = require("../../../report");
|
|
6
|
+
var moveFromChildrenToLabel = function (api, source, localName, needToAddHideLabelProps) {
|
|
7
|
+
if (needToAddHideLabelProps === void 0) { needToAddHideLabelProps = false; }
|
|
8
|
+
var j = api.jscodeshift;
|
|
9
|
+
// Находим все JSX элементы с указанным именем
|
|
10
|
+
source
|
|
11
|
+
.find(j.JSXElement)
|
|
12
|
+
.filter(function (path) {
|
|
13
|
+
var elementName = path.node.openingElement.name;
|
|
14
|
+
return elementName.type === 'JSXIdentifier' && elementName.name === localName;
|
|
15
|
+
})
|
|
16
|
+
.forEach(function (path) {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
|
+
var element = path.node;
|
|
19
|
+
var openingElement = element.openingElement;
|
|
20
|
+
var existingLabelProp = (_a = openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'label'; });
|
|
21
|
+
// Получаем содержимое из props children
|
|
22
|
+
var childrenProp = (_b = openingElement.attributes) === null || _b === void 0 ? void 0 : _b.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'children'; });
|
|
23
|
+
// Получаем содержимое из обычных children
|
|
24
|
+
var regularChildren = (_c = element.children) === null || _c === void 0 ? void 0 : _c.filter(function (child) { return child.type !== 'JSXText' || child.value.trim() !== ''; });
|
|
25
|
+
var labelValue;
|
|
26
|
+
if (childrenProp && childrenProp.type === 'JSXAttribute') {
|
|
27
|
+
// Если есть проп children
|
|
28
|
+
if (((_d = childrenProp.value) === null || _d === void 0 ? void 0 : _d.type) === 'JSXElement') {
|
|
29
|
+
// Если children содержит JSX элемент, оборачиваем его в Fragment
|
|
30
|
+
labelValue = j.jsxExpressionContainer(j.jsxFragment(j.jsxOpeningFragment(), j.jsxClosingFragment(), [childrenProp.value]));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
labelValue = childrenProp.value;
|
|
34
|
+
}
|
|
35
|
+
(0, codemod_helpers_1.removeAttribute)(openingElement.attributes, childrenProp);
|
|
36
|
+
}
|
|
37
|
+
else if (regularChildren && regularChildren.length > 0) {
|
|
38
|
+
if (regularChildren.length === 1 && regularChildren[0].type === 'JSXText') {
|
|
39
|
+
var firstChild = regularChildren[0];
|
|
40
|
+
if (firstChild.type === 'JSXText') {
|
|
41
|
+
labelValue = j.jsxExpressionContainer(j.stringLiteral(firstChild.value.trim()));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Оборачиваем все children в Fragment
|
|
46
|
+
labelValue = j.jsxExpressionContainer(j.jsxFragment(j.jsxOpeningFragment(), j.jsxClosingFragment(), regularChildren));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (labelValue) {
|
|
50
|
+
if (existingLabelProp) {
|
|
51
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"label\" prop. Need to remove \"children\" prop. You can mode \"children\" value to \"label\" prop"));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Очищаем существующие children
|
|
55
|
+
element.children = [];
|
|
56
|
+
// Добавляем проп label
|
|
57
|
+
(_e = openingElement.attributes) === null || _e === void 0 ? void 0 : _e.push(j.jsxAttribute(j.jsxIdentifier('label'), labelValue));
|
|
58
|
+
if (needToAddHideLabelProps) {
|
|
59
|
+
// Добавляем проп hideLabelOnVKCom и hideLabelOnIOS, так как раньше children был скрыт визуально
|
|
60
|
+
// и после того как мы перенесли children в label, визуально ничего не должно измениться
|
|
61
|
+
(_f = openingElement.attributes) === null || _f === void 0 ? void 0 : _f.push(j.jsxAttribute(j.jsxIdentifier('hideLabelOnVKCom')));
|
|
62
|
+
(_g = openingElement.attributes) === null || _g === void 0 ? void 0 : _g.push(j.jsxAttribute(j.jsxIdentifier('hideLabelOnIOS')));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return source.toSource();
|
|
67
|
+
};
|
|
68
|
+
exports.moveFromChildrenToLabel = moveFromChildrenToLabel;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeChildrenFromComponent = void 0;
|
|
4
|
+
var removeChildrenFromComponent = function (api, source, localName) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
source
|
|
7
|
+
.find(j.JSXElement)
|
|
8
|
+
.filter(function (path) {
|
|
9
|
+
var elementName = path.node.openingElement.name;
|
|
10
|
+
return elementName.type === 'JSXIdentifier' && elementName.name === localName;
|
|
11
|
+
})
|
|
12
|
+
.forEach(function (path) {
|
|
13
|
+
var element = path.node;
|
|
14
|
+
element.children = [];
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.removeChildrenFromComponent = removeChildrenFromComponent;
|
|
@@ -0,0 +1,60 @@
|
|
|
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, 'Counter', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
source.find(j.JSXOpeningElement, { name: { name: localName } }).forEach(function (path) {
|
|
17
|
+
var attributes = path.node.attributes;
|
|
18
|
+
if (!attributes || !attributes.length) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var modeProp = attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'mode'; });
|
|
22
|
+
if (!modeProp) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var oldMode = (0, codemod_helpers_1.getStringValueFromAttribute)(modeProp);
|
|
26
|
+
if (!oldMode) {
|
|
27
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"mode\" prop. Need to replace it to another value and add prop appearance"));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var newMode, newAppearance;
|
|
31
|
+
switch (oldMode) {
|
|
32
|
+
case 'inherit':
|
|
33
|
+
newMode = 'inherit';
|
|
34
|
+
break;
|
|
35
|
+
case 'primary':
|
|
36
|
+
newMode = 'primary';
|
|
37
|
+
newAppearance = 'accent';
|
|
38
|
+
break;
|
|
39
|
+
case 'secondary':
|
|
40
|
+
newMode = 'primary';
|
|
41
|
+
newAppearance = 'neutral';
|
|
42
|
+
break;
|
|
43
|
+
case 'prominent':
|
|
44
|
+
newMode = 'primary';
|
|
45
|
+
newAppearance = 'accent-red';
|
|
46
|
+
break;
|
|
47
|
+
case 'contrast':
|
|
48
|
+
newMode = 'contrast';
|
|
49
|
+
newAppearance = 'accent';
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (newMode) {
|
|
53
|
+
modeProp.value = j.stringLiteral(newMode);
|
|
54
|
+
if (newAppearance) {
|
|
55
|
+
attributes.push(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral(newAppearance)));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return source.toSource();
|
|
60
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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, 'DatePicker', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
source
|
|
17
|
+
.find(j.JSXElement, {
|
|
18
|
+
openingElement: {
|
|
19
|
+
name: { name: localName },
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
.forEach(function () {
|
|
23
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(localName, ". component DatePicker was removed in v7.0.0, please use Input, Select or DateInput component"));
|
|
24
|
+
});
|
|
25
|
+
return source.toSource();
|
|
26
|
+
}
|
|
@@ -53,6 +53,7 @@ function transformer(file, api, options) {
|
|
|
53
53
|
}
|
|
54
54
|
return undefined;
|
|
55
55
|
}
|
|
56
|
+
(0, codemod_helpers_1.renameProp)(j, source, localName, { topNode: 'top' });
|
|
56
57
|
source.find(j.JSXElement, { openingElement: { name: { name: localName } } }).forEach(function (path) {
|
|
57
58
|
var formItem = path.node;
|
|
58
59
|
var topMultiline;
|
|
@@ -84,8 +85,7 @@ function transformer(file, api, options) {
|
|
|
84
85
|
// Ищем FormItem.TopLabel в пропе top и topNode
|
|
85
86
|
formItemAttributes === null || formItemAttributes === void 0 ? void 0 : formItemAttributes.forEach(function (attr) {
|
|
86
87
|
var _a, _b;
|
|
87
|
-
if (attr.type === 'JSXAttribute' &&
|
|
88
|
-
(attr.name.name === 'top' || attr.name.name === 'topNode')) {
|
|
88
|
+
if (attr.type === 'JSXAttribute' && attr.name.name === 'top') {
|
|
89
89
|
if (((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXElement') {
|
|
90
90
|
topLabelMultiline = findTopLabelRecursive(attr.value);
|
|
91
91
|
}
|
|
@@ -2,9 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
+
var report_1 = require("../../report");
|
|
5
6
|
var remapSizePropValue_1 = require("./common/remapSizePropValue");
|
|
6
7
|
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
8
|
exports.parser = 'tsx';
|
|
9
|
+
function removePropMode(j, api, source, localName) {
|
|
10
|
+
var changeAttributeValue = function (attributes, attribute, attrName, newValue) {
|
|
11
|
+
if (attribute) {
|
|
12
|
+
attribute.value = j.stringLiteral(newValue);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
attributes === null || attributes === void 0 ? void 0 : attributes.push(j.jsxAttribute(j.jsxIdentifier(attrName), j.stringLiteral(newValue)));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
source
|
|
19
|
+
.find(j.JSXOpeningElement, {
|
|
20
|
+
name: {
|
|
21
|
+
name: localName,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
.forEach(function (path) {
|
|
25
|
+
var attributes = path.node.attributes;
|
|
26
|
+
var modeAttr = (attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'mode'; })) || undefined;
|
|
27
|
+
var sizeAttr = (attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'size'; })) || undefined;
|
|
28
|
+
var hasSpread = !!(attributes === null || attributes === void 0 ? void 0 : attributes.some(function (attr) { return attr.type === 'JSXSpreadAttribute'; }));
|
|
29
|
+
if (!modeAttr) {
|
|
30
|
+
if (hasSpread) {
|
|
31
|
+
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: remove mode attribute and replace it by size prop"));
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(0, codemod_helpers_1.removeAttribute)(attributes, modeAttr);
|
|
36
|
+
var modeValue = (0, codemod_helpers_1.getStringValueFromAttribute)(modeAttr);
|
|
37
|
+
if (!modeValue) {
|
|
38
|
+
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: remove mode attribute and replace it by size prop"));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var sizeValue = (0, codemod_helpers_1.getStringValueFromAttribute)(sizeAttr);
|
|
42
|
+
if (modeValue === 'primary' && sizeValue === 'l') {
|
|
43
|
+
changeAttributeValue(attributes, sizeAttr, 'size', 'xl');
|
|
44
|
+
}
|
|
45
|
+
else if (modeValue === 'tertiary' || (modeValue === 'primary' && sizeValue === 'm')) {
|
|
46
|
+
changeAttributeValue(attributes, sizeAttr, 'size', 'm');
|
|
47
|
+
}
|
|
48
|
+
else if (modeValue === 'secondary') {
|
|
49
|
+
changeAttributeValue(attributes, sizeAttr, 'size', 's');
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
8
53
|
function transformer(file, api, options) {
|
|
9
54
|
var alias = options.alias;
|
|
10
55
|
var j = api.jscodeshift;
|
|
@@ -24,5 +69,6 @@ function transformer(file, api, options) {
|
|
|
24
69
|
},
|
|
25
70
|
});
|
|
26
71
|
(0, codemod_helpers_1.renameProp)(j, source, localName, { aside: 'after' });
|
|
72
|
+
removePropMode(j, api, source, localName);
|
|
27
73
|
return source.toSource();
|
|
28
74
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 moveFromChildrenToLabel_1 = require("./common/moveFromChildrenToLabel");
|
|
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, 'PanelHeaderBack', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, moveFromChildrenToLabel_1.moveFromChildrenToLabel)(api, source, localName, true);
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 moveFromChildrenToLabel_1 = require("./common/moveFromChildrenToLabel");
|
|
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, 'PanelHeaderClose', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, moveFromChildrenToLabel_1.moveFromChildrenToLabel)(api, source, localName, false);
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 removeChildrenFromComponent_1 = require("./common/removeChildrenFromComponent");
|
|
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, 'PanelHeaderEdit', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, codemod_helpers_1.removeProps)(j, api, source, localName, ['children', 'label']);
|
|
17
|
+
(0, removeChildrenFromComponent_1.removeChildrenFromComponent)(api, source, localName);
|
|
18
|
+
return source.toSource();
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 moveFromChildrenToLabel_1 = require("./common/moveFromChildrenToLabel");
|
|
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, 'PanelHeaderSubmit', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, moveFromChildrenToLabel_1.moveFromChildrenToLabel)(api, source, localName, false);
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var remapSizePropValue_1 = require("./common/remapSizePropValue");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
var componentName = 'PanelSpinner';
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
var alias = options.alias;
|
|
11
|
+
var j = api.jscodeshift;
|
|
12
|
+
var source = j(file.source);
|
|
13
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
14
|
+
if (!localName) {
|
|
15
|
+
return source.toSource();
|
|
16
|
+
}
|
|
17
|
+
(0, remapSizePropValue_1.remapSizePropValue)({
|
|
18
|
+
j: j,
|
|
19
|
+
api: api,
|
|
20
|
+
source: source,
|
|
21
|
+
componentName: localName,
|
|
22
|
+
sizesMap: {
|
|
23
|
+
large: 'xl',
|
|
24
|
+
medium: 'l',
|
|
25
|
+
regular: 'm',
|
|
26
|
+
small: 's',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return source.toSource();
|
|
30
|
+
}
|
|
@@ -6,20 +6,6 @@ var codemod_helpers_1 = require("../../codemod-helpers");
|
|
|
6
6
|
var report_1 = require("../../report");
|
|
7
7
|
exports.parser = 'tsx';
|
|
8
8
|
function replaceModeToFixed(j, source, api, localName) {
|
|
9
|
-
var getValueFromAttribute = function (attribute) {
|
|
10
|
-
var _a, _b;
|
|
11
|
-
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
12
|
-
return attribute.value.value;
|
|
13
|
-
}
|
|
14
|
-
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
15
|
-
var expression = attribute.value.expression;
|
|
16
|
-
if (expression.type === 'StringLiteral') {
|
|
17
|
-
return expression.value;
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
};
|
|
23
9
|
source
|
|
24
10
|
.find(j.JSXElement, {
|
|
25
11
|
openingElement: {
|
|
@@ -31,9 +17,9 @@ function replaceModeToFixed(j, source, api, localName) {
|
|
|
31
17
|
.find(j.JSXAttribute)
|
|
32
18
|
.filter(function (attribute) { return attribute.node.name.name === 'mode'; })
|
|
33
19
|
.forEach(function (attr) {
|
|
34
|
-
var value =
|
|
20
|
+
var value = (0, codemod_helpers_1.getStringValueFromAttribute)(attr.node);
|
|
35
21
|
if (value === null) {
|
|
36
|
-
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: change prop mode to flag fixed"));
|
|
22
|
+
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: change prop mode to flag fixed."));
|
|
37
23
|
return;
|
|
38
24
|
}
|
|
39
25
|
if (value === 'overflow') {
|
|
@@ -20,26 +20,13 @@ function transformer(file, api, options) {
|
|
|
20
20
|
'row-reverse': 'inline-end',
|
|
21
21
|
'column': 'block-start',
|
|
22
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
23
|
source
|
|
37
24
|
.find(j.JSXElement, { openingElement: { name: { name: localName } } })
|
|
38
25
|
.find(j.JSXAttribute, { name: { name: attributeToReplace } })
|
|
39
26
|
.forEach(function (path) {
|
|
40
27
|
var avatar = path.node;
|
|
41
28
|
avatar.name.name = newAttributeName;
|
|
42
|
-
var value =
|
|
29
|
+
var value = (0, codemod_helpers_1.getStringValueFromAttribute)(avatar);
|
|
43
30
|
if (!value || !directionToAvatarsPosition[value]) {
|
|
44
31
|
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change direction prop to avatarsPosition."));
|
|
45
32
|
return;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/vkui-codemods",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Codemods for automatic VKUI major version upgrade",
|
|
5
5
|
"repository": "https://github.com/VKCOM/VKUI",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://vkui.io/",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bin": "./dist/index.js",
|
|
9
9
|
"files": [
|
|
@@ -15,22 +15,21 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"chalk": "^4.1.2",
|
|
18
|
-
"commander": "^
|
|
19
|
-
"cross-spawn": "^7.0.
|
|
20
|
-
"jscodeshift": "^17.
|
|
18
|
+
"commander": "^14.0.0",
|
|
19
|
+
"cross-spawn": "^7.0.5",
|
|
20
|
+
"jscodeshift": "^17.3.0",
|
|
21
21
|
"prompts": "^2.4.2",
|
|
22
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.9.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@swc/core": "^1.
|
|
26
|
-
"@swc/jest": "^0.2.
|
|
25
|
+
"@swc/core": "^1.13.3",
|
|
26
|
+
"@swc/jest": "^0.2.39",
|
|
27
27
|
"@types/cross-spawn": "^6.0.6",
|
|
28
|
-
"@types/jest": "^
|
|
29
|
-
"@types/jscodeshift": "^
|
|
30
|
-
"@types/node": "^
|
|
28
|
+
"@types/jest": "^30.0.0",
|
|
29
|
+
"@types/jscodeshift": "^17.3.0",
|
|
30
|
+
"@types/node": "^24.1.0",
|
|
31
31
|
"@types/prompts": "^2.4.9",
|
|
32
|
-
"jest": "^
|
|
33
|
-
"ts-node": "^10.9.2"
|
|
32
|
+
"jest": "^30.0.5"
|
|
34
33
|
},
|
|
35
34
|
"scripts": {
|
|
36
35
|
"prepack": "yarn run build",
|