@@ -4,7 +4,8 @@ var path = require('path');
44var ts = require ( 'typescript' ) ;
55
66var pattern = 'test/**/*.ts' ;
7- var packageData = require ( path . join ( process . cwd ( ) , 'package.json' ) ) ;
7+ var cwd = process . cwd ( ) ;
8+ var packageData = require ( path . join ( cwd , 'package.json' ) ) ;
89
910if ( packageData &&
1011 typeof packageData . directories === 'object' &&
@@ -13,21 +14,22 @@ if (packageData &&
1314 pattern = testDir + ( ( testDir . lastIndexOf ( '/' , 0 ) === 0 ) ? '' : '/' ) + '**/*.ts' ;
1415}
1516
16- var compilerOptions = findAndParseTsConfig ( process . cwd ( ) ) ;
17+ var tsconfigPath = ts . findConfigFile ( cwd ) ;
18+ var tsconfigBasepath = null ;
19+ var compilerOptions = null ;
20+ if ( tsconfigPath ) {
21+ compilerOptions = parseTsConfig ( tsconfigPath ) ;
22+ tsconfigBasepath = path . dirname ( tsconfigPath ) ;
23+ }
1724
1825require ( './index' ) ( {
19- cwd : process . cwd ( ) ,
26+ cwd : cwd ,
2027 pattern : pattern ,
21- compilerOptions : compilerOptions
28+ compilerOptions : compilerOptions ,
29+ basepath : tsconfigBasepath
2230} ) ;
2331
24- function findAndParseTsConfig ( cwd ) {
25- var tsconfigPath = ts . findConfigFile ( process . cwd ( ) ) ;
26- if ( ! tsconfigPath ) {
27- return null ;
28- }
29-
30- var compilerOptions = null ;
32+ function parseTsConfig ( tsconfigPath ) {
3133 var parsed = ts . parseConfigFileTextToJson ( tsconfigPath , fs . readFileSync ( tsconfigPath , 'utf8' ) ) ;
3234 if ( parsed . error ) {
3335 throw new Error ( parsed . error . messageText ) ;
@@ -37,10 +39,5 @@ function findAndParseTsConfig(cwd) {
3739 return null ;
3840 }
3941
40- var converted = ts . convertCompilerOptionsFromJson ( parsed . config . compilerOptions , process . cwd ( ) ) ;
41- if ( converted . errors && converted . errors . length > 0 ) {
42- var msg = converted . errors . map ( function ( e ) { return e . messageText } ) . join ( ', ' ) ;
43- throw new Error ( msg ) ;
44- }
45- return converted . options ;
42+ return parsed . config . compilerOptions ;
4643}
0 commit comments