@@ -34,6 +34,7 @@ namespace ts {
3434
3535 export interface EmitHost extends ScriptReferenceHost {
3636 getSourceFiles ( ) : SourceFile [ ] ;
37+ getFilesFromNodeModules ( ) : Map < boolean > ;
3738
3839 getCommonSourceDirectory ( ) : string ;
3940 getCanonicalFileName ( fileName : string ) : string ;
@@ -2274,9 +2275,10 @@ namespace ts {
22742275 }
22752276 else {
22762277 const sourceFiles = targetSourceFile === undefined ? host . getSourceFiles ( ) : [ targetSourceFile ] ;
2278+ const nodeModulesFiles = host . getFilesFromNodeModules ( ) ;
22772279 for ( const sourceFile of sourceFiles ) {
2278- // Don't emit if source file is a declaration file
2279- if ( ! isDeclarationFile ( sourceFile ) ) {
2280+ // Don't emit if source file is a declaration file, or was located under node_modules
2281+ if ( ! isDeclarationFile ( sourceFile ) && ! lookUp ( nodeModulesFiles , sourceFile . path ) ) {
22802282 onSingleFileEmit ( host , sourceFile ) ;
22812283 }
22822284 }
@@ -2308,11 +2310,14 @@ namespace ts {
23082310 }
23092311
23102312 function onBundledEmit ( host : EmitHost ) {
2311- // Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
2313+ // Can emit only sources that are not declaration file and are either non module code or module with
2314+ // --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
2315+ const nodeModulesFiles = host . getFilesFromNodeModules ( ) ;
23122316 const bundledSources = filter ( host . getSourceFiles ( ) ,
2313- sourceFile => ! isDeclarationFile ( sourceFile ) && // Not a declaration file
2314- ( ! isExternalModule ( sourceFile ) || // non module file
2315- ! ! getEmitModuleKind ( options ) ) ) ; // module that can emit - note falsy value from getEmitModuleKind means the module kind that shouldn't be emitted
2317+ sourceFile => ! isDeclarationFile ( sourceFile ) &&
2318+ ! lookUp ( nodeModulesFiles , sourceFile . path ) &&
2319+ ( ! isExternalModule ( sourceFile ) ||
2320+ ! ! getEmitModuleKind ( options ) ) ) ;
23162321 if ( bundledSources . length ) {
23172322 const jsFilePath = options . outFile || options . out ;
23182323 const emitFileNames : EmitFileNames = {
0 commit comments