@workday/canvas-kit-codemod 13.2.41 → 13.2.43

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.
@@ -3,6 +3,63 @@ export declare const mapping: {
3
3
  readonly type: "base";
4
4
  readonly name: "colors";
5
5
  };
6
+ readonly commonColors: {
7
+ readonly type: "system";
8
+ readonly name: "commonColors";
9
+ readonly keys: {
10
+ readonly background: "system.color.bg.default";
11
+ readonly backgroundAlt: "system.color.bg.alt.default";
12
+ readonly focusOutline: "system.color.border.primary.default";
13
+ readonly focusBackground: "system.color.bg.primary.default";
14
+ readonly hoverBackground: "system.color.bg.alt.strong";
15
+ readonly divider: "system.color.border.divider";
16
+ };
17
+ };
18
+ readonly inputColors: {
19
+ readonly type: "system";
20
+ readonly name: "inputColors";
21
+ readonly keys: {
22
+ readonly background: "system.color.bg.default";
23
+ readonly border: "system.color.border.input.default";
24
+ readonly placeholder: "system.color.fg.muted.default";
25
+ readonly text: "system.color.fg.default";
26
+ readonly icon: "system.color.fg.muted.soft";
27
+ readonly iconHover: "system.color.fg.muted.stronger";
28
+ readonly selectionControlFill: "system.color.bg.primary.default";
29
+ readonly hoverBorder: "system.color.border.input.strong";
30
+ readonly focusBorder: "system.color.border.primary.default";
31
+ readonly disabled: {
32
+ readonly background: "system.color.bg.alt.softer";
33
+ readonly border: "system.color.border.input.strong";
34
+ readonly text: "system.color.fg.disabled";
35
+ readonly icon: "system.color.fg.disabled";
36
+ };
37
+ readonly error: {
38
+ readonly border: "system.color.border.critical.default";
39
+ readonly message: "system.color.fg.critical.default";
40
+ readonly icon: "system.color.fg.critical.default";
41
+ };
42
+ readonly alert: {
43
+ readonly border: "system.color.border.caution.default";
44
+ readonly message: "system.color.fg.caution.default";
45
+ readonly icon: "system.color.fg.caution.default";
46
+ };
47
+ };
48
+ };
49
+ readonly typeColors: {
50
+ readonly type: "system";
51
+ readonly name: "typeColors";
52
+ readonly keys: {
53
+ readonly body: "system.color.fg.default";
54
+ readonly heading: "system.color.fg.strong";
55
+ readonly hint: "system.color.fg.muted.soft";
56
+ readonly inverse: "system.color.fg.inverse";
57
+ readonly label: "system.color.fg.default";
58
+ readonly link: "system.color.fg.primary.default";
59
+ readonly selectHighlight: "system.color.fg.primary.default";
60
+ readonly selectHighlightInverse: "system.color.fg.inverse";
61
+ };
62
+ };
6
63
  readonly borderRadius: {
7
64
  readonly name: "shape";
8
65
  readonly type: "system";
@@ -215,7 +272,7 @@ export declare const systemColors: {
215
272
  licorice400: string;
216
273
  licorice500: string;
217
274
  };
218
- 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
275
+ 'border,borderColor,borderTop,borderTopColor,borderRight,borderRightColor,borderBottom,borderBottomColor,borderLeft,borderLeftColor,borderInlineColor,borderBlockColor,borderInline,borderInlineStart,borderInlineStartColor,borderInlineEnd,borderInlineEndColor,borderBlockStart,borderBlockStartColor,borderBlockEnd,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
219
276
  blackPepper400: string;
220
277
  blackPepper500: string;
221
278
  blueberry400: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/index.ts"],"names":[],"mappings":"AAqFA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBV,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/index.ts"],"names":[],"mappings":"AAqFA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFV,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC"}
@@ -83,6 +83,63 @@ export const mapping = {
83
83
  type: 'base',
84
84
  name: 'colors',
85
85
  },
86
+ commonColors: {
87
+ type: 'system',
88
+ name: 'commonColors',
89
+ keys: {
90
+ background: 'system.color.bg.default',
91
+ backgroundAlt: 'system.color.bg.alt.default',
92
+ focusOutline: 'system.color.border.primary.default',
93
+ focusBackground: 'system.color.bg.primary.default',
94
+ hoverBackground: 'system.color.bg.alt.strong',
95
+ divider: 'system.color.border.divider',
96
+ },
97
+ },
98
+ inputColors: {
99
+ type: 'system',
100
+ name: 'inputColors',
101
+ keys: {
102
+ background: 'system.color.bg.default',
103
+ border: 'system.color.border.input.default',
104
+ placeholder: 'system.color.fg.muted.default',
105
+ text: 'system.color.fg.default',
106
+ icon: 'system.color.fg.muted.soft',
107
+ iconHover: 'system.color.fg.muted.stronger',
108
+ selectionControlFill: 'system.color.bg.primary.default',
109
+ hoverBorder: 'system.color.border.input.strong',
110
+ focusBorder: 'system.color.border.primary.default',
111
+ disabled: {
112
+ background: 'system.color.bg.alt.softer',
113
+ border: 'system.color.border.input.strong',
114
+ text: 'system.color.fg.disabled',
115
+ icon: 'system.color.fg.disabled',
116
+ },
117
+ error: {
118
+ border: 'system.color.border.critical.default',
119
+ message: 'system.color.fg.critical.default',
120
+ icon: 'system.color.fg.critical.default',
121
+ },
122
+ alert: {
123
+ border: 'system.color.border.caution.default',
124
+ message: 'system.color.fg.caution.default',
125
+ icon: 'system.color.fg.caution.default',
126
+ },
127
+ },
128
+ },
129
+ typeColors: {
130
+ type: 'system',
131
+ name: 'typeColors',
132
+ keys: {
133
+ body: 'system.color.fg.default',
134
+ heading: 'system.color.fg.strong',
135
+ hint: 'system.color.fg.muted.soft',
136
+ inverse: 'system.color.fg.inverse',
137
+ label: 'system.color.fg.default',
138
+ link: 'system.color.fg.primary.default',
139
+ selectHighlight: 'system.color.fg.primary.default',
140
+ selectHighlightInverse: 'system.color.fg.inverse',
141
+ },
142
+ },
86
143
  borderRadius: {
87
144
  name: 'shape',
88
145
  type: 'system',
@@ -148,7 +205,7 @@ export const systemColors = {
148
205
  licorice400: 'system.color.fg.muted.strong',
149
206
  licorice500: 'system.color.fg.muted.stronger',
150
207
  },
151
- 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
208
+ 'border,borderColor,borderTop,borderTopColor,borderRight,borderRightColor,borderBottom,borderBottomColor,borderLeft,borderLeftColor,borderInlineColor,borderBlockColor,borderInline,borderInlineStart,borderInlineStartColor,borderInlineEnd,borderInlineEndColor,borderBlockStart,borderBlockStartColor,borderBlockEnd,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
152
209
  blackPepper400: 'system.color.border.contrast.default',
153
210
  blackPepper500: 'system.color.border.contrast.strong',
154
211
  blueberry400: 'system.color.border.primary.default',
@@ -1 +1 @@
1
- {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAQlD,QAAA,MAAM,SAAS,EAAE,SAuFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAiBlD,QAAA,MAAM,SAAS,EAAE,SA0JhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,10 @@
1
- import { addMissingImports, filterOutImports, transformObjectPropertyRecursively } from './utils';
1
+ import { addMissingImports, filterOutImports, transformObjectPropertyRecursively, varToMemberExpression, } from './utils';
2
2
  import { mapping } from './mapping';
3
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
3
+ const canvasImportSources = [
4
+ '@workday/canvas-kit-styling',
5
+ '@workday/canvas-kit-react/tokens',
6
+ '@workday/canvas-colors-web',
7
+ ];
4
8
  const transform = (file, api) => {
5
9
  const j = api.jscodeshift;
6
10
  const root = j(file.source);
@@ -11,7 +15,7 @@ const transform = (file, api) => {
11
15
  source: { value: (value) => canvasImportSources.includes(value) },
12
16
  })
13
17
  .forEach(nodePath => {
14
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
18
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath, 'colors') };
15
19
  });
16
20
  if (!Object.values(importDeclaration).includes('colors')) {
17
21
  return root.toSource();
@@ -26,7 +30,7 @@ const transform = (file, api) => {
26
30
  const name = nodePath.value.callee.name;
27
31
  const stylesDeclaration = nodePath.value.arguments[0];
28
32
  const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
29
- if (stylesDeclaration.type === 'ObjectExpression') {
33
+ if ((stylesDeclaration === null || stylesDeclaration === void 0 ? void 0 : stylesDeclaration.type) === 'ObjectExpression') {
30
34
  stylesDeclaration.properties = stylesDeclaration.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling));
31
35
  }
32
36
  });
@@ -35,21 +39,59 @@ const transform = (file, api) => {
35
39
  });
36
40
  root
37
41
  .find(j.MemberExpression, (value) => {
38
- return (value.type === 'MemberExpression' &&
39
- ((value.object.type === 'MemberExpression' &&
40
- value.object.object.type === 'MemberExpression' &&
41
- checkImport(value.object.object.object.name)) ||
42
- checkImport(value.object.name)));
42
+ // Matches: commonColors.background
43
+ const isTwoParts = value.type === 'MemberExpression' &&
44
+ value.object.type === 'Identifier' &&
45
+ checkImport(value.object.name);
46
+ // Matches: inputColors.disabled.border
47
+ const isThreeParts = value.type === 'MemberExpression' &&
48
+ value.object.type === 'MemberExpression' &&
49
+ value.object.object.type === 'Identifier' &&
50
+ checkImport(value.object.object.name);
51
+ return isTwoParts || isThreeParts;
43
52
  })
44
53
  .replaceWith(nodePath => {
54
+ var _a;
45
55
  const mainWrapper = nodePath.value.object;
46
- if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
56
+ if (mainWrapper.type === 'MemberExpression') {
57
+ const mainObject = mainWrapper.object;
58
+ const mainName = mainObject.type === 'Identifier' ? mainObject.name : '';
59
+ const mainProperty = mainWrapper.property;
60
+ const lowestProperty = nodePath.value.property;
61
+ const importedName = importDeclaration[mainName];
62
+ const map = mapping[importedName];
63
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' &&
64
+ importedName &&
65
+ importedName.toLowerCase().includes('colors') &&
66
+ mainProperty.type === 'Identifier' &&
67
+ lowestProperty.type === 'Identifier') {
68
+ const innerGroup = map.keys[mainProperty.name] || {};
69
+ const token = innerGroup[lowestProperty.name];
70
+ if (token) {
71
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
72
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
73
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, token)]);
74
+ }
75
+ }
76
+ }
77
+ if (mainWrapper.type === 'Identifier' &&
78
+ ((_a = importDeclaration[mainWrapper.name]) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('colors'))) {
47
79
  const mainObject = mainWrapper;
48
80
  const mainName = mainObject.name;
49
81
  const lowestProperty = nodePath.value.property;
50
82
  const importedName = importDeclaration[mainName];
51
83
  const map = mapping[importedName];
52
- if (map.type === 'base' && lowestProperty.type === 'Identifier') {
84
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'system' &&
85
+ lowestProperty.type === 'Identifier' &&
86
+ importedName !== 'inputColors') {
87
+ const token = map.keys[lowestProperty.name];
88
+ if (token && typeof token === 'string') {
89
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
90
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
91
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, token)]);
92
+ }
93
+ }
94
+ if ((map === null || map === void 0 ? void 0 : map.type) === 'base' && lowestProperty.type === 'Identifier') {
53
95
  addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
54
96
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
55
97
  return j.callExpression(j.identifier('cssVar'), [
@@ -57,7 +99,7 @@ const transform = (file, api) => {
57
99
  ]);
58
100
  }
59
101
  }
60
- return nodePath;
102
+ return nodePath.value;
61
103
  });
62
104
  return root.toSource();
63
105
  };
@@ -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;AAOtC,QAAA,MAAM,SAAS,EAAE,SAoKhB,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;AAWtC,QAAA,MAAM,SAAS,EAAE,SAoKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,5 +1,9 @@
1
1
  import { addMissingImports, filterOutImports } from './utils';
2
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
2
+ const canvasImportSources = [
3
+ '@workday/canvas-kit-styling',
4
+ '@workday/canvas-kit-react/tokens',
5
+ '@workday/canvas-depth-web',
6
+ ];
3
7
  const transform = (file, api) => {
4
8
  const j = api.jscodeshift;
5
9
  const root = j(file.source);
@@ -10,7 +14,7 @@ const transform = (file, api) => {
10
14
  source: { value: (value) => canvasImportSources.includes(value) },
11
15
  })
12
16
  .forEach(nodePath => {
13
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
17
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath, 'depth') };
14
18
  });
15
19
  if (!Object.values(importDeclaration).includes('depth')) {
16
20
  return root.toSource();
@@ -97,7 +101,7 @@ const transform = (file, api) => {
97
101
  ]);
98
102
  }
99
103
  }
100
- return nodePath;
104
+ return nodePath.value;
101
105
  });
102
106
  return root.toSource();
103
107
  };
@@ -1 +1 @@
1
- {"version":3,"file":"migrateOtherTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateOtherTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AAQpE,QAAA,MAAM,SAAS,EAAE,SA4KhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"migrateOtherTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateOtherTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AAcpE,QAAA,MAAM,SAAS,EAAE,SAqLhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
2
2
  import { mapping, systemColors } from './mapping';
3
- const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
3
+ const canvasImportSources = [
4
+ '@workday/canvas-kit-styling',
5
+ '@workday/canvas-kit-react/tokens',
6
+ '@workday/canvas-space-web',
7
+ ];
8
+ const tokens = ['space', 'borderRadius'];
4
9
  const transform = (file, api) => {
5
10
  const j = api.jscodeshift;
6
11
  const root = j(file.source);
@@ -11,9 +16,12 @@ const transform = (file, api) => {
11
16
  source: { value: (value) => canvasImportSources.includes(value) },
12
17
  })
13
18
  .forEach(nodePath => {
14
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
19
+ importDeclaration = {
20
+ ...importDeclaration,
21
+ ...filterOutImports(nodePath, tokens),
22
+ };
15
23
  });
16
- if (!Object.values(importDeclaration).some(value => value === 'space' || value === 'borderRadius')) {
24
+ if (!Object.values(importDeclaration).some(value => tokens.includes(value))) {
17
25
  return root.toSource();
18
26
  }
19
27
  root
@@ -23,11 +31,10 @@ const transform = (file, api) => {
23
31
  },
24
32
  })
25
33
  .forEach(nodePath => {
26
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
27
34
  const name = nodePath.value.callee.name;
28
35
  const stylesDeclaration = nodePath.value.arguments[0];
29
36
  const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
30
- if (stylesDeclaration.type === 'ObjectExpression') {
37
+ if ((stylesDeclaration === null || stylesDeclaration === void 0 ? void 0 : stylesDeclaration.type) === 'ObjectExpression') {
31
38
  const transformProperty = (property) => {
32
39
  var _a;
33
40
  if (property.type === 'ObjectProperty' &&
@@ -35,7 +42,7 @@ const transform = (file, api) => {
35
42
  property.value.type === 'MemberExpression' &&
36
43
  property.value.object.type === 'Identifier' &&
37
44
  property.value.property.type === 'Identifier' &&
38
- importDeclaration[property.value.object.name] === 'colors') {
45
+ tokens.includes(importDeclaration[property.value.object.name])) {
39
46
  const key = property.key.name;
40
47
  const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
41
48
  const { property: value } = property.value;
@@ -44,6 +51,7 @@ const transform = (file, api) => {
44
51
  if (!isCanvasKitStyling) {
45
52
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
46
53
  }
54
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
47
55
  return j.objectProperty(j.identifier(key), isCanvasKitStyling
48
56
  ? varToMemberExpression(j, colorToken)
49
57
  : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
@@ -57,11 +65,12 @@ const transform = (file, api) => {
57
65
  if (expr.type === 'MemberExpression' &&
58
66
  expr.object.type === 'Identifier' &&
59
67
  expr.property.type === 'Identifier' &&
60
- importDeclaration[expr.object.name] === 'colors') {
68
+ tokens.includes(importDeclaration[expr.object.name])) {
61
69
  const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _a === void 0 ? void 0 : _a[1];
62
70
  const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
63
71
  if (colorToken) {
64
72
  addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
73
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
65
74
  return j.callExpression(j.identifier('cssVar'), [
66
75
  varToMemberExpression(j, colorToken),
67
76
  ]);
@@ -89,23 +98,23 @@ const transform = (file, api) => {
89
98
  })
90
99
  .replaceWith(nodePath => {
91
100
  const mainWrapper = nodePath.value.object;
92
- if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
93
- const mainObject = mainWrapper;
94
- const mainName = mainObject.name;
101
+ if (mainWrapper.type === 'Identifier' &&
102
+ tokens.includes(importDeclaration[mainWrapper.name])) {
103
+ const mainName = mainWrapper.name;
95
104
  const lowestProperty = nodePath.value.property;
96
105
  const importedName = importDeclaration[mainName];
97
106
  const map = mapping[importedName];
98
- if (importedName !== 'depth') {
99
- if (map.type === 'system' && lowestProperty.type === 'Identifier') {
100
- addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
101
- addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
102
- return j.callExpression(j.identifier('cssVar'), [
103
- j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(map.keys[lowestProperty.name])),
104
- ]);
105
- }
107
+ if (['space', 'borderRadius'].includes(importedName) &&
108
+ (map === null || map === void 0 ? void 0 : map.type) === 'system' &&
109
+ lowestProperty.type === 'Identifier') {
110
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
111
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
112
+ return j.callExpression(j.identifier('cssVar'), [
113
+ j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(map.keys[lowestProperty.name])),
114
+ ]);
106
115
  }
107
116
  }
108
- return nodePath;
117
+ return nodePath.value;
109
118
  });
110
119
  return root.toSource();
111
120
  };
@@ -12,7 +12,7 @@ const transform = (file, api) => {
12
12
  source: { value: (value) => canvasImportSources.includes(value) },
13
13
  })
14
14
  .forEach(nodePath => {
15
- importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
15
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath, 'type') };
16
16
  });
17
17
  if (!Object.values(importDeclaration).includes('type')) {
18
18
  return root.toSource();
@@ -132,7 +132,7 @@ const transform = (file, api) => {
132
132
  }
133
133
  }
134
134
  }
135
- return nodePath;
135
+ return nodePath.value;
136
136
  });
137
137
  return root.toSource();
138
138
  };
@@ -1,3 +1,5 @@
1
1
  import { ASTPath, ImportDeclaration } from 'jscodeshift';
2
- export declare const filterOutImports: (nodePath: ASTPath<ImportDeclaration>) => Record<string, string>;
2
+ type ImportType = 'colors' | 'depth' | 'space' | 'type' | 'borderRadius';
3
+ export declare const filterOutImports: (nodePath: ASTPath<ImportDeclaration>, type: ImportType | ImportType[]) => Record<string, string>;
4
+ export {};
3
5
  //# sourceMappingURL=filterOutImports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,gBAAgB,aAAc,QAAQ,iBAAiB,CAAC,2BAwBpE,CAAC"}
1
+ {"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,KAAK,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC;AASzE,eAAO,MAAM,gBAAgB,aACjB,QAAQ,iBAAiB,CAAC,QAC9B,UAAU,GAAG,UAAU,EAAE,2BA2BhC,CAAC"}
@@ -1,14 +1,21 @@
1
- export const filterOutImports = (nodePath) => {
1
+ const canvasImportSources = [
2
+ '@workday/canvas-kit-react/tokens',
3
+ '@workday/canvas-colors-web',
4
+ '@workday/canvas-space-web',
5
+ '@workday/canvas-depth-web',
6
+ ];
7
+ export const filterOutImports = (nodePath, type) => {
2
8
  var _a, _b;
3
9
  const importName = {};
4
10
  nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(specifier => {
5
- var _a;
6
11
  if (specifier.type === 'ImportSpecifier' && specifier.local) {
7
12
  const localName = specifier.local.name.toString();
8
13
  const importedName = specifier.imported.name.toString();
9
14
  importName[localName] = importedName;
10
- return !(typeof nodePath.value.source.value === 'string' &&
11
- ((_a = nodePath.value.source.value) === null || _a === void 0 ? void 0 : _a.endsWith('tokens')));
15
+ return !(((typeof type === 'string' && importedName.toLowerCase().includes(type)) ||
16
+ type.includes(importedName)) &&
17
+ typeof nodePath.value.source.value === 'string' &&
18
+ canvasImportSources.includes(nodePath.value.source.value));
12
19
  }
13
20
  return true;
14
21
  });
@@ -1 +1 @@
1
- {"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAQ1D,CAAC"}
1
+ {"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAU1D,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export const varToMemberExpression = (j, value) => {
2
2
  const valuesKeys = value.split('.');
3
3
  return valuesKeys.reduce((acc, key, index) => {
4
- if (index === 0) {
4
+ if (!index) {
5
5
  return j.identifier(key);
6
6
  }
7
7
  return j.memberExpression(acc, j.identifier(key));
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": "13.2.41",
5
+ "version": "13.2.43",
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": "45cc5255aa2e83d7f1257ebca7b87ee0abb96689"
49
+ "gitHead": "90bc7321a9d24b04f2e816ab8d7d33cb81f2edb0"
50
50
  }