@workday/canvas-kit-codemod
Advanced tools
Comparing version 5.0.0-beta.0-next.20 to 5.0.0-beta.2-next.0
@@ -5,3 +5,4 @@ import { Collection, JSCodeshift } from 'jscodeshift'; | ||
importMap: Record<string, string>; | ||
styledMap: Record<string, string>; | ||
}; | ||
//# sourceMappingURL=getImportRenameMap.d.ts.map |
@@ -5,2 +5,3 @@ export function getImportRenameMap(j, root, packageName) { | ||
var importMap = {}; | ||
var styledMap = {}; | ||
root.find(j.ImportDeclaration, function (node) { | ||
@@ -12,6 +13,9 @@ var value = node.source.value; | ||
(node.specifiers || []).forEach(function (specifier) { | ||
if (specifier.type === 'ImportSpecifier' && | ||
specifier.local && | ||
specifier.imported.name !== specifier.local.name) { | ||
importMap[specifier.local.name] = specifier.imported.name; | ||
if (specifier.type === 'ImportSpecifier') { | ||
if (!specifier.local || specifier.local.name === specifier.imported.name) { | ||
importMap[specifier.imported.name] = specifier.imported.name; | ||
} | ||
else { | ||
importMap[specifier.imported.name] = specifier.local.name; | ||
} | ||
} | ||
@@ -21,3 +25,23 @@ }); | ||
}); | ||
return { containsCanvasImports: containsCanvasImports, importMap: importMap }; | ||
root | ||
.find(j.CallExpression, function (node) { | ||
if (node.callee.type === 'Identifier' && | ||
node.callee.name === 'styled' && | ||
node.arguments[0].type === 'Identifier') { | ||
return true; | ||
} | ||
return false; | ||
}) | ||
.forEach(function (nodePath) { | ||
if ((nodePath.parent.value.type === 'CallExpression' || | ||
nodePath.parent.value.type === 'TaggedTemplateExpression') && | ||
nodePath.parent.parent.value.type === 'VariableDeclarator' && | ||
nodePath.parent.parent.value.id.type === 'Identifier') { | ||
var styledName = nodePath.parent.parent.value.id.name; | ||
if (nodePath.value.arguments[0].type === 'Identifier') { | ||
styledMap[nodePath.value.arguments[0].name] = styledName; | ||
} | ||
} | ||
}); | ||
return { containsCanvasImports: containsCanvasImports, importMap: importMap, styledMap: styledMap }; | ||
} |
@@ -18,2 +18,3 @@ var __assign = (this && this.__assign) || function () { | ||
import renameCoreImports from './renameCoreImports'; | ||
import compoundCard from './compoundCard'; | ||
export default function transformer(file, api, options) { | ||
@@ -27,4 +28,5 @@ var fixes = [ | ||
renameCoreImports, | ||
compoundCard, | ||
]; | ||
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source); | ||
} |
@@ -6,2 +6,3 @@ import { getImportRenameMap } from './getImportRenameMap'; | ||
'ButtonSize', | ||
'ButtonIconSize', | ||
'OutlineButtonVariant', | ||
@@ -115,2 +116,6 @@ 'DropdownButtonVariant', | ||
.remove(); | ||
var reverseImportMap = Object.keys(importMap).reduce(function (result, key) { | ||
result[importMap[key]] = key; | ||
return result; | ||
}, {}); | ||
function findEnumReplacement(node, candidates, matched) { | ||
@@ -123,4 +128,3 @@ if (candidates === void 0) { candidates = enumsToMap; } | ||
node.property.type === 'Identifier' && | ||
(node.object.name + "." + node.property.name + matched === candidate || | ||
importMap[node.object.name] + "." + node.property.name + matched === candidate)) { | ||
reverseImportMap[node.object.name] + "." + node.property.name + matched === candidate) { | ||
return enumsToMap[candidate]; | ||
@@ -164,3 +168,3 @@ } | ||
for (identifier in enumToLiteralUnionMap) { | ||
if (node.typeName.name === identifier || importMap[node.typeName.name] === identifier) { | ||
if (node.typeName.name === importMap[identifier]) { | ||
return enumToLiteralUnionMap[identifier]; | ||
@@ -167,0 +171,0 @@ } |
var renameDefaultMap = { | ||
'@workday/canvas-kit-react/button': 'Button', | ||
'@workday/canvas-kit-react/card': 'Card', | ||
}; | ||
@@ -4,0 +5,0 @@ export default function transformer(file, api, options) { |
@@ -27,3 +27,3 @@ import { getImportRenameMap } from './getImportRenameMap'; | ||
var elementName = (_d = (_c = (_b = (_a = nodePath.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.name; | ||
if (buttonNames.includes(elementName) || buttonNames.includes(importMap[elementName])) { | ||
if (buttonNames.map(function (n) { return importMap[n]; }).includes(elementName)) { | ||
return j.jsxIdentifier('ref'); | ||
@@ -30,0 +30,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "5.0.0-beta.0-next.20+00bac7ad", | ||
"version": "5.0.0-beta.2-next.0+53383d7e", | ||
"description": "A collection of codemods for use on Workday Canvas Kit packages.", | ||
@@ -42,3 +42,3 @@ "main": "dist/es6/index.js", | ||
}, | ||
"gitHead": "00bac7ad585e7685cfa8c99252675803e16cd166" | ||
"gitHead": "53383d7ebc0e0110a48c7833257ac04f276a62c8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
54666
37
863
2