import { API , ASTPath , FileInfo , ImportDeclaration , ImportSpecifier } from 'jscodeshift' ; export default function transformer ( file , api ) { const j = api . jscodeshift ; const root = j ( file . source ) ; const tokenImport = root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-react/tokens' } , } ) ; const commonImport = root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-react/common' } , } ) ; function transformTypeImports ( nodePath , specifier ) { if ( specifier . imported . name === 'type' ) { if ( tokenImport . paths ( ) . length ) { tokenImport . forEach ( tokenImportPath => { tokenImportPath . value . specifiers ?. push ( specifier ) ; } ) ; } else { nodePath . insertBefore ( j . importDeclaration ( [ specifier ] , j . stringLiteral ( '@workday/canvas-kit-react/tokens' ) ) ) ; } } } function transformStaticStateImports ( nodePath , specifier ) { if ( specifier . imported . name === 'StaticStates' ) { if ( commonImport . paths ( ) . length ) { commonImport . forEach ( tokenImportPath => { tokenImportPath . value . specifiers ?. push ( specifier ) ; } ) ; } else { nodePath . insertBefore ( j . importDeclaration ( [ specifier ] , j . stringLiteral ( '@workday/canvas-kit-react/common' ) ) ) ; } } } root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-labs-react/tokens' } } ) . forEach ( nodePath => { nodePath . value . specifiers ?. forEach ( specifier => { if ( specifier . type === 'ImportSpecifier' ) { transformTypeImports ( nodePath , specifier ) ; transformStaticStateImports ( nodePath , specifier ) ; } } ) ; return nodePath ; } ) ; root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-preview-react/tokens' } } ) . forEach ( nodePath => { nodePath . value . specifiers ?. forEach ( specifier => { if ( specifier . type === 'ImportSpecifier' ) { transformTypeImports ( nodePath , specifier ) ; transformStaticStateImports ( nodePath , specifier ) ; } } ) ; return nodePath ; } ) ; root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-labs-react/tokens' } } ) . remove ( ) ; root . find ( j . ImportDeclaration , { source : { value : '@workday/canvas-kit-preview-react/tokens' } } ) . remove ( ) ; return root . toSource ( ) ; }