import { ImportDeclaration , SourceFile , Project } from 'ts-simple-ast' ; import { deduplicateArray } from '../utilities/deduplicate-array' ; /**
 * Import Analyzer
 */ export class ImportAnalyzer { param typescriptProject returns public static getExternalImportSources ( typescriptProject ) { const externalImportSources = typescriptProject . getSourceFiles ( ) . reduce ( ( externalImportSources , sourceFile ) : Array < string > => { return [ ... externalImportSources , ... this . getExternalImportSourcesOfFile ( sourceFile ) , ] ; } , [ ] ) ; return deduplicateArray ( externalImportSources ) ; } param sourceFile returns private static getExternalImportSourcesOfFile ( sourceFile ) { return sourceFile . getImportDeclarations ( ) . filter ( this . isExternalImport ) . map ( this . getImportSource ) ; } param importDeclaration returns private static isExternalImport ( importDeclaration ) { return ! importDeclaration . isModuleSpecifierRelative ( ) ; } param importDeclaration returns private static getImportSource ( importDeclaration ) { return importDeclaration . getModuleSpecifier ( ) . getText ( ) . replace ( /['"`]/g , '' ) ; } }