@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.
Files changed (84) hide show
  1. package/README.md +41 -5
  2. package/dist/es6/v5/compoundCard.js +19 -22
  3. package/dist/es6/v5/getImportRenameMap.js +11 -12
  4. package/dist/es6/v5/index.js +2 -13
  5. package/dist/es6/v5/mapTypeTokensToNewHierarchy.js +62 -62
  6. package/dist/es6/v5/maps.js +2 -2
  7. package/dist/es6/v5/moveInputProvider.js +6 -6
  8. package/dist/es6/v5/recategorizeButtons.js +34 -35
  9. package/dist/es6/v5/removeButtonEnums.js +26 -28
  10. package/dist/es6/v5/removeDefaultImports.js +7 -7
  11. package/dist/es6/v5/renameButtonRefs.js +8 -8
  12. package/dist/es6/v5/renameCoreImports.js +10 -10
  13. package/dist/es6/v5/renameInputRefs.js +17 -21
  14. package/dist/es6/v5/renamePreviewTokenImports.js +10 -10
  15. package/dist/es6/v5/renameSpacing.js +18 -18
  16. package/dist/es6/v5/slashImports.js +31 -33
  17. package/dist/es6/v6/deprecateCookieBanner.js +3 -3
  18. package/dist/es6/v6/deprecateHeader.js +4 -4
  19. package/dist/es6/v6/deprecatePageHeader.js +3 -3
  20. package/dist/es6/v6/index.js +3 -14
  21. package/dist/es6/v6/moveAndRenameSearchBar.js +23 -29
  22. package/dist/es6/v6/renameCanvasDepthValue.js +3 -3
  23. package/dist/es6/v6/utils/index.js +28 -31
  24. package/dist/es6/v7/compoundActionBar.js +27 -39
  25. package/dist/es6/v7/compoundBanner.js +40 -43
  26. package/dist/es6/v7/index.js +3 -14
  27. package/dist/es6/v7/recategorizeIconButtons.js +27 -31
  28. package/dist/es6/v7/removePropFromPopper.js +14 -18
  29. package/dist/es6/v7/renameIconPosition.js +13 -17
  30. package/dist/es6/v7/renameIconRef.js +17 -21
  31. package/dist/es6/v7/renameLayoutImports.js +14 -14
  32. package/dist/es6/v7/updateDisclosureShowHide.js +22 -22
  33. package/dist/es6/v7/updateModelSignatures.js +21 -21
  34. package/dist/es6/v7/updateSegmentedControl.js +8 -11
  35. package/dist/es6/v7/updateTabs.js +8 -8
  36. package/dist/es6/v7/utils/getImportRenameMap.js +11 -12
  37. package/dist/es6/v7/utils/hasImportSpecifiers.js +9 -11
  38. package/dist/es6/v8/index.d.ts +4 -0
  39. package/dist/es6/v8/index.d.ts.map +1 -0
  40. package/dist/es6/v8/index.js +25 -0
  41. package/dist/es6/v8/promoteBreadcrumbs.d.ts +4 -0
  42. package/dist/es6/v8/promoteBreadcrumbs.d.ts.map +1 -0
  43. package/dist/es6/v8/promoteBreadcrumbs.js +56 -0
  44. package/dist/es6/v8/promoteComponentsToTesting.d.ts +4 -0
  45. package/dist/es6/v8/promoteComponentsToTesting.d.ts.map +1 -0
  46. package/dist/es6/v8/promoteComponentsToTesting.js +76 -0
  47. package/dist/es6/v8/refactorActionBarOverflowButton.d.ts +3 -0
  48. package/dist/es6/v8/refactorActionBarOverflowButton.d.ts.map +1 -0
  49. package/dist/es6/v8/refactorActionBarOverflowButton.js +46 -0
  50. package/dist/es6/v8/removeDefaultImports.d.ts +3 -0
  51. package/dist/es6/v8/removeDefaultImports.d.ts.map +1 -0
  52. package/dist/es6/v8/removeDefaultImports.js +52 -0
  53. package/dist/es6/v8/renameLoadingAnimation.d.ts +3 -0
  54. package/dist/es6/v8/renameLoadingAnimation.d.ts.map +1 -0
  55. package/dist/es6/v8/renameLoadingAnimation.js +62 -0
  56. package/dist/es6/v8/restructureBreadcrumbs.d.ts +3 -0
  57. package/dist/es6/v8/restructureBreadcrumbs.d.ts.map +1 -0
  58. package/dist/es6/v8/restructureBreadcrumbs.js +55 -0
  59. package/dist/es6/v8/softDeprecateDrawer.d.ts +3 -0
  60. package/dist/es6/v8/softDeprecateDrawer.d.ts.map +1 -0
  61. package/dist/es6/v8/softDeprecateDrawer.js +103 -0
  62. package/dist/es6/v8/softDeprecateLayout.d.ts +3 -0
  63. package/dist/es6/v8/softDeprecateLayout.d.ts.map +1 -0
  64. package/dist/es6/v8/softDeprecateLayout.js +76 -0
  65. package/dist/es6/v8/softDeprecatePreviewMenu.d.ts +3 -0
  66. package/dist/es6/v8/softDeprecatePreviewMenu.d.ts.map +1 -0
  67. package/dist/es6/v8/softDeprecatePreviewMenu.js +79 -0
  68. package/dist/es6/v9/compoundToast.d.ts +3 -0
  69. package/dist/es6/v9/compoundToast.d.ts.map +1 -0
  70. package/dist/es6/v9/compoundToast.js +121 -0
  71. package/dist/es6/v9/deprecateStack.d.ts +3 -0
  72. package/dist/es6/v9/deprecateStack.d.ts.map +1 -0
  73. package/dist/es6/v9/deprecateStack.js +275 -0
  74. package/dist/es6/v9/index.d.ts +4 -0
  75. package/dist/es6/v9/index.d.ts.map +1 -0
  76. package/dist/es6/v9/index.js +16 -0
  77. package/dist/es6/v9/promoteToast.d.ts +4 -0
  78. package/dist/es6/v9/promoteToast.d.ts.map +1 -0
  79. package/dist/es6/v9/promoteToast.js +56 -0
  80. package/dist/es6/v9/promoteUseThemedRing.d.ts +4 -0
  81. package/dist/es6/v9/promoteUseThemedRing.d.ts.map +1 -0
  82. package/dist/es6/v9/promoteUseThemedRing.js +56 -0
  83. package/index.js +40 -5
  84. package/package.json +2 -2
@@ -1,24 +1,24 @@
1
1
  import { getImportRenameMap } from './getImportRenameMap';
2
- var updateJSXTag = function (nodePath, newTag) {
2
+ const updateJSXTag = (nodePath, newTag) => {
3
3
  nodePath.value.openingElement.name.name = newTag;
4
4
  if (nodePath.value.closingElement) {
5
5
  nodePath.value.closingElement.name.name = newTag;
6
6
  }
7
7
  };
8
- var findBtnTag = function (elementName, node) {
8
+ const findBtnTag = (elementName, node) => {
9
9
  if (elementName && node.openingElement.name.name === elementName) {
10
10
  return true;
11
11
  }
12
12
  return false;
13
13
  };
14
14
  export default function transformer(file, api, options) {
15
- var j = api.jscodeshift;
16
- var root = j(file.source);
17
- var requiredImportSpecifiers = [];
15
+ const j = api.jscodeshift;
16
+ const root = j(file.source);
17
+ const requiredImportSpecifiers = [];
18
18
  /**
19
19
  * 1. Find button imports
20
20
  */
21
- var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
21
+ const { containsCanvasImports, importMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/button');
22
22
  if (!containsCanvasImports) {
23
23
  return file.source;
24
24
  }
@@ -33,17 +33,17 @@ export default function transformer(file, api, options) {
33
33
  */
34
34
  root
35
35
  .find(j.JSXElement, findBtnTag.bind(undefined, importMap.Button))
36
- .forEach(function (nodePath) {
36
+ .forEach((nodePath) => {
37
37
  var _a, _b;
38
- var attrs = nodePath.value.openingElement.attributes;
39
- var isPrimary = false;
40
- var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
38
+ const attrs = nodePath.value.openingElement.attributes;
39
+ let isPrimary = false;
40
+ const variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
41
41
  if (variantProp) {
42
42
  isPrimary = ((_a = variantProp.value) === null || _a === void 0 ? void 0 : _a.value) === 'primary';
43
43
  // remove variant prop
44
44
  (_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
45
45
  }
46
- var buttonType = isPrimary ? 'PrimaryButton' : 'SecondaryButton';
46
+ const buttonType = isPrimary ? 'PrimaryButton' : 'SecondaryButton';
47
47
  // Swap to `PrimaryButton` or `SecondaryButton`
48
48
  updateJSXTag(nodePath, buttonType);
49
49
  requiredImportSpecifiers.push(buttonType);
@@ -55,7 +55,7 @@ export default function transformer(file, api, options) {
55
55
  */
56
56
  root
57
57
  .find(j.JSXElement, findBtnTag.bind(undefined, importMap.HighlightButton))
58
- .forEach(function (nodePath) {
58
+ .forEach(nodePath => {
59
59
  updateJSXTag(nodePath, 'SecondaryButton');
60
60
  requiredImportSpecifiers.push('SecondaryButton');
61
61
  });
@@ -65,12 +65,12 @@ export default function transformer(file, api, options) {
65
65
  * - If variant is 'inverse', keep it. Otherwise, remove the variant prop
66
66
  * - Replace import with `SecondaryButton` if it doesn't exist
67
67
  */
68
- root.find(j.JSXElement, findBtnTag.bind(undefined, importMap.OutlineButton)).forEach(function (nodePath) {
68
+ root.find(j.JSXElement, findBtnTag.bind(undefined, importMap.OutlineButton)).forEach(nodePath => {
69
69
  var _a;
70
70
  // Swap to `SecondaryButton`
71
71
  updateJSXTag(nodePath, 'SecondaryButton');
72
- var attrs = nodePath.value.openingElement.attributes;
73
- var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
72
+ const attrs = nodePath.value.openingElement.attributes;
73
+ const variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
74
74
  if (variantProp && variantProp.type === 'JSXAttribute') {
75
75
  if (variantProp.value.value !== 'inverse') {
76
76
  // remove variant prop
@@ -84,12 +84,12 @@ export default function transformer(file, api, options) {
84
84
  * - Replace with `TertiaryButton`
85
85
  * - If variant="text", remove variant prop
86
86
  */
87
- root.find(j.JSXElement, findBtnTag.bind(undefined, importMap.TextButton)).forEach(function (nodePath) {
87
+ root.find(j.JSXElement, findBtnTag.bind(undefined, importMap.TextButton)).forEach(nodePath => {
88
88
  var _a, _b, _c;
89
89
  // Swap to `TertiaryButton`
90
90
  updateJSXTag(nodePath, 'TertiaryButton');
91
- var attrs = nodePath.value.openingElement.attributes;
92
- var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
91
+ const attrs = nodePath.value.openingElement.attributes;
92
+ const variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
93
93
  if (variantProp && ((_b = (_a = variantProp) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.value) === 'text') {
94
94
  // remove variant prop
95
95
  (_c = nodePath.value.openingElement.attributes) === null || _c === void 0 ? void 0 : _c.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
@@ -106,17 +106,17 @@ export default function transformer(file, api, options) {
106
106
  */
107
107
  root
108
108
  .find(j.JSXElement, findBtnTag.bind(undefined, importMap.DropdownButton))
109
- .forEach(function (nodePath) {
109
+ .forEach(nodePath => {
110
110
  var _a, _b;
111
- var attrs = nodePath.value.openingElement.attributes;
112
- var isPrimary = false;
113
- var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
111
+ const attrs = nodePath.value.openingElement.attributes;
112
+ let isPrimary = false;
113
+ const variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
114
114
  if (variantProp) {
115
115
  isPrimary = ((_a = variantProp.value) === null || _a === void 0 ? void 0 : _a.value) === 'primary';
116
116
  // remove variant prop
117
117
  (_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
118
118
  }
119
- var buttonType = isPrimary ? 'PrimaryButton' : 'SecondaryButton';
119
+ const buttonType = isPrimary ? 'PrimaryButton' : 'SecondaryButton';
120
120
  // Swap to `PrimaryButton` or `SecondaryButton`
121
121
  updateJSXTag(nodePath, buttonType);
122
122
  // Add `icon="caretDownIcon" iconPosition="right"`
@@ -124,7 +124,7 @@ export default function transformer(file, api, options) {
124
124
  nodePath.value.openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('iconPosition'), j.stringLiteral('right')));
125
125
  requiredImportSpecifiers.push(buttonType);
126
126
  // Add `import {caretDownIcon} from '@workday/canvas-system-icons-web'`
127
- var lastImport = root.find(j.ImportDeclaration).at(-1);
127
+ const lastImport = root.find(j.ImportDeclaration).at(-1);
128
128
  if (lastImport) {
129
129
  lastImport.insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('caretDownIcon'))], j.stringLiteral('@workday/canvas-system-icons-web')));
130
130
  }
@@ -133,22 +133,21 @@ export default function transformer(file, api, options) {
133
133
  * Remove old imports: `DropdownButton`, `TextButton`, `OutlineButton`, `HighlightButton`, `Button`.
134
134
  * Add new required imports
135
135
  */
136
- var buttonImports = root.find(j.ImportDeclaration, {
136
+ const buttonImports = root.find(j.ImportDeclaration, {
137
137
  source: { value: '@workday/canvas-kit-react/button' },
138
138
  });
139
139
  if (!buttonImports.length) {
140
140
  // Add new specifiers to a new import
141
- var allImports = root.find(j.ImportDeclaration);
142
- var lastImport = allImports.at(allImports.length);
141
+ const allImports = root.find(j.ImportDeclaration);
142
+ const lastImport = allImports.at(allImports.length);
143
143
  if (lastImport) {
144
- lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(function (specifier) { return j.importSpecifier(j.identifier(specifier)); }), j.stringLiteral('@workday/canvas-kit-react/button')));
144
+ lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(specifier => j.importSpecifier(j.identifier(specifier))), j.stringLiteral('@workday/canvas-kit-react/button')));
145
145
  }
146
146
  }
147
147
  else {
148
- buttonImports.forEach(function (_a) {
149
- var _b;
150
- var node = _a.node;
151
- var specifiersToRemove = [
148
+ buttonImports.forEach(({ node }) => {
149
+ var _a;
150
+ const specifiersToRemove = [
152
151
  'DropdownButton',
153
152
  'TextButton',
154
153
  'OutlineButton',
@@ -158,7 +157,7 @@ export default function transformer(file, api, options) {
158
157
  // Remove old specifiers
159
158
  if (typeof node.source.value === 'string' &&
160
159
  node.source.value === '@workday/canvas-kit-react/button') {
161
- (_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.forEach(function (specifier) {
160
+ (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
162
161
  var _a, _b;
163
162
  if (specifier.type === 'ImportSpecifier' &&
164
163
  specifiersToRemove.includes(specifier.imported.name)) {
@@ -168,9 +167,9 @@ export default function transformer(file, api, options) {
168
167
  });
169
168
  }
170
169
  // Add new specifiers to existing import
171
- requiredImportSpecifiers.forEach(function (specifier) {
170
+ requiredImportSpecifiers.forEach(specifier => {
172
171
  var _a, _b;
173
- if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(function (existing) { return existing.type === 'ImportSpecifier' && existing.imported.name === specifier; }))) {
172
+ if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(existing => existing.type === 'ImportSpecifier' && existing.imported.name === specifier))) {
174
173
  (_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.push(j.importSpecifier(j.identifier(specifier)));
175
174
  }
176
175
  });
@@ -1,6 +1,6 @@
1
1
  import { getImportRenameMap } from './getImportRenameMap';
2
2
  // List of imports that will be removed from an import statement
3
- var importsToRemove = [
3
+ const importsToRemove = [
4
4
  'ButtonVariant',
5
5
  'ButtonIconPosition',
6
6
  'ButtonSize',
@@ -15,7 +15,7 @@ var importsToRemove = [
15
15
  // List of enums used in code that will be translated to string literals
16
16
  // before: <Button variant={ButtonVariant.Primary} />
17
17
  // after: <Button variant={"primary"} />
18
- var enumsToMap = {
18
+ const enumsToMap = {
19
19
  'ButtonVariant.Primary': 'primary',
20
20
  'ButtonVariant.Secondary': 'secondary',
21
21
  'Button.Variant.Primary': 'primary',
@@ -89,7 +89,7 @@ var enumsToMap = {
89
89
  // List of enum types that will be converted to union types of string literals
90
90
  // before: function foo (variant: ButtonVariant) {}
91
91
  // after: function foo (variant: 'primary' | 'secondary') {}
92
- var enumToLiteralUnionMap = {
92
+ const enumToLiteralUnionMap = {
93
93
  ButtonVariant: ['primary', 'secondary'],
94
94
  ButtonIconPosition: ['left', 'right'],
95
95
  ButtonIconSize: ['small', 'medium', 'large'],
@@ -108,63 +108,61 @@ var enumToLiteralUnionMap = {
108
108
  DeprecatedButtonVariant: ['primary', 'secondary', 'delete'],
109
109
  };
110
110
  export default function transformer(file, api, options) {
111
- var j = api.jscodeshift;
112
- var root = j(file.source);
113
- var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
111
+ const j = api.jscodeshift;
112
+ const root = j(file.source);
113
+ const { containsCanvasImports, importMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/button');
114
114
  if (!containsCanvasImports) {
115
115
  return file.source;
116
116
  }
117
117
  // Remove Variant imports
118
118
  root
119
- .find(j.ImportSpecifier, function (node) {
119
+ .find(j.ImportSpecifier, (node) => {
120
120
  return importsToRemove.includes(node.imported.name);
121
121
  })
122
122
  .remove();
123
- var reverseImportMap = Object.keys(importMap).reduce(function (result, key) {
123
+ const reverseImportMap = Object.keys(importMap).reduce((result, key) => {
124
124
  result[importMap[key]] = key;
125
125
  return result;
126
126
  }, {});
127
127
  // The following will replace JSX attributes that match something in `enumsToMap`
128
128
  // Example: variant={Button.Variant.Primary} => variant="primary"
129
- function findEnumReplacement(node, candidates, matched) {
130
- if (candidates === void 0) { candidates = enumsToMap; }
131
- if (matched === void 0) { matched = ''; }
132
- var candidate;
129
+ function findEnumReplacement(node, candidates = enumsToMap, matched = '') {
130
+ let candidate;
133
131
  // eslint-disable-next-line guard-for-in
134
132
  for (candidate in candidates) {
135
133
  // base case
136
134
  if (node.object.type === 'Identifier' &&
137
135
  node.property.type === 'Identifier' &&
138
- reverseImportMap[node.object.name] + "." + node.property.name + matched === candidate) {
136
+ `${reverseImportMap[node.object.name]}.${node.property.name}${matched}` === candidate) {
139
137
  return enumsToMap[candidate];
140
138
  }
141
139
  // We didn't match yet, we'll try splitting the candidate string up into a left and right
142
140
  // portion and try again
143
- var parts = candidate.split('.');
144
- var last = parts.splice(-1, 1).join('');
141
+ const parts = candidate.split('.');
142
+ const last = parts.splice(-1, 1).join('');
145
143
  if (node.property.type === 'Identifier' &&
146
144
  node.property.name === last &&
147
145
  node.object.type === 'MemberExpression') {
148
146
  // we have a partial match
149
- return findEnumReplacement(node.object, enumsToMap, "." + last);
147
+ return findEnumReplacement(node.object, enumsToMap, `.${last}`);
150
148
  }
151
149
  }
152
150
  return null;
153
151
  }
154
152
  root
155
- .find(j.MemberExpression, function (node) {
156
- var matched = findEnumReplacement(node);
153
+ .find(j.MemberExpression, (node) => {
154
+ const matched = findEnumReplacement(node);
157
155
  return matched !== null;
158
156
  })
159
- .replaceWith(function (nodePath) {
160
- var matched = findEnumReplacement(nodePath.value);
157
+ .replaceWith(nodePath => {
158
+ const matched = findEnumReplacement(nodePath.value);
161
159
  return j.literal(matched);
162
160
  });
163
161
  // Rewrite `import { beta_Button as Button } from `@workday/canvas-kit-react/button` to
164
162
  // `import { Button } from '@workday/canvas-kit-react/button'
165
- root.find(j.ImportSpecifier, { imported: { name: 'beta_Button' } }).forEach(function (nodePath) {
163
+ root.find(j.ImportSpecifier, { imported: { name: 'beta_Button' } }).forEach(nodePath => {
166
164
  var _a;
167
- var parent = nodePath.parent.value;
165
+ const parent = nodePath.parent.value;
168
166
  if (parent.source &&
169
167
  typeof parent.source.value === 'string' &&
170
168
  parent.source.value.includes('@workday/canvas-kit-react')) {
@@ -190,7 +188,7 @@ export default function transformer(file, api, options) {
190
188
  */
191
189
  function findTypeRename(node) {
192
190
  if (node.type === 'TSTypeReference' && node.typeName.type === 'Identifier') {
193
- var identifier = void 0;
191
+ let identifier;
194
192
  for (identifier in enumToLiteralUnionMap) {
195
193
  if (node.typeName.name === importMap[identifier]) {
196
194
  return enumToLiteralUnionMap[identifier];
@@ -200,12 +198,12 @@ export default function transformer(file, api, options) {
200
198
  return null;
201
199
  }
202
200
  root
203
- .find(j.TSTypeReference, function (node) { return !!findTypeRename(node); })
204
- .replaceWith(function (nodePath) {
205
- var node = nodePath.value;
206
- var matches = findTypeRename(node);
201
+ .find(j.TSTypeReference, (node) => !!findTypeRename(node))
202
+ .replaceWith(nodePath => {
203
+ const node = nodePath.value;
204
+ const matches = findTypeRename(node);
207
205
  if (matches) {
208
- return j.tsUnionType(matches.map(function (literal) { return j.tsLiteralType({ type: 'StringLiteral', value: literal }); }));
206
+ return j.tsUnionType(matches.map(literal => j.tsLiteralType({ type: 'StringLiteral', value: literal })));
209
207
  }
210
208
  return nodePath.value;
211
209
  });
@@ -1,13 +1,13 @@
1
1
  // List of import paths and the named export
2
2
  // before: import Button from '@workday/canvas-kit-react/button
3
3
  // after: import { Button } from '@workday/canvas-kit-react/button
4
- var renameDefaultMap = {
4
+ const renameDefaultMap = {
5
5
  '@workday/canvas-kit-react/button': 'Button',
6
6
  '@workday/canvas-kit-react/card': 'Card',
7
7
  };
8
8
  export default function transformer(file, api, options) {
9
- var j = api.jscodeshift;
10
- var root = j(file.source);
9
+ const j = api.jscodeshift;
10
+ const root = j(file.source);
11
11
  // Renames default imports from `renameDefaultMap` and changes them to named exports
12
12
  // Example:
13
13
  // before:
@@ -16,11 +16,11 @@ export default function transformer(file, api, options) {
16
16
  // after:
17
17
  // import { Button } from '@workday/canvas-kit-react/button';
18
18
  // import { Button as StyledButton } from '@workday/canvas-kit-react/button';
19
- root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
19
+ root.find(j.ImportDefaultSpecifier).forEach(nodePath => {
20
20
  var _a;
21
- var parent = nodePath.parent;
22
- var importSource = String(parent.node.source.value);
23
- var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
21
+ const parent = nodePath.parent;
22
+ const importSource = String(parent.node.source.value);
23
+ const localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
24
24
  if (Object.keys(renameDefaultMap).includes(importSource) && localName) {
25
25
  nodePath.replace(j.importSpecifier(j.identifier(renameDefaultMap[importSource]), j.identifier(localName)));
26
26
  }
@@ -1,5 +1,5 @@
1
1
  import { getImportRenameMap } from './getImportRenameMap';
2
- var buttonNames = [
2
+ const buttonNames = [
3
3
  'Button',
4
4
  'DeleteButton',
5
5
  'deprecated_Button',
@@ -13,19 +13,19 @@ var buttonNames = [
13
13
  'ToolbarIconButton',
14
14
  ];
15
15
  export default function transformer(file, api, options) {
16
- var j = api.jscodeshift;
17
- var root = j(file.source);
18
- var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
16
+ const j = api.jscodeshift;
17
+ const root = j(file.source);
18
+ const { containsCanvasImports, importMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/button');
19
19
  if (!containsCanvasImports) {
20
20
  return file.source;
21
21
  }
22
22
  root
23
- .find(j.JSXIdentifier, function (value) { return value.name === 'buttonRef'; })
24
- .replaceWith(function (nodePath) {
23
+ .find(j.JSXIdentifier, (value) => value.name === 'buttonRef')
24
+ .replaceWith(nodePath => {
25
25
  var _a, _b, _c, _d;
26
26
  // only replace via one of our Button imports
27
- 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;
28
- if (buttonNames.map(function (n) { return importMap[n]; }).includes(elementName)) {
27
+ const 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;
28
+ if (buttonNames.map(n => importMap[n]).includes(elementName)) {
29
29
  return j.jsxIdentifier('ref');
30
30
  }
31
31
  return nodePath.value;
@@ -1,17 +1,17 @@
1
- var sourceMap = {
1
+ const sourceMap = {
2
2
  '@workday/canvas-kit-react/core': '@workday/canvas-kit-react/tokens',
3
3
  '@workday/canvas-kit-labs-react/core': '@workday/canvas-kit-labs-react/tokens',
4
4
  };
5
5
  // Rename "/core" imports to "/tokens"
6
6
  export default function transformer(file, api) {
7
- var j = api.jscodeshift;
8
- var root = j(file.source);
7
+ const j = api.jscodeshift;
8
+ const root = j(file.source);
9
9
  // transform import {} from "@workday/canvas-kit-react/core"
10
10
  // to import {} from "@workday/canvas-kit-react/tokens"
11
11
  root
12
12
  .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react/core' } })
13
- .forEach(function (nodePath) {
14
- var source = nodePath.value.source.value;
13
+ .forEach(nodePath => {
14
+ const source = nodePath.value.source.value;
15
15
  nodePath.value.source.value = sourceMap[source];
16
16
  return nodePath;
17
17
  });
@@ -19,8 +19,8 @@ export default function transformer(file, api) {
19
19
  // to "@workday/canvas-kit-labs-react/tokens"
20
20
  root
21
21
  .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/core' } })
22
- .forEach(function (nodePath) {
23
- var source = nodePath.value.source.value;
22
+ .forEach(nodePath => {
23
+ const source = nodePath.value.source.value;
24
24
  nodePath.value.source.value = sourceMap[source];
25
25
  return nodePath;
26
26
  });
@@ -28,10 +28,10 @@ export default function transformer(file, api) {
28
28
  // to `import {type} from "@workday/canvas-kit-labs-react/tokens";`
29
29
  root
30
30
  .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/tokens' } })
31
- .forEach(function (nodePath) {
31
+ .forEach(nodePath => {
32
32
  var _a;
33
- var newSpecifiers = [];
34
- (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
33
+ const newSpecifiers = [];
34
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
35
35
  var _a;
36
36
  if (specifier.type === 'ImportDefaultSpecifier' && ((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) === 'type') {
37
37
  return newSpecifiers.push({
@@ -1,5 +1,5 @@
1
1
  import { getImportRenameMap } from './getImportRenameMap';
2
- var inputsMap = {
2
+ const inputsMap = {
3
3
  '@workday/canvas-kit-react/checkbox': ['Checkbox'],
4
4
  '@workday/canvas-kit-react/color-picker': ['ColorInput', 'ColorPreview'],
5
5
  '@workday/canvas-kit-react/radio': ['Radio'],
@@ -8,8 +8,8 @@ var inputsMap = {
8
8
  '@workday/canvas-kit-react/text-input': ['TextInput'],
9
9
  };
10
10
  export default function transformer(file, api, options) {
11
- var j = api.jscodeshift;
12
- var root = j(file.source);
11
+ const j = api.jscodeshift;
12
+ const root = j(file.source);
13
13
  // defaultImports should be an array of local names that were imported using
14
14
  // a default import from any of the modules listed in inputsMap. For example,
15
15
  // given...
@@ -22,26 +22,26 @@ export default function transformer(file, api, options) {
22
22
  // ```
23
23
  //
24
24
  // ... defaultImports should be set to `['Checkbox', 'CanvasTextArea']`
25
- var defaultImports = [];
26
- root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
25
+ const defaultImports = [];
26
+ root.find(j.ImportDefaultSpecifier).forEach(nodePath => {
27
27
  var _a;
28
- var packageName = nodePath.parent.node.source.value;
29
- var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
28
+ const packageName = nodePath.parent.node.source.value;
29
+ const localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
30
30
  if (packageName in inputsMap && localName) {
31
31
  defaultImports.push(localName);
32
32
  }
33
33
  });
34
- var runningSource = file.source;
35
- var _loop_1 = function (inputPackageName) {
36
- var currentRoot = j(runningSource);
37
- var _a = getImportRenameMap(j, currentRoot, inputPackageName), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
34
+ let runningSource = file.source;
35
+ for (const inputPackageName of Object.keys(inputsMap)) {
36
+ const currentRoot = j(runningSource);
37
+ const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, currentRoot, inputPackageName);
38
38
  if (containsCanvasImports) {
39
- var inputNames_1 = inputsMap[inputPackageName];
39
+ const inputNames = inputsMap[inputPackageName];
40
40
  currentRoot
41
- .find(j.JSXIdentifier, function (value) { return value.name === 'inputRef'; })
42
- .replaceWith(function (nodePath) {
41
+ .find(j.JSXIdentifier, (value) => value.name === 'inputRef')
42
+ .replaceWith(nodePath => {
43
43
  var _a, _b, _c, _d;
44
- 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;
44
+ const 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;
45
45
  // Rewrite inputRef to ref if any of the following are true:
46
46
  // (a) elementName was the name used in a default import of the current
47
47
  // input being processed (e.g., `import TextInput ...`)
@@ -51,18 +51,14 @@ export default function transformer(file, api, options) {
51
51
  // (c) elementName was created by calling `styled` on the current input
52
52
  // being processed (e.g., `const StyledTextInput = styled(TextInput)`)
53
53
  if (defaultImports.includes(elementName) ||
54
- inputNames_1.map(function (n) { return importMap[n]; }).includes(elementName) ||
55
- inputNames_1.map(function (n) { return styledMap[n]; }).includes(elementName)) {
54
+ inputNames.map(n => importMap[n]).includes(elementName) ||
55
+ inputNames.map(n => styledMap[n]).includes(elementName)) {
56
56
  return j.jsxIdentifier('ref');
57
57
  }
58
58
  return nodePath.value;
59
59
  });
60
60
  runningSource = currentRoot.toSource();
61
61
  }
62
- };
63
- for (var _i = 0, _a = Object.keys(inputsMap); _i < _a.length; _i++) {
64
- var inputPackageName = _a[_i];
65
- _loop_1(inputPackageName);
66
62
  }
67
63
  return runningSource;
68
64
  }
@@ -1,12 +1,12 @@
1
1
  export default function transformer(file, api) {
2
- var j = api.jscodeshift;
3
- var root = j(file.source);
2
+ const j = api.jscodeshift;
3
+ const root = j(file.source);
4
4
  // find react/tokens package import declarations
5
- var tokenImport = root.find(j.ImportDeclaration, {
5
+ const tokenImport = root.find(j.ImportDeclaration, {
6
6
  source: { value: '@workday/canvas-kit-react/tokens' },
7
7
  });
8
8
  // find react/common package import declarations
9
- var commonImport = root.find(j.ImportDeclaration, {
9
+ const commonImport = root.find(j.ImportDeclaration, {
10
10
  source: { value: '@workday/canvas-kit-react/common' },
11
11
  });
12
12
  function transformTypeImports(nodePath, specifier) {
@@ -15,7 +15,7 @@ export default function transformer(file, api) {
15
15
  // push this specifier into those node specifiers.
16
16
  // This prevents possible duplicate import declarations.
17
17
  if (tokenImport.paths().length) {
18
- tokenImport.forEach(function (tokenImportPath) {
18
+ tokenImport.forEach(tokenImportPath => {
19
19
  var _a;
20
20
  (_a = tokenImportPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.push(specifier);
21
21
  });
@@ -35,7 +35,7 @@ export default function transformer(file, api) {
35
35
  // push this specifier into those node specifiers.
36
36
  // This prevents possible duplicate import declarations.
37
37
  if (commonImport.paths().length) {
38
- commonImport.forEach(function (tokenImportPath) {
38
+ commonImport.forEach(tokenImportPath => {
39
39
  var _a;
40
40
  (_a = tokenImportPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.push(specifier);
41
41
  });
@@ -49,9 +49,9 @@ export default function transformer(file, api) {
49
49
  // Transform labs/tokens imports
50
50
  root
51
51
  .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/tokens' } })
52
- .forEach(function (nodePath) {
52
+ .forEach(nodePath => {
53
53
  var _a;
54
- (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
54
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
55
55
  if (specifier.type === 'ImportSpecifier') {
56
56
  // Update type import node to use tokens package as the source
57
57
  transformTypeImports(nodePath, specifier);
@@ -64,9 +64,9 @@ export default function transformer(file, api) {
64
64
  // Transform preview/tokens imports
65
65
  root
66
66
  .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-preview-react/tokens' } })
67
- .forEach(function (nodePath) {
67
+ .forEach(nodePath => {
68
68
  var _a;
69
- (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
69
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
70
70
  if (specifier.type === 'ImportSpecifier') {
71
71
  // Update type import node to use tokens package as the source
72
72
  transformTypeImports(nodePath, specifier);