@workday/canvas-kit-codemod 7.1.4 → 7.2.0-427-next.2
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/README.md +41 -5
- package/dist/es6/v5/compoundCard.js +19 -22
- package/dist/es6/v5/getImportRenameMap.js +11 -12
- package/dist/es6/v5/index.js +2 -13
- package/dist/es6/v5/mapTypeTokensToNewHierarchy.js +62 -62
- package/dist/es6/v5/maps.js +2 -2
- package/dist/es6/v5/moveInputProvider.js +6 -6
- package/dist/es6/v5/recategorizeButtons.js +34 -35
- package/dist/es6/v5/removeButtonEnums.js +26 -28
- package/dist/es6/v5/removeDefaultImports.js +7 -7
- package/dist/es6/v5/renameButtonRefs.js +8 -8
- package/dist/es6/v5/renameCoreImports.js +10 -10
- package/dist/es6/v5/renameInputRefs.js +17 -21
- package/dist/es6/v5/renamePreviewTokenImports.js +10 -10
- package/dist/es6/v5/renameSpacing.js +18 -18
- package/dist/es6/v5/slashImports.js +31 -33
- package/dist/es6/v6/deprecateCookieBanner.js +3 -3
- package/dist/es6/v6/deprecateHeader.js +4 -4
- package/dist/es6/v6/deprecatePageHeader.js +3 -3
- package/dist/es6/v6/index.js +3 -14
- package/dist/es6/v6/moveAndRenameSearchBar.js +23 -29
- package/dist/es6/v6/renameCanvasDepthValue.js +3 -3
- package/dist/es6/v6/utils/index.js +28 -31
- package/dist/es6/v7/compoundActionBar.js +27 -39
- package/dist/es6/v7/compoundBanner.js +40 -43
- package/dist/es6/v7/index.js +3 -14
- package/dist/es6/v7/recategorizeIconButtons.js +27 -31
- package/dist/es6/v7/removePropFromPopper.js +14 -18
- package/dist/es6/v7/renameIconPosition.js +13 -17
- package/dist/es6/v7/renameIconRef.js +17 -21
- package/dist/es6/v7/renameLayoutImports.js +14 -14
- package/dist/es6/v7/updateDisclosureShowHide.js +22 -22
- package/dist/es6/v7/updateModelSignatures.js +21 -21
- package/dist/es6/v7/updateSegmentedControl.js +8 -11
- package/dist/es6/v7/updateTabs.js +8 -8
- package/dist/es6/v7/utils/getImportRenameMap.js +11 -12
- package/dist/es6/v7/utils/hasImportSpecifiers.js +9 -11
- package/dist/es6/v8/index.d.ts +4 -0
- package/dist/es6/v8/index.d.ts.map +1 -0
- package/dist/es6/v8/index.js +25 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts +4 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/promoteBreadcrumbs.js +56 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts +4 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts.map +1 -0
- package/dist/es6/v8/promoteComponentsToTesting.js +76 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts +3 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts.map +1 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.js +46 -0
- package/dist/es6/v8/removeDefaultImports.d.ts +3 -0
- package/dist/es6/v8/removeDefaultImports.d.ts.map +1 -0
- package/dist/es6/v8/removeDefaultImports.js +52 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts +3 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts.map +1 -0
- package/dist/es6/v8/renameLoadingAnimation.js +62 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts +3 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/restructureBreadcrumbs.js +55 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts +3 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateDrawer.js +103 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts +3 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateLayout.js +76 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts +3 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.js +79 -0
- package/dist/es6/v9/compoundToast.d.ts +3 -0
- package/dist/es6/v9/compoundToast.d.ts.map +1 -0
- package/dist/es6/v9/compoundToast.js +121 -0
- package/dist/es6/v9/deprecateStack.d.ts +3 -0
- package/dist/es6/v9/deprecateStack.d.ts.map +1 -0
- package/dist/es6/v9/deprecateStack.js +275 -0
- package/dist/es6/v9/index.d.ts +4 -0
- package/dist/es6/v9/index.d.ts.map +1 -0
- package/dist/es6/v9/index.js +16 -0
- package/dist/es6/v9/promoteToast.d.ts +4 -0
- package/dist/es6/v9/promoteToast.d.ts.map +1 -0
- package/dist/es6/v9/promoteToast.js +56 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts +4 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts.map +1 -0
- package/dist/es6/v9/promoteUseThemedRing.js +56 -0
- package/index.js +40 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Canvas Kit Codemods
|
|
2
2
|
|
|
3
|
-
This package is designed to help you migrate between major versions of Canvas Kit and adopt API
|
|
3
|
+
This package is designed to help you migrate between major versions of Canvas Kit and adopt API
|
|
4
|
+
changes.
|
|
4
5
|
|
|
5
6
|
## Usage
|
|
6
7
|
|
|
@@ -13,13 +14,18 @@ Commands (transforms):
|
|
|
13
14
|
canvas-kit-codemod v5 [path] Canvas Kit v4 > v5 migration transform
|
|
14
15
|
|
|
15
16
|
Options:
|
|
16
|
-
-
|
|
17
|
-
-
|
|
17
|
+
--ignore-config, Ignore files if they match patterns sourced from a config file [string]
|
|
18
|
+
--ignore-pattern, Ignore files that match a provided glob expression [string] [default: **/node_modules/**]
|
|
19
|
+
--verbose, Show more information about the transform process [number] [choices: 0, 1, 2] [default: 0]
|
|
20
|
+
-v, --version Show version number [boolean]
|
|
21
|
+
-h, --help Show help [boolean]
|
|
18
22
|
```
|
|
19
23
|
|
|
20
|
-
> Note: These codemods only work on .js, .jsx, .ts, and .tsx extensions. You may need to make some
|
|
24
|
+
> Note: These codemods only work on .js, .jsx, .ts, and .tsx extensions. You may need to make some
|
|
25
|
+
> manual changes in other file types (.json, .mdx, .md, etc.).
|
|
21
26
|
|
|
22
|
-
> Note: You may need to run your linter after executing the codemod, as it's resulting formatting
|
|
27
|
+
> Note: You may need to run your linter after executing the codemod, as it's resulting formatting
|
|
28
|
+
> (spacing, quotes, etc.) may not match your project's styling.
|
|
23
29
|
|
|
24
30
|
## Installation
|
|
25
31
|
|
|
@@ -29,3 +35,33 @@ Alternatively, you can install the codemod package and run it without npx.
|
|
|
29
35
|
> yarn add @workday/canvas-kit-codemod
|
|
30
36
|
> canvas-kit-codemod <transform> [path]
|
|
31
37
|
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
### Ignore Config
|
|
42
|
+
|
|
43
|
+
If you'd like to provide a configuration for files to ignore instead of a glob, use
|
|
44
|
+
`--ignore-config`.
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
> canvas-kit-codemod <transform> [path] --ignore-config=.gitignore
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Ignore Pattern
|
|
51
|
+
|
|
52
|
+
If you'd like to provide a glob to ignore files, use `--ignore-pattern`. By default, this is set to
|
|
53
|
+
ignore all `node_modules` directories.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
> canvas-kit-codemod <transform> [path] --ignore-pattern=**/dist/**
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Verbose
|
|
60
|
+
|
|
61
|
+
If you'd like to have more verbose logging to know which files are being parsed, use `--verbose`. By
|
|
62
|
+
default this is set to `0`.
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
# See all files being parsed
|
|
66
|
+
> canvas-kit-codemod <transform> [path] --verbose=2
|
|
67
|
+
```
|
|
@@ -3,22 +3,19 @@ function filterDefined(input) {
|
|
|
3
3
|
return !!input;
|
|
4
4
|
}
|
|
5
5
|
export default function transformer(file, api, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const j = api.jscodeshift;
|
|
7
|
+
const root = j(file.source);
|
|
8
|
+
const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/card');
|
|
9
9
|
if (!containsCanvasImports) {
|
|
10
10
|
return file.source;
|
|
11
11
|
}
|
|
12
12
|
root
|
|
13
|
-
.find(j.JSXElement,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
.forEach(function (nodePath) {
|
|
13
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
14
|
+
(value.openingElement.name.name === importMap.Card ||
|
|
15
|
+
value.openingElement.name.name === styledMap.Card))
|
|
16
|
+
.forEach(nodePath => {
|
|
19
17
|
// bail early if we find a `Card.Body` as a child
|
|
20
|
-
for (
|
|
21
|
-
var child = _a[_i];
|
|
18
|
+
for (const child of nodePath.value.children || []) {
|
|
22
19
|
if (child.type === 'JSXElement' &&
|
|
23
20
|
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
24
21
|
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
@@ -28,22 +25,22 @@ export default function transformer(file, api, options) {
|
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
|
|
28
|
+
const findAttribute = (name) => (item) => {
|
|
32
29
|
if (item.type === 'JSXAttribute' &&
|
|
33
30
|
item.name.type === 'JSXIdentifier' &&
|
|
34
31
|
item.name.name === name) {
|
|
35
32
|
return true;
|
|
36
33
|
}
|
|
37
34
|
return false;
|
|
38
|
-
};
|
|
39
|
-
|
|
35
|
+
};
|
|
36
|
+
const attributes = nodePath.value.openingElement.attributes;
|
|
40
37
|
if (attributes) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const header = attributes.find(findAttribute('heading'));
|
|
39
|
+
const id = attributes.find(findAttribute('headingId'));
|
|
40
|
+
const children = nodePath.value.children;
|
|
41
|
+
const depth = attributes.find(findAttribute('depth'));
|
|
45
42
|
// remove these attributes from the list - we'll add them as sub components
|
|
46
|
-
nodePath.value.openingElement.attributes = attributes.filter(
|
|
43
|
+
nodePath.value.openingElement.attributes = attributes.filter(item => {
|
|
47
44
|
if (item.type === 'JSXAttribute' &&
|
|
48
45
|
item.name.type === 'JSXIdentifier' &&
|
|
49
46
|
['heading', 'headingId'].includes(item.name.name)) {
|
|
@@ -60,9 +57,9 @@ export default function transformer(file, api, options) {
|
|
|
60
57
|
depth.value.expression.property.type === 'NumericLiteral') {
|
|
61
58
|
depth.value.expression = depth.value.expression.property;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const CardHeadingJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Card), j.jsxIdentifier('Heading'));
|
|
61
|
+
const CardBodyJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Card), j.jsxIdentifier('Body'));
|
|
62
|
+
const convertAttributeToChildren = (input) => {
|
|
66
63
|
var _a;
|
|
67
64
|
switch ((_a = input.value) === null || _a === void 0 ? void 0 : _a.type) {
|
|
68
65
|
case 'JSXExpressionContainer':
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export function getImportRenameMap(j, root, packageName) {
|
|
2
|
-
|
|
3
|
-
var containsCanvasImports = false;
|
|
1
|
+
export function getImportRenameMap(j, root, packageName = '') {
|
|
2
|
+
let containsCanvasImports = false;
|
|
4
3
|
// build import name remapping - in case someone renamed imports...
|
|
5
4
|
// i.e. `import { IconButton as StyledIconButton } ...`
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
root.find(j.ImportDeclaration,
|
|
5
|
+
const importMap = {};
|
|
6
|
+
const styledMap = {};
|
|
7
|
+
root.find(j.ImportDeclaration, node => {
|
|
9
8
|
// imports our module
|
|
10
|
-
|
|
9
|
+
const value = node.source.value;
|
|
11
10
|
if (typeof value === 'string' &&
|
|
12
11
|
(value === '@workday/canvas-kit-react' || value === packageName)) {
|
|
13
12
|
containsCanvasImports = true;
|
|
14
|
-
(node.specifiers || []).forEach(
|
|
13
|
+
(node.specifiers || []).forEach(specifier => {
|
|
15
14
|
if (specifier.type === 'ImportSpecifier') {
|
|
16
15
|
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
17
16
|
importMap[specifier.imported.name] = specifier.imported.name;
|
|
@@ -25,7 +24,7 @@ export function getImportRenameMap(j, root, packageName) {
|
|
|
25
24
|
return false; // keep the loop going
|
|
26
25
|
});
|
|
27
26
|
root
|
|
28
|
-
.find(j.CallExpression,
|
|
27
|
+
.find(j.CallExpression, (node) => {
|
|
29
28
|
if (node.callee.type === 'Identifier' &&
|
|
30
29
|
node.callee.name === 'styled' &&
|
|
31
30
|
node.arguments[0].type === 'Identifier') {
|
|
@@ -33,18 +32,18 @@ export function getImportRenameMap(j, root, packageName) {
|
|
|
33
32
|
}
|
|
34
33
|
return false;
|
|
35
34
|
})
|
|
36
|
-
.forEach(
|
|
35
|
+
.forEach(nodePath => {
|
|
37
36
|
// const StyledName = styled(OriginalName)({})
|
|
38
37
|
// const StyledName = styled(OriginalName)`` // Tagged template
|
|
39
38
|
if ((nodePath.parent.value.type === 'CallExpression' ||
|
|
40
39
|
nodePath.parent.value.type === 'TaggedTemplateExpression') &&
|
|
41
40
|
nodePath.parent.parent.value.type === 'VariableDeclarator' &&
|
|
42
41
|
nodePath.parent.parent.value.id.type === 'Identifier') {
|
|
43
|
-
|
|
42
|
+
const styledName = nodePath.parent.parent.value.id.name;
|
|
44
43
|
if (nodePath.value.arguments[0].type === 'Identifier') {
|
|
45
44
|
styledMap[nodePath.value.arguments[0].name] = styledName;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
|
-
return { containsCanvasImports
|
|
48
|
+
return { containsCanvasImports, importMap, styledMap };
|
|
50
49
|
}
|
package/dist/es6/v5/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import slashImports from './slashImports';
|
|
13
2
|
import removeDefaultImports from './removeDefaultImports';
|
|
14
3
|
// button codemods
|
|
@@ -32,7 +21,7 @@ import renamePreviewTokenImports from './renamePreviewTokenImports';
|
|
|
32
21
|
export default function transformer(file, api, options) {
|
|
33
22
|
// These will run in order. If your transform depends on others, place yours after dependent
|
|
34
23
|
// transforms
|
|
35
|
-
|
|
24
|
+
const fixes = [
|
|
36
25
|
slashImports,
|
|
37
26
|
removeDefaultImports,
|
|
38
27
|
removeButtonEnums,
|
|
@@ -46,5 +35,5 @@ export default function transformer(file, api, options) {
|
|
|
46
35
|
mapTypeTokensToNewHierarchy,
|
|
47
36
|
renamePreviewTokenImports,
|
|
48
37
|
];
|
|
49
|
-
return fixes.reduce(
|
|
38
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
50
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const legacyTypeLevelsMap = {
|
|
2
2
|
dataViz1: 'levels.title.large',
|
|
3
3
|
dataViz2: 'levels.heading.large',
|
|
4
4
|
h1: 'levels.heading.medium',
|
|
@@ -10,7 +10,7 @@ var legacyTypeLevelsMap = {
|
|
|
10
10
|
body2: 'levels.subtext.medium',
|
|
11
11
|
small: 'levels.subtext.medium',
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const legacyTypeFontSizesMap = {
|
|
14
14
|
dataViz1: 56,
|
|
15
15
|
dataViz2: 32,
|
|
16
16
|
h1: 28,
|
|
@@ -22,7 +22,7 @@ var legacyTypeFontSizesMap = {
|
|
|
22
22
|
body2: 12,
|
|
23
23
|
small: 12,
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
const betaTypeLevelsMap = {
|
|
26
26
|
brand1: 'levels.title.large',
|
|
27
27
|
brand2: 'levels.title.medium',
|
|
28
28
|
h1: 'levels.title.small',
|
|
@@ -34,7 +34,7 @@ var betaTypeLevelsMap = {
|
|
|
34
34
|
body2: 'levels.subtext.large',
|
|
35
35
|
small: 'levels.subtext.medium',
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
const betaTypeFontSizesMap = {
|
|
38
38
|
brand1: 56,
|
|
39
39
|
brand2: 48,
|
|
40
40
|
h1: 40,
|
|
@@ -46,7 +46,7 @@ var betaTypeFontSizesMap = {
|
|
|
46
46
|
body2: 14,
|
|
47
47
|
small: 12,
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
const fontWeightsMap = {
|
|
50
50
|
brand1: 'bold',
|
|
51
51
|
brand2: 'bold',
|
|
52
52
|
dataViz1: 'bold',
|
|
@@ -61,67 +61,67 @@ var fontWeightsMap = {
|
|
|
61
61
|
small: 'regular',
|
|
62
62
|
};
|
|
63
63
|
export default function transformer(file, api) {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const j = api.jscodeshift;
|
|
65
|
+
const root = j(file.source);
|
|
66
66
|
// Find all legacy `type` import statements from react/tokens
|
|
67
|
-
|
|
67
|
+
const legacyTypeImportSpecifiers = root
|
|
68
68
|
.find(j.ImportSpecifier, { imported: { name: 'type' } })
|
|
69
|
-
.filter(
|
|
70
|
-
|
|
69
|
+
.filter(nodePath => {
|
|
70
|
+
const parent = nodePath.parent.value;
|
|
71
71
|
// This extra filter ensures we aren't improperly transforming other variables
|
|
72
72
|
return parent.source.value === '@workday/canvas-kit-react/tokens';
|
|
73
73
|
});
|
|
74
74
|
// Find all beta `type` import statements from preview-react/tokens labs-react/tokens
|
|
75
|
-
|
|
75
|
+
const betaTypeImportSpecifiers = root
|
|
76
76
|
.find(j.ImportSpecifier, { imported: { name: 'type' } })
|
|
77
|
-
.filter(
|
|
78
|
-
|
|
77
|
+
.filter(nodePath => {
|
|
78
|
+
const parent = nodePath.parent.value;
|
|
79
79
|
// This extra filter ensures we aren't improperly transforming other variables
|
|
80
80
|
return (parent.source.value === '@workday/canvas-kit-preview-react/tokens' ||
|
|
81
81
|
parent.source.value === '@workday/canvas-kit-labs-react/tokens');
|
|
82
82
|
});
|
|
83
83
|
// Find all canvas import statements from react/tokens
|
|
84
|
-
|
|
84
|
+
const canvasImportDefaultSpecifiers = root
|
|
85
85
|
.find(j.ImportDefaultSpecifier, { local: { name: 'canvas' } })
|
|
86
|
-
.filter(
|
|
87
|
-
|
|
86
|
+
.filter(nodePath => {
|
|
87
|
+
const parent = nodePath.parent.value;
|
|
88
88
|
// This extra filter ensures we aren't improperly transforming other variables
|
|
89
89
|
return parent.source.value === '@workday/canvas-kit-react/tokens';
|
|
90
90
|
});
|
|
91
91
|
function updateFontFamily(nodePath, identifierName, isDefaultImport) {
|
|
92
|
-
|
|
92
|
+
const updatedProperty = j.memberExpression(j.identifier(identifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontFamilies'), j.identifier('default'), false), false), false);
|
|
93
93
|
if (isDefaultImport) {
|
|
94
94
|
return nodePath.parent.replace(j.memberExpression(j.identifier('canvas'), updatedProperty, false));
|
|
95
95
|
}
|
|
96
96
|
nodePath.parent.replace(updatedProperty);
|
|
97
97
|
}
|
|
98
98
|
function updateFontSize(nodePath, importSpecifierName, identifierName, typeMap, isDefaultImport) {
|
|
99
|
-
|
|
99
|
+
const updatedFontSizeValue = typeMap === 'legacy'
|
|
100
100
|
? legacyTypeFontSizesMap[identifierName]
|
|
101
101
|
: betaTypeFontSizesMap[identifierName];
|
|
102
|
-
|
|
102
|
+
const updatedProperty = j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontSizes'), j.literal(updatedFontSizeValue), true), false), false);
|
|
103
103
|
if (isDefaultImport) {
|
|
104
104
|
return nodePath.parent.replace(j.memberExpression(j.identifier('canvas'), updatedProperty, false));
|
|
105
105
|
}
|
|
106
106
|
nodePath.parent.replace(updatedProperty);
|
|
107
107
|
}
|
|
108
108
|
function updateFontWeight(nodePath, importSpecifierName, identifierName, isDefaultImport) {
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const updatedFontWeight = fontWeightsMap[identifierName];
|
|
110
|
+
const updatedProperty = j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier(updatedFontWeight)), false), false);
|
|
111
111
|
if (isDefaultImport) {
|
|
112
112
|
return nodePath.parent.replace(j.memberExpression(j.identifier('canvas'), updatedProperty, false));
|
|
113
113
|
}
|
|
114
114
|
nodePath.parent.replace(updatedProperty);
|
|
115
115
|
}
|
|
116
116
|
function replaceVariantProperties(nodePath, properties) {
|
|
117
|
-
|
|
117
|
+
const grandParentNodeType = nodePath.parent.parent.value.type;
|
|
118
118
|
// This covers variant object styles and variants in styled components />`
|
|
119
119
|
if (grandParentNodeType === 'JSXExpressionContainer' ||
|
|
120
120
|
grandParentNodeType === 'CallExpression') {
|
|
121
121
|
return nodePath.parent.replace(j.objectExpression(properties));
|
|
122
122
|
}
|
|
123
123
|
// And this covers all other variant transformations
|
|
124
|
-
properties.forEach(
|
|
124
|
+
properties.forEach((property, index) => {
|
|
125
125
|
if (index === 0) {
|
|
126
126
|
// Replace the first property provided
|
|
127
127
|
nodePath.parent.parent.replace(property);
|
|
@@ -142,10 +142,10 @@ export default function transformer(file, api) {
|
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
144
|
case 'button': {
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
const newFontWeightProperty = j.property('init', j.identifier('fontWeight'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('bold'), false), false), false));
|
|
146
|
+
const newFontWeightMemberExpression = j.memberExpression(j.identifier('canvas'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('bold'), false), false), false), false);
|
|
147
147
|
if (isDefaultImport) {
|
|
148
|
-
|
|
148
|
+
const newCanvasProperty = j.property('init', j.identifier('fontWeight'), newFontWeightMemberExpression);
|
|
149
149
|
return replaceVariantProperties(nodePath, [newCanvasProperty]);
|
|
150
150
|
}
|
|
151
151
|
// Replace the target node with the new fontWeight property
|
|
@@ -154,12 +154,12 @@ export default function transformer(file, api) {
|
|
|
154
154
|
}
|
|
155
155
|
case 'caps': {
|
|
156
156
|
// Create a new property: `fontWeight: {importSpecifierName}.properties.fontWeights.medium`
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const newFontWeightProperty = j.property('init', j.identifier('fontWeight'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('medium'), false), false), false));
|
|
158
|
+
const newFontWeightMemberExpression = j.memberExpression(j.identifier('canvas'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('medium'), false), false), false), false);
|
|
159
159
|
// Create a new property: `textTransform: 'uppercase'`
|
|
160
|
-
|
|
160
|
+
const newTextTransformProperty = j.property('init', j.identifier('textTransform'), j.literal('uppercase'));
|
|
161
161
|
if (isDefaultImport) {
|
|
162
|
-
|
|
162
|
+
const newCanvasProperty = j.property('init', j.identifier('fontWeight'), newFontWeightMemberExpression);
|
|
163
163
|
return replaceVariantProperties(nodePath, [newCanvasProperty, newTextTransformProperty]);
|
|
164
164
|
}
|
|
165
165
|
// Replace the target node with the new fontWeight and text transform properties
|
|
@@ -168,10 +168,10 @@ export default function transformer(file, api) {
|
|
|
168
168
|
}
|
|
169
169
|
case 'label': {
|
|
170
170
|
// Create a new property: `fontWeight: {importSpecifierName}.properties.fontWeights.medium`
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const newFontWeightProperty = j.property('init', j.identifier('fontWeight'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('medium'), false), false), false));
|
|
172
|
+
const newFontWeightMemberExpression = j.memberExpression(j.identifier('canvas'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('medium'), false), false), false), false);
|
|
173
173
|
if (isDefaultImport) {
|
|
174
|
-
|
|
174
|
+
const newCanvasProperty = j.property('init', j.identifier('fontWeight'), newFontWeightMemberExpression);
|
|
175
175
|
return replaceVariantProperties(nodePath, [newCanvasProperty]);
|
|
176
176
|
}
|
|
177
177
|
// Replace the target node with the new fontWeight property
|
|
@@ -179,10 +179,10 @@ export default function transformer(file, api) {
|
|
|
179
179
|
break;
|
|
180
180
|
}
|
|
181
181
|
case 'mono': {
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const newFontProperty = j.property('init', j.identifier('fontFamily'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontFamilies'), j.identifier('monospace'), false), false), false));
|
|
183
|
+
const newFontMemberExpression = j.memberExpression(j.identifier('canvas'), j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontFamilies'), j.identifier('monospace'), false), false), false), false);
|
|
184
184
|
if (isDefaultImport) {
|
|
185
|
-
|
|
185
|
+
const newCanvasProperty = j.property('init', j.identifier('fontFamily'), newFontMemberExpression);
|
|
186
186
|
return replaceVariantProperties(nodePath, [newCanvasProperty]);
|
|
187
187
|
}
|
|
188
188
|
replaceVariantProperties(nodePath, [newFontProperty]);
|
|
@@ -194,21 +194,21 @@ export default function transformer(file, api) {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
function updateTypeHierarchy(nodePath, identifierName, typeMap) {
|
|
197
|
-
|
|
197
|
+
const updatedTypeLevelProperty = typeMap === 'legacy'
|
|
198
198
|
? legacyTypeLevelsMap[identifierName]
|
|
199
199
|
: betaTypeLevelsMap[identifierName];
|
|
200
200
|
nodePath.value.property = j.identifier(updatedTypeLevelProperty);
|
|
201
201
|
}
|
|
202
202
|
function updateHeadingFontWeight(nodePath, importSpecifierName, legacy) {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const newFontWeightMemberExpression = j.memberExpression(j.identifier(importSpecifierName), j.memberExpression(j.identifier('properties'), j.memberExpression(j.identifier('fontWeights'), j.identifier('bold'), false), false), false);
|
|
204
|
+
const fontWeightProperty = j.property('init', j.identifier('fontWeight'), legacy
|
|
205
205
|
? j.memberExpression(j.identifier('canvas'), newFontWeightMemberExpression, false)
|
|
206
206
|
: newFontWeightMemberExpression);
|
|
207
207
|
if (nodePath.parent.parent.value.type === 'ObjectExpression') {
|
|
208
208
|
return nodePath.parent.parent.value.properties.push(fontWeightProperty);
|
|
209
209
|
}
|
|
210
210
|
else if (nodePath.parent.value.type === 'CallExpression') {
|
|
211
|
-
|
|
211
|
+
const typeArgIndex = nodePath.parent.value.arguments.indexOf(nodePath.value);
|
|
212
212
|
return nodePath.parent.value.arguments.splice(typeArgIndex + 1, 0, fontWeightProperty);
|
|
213
213
|
}
|
|
214
214
|
else if (nodePath.parent.value.type === 'JSXExpressionContainer') {
|
|
@@ -218,19 +218,19 @@ export default function transformer(file, api) {
|
|
|
218
218
|
// Run only if there are type imports from react/tokens
|
|
219
219
|
if (legacyTypeImportSpecifiers.paths().length) {
|
|
220
220
|
// Iterate over all type import specifiers and transform their corresponding member expressions
|
|
221
|
-
legacyTypeImportSpecifiers.forEach(
|
|
221
|
+
legacyTypeImportSpecifiers.forEach(importSpecifier => {
|
|
222
222
|
var _a;
|
|
223
223
|
// Use either the local or imported name for the import specifier
|
|
224
224
|
// e.g. `import { type as typeTokens } from '@workday/canvas-kit-react/tokens';`
|
|
225
225
|
// 'type' is the imported name, and 'typeTokens' is the local name
|
|
226
|
-
|
|
226
|
+
const importSpecifierName = ((_a = importSpecifier.value.local) === null || _a === void 0 ? void 0 : _a.name) || importSpecifier.value.imported.name;
|
|
227
227
|
// Find all member expressions using the specifier name
|
|
228
228
|
root
|
|
229
229
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: importSpecifierName } })
|
|
230
|
-
.forEach(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
.forEach(nodePath => {
|
|
231
|
+
const parentProperty = nodePath.parent.value.property;
|
|
232
|
+
const propertyIdentifier = nodePath.value.property;
|
|
233
|
+
const identifierName = propertyIdentifier.name;
|
|
234
234
|
// Handle font-family transformations
|
|
235
235
|
if (parentProperty && parentProperty.name === 'fontFamily') {
|
|
236
236
|
return updateFontFamily(nodePath, importSpecifierName);
|
|
@@ -245,7 +245,7 @@ export default function transformer(file, api) {
|
|
|
245
245
|
}
|
|
246
246
|
// Handle variant transformations
|
|
247
247
|
if (parentProperty && propertyIdentifier.name === 'variant') {
|
|
248
|
-
|
|
248
|
+
const variantName = parentProperty.name;
|
|
249
249
|
return updateVariant(nodePath, importSpecifierName, variantName);
|
|
250
250
|
}
|
|
251
251
|
// Handle type hierarchy transformations
|
|
@@ -262,15 +262,15 @@ export default function transformer(file, api) {
|
|
|
262
262
|
}
|
|
263
263
|
if (canvasImportDefaultSpecifiers.paths().length) {
|
|
264
264
|
// Only run if there are canvas default imports from react/tokens or labs-react/tokens
|
|
265
|
-
canvasImportDefaultSpecifiers.forEach(
|
|
265
|
+
canvasImportDefaultSpecifiers.forEach(importDefaultSpecifier => {
|
|
266
266
|
root
|
|
267
267
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: 'canvas' } })
|
|
268
|
-
.forEach(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
268
|
+
.forEach(nodePath => {
|
|
269
|
+
const grandParentProperty = nodePath.parent.parent.value.property;
|
|
270
|
+
const parentProperty = nodePath.parent.value.property;
|
|
271
|
+
const parentIdentifierName = parentProperty.name;
|
|
272
|
+
const propertyIdentifier = nodePath.value.property;
|
|
273
|
+
const identifierName = propertyIdentifier.name;
|
|
274
274
|
if (identifierName === 'type') {
|
|
275
275
|
// Handle font-family transformations
|
|
276
276
|
if (grandParentProperty && grandParentProperty.name === 'fontFamily') {
|
|
@@ -286,7 +286,7 @@ export default function transformer(file, api) {
|
|
|
286
286
|
}
|
|
287
287
|
// Handle variant transformations
|
|
288
288
|
if (parentProperty && parentProperty.name === 'variant') {
|
|
289
|
-
|
|
289
|
+
const variantName = grandParentProperty.name;
|
|
290
290
|
return updateVariant(nodePath.parent, 'type', variantName, true);
|
|
291
291
|
}
|
|
292
292
|
// Handle type hierarchy transformations
|
|
@@ -305,19 +305,19 @@ export default function transformer(file, api) {
|
|
|
305
305
|
// Only run if there are type imports from preview-react/tokens or labs-react/tokens
|
|
306
306
|
if (betaTypeImportSpecifiers.paths().length) {
|
|
307
307
|
// Iterate over all type import specifiers and transform their corresponding member expressions
|
|
308
|
-
betaTypeImportSpecifiers.forEach(
|
|
308
|
+
betaTypeImportSpecifiers.forEach(importSpecifier => {
|
|
309
309
|
var _a;
|
|
310
310
|
// Use either the local or imported name for the import specifier
|
|
311
311
|
// e.g. `import { type as typeTokens } from '@workday/canvas-kit-react/tokens';`
|
|
312
312
|
// 'type' is the imported name, and 'typeTokens' is the local name
|
|
313
|
-
|
|
313
|
+
const importSpecifierName = ((_a = importSpecifier.value.local) === null || _a === void 0 ? void 0 : _a.name) || importSpecifier.value.imported.name;
|
|
314
314
|
// Find all member expressions using the specifier name
|
|
315
315
|
root
|
|
316
316
|
.find(j.MemberExpression, { object: { type: 'Identifier', name: importSpecifierName } })
|
|
317
|
-
.forEach(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
.forEach(nodePath => {
|
|
318
|
+
const parentProperty = nodePath.parent.value.property;
|
|
319
|
+
const propertyIdentifier = nodePath.value.property;
|
|
320
|
+
const identifierName = propertyIdentifier.name;
|
|
321
321
|
// Handle font-family transformations
|
|
322
322
|
if (parentProperty && parentProperty.name === 'fontFamily') {
|
|
323
323
|
return updateFontFamily(nodePath, importSpecifierName);
|
|
@@ -332,7 +332,7 @@ export default function transformer(file, api) {
|
|
|
332
332
|
}
|
|
333
333
|
// Handle variant transformations
|
|
334
334
|
if (parentProperty && propertyIdentifier.name === 'variant') {
|
|
335
|
-
|
|
335
|
+
const variantName = parentProperty.name;
|
|
336
336
|
return updateVariant(nodePath, importSpecifierName, variantName);
|
|
337
337
|
}
|
|
338
338
|
// Handle type hierarchy transformations
|
package/dist/es6/v5/maps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const sourceMap = {
|
|
2
2
|
// React
|
|
3
3
|
'@workday/canvas-kit-react-action-bar': '@workday/canvas-kit-react/action-bar',
|
|
4
4
|
'@workday/canvas-kit-react-avatar': '@workday/canvas-kit-react/avatar',
|
|
@@ -66,7 +66,7 @@ export var sourceMap = {
|
|
|
66
66
|
'@workday/canvas-kit-labs-react-side-panel': '@workday/canvas-kit-labs-react/side-panel',
|
|
67
67
|
'@workday/canvas-kit-labs-react-tabs': '@workday/canvas-kit-labs-react/tabs',
|
|
68
68
|
};
|
|
69
|
-
export
|
|
69
|
+
export const bundleExportMap = {
|
|
70
70
|
canvas: '@workday/canvas-kit-react/core',
|
|
71
71
|
ActionBar: '@workday/canvas-kit-react/action-bar',
|
|
72
72
|
Avatar: '@workday/canvas-kit-react/avatar',
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export default function transformer(file, api) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const j = api.jscodeshift;
|
|
3
|
+
const root = j(file.source);
|
|
4
4
|
// Rename spacing imports
|
|
5
5
|
root
|
|
6
6
|
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react/tokens' } })
|
|
7
|
-
.forEach(
|
|
8
|
-
|
|
7
|
+
.forEach(importDeclaration => {
|
|
8
|
+
const specifiers = importDeclaration.value.specifiers;
|
|
9
9
|
// If `InputProvider` is the only import, change source to `/common`
|
|
10
10
|
if ((specifiers === null || specifiers === void 0 ? void 0 : specifiers.length) === 1) {
|
|
11
|
-
|
|
11
|
+
const specifier = specifiers[0];
|
|
12
12
|
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'InputProvider') {
|
|
13
13
|
importDeclaration.value.source.value = '@workday/canvas-kit-react/common';
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
// If `InputProvider` is not the only import, delete `InputProvider` specifier and create a new import declaration
|
|
18
|
-
specifiers === null || specifiers === void 0 ? void 0 : specifiers.forEach(
|
|
18
|
+
specifiers === null || specifiers === void 0 ? void 0 : specifiers.forEach((specifier, index) => {
|
|
19
19
|
var _a;
|
|
20
20
|
// Only iterate over named import statements
|
|
21
21
|
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'InputProvider') {
|