This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Add ts_proto_library rule. #193
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e0de5e
Add ts_proto_library rule.
alexeagle 543aeba
Get AMD shims from the js_library in bootstrap[]
alexeagle 41f499c
Add ts_devserver bootstrap attribute for UMD scripts that must come b…
alexeagle 2828b3c
Add test case for Long handling in int64
alexeagle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
load("@build_bazel_rules_typescript//:defs.bzl", | ||
"ts_library", | ||
"ts_proto_library", | ||
"ts_web_test", | ||
"ts_devserver", | ||
) | ||
|
||
proto_library( | ||
name = "tire_proto", | ||
srcs = ["tire.proto"], | ||
) | ||
|
||
proto_library( | ||
name = "car_proto", | ||
srcs = ["car.proto"], | ||
deps = [":tire_proto"], | ||
) | ||
|
||
ts_proto_library( | ||
# The result will be "car.d.ts" named after this target. | ||
# We could use the output_name attribute if we want the output named | ||
# differently than the target. | ||
name = "car", | ||
deps = [":car_proto"], | ||
) | ||
|
||
ts_library( | ||
name = "test_lib", | ||
testonly = True, | ||
srcs = ["car.spec.ts"], | ||
deps = [":car"], | ||
) | ||
|
||
ts_web_test( | ||
name = "test", | ||
deps = ["test_lib"], | ||
bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"], | ||
) | ||
|
||
ts_library( | ||
name = "app", | ||
srcs = ["app.ts"], | ||
deps = [":car"], | ||
) | ||
|
||
ts_devserver( | ||
name = "devserver", | ||
deps = [":app"], | ||
entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app", | ||
bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Car} from './car'; | ||
|
||
const serverResponse = `{"make": "Porsche"}`; | ||
const car = Car.create(JSON.parse(serverResponse)); | ||
const el: HTMLDivElement = document.createElement('div'); | ||
el.innerText = `Car from server: ${car.make}`; | ||
document.body.appendChild(el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
|
||
import "examples/protocol_buffers/tire.proto"; | ||
|
||
message Car { | ||
string make = 1; | ||
string model = 2; | ||
int32 year = 3; | ||
Tire front_tires = 4; | ||
Tire rear_tires = 5; | ||
int64 mileage = 6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Car} from './car'; | ||
import Long = require('long'); | ||
|
||
describe('protocol buffers', () => { | ||
|
||
it('allows creation of an object described by proto', () => { | ||
const pontiac = Car.create({ | ||
make: "pontiac", | ||
frontTires: { | ||
width: 225, | ||
aspectRatio: 65, | ||
construction: 'R', | ||
diameter: 17, | ||
}, | ||
}); | ||
expect(pontiac.make).toEqual('pontiac'); | ||
if (!pontiac.frontTires) { | ||
fail('Should have frontTires set'); | ||
} else { | ||
expect(pontiac.frontTires.width).toEqual(225); | ||
} | ||
}); | ||
|
||
// Asserts that longs are handled correctly. | ||
// This value comes from https://github.com/dcodeIO/long.js#background | ||
it('handles long values correctly', () => { | ||
const pontiac = Car.create({ | ||
make: "pontiac", | ||
// Long.MAX_VALUE | ||
mileage: new Long(0xFFFFFFFF, 0x7FFFFFFF), | ||
}); | ||
const object = Car.toObject(pontiac, {longs: String}); | ||
expect(object["mileage"]).toEqual("9223372036854775807"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
message Tire { | ||
string type = 1; | ||
int32 width = 2; | ||
int32 aspect_ratio = 3; | ||
string construction = 4; | ||
int32 diameter = 5; | ||
int32 load_index = 6; | ||
string speed_rating = 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"lib": ["es2015.promise", "dom", "es5"] | ||
"lib": ["es2015.promise", "dom", "es5"], | ||
// Include the output directory in rootDirs so that generated .d.ts files | ||
// can be used for type-checking in the editor, for example the car.proto | ||
// produces a car.d.ts. | ||
"rootDirs": [".", "../bazel-bin/examples"] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ See the README.md. | |
load("@build_bazel_rules_nodejs//internal:node.bzl", | ||
"sources_aspect", | ||
) | ||
load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", | ||
"write_amd_names_shim", | ||
) | ||
|
||
def _ts_devserver(ctx): | ||
files = depset() | ||
|
@@ -46,12 +49,19 @@ def _ts_devserver(ctx): | |
workspace_name + "/" + f.short_path + "\n" for f in files | ||
])) | ||
|
||
amd_names_shim = ctx.actions.declare_file( | ||
"_%s.amd_names_shim.js" % ctx.label.name, | ||
sibling = ctx.outputs.executable) | ||
write_amd_names_shim(ctx.actions, amd_names_shim, ctx.attr.bootstrap) | ||
|
||
# Requirejs is always needed so its included as the first script | ||
# in script_files before any user specified scripts for the devserver | ||
# to concat in order. | ||
script_files = depset() | ||
script_files += ctx.files._requirejs_script | ||
script_files += ctx.files.scripts | ||
script_files = [] | ||
script_files.extend(ctx.files.bootstrap) | ||
script_files.append(ctx.file._requirejs_script) | ||
script_files.append(amd_names_shim) | ||
script_files.extend(ctx.files.scripts) | ||
ctx.actions.write(ctx.outputs.scripts_manifest, "".join([ | ||
workspace_name + "/" + f.short_path + "\n" for f in script_files | ||
])) | ||
|
@@ -60,9 +70,9 @@ def _ts_devserver(ctx): | |
ctx.executable._devserver, | ||
ctx.outputs.manifest, | ||
ctx.outputs.scripts_manifest, | ||
ctx.file._requirejs_script] | ||
] | ||
devserver_runfiles += ctx.files.static_files | ||
devserver_runfiles += ctx.files.scripts | ||
devserver_runfiles += script_files | ||
|
||
serving_arg = "" | ||
if ctx.attr.serving_path: | ||
|
@@ -106,6 +116,7 @@ ts_devserver = rule( | |
"serving_path": attr.string(), | ||
"data": attr.label_list(allow_files = True, cfg = "data"), | ||
"static_files": attr.label_list(allow_files = True), | ||
"bootstrap": attr.label_list(allow_files = [".js"]), | ||
# User scripts for the devserver to concat before the source files | ||
"scripts": attr.label_list(allow_files = True), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suppose it is correct to limit scripts to [".js"] as well |
||
# The entry_module should be the AMD module name of the entry module such as "__main__/src/index" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package(default_visibility=["//visibility:public"]) | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") | ||
|
||
exports_files(["node_modules/protobufjs/dist/minimal/protobuf.min.js"]) | ||
|
||
nodejs_binary( | ||
name = "pbjs", | ||
node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules", | ||
entry_point = "protobufjs/bin/pbjs", | ||
) | ||
nodejs_binary( | ||
name = "pbts", | ||
node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules", | ||
entry_point = "protobufjs/bin/pbts", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "protobufjs", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"chalk": "^1.1.3", | ||
"escodegen": "^1.9.0", | ||
"espree": "^3.5.3", | ||
"estraverse": "^4.2.0", | ||
"glob": "^7.1.2", | ||
"jsdoc": "^3.5.5", | ||
"minimist": "^1.2.0", | ||
"protobufjs": "Use HEAD to pick up fix for https://github.com/dcodeIO/protobuf.js/pull/1018", | ||
"protobufjs": "github:dcodeIO/protobuf.js#65d113b0079fa2570837f3cf95268ce24714a248", | ||
"semver": "^5.5.0", | ||
"tmp": "0.0.33", | ||
"uglify-js": "^2.8.29" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider exercising your test with a message containing an int64.
pbjs
has a couple of modes for handingint64
in JS and one of the requires that thelong
node_module be used. We should test that we integrated that scenario correctlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, good point