@@ -4,14 +4,13 @@ var fs = require('fs');
44
55var espowerSource = require ( 'espower-source' ) ;
66var minimatch = require ( 'minimatch' ) ;
7+ var ts = require ( 'typescript' ) ;
78var TypeScriptSimple = require ( 'typescript-simple' ) . TypeScriptSimple ;
89
910function espowerTypeScript ( options ) {
1011 var separator = ( options . pattern . lastIndexOf ( '/' , 0 ) === 0 ) ? '' : '/' ;
1112 var pattern = options . cwd + separator + options . pattern ;
12- // TODO: load tsconfig.json
13- var tsconfig = options . tsconfig || { } ;
14- var compilerOptions = tsconfig . compilerOptions || { } ;
13+ var compilerOptions = convertCompilerOptions ( options . compilerOptions , options . basepath ) ;
1514 var tss = new TypeScriptSimple ( compilerOptions , false ) ;
1615
1716 require . extensions [ '.ts' ] = function ( localModule , filepath ) {
@@ -23,4 +22,18 @@ function espowerTypeScript(options) {
2322 } ;
2423}
2524
25+ function convertCompilerOptions ( compilerOptions , basepath ) {
26+ if ( ! compilerOptions ) {
27+ return null ;
28+ }
29+
30+ var basepath = basepath || process . cwd ( ) ;
31+ var converted = ts . convertCompilerOptionsFromJson ( compilerOptions , basepath ) ;
32+ if ( converted . errors && converted . errors . length > 0 ) {
33+ var msg = converted . errors . map ( function ( e ) { return e . messageText } ) . join ( ', ' ) ;
34+ throw new Error ( msg ) ;
35+ }
36+ return converted . options ;
37+ }
38+
2639module . exports = espowerTypeScript ;
0 commit comments