@workday/canvas-kit-codemod 7.0.0-alpha.89-next.16 → 7.0.0-alpha.92-next.19

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":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAWtC,QAAA,MAAM,SAAS,EAAE,SAchB,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;AAatC,QAAA,MAAM,SAAS,EAAE,SAgBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
@@ -17,6 +17,8 @@ import renameLayoutImports from './renameLayoutImports';
17
17
  import updateSegmentedControl from './updateSegmentedControl';
18
18
  import renameIconPosition from './renameIconPosition';
19
19
  import recategorizeIconButtons from './recategorizeIconButtons';
20
+ import updateModelSignatures from './updateModelSignatures';
21
+ import updateTabs from './updateTabs';
20
22
  var transform = function (file, api, options) {
21
23
  // These will run in order. If your transform depends on others, place yours after dependent transforms
22
24
  var fixes = [
@@ -28,6 +30,8 @@ var transform = function (file, api, options) {
28
30
  renameIconPosition,
29
31
  renameLayoutImports,
30
32
  updateSegmentedControl,
33
+ updateModelSignatures,
34
+ updateTabs,
31
35
  ];
32
36
  return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
33
37
  };
@@ -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,UA0J7E"}
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"}
@@ -73,6 +73,9 @@ export default function transformer(file, api, options) {
73
73
  updateJSXTag(nodePath, buttonType);
74
74
  requiredImportSpecifiers.push(buttonType);
75
75
  });
76
+ if (requiredImportSpecifiers.length === 0) {
77
+ return file.source;
78
+ }
76
79
  // Find all instances of IconButton within a style function
77
80
  // const StyledIconButton = styled(IconButton) gets renamed to
78
81
  // const StyledIconButton = styled(CorrectButtonMapping)
@@ -80,7 +83,10 @@ export default function transformer(file, api, options) {
80
83
  var _a;
81
84
  if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
82
85
  nodePath.value.init.callee.type === 'CallExpression' &&
83
- nodePath.value.init.callee.arguments[0].type === 'Identifier') {
86
+ nodePath.value.init.callee.callee.type === 'Identifier' &&
87
+ nodePath.value.init.callee.callee.name === 'styled' &&
88
+ nodePath.value.init.callee.arguments[0].type === 'Identifier' &&
89
+ nodePath.value.init.callee.arguments[0].name === importMap.IconButton) {
84
90
  nodePath.value.init.callee.arguments[0].name = buttonType;
85
91
  requiredImportSpecifiers.push(buttonType);
86
92
  }
@@ -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,SAqFhB,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;AAelE,QAAA,MAAM,SAAS,EAAE,SAuFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -68,7 +68,9 @@ var transform = function (file, api) {
68
68
  }
69
69
  else {
70
70
  // create new import
71
- foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/layout')));
71
+ if (foundImport.length) {
72
+ foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/layout')));
73
+ }
72
74
  }
73
75
  foundImport.forEach(function (importPath) {
74
76
  var _a;
@@ -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=updateModelSignatures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateModelSignatures.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateModelSignatures.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,UA0G7E"}
@@ -0,0 +1,90 @@
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
+ // inverse the import map. It is more useful this way for this function
11
+ var imports = Object.keys(importMap).reduce(function (result, key) {
12
+ result[importMap[key]] = key;
13
+ return result;
14
+ }, {});
15
+ root.find(j.CallExpression).forEach(function (nodePath) {
16
+ var value = nodePath.value;
17
+ // check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
18
+ if (value.callee.type === 'Identifier' &&
19
+ /use[a-zA-Z]+Model/.test(imports[value.callee.name])) {
20
+ // loop over all the arguments of the `use{*}Model` hook
21
+ value.arguments.forEach(function (argument) {
22
+ // look for object expressions: `use{*}Model({ /* here */ })`
23
+ if (argument.type === 'ObjectExpression') {
24
+ // loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
25
+ // the value is a function matching `on{*}` or `should{*}` naming convention
26
+ argument.properties.forEach(function (property) {
27
+ // If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
28
+ // {
29
+ // onShow() {}, // ObjectMethod
30
+ // onHide: () => {}, ObjectProperty with arrow function expression
31
+ // }
32
+ if ((property.type === 'ObjectMethod' ||
33
+ (property.type === 'ObjectProperty' &&
34
+ property.value.type === 'ArrowFunctionExpression')) &&
35
+ property.key.type === 'Identifier') {
36
+ var propertyName_1 = property.key.name;
37
+ // Both types have a `params`, but are at different places in the AST
38
+ var params_1 = property.type === 'ObjectMethod'
39
+ ? property.params
40
+ : property.value.type === 'ArrowFunctionExpression'
41
+ ? property.value.params
42
+ : [];
43
+ // create a mapping for param names of callbacks and guards. This makes the logic more
44
+ // difficult to follow, but decreases duplication
45
+ var paramMapping_1 = {
46
+ on: ['data', 'state'],
47
+ should: ['data', 'prevState'],
48
+ };
49
+ // We will be overriding the params with this variable later
50
+ var finalParams_1 = [];
51
+ // loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
52
+ keys(paramMapping_1).forEach(function (key) {
53
+ // matches `onShow` and `shouldShow`
54
+ if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
55
+ params_1.forEach(function (param) {
56
+ if (param.type === 'ObjectPattern') {
57
+ param.properties.forEach(function (property) {
58
+ if (property.type === 'ObjectProperty' &&
59
+ property.key.type === 'Identifier') {
60
+ if (property.value.type === 'Identifier' ||
61
+ property.value.type === 'ObjectPattern') {
62
+ var index = paramMapping_1[key].indexOf(property.key.name);
63
+ // use `property.value` instead of `property.key.name` in case they
64
+ // renamed it example `shouldShow({ data: myData })`. The key name is
65
+ // `data` while the value is `myData`
66
+ finalParams_1[index] = property.value;
67
+ }
68
+ }
69
+ });
70
+ }
71
+ });
72
+ // `ObjectMethod` and `ObjectProperty` have params in a different place in the
73
+ // AST, so apply `finalParams` where appropriate
74
+ if (property.type === 'ObjectMethod') {
75
+ property.params = finalParams_1;
76
+ }
77
+ else if (property.type === 'ObjectProperty' &&
78
+ property.value.type === 'ArrowFunctionExpression') {
79
+ property.value.params = finalParams_1;
80
+ }
81
+ }
82
+ });
83
+ }
84
+ });
85
+ }
86
+ });
87
+ }
88
+ });
89
+ return root.toSource();
90
+ }
@@ -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,UA0B7E"}
@@ -0,0 +1,23 @@
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(j.JSXOpeningElement, { name: { object: { name: importMap.Tabs }, property: { name: 'Item' } } })
11
+ .forEach(function (nodePath) {
12
+ var _a;
13
+ nodePath.value.attributes = (_a = nodePath.value.attributes) === null || _a === void 0 ? void 0 : _a.map(function (attribute) {
14
+ if (attribute.type === 'JSXAttribute' &&
15
+ attribute.name.type === 'JSXIdentifier' &&
16
+ attribute.name.name === 'name') {
17
+ attribute.name.name = 'data-id';
18
+ }
19
+ return attribute;
20
+ });
21
+ });
22
+ return root.toSource();
23
+ }
@@ -9,7 +9,7 @@ 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 === '@workday/canvas-kit-react' || value === packageName)) {
12
+ (value.startsWith('@workday/canvas-kit-react') || value === packageName)) {
13
13
  containsCanvasImports = true;
14
14
  (node.specifiers || []).forEach(function (specifier) {
15
15
  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.89-next.16+b786927d",
5
+ "version": "7.0.0-alpha.92-next.19+e2cad878",
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": "b786927d54a293fcb6f6e745f1831317e101371d"
45
+ "gitHead": "e2cad87834c40633618cb65a95a0271b1256e214"
46
46
  }