@workday/canvas-kit-codemod 15.0.0-alpha.1293-next.0 → 15.0.0-alpha.1301-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.
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14.1/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ import replaceDeprecatedStyleProps from './replaceDeprecatedStyleProps';
2
+ const transform = (file, api, options) => {
3
+ // These will run in order. If your transform depends on others, place yours after dependent transforms
4
+ const fixes = [replaceDeprecatedStyleProps];
5
+ return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
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=replaceDeprecatedStyleProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceDeprecatedStyleProps.d.ts","sourceRoot":"","sources":["../../../lib/v14.1/replaceDeprecatedStyleProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAc,OAAO,EAAC,MAAM,aAAa,CAAC;AAmG/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA6I7E"}
@@ -0,0 +1,159 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ import { hasImportSpecifiers } from '../v6/utils';
3
+ import { backgroundStyleFnConfigs, borderStyleFnConfigs, colorStyleFnConfigs, depthStyleFnConfigs, flexStyleFnConfigs, flexItemStyleFnConfigs, gridStyleFnConfigs, gridItemStyleFnConfigs, layoutStyleFnConfigs, otherStyleFnConfigs, positionStyleFnConfigs, spaceStyleFnConfigs, textStyleFnConfigs, } from '@workday/canvas-kit-react/layout';
4
+ import { getToken } from './utils/getToken';
5
+ const mainPackage = '@workday/canvas-kit-react';
6
+ const previewPackage = '@workday/canvas-kit-preview-react';
7
+ const labsPackage = '@workday/canvas-kit-labs-react';
8
+ const packages = [mainPackage, previewPackage, labsPackage];
9
+ const allProps = [
10
+ ...backgroundStyleFnConfigs,
11
+ ...borderStyleFnConfigs,
12
+ ...colorStyleFnConfigs,
13
+ ...depthStyleFnConfigs,
14
+ ...flexStyleFnConfigs,
15
+ ...flexItemStyleFnConfigs,
16
+ ...gridStyleFnConfigs,
17
+ ...gridItemStyleFnConfigs,
18
+ ...layoutStyleFnConfigs,
19
+ ...otherStyleFnConfigs,
20
+ ...positionStyleFnConfigs,
21
+ ...spaceStyleFnConfigs,
22
+ ...textStyleFnConfigs,
23
+ ];
24
+ const ignoredProps = {
25
+ Avatar: ['color', 'backgroundColor'],
26
+ Graphic: ['width', 'height'],
27
+ Pill: ['maxWidth'],
28
+ 'Pill.Count': ['backgroundColor', 'borderColor'],
29
+ 'Breadcrumbs.Item': ['maxWidth'],
30
+ 'Breadcrumbs.Link': ['maxWidth'],
31
+ BaseButton: [
32
+ 'background',
33
+ 'border',
34
+ 'boxShadowInner',
35
+ 'boxShadowOuter',
36
+ 'opacity',
37
+ 'borderRadius',
38
+ ],
39
+ ColorSwatch: ['color'],
40
+ AccentIcon: ['color'],
41
+ SVG: ['width', 'height'],
42
+ SystemIcon: ['background', 'color', 'fill'],
43
+ 'Menu.Card': ['minWidth', 'maxHeight'],
44
+ 'Popup.Card': ['maxHeight'],
45
+ 'Skeleton.Header': ['width', 'height', 'backgroundColor'],
46
+ 'Skeleton.Shape': ['width', 'height', 'backgroundColor', 'borderRadius'],
47
+ 'Skeleton.Text': ['backgroundColor'],
48
+ 'InputGroup.InnerStart': [
49
+ 'width',
50
+ 'height',
51
+ 'insetInlineStart',
52
+ 'insetInlineEnd',
53
+ 'pointerEvents',
54
+ ],
55
+ 'InputGroup.InnerEnd': ['width', 'height', 'insetInlineStart', 'insetInlineEnd', 'pointerEvents'],
56
+ TextInput: ['width'],
57
+ };
58
+ const checkName = (name, { importMap, styledMap }) => {
59
+ return Object.values(importMap).includes(name) || Object.values(styledMap).includes(name);
60
+ };
61
+ const getImportedName = (name, { importMap, styledMap }) => {
62
+ const [importedName] = Object.entries(importMap).find(([_, imported]) => imported === name) ||
63
+ Object.entries(styledMap).find(([_, styled]) => styled === name) ||
64
+ [];
65
+ return importedName || name;
66
+ };
67
+ const getPropConfig = (propName) => {
68
+ return allProps.find(prop => prop.name === propName);
69
+ };
70
+ export default function transformer(file, api, options) {
71
+ const j = api.jscodeshift;
72
+ const root = j(file.source);
73
+ if (!hasImportSpecifiers(api, root, packages, [])) {
74
+ return file.source;
75
+ }
76
+ const { importMap, styledMap } = getImportRenameMap(j, root, packages);
77
+ root
78
+ .find(j.JSXElement, (value) => {
79
+ var _a;
80
+ return ((value.openingElement.name.type === 'JSXIdentifier' &&
81
+ checkName(value.openingElement.name.name, { importMap, styledMap })) ||
82
+ (value.openingElement.name.type === 'JSXMemberExpression' &&
83
+ value.openingElement.name.object.type === 'JSXIdentifier' &&
84
+ checkName(value.openingElement.name.object.name, { importMap, styledMap }))) &&
85
+ !!((_a = value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.length);
86
+ })
87
+ .forEach(nodePath => {
88
+ var _a, _b, _c, _d;
89
+ const csProp = (_a = nodePath.node.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(attr => attr.type === 'JSXAttribute' &&
90
+ attr.name.type === 'JSXIdentifier' &&
91
+ attr.name.name === 'cs');
92
+ const asProp = (_b = nodePath.node.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.find(attr => attr.type === 'JSXAttribute' &&
93
+ attr.name.type === 'JSXIdentifier' &&
94
+ attr.name.name === 'as');
95
+ let csPropValue = {};
96
+ const stringifiedName = (nodePath.node.openingElement.name.type === 'JSXMemberExpression' &&
97
+ nodePath.node.openingElement.name.object.type === 'JSXIdentifier' &&
98
+ nodePath.node.openingElement.name.property.type === 'JSXIdentifier'
99
+ ? `${getImportedName(nodePath.node.openingElement.name.object.name, {
100
+ importMap,
101
+ styledMap,
102
+ })}.${nodePath.node.openingElement.name.property.name}`
103
+ : nodePath.node.openingElement.name.type === 'JSXIdentifier' &&
104
+ getImportedName(nodePath.node.openingElement.name.name, { importMap, styledMap }));
105
+ nodePath.node.openingElement.attributes = (_c = nodePath.node.openingElement.attributes) === null || _c === void 0 ? void 0 : _c.filter(attr => {
106
+ var _a, _b, _c, _d;
107
+ if (attr.type === 'JSXAttribute' &&
108
+ attr.name.type === 'JSXIdentifier' &&
109
+ getPropConfig(attr.name.name)) {
110
+ if (((_a = ignoredProps[stringifiedName]) === null || _a === void 0 ? void 0 : _a.includes(attr.name.name)) ||
111
+ (asProp &&
112
+ asProp.type === 'JSXAttribute' &&
113
+ asProp.value &&
114
+ ((asProp.value.type === 'JSXExpressionContainer' &&
115
+ asProp.value.expression.type === 'Identifier' &&
116
+ ((_b = ignoredProps[getImportedName(asProp.value.expression.name, {
117
+ importMap,
118
+ styledMap,
119
+ })]) === null || _b === void 0 ? void 0 : _b.includes(attr.name.name))) ||
120
+ (asProp.value.type === 'JSXExpressionContainer' &&
121
+ asProp.value.expression.type === 'MemberExpression' &&
122
+ asProp.value.expression.object.type === 'Identifier' &&
123
+ asProp.value.expression.property.type === 'Identifier' &&
124
+ ((_c = ignoredProps[`${getImportedName(asProp.value.expression.object.name, {
125
+ importMap,
126
+ styledMap,
127
+ })}.${asProp.value.expression.property.name}`]) === null || _c === void 0 ? void 0 : _c.includes(attr.name.name)))))) {
128
+ return true;
129
+ }
130
+ const { properties, system } = getPropConfig(attr.name.name);
131
+ if (csProp &&
132
+ csProp.type === 'JSXAttribute' &&
133
+ csProp.value &&
134
+ csProp.value.type === 'JSXExpressionContainer' &&
135
+ csProp.value.expression.type === 'ObjectExpression') {
136
+ csProp.value.expression.properties.push(...properties.map((prop) => j.objectProperty(j.identifier(prop), getToken({ j, root }, { system, prop, value: attr.value }))));
137
+ }
138
+ if (!csProp && nodePath.node.openingElement.attributes) {
139
+ const value = ((_d = attr.value) === null || _d === void 0 ? void 0 : _d.type) === 'JSXExpressionContainer' ? attr.value.expression : attr.value;
140
+ csPropValue = {
141
+ ...csPropValue,
142
+ ...properties.reduce((acc, prop) => {
143
+ return {
144
+ ...acc,
145
+ [prop]: getToken({ j, root }, { system, prop, value }),
146
+ };
147
+ }, {}),
148
+ };
149
+ }
150
+ return false;
151
+ }
152
+ return true;
153
+ });
154
+ if (Object.keys(csPropValue).length) {
155
+ (_d = nodePath.node.openingElement.attributes) === null || _d === void 0 ? void 0 : _d.push(j.jsxAttribute(j.jsxIdentifier('cs'), j.jsxExpressionContainer(j.objectExpression(Object.entries(csPropValue).map(([key, value]) => j.objectProperty(j.identifier(key), value))))));
156
+ }
157
+ });
158
+ return root.toSource();
159
+ }
@@ -0,0 +1,7 @@
1
+ import { Collection, JSCodeshift } from 'jscodeshift';
2
+ export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, packages: 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/v14.1/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,QAAQ,EAAE,MAAM,EAAE;;;;EAoD3F"}
@@ -0,0 +1,43 @@
1
+ export function getImportRenameMap(j, root, packages) {
2
+ let containsCanvasImports = false;
3
+ // build import name remapping - in case someone renamed imports...
4
+ // i.e. `import { IconButton as StyledIconButton } ...`
5
+ const importMap = {};
6
+ const styledMap = {};
7
+ root.find(j.ImportDeclaration, node => {
8
+ // imports our module
9
+ const value = node.source.value;
10
+ if (typeof value === 'string' && packages.some(p => value.startsWith(p))) {
11
+ containsCanvasImports = true;
12
+ (node.specifiers || []).forEach(specifier => {
13
+ if (specifier.type === 'ImportSpecifier') {
14
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
15
+ importMap[specifier.imported.name] = specifier.imported.name;
16
+ }
17
+ else {
18
+ importMap[specifier.imported.name] = specifier.local.name;
19
+ }
20
+ }
21
+ });
22
+ }
23
+ return false;
24
+ });
25
+ root
26
+ .find(j.CallExpression, (node) => node.callee.type === 'Identifier' &&
27
+ node.callee.name === 'styled' &&
28
+ node.arguments[0].type === 'Identifier')
29
+ .forEach(nodePath => {
30
+ // const StyledName = styled(OriginalName)({})
31
+ // const StyledName = styled(OriginalName)`` // Tagged template
32
+ if ((nodePath.parent.value.type === 'CallExpression' ||
33
+ nodePath.parent.value.type === 'TaggedTemplateExpression') &&
34
+ nodePath.parent.parent.value.type === 'VariableDeclarator' &&
35
+ nodePath.parent.parent.value.id.type === 'Identifier') {
36
+ const styledName = nodePath.parent.parent.value.id.name;
37
+ if (nodePath.value.arguments[0].type === 'Identifier') {
38
+ styledMap[nodePath.value.arguments[0].name] = styledName;
39
+ }
40
+ }
41
+ });
42
+ return { containsCanvasImports, importMap, styledMap };
43
+ }
@@ -0,0 +1,6 @@
1
+ export declare const getToken: ({ j, root }: any, { system, prop, value }: {
2
+ system: string;
3
+ prop: string;
4
+ value: any;
5
+ }) => any;
6
+ //# sourceMappingURL=getToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getToken.d.ts","sourceRoot":"","sources":["../../../../lib/v14.1/utils/getToken.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ,gBACR,GAAG;YACkB,MAAM;UAAQ,MAAM;WAAS,GAAG;SAmCjE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { tokensMap } from './tokensMap';
2
+ import { varToMemberExpression } from '../../v13.2/utils/varToMemberExpression';
3
+ import { systemColors } from '../../v13.2/mapping';
4
+ import { addMissingImports } from '../../v13.2/utils';
5
+ const createSystemToken = (key, system) => key ? `system.${system}${isNaN(key) ? `.${key}` : `[${key}]`}` : null;
6
+ export const getToken = ({ j, root }, { system, prop, value }) => {
7
+ var _a, _b;
8
+ if (system in tokensMap) {
9
+ const tokens = tokensMap[system];
10
+ let token = '';
11
+ if (system === 'color') {
12
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === prop))) === null || _a === void 0 ? void 0 : _a[1];
13
+ const key = tokens === null || tokens === void 0 ? void 0 : tokens[value.value];
14
+ token = key || `base.${value.value}`;
15
+ }
16
+ else {
17
+ const key = tokens[((_b = value === null || value === void 0 ? void 0 : value.value) !== null && _b !== void 0 ? _b : value)];
18
+ token = createSystemToken(key, system) || '';
19
+ }
20
+ if (token) {
21
+ if (token.startsWith('system')) {
22
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
23
+ }
24
+ else if (token.startsWith('base')) {
25
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
26
+ }
27
+ return varToMemberExpression(j, token);
28
+ }
29
+ }
30
+ return value.type === 'JSXExpressionContainer' ? value.expression : value;
31
+ };
@@ -0,0 +1,31 @@
1
+ export declare const tokensMap: {
2
+ space: {
3
+ zero: string;
4
+ xxxs: string;
5
+ xxs: string;
6
+ xs: string;
7
+ s: string;
8
+ m: string;
9
+ l: string;
10
+ xl: string;
11
+ xxl: string;
12
+ xxxl: string;
13
+ };
14
+ shape: {
15
+ zero: string;
16
+ s: string;
17
+ m: string;
18
+ l: string;
19
+ circle: string;
20
+ };
21
+ depth: {
22
+ 1: number;
23
+ 2: number;
24
+ 3: number;
25
+ 4: number;
26
+ 5: number;
27
+ 6: number;
28
+ };
29
+ color: {};
30
+ };
31
+ //# sourceMappingURL=tokensMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokensMap.d.ts","sourceRoot":"","sources":["../../../../lib/v14.1/utils/tokensMap.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBrB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { mapping } from '../../v13.2/mapping/index';
2
+ export const tokensMap = {
3
+ space: {
4
+ ...mapping.space.keys,
5
+ },
6
+ shape: {
7
+ ...mapping.borderRadius.keys,
8
+ },
9
+ depth: {
10
+ 1: 1,
11
+ 2: 2,
12
+ 3: 3,
13
+ 4: 4,
14
+ 5: 5,
15
+ 6: 6,
16
+ },
17
+ color: {},
18
+ };
package/index.js CHANGED
@@ -109,6 +109,17 @@ const {
109
109
  describe: chalk.gray('The path to execute the transform in (recursively).'),
110
110
  });
111
111
  })
112
+ .command(
113
+ 'v14.1 [path]',
114
+ chalk.gray('Canvas Kit v14.1 upgrade transform (style props deprecation)'),
115
+ yargs => {
116
+ yargs.positional('path', {
117
+ type: 'string',
118
+ default: '.',
119
+ describe: chalk.gray('The path to execute the transform in (recursively).'),
120
+ });
121
+ }
122
+ )
112
123
  .demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
113
124
  .strictCommands()
114
125
  .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": "15.0.0-alpha.1293-next.0",
5
+ "version": "15.0.0-alpha.1301-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": "3af12af1258fa5f8a09c702f9bb322b5a1f0653d"
49
+ "gitHead": "5a43df05e8c2e88e1bf2aa502b38c511f6a35117"
50
50
  }