@workday/canvas-kit-codemod 8.0.0 → 8.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/es6/v8/index.d.ts +4 -0
- package/dist/es6/v8/index.d.ts.map +1 -0
- package/dist/es6/v8/index.js +36 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts +4 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/promoteBreadcrumbs.js +54 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts +4 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts.map +1 -0
- package/dist/es6/v8/promoteComponentsToTesting.js +76 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts +3 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts.map +1 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.js +50 -0
- package/dist/es6/v8/removeDefaultImports.d.ts +3 -0
- package/dist/es6/v8/removeDefaultImports.d.ts.map +1 -0
- package/dist/es6/v8/removeDefaultImports.js +52 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts +3 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts.map +1 -0
- package/dist/es6/v8/renameLoadingAnimation.js +62 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts +3 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/restructureBreadcrumbs.js +59 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts +3 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateDrawer.js +103 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts +3 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateLayout.js +84 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts +3 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.js +79 -0
- package/index.js +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v8/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAYtC,QAAA,MAAM,SAAS,EAAE,SAehB,CAAC;AACF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 softDeprecateDrawer from './softDeprecateDrawer';
|
|
13
|
+
import softDeprecateLayout from './softDeprecateLayout';
|
|
14
|
+
import softDeprecatePreviewMenu from './softDeprecatePreviewMenu';
|
|
15
|
+
import revomeDefaultImports from './removeDefaultImports';
|
|
16
|
+
import promoteComponentsToTesting from './promoteComponentsToTesting';
|
|
17
|
+
import promoteBreadcrumbs from './promoteBreadcrumbs';
|
|
18
|
+
import restructureBreadcrumbs from './restructureBreadcrumbs';
|
|
19
|
+
import refactorActionBarOverflowButton from './refactorActionBarOverflowButton';
|
|
20
|
+
import renameLoadingAnimation from './renameLoadingAnimation';
|
|
21
|
+
var transform = function (file, api, options) {
|
|
22
|
+
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
23
|
+
var fixes = [
|
|
24
|
+
promoteBreadcrumbs,
|
|
25
|
+
restructureBreadcrumbs,
|
|
26
|
+
revomeDefaultImports,
|
|
27
|
+
softDeprecateDrawer,
|
|
28
|
+
softDeprecateLayout,
|
|
29
|
+
softDeprecatePreviewMenu,
|
|
30
|
+
promoteComponentsToTesting,
|
|
31
|
+
refactorActionBarOverflowButton,
|
|
32
|
+
renameLoadingAnimation,
|
|
33
|
+
];
|
|
34
|
+
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
35
|
+
};
|
|
36
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promoteBreadcrumbs.d.ts","sourceRoot":"","sources":["../../../lib/v8/promoteBreadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAIlE,QAAA,MAAM,SAAS,EAAE,SAuEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var transform = function (file, api) {
|
|
2
|
+
var j = api.jscodeshift;
|
|
3
|
+
var root = j(file.source);
|
|
4
|
+
var reactLayoutSpecifiers = [];
|
|
5
|
+
var foundImport = [];
|
|
6
|
+
root
|
|
7
|
+
.find(j.ImportDeclaration, {
|
|
8
|
+
source: { value: function (value) { return value.includes('@workday/canvas-kit-preview-react'); } },
|
|
9
|
+
})
|
|
10
|
+
.forEach(function (nodePath) {
|
|
11
|
+
var _a;
|
|
12
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
|
|
13
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
14
|
+
specifier.local &&
|
|
15
|
+
specifier.imported.name === 'Breadcrumbs') {
|
|
16
|
+
reactLayoutSpecifiers.push({
|
|
17
|
+
importedName: specifier.imported.name,
|
|
18
|
+
name: specifier.local.name,
|
|
19
|
+
});
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
foundImport.push(nodePath);
|
|
25
|
+
});
|
|
26
|
+
var existingLayoutImports = root.find(j.ImportDeclaration, {
|
|
27
|
+
source: { value: '@workday/canvas-kit-react/breadcrumbs' },
|
|
28
|
+
});
|
|
29
|
+
var mapToSpecifiers = function (specifier) {
|
|
30
|
+
return j.importSpecifier(j.identifier(specifier.importedName), specifier.name ? j.identifier(specifier.name) : undefined);
|
|
31
|
+
};
|
|
32
|
+
// add to existing import
|
|
33
|
+
if (existingLayoutImports.length) {
|
|
34
|
+
existingLayoutImports.forEach(function (nodePath) {
|
|
35
|
+
var _a;
|
|
36
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(reactLayoutSpecifiers.map(mapToSpecifiers));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// create new import
|
|
41
|
+
if (foundImport.length) {
|
|
42
|
+
foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/breadcrumbs')));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
foundImport.forEach(function (importPath) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
48
|
+
importPath.value.source.value === '@workday/canvas-kit-preview-react/breadcrumbs') {
|
|
49
|
+
importPath.prune();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return root.toSource();
|
|
53
|
+
};
|
|
54
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promoteComponentsToTesting.d.ts","sourceRoot":"","sources":["../../../lib/v8/promoteComponentsToTesting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAiBlE,QAAA,MAAM,SAAS,EAAE,SA8EhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var specifiersToMove = [
|
|
2
|
+
'ComponentStatesTable',
|
|
3
|
+
'permutateProps',
|
|
4
|
+
'ComponentStatesTableProps',
|
|
5
|
+
'PropCombination',
|
|
6
|
+
'PropDeclaration',
|
|
7
|
+
'Props',
|
|
8
|
+
'PropsDeclaration',
|
|
9
|
+
'convertToStaticStates',
|
|
10
|
+
'StaticStates',
|
|
11
|
+
];
|
|
12
|
+
// 1. Gather all import specifiers from @workday/canvas-kit-labs-react/common & @workday/canvas-kit-react/common
|
|
13
|
+
// 2. Filter through all imports from @workday/canvas-kit-labs-react/common and gather specifiers we care about
|
|
14
|
+
// 3. If no existing import, create new import with specifiers and insert before closest canvas kit import
|
|
15
|
+
var transform = function (file, api) {
|
|
16
|
+
var j = api.jscodeshift;
|
|
17
|
+
var root = j(file.source);
|
|
18
|
+
var commonLabsSpecifiers = [];
|
|
19
|
+
var foundImport = [];
|
|
20
|
+
// First move specifiers from labs or from main common
|
|
21
|
+
root
|
|
22
|
+
.find(j.ImportDeclaration, {
|
|
23
|
+
source: {
|
|
24
|
+
value: function (value) {
|
|
25
|
+
return value.includes('@workday/canvas-kit-labs-react') ||
|
|
26
|
+
value.includes('@workday/canvas-kit-react');
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
.forEach(function (nodePath) {
|
|
31
|
+
var _a;
|
|
32
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
|
|
33
|
+
var _a, _b, _c, _d;
|
|
34
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
35
|
+
if (((_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name) !== undefined &&
|
|
36
|
+
specifiersToMove.includes((_b = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _b === void 0 ? void 0 : _b.name)) {
|
|
37
|
+
commonLabsSpecifiers.push({
|
|
38
|
+
importedName: (_c = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _c === void 0 ? void 0 : _c.name,
|
|
39
|
+
name: (_d = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _d === void 0 ? void 0 : _d.name,
|
|
40
|
+
});
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
foundImport.push(nodePath);
|
|
47
|
+
});
|
|
48
|
+
var existingTestingImports = root.find(j.ImportDeclaration, {
|
|
49
|
+
source: { value: '@workday/canvas-kit-react/testing' },
|
|
50
|
+
});
|
|
51
|
+
var mapToSpecifiers = function (specifier) {
|
|
52
|
+
return j.importSpecifier(j.identifier(specifier.name), specifier.importedName ? j.identifier(specifier.importedName) : undefined);
|
|
53
|
+
};
|
|
54
|
+
// add to existing import testing import
|
|
55
|
+
if (existingTestingImports.length) {
|
|
56
|
+
existingTestingImports.forEach(function (nodePath) {
|
|
57
|
+
var _a;
|
|
58
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(commonLabsSpecifiers.map(mapToSpecifiers));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// create new testing import
|
|
63
|
+
if (foundImport.length) {
|
|
64
|
+
foundImport[0].insertBefore(j.importDeclaration(commonLabsSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/testing')));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
foundImport.forEach(function (importPath) {
|
|
68
|
+
var _a;
|
|
69
|
+
if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
70
|
+
importPath.value.source.value === '@workday/canvas-kit-react/testing') {
|
|
71
|
+
importPath.prune();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return root.toSource();
|
|
75
|
+
};
|
|
76
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refactorActionBarOverflowButton.d.ts","sourceRoot":"","sources":["../../../lib/v8/refactorActionBarOverflowButton.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,UA6E7E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getImportRenameMap } from '../v7/utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
var actionBarPackage = '@workday/canvas-kit-react/action-bar';
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
if (!hasImportSpecifiers(api, root, actionBarPackage, ['ActionBar'])) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
// Replace default import with named or renamed import
|
|
11
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
12
|
+
var _a;
|
|
13
|
+
var parent = nodePath.parent;
|
|
14
|
+
var importSource = String(parent.node.source.value);
|
|
15
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
16
|
+
if (actionBarPackage === importSource && localName) {
|
|
17
|
+
nodePath.replace(j.importSpecifier(j.identifier('ActionBar'), j.identifier(localName)));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/action-bar'), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
21
|
+
root
|
|
22
|
+
.find(j.JSXElement, function (value) {
|
|
23
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
24
|
+
(value.openingElement.name.name === importMap.ActionBar ||
|
|
25
|
+
value.openingElement.name.name === styledMap.ActionBar);
|
|
26
|
+
})
|
|
27
|
+
.forEach(function (nodePath) {
|
|
28
|
+
(nodePath.value.children || []).forEach(function (child, index) {
|
|
29
|
+
var _a;
|
|
30
|
+
// Remove all attributes from ActionBar to replace them to ActionBar.List
|
|
31
|
+
var attributes = nodePath.value.openingElement.attributes || [];
|
|
32
|
+
var isModelProp = !!attributes.find(function (attr) {
|
|
33
|
+
return attr.type === 'JSXAttribute' &&
|
|
34
|
+
(attr.name.name === 'model' || attr.name.name === 'items');
|
|
35
|
+
});
|
|
36
|
+
if (child.type === 'JSXElement' &&
|
|
37
|
+
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
38
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
39
|
+
child.openingElement.name.object.name === importMap.ActionBar &&
|
|
40
|
+
child.openingElement.name.property.type === 'JSXIdentifier' &&
|
|
41
|
+
child.openingElement.name.property.name === 'List' &&
|
|
42
|
+
isModelProp) {
|
|
43
|
+
var ActionBarOverflowButtonJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('OverflowButton'));
|
|
44
|
+
var overflowButton = j.jsxElement(j.jsxOpeningElement(ActionBarOverflowButtonJSX, [j.jsxAttribute(j.jsxIdentifier('aria-label'), j.stringLiteral('More actions'))], true));
|
|
45
|
+
(_a = child.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.push(j.jsxAttribute(j.jsxIdentifier('overflowButton'), j.jsxExpressionContainer(overflowButton)));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return root.toSource();
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeDefaultImports.d.ts","sourceRoot":"","sources":["../../../lib/v8/removeDefaultImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAA6B,MAAM,aAAa,CAAC;AAiC/E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuB7E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// List of import paths and the named export
|
|
2
|
+
// before: import Button from '@workday/canvas-kit-react/button
|
|
3
|
+
// after: import { Button } from '@workday/canvas-kit-react/button
|
|
4
|
+
var renameDefaultMap = {
|
|
5
|
+
'@workday/canvas-kit-labs-react/combobox': 'Combobox',
|
|
6
|
+
'@workday/canvas-kit-labs-react/drawer': 'Drawer',
|
|
7
|
+
'@workday/canvas-kit-preview-react/breadcrumbs': 'Breadcrumbs',
|
|
8
|
+
'@workday/canvas-kit-preview-react/color-picker': 'ColorPicker',
|
|
9
|
+
'@workday/canvas-kit-preview-react/menu': 'Menu',
|
|
10
|
+
'@workday/canvas-kit-preview-react/select': 'Select',
|
|
11
|
+
'@workday/canvas-kit-preview-react/side-panel': 'SidePanel',
|
|
12
|
+
'@workday/canvas-kit-react-fonts': 'fonts',
|
|
13
|
+
'@workday/canvas-kit-react/toast': 'Toast',
|
|
14
|
+
'@workday/canvas-kit-react/tokens': 'Canvas',
|
|
15
|
+
'@workday/canvas-kit-react/tooltip': 'Tooltip',
|
|
16
|
+
'@workday/canvas-kit-react/text-area': 'TextArea',
|
|
17
|
+
'@workday/canvas-kit-react/avatar': 'Avatar',
|
|
18
|
+
'@workday/canvas-kit-react/badge': 'CountBadge',
|
|
19
|
+
'@workday/canvas-kit-react/checkbox': 'Checkbox',
|
|
20
|
+
'@workday/canvas-kit-react/form-field': 'FormField',
|
|
21
|
+
'@workday/canvas-kit-react/loading-animation': 'LoadingDots',
|
|
22
|
+
'@workday/canvas-kit-react/radio': 'Radio',
|
|
23
|
+
'@workday/canvas-kit-react/segmented-control': 'SegmentedControl',
|
|
24
|
+
'@workday/canvas-kit-react/select': 'Select',
|
|
25
|
+
'@workday/canvas-kit-react/side-panel': 'SidePanel',
|
|
26
|
+
'@workday/canvas-kit-react/status-indicator': 'StatusIndicator',
|
|
27
|
+
'@workday/canvas-kit-react/switch': 'Switch',
|
|
28
|
+
'@workday/canvas-kit-react/table': 'Table',
|
|
29
|
+
'@workday/canvas-kit-react/text-input': 'TextInput',
|
|
30
|
+
};
|
|
31
|
+
export default function transformer(file, api, options) {
|
|
32
|
+
var j = api.jscodeshift;
|
|
33
|
+
var root = j(file.source);
|
|
34
|
+
// Renames default imports from `renameDefaultMap` and changes them to named exports
|
|
35
|
+
// Example:
|
|
36
|
+
// before:
|
|
37
|
+
// import Button from '@workday/canvas-kit-react/button';
|
|
38
|
+
// import StyledButton from '@workday/canvas-kit-react/button';
|
|
39
|
+
// after:
|
|
40
|
+
// import { Button } from '@workday/canvas-kit-react/button';
|
|
41
|
+
// import { Button as StyledButton } from '@workday/canvas-kit-react/button';
|
|
42
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
43
|
+
var _a;
|
|
44
|
+
var parent = nodePath.parent;
|
|
45
|
+
var importSource = String(parent.node.source.value);
|
|
46
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
47
|
+
if (Object.keys(renameDefaultMap).includes(importSource) && localName) {
|
|
48
|
+
nodePath.replace(j.importSpecifier(j.identifier(localName)));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return root.toSource();
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameLoadingAnimation.d.ts","sourceRoot":"","sources":["../../../lib/v8/renameLoadingAnimation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AASnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA+D7E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getImportRenameMap } from '../v7/utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
var mainPackage = '@workday/canvas-kit-react';
|
|
4
|
+
var loadingAnimationPackage = '@workday/canvas-kit-react/loading-animation';
|
|
5
|
+
var loadingDotsPackage = '@workday/canvas-kit-react/loading-dots';
|
|
6
|
+
var loadingAnimationImports = ['LoadingDots', 'LoadingAnimation'];
|
|
7
|
+
export default function transformer(file, api, options) {
|
|
8
|
+
var j = api.jscodeshift;
|
|
9
|
+
var root = j(file.source);
|
|
10
|
+
// exit if the named imports aren't found
|
|
11
|
+
if (!hasImportSpecifiers(api, root, loadingAnimationPackage, loadingAnimationImports)) {
|
|
12
|
+
return file.source;
|
|
13
|
+
}
|
|
14
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
15
|
+
// and give us an importMap to track what identifiers we need to update
|
|
16
|
+
var importMap = getImportRenameMap(j, root, '@workday/canvas-kit-react/loading-animation').importMap;
|
|
17
|
+
root
|
|
18
|
+
.find(j.ImportDeclaration, {
|
|
19
|
+
// filter on imports from "@workday/canvas-kit/react" including slash imports
|
|
20
|
+
source: { value: function (value) { return value.includes(mainPackage); } },
|
|
21
|
+
})
|
|
22
|
+
.forEach(function (nodePath) {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
25
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
26
|
+
// Transform named import
|
|
27
|
+
// e.g. `import {LoadingAnimation}` becomes `import {LoadingDots}`
|
|
28
|
+
if (specifier.imported.name === 'LoadingAnimation') {
|
|
29
|
+
specifier.imported.name = 'LoadingDots';
|
|
30
|
+
}
|
|
31
|
+
// Transform slash imports
|
|
32
|
+
// e.g. `import {LoadingAnimation} from from "@workday/canvas-kit-react/loading-animation"`
|
|
33
|
+
// and `import {LoadingDots} from from "@workday/canvas-kit-react/loading-animation"`
|
|
34
|
+
// becomes `import {LoadingDots} from from "@workday/canvas-kit-react/loading-dots"`
|
|
35
|
+
if (nodePath.value.source.value === loadingAnimationPackage) {
|
|
36
|
+
nodePath.value.source.value = loadingDotsPackage;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return specifier;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
// Transform LoadingAnimation JSXElements
|
|
43
|
+
// e.g. `<LoadingAnimation />` becomes `<LoadingDots />`
|
|
44
|
+
root.find(j.JSXIdentifier, { name: 'LoadingAnimation' }).forEach(function (nodePath) {
|
|
45
|
+
nodePath.node.name = 'LoadingDots';
|
|
46
|
+
});
|
|
47
|
+
// Transform styled compoents
|
|
48
|
+
// e.g. `const StyledLoadingAnimation = styled(LoadingAnimation)({});`
|
|
49
|
+
// becomes `const StyledLoadingAnimation = styled(LoadingDots)({});`
|
|
50
|
+
root.find(j.VariableDeclarator).forEach(function (nodePath) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
|
|
53
|
+
nodePath.value.init.callee.type === 'CallExpression' &&
|
|
54
|
+
nodePath.value.init.callee.callee.type === 'Identifier' &&
|
|
55
|
+
nodePath.value.init.callee.callee.name === 'styled' &&
|
|
56
|
+
nodePath.value.init.callee.arguments[0].type === 'Identifier' &&
|
|
57
|
+
nodePath.value.init.callee.arguments[0].name === importMap.LoadingAnimation) {
|
|
58
|
+
nodePath.value.init.callee.arguments[0].name = 'LoadingDots';
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return root.toSource();
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restructureBreadcrumbs.d.ts","sourceRoot":"","sources":["../../../lib/v8/restructureBreadcrumbs.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,UAwE7E"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getImportRenameMap } from '../v7/utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
var breadcrumbsPackage = '@workday/canvas-kit-react/breadcrumbs';
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
if (!hasImportSpecifiers(api, root, breadcrumbsPackage, ['Breadcrumbs'])) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
var _a = getImportRenameMap(j, root, breadcrumbsPackage), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
11
|
+
root
|
|
12
|
+
.find(j.JSXElement, function (value) {
|
|
13
|
+
return value.openingElement.name.type === 'JSXMemberExpression' &&
|
|
14
|
+
value.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
15
|
+
(value.openingElement.name.object.name === importMap.Breadcrumbs ||
|
|
16
|
+
value.openingElement.name.object.name === styledMap.Breadcrumbs) &&
|
|
17
|
+
value.openingElement.name.property.name === 'Nav';
|
|
18
|
+
})
|
|
19
|
+
.forEach(function (nodePath) {
|
|
20
|
+
// Select all props from opening tag
|
|
21
|
+
var attributes = nodePath.value.openingElement.attributes || [];
|
|
22
|
+
if (attributes) {
|
|
23
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) { return !(item.type === 'JSXAttribute' && item.name.type === 'JSXIdentifier'); });
|
|
24
|
+
}
|
|
25
|
+
nodePath.value.openingElement = j.jsxOpeningElement(j.jsxIdentifier(importMap.Breadcrumbs));
|
|
26
|
+
nodePath.value.openingElement.attributes = attributes;
|
|
27
|
+
nodePath.value.closingElement = j.jsxClosingElement(j.jsxIdentifier(importMap.Breadcrumbs));
|
|
28
|
+
(nodePath.value.children || []).forEach(function (child) {
|
|
29
|
+
if (child.type === 'JSXElement' &&
|
|
30
|
+
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
31
|
+
child.openingElement.name.property.name === 'CollapsibleList') {
|
|
32
|
+
if (child.openingElement.name.type === 'JSXMemberExpression') {
|
|
33
|
+
child.openingElement.name.property.name = 'List';
|
|
34
|
+
}
|
|
35
|
+
if (child.closingElement && child.closingElement.name.type === 'JSXMemberExpression') {
|
|
36
|
+
child.closingElement.name.property.name = 'List';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
root
|
|
42
|
+
.find(j.JSXElement, function (value) {
|
|
43
|
+
return value.openingElement.name.type === 'JSXMemberExpression' &&
|
|
44
|
+
value.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
45
|
+
(value.openingElement.name.object.name === importMap.Breadcrumbs ||
|
|
46
|
+
value.openingElement.name.object.name === styledMap.Breadcrumbs) &&
|
|
47
|
+
value.openingElement.name.property.name === 'ListItem';
|
|
48
|
+
})
|
|
49
|
+
.forEach(function (nodePath) {
|
|
50
|
+
if (nodePath.value.openingElement.name.type === 'JSXMemberExpression') {
|
|
51
|
+
nodePath.value.openingElement.name.property.name = 'Item';
|
|
52
|
+
}
|
|
53
|
+
if (nodePath.value.closingElement &&
|
|
54
|
+
nodePath.value.closingElement.name.type === 'JSXMemberExpression') {
|
|
55
|
+
nodePath.value.closingElement.name.property.name = 'Item';
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return root.toSource();
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"softDeprecateDrawer.d.ts","sourceRoot":"","sources":["../../../lib/v8/softDeprecateDrawer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAYlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0G7E"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-labs-react';
|
|
2
|
+
var drawerPackage = '@workday/canvas-kit-labs-react/drawer';
|
|
3
|
+
var drawerImportNames = [
|
|
4
|
+
'Drawer',
|
|
5
|
+
'DrawerProps',
|
|
6
|
+
'DrawerHeaderProps',
|
|
7
|
+
'DrawerHeader',
|
|
8
|
+
'DrawerDirection',
|
|
9
|
+
];
|
|
10
|
+
export default function transformer(file, api, options) {
|
|
11
|
+
var j = api.jscodeshift;
|
|
12
|
+
var root = j(file.source);
|
|
13
|
+
var hasDrawerImports = false;
|
|
14
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
15
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
16
|
+
var value = nodePath.source.value;
|
|
17
|
+
// If there's an import from the drawer package, set the import boolean check to true
|
|
18
|
+
if (value === drawerPackage) {
|
|
19
|
+
hasDrawerImports = true;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// If there's an import from the main package, check to see if Drawer or DrawerProps are among the named imports
|
|
23
|
+
// e.g. import {Drawer} from '@workday/canvas-kit-labs-react';
|
|
24
|
+
if (value === mainPackage) {
|
|
25
|
+
(nodePath.specifiers || []).forEach(function (specifier) {
|
|
26
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
27
|
+
drawerImportNames.includes(specifier.imported.name)) {
|
|
28
|
+
hasDrawerImports = true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
// Failsafe to skip transforms unless a Drawer import is detected
|
|
35
|
+
if (!hasDrawerImports) {
|
|
36
|
+
return root.toSource();
|
|
37
|
+
}
|
|
38
|
+
root
|
|
39
|
+
.find(j.ImportDeclaration, {
|
|
40
|
+
source: { value: function (value) { return value.includes(mainPackage); } },
|
|
41
|
+
})
|
|
42
|
+
.forEach(function (nodePath) {
|
|
43
|
+
var _a;
|
|
44
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
45
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
46
|
+
// `import {Drawer}` becomes `import {DeprecatedDrawer}`
|
|
47
|
+
// `import {DrawerProps}` becomes `import {DeprecatedDrawerProps}`
|
|
48
|
+
// `import {DrawerHeader}` becomes `import {DeprecatedDrawerHeader}`
|
|
49
|
+
// `import {DrawerHeaderProps}` becomes `import {DeprecatedDrawerHeaderProps}`
|
|
50
|
+
if (drawerImportNames.includes(specifier.imported.name)) {
|
|
51
|
+
specifier.imported.name = "Deprecated" + specifier.imported.name;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return specifier;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
// Transform DrawerProps type references
|
|
58
|
+
// e.g. `type CustomProps = DrawerProps;` becomes `type CustomProps = DeprecatedDrawerProps;`
|
|
59
|
+
// Transform DrawerHeaderProps type references
|
|
60
|
+
// e.g. `type CustomProps = DrawerHeaderProps;` becomes `type CustomProps = DeprecatedDrawerHeaderProps;`
|
|
61
|
+
var typeNames = ['DrawerProps', 'DrawerHeaderProps'];
|
|
62
|
+
root
|
|
63
|
+
.find(j.TSTypeReference, {
|
|
64
|
+
typeName: {
|
|
65
|
+
type: 'Identifier',
|
|
66
|
+
name: function (value) { return typeNames.includes(value); },
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
.forEach(function (nodePath) {
|
|
70
|
+
var identifier = nodePath.value.typeName;
|
|
71
|
+
identifier.name = "Deprecated" + identifier.name;
|
|
72
|
+
});
|
|
73
|
+
// Transform DrawerProps type interface declaration references
|
|
74
|
+
// e.g. `interface CustomProps extends DrawerProps` becomes `interface CustomProps extends DeprecatedDrawerProps`
|
|
75
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
76
|
+
var _a;
|
|
77
|
+
// If the interface is extending DrawerProps, transform the extension name to DeprecatedDrawerProps
|
|
78
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
79
|
+
if (typeExtension.expression.type === 'Identifier') {
|
|
80
|
+
var typeExtensionName = typeExtension.expression.name;
|
|
81
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
82
|
+
typeNames.includes(typeExtensionName)) {
|
|
83
|
+
typeExtension.expression.name = "Deprecated" + typeExtensionName;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
// Transform `<DrawerDirection>` to `<DeprecatedDrawerDirection>`
|
|
89
|
+
root.find(j.Identifier, { name: 'DrawerDirection' }).forEach(function (nodePath) {
|
|
90
|
+
nodePath.value.name = 'DeprecatedDrawerDirection';
|
|
91
|
+
});
|
|
92
|
+
// Transform Drawer JSXElements
|
|
93
|
+
// e.g. `<Drawer>` becomes `<DeprecatedDrawer>`
|
|
94
|
+
root.find(j.JSXIdentifier, { name: 'Drawer' }).forEach(function (nodePath) {
|
|
95
|
+
nodePath.node.name = 'DeprecatedDrawer';
|
|
96
|
+
});
|
|
97
|
+
// Transform Drawer JSXElements
|
|
98
|
+
// e.g. `<DrawerHeader>` becomes `<DeprecatedDrawerHeader>`
|
|
99
|
+
root.find(j.JSXIdentifier, { name: 'DrawerHeader' }).forEach(function (nodePath) {
|
|
100
|
+
nodePath.node.name = 'DeprecatedDrawerHeader';
|
|
101
|
+
});
|
|
102
|
+
return root.toSource();
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"softDeprecateLayout.d.ts","sourceRoot":"","sources":["../../../lib/v8/softDeprecateLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAMlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAwF7E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-react';
|
|
2
|
+
var layoutPackage = '@workday/canvas-kit-react/layout';
|
|
3
|
+
var allImportNames = ['Layout', 'LayoutProps', 'Column', 'ColumnProps'];
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
var hasLayoutImports = false;
|
|
8
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
9
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
10
|
+
var value = nodePath.source.value;
|
|
11
|
+
// If there's an import from the layout package, set the import boolean check to true
|
|
12
|
+
if (value === layoutPackage) {
|
|
13
|
+
hasLayoutImports = true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
// If there's an import from the main package, check to see if Layout or LayoutProps are among the named imports
|
|
17
|
+
// e.g. import {Layout} from '@workday/canvas-kit-react';
|
|
18
|
+
if (value === mainPackage) {
|
|
19
|
+
(nodePath.specifiers || []).forEach(function (specifier) {
|
|
20
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
21
|
+
if (allImportNames.includes(specifier.imported.name)) {
|
|
22
|
+
hasLayoutImports = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
29
|
+
// Failsafe to skip transforms unless a Layout import is detected
|
|
30
|
+
if (!hasLayoutImports) {
|
|
31
|
+
return root.toSource();
|
|
32
|
+
}
|
|
33
|
+
root
|
|
34
|
+
.find(j.ImportDeclaration, {
|
|
35
|
+
source: { value: function (value) { return value.includes(mainPackage); } },
|
|
36
|
+
})
|
|
37
|
+
.forEach(function (nodePath) {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
40
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
41
|
+
// Adds Deprecated part to a import name for Layout, LayoutProps, Column, ColumnProps
|
|
42
|
+
if (allImportNames.includes(specifier.imported.name)) {
|
|
43
|
+
specifier.imported.name = "Deprecated" + specifier.imported.name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return specifier;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
// Add Deprecated in menu types and type interfaces
|
|
50
|
+
var typeNames = ['LayoutProps', 'ColumnProps'];
|
|
51
|
+
root
|
|
52
|
+
.find(j.TSTypeReference, {
|
|
53
|
+
typeName: {
|
|
54
|
+
type: 'Identifier',
|
|
55
|
+
name: function (name) { return typeNames.includes(name); },
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
.forEach(function (nodePath) {
|
|
59
|
+
var identifier = nodePath.value.typeName;
|
|
60
|
+
identifier.name = "Deprecated" + identifier.name;
|
|
61
|
+
});
|
|
62
|
+
// Add Deprecated to all interface names
|
|
63
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
64
|
+
var _a;
|
|
65
|
+
// If the interface is extending menu interfaces it should add Deprecated to them
|
|
66
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
67
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
68
|
+
typeNames.includes(typeExtension.expression.name)) {
|
|
69
|
+
typeExtension.expression.name = "Deprecated" + typeExtension.expression.name;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
// Transform Layout and LayoutItem JSXElements
|
|
74
|
+
// e.g. `<Layout>` becomes `<DeprecatedLayout>`
|
|
75
|
+
// e.g. `<Column>` becomes `<DeprecatedColumn>`
|
|
76
|
+
root
|
|
77
|
+
.find(j.JSXIdentifier, { name: function (name) { return name === 'Layout' || name === 'Column'; } })
|
|
78
|
+
.forEach(function (nodePath) {
|
|
79
|
+
if (nodePath.name !== 'property') {
|
|
80
|
+
nodePath.node.name = "Deprecated" + nodePath.node.name;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return root.toSource();
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"softDeprecatePreviewMenu.d.ts","sourceRoot":"","sources":["../../../lib/v8/softDeprecatePreviewMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAMlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmF7E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-preview-react';
|
|
2
|
+
var menuPackage = '@workday/canvas-kit-preview-react/menu';
|
|
3
|
+
var allImportNames = ['Menu', 'MenuProps', 'MenuState', 'MenuItem', 'MenuItemProps'];
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
var hasMenuImports = false;
|
|
8
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
9
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
10
|
+
var value = nodePath.source.value;
|
|
11
|
+
// If there's an import from the menu preview package, set the import boolean check to true
|
|
12
|
+
if (value === menuPackage) {
|
|
13
|
+
hasMenuImports = true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
// If there's an import from the main package, check to see if Menu or MenuProps are among the named imports
|
|
17
|
+
// e.g. import {Menu} from '@workday/canvas-kit-preview-react';
|
|
18
|
+
if (value === mainPackage) {
|
|
19
|
+
(nodePath.specifiers || []).forEach(function (specifier) {
|
|
20
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
21
|
+
if (allImportNames.includes(specifier.imported.name)) {
|
|
22
|
+
hasMenuImports = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
29
|
+
// Failsafe to skip transforms unless a Menu import is detected
|
|
30
|
+
if (!hasMenuImports) {
|
|
31
|
+
return root.toSource();
|
|
32
|
+
}
|
|
33
|
+
root
|
|
34
|
+
.find(j.ImportDeclaration, {
|
|
35
|
+
source: { value: function (value) { return value.includes(mainPackage); } },
|
|
36
|
+
})
|
|
37
|
+
.forEach(function (nodePath) {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
40
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
41
|
+
// Adds Deprecated part to a import name for Menu, MenuProps, MenuState, MenuItem, MenuItemProps
|
|
42
|
+
if (allImportNames.includes(specifier.imported.name)) {
|
|
43
|
+
specifier.imported.name = "Deprecated" + specifier.imported.name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return specifier;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
// Add Deprecated in types using menu interfaces
|
|
50
|
+
var typeNames = ['MenuProps', 'MenuState', 'MenuItemProps'];
|
|
51
|
+
root
|
|
52
|
+
.find(j.TSTypeReference, {
|
|
53
|
+
typeName: { type: 'Identifier', name: function (name) { return typeNames.includes(name); } },
|
|
54
|
+
})
|
|
55
|
+
.forEach(function (nodePath) {
|
|
56
|
+
var identifier = nodePath.value.typeName;
|
|
57
|
+
identifier.name = "Deprecated" + identifier.name;
|
|
58
|
+
});
|
|
59
|
+
// Add Deprecated to all interface names
|
|
60
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
61
|
+
var _a;
|
|
62
|
+
// If the interface is extending menu interfaces it should add Deprecated to them
|
|
63
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
64
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
65
|
+
typeNames.includes(typeExtension.expression.name)) {
|
|
66
|
+
typeExtension.expression.name = "Deprecated" + typeExtension.expression.name;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
// Transform Menu and MenuItem JSXElements
|
|
71
|
+
// e.g. `<Menu>` becomes `<DeprecatedMenu>`
|
|
72
|
+
// e.g. `<MenuItem>` becomes `<DeprecatedMenuItem>`
|
|
73
|
+
root
|
|
74
|
+
.find(j.JSXIdentifier, { name: function (name) { return name === 'Menu' || name === 'MenuItem'; } })
|
|
75
|
+
.forEach(function (nodePath) {
|
|
76
|
+
nodePath.node.name = "Deprecated" + nodePath.node.name;
|
|
77
|
+
});
|
|
78
|
+
return root.toSource();
|
|
79
|
+
}
|
package/index.js
CHANGED
|
@@ -28,6 +28,13 @@ const {_: commands, path} = require('yargs')
|
|
|
28
28
|
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
29
29
|
});
|
|
30
30
|
})
|
|
31
|
+
.command('v8 [path]', chalk.gray('Canvas Kit v7 > v8 migration transform'), yargs => {
|
|
32
|
+
yargs.positional('path', {
|
|
33
|
+
type: 'string',
|
|
34
|
+
default: '.',
|
|
35
|
+
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
36
|
+
});
|
|
37
|
+
})
|
|
31
38
|
.demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
|
|
32
39
|
.strictCommands()
|
|
33
40
|
.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": "8.0.
|
|
5
|
+
"version": "8.0.1",
|
|
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,
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
44
44
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9a2467e289759e1aab0cbc7f1c37cd4739d0f071"
|
|
47
47
|
}
|