@workday/canvas-kit-codemod 15.0.0-alpha.1303-next.0 → 15.0.0-alpha.1326-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.
Files changed (39) hide show
  1. package/dist/es6/v13.2/mapping/index.d.ts +59 -1
  2. package/dist/es6/v13.2/mapping/index.d.ts.map +1 -1
  3. package/dist/es6/v13.2/mapping/index.js +88 -1
  4. package/dist/es6/v13.2/migrateColorTokens.d.ts.map +1 -1
  5. package/dist/es6/v13.2/migrateColorTokens.js +64 -13
  6. package/dist/es6/v13.2/migrateDepthTokens.d.ts.map +1 -1
  7. package/dist/es6/v13.2/migrateDepthTokens.js +42 -26
  8. package/dist/es6/v13.2/migrateOtherTokens.d.ts.map +1 -1
  9. package/dist/es6/v13.2/migrateOtherTokens.js +37 -67
  10. package/dist/es6/v13.2/migrateTypeTokens.d.ts.map +1 -1
  11. package/dist/es6/v13.2/migrateTypeTokens.js +43 -19
  12. package/dist/es6/v13.2/utils/filterOutImports.d.ts +6 -1
  13. package/dist/es6/v13.2/utils/filterOutImports.d.ts.map +1 -1
  14. package/dist/es6/v13.2/utils/filterOutImports.js +22 -4
  15. package/dist/es6/v13.2/utils/getImports.d.ts +3 -0
  16. package/dist/es6/v13.2/utils/getImports.d.ts.map +1 -0
  17. package/dist/es6/v13.2/utils/getImports.js +12 -0
  18. package/dist/es6/v13.2/utils/index.d.ts +1 -0
  19. package/dist/es6/v13.2/utils/index.d.ts.map +1 -1
  20. package/dist/es6/v13.2/utils/index.js +1 -0
  21. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts +1 -1
  22. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
  23. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.js +151 -33
  24. package/dist/es6/v13.2/utils/varToMemberExpression.d.ts.map +1 -1
  25. package/dist/es6/v13.2/utils/varToMemberExpression.js +1 -1
  26. package/dist/es6/v14-tokens/index.d.ts.map +1 -1
  27. package/dist/es6/v14-tokens/index.js +9 -2
  28. package/dist/es6/v14-tokens/migrateColorTokens.d.ts.map +1 -1
  29. package/dist/es6/v14-tokens/migrateColorTokens.js +10 -23
  30. package/dist/es6/v14-tokens/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
  31. package/dist/es6/v14-tokens/utils/transformObjectPropertyRecursively.js +31 -28
  32. package/dist/es6/v15/index.d.ts +4 -0
  33. package/dist/es6/v15/index.d.ts.map +1 -0
  34. package/dist/es6/v15/index.js +6 -0
  35. package/dist/es6/v15/utils/getImportRenameMap.d.ts +7 -0
  36. package/dist/es6/v15/utils/getImportRenameMap.d.ts.map +1 -0
  37. package/dist/es6/v15/utils/getImportRenameMap.js +44 -0
  38. package/index.js +7 -0
  39. package/package.json +2 -2
@@ -30,40 +30,43 @@ const updateArguments = ({ j, root }, expr, property, importDeclaration) => {
30
30
  };
31
31
  export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling) => {
32
32
  var _a;
33
+ const createObjectProperty = (key, value) => {
34
+ var _a, _b, _c;
35
+ const prop = j.objectProperty(key, value);
36
+ // Preserve computed flag: if explicitly true, or if key is not a simple literal/identifier
37
+ if (property.computed === true ||
38
+ (((_a = property.key) === null || _a === void 0 ? void 0 : _a.type) !== 'Identifier' &&
39
+ ((_b = property.key) === null || _b === void 0 ? void 0 : _b.type) !== 'StringLiteral' &&
40
+ ((_c = property.key) === null || _c === void 0 ? void 0 : _c.type) !== 'NumericLiteral')) {
41
+ prop.computed = true;
42
+ }
43
+ return prop;
44
+ };
33
45
  if (property.type === 'ObjectProperty' &&
34
46
  property.key.type === 'Identifier' &&
35
- property.value.type === 'MemberExpression' &&
47
+ ((_a = property.value) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' &&
36
48
  property.value.object.type === 'Identifier' &&
37
49
  property.value.property.type === 'Identifier') {
38
50
  const cssProperty = property.key.name;
39
- const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === cssProperty))) === null || _a === void 0 ? void 0 : _a[1];
40
- const { property: value, object: { name }, } = property.value;
41
- const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
42
- if (colorToken) {
43
- if (importDeclaration[name] === 'colors') {
44
- if (!isCanvasKitStyling) {
45
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
46
- }
47
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
48
- return j.objectProperty(j.identifier(cssProperty), isCanvasKitStyling
49
- ? varToMemberExpression(j, colorToken)
50
- : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
51
- }
52
- if (importDeclaration[property.value.object.name] === 'base') {
53
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
54
- return j.objectProperty(j.identifier(cssProperty), varToMemberExpression(j, colorToken));
55
- }
51
+ const propsName = Object.keys(systemColors).find(blockKey => blockKey.split(',').some(prop => prop === cssProperty));
52
+ const tokens = propsName ? systemColors[propsName] : null;
53
+ const propertyName = property.value.object.name;
54
+ const valueName = property.value.property.name;
55
+ if (!(tokens && importDeclaration[propertyName] === 'base')) {
56
+ return property;
56
57
  }
57
- else {
58
- const baseToken = baseMapping[property.value.property.name];
59
- if (baseToken) {
60
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
61
- return j.objectProperty(j.identifier(cssProperty), j.memberExpression(j.identifier('base'), j.identifier(baseToken)));
62
- }
58
+ const colorToken = tokens[valueName];
59
+ const baseToken = baseMapping[valueName];
60
+ if (colorToken || baseToken) {
61
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: [colorToken ? 'system' : 'base'] });
62
+ const newToken = colorToken
63
+ ? varToMemberExpression(j, colorToken)
64
+ : j.memberExpression(j.identifier('base'), j.identifier(baseToken));
65
+ return createObjectProperty(j.identifier(cssProperty), isCanvasKitStyling ? newToken : j.callExpression(j.identifier('cssVar'), [newToken]));
63
66
  }
64
67
  return property;
65
68
  }
66
- if (property.value.type === 'CallExpression') {
69
+ if (property.type === 'ObjectProperty' && property.value.type === 'CallExpression') {
67
70
  property.value.arguments = updateArguments({ j, root }, property.value, property, importDeclaration);
68
71
  }
69
72
  if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
@@ -95,7 +98,7 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
95
98
  }
96
99
  return expr;
97
100
  });
98
- return j.objectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
101
+ return createObjectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
99
102
  }
100
103
  if (property.type === 'ObjectProperty' && property.value.type === 'ConditionalExpression') {
101
104
  const { test, consequent, alternate } = property.value;
@@ -132,10 +135,10 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
132
135
  if (alternate.type === 'CallExpression') {
133
136
  alternate.arguments = updateArguments({ j, root }, alternate, property, importDeclaration);
134
137
  }
135
- return j.objectProperty(property.key, j.conditionalExpression(test, consequentNode, alternateNode));
138
+ return createObjectProperty(property.key, j.conditionalExpression(test, consequentNode, alternateNode));
136
139
  }
137
140
  if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
138
- return j.objectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling))));
141
+ return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling))));
139
142
  }
140
143
  return property;
141
144
  };
@@ -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/v15/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ const transform = (file, api, options) => {
2
+ // These will run in order. If your transform depends on others, place yours after dependent transforms
3
+ // const fixes: Transform[] = [];
4
+ // return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source);
5
+ };
6
+ export default transform;
@@ -0,0 +1,7 @@
1
+ import { Collection, JSCodeshift } from 'jscodeshift';
2
+ export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, mainPackage?: string, 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/v15/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,WAAW,EACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,SAA8B,EACzC,WAAW,SAAK;;;;EAuDjB"}
@@ -0,0 +1,44 @@
1
+ export function getImportRenameMap(j, root, mainPackage = '@workday/canvas-kit-react', packageName = '') {
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' &&
11
+ (value === mainPackage || value.startsWith(mainPackage) || value === packageName)) {
12
+ containsCanvasImports = true;
13
+ (node.specifiers || []).forEach(specifier => {
14
+ if (specifier.type === 'ImportSpecifier') {
15
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
16
+ importMap[specifier.imported.name] = specifier.imported.name;
17
+ }
18
+ else {
19
+ importMap[specifier.imported.name] = specifier.local.name;
20
+ }
21
+ }
22
+ });
23
+ }
24
+ return false;
25
+ });
26
+ root
27
+ .find(j.CallExpression, (node) => node.callee.type === 'Identifier' &&
28
+ node.callee.name === 'styled' &&
29
+ node.arguments[0].type === 'Identifier')
30
+ .forEach(nodePath => {
31
+ // const StyledName = styled(OriginalName)({})
32
+ // const StyledName = styled(OriginalName)`` // Tagged template
33
+ if ((nodePath.parent.value.type === 'CallExpression' ||
34
+ nodePath.parent.value.type === 'TaggedTemplateExpression') &&
35
+ nodePath.parent.parent.value.type === 'VariableDeclarator' &&
36
+ nodePath.parent.parent.value.id.type === 'Identifier') {
37
+ const styledName = nodePath.parent.parent.value.id.name;
38
+ if (nodePath.value.arguments[0].type === 'Identifier') {
39
+ styledMap[nodePath.value.arguments[0].name] = styledName;
40
+ }
41
+ }
42
+ });
43
+ return { containsCanvasImports, importMap, styledMap };
44
+ }
package/index.js CHANGED
@@ -120,6 +120,13 @@ const {
120
120
  });
121
121
  }
122
122
  )
123
+ .command('v15 [path]', chalk.gray('Canvas Kit v14 > v15 upgrade transform'), yargs => {
124
+ yargs.positional('path', {
125
+ type: 'string',
126
+ default: '.',
127
+ describe: chalk.gray('The path to execute the transform in (recursively).'),
128
+ });
129
+ })
123
130
  .demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
124
131
  .strictCommands()
125
132
  .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.1303-next.0",
5
+ "version": "15.0.0-alpha.1326-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": "4dc1e2083d2767fd402c2d014bedd8b35a014490"
49
+ "gitHead": "9cdfd5792eab2f74d194662da6b9957fdf573654"
50
50
  }