@@ -53,13 +53,35 @@ function getTsCompilerOptions(): ts.CompilerOptions {
5353 } ;
5454}
5555
56+ /**
57+ * stripExternalName is used to remove external workspace identifiers from bazel
58+ * paths. This allows the filenames
59+ * BAZEL_BIN/external/io_bazel_rules_closure+/google3/third_party/javascript/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js
60+ * and
61+ * BAZEL_BIN/google3/third_party/javascript/safevalues/builders/html_sanitizer/sanitizer_table/sanitizer_table.js
62+ * to generate the same moduleName.
63+ *
64+ * @param moduleName the module name to strip
65+ * @returns
66+ */
67+ function stripExternalName ( moduleName : string ) : string {
68+ if ( ! moduleName . startsWith ( 'external.' ) ) {
69+ return moduleName ;
70+ }
71+ const parts = moduleName . split ( '.' ) ;
72+ if ( parts . length <= 2 ) {
73+ return moduleName ;
74+ }
75+ return parts . slice ( 2 ) . join ( '.' ) ;
76+ }
77+
5678function run (
5779 options : ts . CompilerOptions ,
5880 fileNames : string [ ] ,
5981 writeFile : ts . WriteFileCallback ,
6082) : tsickle . EmitResult {
61- // Use absolute paths to determine what files to process since files may be imported using
62- // relative or absolute paths
83+ // Use absolute paths to determine what files to process since files may be
84+ // imported using relative or absolute paths
6385 fileNames = fileNames . map ( i => path . resolve ( i ) ) ;
6486
6587 const compilerHost = ts . createCompilerHost ( options ) ;
@@ -73,9 +95,20 @@ function run(
7395 return ! filesToProcess . has ( path . resolve ( fileName ) ) ;
7496 } ,
7597 shouldIgnoreWarningsForPath : ( fileName : string ) => false ,
76- pathToModuleName : ( context , fileName ) =>
77- tsickle . pathToModuleName ( rootModulePath , context , fileName ) ,
78- fileNameToModuleId : ( fileName ) => path . relative ( rootModulePath , fileName ) ,
98+ pathToModuleName : ( context , fileName ) => {
99+ const moduleName = stripExternalName ( tsickle . pathToModuleName ( rootModulePath , context , fileName ) ) ;
100+ if ( DEBUG ) {
101+ console . log ( `pathToModuleName: ${ fileName } => ${ moduleName } ` ) ;
102+ }
103+ return moduleName ;
104+ } ,
105+ fileNameToModuleId : ( fileName ) => {
106+ const moduleId = path . relative ( rootModulePath , fileName ) ;
107+ if ( DEBUG ) {
108+ console . log ( `fileNameToModuleId: ${ fileName } => ${ moduleId } ` ) ;
109+ }
110+ return moduleId ;
111+ } ,
79112 googmodule : true ,
80113 transformDecorators : true ,
81114 transformTypesToClosure : true ,
@@ -109,8 +142,6 @@ async function main() {
109142 const execRoot = getExecRoot ( ) ;
110143 const externsPath = getExternsPath ( ) ;
111144
112- await listExecrootFiles ( ) ;
113-
114145 const args = process . argv . slice ( 2 ) ;
115146 const inputFiles = getInputFiles ( execRoot , args ) ;
116147 if ( inputFiles . length === 0 ) {
0 commit comments