Skip to content

Commit 41da6ce

Browse files
committed
2 parents 85e4734 + dcb4e24 commit 41da6ce

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

src/typescript_proto_library.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3336
def _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")

test/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ts_library(
2424
deps = [
2525
"//test/proto:pizza_service_ts_proto",
2626
"//test/proto/common:delivery_person_ts_proto",
27-
"@npm//@types/jasmine",
27+
"@npm//@types",
2828
],
2929
)
3030

@@ -50,7 +50,7 @@ ts_library(
5050
tsconfig = ":tsconfig.json",
5151
deps = [
5252
"//test/proto/common:delivery_person_ts_proto",
53-
"@npm//@types/jasmine",
53+
"@npm//@types",
5454
# Don't put pizza_ts_proto here, we want to test it is included transitively
5555
],
5656
)
@@ -75,7 +75,7 @@ ts_library(
7575
deps = [
7676
"//test/proto:pizza_service_ts_proto",
7777
"//test/proto/common:pizza_ts_proto",
78-
"@npm//@types/jasmine",
78+
"@npm//@types",
7979
# Don't put delivery_person_ts_proto here, we want to test it is included transitively
8080
],
8181
)

test/commonjs_test.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import deliveryPersonPb = require('rules_typescript_proto/test/proto/common/delivery_person_pb');
1+
import {Timestamp} from 'google-protobuf/google/protobuf/timestamp_pb';
2+
import * as deliveryPersonPb from 'rules_typescript_proto/test/proto/common/delivery_person_pb';
23
import {PizzaService} from 'rules_typescript_proto/test/proto/pizza_service_pb_service';
34

45
describe('CommonJs', () => {
@@ -7,6 +8,9 @@ describe('CommonJs', () => {
78

89
const person = new deliveryPersonPb.DeliveryPerson();
910
person.setName('Doug');
11+
const lastDeliveryTime = new Timestamp();
12+
lastDeliveryTime.fromDate(new Date());
13+
person.setLastDeliveryTime(lastDeliveryTime);
1014
expect(person).toBeDefined();
1115
});
1216

test/proto/common/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ proto_library(
1010
"delivery_person.proto",
1111
],
1212
deps = [
13+
"@com_google_protobuf//:timestamp_proto",
1314
":pizza_proto",
1415
],
1516
)

test/proto/common/delivery_person.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ syntax = "proto3";
33
package test.bazel.proto;
44

55
import "test/proto/common/pizza.proto";
6+
import "google/protobuf/timestamp.proto";
67

78
message DeliveryPerson {
89
// The name of the delivery person.
@@ -16,4 +17,5 @@ message DeliveryPerson {
1617
string id = 3;
1718
int64 id_v2 = 4;
1819
}
20+
google.protobuf.Timestamp last_delivery_time = 5;
1921
}

test/tsconfig.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
"noEmitOnError": true,
1616
"types": [
1717
"jasmine"
18-
]
18+
],
19+
"baseUrl": "..",
20+
"paths": {
21+
"rules_typescript_proto/*": [
22+
"*",
23+
"bazel-bin/*"
24+
]
25+
}
26+
1927
}
2028
}

0 commit comments

Comments
 (0)