Skip to content

Commit

Permalink
change ts_proto_library to default es5 wrapping (#1593)
Browse files Browse the repository at this point in the history
* change ts_proto_library to default es5 wrapping

This change wraps es5 sources generated with `ts_proto_library` to be wrapped in "default" mode. The "default" mode behaves like UMD, supporting both AMD and CommonJS. This change is necessary to support Node, as Node does not use AMD. See #562
  • Loading branch information
CooperBills authored Feb 5, 2020
1 parent 30d0f37 commit dbb2a90
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,8 @@ load("@build_bazel_integration_testing//tools:repositories.bzl", "bazel_binaries

# Depend on the Bazel binaries
bazel_binaries(versions = [BAZEL_VERSION])

# Install labs dependencies
load("@npm_bazel_labs//:package.bzl", "npm_bazel_labs_dependencies")

npm_bazel_labs_dependencies()
2 changes: 1 addition & 1 deletion packages/labs/src/protobufjs/ts_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo")

def _run_pbjs(actions, executable, var, output_name, proto_files, suffix = ".js", wrap = "amd", amd_name = ""):
def _run_pbjs(actions, executable, var, output_name, proto_files, suffix = ".js", wrap = "default", amd_name = ""):
js_file = actions.declare_file(output_name + suffix)

# Create an intermediate file so that we can do some manipulation of the
Expand Down
31 changes: 31 additions & 0 deletions packages/labs/test/protobufjs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_labs//:index.bzl", "ts_proto_library")
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

ts_library(
name = "test",
srcs = ["test.ts"],
deps = [
":test_ts_proto",
"@npm//@types/jasmine",
],
)

proto_library(
name = "test_proto",
srcs = [":test.proto"],
)

ts_proto_library(
name = "test_ts_proto",
deps = [":test_proto"],
)

jasmine_node_test(
name = "protobuf_test",
srcs = [":test"],
deps = [
"@npm//protobufjs",
],
)
5 changes: 5 additions & 0 deletions packages/labs/test/protobufjs/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message TestMessage {
string test_field = 1;
}
9 changes: 9 additions & 0 deletions packages/labs/test/protobufjs/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {TestMessage} from 'build_bazel_rules_nodejs/packages/labs/test/protobufjs/test_ts_proto';

describe('protobufjs', () => {
it('should work in node', () => {
expect(TestMessage.verify({
testField: 'Hello',
})).toBeFalsy(); // verify returns an error if failed
});
});

0 comments on commit dbb2a90

Please sign in to comment.