@@ -335,16 +335,52 @@ def fix_hermetic(relative_dir, hide_output=False):
335335 )
336336
337337
338+ def compile_protos (hide_output = False , is_esm = False ):
339+ """
340+ Compiles protos into .json, .js, and .d.ts files using
341+ compileProtos script from google-gax.
342+ """
343+ logger .debug ("Compiling protos..." )
344+ command = (
345+ ["npx" , "compileProtos" , "src" ]
346+ if not is_esm
347+ else ["npx" , "compileProtos" , "esm/src" , "--esm" ]
348+ )
349+ shell .run (command , hide_output = hide_output )
350+
351+
352+ def compile_protos_hermetic (relative_dir , is_esm = False , hide_output = False ):
353+ """
354+ Compiles protos into .json, .js, and .d.ts files using
355+ compileProtos script from google-gax. Assumes that compileProtos
356+ is already installed in a well known location on disk (node_modules/.bin).
357+ """
358+ logger .debug ("Compiling protos..." )
359+ command = (
360+ [f"{ _TOOLS_DIRECTORY } /node_modules/.bin/compileProtos" , "esm/src" , "--esm" ]
361+ if not is_esm
362+ else [f"{ _TOOLS_DIRECTORY } /node_modules/.bin/compileProtos" , "esm/src" , "--esm" ]
363+ )
364+ shell .run (
365+ command ,
366+ cwd = relative_dir ,
367+ check = True ,
368+ hide_output = hide_output ,
369+ )
370+
371+
338372def postprocess_gapic_library (hide_output = False , is_esm = False ):
339373 logger .debug ("Post-processing GAPIC library..." )
340374 install (hide_output = hide_output )
341375 fix (hide_output = hide_output )
376+ compile_protos (hide_output = hide_output , is_esm = is_esm )
342377 logger .debug ("Post-processing completed" )
343378
344379
345380def postprocess_gapic_library_hermetic (relative_dir , hide_output = False , is_esm = False ):
346381 logger .debug ("Post-processing GAPIC library..." )
347382 fix_hermetic (relative_dir , hide_output = hide_output )
383+ compile_protos_hermetic (relative_dir , hide_output = hide_output , is_esm = is_esm )
348384 logger .debug ("Post-processing completed" )
349385
350386
0 commit comments