import * as ts from 'typescript' ; export class HostBase implements ts . CompilerHost { fileExists ( fileName ) { return false ; } directoryExists ( directoryName ) { return false ; } readFile ( fileName ) { return null ; } getSourceFile ( fileName , languageVersion , onError ? ) { return null ; } writeFile ( name , text , writeByteOrderMark ) { } useCaseSensitiveFileNames ( ) { return false ; } getCanonicalFileName ( fileName ) { return fileName ; } getCurrentDirectory ( ) { return '' ; } getNewLine ( ) { return '\n' ; } getDefaultLibFileName ( options ) { return 'lib.d.ts' ; } getCancellationToken ( ) { return null ; } getDirectories ( path ) { return [ ] ; } } export class ChainableHost extends HostBase { protected source : ts . CompilerHost = null ; setSource ( source ) { if ( this . source === null ) { this . source = source ; } else { throw new Error ( `A chainable host can be connected to a source only once. It looks like you're trying to include the same instance in multiple chains.` ) ; } } fileExists ( fileName ) { return this . source . fileExists ( fileName ) ; } directoryExists ( directoryName ) { return this . source . directoryExists ( directoryName ) ; } getCurrentDirectory ( ) { return this . source . getCurrentDirectory ( ) ; } readFile ( fileName ) { return this . source . readFile ( fileName ) ; } getSourceFile ( fileName , languageVersion , onError ? ) { return this . source . getSourceFile ( fileName , languageVersion , onError ) ; } writeFile ( name , text , writeByteOrderMark ) { this . source . writeFile ( name , text , writeByteOrderMark ) ; } getDirectories ( path ) { return this . source . getDirectories ( path ) ; } } export function chainHosts ( host0 , ... chainableHosts ) { return chainableHosts . reduce ( ( acc , chainableHost ) => { chainableHost . setSource ( acc ) ; return chainableHost ; } , host0 as ChainableHost ) ; }