Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/typescript_proto_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def _proto_path(proto):
path = path[len(root):]
if path.startswith("/"):
path = path[1:]
if path.startswith(ws):
if path.startswith(ws) and 0 < len(ws):
path = path[len(ws):]
if path.startswith("/"):
path = path[1:]
if path.startswith("_virtual_imports/"):
path = path.split("/")[2:]
path = "/".join(path)
return path

def _get_protoc_inputs(target, ctx):
Expand Down Expand Up @@ -85,7 +88,7 @@ def _build_protoc_command(target, ctx):
if ctx.attr.generate == "grpc-node":
protoc_command += " --plugin=protoc-gen-grpc=%s" % (ctx.executable._grpc_protoc_gen.path)

protoc_output_dir = ctx.var["BINDIR"]
protoc_output_dir = ctx.bin_dir.path + "/" + ctx.label.workspace_root
protoc_command += " --ts_out=%s%s%s" % (",".join(ts_flags), ":" if bool(ts_flags) else "", protoc_output_dir)
protoc_command += " --js_out=import_style=commonjs,binary:%s" % (protoc_output_dir)

Expand Down Expand Up @@ -172,7 +175,12 @@ def _get_outputs(target, ctx):
ts_file_suffixes.append("_pb_service.d.ts")

for src in target[ProtoInfo].direct_sources:
file_name = src.basename[:-len(src.extension) - 1]
# workspace_root is empty for our local workspace, or external/other_workspace
# for @other_workspace//
if ctx.label.workspace_root == "":
file_name = src.basename[:-len(src.extension) - 1]
else:
file_name = _proto_path(src)[:-len(src.extension) - 1]
relative_path = _get_path_relative_to_build(ctx, src)
for f in js_file_suffixes:
output = ctx.actions.declare_file(relative_path + file_name + f)
Expand Down