import type * as d from '../../declarations' ; import ts from 'typescript' ; export const removeCollectionImports = ( compilerCtx ) : ts . TransformerFactory < ts . SourceFile > => { return ( ) => { return ( tsSourceFile ) => { let madeUpdates = false ; const statements = tsSourceFile . statements . slice ( ) ; for ( let i = statements . length - 1 ; i >= 0 ; i -- ) { const n = statements [ i ] ; if ( ts . isImportDeclaration ( n ) ) { if ( ! n . importClause && n . moduleSpecifier && ts . isStringLiteral ( n . moduleSpecifier ) ) { const importPath = n . moduleSpecifier . text ; const isCollectionImport = compilerCtx . collections . some ( ( c ) => { return c . collectionName === importPath || c . moduleId === importPath ; } ) ; if ( isCollectionImport ) { madeUpdates = true ; statements . splice ( i , 1 ) ; } } } } if ( madeUpdates ) { return ts . updateSourceFileNode ( tsSourceFile , statements ) ; } return tsSourceFile ; } ; } ; } ;