@workday/canvas-kit-codemod 7.1.4 → 7.2.0-427-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -5
- package/dist/es6/v5/compoundCard.js +19 -22
- package/dist/es6/v5/getImportRenameMap.js +11 -12
- package/dist/es6/v5/index.js +2 -13
- package/dist/es6/v5/mapTypeTokensToNewHierarchy.js +62 -62
- package/dist/es6/v5/maps.js +2 -2
- package/dist/es6/v5/moveInputProvider.js +6 -6
- package/dist/es6/v5/recategorizeButtons.js +34 -35
- package/dist/es6/v5/removeButtonEnums.js +26 -28
- package/dist/es6/v5/removeDefaultImports.js +7 -7
- package/dist/es6/v5/renameButtonRefs.js +8 -8
- package/dist/es6/v5/renameCoreImports.js +10 -10
- package/dist/es6/v5/renameInputRefs.js +17 -21
- package/dist/es6/v5/renamePreviewTokenImports.js +10 -10
- package/dist/es6/v5/renameSpacing.js +18 -18
- package/dist/es6/v5/slashImports.js +31 -33
- package/dist/es6/v6/deprecateCookieBanner.js +3 -3
- package/dist/es6/v6/deprecateHeader.js +4 -4
- package/dist/es6/v6/deprecatePageHeader.js +3 -3
- package/dist/es6/v6/index.js +3 -14
- package/dist/es6/v6/moveAndRenameSearchBar.js +23 -29
- package/dist/es6/v6/renameCanvasDepthValue.js +3 -3
- package/dist/es6/v6/utils/index.js +28 -31
- package/dist/es6/v7/compoundActionBar.js +27 -39
- package/dist/es6/v7/compoundBanner.js +40 -43
- package/dist/es6/v7/index.js +3 -14
- package/dist/es6/v7/recategorizeIconButtons.js +27 -31
- package/dist/es6/v7/removePropFromPopper.js +14 -18
- package/dist/es6/v7/renameIconPosition.js +13 -17
- package/dist/es6/v7/renameIconRef.js +17 -21
- package/dist/es6/v7/renameLayoutImports.js +14 -14
- package/dist/es6/v7/updateDisclosureShowHide.js +22 -22
- package/dist/es6/v7/updateModelSignatures.js +21 -21
- package/dist/es6/v7/updateSegmentedControl.js +8 -11
- package/dist/es6/v7/updateTabs.js +8 -8
- package/dist/es6/v7/utils/getImportRenameMap.js +11 -12
- package/dist/es6/v7/utils/hasImportSpecifiers.js +9 -11
- 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 +25 -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 +56 -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 +46 -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 +55 -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 +76 -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/dist/es6/v9/compoundToast.d.ts +3 -0
- package/dist/es6/v9/compoundToast.d.ts.map +1 -0
- package/dist/es6/v9/compoundToast.js +121 -0
- package/dist/es6/v9/deprecateStack.d.ts +3 -0
- package/dist/es6/v9/deprecateStack.d.ts.map +1 -0
- package/dist/es6/v9/deprecateStack.js +275 -0
- package/dist/es6/v9/index.d.ts +4 -0
- package/dist/es6/v9/index.d.ts.map +1 -0
- package/dist/es6/v9/index.js +16 -0
- package/dist/es6/v9/promoteToast.d.ts +4 -0
- package/dist/es6/v9/promoteToast.d.ts.map +1 -0
- package/dist/es6/v9/promoteToast.js +56 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts +4 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts.map +1 -0
- package/dist/es6/v9/promoteUseThemedRing.js +56 -0
- package/index.js +40 -5
- package/package.json +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export default function transformer(file, api) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const j = api.jscodeshift;
|
|
3
|
+
const root = j(file.source);
|
|
4
4
|
// Rename spacing imports
|
|
5
5
|
root
|
|
6
6
|
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react/core' } })
|
|
7
|
-
.forEach(
|
|
7
|
+
.forEach(nodePath => {
|
|
8
8
|
var _a;
|
|
9
|
-
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
9
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
10
10
|
// Only iterate over named import statements
|
|
11
11
|
if (specifier.type === 'ImportSpecifier') {
|
|
12
12
|
switch (specifier.imported.name) {
|
|
@@ -41,8 +41,8 @@ export default function transformer(file, api) {
|
|
|
41
41
|
// Rename spacing expressions
|
|
42
42
|
// Check file import statements for canvas-kit imports
|
|
43
43
|
// This allows us to somewhat safely assume any member expressions or types should not be modified
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const canvasKitImports = root.find(j.ImportDeclaration).filter(nodePath => {
|
|
45
|
+
const importSource = nodePath.value.source.value;
|
|
46
46
|
return (importSource === '@workday/canvas-kit-react/core' ||
|
|
47
47
|
importSource === '@workday/canvas-kit-react');
|
|
48
48
|
});
|
|
@@ -54,8 +54,8 @@ export default function transformer(file, api) {
|
|
|
54
54
|
// e.g. `{ margin: spacing.m }` becomes `{ margin: space.m }`
|
|
55
55
|
root
|
|
56
56
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: 'spacing' } })
|
|
57
|
-
.forEach(
|
|
58
|
-
|
|
57
|
+
.forEach(nodePath => {
|
|
58
|
+
const identifier = nodePath.value.object;
|
|
59
59
|
identifier.name = 'space';
|
|
60
60
|
return nodePath;
|
|
61
61
|
});
|
|
@@ -63,8 +63,8 @@ export default function transformer(file, api) {
|
|
|
63
63
|
// e.g. `{ margin: spacingNumbers.m }` becomes `{ margin: spaceNumbers.m }`
|
|
64
64
|
root
|
|
65
65
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: 'spacingNumbers' } })
|
|
66
|
-
.forEach(
|
|
67
|
-
|
|
66
|
+
.forEach(nodePath => {
|
|
67
|
+
const identifier = nodePath.value.object;
|
|
68
68
|
identifier.name = 'spaceNumbers';
|
|
69
69
|
return nodePath;
|
|
70
70
|
});
|
|
@@ -73,8 +73,8 @@ export default function transformer(file, api) {
|
|
|
73
73
|
// and `{ margin: canvas.spacingNumber.m }` becomes `{ margin: canvas.spaceNumber.m }`
|
|
74
74
|
root
|
|
75
75
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: 'canvas' } })
|
|
76
|
-
.forEach(
|
|
77
|
-
|
|
76
|
+
.forEach(nodePath => {
|
|
77
|
+
const objectProperty = nodePath.value.property;
|
|
78
78
|
if (objectProperty.name === 'spacing') {
|
|
79
79
|
objectProperty.name = 'space';
|
|
80
80
|
}
|
|
@@ -88,8 +88,8 @@ export default function transformer(file, api) {
|
|
|
88
88
|
// becomes `type SpaceProps = CanvasSpace;`
|
|
89
89
|
root
|
|
90
90
|
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: 'CanvasSpacing' } })
|
|
91
|
-
.forEach(
|
|
92
|
-
|
|
91
|
+
.forEach(nodePath => {
|
|
92
|
+
const identifier = nodePath.value.typeName;
|
|
93
93
|
identifier.name = 'CanvasSpace';
|
|
94
94
|
return nodePath;
|
|
95
95
|
});
|
|
@@ -98,8 +98,8 @@ export default function transformer(file, api) {
|
|
|
98
98
|
// becomes `type SpaceNumberProps = CanvasSpaceNumbers;`
|
|
99
99
|
root
|
|
100
100
|
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: 'CanvasSpacingNumber' } })
|
|
101
|
-
.forEach(
|
|
102
|
-
|
|
101
|
+
.forEach(nodePath => {
|
|
102
|
+
const identifier = nodePath.value.typeName;
|
|
103
103
|
identifier.name = 'CanvasSpaceNumbers';
|
|
104
104
|
return nodePath;
|
|
105
105
|
});
|
|
@@ -108,8 +108,8 @@ export default function transformer(file, api) {
|
|
|
108
108
|
// becomes `type SpaceValueProps = CanvasSpaceValues;`
|
|
109
109
|
root
|
|
110
110
|
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: 'CanvasSpacingValue' } })
|
|
111
|
-
.forEach(
|
|
112
|
-
|
|
111
|
+
.forEach(nodePath => {
|
|
112
|
+
const identifier = nodePath.value.typeName;
|
|
113
113
|
identifier.name = 'CanvasSpaceValues';
|
|
114
114
|
return nodePath;
|
|
115
115
|
});
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
import { bundleExportMap, sourceMap } from './maps';
|
|
13
2
|
/**
|
|
14
3
|
* Adds a default import specifier with the same name to the `newImports`
|
|
@@ -20,9 +9,9 @@ import { bundleExportMap, sourceMap } from './maps';
|
|
|
20
9
|
* @param source The source string to reference so we can get the new source package
|
|
21
10
|
* @param newImports
|
|
22
11
|
*/
|
|
23
|
-
|
|
12
|
+
const addMappedDefaultSpecifier = (specifier, source, newImports, j) => {
|
|
24
13
|
var _a;
|
|
25
|
-
|
|
14
|
+
const specifierName = (_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
26
15
|
if (!specifierName) {
|
|
27
16
|
return;
|
|
28
17
|
}
|
|
@@ -31,8 +20,11 @@ var addMappedDefaultSpecifier = function (specifier, source, newImports, j) {
|
|
|
31
20
|
addMappedSpecifier(j.importSpecifier(j.identifier(specifierName)), source, newImports);
|
|
32
21
|
return;
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
newImports[mappedSource] =
|
|
23
|
+
const mappedSource = bundleExportMap[specifierName];
|
|
24
|
+
newImports[mappedSource] = {
|
|
25
|
+
...newImports[mappedSource],
|
|
26
|
+
default: specifier,
|
|
27
|
+
};
|
|
36
28
|
};
|
|
37
29
|
/**
|
|
38
30
|
* Adds a namespaced import specifier with the same name to the `newImports`
|
|
@@ -44,19 +36,22 @@ var addMappedDefaultSpecifier = function (specifier, source, newImports, j) {
|
|
|
44
36
|
* @param source The source string to reference so we can get the new source package
|
|
45
37
|
* @param newImports
|
|
46
38
|
*/
|
|
47
|
-
|
|
39
|
+
const addMappedNamespaceSpecifier = (specifier, source, newImports) => {
|
|
48
40
|
var _a;
|
|
49
|
-
|
|
41
|
+
const specifierName = (_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
50
42
|
if (!specifierName) {
|
|
51
43
|
return;
|
|
52
44
|
}
|
|
53
45
|
// TODO: ADD HANDLING FOR @workday/canvas-kit-react source. Need to split imports
|
|
54
46
|
if (source === '@workday/canvas-kit-react') {
|
|
55
|
-
console.error(
|
|
47
|
+
console.error(`Failed to split namespace import \`import * as ${specifierName} from ${source}\``);
|
|
56
48
|
return;
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
newImports[mappedSource] =
|
|
50
|
+
const mappedSource = sourceMap[source];
|
|
51
|
+
newImports[mappedSource] = {
|
|
52
|
+
...newImports[mappedSource],
|
|
53
|
+
namespace: specifier,
|
|
54
|
+
};
|
|
60
55
|
};
|
|
61
56
|
/**
|
|
62
57
|
* Adds a named import specifier with the same name to the `newImports`
|
|
@@ -68,23 +63,26 @@ var addMappedNamespaceSpecifier = function (specifier, source, newImports) {
|
|
|
68
63
|
* @param source The source string to reference so we can get the new source package
|
|
69
64
|
* @param newImports
|
|
70
65
|
*/
|
|
71
|
-
|
|
66
|
+
const addMappedSpecifier = (specifier, source, newImports) => {
|
|
72
67
|
var _a;
|
|
73
|
-
|
|
68
|
+
const specifierName = specifier.imported.name;
|
|
74
69
|
// If the import is coming from the bundle import, use the bundle export map
|
|
75
70
|
// to get the correct new source. Otherwise, use the mapped source name.
|
|
76
|
-
|
|
71
|
+
const newSource = source === '@workday/canvas-kit-react' ? bundleExportMap[specifierName] : sourceMap[source];
|
|
77
72
|
// Create new array of import specifiers for new import if not defined, otherwise push new import
|
|
78
73
|
if (!newImports[newSource] || !newImports[newSource].namedImports) {
|
|
79
|
-
newImports[newSource] =
|
|
74
|
+
newImports[newSource] = {
|
|
75
|
+
...newImports[newSource],
|
|
76
|
+
namedImports: [],
|
|
77
|
+
};
|
|
80
78
|
}
|
|
81
79
|
(_a = newImports[newSource].namedImports) === null || _a === void 0 ? void 0 : _a.push(specifier);
|
|
82
80
|
};
|
|
83
81
|
export default function transformer(file, api, options) {
|
|
84
|
-
|
|
82
|
+
const j = api.jscodeshift;
|
|
85
83
|
return j(file.source)
|
|
86
84
|
.find(j.ImportDeclaration)
|
|
87
|
-
.forEach(
|
|
85
|
+
.forEach(_import => {
|
|
88
86
|
var _a;
|
|
89
87
|
// Move on if source isn't a canvas kit package
|
|
90
88
|
if (typeof _import.value.source.value !== 'string' ||
|
|
@@ -92,9 +90,9 @@ export default function transformer(file, api, options) {
|
|
|
92
90
|
!Object.keys(sourceMap).includes(_import.value.source.value))) {
|
|
93
91
|
return;
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(_a = _import.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
93
|
+
const source = _import.value.source.value;
|
|
94
|
+
const newImports = {};
|
|
95
|
+
(_a = _import.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
98
96
|
switch (specifier.type) {
|
|
99
97
|
case 'ImportDefaultSpecifier':
|
|
100
98
|
addMappedDefaultSpecifier(specifier, source, newImports, j);
|
|
@@ -111,9 +109,9 @@ export default function transformer(file, api, options) {
|
|
|
111
109
|
if (!Object.keys(newImports).length) {
|
|
112
110
|
return;
|
|
113
111
|
}
|
|
114
|
-
j(_import).replaceWith(Object.keys(newImports).map(
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
j(_import).replaceWith(Object.keys(newImports).map(source => {
|
|
113
|
+
const newImportSet = [];
|
|
114
|
+
const { default: defaultImport, namespace, namedImports } = newImports[source];
|
|
117
115
|
// add `import X` default specifier
|
|
118
116
|
if (defaultImport) {
|
|
119
117
|
newImportSet.push(defaultImport);
|
|
@@ -124,7 +122,7 @@ export default function transformer(file, api, options) {
|
|
|
124
122
|
}
|
|
125
123
|
// Add `import { X }` named specifier
|
|
126
124
|
if (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length) {
|
|
127
|
-
namedImports === null || namedImports === void 0 ? void 0 : namedImports.forEach(
|
|
125
|
+
namedImports === null || namedImports === void 0 ? void 0 : namedImports.forEach(specifier => {
|
|
128
126
|
newImportSet.push(specifier);
|
|
129
127
|
});
|
|
130
128
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { renameImports } from './utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const transform = (file, api) => {
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const root = j(file.source);
|
|
5
5
|
return renameImports(api, root, '@workday/canvas-kit-react/cookie-banner', {
|
|
6
6
|
CookieBanner: 'DeprecatedCookieBanner',
|
|
7
7
|
CookieBannerProps: 'DeprecatedCookieBannerProps',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { renameImports } from './utils';
|
|
2
|
-
|
|
2
|
+
const headerRenameMap = {
|
|
3
3
|
DubLogoTitle: 'DeprecatedDubLogoTitle',
|
|
4
4
|
GlobalHeader: 'DeprecatedGlobalHeader',
|
|
5
5
|
Header: 'DeprecatedHeader',
|
|
@@ -11,9 +11,9 @@ var headerRenameMap = {
|
|
|
11
11
|
WorkdayLogoTitle: 'DeprecatedWorkdayLogoTitle',
|
|
12
12
|
themes: 'deprecatedHeaderThemes',
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const transform = (file, api) => {
|
|
15
|
+
const j = api.jscodeshift;
|
|
16
|
+
const root = j(file.source);
|
|
17
17
|
return renameImports(api, root, '@workday/canvas-kit-labs-react/header', headerRenameMap).toSource();
|
|
18
18
|
};
|
|
19
19
|
export default transform;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { renameImports } from './utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const transform = (file, api) => {
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const root = j(file.source);
|
|
5
5
|
return renameImports(api, root, '@workday/canvas-kit-react/page-header', {
|
|
6
6
|
PageHeader: 'DeprecatedPageHeader',
|
|
7
7
|
PageHeaderProps: 'DeprecatedPageHeaderProps',
|
package/dist/es6/v6/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
// deprecate PageHeader
|
|
13
2
|
import deprecatePageHeader from './deprecatePageHeader';
|
|
14
3
|
// deprecate CookieBanner
|
|
@@ -19,9 +8,9 @@ import moveAndRenameSearchBar from './moveAndRenameSearchBar';
|
|
|
19
8
|
import deprecateHeader from './deprecateHeader';
|
|
20
9
|
// rename CanvasDepthValue
|
|
21
10
|
import renameCanvasDepthValue from './renameCanvasDepthValue';
|
|
22
|
-
|
|
11
|
+
const transform = (file, api, options) => {
|
|
23
12
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
24
|
-
|
|
13
|
+
const fixes = [
|
|
25
14
|
deprecatePageHeader,
|
|
26
15
|
deprecateCookieBanner,
|
|
27
16
|
moveAndRenameSearchBar,
|
|
@@ -29,6 +18,6 @@ var transform = function (file, api, options) {
|
|
|
29
18
|
deprecateHeader,
|
|
30
19
|
renameCanvasDepthValue,
|
|
31
20
|
];
|
|
32
|
-
return fixes.reduce(
|
|
21
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
33
22
|
};
|
|
34
23
|
export default transform;
|
|
@@ -1,43 +1,37 @@
|
|
|
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
1
|
import { filterImportSpecifiers, renameImports, hasImportSpecifiers, } from './utils';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
const mainPackage = '@workday/canvas-kit-labs-react';
|
|
3
|
+
const headerPackage = '@workday/canvas-kit-labs-react/header';
|
|
4
|
+
const searchBarRenameImports = ['SearchBar', 'SearchBarProps', 'SearchBarState'];
|
|
5
|
+
const searchBarImportSpecifiers = [
|
|
6
|
+
...searchBarRenameImports,
|
|
13
7
|
'SearchThemeAttributes',
|
|
14
8
|
'SearchThemes',
|
|
15
|
-
]
|
|
16
|
-
|
|
9
|
+
];
|
|
10
|
+
const renameMap = {
|
|
17
11
|
SearchBar: 'SearchForm',
|
|
18
12
|
SearchBarProps: 'SearchFormProps',
|
|
19
13
|
SearchBarState: 'SearchFormState',
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const transform = (file, api) => {
|
|
16
|
+
const j = api.jscodeshift;
|
|
17
|
+
const root = j(file.source);
|
|
24
18
|
if (!hasImportSpecifiers(api, root, '@workday/canvas-kit-labs-react/header', Object.keys(renameMap))) {
|
|
25
19
|
return file.source;
|
|
26
20
|
}
|
|
27
21
|
function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
|
|
28
22
|
nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
|
|
29
23
|
}
|
|
30
|
-
|
|
24
|
+
const discoveredImportSpecifiers = {};
|
|
31
25
|
// Rename search-bar named imports from @workday/canvas-kit-labs-react
|
|
32
26
|
// e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
|
|
33
27
|
// becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
|
|
34
|
-
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(
|
|
35
|
-
|
|
28
|
+
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(nodePath => {
|
|
29
|
+
const importSpecifiers = nodePath.value.specifiers || [];
|
|
36
30
|
// Filter search bar imports
|
|
37
|
-
|
|
31
|
+
const searchBarImports = filterImportSpecifiers(importSpecifiers);
|
|
38
32
|
// Rename search bar imports
|
|
39
|
-
searchBarImports.forEach(
|
|
40
|
-
|
|
33
|
+
searchBarImports.forEach(specifier => {
|
|
34
|
+
const specifierName = specifier.imported.name;
|
|
41
35
|
if (specifierName in renameMap) {
|
|
42
36
|
// if it hasn't been aliased, track it for updating JSX
|
|
43
37
|
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
@@ -51,11 +45,11 @@ var transform = function (file, api) {
|
|
|
51
45
|
// e.g import { Header, SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react/header';
|
|
52
46
|
// becomes import { Header } from '@workday/canvas-kit-labs-react/header';
|
|
53
47
|
// and import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react/search-form';
|
|
54
|
-
root.find(j.ImportDeclaration, { source: { value: headerPackage } }).forEach(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
importSpecifiers.forEach(
|
|
48
|
+
root.find(j.ImportDeclaration, { source: { value: headerPackage } }).forEach(nodePath => {
|
|
49
|
+
const importSpecifiers = nodePath.value.specifiers || [];
|
|
50
|
+
const headerSpecifiers = [];
|
|
51
|
+
const searchBarSpecifiers = [];
|
|
52
|
+
importSpecifiers.forEach(specifier => {
|
|
59
53
|
// If there is a SearchBar import specifier, keep it in an array.
|
|
60
54
|
// This will be used to build a new import declaration later.
|
|
61
55
|
if (specifier.type === 'ImportSpecifier' &&
|
|
@@ -72,8 +66,8 @@ var transform = function (file, api) {
|
|
|
72
66
|
root.find(j.ImportDeclaration, { source: { value: headerPackage } }).remove();
|
|
73
67
|
// If SearchBar import specifiers were found, insert a new import declaration above the original import declaration
|
|
74
68
|
if (searchBarSpecifiers.length) {
|
|
75
|
-
searchBarSpecifiers.forEach(
|
|
76
|
-
|
|
69
|
+
searchBarSpecifiers.forEach(specifier => {
|
|
70
|
+
const specifierName = specifier.imported.name;
|
|
77
71
|
if (specifierName in renameMap) {
|
|
78
72
|
// if it hasn't been aliased, track it for updating JSX
|
|
79
73
|
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { renameImports } from './utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const transform = (file, api) => {
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const root = j(file.source);
|
|
5
5
|
return renameImports(api, root, '@workday/canvas-kit-react/tokens', {
|
|
6
6
|
CanvasDepthValue: 'CanvasDepthValues',
|
|
7
7
|
}).toSource();
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* }
|
|
12
12
|
*/
|
|
13
13
|
export function filterImportSpecifiers(importSpecifiers, importNames) {
|
|
14
|
-
|
|
15
|
-
importSpecifiers.forEach(
|
|
14
|
+
const filteredSpecifiers = [];
|
|
15
|
+
importSpecifiers.forEach(specifier => {
|
|
16
16
|
if (specifier.type === 'ImportSpecifier') {
|
|
17
17
|
if (importNames && importNames.includes(specifier.imported.name)) {
|
|
18
18
|
filteredSpecifiers.push(specifier);
|
|
@@ -37,11 +37,11 @@ export function filterImportSpecifiers(importSpecifiers, importNames) {
|
|
|
37
37
|
* }
|
|
38
38
|
*/
|
|
39
39
|
export function filterImportDefaultSpecifiers(importSpecifiers, importNames) {
|
|
40
|
-
|
|
41
|
-
importSpecifiers.forEach(
|
|
40
|
+
const filteredSpecifiers = [];
|
|
41
|
+
importSpecifiers.forEach(specifier => {
|
|
42
42
|
var _a;
|
|
43
43
|
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
44
|
-
|
|
44
|
+
const localName = ((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) || '';
|
|
45
45
|
if (importNames && importNames.includes(localName)) {
|
|
46
46
|
filteredSpecifiers.push(specifier);
|
|
47
47
|
}
|
|
@@ -60,9 +60,9 @@ export function filterImportDefaultSpecifiers(importSpecifiers, importNames) {
|
|
|
60
60
|
* renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
|
|
61
61
|
*/
|
|
62
62
|
export function renameImportDefaultSpecifiers(importSpecifiers, renameMap) {
|
|
63
|
-
importSpecifiers.forEach(
|
|
63
|
+
importSpecifiers.forEach(specifier => {
|
|
64
64
|
var _a;
|
|
65
|
-
|
|
65
|
+
const specifierName = (_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
66
66
|
if (specifier.local && specifierName && specifierName in renameMap) {
|
|
67
67
|
specifier.local.name = renameMap[specifierName];
|
|
68
68
|
}
|
|
@@ -87,9 +87,9 @@ export function renameImportDefaultSpecifiers(importSpecifiers, renameMap) {
|
|
|
87
87
|
* }
|
|
88
88
|
*/
|
|
89
89
|
export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
90
|
-
|
|
91
|
-
return !!root.find(j.ImportDeclaration,
|
|
92
|
-
|
|
90
|
+
const j = api.jscodeshift;
|
|
91
|
+
return !!root.find(j.ImportDeclaration, nodePath => {
|
|
92
|
+
const value = nodePath.source.value;
|
|
93
93
|
// package name was found
|
|
94
94
|
if (typeof packageName === 'string'
|
|
95
95
|
? value === packageName
|
|
@@ -97,16 +97,14 @@ export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
|
97
97
|
return true;
|
|
98
98
|
}
|
|
99
99
|
// Extract the main package(s) from the import, and test specifiers against that package
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.join('/');
|
|
105
|
-
});
|
|
100
|
+
const mainPackage = (typeof packageName === 'string' ? [packageName] : packageName).map(s => s
|
|
101
|
+
.split('/')
|
|
102
|
+
.slice(0, -1)
|
|
103
|
+
.join('/'));
|
|
106
104
|
if (mainPackage.includes(value)) {
|
|
107
|
-
return !!(nodePath.specifiers || []).find(
|
|
105
|
+
return !!(nodePath.specifiers || []).find(specifier => {
|
|
108
106
|
if (specifier.type === 'ImportSpecifier') {
|
|
109
|
-
|
|
107
|
+
const specifierName = specifier.imported.name;
|
|
110
108
|
return specifiers.includes(specifierName);
|
|
111
109
|
}
|
|
112
110
|
return false;
|
|
@@ -115,13 +113,12 @@ export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
|
115
113
|
return false;
|
|
116
114
|
});
|
|
117
115
|
}
|
|
118
|
-
export function renameImports(api, root, packageName, specifierMap, discoveredImportSpecifiers) {
|
|
119
|
-
|
|
120
|
-
var j = api.jscodeshift;
|
|
116
|
+
export function renameImports(api, root, packageName, specifierMap, discoveredImportSpecifiers = {}) {
|
|
117
|
+
const j = api.jscodeshift;
|
|
121
118
|
if (!hasImportSpecifiers(api, root, packageName, Object.keys(specifierMap))) {
|
|
122
119
|
return root;
|
|
123
120
|
}
|
|
124
|
-
|
|
121
|
+
const mainPackage = packageName
|
|
125
122
|
.split('/')
|
|
126
123
|
.slice(0, -1)
|
|
127
124
|
.join('/');
|
|
@@ -130,9 +127,9 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
130
127
|
// becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
|
|
131
128
|
// Find imports from main packages
|
|
132
129
|
// ex. '@workday/canvas-kit-labs-react'
|
|
133
|
-
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(
|
|
130
|
+
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(nodePath => {
|
|
134
131
|
var _a;
|
|
135
|
-
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
132
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
136
133
|
if (specifier.type === 'ImportSpecifier') {
|
|
137
134
|
if (Object.keys(specifierMap).includes(specifier.imported.name)) {
|
|
138
135
|
// if it hasn't been aliased, track it for updating JSX
|
|
@@ -146,9 +143,9 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
146
143
|
});
|
|
147
144
|
// Find imports from component specific packages
|
|
148
145
|
// ex. '@workday/canvas-kit-labs-react/header'
|
|
149
|
-
root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(
|
|
146
|
+
root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(nodePath => {
|
|
150
147
|
var _a;
|
|
151
|
-
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
148
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
152
149
|
// Transforms default imports
|
|
153
150
|
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
154
151
|
if (specifier.local && Object.keys(specifierMap).includes(specifier.local.name)) {
|
|
@@ -170,7 +167,7 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
170
167
|
});
|
|
171
168
|
// Transform type references
|
|
172
169
|
// e.g. `type CustomProps = CookieBannerProps;` becomes `type CustomProps = DeprecatedCookieBannerProps;`
|
|
173
|
-
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(
|
|
170
|
+
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(nodePath => {
|
|
174
171
|
if (nodePath.value.typeName.type === 'Identifier' &&
|
|
175
172
|
Object.keys(specifierMap).includes(nodePath.value.typeName.name)) {
|
|
176
173
|
nodePath.value.typeName.name = specifierMap[nodePath.value.typeName.name];
|
|
@@ -178,10 +175,10 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
178
175
|
});
|
|
179
176
|
// Transform type interface declaration references
|
|
180
177
|
// e.g. `interface CustomProps extends CookieBannerProps` becomes `interface CustomProps extends DeprecatedCookieBannerProps`
|
|
181
|
-
root.find(j.TSInterfaceDeclaration).forEach(
|
|
178
|
+
root.find(j.TSInterfaceDeclaration).forEach(nodePath => {
|
|
182
179
|
var _a;
|
|
183
180
|
// If the interface is extending CookieBannerProps, transform the extension name to DeprecatedCookieBannerProps
|
|
184
|
-
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
181
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(typeExtension => {
|
|
185
182
|
if (typeExtension.expression.type === 'Identifier' &&
|
|
186
183
|
Object.keys(specifierMap).includes(typeExtension.expression.name)) {
|
|
187
184
|
typeExtension.expression.name = specifierMap[typeExtension.expression.name];
|
|
@@ -190,7 +187,7 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
190
187
|
});
|
|
191
188
|
// Transform JSXElements
|
|
192
189
|
// e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
|
|
193
|
-
root.find(j.JSXIdentifier).forEach(
|
|
190
|
+
root.find(j.JSXIdentifier).forEach(nodePath => {
|
|
194
191
|
if (
|
|
195
192
|
// Check to see if it was imported from Canvas Kit
|
|
196
193
|
discoveredImportSpecifiers[nodePath.value.name] &&
|
|
@@ -200,7 +197,7 @@ export function renameImports(api, root, packageName, specifierMap, discoveredIm
|
|
|
200
197
|
});
|
|
201
198
|
// Transform MemberExpressions
|
|
202
199
|
// e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
|
|
203
|
-
root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(
|
|
200
|
+
root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(nodePath => {
|
|
204
201
|
if (nodePath.value.object.type === 'Identifier' &&
|
|
205
202
|
// Check to see if it was imported from Canvas Kit
|
|
206
203
|
discoveredImportSpecifiers[nodePath.value.object.name] &&
|