@workday/canvas-kit-codemod 7.0.0-alpha.95-next.21 → 7.0.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,SA0EhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,SAyGhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -5,7 +5,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
5
5
  r[k] = a[j];
6
6
  return r;
7
7
  };
8
- import { filterImportSpecifiers, renameImportSpecifiers, renameImports, hasImportSpecifiers, } from './utils';
8
+ import { filterImportSpecifiers, renameImports, hasImportSpecifiers, } from './utils';
9
9
  var mainPackage = '@workday/canvas-kit-labs-react';
10
10
  var headerPackage = '@workday/canvas-kit-labs-react/header';
11
11
  var searchBarRenameImports = ['SearchBar', 'SearchBarProps', 'SearchBarState'];
@@ -27,6 +27,7 @@ var transform = function (file, api) {
27
27
  function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
28
28
  nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
29
29
  }
30
+ var discoveredImportSpecifiers = {};
30
31
  // Rename search-bar named imports from @workday/canvas-kit-labs-react
31
32
  // e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
32
33
  // becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
@@ -35,7 +36,16 @@ var transform = function (file, api) {
35
36
  // Filter search bar imports
36
37
  var searchBarImports = filterImportSpecifiers(importSpecifiers);
37
38
  // Rename search bar imports
38
- renameImportSpecifiers(searchBarImports, renameMap);
39
+ searchBarImports.forEach(function (specifier) {
40
+ var specifierName = specifier.imported.name;
41
+ if (specifierName in renameMap) {
42
+ // if it hasn't been aliased, track it for updating JSX
43
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
44
+ discoveredImportSpecifiers[specifier.imported.name] = true;
45
+ }
46
+ specifier.imported.name = renameMap[specifierName];
47
+ }
48
+ });
39
49
  });
40
50
  // Handle imports from @workday/canvas-kit-react/header
41
51
  // e.g import { Header, SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react/header';
@@ -62,8 +72,17 @@ var transform = function (file, api) {
62
72
  root.find(j.ImportDeclaration, { source: { value: headerPackage } }).remove();
63
73
  // If SearchBar import specifiers were found, insert a new import declaration above the original import declaration
64
74
  if (searchBarSpecifiers.length) {
65
- var renamedSearchBarSpecifiers = renameImportSpecifiers(searchBarSpecifiers, renameMap);
66
- insertImportDeclarationBefore(nodePath, renamedSearchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
75
+ searchBarSpecifiers.forEach(function (specifier) {
76
+ var specifierName = specifier.imported.name;
77
+ if (specifierName in renameMap) {
78
+ // if it hasn't been aliased, track it for updating JSX
79
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
80
+ discoveredImportSpecifiers[specifier.imported.name] = true;
81
+ }
82
+ specifier.imported.name = renameMap[specifierName];
83
+ }
84
+ });
85
+ insertImportDeclarationBefore(nodePath, searchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
67
86
  }
68
87
  // If other header import specifiers were found, insert a new import declaration above the original import declaration
69
88
  // This will replace the import declaration that was removed above
@@ -71,6 +90,6 @@ var transform = function (file, api) {
71
90
  insertImportDeclarationBefore(nodePath, headerSpecifiers, headerPackage);
72
91
  }
73
92
  });
74
- return renameImports(api, root, '@workday/canvas-kit-labs-react/header', renameMap).toSource();
93
+ return renameImports(api, root, '@workday/canvas-kit-labs-react/search-form', renameMap, discoveredImportSpecifiers).toSource();
75
94
  };
76
95
  export default transform;
@@ -16,17 +16,6 @@ export declare function filterImportSpecifiers(importSpecifiers: ImportSpecifier
16
16
  export declare type RenameMap = {
17
17
  [key: string]: string;
18
18
  };
19
- /**
20
- * Renames import specifiers for a given rename map
21
- * @example
22
- * const renameMap = {
23
- * 'PageHeader': 'DeprecatedPageHeader',
24
- * 'PageHeaderProps': 'DeprecatedPageHeaderProps',
25
- * };
26
- * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
27
- * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
28
- */
29
- export declare function renameImportSpecifiers(importSpecifiers: ImportSpecifier[], renameMap: RenameMap): ImportSpecifier[];
30
19
  /**
31
20
  * Returns a filtered array of ImportDefaultSpecifiers
32
21
  * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
@@ -66,5 +55,5 @@ export declare function renameImportDefaultSpecifiers(importSpecifiers: ImportDe
66
55
  * }
67
56
  */
68
57
  export declare function hasImportSpecifiers(api: API, root: Collection<any>, packageName: string | string[], specifiers: string[]): boolean;
69
- export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>): Collection<any>;
58
+ export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>, discoveredImportSpecifiers?: Record<string, boolean>): Collection<any>;
70
59
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,EACJ,MAAM,aAAa,CAAC;AAErB,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,gBAAgB,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,SAAS,qBAQ/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,4BAevB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,sBAAsB,EAAE,EAC1C,SAAS,EAAE,SAAS,4BASrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,UAAU,CAAC,GAAG,CAAC,CAsFjB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,EACJ,MAAM,aAAa,CAAC;AAErB,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,4BAevB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,sBAAsB,EAAE,EAC1C,SAAS,EAAE,SAAS,4BASrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,0BAA0B,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvD,UAAU,CAAC,GAAG,CAAC,CA+GjB"}
@@ -24,25 +24,6 @@ export function filterImportSpecifiers(importSpecifiers, importNames) {
24
24
  });
25
25
  return filteredSpecifiers;
26
26
  }
27
- /**
28
- * Renames import specifiers for a given rename map
29
- * @example
30
- * const renameMap = {
31
- * 'PageHeader': 'DeprecatedPageHeader',
32
- * 'PageHeaderProps': 'DeprecatedPageHeaderProps',
33
- * };
34
- * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
35
- * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
36
- */
37
- export function renameImportSpecifiers(importSpecifiers, renameMap) {
38
- importSpecifiers.forEach(function (specifier) {
39
- var specifierName = specifier.imported.name;
40
- if (specifierName in renameMap) {
41
- specifier.imported.name = renameMap[specifierName];
42
- }
43
- });
44
- return importSpecifiers;
45
- }
46
27
  /**
47
28
  * Returns a filtered array of ImportDefaultSpecifiers
48
29
  * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
@@ -134,7 +115,8 @@ export function hasImportSpecifiers(api, root, packageName, specifiers) {
134
115
  return false;
135
116
  });
136
117
  }
137
- export function renameImports(api, root, packageName, specifierMap) {
118
+ export function renameImports(api, root, packageName, specifierMap, discoveredImportSpecifiers) {
119
+ if (discoveredImportSpecifiers === void 0) { discoveredImportSpecifiers = {}; }
138
120
  var j = api.jscodeshift;
139
121
  if (!hasImportSpecifiers(api, root, packageName, Object.keys(specifierMap))) {
140
122
  return root;
@@ -146,27 +128,41 @@ export function renameImports(api, root, packageName, specifierMap) {
146
128
  // Transform import statements
147
129
  // e.g. import { CookieBanner, CookieBannerProps } from '@workday/canvas-kit-react';
148
130
  // becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
131
+ // Find imports from main packages
132
+ // ex. '@workday/canvas-kit-labs-react'
149
133
  root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
150
134
  var _a;
151
135
  (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
152
136
  if (specifier.type === 'ImportSpecifier') {
153
137
  if (Object.keys(specifierMap).includes(specifier.imported.name)) {
138
+ // if it hasn't been aliased, track it for updating JSX
139
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
140
+ discoveredImportSpecifiers[specifier.imported.name] = true;
141
+ }
154
142
  specifier.imported.name = specifierMap[specifier.imported.name];
155
143
  }
156
144
  }
157
145
  });
158
146
  });
159
- // Transforms default imports from package
147
+ // Find imports from component specific packages
148
+ // ex. '@workday/canvas-kit-labs-react/header'
160
149
  root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(function (nodePath) {
161
150
  var _a;
162
151
  (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
152
+ // Transforms default imports
163
153
  if (specifier.type === 'ImportDefaultSpecifier') {
164
154
  if (specifier.local && Object.keys(specifierMap).includes(specifier.local.name)) {
155
+ discoveredImportSpecifiers[specifier.local.name] = true;
165
156
  specifier.local.name = specifierMap[specifier.local.name];
166
157
  }
167
158
  }
159
+ // Transform named exports
168
160
  if (specifier.type === 'ImportSpecifier') {
169
161
  if (Object.keys(specifierMap).includes(specifier.imported.name)) {
162
+ // if it hasn't been aliased, track it for updating JSX
163
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
164
+ discoveredImportSpecifiers[specifier.imported.name] = true;
165
+ }
170
166
  specifier.imported.name = specifierMap[specifier.imported.name];
171
167
  }
172
168
  }
@@ -195,7 +191,10 @@ export function renameImports(api, root, packageName, specifierMap) {
195
191
  // Transform JSXElements
196
192
  // e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
197
193
  root.find(j.JSXIdentifier).forEach(function (nodePath) {
198
- if (Object.keys(specifierMap).includes(nodePath.value.name)) {
194
+ if (
195
+ // Check to see if it was imported from Canvas Kit
196
+ discoveredImportSpecifiers[nodePath.value.name] &&
197
+ Object.keys(specifierMap).includes(nodePath.value.name)) {
199
198
  nodePath.node.name = specifierMap[nodePath.value.name];
200
199
  }
201
200
  });
@@ -203,6 +202,8 @@ export function renameImports(api, root, packageName, specifierMap) {
203
202
  // e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
204
203
  root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(function (nodePath) {
205
204
  if (nodePath.value.object.type === 'Identifier' &&
205
+ // Check to see if it was imported from Canvas Kit
206
+ discoveredImportSpecifiers[nodePath.value.object.name] &&
206
207
  Object.keys(specifierMap).includes(nodePath.value.object.name)) {
207
208
  nodePath.value.object.name = specifierMap[nodePath.value.object.name];
208
209
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmD7E"}
1
+ {"version":3,"file":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0H7E"}
@@ -1,3 +1,10 @@
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
+ };
1
8
  import { getImportRenameMap } from './utils/getImportRenameMap';
2
9
  import { hasImportSpecifiers } from '../v6/utils';
3
10
  var actionBarPackage = '@workday/canvas-kit-react/action-bar';
@@ -18,7 +25,6 @@ export default function transformer(file, api, options) {
18
25
  }
19
26
  });
20
27
  var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/action-bar'), importMap = _a.importMap, styledMap = _a.styledMap;
21
- // Remove fixed prop from ActionBar component
22
28
  root
23
29
  .find(j.JSXElement, function (value) {
24
30
  return value.openingElement.name.type === 'JSXIdentifier' &&
@@ -26,17 +32,60 @@ export default function transformer(file, api, options) {
26
32
  value.openingElement.name.name === styledMap.ActionBar);
27
33
  })
28
34
  .forEach(function (nodePath) {
35
+ (nodePath.value.children || []).forEach(function (child, index) {
36
+ if (child.type === 'JSXElement') {
37
+ // bail early if we find a `ActionBar.List` as a child
38
+ if (child.openingElement.name.type === 'JSXMemberExpression' &&
39
+ child.openingElement.name.object.type === 'JSXIdentifier' &&
40
+ child.openingElement.name.object.name === 'ActionBar' &&
41
+ child.openingElement.name.property.type === 'JSXIdentifier' &&
42
+ child.openingElement.name.property.name === 'List') {
43
+ return;
44
+ }
45
+ // Transform Primary and Secondary button to ActionBar.Item
46
+ if (child.openingElement.name.type === 'JSXIdentifier') {
47
+ var buttonAttrs = child.openingElement.attributes || [];
48
+ var ActionItemJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('Item'));
49
+ if (nodePath.value.children &&
50
+ ['PrimaryButton', 'SecondaryButton'].includes(child.openingElement.name.name)) {
51
+ // Add isPrimary attribute to primary Action Item
52
+ var elementAttrs = child.openingElement.name.name === 'PrimaryButton'
53
+ ? __spreadArrays(buttonAttrs, [j.jsxAttribute(j.jsxIdentifier('isPrimary'))]) : buttonAttrs;
54
+ nodePath.value.children[index] = j.jsxElement(j.jsxOpeningElement(ActionItemJSX, elementAttrs), j.jsxClosingElement(ActionItemJSX), child.children);
55
+ }
56
+ }
57
+ }
58
+ });
59
+ var children = nodePath.value.children || [];
60
+ // Remove all attributes from ActionBar to replace them to ActionBar.List
29
61
  var attributes = nodePath.value.openingElement.attributes;
30
62
  if (attributes) {
31
- // remove these attributes from ActionBar
32
- nodePath.value.openingElement.attributes = attributes.filter(function (item) {
33
- return item.type === 'JSXAttribute' &&
34
- item.name.type === 'JSXIdentifier' &&
35
- ['fixed'].includes(item.name.name)
36
- ? false
37
- : true;
38
- });
63
+ nodePath.value.openingElement.attributes = attributes.filter(function (item) { return !(item.type === 'JSXAttribute' && item.name.type === 'JSXIdentifier'); });
39
64
  }
65
+ // Create closing element for ActionBar without closing tag
66
+ if (nodePath.value.openingElement.selfClosing) {
67
+ nodePath.value.openingElement.selfClosing = false;
68
+ nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
69
+ }
70
+ // Create ActionBar.List component
71
+ var ActionBarListJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('List'));
72
+ var subComponentJSX = j.jsxElement(j.jsxOpeningElement(ActionBarListJSX,
73
+ // All attributes except fixed should be passed
74
+ attributes === null ||
75
+ // All attributes except fixed should be passed
76
+ attributes === void 0 ? void 0 :
77
+ // All attributes except fixed should be passed
78
+ attributes.filter(function (attr) { return !(attr.type === 'JSXAttribute' && attr.name.name === 'fixed'); })), j.jsxClosingElement(ActionBarListJSX), children);
79
+ // Keep space for code structure
80
+ var textLiteralStart = children.find(function (child) { return child.type === 'JSXText'; });
81
+ var textLiteralEnd = children
82
+ .slice()
83
+ .reverse()
84
+ .find(function (child) { return child.type === 'JSXText'; });
85
+ nodePath.value.children =
86
+ textLiteralStart && textLiteralEnd
87
+ ? [textLiteralStart, subComponentJSX, textLiteralEnd]
88
+ : [subComponentJSX];
40
89
  });
41
90
  return root.toSource();
42
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAatC,QAAA,MAAM,SAAS,EAAE,SAgBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AActC,QAAA,MAAM,SAAS,EAAE,SAiBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
@@ -19,6 +19,7 @@ import renameIconPosition from './renameIconPosition';
19
19
  import recategorizeIconButtons from './recategorizeIconButtons';
20
20
  import updateModelSignatures from './updateModelSignatures';
21
21
  import updateTabs from './updateTabs';
22
+ import updateDisclosureShowHide from './updateDisclosureShowHide';
22
23
  var transform = function (file, api, options) {
23
24
  // These will run in order. If your transform depends on others, place yours after dependent transforms
24
25
  var fixes = [
@@ -32,6 +33,7 @@ var transform = function (file, api, options) {
32
33
  updateSegmentedControl,
33
34
  updateModelSignatures,
34
35
  updateTabs,
36
+ updateDisclosureShowHide,
35
37
  ];
36
38
  return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
37
39
  };
@@ -1 +1 @@
1
- {"version":3,"file":"recategorizeIconButtons.d.ts","sourceRoot":"","sources":["../../../lib/v7/recategorizeIconButtons.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAMR,MAAM,aAAa,CAAC;AAcrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiK7E"}
1
+ {"version":3,"file":"recategorizeIconButtons.d.ts","sourceRoot":"","sources":["../../../lib/v7/recategorizeIconButtons.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAMR,MAAM,aAAa,CAAC;AAcrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAoK7E"}
@@ -96,7 +96,11 @@ export default function transformer(file, api, options) {
96
96
  * Add new required imports
97
97
  */
98
98
  var buttonImports = root.find(j.ImportDeclaration, {
99
- source: { value: function (value) { return value.includes('@workday/canvas-kit-react'); } },
99
+ source: {
100
+ value: function (value) {
101
+ return value === '@workday/canvas-kit-react' || value === '@workday/canvas-kit-react/button';
102
+ },
103
+ },
100
104
  });
101
105
  if (!buttonImports.length) {
102
106
  // Add new specifiers to a new import
@@ -1 +1 @@
1
- {"version":3,"file":"renameLayoutImports.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameLayoutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAelE,QAAA,MAAM,SAAS,EAAE,SAuFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"renameLayoutImports.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameLayoutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAoDlE,QAAA,MAAM,SAAS,EAAE,SAyEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -6,6 +6,42 @@ var commonSpecifiers = [
6
6
  'useThemeRTL',
7
7
  'useThemedRing',
8
8
  ];
9
+ var layoutSpecifiers = [
10
+ 'Flex',
11
+ 'Stack',
12
+ 'StackProps',
13
+ 'HStackProps',
14
+ 'VStack',
15
+ 'VStackProps',
16
+ 'HStack',
17
+ 'Box',
18
+ 'BoxProps',
19
+ 'FlexProps',
20
+ 'ColorStyleProps',
21
+ 'StackSpacing',
22
+ 'StackDirection',
23
+ 'StackStyleProps',
24
+ 'FlexStyleProps',
25
+ 'SpaceStyleProps',
26
+ 'DepthStyleProps',
27
+ 'BorderShorthandStyleProps',
28
+ 'BorderColorStyleProps',
29
+ 'BorderRadiusStyleProps',
30
+ 'BorderLineStyleProps',
31
+ 'BorderWidthStyleProps',
32
+ 'BorderLogicalStyleProps',
33
+ 'BorderStyleProps',
34
+ 'border',
35
+ 'ColorTokens',
36
+ 'ColorStyleProps',
37
+ 'color',
38
+ 'FlexItemStyleProps',
39
+ 'flexItem',
40
+ 'PositionStandardProps',
41
+ 'PositionLogicalProps',
42
+ 'PositionStyleProps',
43
+ 'position',
44
+ ];
9
45
  // 1. Gather all import specifiers from @workday/canvas-kit-labs-react/layout
10
46
  // 2. Filter through all imports from @workday/canvas-kit-labs-react/common and gather specifiers we care about
11
47
  // 3. If there's an existing @workday/canvas-kit-react/layout add gathered specifiers to that import
@@ -15,39 +51,24 @@ var transform = function (file, api) {
15
51
  var root = j(file.source);
16
52
  var reactLayoutSpecifiers = [];
17
53
  var foundImport = [];
18
- // for each specifier in @workday/canvas-kit-labs-react/layout it pushes
19
- // the specifier to reactLayoutSpecifiers
20
- // We also push the found import to foundImport
21
- root
22
- .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/layout' } })
23
- .forEach(function (nodePath) {
24
- var _a;
25
- (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
26
- var _a, _b;
27
- if (specifier.type === 'ImportSpecifier') {
28
- reactLayoutSpecifiers.push({
29
- importedName: (_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name,
30
- name: (_b = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _b === void 0 ? void 0 : _b.name,
31
- });
32
- }
33
- });
34
- foundImport.push(nodePath);
35
- });
36
- // We filter through @workday/canvas-kit-labs-react/common specifiers and
37
- // if it includes specifiers that we want, we push those to reactLayoutSpecifiers
38
54
  root
39
- .find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/common' } })
55
+ .find(j.ImportDeclaration, {
56
+ source: { value: function (value) { return value.includes('@workday/canvas-kit-labs-react'); } },
57
+ })
40
58
  .forEach(function (nodePath) {
41
59
  var _a;
42
60
  nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
43
- var _a, _b;
61
+ var _a, _b, _c, _d;
44
62
  if (specifier.type === 'ImportSpecifier' &&
45
63
  !commonSpecifiers.includes(specifier.imported.name)) {
46
- reactLayoutSpecifiers.push({
47
- importedName: (_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name,
48
- name: (_b = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _b === void 0 ? void 0 : _b.name,
49
- });
50
- return false;
64
+ if (((_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name) !== undefined &&
65
+ layoutSpecifiers.includes((_b = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _b === void 0 ? void 0 : _b.name)) {
66
+ reactLayoutSpecifiers.push({
67
+ importedName: (_c = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _c === void 0 ? void 0 : _c.name,
68
+ name: (_d = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _d === void 0 ? void 0 : _d.name,
69
+ });
70
+ return false;
71
+ }
51
72
  }
52
73
  return true;
53
74
  });
@@ -74,7 +95,6 @@ var transform = function (file, api) {
74
95
  }
75
96
  foundImport.forEach(function (importPath) {
76
97
  var _a;
77
- // remove imports we no longer need
78
98
  if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
79
99
  importPath.value.source.value === '@workday/canvas-kit-labs-react/layout') {
80
100
  importPath.prune();
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=updateDisclosureShowHide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateDisclosureShowHide.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateDisclosureShowHide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiH7E"}
@@ -0,0 +1,96 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ var keys = function (input) { return Object.keys(input); };
3
+ export default function transformer(file, api, options) {
4
+ var j = api.jscodeshift;
5
+ var root = j(file.source);
6
+ var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
7
+ if (!containsCanvasImports) {
8
+ return file.source;
9
+ }
10
+ var disclosureModels = [
11
+ 'useDisclosureModel',
12
+ 'usePopupModel',
13
+ 'useModalModel',
14
+ 'useDialogModel',
15
+ ];
16
+ // inverse the import map. It is more useful this way for this function
17
+ var imports = Object.keys(importMap).reduce(function (result, key) {
18
+ result[importMap[key]] = key;
19
+ return result;
20
+ }, {});
21
+ root.find(j.CallExpression).forEach(function (nodePath) {
22
+ var value = nodePath.value;
23
+ // check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
24
+ if (value.callee.type === 'Identifier' &&
25
+ disclosureModels.includes(imports[value.callee.name])) {
26
+ // loop over all the arguments of the `use{*}Model` hook
27
+ value.arguments.forEach(function (argument) {
28
+ // look for object expressions: `use{*}Model({ /* here */ })`
29
+ if (argument.type === 'ObjectExpression') {
30
+ // loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
31
+ // the value is a function matching `on{*}` or `should{*}` naming convention
32
+ argument.properties.forEach(function (property) {
33
+ // If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
34
+ // {
35
+ // onShow() {}, // ObjectMethod
36
+ // onHide: () => {}, ObjectProperty with arrow function expression
37
+ // }
38
+ if ((property.type === 'ObjectMethod' ||
39
+ (property.type === 'ObjectProperty' &&
40
+ property.value.type === 'ArrowFunctionExpression')) &&
41
+ property.key.type === 'Identifier') {
42
+ var propertyName_1 = property.key.name;
43
+ // Both types have a `params`, but are at different places in the AST
44
+ var params_1 = property.type === 'ObjectMethod'
45
+ ? property.params
46
+ : property.value.type === 'ArrowFunctionExpression'
47
+ ? property.value.params
48
+ : [];
49
+ // create a mapping for param names of callbacks and guards. This makes the logic more
50
+ // difficult to follow, but decreases duplication
51
+ var paramMapping_1 = {
52
+ on: ['event'],
53
+ should: ['event'],
54
+ };
55
+ // We will be overriding the params with this variable later
56
+ var finalParams_1 = [];
57
+ // loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
58
+ keys(paramMapping_1).forEach(function (key) {
59
+ // matches `onShow` and `shouldShow`
60
+ if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
61
+ params_1.forEach(function (param) {
62
+ if (param.type === 'ObjectPattern') {
63
+ param.properties.forEach(function (property) {
64
+ if (property.type === 'ObjectProperty' &&
65
+ property.key.type === 'Identifier') {
66
+ if (property.value.type === 'Identifier' ||
67
+ property.value.type === 'ObjectPattern') {
68
+ var index = paramMapping_1[key].indexOf(property.key.name);
69
+ // use `property.value` instead of `property.key.name` in case they
70
+ // renamed it example `shouldShow({ data: myData })`. The key name is
71
+ // `data` while the value is `myData`
72
+ finalParams_1[index] = property.value;
73
+ }
74
+ }
75
+ });
76
+ }
77
+ });
78
+ // `ObjectMethod` and `ObjectProperty` have params in a different place in the
79
+ // AST, so apply `finalParams` where appropriate
80
+ if (property.type === 'ObjectMethod') {
81
+ property.params = finalParams_1;
82
+ }
83
+ else if (property.type === 'ObjectProperty' &&
84
+ property.value.type === 'ArrowFunctionExpression') {
85
+ property.value.params = finalParams_1;
86
+ }
87
+ }
88
+ });
89
+ }
90
+ });
91
+ }
92
+ });
93
+ }
94
+ });
95
+ return root.toSource();
96
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,SAAK;;;;EAyDzF"}
1
+ {"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,SAAK;;;;EA2DzF"}
@@ -9,7 +9,9 @@ export function getImportRenameMap(j, root, packageName) {
9
9
  // imports our module
10
10
  var value = node.source.value;
11
11
  if (typeof value === 'string' &&
12
- (value.startsWith('@workday/canvas-kit-react') || value === packageName)) {
12
+ (value === '@workday/canvas-kit-react' ||
13
+ value.startsWith('@workday/canvas-kit-react/') ||
14
+ value === packageName)) {
13
15
  containsCanvasImports = true;
14
16
  (node.specifiers || []).forEach(function (specifier) {
15
17
  if (specifier.type === 'ImportSpecifier') {
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": "7.0.0-alpha.95-next.21+da657912",
5
+ "version": "7.0.0",
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,
@@ -42,5 +42,5 @@
42
42
  "test": "TZ=UTC jest -c ../../jest.config.js",
43
43
  "typecheck:src": "tsc -p . --noEmit --incremental false"
44
44
  },
45
- "gitHead": "da657912adb9b86971737b33838e6f8f22d3264a"
45
+ "gitHead": "5f2a5c83ce927fa64ac24447f5391e467f51a406"
46
46
  }