import { API , FileInfo , Identifier } from 'jscodeshift' ; export default function transformer ( file , api ) { const j = api . jscodeshift ; const root = j ( file . source ) ; root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-react/core' } } ) . forEach ( nodePath => { nodePath . value . specifiers ?. forEach ( specifier => { if ( specifier . type === 'ImportSpecifier' ) { switch ( specifier . imported . name ) { case 'spacing' : specifier . imported . name = 'space' ; break ; case 'spacingNumbers' : specifier . imported . name = 'spaceNumbers' ; break ; case 'CanvasSpacing' : specifier . imported . name = 'CanvasSpace' ; break ; case 'CanvasSpacingValue' : specifier . imported . name = 'CanvasSpaceValues' ; break ; case 'CanvasSpacingNumber' : specifier . imported . name = 'CanvasSpaceNumbers' ; break ; default : break ; } } return specifier ; } ) ; return nodePath ; } ) ; const canvasKitImports = root . find ( j . ImportDeclaration ) . filter ( nodePath => { const importSource = nodePath . value . source . value ; return ( importSource === '@workday/canvas-kit-react/core' || importSource === '@workday/canvas-kit-react' ) ; } ) ; if ( ! canvasKitImports . length ) { return root . toSource ( ) ; } root . find ( j . MemberExpression , { object : { type : 'Identifier' , name : 'spacing' } } ) . forEach ( nodePath => { const identifier = nodePath . value . object as Identifier ; identifier . name = 'space' ; return nodePath ; } ) ; root . find ( j . MemberExpression , { object : { type : 'Identifier' , name : 'spacingNumbers' } } ) . forEach ( nodePath => { const identifier = nodePath . value . object as Identifier ; identifier . name = 'spaceNumbers' ; return nodePath ; } ) ; root . find ( j . MemberExpression , { object : { type : 'Identifier' , name : 'canvas' } } ) . forEach ( nodePath => { const objectProperty = nodePath . value . property as Identifier ; if ( objectProperty . name === 'spacing' ) { objectProperty . name = 'space' ; } if ( objectProperty . name === 'spacingNumbers' ) { objectProperty . name = 'spaceNumbers' ; } return nodePath ; } ) ; root . find ( j . TSTypeReference , { typeName : { type : 'Identifier' , name : 'CanvasSpacing' } } ) . forEach ( nodePath => { const identifier = nodePath . value . typeName as Identifier ; identifier . name = 'CanvasSpace' ; return nodePath ; } ) ; root . find ( j . TSTypeReference , { typeName : { type : 'Identifier' , name : 'CanvasSpacingNumber' } } ) . forEach ( nodePath => { const identifier = nodePath . value . typeName as Identifier ; identifier . name = 'CanvasSpaceNumbers' ; return nodePath ; } ) ; root . find ( j . TSTypeReference , { typeName : { type : 'Identifier' , name : 'CanvasSpacingValue' } } ) . forEach ( nodePath => { const identifier = nodePath . value . typeName as Identifier ; identifier . name = 'CanvasSpaceValues' ; return nodePath ; } ) ; return root . toSource ( ) ; }