@workday/canvas-kit-codemod 6.8.8 → 6.9.0-next.4
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/es6/v5/recategorizeButtons.js +1 -1
- package/dist/es6/v7/compoundActionBar.d.ts +3 -0
- package/dist/es6/v7/compoundActionBar.d.ts.map +1 -0
- package/dist/es6/v7/compoundActionBar.js +91 -0
- package/dist/es6/v7/compoundBanner.d.ts +3 -0
- package/dist/es6/v7/compoundBanner.d.ts.map +1 -0
- package/dist/es6/v7/compoundBanner.js +133 -0
- package/dist/es6/v7/index.d.ts +4 -0
- package/dist/es6/v7/index.d.ts.map +1 -0
- package/dist/es6/v7/index.js +40 -0
- package/dist/es6/v7/recategorizeIconButtons.d.ts +3 -0
- package/dist/es6/v7/recategorizeIconButtons.d.ts.map +1 -0
- package/dist/es6/v7/recategorizeIconButtons.js +148 -0
- package/dist/es6/v7/removePropFromPopper.d.ts +3 -0
- package/dist/es6/v7/removePropFromPopper.d.ts.map +1 -0
- package/dist/es6/v7/removePropFromPopper.js +31 -0
- package/dist/es6/v7/renameIconPosition.d.ts +3 -0
- package/dist/es6/v7/renameIconPosition.d.ts.map +1 -0
- package/dist/es6/v7/renameIconPosition.js +37 -0
- package/dist/es6/v7/renameIconRef.d.ts +3 -0
- package/dist/es6/v7/renameIconRef.d.ts.map +1 -0
- package/dist/es6/v7/renameIconRef.js +70 -0
- package/dist/es6/v7/renameLayoutImports.d.ts +4 -0
- package/dist/es6/v7/renameLayoutImports.d.ts.map +1 -0
- package/dist/es6/v7/renameLayoutImports.js +105 -0
- package/dist/es6/v7/updateDisclosureShowHide.d.ts +3 -0
- package/dist/es6/v7/updateDisclosureShowHide.d.ts.map +1 -0
- package/dist/es6/v7/updateDisclosureShowHide.js +96 -0
- package/dist/es6/v7/updateModelSignatures.d.ts +3 -0
- package/dist/es6/v7/updateModelSignatures.d.ts.map +1 -0
- package/dist/es6/v7/updateModelSignatures.js +90 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts +3 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts.map +1 -0
- package/dist/es6/v7/updateSegmentedControl.js +24 -0
- package/dist/es6/v7/updateTabs.d.ts +3 -0
- package/dist/es6/v7/updateTabs.d.ts.map +1 -0
- package/dist/es6/v7/updateTabs.js +48 -0
- package/dist/es6/v7/utils/getImportRenameMap.d.ts +7 -0
- package/dist/es6/v7/utils/getImportRenameMap.d.ts.map +1 -0
- package/dist/es6/v7/utils/getImportRenameMap.js +52 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.d.ts +20 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.d.ts.map +1 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.js +46 -0
- package/index.js +7 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0H7E"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
2
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
5
|
+
r[k] = a[j];
|
|
6
|
+
return r;
|
|
7
|
+
};
|
|
8
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
9
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
10
|
+
var actionBarPackage = '@workday/canvas-kit-react/action-bar';
|
|
11
|
+
export default function transformer(file, api, options) {
|
|
12
|
+
var j = api.jscodeshift;
|
|
13
|
+
var root = j(file.source);
|
|
14
|
+
if (!hasImportSpecifiers(api, root, actionBarPackage, ['ActionBar'])) {
|
|
15
|
+
return file.source;
|
|
16
|
+
}
|
|
17
|
+
// Replace default import with named or renamed import
|
|
18
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
19
|
+
var _a;
|
|
20
|
+
var parent = nodePath.parent;
|
|
21
|
+
var importSource = String(parent.node.source.value);
|
|
22
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
23
|
+
if (actionBarPackage === importSource && localName) {
|
|
24
|
+
nodePath.replace(j.importSpecifier(j.identifier('ActionBar'), j.identifier(localName)));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/action-bar'), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
28
|
+
root
|
|
29
|
+
.find(j.JSXElement, function (value) {
|
|
30
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
31
|
+
(value.openingElement.name.name === importMap.ActionBar ||
|
|
32
|
+
value.openingElement.name.name === styledMap.ActionBar);
|
|
33
|
+
})
|
|
34
|
+
.forEach(function (nodePath) {
|
|
35
|
+
(nodePath.value.children || []).forEach(function (child, index) {
|
|
36
|
+
if (child.type === 'JSXElement') {
|
|
37
|
+
// bail early if we find a `ActionBar.List` as a child
|
|
38
|
+
if (child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
39
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
40
|
+
child.openingElement.name.object.name === 'ActionBar' &&
|
|
41
|
+
child.openingElement.name.property.type === 'JSXIdentifier' &&
|
|
42
|
+
child.openingElement.name.property.name === 'List') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Transform Primary and Secondary button to ActionBar.Item
|
|
46
|
+
if (child.openingElement.name.type === 'JSXIdentifier') {
|
|
47
|
+
var buttonAttrs = child.openingElement.attributes || [];
|
|
48
|
+
var ActionItemJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('Item'));
|
|
49
|
+
if (nodePath.value.children &&
|
|
50
|
+
['PrimaryButton', 'SecondaryButton'].includes(child.openingElement.name.name)) {
|
|
51
|
+
// Add isPrimary attribute to primary Action Item
|
|
52
|
+
var elementAttrs = child.openingElement.name.name === 'PrimaryButton'
|
|
53
|
+
? __spreadArrays(buttonAttrs, [j.jsxAttribute(j.jsxIdentifier('isPrimary'))]) : buttonAttrs;
|
|
54
|
+
nodePath.value.children[index] = j.jsxElement(j.jsxOpeningElement(ActionItemJSX, elementAttrs), j.jsxClosingElement(ActionItemJSX), child.children);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var children = nodePath.value.children || [];
|
|
60
|
+
// Remove all attributes from ActionBar to replace them to ActionBar.List
|
|
61
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
62
|
+
if (attributes) {
|
|
63
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) { return !(item.type === 'JSXAttribute' && item.name.type === 'JSXIdentifier'); });
|
|
64
|
+
}
|
|
65
|
+
// Create closing element for ActionBar without closing tag
|
|
66
|
+
if (nodePath.value.openingElement.selfClosing) {
|
|
67
|
+
nodePath.value.openingElement.selfClosing = false;
|
|
68
|
+
nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
|
|
69
|
+
}
|
|
70
|
+
// Create ActionBar.List component
|
|
71
|
+
var ActionBarListJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('List'));
|
|
72
|
+
var subComponentJSX = j.jsxElement(j.jsxOpeningElement(ActionBarListJSX,
|
|
73
|
+
// All attributes except fixed should be passed
|
|
74
|
+
attributes === null ||
|
|
75
|
+
// All attributes except fixed should be passed
|
|
76
|
+
attributes === void 0 ? void 0 :
|
|
77
|
+
// All attributes except fixed should be passed
|
|
78
|
+
attributes.filter(function (attr) { return !(attr.type === 'JSXAttribute' && attr.name.name === 'fixed'); })), j.jsxClosingElement(ActionBarListJSX), children);
|
|
79
|
+
// Keep space for code structure
|
|
80
|
+
var textLiteralStart = children.find(function (child) { return child.type === 'JSXText'; });
|
|
81
|
+
var textLiteralEnd = children
|
|
82
|
+
.slice()
|
|
83
|
+
.reverse()
|
|
84
|
+
.find(function (child) { return child.type === 'JSXText'; });
|
|
85
|
+
nodePath.value.children =
|
|
86
|
+
textLiteralStart && textLiteralEnd
|
|
87
|
+
? [textLiteralStart, subComponentJSX, textLiteralEnd]
|
|
88
|
+
: [subComponentJSX];
|
|
89
|
+
});
|
|
90
|
+
return root.toSource();
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compoundBanner.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAUR,MAAM,aAAa,CAAC;AAQrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuM7E"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
function filterDefined(input) {
|
|
3
|
+
return !!input;
|
|
4
|
+
}
|
|
5
|
+
export default function transformer(file, api, options) {
|
|
6
|
+
var j = api.jscodeshift;
|
|
7
|
+
var root = j(file.source);
|
|
8
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/banner'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
9
|
+
if (!containsCanvasImports) {
|
|
10
|
+
return file.source;
|
|
11
|
+
}
|
|
12
|
+
root
|
|
13
|
+
.find(j.JSXElement, function (value) {
|
|
14
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
15
|
+
(value.openingElement.name.name === importMap.Banner ||
|
|
16
|
+
value.openingElement.name.name === styledMap.Banner);
|
|
17
|
+
})
|
|
18
|
+
.forEach(function (nodePath) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
// bail early if we find a `Banner.Label` as a child
|
|
21
|
+
for (var _i = 0, _c = nodePath.value.children || []; _i < _c.length; _i++) {
|
|
22
|
+
var child = _c[_i];
|
|
23
|
+
if (child.type === 'JSXElement' &&
|
|
24
|
+
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
25
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
26
|
+
child.openingElement.name.object.name === 'Banner' &&
|
|
27
|
+
child.openingElement.name.property.type === 'JSXIdentifier' &&
|
|
28
|
+
child.openingElement.name.property.name === 'Label') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
var findAttribute = function (name) { return function (item) {
|
|
33
|
+
if (item.type === 'JSXAttribute' &&
|
|
34
|
+
item.name.type === 'JSXIdentifier' &&
|
|
35
|
+
item.name.name === name) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}; };
|
|
40
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
41
|
+
if (attributes) {
|
|
42
|
+
var label = attributes.find(findAttribute('label'));
|
|
43
|
+
var actionText = attributes.find(findAttribute('actionText'));
|
|
44
|
+
var errorIndex_1 = attributes.findIndex(findAttribute('error'));
|
|
45
|
+
var variantIndex_1 = attributes.findIndex(findAttribute('variant'));
|
|
46
|
+
if (errorIndex_1 >= 0 && ((_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a[errorIndex_1])) {
|
|
47
|
+
var errorExpression = nodePath.value.openingElement.attributes[errorIndex_1].value.expression;
|
|
48
|
+
var getNameToBoolean = function (name) {
|
|
49
|
+
return name === 'Error' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
50
|
+
};
|
|
51
|
+
var setHasError = function (hasErrorValue) {
|
|
52
|
+
if (nodePath.value.openingElement.attributes) {
|
|
53
|
+
nodePath.value.openingElement.attributes[errorIndex_1] = j.jsxAttribute(j.jsxIdentifier('hasError'), j.jsxExpressionContainer(hasErrorValue));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (errorExpression.property) {
|
|
57
|
+
var previousExpression = errorExpression;
|
|
58
|
+
var newValue = getNameToBoolean(previousExpression.property.name);
|
|
59
|
+
setHasError(newValue);
|
|
60
|
+
}
|
|
61
|
+
if (errorExpression.test) {
|
|
62
|
+
var previousExpression = errorExpression;
|
|
63
|
+
var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
64
|
+
setHasError(newValue);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (variantIndex_1 >= 0 && ((_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b[variantIndex_1])) {
|
|
68
|
+
var stickyExpression = nodePath.value.openingElement.attributes[variantIndex_1].value.expression;
|
|
69
|
+
var getNameToBoolean = function (name) {
|
|
70
|
+
return name === 'Sticky' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
71
|
+
};
|
|
72
|
+
var setIsSticky = function (hasStickyValue) {
|
|
73
|
+
if (nodePath.value.openingElement.attributes) {
|
|
74
|
+
nodePath.value.openingElement.attributes[variantIndex_1] = j.jsxAttribute(j.jsxIdentifier('isSticky'), j.jsxExpressionContainer(hasStickyValue));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (stickyExpression.property) {
|
|
78
|
+
var previousExpression = stickyExpression;
|
|
79
|
+
var newValue = getNameToBoolean(previousExpression.property.name);
|
|
80
|
+
setIsSticky(newValue);
|
|
81
|
+
}
|
|
82
|
+
if (stickyExpression.test) {
|
|
83
|
+
var previousExpression = stickyExpression;
|
|
84
|
+
var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
85
|
+
setIsSticky(newValue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// remove these attributes from the list - we'll add them as sub components
|
|
89
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) {
|
|
90
|
+
if (item.type === 'JSXAttribute' &&
|
|
91
|
+
item.name.type === 'JSXIdentifier' &&
|
|
92
|
+
['label', 'actionText'].includes(item.name.name)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
var BannerIconJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Icon'));
|
|
98
|
+
var BannerLabelJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Label'));
|
|
99
|
+
var BannerActionTextJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('ActionText'));
|
|
100
|
+
var convertAttributeToChildren = function (input) {
|
|
101
|
+
var _a;
|
|
102
|
+
switch ((_a = input.value) === null || _a === void 0 ? void 0 : _a.type) {
|
|
103
|
+
case 'JSXExpressionContainer':
|
|
104
|
+
// unwrap JSXElements
|
|
105
|
+
if (input.value.expression.type === 'JSXElement') {
|
|
106
|
+
return [input.value.expression];
|
|
107
|
+
}
|
|
108
|
+
return [input.value];
|
|
109
|
+
default:
|
|
110
|
+
return [input.value];
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var createSelfClosingTag = function (Tag) {
|
|
114
|
+
var OpeningTag = j.jsxOpeningElement(Tag);
|
|
115
|
+
OpeningTag.selfClosing = true;
|
|
116
|
+
return j.jsxElement(OpeningTag);
|
|
117
|
+
};
|
|
118
|
+
nodePath.value.openingElement.selfClosing = false;
|
|
119
|
+
// Add subcomponents back as children
|
|
120
|
+
nodePath.value.children = [
|
|
121
|
+
createSelfClosingTag(BannerIconJSX),
|
|
122
|
+
!!label
|
|
123
|
+
? j.jsxElement(j.jsxOpeningElement(BannerLabelJSX), j.jsxClosingElement(BannerLabelJSX), convertAttributeToChildren(label))
|
|
124
|
+
: createSelfClosingTag(BannerLabelJSX),
|
|
125
|
+
!!actionText
|
|
126
|
+
? j.jsxElement(j.jsxOpeningElement(BannerActionTextJSX), j.jsxClosingElement(BannerActionTextJSX), convertAttributeToChildren(actionText))
|
|
127
|
+
: createSelfClosingTag(BannerActionTextJSX),
|
|
128
|
+
].filter(filterDefined);
|
|
129
|
+
nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return root.toSource();
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AActC,QAAA,MAAM,SAAS,EAAE,SAiBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import compoundActionBar from './compoundActionBar';
|
|
13
|
+
import compoundBanner from './compoundBanner';
|
|
14
|
+
import removePropFromPopper from './removePropFromPopper';
|
|
15
|
+
import renameIconRef from './renameIconRef';
|
|
16
|
+
import renameLayoutImports from './renameLayoutImports';
|
|
17
|
+
import updateSegmentedControl from './updateSegmentedControl';
|
|
18
|
+
import renameIconPosition from './renameIconPosition';
|
|
19
|
+
import recategorizeIconButtons from './recategorizeIconButtons';
|
|
20
|
+
import updateModelSignatures from './updateModelSignatures';
|
|
21
|
+
import updateTabs from './updateTabs';
|
|
22
|
+
import updateDisclosureShowHide from './updateDisclosureShowHide';
|
|
23
|
+
var transform = function (file, api, options) {
|
|
24
|
+
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
25
|
+
var fixes = [
|
|
26
|
+
compoundActionBar,
|
|
27
|
+
compoundBanner,
|
|
28
|
+
recategorizeIconButtons,
|
|
29
|
+
renameIconRef,
|
|
30
|
+
removePropFromPopper,
|
|
31
|
+
renameIconPosition,
|
|
32
|
+
renameLayoutImports,
|
|
33
|
+
updateSegmentedControl,
|
|
34
|
+
updateModelSignatures,
|
|
35
|
+
updateTabs,
|
|
36
|
+
updateDisclosureShowHide,
|
|
37
|
+
];
|
|
38
|
+
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
39
|
+
};
|
|
40
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recategorizeIconButtons.d.ts","sourceRoot":"","sources":["../../../lib/v7/recategorizeIconButtons.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAMR,MAAM,aAAa,CAAC;AAcrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA8K7E"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
var updateJSXTag = function (nodePath, newTag) {
|
|
4
|
+
var componentName = nodePath.value.openingElement.name.name;
|
|
5
|
+
if (componentName === 'IconButton') {
|
|
6
|
+
nodePath.value.openingElement.name.name = newTag;
|
|
7
|
+
if (nodePath.value.closingElement) {
|
|
8
|
+
nodePath.value.closingElement.name.name = newTag;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export default function transformer(file, api, options) {
|
|
13
|
+
var j = api.jscodeshift;
|
|
14
|
+
var root = j(file.source);
|
|
15
|
+
var requiredImportSpecifiers = [];
|
|
16
|
+
/**
|
|
17
|
+
* 1. Find button imports
|
|
18
|
+
*/
|
|
19
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
20
|
+
if (!containsCanvasImports) {
|
|
21
|
+
return file.source;
|
|
22
|
+
}
|
|
23
|
+
var buttonType = 'TertiaryButton'; //default button if no variant is specified
|
|
24
|
+
// Button Mapping
|
|
25
|
+
// circle -> tertiary
|
|
26
|
+
// circle-filled -> secondary
|
|
27
|
+
// inverse -> tertiary inverse
|
|
28
|
+
// inverse-filled -> secondary inverse
|
|
29
|
+
// plain/square -> not supported
|
|
30
|
+
// square-filled -> not supported
|
|
31
|
+
/**
|
|
32
|
+
* 2. Find `IconButton`
|
|
33
|
+
* - If it has no variant, it means it's "circle" which is the default
|
|
34
|
+
* - Swap to `TertiaryButton`
|
|
35
|
+
* - Add `TertiaryButton` import if it doesn't exist.
|
|
36
|
+
* - If not
|
|
37
|
+
* - check the variant of the IconButton
|
|
38
|
+
* - Swap it out for the appropriate mapping
|
|
39
|
+
*/
|
|
40
|
+
root
|
|
41
|
+
.find(j.JSXElement, function (value) {
|
|
42
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
43
|
+
(value.openingElement.name.name === importMap.IconButton ||
|
|
44
|
+
value.openingElement.name.name === styledMap.IconButton);
|
|
45
|
+
})
|
|
46
|
+
.forEach(function (nodePath) {
|
|
47
|
+
var _a;
|
|
48
|
+
var attrs = nodePath.value.openingElement.attributes;
|
|
49
|
+
var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
|
|
50
|
+
// Default IconButton variant is `circle`
|
|
51
|
+
if (variantProp) {
|
|
52
|
+
var valueBody = variantProp.value;
|
|
53
|
+
if ((valueBody === null || valueBody === void 0 ? void 0 : valueBody.type) === 'JSXExpressionContainer' &&
|
|
54
|
+
valueBody.expression.type === 'StringLiteral') {
|
|
55
|
+
variantProp.value = valueBody.expression;
|
|
56
|
+
}
|
|
57
|
+
var variantPropValue = variantProp.value.value;
|
|
58
|
+
if (variantPropValue) {
|
|
59
|
+
variantProp.value.value = variantPropValue.replace('Filled', '');
|
|
60
|
+
buttonType = /filled/gi.test(variantPropValue) ? 'SecondaryButton' : 'TertiaryButton';
|
|
61
|
+
if (!variantPropValue.includes('inverse')) {
|
|
62
|
+
(_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.warn(chalk.bold.red('** CANNOT UPDATE EXPRESSION FOR ICON BUTTON VARIANT. **') +
|
|
67
|
+
'\nYou will need to manually update this file to fix this warning.' +
|
|
68
|
+
'\nFile Name: ' +
|
|
69
|
+
chalk.blue(file.path) +
|
|
70
|
+
'\nConsult Upgrade Guide Section for v7: "Removal of Icon Button"');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
updateJSXTag(nodePath, buttonType);
|
|
74
|
+
requiredImportSpecifiers.push(buttonType);
|
|
75
|
+
});
|
|
76
|
+
if (requiredImportSpecifiers.length === 0) {
|
|
77
|
+
return file.source;
|
|
78
|
+
}
|
|
79
|
+
// Find all instances of IconButton within a style function
|
|
80
|
+
// const StyledIconButton = styled(IconButton) gets renamed to
|
|
81
|
+
// const StyledIconButton = styled(CorrectButtonMapping)
|
|
82
|
+
root.find(j.VariableDeclarator).forEach(function (nodePath) {
|
|
83
|
+
var _a;
|
|
84
|
+
if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
|
|
85
|
+
nodePath.value.init.callee.type === 'CallExpression' &&
|
|
86
|
+
nodePath.value.init.callee.callee.type === 'Identifier' &&
|
|
87
|
+
nodePath.value.init.callee.callee.name === 'styled' &&
|
|
88
|
+
nodePath.value.init.callee.arguments[0].type === 'Identifier' &&
|
|
89
|
+
nodePath.value.init.callee.arguments[0].name === importMap.IconButton) {
|
|
90
|
+
nodePath.value.init.callee.arguments[0].name = buttonType;
|
|
91
|
+
requiredImportSpecifiers.push(buttonType);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Remove old imports: `IconButton`
|
|
96
|
+
* Add new required imports
|
|
97
|
+
*/
|
|
98
|
+
var buttonImports = root.find(j.ImportDeclaration, {
|
|
99
|
+
source: {
|
|
100
|
+
value: function (value) {
|
|
101
|
+
return value === '@workday/canvas-kit-react' || value === '@workday/canvas-kit-react/button';
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (!buttonImports.length) {
|
|
106
|
+
// Add new specifiers to a new import
|
|
107
|
+
var allImports = root.find(j.ImportDeclaration);
|
|
108
|
+
var lastImport = allImports.at(allImports.length);
|
|
109
|
+
if (lastImport) {
|
|
110
|
+
lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(function (specifier) { return j.importSpecifier(j.identifier(specifier)); }), j.stringLiteral('@workday/canvas-kit-react/button')));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
buttonImports.forEach(function (nodePath) {
|
|
115
|
+
var _a, _b, _c;
|
|
116
|
+
var node = nodePath.node;
|
|
117
|
+
var specifiersToRemove = ['IconButton'];
|
|
118
|
+
// Remove old specifiers
|
|
119
|
+
if (typeof node.source.value === 'string' &&
|
|
120
|
+
node.source.value.includes('@workday/canvas-kit-react')) {
|
|
121
|
+
(_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
124
|
+
specifiersToRemove.includes(specifier.imported.name)) {
|
|
125
|
+
// delete specifier
|
|
126
|
+
(_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.splice((_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.indexOf(specifier), 1);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// Add new specifiers to existing import
|
|
131
|
+
requiredImportSpecifiers.forEach(function (specifier) {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(function (existing) { return existing.type === 'ImportSpecifier' && existing.imported.name === specifier; }))) {
|
|
134
|
+
// Only add a specifier if it has not already been declared
|
|
135
|
+
if (!importMap[buttonType]) {
|
|
136
|
+
(_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.push(j.importSpecifier(j.identifier(specifier)));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
console.log((_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.length);
|
|
141
|
+
// if we removed all specifiers, remove the import
|
|
142
|
+
if (!((_c = node.specifiers) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
143
|
+
nodePath.prune();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return root.toSource();
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removePropFromPopper.d.ts","sourceRoot":"","sources":["../../../lib/v7/removePropFromPopper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAM/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAkC7E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
var popupBarPackage = '@workday/canvas-kit-react/popup';
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
if (!hasImportSpecifiers(api, root, popupBarPackage, ['Popper'])) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
var _a = getImportRenameMap(j, root, popupBarPackage), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
11
|
+
root
|
|
12
|
+
.find(j.JSXElement, function (value) {
|
|
13
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
14
|
+
(value.openingElement.name.name === importMap.Popper ||
|
|
15
|
+
value.openingElement.name.name === styledMap.Popper);
|
|
16
|
+
})
|
|
17
|
+
.forEach(function (nodePath) {
|
|
18
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
19
|
+
// Remove containerElement prop from Popper component
|
|
20
|
+
if (attributes) {
|
|
21
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) {
|
|
22
|
+
return item.type === 'JSXAttribute' &&
|
|
23
|
+
item.name.type === 'JSXIdentifier' &&
|
|
24
|
+
['containerElement'].includes(item.name.name)
|
|
25
|
+
? false
|
|
26
|
+
: true;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return root.toSource();
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameIconPosition.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAA+C,MAAM,aAAa,CAAC;AAIjG,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA+C7E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
export default function transformer(file, api, options) {
|
|
3
|
+
var j = api.jscodeshift;
|
|
4
|
+
var root = j(file.source);
|
|
5
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
6
|
+
if (!containsCanvasImports) {
|
|
7
|
+
return file.source;
|
|
8
|
+
}
|
|
9
|
+
root
|
|
10
|
+
.find(j.JSXElement, function (value) {
|
|
11
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
12
|
+
(value.openingElement.name.name ===
|
|
13
|
+
(importMap.PrimaryButton || importMap.SecondaryButton) ||
|
|
14
|
+
value.openingElement.name.name === (styledMap.PrimaryButton || styledMap.SecondaryButton));
|
|
15
|
+
})
|
|
16
|
+
.forEach(function (nodePath) {
|
|
17
|
+
var _a;
|
|
18
|
+
var findAttribute = function (name) { return function (item) {
|
|
19
|
+
return item.type === 'JSXAttribute' &&
|
|
20
|
+
item.name.type === 'JSXIdentifier' &&
|
|
21
|
+
item.name.name === name;
|
|
22
|
+
}; };
|
|
23
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
24
|
+
if (attributes) {
|
|
25
|
+
var iconPosition = attributes.find(findAttribute('iconPosition'));
|
|
26
|
+
if (((_a = iconPosition === null || iconPosition === void 0 ? void 0 : iconPosition.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
27
|
+
if (iconPosition.value.value === 'left') {
|
|
28
|
+
iconPosition.value.value = 'start';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
iconPosition.value.value = 'end';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return root.toSource();
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameIconRef.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAgBlE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiE7E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var inputsMap = {
|
|
3
|
+
'@workday/canvas-kit-react/icon': [
|
|
4
|
+
'AccentIcon',
|
|
5
|
+
'AppletIcon',
|
|
6
|
+
'SystemIcon',
|
|
7
|
+
'SystemIconCircle',
|
|
8
|
+
'Graphic',
|
|
9
|
+
'Svg',
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
export default function transformer(file, api, options) {
|
|
13
|
+
var j = api.jscodeshift;
|
|
14
|
+
var root = j(file.source);
|
|
15
|
+
// defaultImports should be an array of local names that were imported using
|
|
16
|
+
// a default import from any of the modules listed in inputsMap. For example,
|
|
17
|
+
// given...
|
|
18
|
+
//
|
|
19
|
+
// ```
|
|
20
|
+
// import Checkbox from '@workday/canvas-kit-react/checkbox';
|
|
21
|
+
// import CanvasTextArea from '@workday/canvas-kit-react/text-area';
|
|
22
|
+
// import {TextInput} from '@workday/canvas-kit-react/text-input';
|
|
23
|
+
// import StatusIndicator from '@workday/canvas-kit-react/status-indicator';
|
|
24
|
+
// ```
|
|
25
|
+
//
|
|
26
|
+
// ... defaultImports should be set to `['Checkbox', 'CanvasTextArea']`
|
|
27
|
+
var defaultImports = [];
|
|
28
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
29
|
+
var _a;
|
|
30
|
+
var packageName = nodePath.parent.node.source.value;
|
|
31
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
32
|
+
if (packageName in inputsMap && localName) {
|
|
33
|
+
defaultImports.push(localName);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var runningSource = file.source;
|
|
37
|
+
var _loop_1 = function (inputPackageName) {
|
|
38
|
+
var currentRoot = j(runningSource);
|
|
39
|
+
var _a = getImportRenameMap(j, currentRoot, inputPackageName), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
40
|
+
if (containsCanvasImports) {
|
|
41
|
+
var inputNames_1 = inputsMap[inputPackageName];
|
|
42
|
+
currentRoot
|
|
43
|
+
.find(j.JSXIdentifier, function (value) { return value.name === 'iconRef'; })
|
|
44
|
+
.replaceWith(function (nodePath) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
var elementName = (_d = (_c = (_b = (_a = nodePath.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.name;
|
|
47
|
+
// Rewrite inputRef to ref if any of the following are true:
|
|
48
|
+
// (a) elementName was the name used in a default import of the current
|
|
49
|
+
// input being processed (e.g., `import TextInput ...`)
|
|
50
|
+
// (b) elementName was the name used in a named import of the current
|
|
51
|
+
// input being processed (e.g., `import {TextInput} ...` or
|
|
52
|
+
// `import {TextInput as CanvasTextInput} ...`)
|
|
53
|
+
// (c) elementName was created by calling `styled` on the current input
|
|
54
|
+
// being processed (e.g., `const StyledTextInput = styled(TextInput)`)
|
|
55
|
+
if (defaultImports.includes(elementName) ||
|
|
56
|
+
inputNames_1.map(function (n) { return importMap[n]; }).includes(elementName) ||
|
|
57
|
+
inputNames_1.map(function (n) { return styledMap[n]; }).includes(elementName)) {
|
|
58
|
+
return j.jsxIdentifier('ref');
|
|
59
|
+
}
|
|
60
|
+
return nodePath.value;
|
|
61
|
+
});
|
|
62
|
+
runningSource = currentRoot.toSource();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
for (var _i = 0, _a = Object.keys(inputsMap); _i < _a.length; _i++) {
|
|
66
|
+
var inputPackageName = _a[_i];
|
|
67
|
+
_loop_1(inputPackageName);
|
|
68
|
+
}
|
|
69
|
+
return runningSource;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameLayoutImports.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameLayoutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAoDlE,QAAA,MAAM,SAAS,EAAE,SAyEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// used to filter our imports we want to keep in @workday/canvas-kit-labs-react/common
|
|
2
|
+
var commonSpecifiers = [
|
|
3
|
+
'useTheme',
|
|
4
|
+
'ComponentStatesTable',
|
|
5
|
+
'permutateProps',
|
|
6
|
+
'useThemeRTL',
|
|
7
|
+
'useThemedRing',
|
|
8
|
+
];
|
|
9
|
+
var layoutSpecifiers = [
|
|
10
|
+
'Flex',
|
|
11
|
+
'Stack',
|
|
12
|
+
'StackProps',
|
|
13
|
+
'HStackProps',
|
|
14
|
+
'VStack',
|
|
15
|
+
'VStackProps',
|
|
16
|
+
'HStack',
|
|
17
|
+
'Box',
|
|
18
|
+
'BoxProps',
|
|
19
|
+
'FlexProps',
|
|
20
|
+
'ColorStyleProps',
|
|
21
|
+
'StackSpacing',
|
|
22
|
+
'StackDirection',
|
|
23
|
+
'StackStyleProps',
|
|
24
|
+
'FlexStyleProps',
|
|
25
|
+
'SpaceStyleProps',
|
|
26
|
+
'DepthStyleProps',
|
|
27
|
+
'BorderShorthandStyleProps',
|
|
28
|
+
'BorderColorStyleProps',
|
|
29
|
+
'BorderRadiusStyleProps',
|
|
30
|
+
'BorderLineStyleProps',
|
|
31
|
+
'BorderWidthStyleProps',
|
|
32
|
+
'BorderLogicalStyleProps',
|
|
33
|
+
'BorderStyleProps',
|
|
34
|
+
'border',
|
|
35
|
+
'ColorTokens',
|
|
36
|
+
'ColorStyleProps',
|
|
37
|
+
'color',
|
|
38
|
+
'FlexItemStyleProps',
|
|
39
|
+
'flexItem',
|
|
40
|
+
'PositionStandardProps',
|
|
41
|
+
'PositionLogicalProps',
|
|
42
|
+
'PositionStyleProps',
|
|
43
|
+
'position',
|
|
44
|
+
];
|
|
45
|
+
// 1. Gather all import specifiers from @workday/canvas-kit-labs-react/layout
|
|
46
|
+
// 2. Filter through all imports from @workday/canvas-kit-labs-react/common and gather specifiers we care about
|
|
47
|
+
// 3. If there's an existing @workday/canvas-kit-react/layout add gathered specifiers to that import
|
|
48
|
+
// 4. If no existing import, create new import with specifiers and insert before closest canvas kit import
|
|
49
|
+
var transform = function (file, api) {
|
|
50
|
+
var j = api.jscodeshift;
|
|
51
|
+
var root = j(file.source);
|
|
52
|
+
var reactLayoutSpecifiers = [];
|
|
53
|
+
var foundImport = [];
|
|
54
|
+
root
|
|
55
|
+
.find(j.ImportDeclaration, {
|
|
56
|
+
source: { value: function (value) { return value.includes('@workday/canvas-kit-labs-react'); } },
|
|
57
|
+
})
|
|
58
|
+
.forEach(function (nodePath) {
|
|
59
|
+
var _a;
|
|
60
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
|
|
61
|
+
var _a, _b, _c, _d;
|
|
62
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
63
|
+
!commonSpecifiers.includes(specifier.imported.name)) {
|
|
64
|
+
if (((_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name) !== undefined &&
|
|
65
|
+
layoutSpecifiers.includes((_b = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _b === void 0 ? void 0 : _b.name)) {
|
|
66
|
+
reactLayoutSpecifiers.push({
|
|
67
|
+
importedName: (_c = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _c === void 0 ? void 0 : _c.name,
|
|
68
|
+
name: (_d = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _d === void 0 ? void 0 : _d.name,
|
|
69
|
+
});
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
foundImport.push(nodePath);
|
|
76
|
+
});
|
|
77
|
+
var existingLayoutImports = root.find(j.ImportDeclaration, {
|
|
78
|
+
source: { value: '@workday/canvas-kit-react/layout' },
|
|
79
|
+
});
|
|
80
|
+
var mapToSpecifiers = function (specifier) {
|
|
81
|
+
return j.importSpecifier(j.identifier(specifier.name), specifier.importedName ? j.identifier(specifier.importedName) : undefined);
|
|
82
|
+
};
|
|
83
|
+
// add to existing import
|
|
84
|
+
if (existingLayoutImports.length) {
|
|
85
|
+
existingLayoutImports.forEach(function (nodePath) {
|
|
86
|
+
var _a;
|
|
87
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(reactLayoutSpecifiers.map(mapToSpecifiers));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// create new import
|
|
92
|
+
if (foundImport.length) {
|
|
93
|
+
foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/layout')));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
foundImport.forEach(function (importPath) {
|
|
97
|
+
var _a;
|
|
98
|
+
if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
99
|
+
importPath.value.source.value === '@workday/canvas-kit-labs-react/layout') {
|
|
100
|
+
importPath.prune();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return root.toSource();
|
|
104
|
+
};
|
|
105
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateDisclosureShowHide.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateDisclosureShowHide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiH7E"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var keys = function (input) { return Object.keys(input); };
|
|
3
|
+
export default function transformer(file, api, options) {
|
|
4
|
+
var j = api.jscodeshift;
|
|
5
|
+
var root = j(file.source);
|
|
6
|
+
var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
|
|
7
|
+
if (!containsCanvasImports) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
var disclosureModels = [
|
|
11
|
+
'useDisclosureModel',
|
|
12
|
+
'usePopupModel',
|
|
13
|
+
'useModalModel',
|
|
14
|
+
'useDialogModel',
|
|
15
|
+
];
|
|
16
|
+
// inverse the import map. It is more useful this way for this function
|
|
17
|
+
var imports = Object.keys(importMap).reduce(function (result, key) {
|
|
18
|
+
result[importMap[key]] = key;
|
|
19
|
+
return result;
|
|
20
|
+
}, {});
|
|
21
|
+
root.find(j.CallExpression).forEach(function (nodePath) {
|
|
22
|
+
var value = nodePath.value;
|
|
23
|
+
// check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
|
|
24
|
+
if (value.callee.type === 'Identifier' &&
|
|
25
|
+
disclosureModels.includes(imports[value.callee.name])) {
|
|
26
|
+
// loop over all the arguments of the `use{*}Model` hook
|
|
27
|
+
value.arguments.forEach(function (argument) {
|
|
28
|
+
// look for object expressions: `use{*}Model({ /* here */ })`
|
|
29
|
+
if (argument.type === 'ObjectExpression') {
|
|
30
|
+
// loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
|
|
31
|
+
// the value is a function matching `on{*}` or `should{*}` naming convention
|
|
32
|
+
argument.properties.forEach(function (property) {
|
|
33
|
+
// If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
|
|
34
|
+
// {
|
|
35
|
+
// onShow() {}, // ObjectMethod
|
|
36
|
+
// onHide: () => {}, ObjectProperty with arrow function expression
|
|
37
|
+
// }
|
|
38
|
+
if ((property.type === 'ObjectMethod' ||
|
|
39
|
+
(property.type === 'ObjectProperty' &&
|
|
40
|
+
property.value.type === 'ArrowFunctionExpression')) &&
|
|
41
|
+
property.key.type === 'Identifier') {
|
|
42
|
+
var propertyName_1 = property.key.name;
|
|
43
|
+
// Both types have a `params`, but are at different places in the AST
|
|
44
|
+
var params_1 = property.type === 'ObjectMethod'
|
|
45
|
+
? property.params
|
|
46
|
+
: property.value.type === 'ArrowFunctionExpression'
|
|
47
|
+
? property.value.params
|
|
48
|
+
: [];
|
|
49
|
+
// create a mapping for param names of callbacks and guards. This makes the logic more
|
|
50
|
+
// difficult to follow, but decreases duplication
|
|
51
|
+
var paramMapping_1 = {
|
|
52
|
+
on: ['event'],
|
|
53
|
+
should: ['event'],
|
|
54
|
+
};
|
|
55
|
+
// We will be overriding the params with this variable later
|
|
56
|
+
var finalParams_1 = [];
|
|
57
|
+
// loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
|
|
58
|
+
keys(paramMapping_1).forEach(function (key) {
|
|
59
|
+
// matches `onShow` and `shouldShow`
|
|
60
|
+
if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
|
|
61
|
+
params_1.forEach(function (param) {
|
|
62
|
+
if (param.type === 'ObjectPattern') {
|
|
63
|
+
param.properties.forEach(function (property) {
|
|
64
|
+
if (property.type === 'ObjectProperty' &&
|
|
65
|
+
property.key.type === 'Identifier') {
|
|
66
|
+
if (property.value.type === 'Identifier' ||
|
|
67
|
+
property.value.type === 'ObjectPattern') {
|
|
68
|
+
var index = paramMapping_1[key].indexOf(property.key.name);
|
|
69
|
+
// use `property.value` instead of `property.key.name` in case they
|
|
70
|
+
// renamed it example `shouldShow({ data: myData })`. The key name is
|
|
71
|
+
// `data` while the value is `myData`
|
|
72
|
+
finalParams_1[index] = property.value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// `ObjectMethod` and `ObjectProperty` have params in a different place in the
|
|
79
|
+
// AST, so apply `finalParams` where appropriate
|
|
80
|
+
if (property.type === 'ObjectMethod') {
|
|
81
|
+
property.params = finalParams_1;
|
|
82
|
+
}
|
|
83
|
+
else if (property.type === 'ObjectProperty' &&
|
|
84
|
+
property.value.type === 'ArrowFunctionExpression') {
|
|
85
|
+
property.value.params = finalParams_1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return root.toSource();
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateModelSignatures.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateModelSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0G7E"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var keys = function (input) { return Object.keys(input); };
|
|
3
|
+
export default function transformer(file, api, options) {
|
|
4
|
+
var j = api.jscodeshift;
|
|
5
|
+
var root = j(file.source);
|
|
6
|
+
var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
|
|
7
|
+
if (!containsCanvasImports) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
// inverse the import map. It is more useful this way for this function
|
|
11
|
+
var imports = Object.keys(importMap).reduce(function (result, key) {
|
|
12
|
+
result[importMap[key]] = key;
|
|
13
|
+
return result;
|
|
14
|
+
}, {});
|
|
15
|
+
root.find(j.CallExpression).forEach(function (nodePath) {
|
|
16
|
+
var value = nodePath.value;
|
|
17
|
+
// check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
|
|
18
|
+
if (value.callee.type === 'Identifier' &&
|
|
19
|
+
/use[a-zA-Z]+Model/.test(imports[value.callee.name])) {
|
|
20
|
+
// loop over all the arguments of the `use{*}Model` hook
|
|
21
|
+
value.arguments.forEach(function (argument) {
|
|
22
|
+
// look for object expressions: `use{*}Model({ /* here */ })`
|
|
23
|
+
if (argument.type === 'ObjectExpression') {
|
|
24
|
+
// loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
|
|
25
|
+
// the value is a function matching `on{*}` or `should{*}` naming convention
|
|
26
|
+
argument.properties.forEach(function (property) {
|
|
27
|
+
// If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
|
|
28
|
+
// {
|
|
29
|
+
// onShow() {}, // ObjectMethod
|
|
30
|
+
// onHide: () => {}, ObjectProperty with arrow function expression
|
|
31
|
+
// }
|
|
32
|
+
if ((property.type === 'ObjectMethod' ||
|
|
33
|
+
(property.type === 'ObjectProperty' &&
|
|
34
|
+
property.value.type === 'ArrowFunctionExpression')) &&
|
|
35
|
+
property.key.type === 'Identifier') {
|
|
36
|
+
var propertyName_1 = property.key.name;
|
|
37
|
+
// Both types have a `params`, but are at different places in the AST
|
|
38
|
+
var params_1 = property.type === 'ObjectMethod'
|
|
39
|
+
? property.params
|
|
40
|
+
: property.value.type === 'ArrowFunctionExpression'
|
|
41
|
+
? property.value.params
|
|
42
|
+
: [];
|
|
43
|
+
// create a mapping for param names of callbacks and guards. This makes the logic more
|
|
44
|
+
// difficult to follow, but decreases duplication
|
|
45
|
+
var paramMapping_1 = {
|
|
46
|
+
on: ['data', 'state'],
|
|
47
|
+
should: ['data', 'prevState'],
|
|
48
|
+
};
|
|
49
|
+
// We will be overriding the params with this variable later
|
|
50
|
+
var finalParams_1 = [];
|
|
51
|
+
// loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
|
|
52
|
+
keys(paramMapping_1).forEach(function (key) {
|
|
53
|
+
// matches `onShow` and `shouldShow`
|
|
54
|
+
if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
|
|
55
|
+
params_1.forEach(function (param) {
|
|
56
|
+
if (param.type === 'ObjectPattern') {
|
|
57
|
+
param.properties.forEach(function (property) {
|
|
58
|
+
if (property.type === 'ObjectProperty' &&
|
|
59
|
+
property.key.type === 'Identifier') {
|
|
60
|
+
if (property.value.type === 'Identifier' ||
|
|
61
|
+
property.value.type === 'ObjectPattern') {
|
|
62
|
+
var index = paramMapping_1[key].indexOf(property.key.name);
|
|
63
|
+
// use `property.value` instead of `property.key.name` in case they
|
|
64
|
+
// renamed it example `shouldShow({ data: myData })`. The key name is
|
|
65
|
+
// `data` while the value is `myData`
|
|
66
|
+
finalParams_1[index] = property.value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// `ObjectMethod` and `ObjectProperty` have params in a different place in the
|
|
73
|
+
// AST, so apply `finalParams` where appropriate
|
|
74
|
+
if (property.type === 'ObjectMethod') {
|
|
75
|
+
property.params = finalParams_1;
|
|
76
|
+
}
|
|
77
|
+
else if (property.type === 'ObjectProperty' &&
|
|
78
|
+
property.value.type === 'ArrowFunctionExpression') {
|
|
79
|
+
property.value.params = finalParams_1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return root.toSource();
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateSegmentedControl.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateSegmentedControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAI/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAgC7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
export default function transformer(file, api, options) {
|
|
3
|
+
var j = api.jscodeshift;
|
|
4
|
+
var root = j(file.source);
|
|
5
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/segmented-control'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
6
|
+
if (!containsCanvasImports) {
|
|
7
|
+
return file.source;
|
|
8
|
+
}
|
|
9
|
+
root
|
|
10
|
+
.find(j.JSXElement, function (value) {
|
|
11
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
12
|
+
(value.openingElement.name.name === importMap.SegmentedControl ||
|
|
13
|
+
value.openingElement.name.name === styledMap.SegmentedControl);
|
|
14
|
+
})
|
|
15
|
+
.forEach(function (nodePath) {
|
|
16
|
+
for (var _i = 0, _a = nodePath.value.children || []; _i < _a.length; _i++) {
|
|
17
|
+
var child = _a[_i];
|
|
18
|
+
if (child.type === 'JSXElement' && child.openingElement.name.type === 'JSXIdentifier') {
|
|
19
|
+
child.openingElement.name.name = 'SegmentedControl.Button';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return root.toSource();
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTabs.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateTabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAGnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuD7E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
export default function transformer(file, api, options) {
|
|
3
|
+
var j = api.jscodeshift;
|
|
4
|
+
var root = j(file.source);
|
|
5
|
+
var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
|
|
6
|
+
if (!containsCanvasImports) {
|
|
7
|
+
return file.source;
|
|
8
|
+
}
|
|
9
|
+
root
|
|
10
|
+
// Find <Tabs
|
|
11
|
+
.find(j.JSXOpeningElement, { name: { object: { name: importMap.Tabs } } })
|
|
12
|
+
// Filter for <Tabs.Item and <Tabs.Panel
|
|
13
|
+
.filter(function (path) {
|
|
14
|
+
return (path.value.name.type === 'JSXMemberExpression' &&
|
|
15
|
+
(path.value.name.property.name === 'Item' || path.value.name.property.name === 'Panel'));
|
|
16
|
+
})
|
|
17
|
+
.forEach(function (nodePath) {
|
|
18
|
+
var _a;
|
|
19
|
+
nodePath.value.attributes = (_a = nodePath.value.attributes) === null || _a === void 0 ? void 0 : _a.map(function (attribute) {
|
|
20
|
+
if (attribute.type === 'JSXAttribute' &&
|
|
21
|
+
attribute.name.type === 'JSXIdentifier' &&
|
|
22
|
+
attribute.name.name === 'name') {
|
|
23
|
+
attribute.name.name = 'data-id';
|
|
24
|
+
}
|
|
25
|
+
return attribute;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
root
|
|
29
|
+
// find <Tabs.Menu.Item
|
|
30
|
+
.find(j.JSXOpeningElement, {
|
|
31
|
+
name: {
|
|
32
|
+
object: { object: { name: importMap.Tabs }, property: { name: 'Menu' } },
|
|
33
|
+
property: { name: 'Item' },
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.forEach(function (nodePath) {
|
|
37
|
+
var _a;
|
|
38
|
+
nodePath.value.attributes = (_a = nodePath.value.attributes) === null || _a === void 0 ? void 0 : _a.map(function (attribute) {
|
|
39
|
+
if (attribute.type === 'JSXAttribute' &&
|
|
40
|
+
attribute.name.type === 'JSXIdentifier' &&
|
|
41
|
+
attribute.name.name === 'name') {
|
|
42
|
+
attribute.name.name = 'data-id';
|
|
43
|
+
}
|
|
44
|
+
return attribute;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return root.toSource();
|
|
48
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Collection, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, packageName?: string): {
|
|
3
|
+
containsCanvasImports: boolean;
|
|
4
|
+
importMap: Record<string, string>;
|
|
5
|
+
styledMap: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getImportRenameMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,SAAK;;;;EA2DzF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function getImportRenameMap(j, root, packageName) {
|
|
2
|
+
if (packageName === void 0) { packageName = ''; }
|
|
3
|
+
var containsCanvasImports = false;
|
|
4
|
+
// build import name remapping - in case someone renamed imports...
|
|
5
|
+
// i.e. `import { IconButton as StyledIconButton } ...`
|
|
6
|
+
var importMap = {};
|
|
7
|
+
var styledMap = {};
|
|
8
|
+
root.find(j.ImportDeclaration, function (node) {
|
|
9
|
+
// imports our module
|
|
10
|
+
var value = node.source.value;
|
|
11
|
+
if (typeof value === 'string' &&
|
|
12
|
+
(value === '@workday/canvas-kit-react' ||
|
|
13
|
+
value.startsWith('@workday/canvas-kit-react/') ||
|
|
14
|
+
value === packageName)) {
|
|
15
|
+
containsCanvasImports = true;
|
|
16
|
+
(node.specifiers || []).forEach(function (specifier) {
|
|
17
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
18
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
19
|
+
importMap[specifier.imported.name] = specifier.imported.name;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
importMap[specifier.imported.name] = specifier.local.name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
29
|
+
root
|
|
30
|
+
.find(j.CallExpression, function (node) {
|
|
31
|
+
if (node.callee.type === 'Identifier' &&
|
|
32
|
+
node.callee.name === 'styled' &&
|
|
33
|
+
node.arguments[0].type === 'Identifier') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
})
|
|
38
|
+
.forEach(function (nodePath) {
|
|
39
|
+
// const StyledName = styled(OriginalName)({})
|
|
40
|
+
// const StyledName = styled(OriginalName)`` // Tagged template
|
|
41
|
+
if ((nodePath.parent.value.type === 'CallExpression' ||
|
|
42
|
+
nodePath.parent.value.type === 'TaggedTemplateExpression') &&
|
|
43
|
+
nodePath.parent.parent.value.type === 'VariableDeclarator' &&
|
|
44
|
+
nodePath.parent.parent.value.id.type === 'Identifier') {
|
|
45
|
+
var styledName = nodePath.parent.parent.value.id.name;
|
|
46
|
+
if (nodePath.value.arguments[0].type === 'Identifier') {
|
|
47
|
+
styledMap[nodePath.value.arguments[0].name] = styledName;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return { containsCanvasImports: containsCanvasImports, importMap: importMap, styledMap: styledMap };
|
|
52
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Collection, API } from 'jscodeshift';
|
|
2
|
+
/**
|
|
3
|
+
* Search for import statements for a package and specific import specifiers. This
|
|
4
|
+
* is useful for codemods to skip files that don't contain import specifiers that
|
|
5
|
+
* require codemoding.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const hasImports = hasImportSpecifiers(
|
|
9
|
+
* api,
|
|
10
|
+
* root,
|
|
11
|
+
* '@workday/canvas-kit-react/cookie-banner',
|
|
12
|
+
* ['CookieBanner', 'CookieBannerProps']
|
|
13
|
+
* )
|
|
14
|
+
*
|
|
15
|
+
* if (!hasImports) {
|
|
16
|
+
* return file.source
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasImportSpecifiers(api: API, root: Collection<any>, packageName: string | string[], specifiers: string[]): boolean;
|
|
20
|
+
//# sourceMappingURL=hasImportSpecifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasImportSpecifiers.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/hasImportSpecifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,GAAG,EAAC,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search for import statements for a package and specific import specifiers. This
|
|
3
|
+
* is useful for codemods to skip files that don't contain import specifiers that
|
|
4
|
+
* require codemoding.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const hasImports = hasImportSpecifiers(
|
|
8
|
+
* api,
|
|
9
|
+
* root,
|
|
10
|
+
* '@workday/canvas-kit-react/cookie-banner',
|
|
11
|
+
* ['CookieBanner', 'CookieBannerProps']
|
|
12
|
+
* )
|
|
13
|
+
*
|
|
14
|
+
* if (!hasImports) {
|
|
15
|
+
* return file.source
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
19
|
+
var j = api.jscodeshift;
|
|
20
|
+
return !!root.find(j.ImportDeclaration, function (nodePath) {
|
|
21
|
+
var value = nodePath.source.value;
|
|
22
|
+
// package name was found
|
|
23
|
+
if (typeof packageName === 'string'
|
|
24
|
+
? value === packageName
|
|
25
|
+
: packageName.includes(value)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// Extract the main package(s) from the import, and test specifiers against that package
|
|
29
|
+
var mainPackage = (typeof packageName === 'string' ? [packageName] : packageName).map(function (s) {
|
|
30
|
+
return s
|
|
31
|
+
.split('/')
|
|
32
|
+
.slice(0, -1)
|
|
33
|
+
.join('/');
|
|
34
|
+
});
|
|
35
|
+
if (mainPackage.includes(value)) {
|
|
36
|
+
return !!(nodePath.specifiers || []).find(function (specifier) {
|
|
37
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
38
|
+
var specifierName = specifier.imported.name;
|
|
39
|
+
return specifiers.includes(specifierName);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
}
|
package/index.js
CHANGED
|
@@ -21,6 +21,13 @@ const {_: commands, path} = require('yargs')
|
|
|
21
21
|
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
22
22
|
});
|
|
23
23
|
})
|
|
24
|
+
.command('v7 [path]', chalk.gray('Canvas Kit v6 > v7 migration transform'), yargs => {
|
|
25
|
+
yargs.positional('path', {
|
|
26
|
+
type: 'string',
|
|
27
|
+
default: '.',
|
|
28
|
+
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
29
|
+
});
|
|
30
|
+
})
|
|
24
31
|
.demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
|
|
25
32
|
.strictCommands()
|
|
26
33
|
.fail((msg, err, yargs) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@workday/canvas-kit-codemod",
|
|
3
3
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "6.
|
|
5
|
+
"version": "6.9.0-next.4+8ddbb273",
|
|
6
6
|
"description": "A collection of codemods for use on Workday Canvas Kit packages.",
|
|
7
7
|
"main": "dist/es6/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "
|
|
14
|
+
"url": "https://github.com/workday/canvas-kit.git",
|
|
15
|
+
"directory": "modules/codemod"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist/",
|
|
@@ -42,5 +43,5 @@
|
|
|
42
43
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
43
44
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
44
45
|
},
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "8ddbb27356d06d06508938ae073ce2006b6dc4fd"
|
|
46
47
|
}
|