@workday/canvas-kit-codemod 14.0.0-alpha.1206-next.0 → 14.0.0-alpha.1210-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es6/v14/index.d.ts.map +1 -1
- package/dist/es6/v14/index.js +3 -4
- package/dist/es6/v14/updateStatusIndicatorPreview.d.ts +3 -0
- package/dist/es6/v14/updateStatusIndicatorPreview.d.ts.map +1 -0
- package/dist/es6/v14/updateStatusIndicatorPreview.js +48 -0
- package/dist/es6/v14/utils/getImportRenameMap.d.ts +7 -0
- package/dist/es6/v14/utils/getImportRenameMap.d.ts.map +1 -0
- package/dist/es6/v14/utils/getImportRenameMap.js +44 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAItC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/es6/v14/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import updateStatusIndicatorPreview from './updateStatusIndicatorPreview';
|
|
1
2
|
const transform = (file, api, options) => {
|
|
2
3
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// ];
|
|
6
|
-
// return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source);
|
|
4
|
+
const fixes = [updateStatusIndicatorPreview];
|
|
5
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
7
6
|
};
|
|
8
7
|
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateStatusIndicatorPreview.d.ts","sourceRoot":"","sources":["../../../lib/v14/updateStatusIndicatorPreview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA4B,OAAO,EAAC,MAAM,aAAa,CAAC;AAkB7E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmD7E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
3
|
+
const packages = [
|
|
4
|
+
'@workday/canvas-kit-preview-react',
|
|
5
|
+
'@workday/canvas-kit-preview-react/status-indicator',
|
|
6
|
+
];
|
|
7
|
+
const packageImports = ['StatusIndicator'];
|
|
8
|
+
const variantMap = {
|
|
9
|
+
blue: 'info',
|
|
10
|
+
green: 'positive',
|
|
11
|
+
orange: 'caution',
|
|
12
|
+
red: 'critical',
|
|
13
|
+
gray: 'neutral',
|
|
14
|
+
};
|
|
15
|
+
export default function transformer(file, api, options) {
|
|
16
|
+
const j = api.jscodeshift;
|
|
17
|
+
const root = j(file.source);
|
|
18
|
+
// exit if the named imports aren't found
|
|
19
|
+
if (!hasImportSpecifiers(api, root, packages, packageImports)) {
|
|
20
|
+
return file.source;
|
|
21
|
+
}
|
|
22
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
23
|
+
// and give us an importMap to track what identifiers we need to update
|
|
24
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-preview-react');
|
|
25
|
+
// Find all <StatusIndicator> components
|
|
26
|
+
const components = root.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
27
|
+
(value.openingElement.name.name === importMap.StatusIndicator ||
|
|
28
|
+
value.openingElement.name.name === styledMap.StatusIndicator));
|
|
29
|
+
// Update the `variant` prop to the new value
|
|
30
|
+
components.forEach(component => {
|
|
31
|
+
var _a;
|
|
32
|
+
const variantProp = (_a = component.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
|
|
33
|
+
// For string literals like `variant="blue"`
|
|
34
|
+
if (variantProp && variantProp.value && variantProp.value.type === 'StringLiteral') {
|
|
35
|
+
variantProp.value = j.stringLiteral(variantMap[variantProp.value.value] || variantProp.value.value);
|
|
36
|
+
}
|
|
37
|
+
// For object literals like `variant={'blue'}`
|
|
38
|
+
if (variantProp &&
|
|
39
|
+
variantProp.value &&
|
|
40
|
+
variantProp.value.type === 'JSXExpressionContainer' &&
|
|
41
|
+
(variantProp.value.expression.type === 'Literal' ||
|
|
42
|
+
variantProp.value.expression.type === 'StringLiteral')) {
|
|
43
|
+
variantProp.value = j.stringLiteral(variantMap[variantProp.value.expression.value] ||
|
|
44
|
+
String(variantProp.value.expression.value));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return root.toSource();
|
|
48
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Collection, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, mainPackage?: string, packageName?: string): {
|
|
3
|
+
containsCanvasImports: boolean;
|
|
4
|
+
importMap: Record<string, string>;
|
|
5
|
+
styledMap: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getImportRenameMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v14/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,WAAW,EACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,SAA8B,EACzC,WAAW,SAAK;;;;EAuDjB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function getImportRenameMap(j, root, mainPackage = '@workday/canvas-kit-react', packageName = '') {
|
|
2
|
+
let containsCanvasImports = false;
|
|
3
|
+
// build import name remapping - in case someone renamed imports...
|
|
4
|
+
// i.e. `import { IconButton as StyledIconButton } ...`
|
|
5
|
+
const importMap = {};
|
|
6
|
+
const styledMap = {};
|
|
7
|
+
root.find(j.ImportDeclaration, node => {
|
|
8
|
+
// imports our module
|
|
9
|
+
const value = node.source.value;
|
|
10
|
+
if (typeof value === 'string' &&
|
|
11
|
+
(value === mainPackage || value.startsWith(mainPackage) || value === packageName)) {
|
|
12
|
+
containsCanvasImports = true;
|
|
13
|
+
(node.specifiers || []).forEach(specifier => {
|
|
14
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
15
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
16
|
+
importMap[specifier.imported.name] = specifier.imported.name;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
importMap[specifier.imported.name] = specifier.local.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
root
|
|
27
|
+
.find(j.CallExpression, (node) => node.callee.type === 'Identifier' &&
|
|
28
|
+
node.callee.name === 'styled' &&
|
|
29
|
+
node.arguments[0].type === 'Identifier')
|
|
30
|
+
.forEach(nodePath => {
|
|
31
|
+
// const StyledName = styled(OriginalName)({})
|
|
32
|
+
// const StyledName = styled(OriginalName)`` // Tagged template
|
|
33
|
+
if ((nodePath.parent.value.type === 'CallExpression' ||
|
|
34
|
+
nodePath.parent.value.type === 'TaggedTemplateExpression') &&
|
|
35
|
+
nodePath.parent.parent.value.type === 'VariableDeclarator' &&
|
|
36
|
+
nodePath.parent.parent.value.id.type === 'Identifier') {
|
|
37
|
+
const styledName = nodePath.parent.parent.value.id.name;
|
|
38
|
+
if (nodePath.value.arguments[0].type === 'Identifier') {
|
|
39
|
+
styledMap[nodePath.value.arguments[0].name] = styledName;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return { containsCanvasImports, importMap, styledMap };
|
|
44
|
+
}
|
package/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.0.0-alpha.
|
|
5
|
+
"version": "14.0.0-alpha.1210-next.0",
|
|
6
6
|
"description": "A collection of codemods for use on Workday Canvas Kit packages.",
|
|
7
7
|
"main": "dist/es6/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"resolutions": {
|
|
47
47
|
"recast": "0.20.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8ef8c7a0b7515a9341550c564b84bed91598e9f7"
|
|
50
50
|
}
|