@@ -34,6 +34,7 @@ namespace ts {
34
34
35
35
export interface EmitHost extends ScriptReferenceHost {
36
36
getSourceFiles ( ) : SourceFile [ ] ;
37
+ getFilesFromNodeModules ( ) : Map < boolean > ;
37
38
38
39
getCommonSourceDirectory ( ) : string ;
39
40
getCanonicalFileName ( fileName : string ) : string ;
@@ -2274,9 +2275,10 @@ namespace ts {
2274
2275
}
2275
2276
else {
2276
2277
const sourceFiles = targetSourceFile === undefined ? host . getSourceFiles ( ) : [ targetSourceFile ] ;
2278
+ const nodeModulesFiles = host . getFilesFromNodeModules ( ) ;
2277
2279
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 ) ) {
2280
2282
onSingleFileEmit ( host , sourceFile ) ;
2281
2283
}
2282
2284
}
@@ -2308,11 +2310,14 @@ namespace ts {
2308
2310
}
2309
2311
2310
2312
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 ( ) ;
2312
2316
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 ) ) ) ;
2316
2321
if ( bundledSources . length ) {
2317
2322
const jsFilePath = options . outFile || options . out ;
2318
2323
const emitFileNames : EmitFileNames = {
0 commit comments