@@ -18,32 +18,23 @@ export function emitTranspiledFiles(
1818) : OutputFile [ ] {
1919 let { rootDir, outDir, outFile, luaLibImport } = options ;
2020
21- if ( rootDir === undefined ) {
22- const configFileName = options . configFilePath as string | undefined ;
23- // TODO: Use getCommonSourceDirectory
24- rootDir = configFileName ? path . dirname ( configFileName ) : process . cwd ( ) ;
25- }
21+ const configFileName = options . configFilePath as string | undefined ;
22+ // TODO: Use getCommonSourceDirectory
23+ const baseDir = configFileName ? path . dirname ( configFileName ) : process . cwd ( ) ;
2624
27- if ( outDir === undefined ) {
28- outDir = rootDir ;
29- }
25+ rootDir = rootDir || baseDir ;
26+ outDir = outDir ? path . resolve ( baseDir , outDir ) : rootDir ;
3027
3128 const files : OutputFile [ ] = [ ] ;
3229 for ( const [ fileName , { lua, sourceMap, declaration, declarationMap } ] of transpiledFiles ) {
3330 let outPath = fileName ;
3431 if ( outDir !== rootDir ) {
35- const relativeSourcePath = path . resolve ( fileName ) . replace ( path . resolve ( rootDir ) , "" ) ;
36- outPath = path . join ( outDir , relativeSourcePath ) ;
32+ outPath = path . resolve ( outDir , path . relative ( rootDir , fileName ) ) ;
3733 }
3834
3935 // change extension or rename to outFile
4036 if ( outFile ) {
41- if ( path . isAbsolute ( outFile ) ) {
42- outPath = outFile ;
43- } else {
44- // append to workingDir or outDir
45- outPath = path . resolve ( outDir , outFile ) ;
46- }
37+ outPath = path . isAbsolute ( outFile ) ? outFile : path . resolve ( baseDir , outFile ) ;
4738 } else {
4839 outPath = trimExt ( outPath ) + ".lua" ;
4940 }
@@ -75,10 +66,9 @@ export function emitTranspiledFiles(
7566 ) ;
7667 }
7768
78- let outPath = path . resolve ( path . join ( rootDir , "lualib_bundle.lua" ) ) ;
69+ let outPath = path . resolve ( rootDir , "lualib_bundle.lua" ) ;
7970 if ( outDir !== rootDir ) {
80- const relativeSourcePath = path . resolve ( outPath ) . replace ( path . resolve ( rootDir ) , "" ) ;
81- outPath = path . join ( outDir , relativeSourcePath ) ;
71+ outPath = path . join ( outDir , path . relative ( rootDir , outPath ) ) ;
8272 }
8373
8474 files . push ( { name : normalizeSlashes ( outPath ) , text : lualibContent } ) ;
0 commit comments