import { API , FileInfo , Options } from 'jscodeshift' ; type NamedExport = string | { exported : string ; local : string ; } ; export type AddExportConfig = { namedExports : NamedExport [ ] ; relativePathname : string ; } ; export const getLocalAndExported = ( named ) => { if ( typeof named === 'string' ) { return { local : named , exported : named } ; } return { local : named . local , exported : named . exported } ; } ; export const addExportDeclarations = ( file , api , options ) => { const j = api . jscodeshift ; const root = j ( file . source ) ; const printOptions = options . printOptions || { quote : 'single' , trailingComma : false , lineTerminator : '\n' } ; const { config } = options ; const { namedExports , relativePathname } = config ; let specifiers = [ ] ; for ( const namedExport of namedExports ) { const { local , exported } = getLocalAndExported ( namedExport ) ; const specifier = j . exportSpecifier . from ( { exported : j . identifier ( exported ) , id : j . identifier ( local ) } ) ; specifiers = [ ... specifiers , specifier ] ; } const exportDeclaration = j . exportNamedDeclaration ( null , specifiers , j . literal ( relativePathname ) ) ; root . get ( ) . node . program . body . push ( exportDeclaration ) ; return root . toSource ( printOptions ) ; } ; export default addExportDeclarations ; export const parser = 'tsx' ;