@workday/canvas-kit-codemod 14.1.8 → 14.1.9

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":"migrateDepthTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateDepthTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAWtC,QAAA,MAAM,SAAS,EAAE,SA6KhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateDepthTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateDepthTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAatC,QAAA,MAAM,SAAS,EAAE,SAqLhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -4,6 +4,7 @@ const canvasImportSources = [
4
4
  '@workday/canvas-kit-react/tokens',
5
5
  '@workday/canvas-depth-web',
6
6
  ];
7
+ const depthValues = ['0', '1', '2', '3', '4', '5', '6'];
7
8
  const transform = (file, api) => {
8
9
  const j = api.jscodeshift;
9
10
  const root = j(file.source);
@@ -28,24 +29,26 @@ const transform = (file, api) => {
28
29
  name: (name) => importDeclaration[name] === 'depth',
29
30
  },
30
31
  property: {
31
- type: 'NumericLiteral',
32
+ type: (type) => type === 'NumericLiteral' || type === 'StringLiteral',
33
+ value: (value) => ['0', '1', '2', '3', '4', '5', '6'].includes(`${value}`),
32
34
  },
33
35
  },
34
36
  })
35
37
  .replaceWith(nodePath => {
36
38
  const argument = nodePath.value.argument;
37
- if (argument.type === 'MemberExpression' && argument.property.type === 'NumericLiteral') {
39
+ if (argument.type === 'MemberExpression' &&
40
+ (argument.property.type === 'NumericLiteral' || argument.property.type === 'StringLiteral')) {
38
41
  const depthValue = argument.property.value;
39
- const isDepthNotZero = depthValue > 0;
42
+ const isDepthNotZero = `${depthValue}` !== '0';
40
43
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
41
44
  if (isDepthNotZero) {
42
45
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
43
46
  }
44
- return isDepthNotZero
45
- ? j.objectProperty(j.identifier('boxShadow'), j.callExpression(j.identifier('cssVar'), [
46
- j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(depthValue), true),
47
- ]))
48
- : j.objectProperty(j.identifier('boxShadow'), j.literal('none'));
47
+ return j.objectProperty(j.identifier('boxShadow'), isDepthNotZero
48
+ ? j.callExpression(j.identifier('cssVar'), [
49
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(parseInt(`${depthValue}`, 10)), true),
50
+ ])
51
+ : j.literal('none'));
49
52
  }
50
53
  return nodePath.value;
51
54
  });
@@ -58,16 +61,19 @@ const transform = (file, api) => {
58
61
  .replaceWith(nodePath => {
59
62
  if (nodePath.value.object.type === 'MemberExpression' &&
60
63
  nodePath.value.object.object.type === 'Identifier' &&
61
- nodePath.value.object.property.type === 'NumericLiteral') {
64
+ (nodePath.value.object.property.type === 'NumericLiteral' ||
65
+ (nodePath.value.object.property.type === 'StringLiteral' &&
66
+ depthValues.includes(nodePath.value.object.property.value)))) {
62
67
  const value = nodePath.value.object.property.value;
63
- if (value.toString() !== '0') {
68
+ const isNotZero = `${value}` !== '0';
69
+ if (isNotZero) {
64
70
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
65
71
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
66
72
  }
67
- return value.toString() === '0'
73
+ return !isNotZero
68
74
  ? j.literal('none')
69
75
  : j.callExpression(j.identifier('cssVar'), [
70
- j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(value), true),
76
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(parseInt(`${value}`, 10)), true),
71
77
  ]);
72
78
  }
73
79
  return nodePath.value;
@@ -82,13 +88,11 @@ const transform = (file, api) => {
82
88
  })
83
89
  .replaceWith(nodePath => {
84
90
  const mainWrapper = nodePath.value.object;
85
- if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
86
- const mainObject = mainWrapper;
87
- const mainName = mainObject.name;
91
+ if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] === 'depth') {
88
92
  const lowestProperty = nodePath.value.property;
89
- const importedName = importDeclaration[mainName];
90
- if (importedName === 'depth' && lowestProperty.type === 'NumericLiteral') {
91
- const isZero = lowestProperty.value.toString() === '0';
93
+ if (lowestProperty.type === 'NumericLiteral' ||
94
+ (lowestProperty.type === 'StringLiteral' && depthValues.includes(lowestProperty.value))) {
95
+ const isZero = `${lowestProperty.value}` === '0';
92
96
  if (!isZero) {
93
97
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
94
98
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
@@ -97,7 +101,7 @@ const transform = (file, api) => {
97
101
  j.property('init', j.identifier('boxShadow'), isZero
98
102
  ? j.literal('none')
99
103
  : j.callExpression(j.identifier('cssVar'), [
100
- j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(lowestProperty.value), true),
104
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(parseInt(`${lowestProperty.value}`, 10)), true),
101
105
  ])),
102
106
  ]);
103
107
  }
@@ -165,9 +165,6 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
165
165
  }
166
166
  }
167
167
  }
168
- if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
169
- return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
170
- }
171
168
  if (property.type === 'ObjectProperty' &&
172
169
  property.key.type === 'Identifier' &&
173
170
  property.value.type === 'MemberExpression' &&
@@ -190,5 +187,8 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
190
187
  }
191
188
  }
192
189
  }
190
+ if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
191
+ return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
192
+ }
193
193
  return property;
194
194
  };
@@ -1 +1 @@
1
- {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAUlD,QAAA,MAAM,SAAS,EAAE,SAwHhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AASlD,QAAA,MAAM,SAAS,EAAE,SA6GhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,5 @@
1
- import { addMissingImports, filterOutImports, getImports } from '../v13.2/utils';
1
+ import { addMissingImports, getImports } from '../v13.2/utils';
2
2
  import { transformObjectPropertyRecursively } from './utils/transformObjectPropertyRecursively';
3
- import { mapping } from '../v13.2/mapping';
4
3
  import baseMapping from './baseMapping';
5
4
  const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-tokens-web'];
6
5
  const transform = (file, api) => {
@@ -39,7 +38,8 @@ const transform = (file, api) => {
39
38
  .find(j.MemberExpression, (value) => {
40
39
  return (value.type === 'MemberExpression' &&
41
40
  checkImport(value.object.name) &&
42
- Object.keys(baseMapping).includes(value.property.name));
41
+ Object.keys(baseMapping).includes(value.property.name) &&
42
+ importDeclaration[value.object.name] === 'base');
43
43
  })
44
44
  .replaceWith(nodePath => {
45
45
  const mainWrapper = nodePath.value.object;
@@ -47,17 +47,15 @@ const transform = (file, api) => {
47
47
  const mainObject = mainWrapper;
48
48
  const mainName = mainObject.name;
49
49
  const lowestProperty = nodePath.value.property;
50
- const importedName = importDeclaration[mainName];
51
- const map = importedName === 'base' ? { type: 'base' } : mapping[importedName];
52
- if (map.type === 'base' && lowestProperty.type === 'Identifier') {
50
+ if (lowestProperty.type === 'Identifier') {
53
51
  const colorName = baseMapping[lowestProperty.name];
54
- if (mainName === 'base') {
52
+ if (mainName === 'base' && colorName) {
55
53
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
56
- return j.memberExpression(j.identifier(map.type), j.identifier(colorName));
54
+ return j.memberExpression(j.identifier('base'), j.identifier(colorName));
57
55
  }
58
56
  }
59
57
  }
60
- return nodePath;
58
+ return nodePath.value;
61
59
  });
62
60
  // Filter out base imports if no base tokens are used
63
61
  root
@@ -85,13 +83,6 @@ const transform = (file, api) => {
85
83
  return true;
86
84
  });
87
85
  });
88
- root
89
- .find(j.ImportDeclaration, {
90
- source: { value: (value) => canvasImportSources.includes(value) },
91
- })
92
- .forEach(nodePath => {
93
- filterOutImports({ root, j }, nodePath, 'colors');
94
- });
95
86
  return root.toSource();
96
87
  };
97
88
  export default transform;
@@ -1 +1 @@
1
- {"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v14-tokens/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAiDA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,KAC3B,GAuNF,CAAC"}
1
+ {"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v14-tokens/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAiDA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,KAC3B,GA6MF,CAAC"}
@@ -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
  };
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": "14.1.8",
5
+ "version": "14.1.9",
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": "ff982533fc1812c0ef704246fe432f9ec1164098"
49
+ "gitHead": "5c2ed669b828845673b6eac948b98b43da3286e2"
50
50
  }