@@ -24,10 +24,13 @@ def _proto_path(proto):
2424 path = path [len (root ):]
2525 if path .startswith ("/" ):
2626 path = path [1 :]
27- if path .startswith (ws ):
27+ if path .startswith (ws ) and len ( ws ) > 0 :
2828 path = path [len (ws ):]
2929 if path .startswith ("/" ):
3030 path = path [1 :]
31+ if path .startswith ("_virtual_imports/" ):
32+ path = path .split ("/" )[2 :]
33+ path = "/" .join (path )
3134 return path
3235
3336def _get_protoc_inputs (target , ctx ):
@@ -53,7 +56,7 @@ def _build_protoc_command(target, ctx):
5356
5457 protoc_command += " --plugin=protoc-gen-ts=%s" % (ctx .executable ._ts_protoc_gen .path )
5558
56- protoc_output_dir = ctx .var [ "BINDIR" ]
59+ protoc_output_dir = ctx .bin_dir . path + "/" + ctx . label . workspace_root
5760 protoc_command += " --ts_out=service=grpc-web:%s" % (protoc_output_dir )
5861 protoc_command += " --js_out=import_style=commonjs,binary:%s" % (protoc_output_dir )
5962
@@ -97,7 +100,13 @@ def _get_outputs(target, ctx):
97100 js_outputs_es6 = []
98101 dts_outputs = []
99102 for src in target [ProtoInfo ].direct_sources :
100- file_name = src .basename [:- len (src .extension ) - 1 ]
103+ # workspace_root is empty for our local workspace, or external/other_workspace
104+ # for @other_workspace//
105+ if ctx .label .workspace_root == "" :
106+ file_name = src .basename [:- len (src .extension ) - 1 ]
107+ else :
108+ file_name = _proto_path (src )[:- len (src .extension ) - 1 ]
109+
101110 for f in ["_pb" , "_pb_service" ]:
102111 full_name = file_name + f
103112 output = ctx .actions .declare_file (full_name + ".js" )
0 commit comments