@workday/canvas-kit-codemod 6.9.0-next.0 → 6.9.0-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 (50) hide show
  1. package/dist/es6/v5/recategorizeButtons.js +1 -1
  2. package/dist/es6/v6/moveAndRenameSearchBar.d.ts.map +1 -1
  3. package/dist/es6/v6/moveAndRenameSearchBar.js +24 -5
  4. package/dist/es6/v6/utils/index.d.ts +1 -12
  5. package/dist/es6/v6/utils/index.d.ts.map +1 -1
  6. package/dist/es6/v6/utils/index.js +23 -22
  7. package/dist/es6/v7/compoundActionBar.d.ts +3 -0
  8. package/dist/es6/v7/compoundActionBar.d.ts.map +1 -0
  9. package/dist/es6/v7/compoundActionBar.js +91 -0
  10. package/dist/es6/v7/compoundBanner.d.ts +3 -0
  11. package/dist/es6/v7/compoundBanner.d.ts.map +1 -0
  12. package/dist/es6/v7/compoundBanner.js +133 -0
  13. package/dist/es6/v7/index.d.ts +4 -0
  14. package/dist/es6/v7/index.d.ts.map +1 -0
  15. package/dist/es6/v7/index.js +40 -0
  16. package/dist/es6/v7/recategorizeIconButtons.d.ts +3 -0
  17. package/dist/es6/v7/recategorizeIconButtons.d.ts.map +1 -0
  18. package/dist/es6/v7/recategorizeIconButtons.js +148 -0
  19. package/dist/es6/v7/removePropFromPopper.d.ts +3 -0
  20. package/dist/es6/v7/removePropFromPopper.d.ts.map +1 -0
  21. package/dist/es6/v7/removePropFromPopper.js +31 -0
  22. package/dist/es6/v7/renameIconPosition.d.ts +3 -0
  23. package/dist/es6/v7/renameIconPosition.d.ts.map +1 -0
  24. package/dist/es6/v7/renameIconPosition.js +37 -0
  25. package/dist/es6/v7/renameIconRef.d.ts +3 -0
  26. package/dist/es6/v7/renameIconRef.d.ts.map +1 -0
  27. package/dist/es6/v7/renameIconRef.js +70 -0
  28. package/dist/es6/v7/renameLayoutImports.d.ts +4 -0
  29. package/dist/es6/v7/renameLayoutImports.d.ts.map +1 -0
  30. package/dist/es6/v7/renameLayoutImports.js +105 -0
  31. package/dist/es6/v7/updateDisclosureShowHide.d.ts +3 -0
  32. package/dist/es6/v7/updateDisclosureShowHide.d.ts.map +1 -0
  33. package/dist/es6/v7/updateDisclosureShowHide.js +96 -0
  34. package/dist/es6/v7/updateModelSignatures.d.ts +3 -0
  35. package/dist/es6/v7/updateModelSignatures.d.ts.map +1 -0
  36. package/dist/es6/v7/updateModelSignatures.js +90 -0
  37. package/dist/es6/v7/updateSegmentedControl.d.ts +3 -0
  38. package/dist/es6/v7/updateSegmentedControl.d.ts.map +1 -0
  39. package/dist/es6/v7/updateSegmentedControl.js +24 -0
  40. package/dist/es6/v7/updateTabs.d.ts +3 -0
  41. package/dist/es6/v7/updateTabs.d.ts.map +1 -0
  42. package/dist/es6/v7/updateTabs.js +48 -0
  43. package/dist/es6/v7/utils/getImportRenameMap.d.ts +7 -0
  44. package/dist/es6/v7/utils/getImportRenameMap.d.ts.map +1 -0
  45. package/dist/es6/v7/utils/getImportRenameMap.js +52 -0
  46. package/dist/es6/v7/utils/hasImportSpecifiers.d.ts +20 -0
  47. package/dist/es6/v7/utils/hasImportSpecifiers.d.ts.map +1 -0
  48. package/dist/es6/v7/utils/hasImportSpecifiers.js +46 -0
  49. package/index.js +7 -0
  50. package/package.json +4 -3
@@ -0,0 +1,24 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ export default function transformer(file, api, options) {
3
+ var j = api.jscodeshift;
4
+ var root = j(file.source);
5
+ var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/segmented-control'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
6
+ if (!containsCanvasImports) {
7
+ return file.source;
8
+ }
9
+ root
10
+ .find(j.JSXElement, function (value) {
11
+ return value.openingElement.name.type === 'JSXIdentifier' &&
12
+ (value.openingElement.name.name === importMap.SegmentedControl ||
13
+ value.openingElement.name.name === styledMap.SegmentedControl);
14
+ })
15
+ .forEach(function (nodePath) {
16
+ for (var _i = 0, _a = nodePath.value.children || []; _i < _a.length; _i++) {
17
+ var child = _a[_i];
18
+ if (child.type === 'JSXElement' && child.openingElement.name.type === 'JSXIdentifier') {
19
+ child.openingElement.name.name = 'SegmentedControl.Button';
20
+ }
21
+ }
22
+ });
23
+ return root.toSource();
24
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=updateTabs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateTabs.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateTabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAGnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuD7E"}
@@ -0,0 +1,48 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ export default function transformer(file, api, options) {
3
+ var j = api.jscodeshift;
4
+ var root = j(file.source);
5
+ var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
6
+ if (!containsCanvasImports) {
7
+ return file.source;
8
+ }
9
+ root
10
+ // Find <Tabs
11
+ .find(j.JSXOpeningElement, { name: { object: { name: importMap.Tabs } } })
12
+ // Filter for <Tabs.Item and <Tabs.Panel
13
+ .filter(function (path) {
14
+ return (path.value.name.type === 'JSXMemberExpression' &&
15
+ (path.value.name.property.name === 'Item' || path.value.name.property.name === 'Panel'));
16
+ })
17
+ .forEach(function (nodePath) {
18
+ var _a;
19
+ nodePath.value.attributes = (_a = nodePath.value.attributes) === null || _a === void 0 ? void 0 : _a.map(function (attribute) {
20
+ if (attribute.type === 'JSXAttribute' &&
21
+ attribute.name.type === 'JSXIdentifier' &&
22
+ attribute.name.name === 'name') {
23
+ attribute.name.name = 'data-id';
24
+ }
25
+ return attribute;
26
+ });
27
+ });
28
+ root
29
+ // find <Tabs.Menu.Item
30
+ .find(j.JSXOpeningElement, {
31
+ name: {
32
+ object: { object: { name: importMap.Tabs }, property: { name: 'Menu' } },
33
+ property: { name: 'Item' },
34
+ },
35
+ })
36
+ .forEach(function (nodePath) {
37
+ var _a;
38
+ nodePath.value.attributes = (_a = nodePath.value.attributes) === null || _a === void 0 ? void 0 : _a.map(function (attribute) {
39
+ if (attribute.type === 'JSXAttribute' &&
40
+ attribute.name.type === 'JSXIdentifier' &&
41
+ attribute.name.name === 'name') {
42
+ attribute.name.name = 'data-id';
43
+ }
44
+ return attribute;
45
+ });
46
+ });
47
+ return root.toSource();
48
+ }
@@ -0,0 +1,7 @@
1
+ import { Collection, JSCodeshift } from 'jscodeshift';
2
+ export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, packageName?: string): {
3
+ containsCanvasImports: boolean;
4
+ importMap: Record<string, string>;
5
+ styledMap: Record<string, string>;
6
+ };
7
+ //# sourceMappingURL=getImportRenameMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,SAAK;;;;EA2DzF"}
@@ -0,0 +1,52 @@
1
+ export function getImportRenameMap(j, root, packageName) {
2
+ if (packageName === void 0) { packageName = ''; }
3
+ var containsCanvasImports = false;
4
+ // build import name remapping - in case someone renamed imports...
5
+ // i.e. `import { IconButton as StyledIconButton } ...`
6
+ var importMap = {};
7
+ var styledMap = {};
8
+ root.find(j.ImportDeclaration, function (node) {
9
+ // imports our module
10
+ var value = node.source.value;
11
+ if (typeof value === 'string' &&
12
+ (value === '@workday/canvas-kit-react' ||
13
+ value.startsWith('@workday/canvas-kit-react/') ||
14
+ value === packageName)) {
15
+ containsCanvasImports = true;
16
+ (node.specifiers || []).forEach(function (specifier) {
17
+ if (specifier.type === 'ImportSpecifier') {
18
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
19
+ importMap[specifier.imported.name] = specifier.imported.name;
20
+ }
21
+ else {
22
+ importMap[specifier.imported.name] = specifier.local.name;
23
+ }
24
+ }
25
+ });
26
+ }
27
+ return false;
28
+ });
29
+ root
30
+ .find(j.CallExpression, function (node) {
31
+ if (node.callee.type === 'Identifier' &&
32
+ node.callee.name === 'styled' &&
33
+ node.arguments[0].type === 'Identifier') {
34
+ return true;
35
+ }
36
+ return false;
37
+ })
38
+ .forEach(function (nodePath) {
39
+ // const StyledName = styled(OriginalName)({})
40
+ // const StyledName = styled(OriginalName)`` // Tagged template
41
+ if ((nodePath.parent.value.type === 'CallExpression' ||
42
+ nodePath.parent.value.type === 'TaggedTemplateExpression') &&
43
+ nodePath.parent.parent.value.type === 'VariableDeclarator' &&
44
+ nodePath.parent.parent.value.id.type === 'Identifier') {
45
+ var styledName = nodePath.parent.parent.value.id.name;
46
+ if (nodePath.value.arguments[0].type === 'Identifier') {
47
+ styledMap[nodePath.value.arguments[0].name] = styledName;
48
+ }
49
+ }
50
+ });
51
+ return { containsCanvasImports: containsCanvasImports, importMap: importMap, styledMap: styledMap };
52
+ }
@@ -0,0 +1,20 @@
1
+ import { Collection, API } from 'jscodeshift';
2
+ /**
3
+ * Search for import statements for a package and specific import specifiers. This
4
+ * is useful for codemods to skip files that don't contain import specifiers that
5
+ * require codemoding.
6
+ *
7
+ * @example
8
+ * const hasImports = hasImportSpecifiers(
9
+ * api,
10
+ * root,
11
+ * '@workday/canvas-kit-react/cookie-banner',
12
+ * ['CookieBanner', 'CookieBannerProps']
13
+ * )
14
+ *
15
+ * if (!hasImports) {
16
+ * return file.source
17
+ * }
18
+ */
19
+ export declare function hasImportSpecifiers(api: API, root: Collection<any>, packageName: string | string[], specifiers: string[]): boolean;
20
+ //# sourceMappingURL=hasImportSpecifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasImportSpecifiers.d.ts","sourceRoot":"","sources":["../../../../lib/v7/utils/hasImportSpecifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,GAAG,EAAC,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Search for import statements for a package and specific import specifiers. This
3
+ * is useful for codemods to skip files that don't contain import specifiers that
4
+ * require codemoding.
5
+ *
6
+ * @example
7
+ * const hasImports = hasImportSpecifiers(
8
+ * api,
9
+ * root,
10
+ * '@workday/canvas-kit-react/cookie-banner',
11
+ * ['CookieBanner', 'CookieBannerProps']
12
+ * )
13
+ *
14
+ * if (!hasImports) {
15
+ * return file.source
16
+ * }
17
+ */
18
+ export function hasImportSpecifiers(api, root, packageName, specifiers) {
19
+ var j = api.jscodeshift;
20
+ return !!root.find(j.ImportDeclaration, function (nodePath) {
21
+ var value = nodePath.source.value;
22
+ // package name was found
23
+ if (typeof packageName === 'string'
24
+ ? value === packageName
25
+ : packageName.includes(value)) {
26
+ return true;
27
+ }
28
+ // Extract the main package(s) from the import, and test specifiers against that package
29
+ var mainPackage = (typeof packageName === 'string' ? [packageName] : packageName).map(function (s) {
30
+ return s
31
+ .split('/')
32
+ .slice(0, -1)
33
+ .join('/');
34
+ });
35
+ if (mainPackage.includes(value)) {
36
+ return !!(nodePath.specifiers || []).find(function (specifier) {
37
+ if (specifier.type === 'ImportSpecifier') {
38
+ var specifierName = specifier.imported.name;
39
+ return specifiers.includes(specifierName);
40
+ }
41
+ return false;
42
+ });
43
+ }
44
+ return false;
45
+ });
46
+ }
package/index.js CHANGED
@@ -21,6 +21,13 @@ const {_: commands, path} = require('yargs')
21
21
  describe: chalk.gray('The path to execute the transform in (recursively).'),
22
22
  });
23
23
  })
24
+ .command('v7 [path]', chalk.gray('Canvas Kit v6 > v7 migration transform'), yargs => {
25
+ yargs.positional('path', {
26
+ type: 'string',
27
+ default: '.',
28
+ describe: chalk.gray('The path to execute the transform in (recursively).'),
29
+ });
30
+ })
24
31
  .demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
25
32
  .strictCommands()
26
33
  .fail((msg, err, yargs) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@workday/canvas-kit-codemod",
3
3
  "author": "Workday, Inc. (https://www.workday.com)",
4
4
  "license": "Apache-2.0",
5
- "version": "6.9.0-next.0+8f9fb600",
5
+ "version": "6.9.0-next.2+8dd3d6b6",
6
6
  "description": "A collection of codemods for use on Workday Canvas Kit packages.",
7
7
  "main": "dist/es6/index.js",
8
8
  "sideEffects": false,
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/Workday/canvas-kit.git"
14
+ "url": "https://github.com/workday/canvas-kit.git",
15
+ "directory": "modules/codemod"
15
16
  },
16
17
  "files": [
17
18
  "dist/",
@@ -42,5 +43,5 @@
42
43
  "test": "TZ=UTC jest -c ../../jest.config.js",
43
44
  "typecheck:src": "tsc -p . --noEmit --incremental false"
44
45
  },
45
- "gitHead": "8f9fb600b56c986b012e0282536296a2f5a54dff"
46
+ "gitHead": "8dd3d6b6d1af27a68d8ee952ad70a389a0b675dd"
46
47
  }