@@ -17,7 +17,7 @@ import * as ts from './typescript';
1717import * as cliSupport from './cli_support' ;
1818import * as tsickle from './tsickle' ;
1919import { ModulesManifest } from './tsickle' ;
20- import { createSourceReplacingCompilerHost } from './util' ;
20+ import { getCommonParentDirectory } from './util' ;
2121
2222/** Tsickle settings passed on the command line. */
2323export interface Settings {
@@ -131,17 +131,20 @@ function loadTscConfig(args: string[]):
131131export function toClosureJS (
132132 options : ts . CompilerOptions , fileNames : string [ ] , settings : Settings ,
133133 writeFile ?: ts . WriteFileCallback ) : tsickle . EmitResult {
134- const compilerHost = ts . createCompilerHost ( options ) ;
135- const program = ts . createProgram ( fileNames , options , compilerHost ) ;
136134 // Use absolute paths to determine what files to process since files may be imported using
137135 // relative or absolute paths
138- const filesToProcess = new Set ( fileNames . map ( i => path . resolve ( i ) ) ) ;
136+ const absoluteFileNames = fileNames . map ( i => path . resolve ( i ) ) ;
137+
138+ const compilerHost = ts . createCompilerHost ( options ) ;
139+ const program = ts . createProgram ( fileNames , options , compilerHost ) ;
140+ const filesToProcess = new Set ( absoluteFileNames ) ;
141+ const rootModulePath = options . rootDir || getCommonParentDirectory ( absoluteFileNames ) ;
139142 const transformerHost : tsickle . TsickleHost = {
140143 shouldSkipTsickleProcessing : ( fileName : string ) => {
141144 return ! filesToProcess . has ( path . resolve ( fileName ) ) ;
142145 } ,
143146 shouldIgnoreWarningsForPath : ( fileName : string ) => false ,
144- pathToModuleName : cliSupport . pathToModuleName ,
147+ pathToModuleName : cliSupport . pathToModuleName . bind ( null , rootModulePath ) ,
145148 fileNameToModuleId : ( fileName ) => fileName ,
146149 es5Mode : true ,
147150 googmodule : true ,
0 commit comments