11'use strict' ;
22
33var fs = require ( 'fs' ) ;
4+ var path = require ( 'path' ) ;
45
56var espowerSource = require ( 'espower-source' ) ;
67var minimatch = require ( 'minimatch' ) ;
78var ts = require ( 'typescript' ) ;
89var TypeScriptSimple = require ( 'typescript-simple' ) . TypeScriptSimple ;
910
1011function espowerTypeScript ( options ) {
12+ var cwd = options . cwd || process . cwd ( ) ;
1113 var separator = ( options . pattern . lastIndexOf ( '/' , 0 ) === 0 ) ? '' : '/' ;
12- var pattern = options . cwd + separator + options . pattern ;
13- var compilerOptions = convertCompilerOptions ( options . compilerOptions , options . basepath ) ;
14+ var pattern = cwd + separator + options . pattern ;
15+ var compilerOptions = convertCompilerOptions ( options . compilerOptions , options . basepath || cwd ) ;
1416 var tss = new TypeScriptSimple ( compilerOptions , false ) ;
1517
1618 function loadTypeScript ( localModule , filepath ) {
17- var result = tss . compile ( fs . readFileSync ( filepath , 'utf-8' ) ) ;
19+ var result = tss . compile ( fs . readFileSync ( filepath , 'utf-8' ) , path . relative ( cwd , filepath ) ) ;
1820 if ( minimatch ( filepath , pattern ) ) {
1921 result = espowerSource ( result , filepath , options ) ;
2022 }
@@ -30,7 +32,6 @@ function convertCompilerOptions(compilerOptions, basepath) {
3032 return null ;
3133 }
3234
33- var basepath = basepath || process . cwd ( ) ;
3435 var converted = ts . convertCompilerOptionsFromJson ( compilerOptions , basepath ) ;
3536 if ( converted . errors && converted . errors . length > 0 ) {
3637 var msg = converted . errors . map ( function ( e ) { return e . messageText } ) . join ( ', ' ) ;
0 commit comments