@workday/canvas-kit-codemod 14.1.6 → 14.1.8
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.
- package/dist/es6/v13.2/migrateTypeTokens.d.ts.map +1 -1
- package/dist/es6/v13.2/migrateTypeTokens.js +9 -7
- package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
- package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.js +68 -11
- package/dist/es6/v14-tokens/index.d.ts.map +1 -1
- package/dist/es6/v14-tokens/index.js +9 -2
- package/dist/es6/v14-tokens/migrateColorTokens.d.ts.map +1 -1
- package/dist/es6/v14-tokens/migrateColorTokens.js +2 -13
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateTypeTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateTypeTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AASpE,QAAA,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"migrateTypeTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateTypeTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AASpE,QAAA,MAAM,SAAS,EAAE,SA6OhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -92,7 +92,7 @@ const transform = (file, api) => {
|
|
|
92
92
|
return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
return nodePath;
|
|
95
|
+
return nodePath.value;
|
|
96
96
|
});
|
|
97
97
|
root
|
|
98
98
|
.find(j.MemberExpression, (value) => {
|
|
@@ -138,12 +138,14 @@ const transform = (file, api) => {
|
|
|
138
138
|
const { values } = mapping.type.keys.levels;
|
|
139
139
|
const levels = values[innerKey];
|
|
140
140
|
const lowestKey = lowestPropertyValue;
|
|
141
|
-
const tokens = levels[lowestKey];
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
const tokens = levels === null || levels === void 0 ? void 0 : levels[lowestKey];
|
|
142
|
+
if (tokens) {
|
|
143
|
+
const props = Object.entries(tokens).map(([key, value]) => {
|
|
144
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
145
|
+
return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
|
|
146
|
+
});
|
|
147
|
+
return j.objectExpression(props);
|
|
148
|
+
}
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,eACf,MAAM,EAAE,KACpB,GA2UF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mapping, systemColors } from '../mapping';
|
|
1
|
+
import { mapping, paletteNames, systemColors } from '../mapping';
|
|
2
2
|
import { addMissingImports } from './addMissingImports';
|
|
3
3
|
import { varToMemberExpression } from './varToMemberExpression';
|
|
4
4
|
export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling, tokenTypes) => {
|
|
@@ -62,6 +62,27 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
62
62
|
const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
|
|
63
63
|
const transformedExpressions = templateLiteral.expressions.map((expr) => {
|
|
64
64
|
var _a;
|
|
65
|
+
if (expr.type === 'CallExpression') {
|
|
66
|
+
expr.arguments = expr.arguments.map((arg) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (arg.type === 'MemberExpression' &&
|
|
69
|
+
arg.object.type === 'Identifier' &&
|
|
70
|
+
arg.object.name === 'colors' &&
|
|
71
|
+
arg.property.type === 'Identifier') {
|
|
72
|
+
const keyName = property.key.type === 'Identifier' ? property.key.name : null;
|
|
73
|
+
const tokens = keyName
|
|
74
|
+
? (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _a === void 0 ? void 0 : _a[1]
|
|
75
|
+
: {};
|
|
76
|
+
const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[arg.property.name];
|
|
77
|
+
if (colorToken) {
|
|
78
|
+
return isCanvasKitStyling
|
|
79
|
+
? varToMemberExpression(j, colorToken)
|
|
80
|
+
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return arg;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
65
86
|
if (expr.type === 'MemberExpression' &&
|
|
66
87
|
expr.object.type === 'Identifier' &&
|
|
67
88
|
expr.property.type === 'Identifier') {
|
|
@@ -74,9 +95,13 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
74
95
|
: null;
|
|
75
96
|
const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
|
|
76
97
|
if (colorToken) {
|
|
77
|
-
|
|
98
|
+
if (!isCanvasKitStyling) {
|
|
99
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
100
|
+
}
|
|
78
101
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
79
|
-
return
|
|
102
|
+
return isCanvasKitStyling
|
|
103
|
+
? varToMemberExpression(j, colorToken)
|
|
104
|
+
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
|
|
80
105
|
}
|
|
81
106
|
}
|
|
82
107
|
// Handle space and borderRadius tokens
|
|
@@ -88,10 +113,14 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
88
113
|
if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
|
|
89
114
|
const newValue = map.keys[propertyName];
|
|
90
115
|
if (newValue) {
|
|
91
|
-
|
|
116
|
+
if (!isCanvasKitStyling) {
|
|
117
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
118
|
+
}
|
|
92
119
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
93
120
|
const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
|
|
94
|
-
return
|
|
121
|
+
return isCanvasKitStyling
|
|
122
|
+
? tokenPath
|
|
123
|
+
: j.callExpression(j.identifier('cssVar'), [tokenPath]);
|
|
95
124
|
}
|
|
96
125
|
}
|
|
97
126
|
}
|
|
@@ -120,18 +149,46 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
120
149
|
const consequentColorToken = consequentTokens === null || consequentTokens === void 0 ? void 0 : consequentTokens[consequent.property.name];
|
|
121
150
|
const alternateColorToken = alternateTokens === null || alternateTokens === void 0 ? void 0 : alternateTokens[alternate.property.name];
|
|
122
151
|
if (consequentColorToken && alternateColorToken) {
|
|
123
|
-
|
|
152
|
+
if (!isCanvasKitStyling) {
|
|
153
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
154
|
+
}
|
|
124
155
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
125
|
-
return createObjectProperty(property.key, j.conditionalExpression(test,
|
|
126
|
-
varToMemberExpression(j, consequentColorToken)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
156
|
+
return createObjectProperty(property.key, j.conditionalExpression(test, isCanvasKitStyling
|
|
157
|
+
? varToMemberExpression(j, consequentColorToken)
|
|
158
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
159
|
+
varToMemberExpression(j, consequentColorToken),
|
|
160
|
+
]), isCanvasKitStyling
|
|
161
|
+
? varToMemberExpression(j, alternateColorToken)
|
|
162
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
163
|
+
varToMemberExpression(j, alternateColorToken),
|
|
164
|
+
])));
|
|
130
165
|
}
|
|
131
166
|
}
|
|
132
167
|
}
|
|
133
168
|
if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
|
|
134
169
|
return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
|
|
135
170
|
}
|
|
171
|
+
if (property.type === 'ObjectProperty' &&
|
|
172
|
+
property.key.type === 'Identifier' &&
|
|
173
|
+
property.value.type === 'MemberExpression' &&
|
|
174
|
+
property.value.object.type === 'Identifier' &&
|
|
175
|
+
property.value.property.type === 'Identifier') {
|
|
176
|
+
const importedTokenName = importDeclaration[property.value.object.name];
|
|
177
|
+
// Handle colors tokens
|
|
178
|
+
if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
|
|
179
|
+
const { property: value } = property.value;
|
|
180
|
+
if (paletteNames.some(name => value.name.includes(name))) {
|
|
181
|
+
if (!isCanvasKitStyling) {
|
|
182
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
183
|
+
}
|
|
184
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
185
|
+
return createObjectProperty(property.key, isCanvasKitStyling
|
|
186
|
+
? j.memberExpression(j.identifier('base'), j.identifier(value.name))
|
|
187
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
188
|
+
j.memberExpression(j.identifier('base'), j.identifier(value.name)),
|
|
189
|
+
]));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
136
193
|
return property;
|
|
137
194
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAQtC,QAAA,MAAM,SAAS,EAAE,SAShB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import migrateNewColorTokens from './migrateColorTokens';
|
|
2
|
+
import migrateColorTokens from '../v13.2/migrateColorTokens';
|
|
2
3
|
import migrateDepthTokens from '../v13.2/migrateDepthTokens';
|
|
3
4
|
import migrateOtherTokens from '../v13.2/migrateOtherTokens';
|
|
4
5
|
import migrateTypeTokens from '../v13.2/migrateTypeTokens';
|
|
5
6
|
const transform = (file, api, options) => {
|
|
6
|
-
const fixes = [
|
|
7
|
+
const fixes = [
|
|
8
|
+
migrateColorTokens,
|
|
9
|
+
migrateNewColorTokens,
|
|
10
|
+
migrateDepthTokens,
|
|
11
|
+
migrateTypeTokens,
|
|
12
|
+
migrateOtherTokens,
|
|
13
|
+
];
|
|
7
14
|
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
8
15
|
};
|
|
9
16
|
export default transform;
|
|
@@ -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;
|
|
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"}
|
|
@@ -2,11 +2,7 @@ import { addMissingImports, filterOutImports, getImports } from '../v13.2/utils'
|
|
|
2
2
|
import { transformObjectPropertyRecursively } from './utils/transformObjectPropertyRecursively';
|
|
3
3
|
import { mapping } from '../v13.2/mapping';
|
|
4
4
|
import baseMapping from './baseMapping';
|
|
5
|
-
const canvasImportSources = [
|
|
6
|
-
'@workday/canvas-kit-styling',
|
|
7
|
-
'@workday/canvas-kit-react/tokens',
|
|
8
|
-
'@workday/canvas-tokens-web',
|
|
9
|
-
];
|
|
5
|
+
const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-tokens-web'];
|
|
10
6
|
const transform = (file, api) => {
|
|
11
7
|
const j = api.jscodeshift;
|
|
12
8
|
const root = j(file.source);
|
|
@@ -19,7 +15,7 @@ const transform = (file, api) => {
|
|
|
19
15
|
.forEach(nodePath => {
|
|
20
16
|
importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
|
|
21
17
|
});
|
|
22
|
-
if (!Object.values(importDeclaration).some(importedValue => importedValue === '
|
|
18
|
+
if (!Object.values(importDeclaration).some(importedValue => importedValue === 'base')) {
|
|
23
19
|
return root.toSource();
|
|
24
20
|
}
|
|
25
21
|
root
|
|
@@ -55,13 +51,6 @@ const transform = (file, api) => {
|
|
|
55
51
|
const map = importedName === 'base' ? { type: 'base' } : mapping[importedName];
|
|
56
52
|
if (map.type === 'base' && lowestProperty.type === 'Identifier') {
|
|
57
53
|
const colorName = baseMapping[lowestProperty.name];
|
|
58
|
-
if (mainName === 'colors') {
|
|
59
|
-
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
60
|
-
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
61
|
-
return j.callExpression(j.identifier('cssVar'), [
|
|
62
|
-
j.memberExpression(j.identifier(map.type), j.identifier(colorName || lowestProperty.name)),
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
54
|
if (mainName === 'base') {
|
|
66
55
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
67
56
|
return j.memberExpression(j.identifier(map.type), j.identifier(colorName));
|
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.
|
|
5
|
+
"version": "14.1.8",
|
|
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": "
|
|
49
|
+
"gitHead": "ff982533fc1812c0ef704246fe432f9ec1164098"
|
|
50
50
|
}
|