@workday/canvas-kit-codemod 16.0.0-alpha.0490-next.0 → 16.0.0-alpha.0491-next.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":"index.d.ts","sourceRoot":"","sources":["../../../lib/v16/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAItC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v16/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAKtC,QAAA,MAAM,SAAS,EAAE,SAKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,7 +1,8 @@
1
+ import updateCardVariant from './updateCardVariant';
1
2
  import updateHyperlinkProps from './updateHyperlinkProps';
2
3
  const transform = (file, api, options) => {
3
4
  // These will run in order. If your transform depends on others, place yours after dependent transforms
4
- const fixes = [updateHyperlinkProps];
5
+ const fixes = [updateHyperlinkProps, updateCardVariant];
5
6
  return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
6
7
  };
7
8
  export default transform;
@@ -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=updateCardVariant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateCardVariant.d.ts","sourceRoot":"","sources":["../../../lib/v16/updateCardVariant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA4B,OAAO,EAAC,MAAM,aAAa,CAAC;AAY7E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmD7E"}
@@ -0,0 +1,41 @@
1
+ import { hasImportSpecifiers } from '../v6/utils';
2
+ import { getImportRenameMap } from '../v15/utils/getImportRenameMap';
3
+ const packages = ['@workday/canvas-kit-react', '@workday/canvas-kit-react/card'];
4
+ const packageImports = ['Card'];
5
+ const variantMap = {
6
+ borderless: 'alt',
7
+ };
8
+ export default function transformer(file, api, options) {
9
+ const j = api.jscodeshift;
10
+ const root = j(file.source);
11
+ // exit if the named imports aren't found
12
+ if (!hasImportSpecifiers(api, root, packages, packageImports)) {
13
+ return file.source;
14
+ }
15
+ // getImportRenameMap utility will tell us if the file containsCanvasImports
16
+ // and give us an importMap to track what identifiers we need to update
17
+ const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
18
+ // Find all <Card> components
19
+ const components = root.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
20
+ (value.openingElement.name.name === importMap.Card ||
21
+ value.openingElement.name.name === styledMap.Card));
22
+ // Update the `variant` prop to the new value
23
+ components.forEach(component => {
24
+ var _a;
25
+ const variantProp = (_a = component.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
26
+ // For string literals like `variant="borderless"`
27
+ if (variantProp && variantProp.value && variantProp.value.type === 'StringLiteral') {
28
+ variantProp.value = j.stringLiteral(variantMap[variantProp.value.value] || variantProp.value.value);
29
+ }
30
+ // For object literals like `variant={'borderless'}`
31
+ if (variantProp &&
32
+ variantProp.value &&
33
+ variantProp.value.type === 'JSXExpressionContainer' &&
34
+ (variantProp.value.expression.type === 'Literal' ||
35
+ variantProp.value.expression.type === 'StringLiteral')) {
36
+ variantProp.value = j.stringLiteral(variantMap[variantProp.value.expression.value] ||
37
+ String(variantProp.value.expression.value));
38
+ }
39
+ });
40
+ return root.toSource();
41
+ }
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": "16.0.0-alpha.0490-next.0",
5
+ "version": "16.0.0-alpha.0491-next.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,
@@ -46,5 +46,5 @@
46
46
  "resolutions": {
47
47
  "recast": "0.20.4"
48
48
  },
49
- "gitHead": "84f8bdfe0708c6a33b246744ae4827349c123303"
49
+ "gitHead": "46f6ffe99425371997fcc5ad1821235567db140b"
50
50
  }