@workday/canvas-kit-codemod 16.0.0-alpha.0477-next.0 → 16.0.0-alpha.0479-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;AAEtC,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;AAItC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,7 @@
1
+ import updateHyperlinkProps from './updateHyperlinkProps';
1
2
  const transform = (file, api, options) => {
2
3
  // These will run in order. If your transform depends on others, place yours after dependent transforms
3
- const fixes = [];
4
+ const fixes = [updateHyperlinkProps];
4
5
  return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
5
6
  };
6
7
  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=updateHyperlinkProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateHyperlinkProps.d.ts","sourceRoot":"","sources":["../../../lib/v16/updateHyperlinkProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA4B,OAAO,EAAC,MAAM,aAAa,CAAC;AAmC7E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,UAoE9E"}
@@ -0,0 +1,70 @@
1
+ import { hasImportSpecifiers } from '../v6/utils';
2
+ import { getImportRenameMap } from './utils/getImportRenameMap';
3
+ const packages = ['@workday/canvas-kit-react', '@workday/canvas-kit-react/button'];
4
+ const packageImports = ['Hyperlink', 'ExternalHyperlink'];
5
+ function getVariantValue(attr) {
6
+ if (!attr.value) {
7
+ return null;
8
+ }
9
+ if (attr.value.type === 'StringLiteral') {
10
+ return attr.value.value;
11
+ }
12
+ if (attr.value.type === 'JSXExpressionContainer' &&
13
+ (attr.value.expression.type === 'Literal' || attr.value.expression.type === 'StringLiteral')) {
14
+ return String(attr.value.expression.value);
15
+ }
16
+ return null;
17
+ }
18
+ function findLinkTypeAttribute(attributes) {
19
+ return attributes === null || attributes === void 0 ? void 0 : attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'linkType');
20
+ }
21
+ export default function transformer(file, api, _options) {
22
+ const j = api.jscodeshift;
23
+ const root = j(file.source);
24
+ if (!hasImportSpecifiers(api, root, packages, packageImports)) {
25
+ return file.source;
26
+ }
27
+ const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
28
+ const componentNames = new Set([
29
+ importMap.Hyperlink,
30
+ styledMap.Hyperlink,
31
+ importMap.ExternalHyperlink,
32
+ styledMap.ExternalHyperlink,
33
+ ].filter(Boolean));
34
+ const components = root.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
35
+ componentNames.has(value.openingElement.name.name));
36
+ components.forEach(component => {
37
+ const attributes = component.value.openingElement.attributes;
38
+ if (!attributes) {
39
+ return;
40
+ }
41
+ const variantPropIndex = attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
42
+ if (variantPropIndex === -1) {
43
+ return;
44
+ }
45
+ const variantProp = attributes[variantPropIndex];
46
+ const variantValue = getVariantValue(variantProp);
47
+ if (!variantValue) {
48
+ return;
49
+ }
50
+ const ensureTypeStandalone = () => {
51
+ const existingLinkTypeAttr = findLinkTypeAttribute(attributes);
52
+ if (existingLinkTypeAttr) {
53
+ existingLinkTypeAttr.value = j.stringLiteral('standalone');
54
+ }
55
+ else {
56
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('linkType'), j.stringLiteral('standalone')));
57
+ }
58
+ };
59
+ if (variantValue === 'standalone') {
60
+ attributes.splice(variantPropIndex, 1);
61
+ ensureTypeStandalone();
62
+ return;
63
+ }
64
+ if (variantValue === 'standaloneInverse') {
65
+ variantProp.value = j.stringLiteral('inverse');
66
+ ensureTypeStandalone();
67
+ }
68
+ });
69
+ return root.toSource();
70
+ }
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.0477-next.0",
5
+ "version": "16.0.0-alpha.0479-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": "bae01a1c78cf7e68292fc4d37368147af79932af"
49
+ "gitHead": "1345e0f544f5bbd437409e92c3002f77e866306c"
50
50
  }