@@ -8,6 +8,7 @@ var trace = require('util').debuglog(require('../package').name + '-trace');
8
8
var os = require ( 'os' ) ;
9
9
var path = require ( 'path' ) ;
10
10
var util = require ( 'util' ) ;
11
+ var semver = require ( 'semver' ) ;
11
12
12
13
module . exports = function ( ts ) {
13
14
function Host ( currentDirectory , opts ) {
@@ -81,7 +82,8 @@ module.exports = function (ts) {
81
82
contents : text ,
82
83
ts : file ,
83
84
root : root ,
84
- version : version
85
+ version : version ,
86
+ nodeModule : / \/ n o d e _ m o d u l e s \/ (? ! t y p e s c r i p t \/ ) / . test ( canonical )
85
87
} ;
86
88
this . emit ( 'file' , canonical , relative ) ;
87
89
@@ -158,6 +160,34 @@ module.exports = function (ts) {
158
160
return rootFilenames ;
159
161
}
160
162
163
+ Host . prototype . _nodeModuleFilenames = function ( ) {
164
+
165
+ var nodeModuleFilenames = [ ] ;
166
+
167
+ for ( var filename in this . files ) {
168
+ if ( ! Object . hasOwnProperty . call ( this . files , filename ) ) continue ;
169
+ if ( ! this . files [ filename ] . nodeModule ) continue ;
170
+ nodeModuleFilenames . push ( filename ) ;
171
+ }
172
+ return nodeModuleFilenames ;
173
+ }
174
+
175
+ Host . prototype . _compile = function ( opts ) {
176
+
177
+ var rootFilenames = this . _rootFilenames ( ) ;
178
+ var nodeModuleFilenames = [ ] ;
179
+
180
+ log ( 'Compiling files:' ) ;
181
+ rootFilenames . forEach ( function ( file ) { log ( ' %s' , file ) ; } ) ;
182
+
183
+ if ( semver . gte ( ts . version , '2.0.0' ) ) {
184
+ ts . createProgram ( rootFilenames , opts , this ) ;
185
+ nodeModuleFilenames = this . _nodeModuleFilenames ( ) ;
186
+ log ( ' + %d file(s) found in node_modules' , nodeModuleFilenames . length ) ;
187
+ }
188
+ return ts . createProgram ( rootFilenames . concat ( nodeModuleFilenames ) , opts , this ) ;
189
+ }
190
+
161
191
Host . prototype . _output = function ( filename ) {
162
192
163
193
var outputCanonical = this . _inferOutputCanonical ( filename ) ;
0 commit comments