@workday/canvas-kit-codemod 6.3.6 → 7.0.0-alpha.0-next.4

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.
@@ -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=compoundActionBar.d.ts.map
@@ -0,0 +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,UAkD7E"}
@@ -0,0 +1,42 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ import { hasImportSpecifiers } from '../v6/utils';
3
+ var actionBarPackage = '@workday/canvas-kit-react/action-bar';
4
+ export default function transformer(file, api, options) {
5
+ var j = api.jscodeshift;
6
+ var root = j(file.source);
7
+ if (!hasImportSpecifiers(api, root, actionBarPackage, ['ActionBar'])) {
8
+ return file.source;
9
+ }
10
+ // Replace default import with named or renamed import
11
+ root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
12
+ var _a;
13
+ var parent = nodePath.parent;
14
+ var importSource = String(parent.node.source.value);
15
+ var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
16
+ if (actionBarPackage === importSource && localName) {
17
+ nodePath.replace(j.importSpecifier(j.identifier('ActionBar'), j.identifier(localName)));
18
+ }
19
+ });
20
+ 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
+ root
23
+ .find(j.JSXElement, function (value) {
24
+ return value.openingElement.name.type === 'JSXIdentifier' &&
25
+ (value.openingElement.name.name === importMap.ActionBar ||
26
+ value.openingElement.name.name === styledMap.ActionBar);
27
+ })
28
+ .forEach(function (nodePath) {
29
+ var attributes = nodePath.value.openingElement.attributes;
30
+ 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
+ });
39
+ }
40
+ });
41
+ return root.toSource();
42
+ }
@@ -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=compoundBanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compoundBanner.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAUR,MAAM,aAAa,CAAC;AAQrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuM7E"}
@@ -0,0 +1,133 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ function filterDefined(input) {
3
+ return !!input;
4
+ }
5
+ export default function transformer(file, api, options) {
6
+ var j = api.jscodeshift;
7
+ var root = j(file.source);
8
+ var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/banner'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
9
+ if (!containsCanvasImports) {
10
+ return file.source;
11
+ }
12
+ root
13
+ .find(j.JSXElement, function (value) {
14
+ return value.openingElement.name.type === 'JSXIdentifier' &&
15
+ (value.openingElement.name.name === importMap.Banner ||
16
+ value.openingElement.name.name === styledMap.Banner);
17
+ })
18
+ .forEach(function (nodePath) {
19
+ var _a, _b;
20
+ // bail early if we find a `Banner.Label` as a child
21
+ for (var _i = 0, _c = nodePath.value.children || []; _i < _c.length; _i++) {
22
+ var child = _c[_i];
23
+ if (child.type === 'JSXElement' &&
24
+ child.openingElement.name.type === 'JSXMemberExpression' &&
25
+ child.openingElement.name.object.type === 'JSXIdentifier' &&
26
+ child.openingElement.name.object.name === 'Banner' &&
27
+ child.openingElement.name.property.type === 'JSXIdentifier' &&
28
+ child.openingElement.name.property.name === 'Label') {
29
+ return;
30
+ }
31
+ }
32
+ var findAttribute = function (name) { return function (item) {
33
+ if (item.type === 'JSXAttribute' &&
34
+ item.name.type === 'JSXIdentifier' &&
35
+ item.name.name === name) {
36
+ return true;
37
+ }
38
+ return false;
39
+ }; };
40
+ var attributes = nodePath.value.openingElement.attributes;
41
+ if (attributes) {
42
+ var label = attributes.find(findAttribute('label'));
43
+ var actionText = attributes.find(findAttribute('actionText'));
44
+ var errorIndex_1 = attributes.findIndex(findAttribute('error'));
45
+ var variantIndex_1 = attributes.findIndex(findAttribute('variant'));
46
+ if (errorIndex_1 >= 0 && ((_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a[errorIndex_1])) {
47
+ var errorExpression = nodePath.value.openingElement.attributes[errorIndex_1].value.expression;
48
+ var getNameToBoolean = function (name) {
49
+ return name === 'Error' ? j.booleanLiteral(true) : j.booleanLiteral(false);
50
+ };
51
+ var setHasError = function (hasErrorValue) {
52
+ if (nodePath.value.openingElement.attributes) {
53
+ nodePath.value.openingElement.attributes[errorIndex_1] = j.jsxAttribute(j.jsxIdentifier('hasError'), j.jsxExpressionContainer(hasErrorValue));
54
+ }
55
+ };
56
+ if (errorExpression.property) {
57
+ var previousExpression = errorExpression;
58
+ var newValue = getNameToBoolean(previousExpression.property.name);
59
+ setHasError(newValue);
60
+ }
61
+ if (errorExpression.test) {
62
+ var previousExpression = errorExpression;
63
+ var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
64
+ setHasError(newValue);
65
+ }
66
+ }
67
+ if (variantIndex_1 >= 0 && ((_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b[variantIndex_1])) {
68
+ var stickyExpression = nodePath.value.openingElement.attributes[variantIndex_1].value.expression;
69
+ var getNameToBoolean = function (name) {
70
+ return name === 'Sticky' ? j.booleanLiteral(true) : j.booleanLiteral(false);
71
+ };
72
+ var setIsSticky = function (hasStickyValue) {
73
+ if (nodePath.value.openingElement.attributes) {
74
+ nodePath.value.openingElement.attributes[variantIndex_1] = j.jsxAttribute(j.jsxIdentifier('isSticky'), j.jsxExpressionContainer(hasStickyValue));
75
+ }
76
+ };
77
+ if (stickyExpression.property) {
78
+ var previousExpression = stickyExpression;
79
+ var newValue = getNameToBoolean(previousExpression.property.name);
80
+ setIsSticky(newValue);
81
+ }
82
+ if (stickyExpression.test) {
83
+ var previousExpression = stickyExpression;
84
+ var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
85
+ setIsSticky(newValue);
86
+ }
87
+ }
88
+ // remove these attributes from the list - we'll add them as sub components
89
+ nodePath.value.openingElement.attributes = attributes.filter(function (item) {
90
+ if (item.type === 'JSXAttribute' &&
91
+ item.name.type === 'JSXIdentifier' &&
92
+ ['label', 'actionText'].includes(item.name.name)) {
93
+ return false;
94
+ }
95
+ return true;
96
+ });
97
+ var BannerIconJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Icon'));
98
+ var BannerLabelJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Label'));
99
+ var BannerActionTextJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('ActionText'));
100
+ var convertAttributeToChildren = function (input) {
101
+ var _a;
102
+ switch ((_a = input.value) === null || _a === void 0 ? void 0 : _a.type) {
103
+ case 'JSXExpressionContainer':
104
+ // unwrap JSXElements
105
+ if (input.value.expression.type === 'JSXElement') {
106
+ return [input.value.expression];
107
+ }
108
+ return [input.value];
109
+ default:
110
+ return [input.value];
111
+ }
112
+ };
113
+ var createSelfClosingTag = function (Tag) {
114
+ var OpeningTag = j.jsxOpeningElement(Tag);
115
+ OpeningTag.selfClosing = true;
116
+ return j.jsxElement(OpeningTag);
117
+ };
118
+ nodePath.value.openingElement.selfClosing = false;
119
+ // Add subcomponents back as children
120
+ nodePath.value.children = [
121
+ createSelfClosingTag(BannerIconJSX),
122
+ !!label
123
+ ? j.jsxElement(j.jsxOpeningElement(BannerLabelJSX), j.jsxClosingElement(BannerLabelJSX), convertAttributeToChildren(label))
124
+ : createSelfClosingTag(BannerLabelJSX),
125
+ !!actionText
126
+ ? j.jsxElement(j.jsxOpeningElement(BannerActionTextJSX), j.jsxClosingElement(BannerActionTextJSX), convertAttributeToChildren(actionText))
127
+ : createSelfClosingTag(BannerActionTextJSX),
128
+ ].filter(filterDefined);
129
+ nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
130
+ }
131
+ });
132
+ return root.toSource();
133
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAEnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,QAI7E"}
@@ -0,0 +1,5 @@
1
+ export default function transformer(file, api, options) {
2
+ // These will run in order. If your transform depends on others, place yours after dependent transforms
3
+ // const fixes = [];
4
+ // return fixes.reduce((source, fix) => fix({...file, source}, api, options), file.source);
5
+ }
@@ -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;;;;EAyDzF"}
@@ -0,0 +1,50 @@
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' || value === packageName)) {
13
+ containsCanvasImports = true;
14
+ (node.specifiers || []).forEach(function (specifier) {
15
+ if (specifier.type === 'ImportSpecifier') {
16
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
17
+ importMap[specifier.imported.name] = specifier.imported.name;
18
+ }
19
+ else {
20
+ importMap[specifier.imported.name] = specifier.local.name;
21
+ }
22
+ }
23
+ });
24
+ }
25
+ return false;
26
+ });
27
+ root
28
+ .find(j.CallExpression, function (node) {
29
+ if (node.callee.type === 'Identifier' &&
30
+ node.callee.name === 'styled' &&
31
+ node.arguments[0].type === 'Identifier') {
32
+ return true;
33
+ }
34
+ return false;
35
+ })
36
+ .forEach(function (nodePath) {
37
+ // const StyledName = styled(OriginalName)({})
38
+ // const StyledName = styled(OriginalName)`` // Tagged template
39
+ if ((nodePath.parent.value.type === 'CallExpression' ||
40
+ nodePath.parent.value.type === 'TaggedTemplateExpression') &&
41
+ nodePath.parent.parent.value.type === 'VariableDeclarator' &&
42
+ nodePath.parent.parent.value.id.type === 'Identifier') {
43
+ var styledName = nodePath.parent.parent.value.id.name;
44
+ if (nodePath.value.arguments[0].type === 'Identifier') {
45
+ styledMap[nodePath.value.arguments[0].name] = styledName;
46
+ }
47
+ }
48
+ });
49
+ return { containsCanvasImports: containsCanvasImports, importMap: importMap, styledMap: styledMap };
50
+ }
@@ -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.3.6",
5
+ "version": "7.0.0-alpha.0-next.4+bdd1ec94",
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": "3322ef6ba113940373412840edd14d35a7a3093c"
45
+ "gitHead": "bdd1ec9493a5a2dc4d67e4cc33adcba13efee4b7"
46
46
  }