@@ -60,11 +60,20 @@ class Transpilation {
6060 private seenFiles = new Set < string > ( ) ;
6161 private files : ProcessedFile [ ] = [ ] ;
6262
63- constructor ( private emitHost : EmitHost , private program : ts . Program ) { }
64-
6563 private options = this . program . getCompilerOptions ( ) as CompilerOptions ;
66- private rootDir = this . program . getCommonSourceDirectory ( ) ;
67- private outDir = this . options . outDir ?? this . rootDir ;
64+ private rootDir : string ;
65+ private outDir : string ;
66+
67+ constructor ( private emitHost : EmitHost , private program : ts . Program ) {
68+ const { rootDir } = program . getCompilerOptions ( ) ;
69+ this . rootDir =
70+ // getCommonSourceDirectory ignores provided rootDir when TS6059 is emitted
71+ rootDir == null
72+ ? program . getCommonSourceDirectory ( )
73+ : ts . getNormalizedAbsolutePath ( rootDir , emitHost . getCurrentDirectory ( ) ) ;
74+
75+ this . outDir = this . options . outDir ?? this . rootDir ;
76+ }
6877
6978 public emit ( transpiledFiles : ProcessedFile [ ] ) : EmitFile [ ] {
7079 transpiledFiles . forEach ( file => this . seenFiles . add ( file . fileName ) ) ;
@@ -93,11 +102,9 @@ class Transpilation {
93102
94103 private handleProcessedFile ( file : ProcessedFile ) {
95104 const replacer : ResolveMacroReplacer = ( request : string ) => {
96- let basedir = path . dirname ( file . fileName ) ;
97- if ( basedir === "." ) basedir = this . emitHost . getCurrentDirectory ( ) ;
98105 let resolvedPath : string ;
99106 try {
100- const result = this . resolver . resolveSync ( { } , basedir , request ) ;
107+ const result = this . resolver . resolveSync ( { } , path . dirname ( file . fileName ) , request ) ;
101108 assert ( typeof result === "string" ) ;
102109 resolvedPath = result ;
103110 } catch ( error ) {
0 commit comments