import ts , { factory } from 'typescript' ; import { ContentChange , ReplaceContentChange } from '../../../types' ; import { MigrationBase } from '../../../class' ; export class ImportEntryPointTrimMigration extends MigrationBase { run ( ) { const importDeclarationList = this . getImportDeclarationList ( ) ; const contentChangeList = [ ] ; for ( const importDeclaration of importDeclarationList ) { let tempImportDeclaration ; const packagePathList = this . getImportDeclarationPackageName ( importDeclaration ) . split ( '/' ) . filter ( item => item ) ; if ( packagePathList . length > 2 ) { tempImportDeclaration = this . updateImportDeclaration ( importDeclaration , this . createStringLiteral ( packagePathList . slice ( 0 , 2 ) . join ( '/' ) ) ) ; contentChangeList . push ( new ReplaceContentChange ( importDeclaration . getStart ( ) , importDeclaration . getWidth ( ) , this . printNodeContent ( tempImportDeclaration ) ) ) ; } } this . updateFileService . change ( this . sourceFile . fileName , contentChangeList ) ; } }