-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(examples): use protobufjs-cli instead of protobufjs to build…
… protos
- Loading branch information
Showing
1 changed file
with
3 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,9 @@ | ||
"Illustrate how to wrap pbjs and pbts from protobufjs" | ||
|
||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
|
||
# TODO switch to protobufjs-cli when its published | ||
# https://github.com/protobufjs/protobuf.js/commit/da34f43ccd51ad97017e139f137521782f5ef119 | ||
load("@npm//protobufjs:index.bzl", "pbjs", "pbts") | ||
load("@npm//protobufjs-cli:index.bzl", "pbjs", "pbts") | ||
load("@rules_proto//proto:defs.bzl", "ProtoInfo") | ||
|
||
# protobuf.js relies on these packages, but does not list them as dependencies | ||
# in its package.json. | ||
# Instead they are listed under "cliDependencies" | ||
# (see https://unpkg.com/[email protected]/package.json) | ||
# When run, the CLI attempts to run `npm install` at runtime to get them. | ||
# This fails under Bazel as it tries to access the npm cache outside of the sandbox. | ||
# Per Bazel semantics, all dependencies should be pre-declared. | ||
# Note, you'll also need to install all of these in your package.json! | ||
# (This should be fixed when we switch to protobufjs-cli) | ||
_PROTOBUFJS_CLI_DEPS = ["@npm//%s" % s for s in [ | ||
"chalk", | ||
"escodegen", | ||
"espree", | ||
"estraverse", | ||
"glob", | ||
"jsdoc", | ||
"minimist", | ||
"semver", | ||
"tmp", | ||
"uglify-js", | ||
]] | ||
|
||
def _proto_sources_impl(ctx): | ||
return DefaultInfo(files = ctx.attr.proto[ProtoInfo].transitive_sources) | ||
|
||
|
@@ -69,7 +44,7 @@ def protobufjs_library(name, proto, **kwargs): | |
# Transform .proto files to a single _pb.js file named after the macro | ||
pbjs( | ||
name = js_target, | ||
data = [proto_target] + _PROTOBUFJS_CLI_DEPS, | ||
data = [proto_target], | ||
# Arguments documented at | ||
# https://github.com/protobufjs/protobuf.js/tree/6.8.8#pbjs-for-javascript | ||
args = [ | ||
|
@@ -85,7 +60,7 @@ def protobufjs_library(name, proto, **kwargs): | |
# Transform the _pb.js file to a .d.ts file with TypeScript types | ||
pbts( | ||
name = ts_target, | ||
data = [js_target] + _PROTOBUFJS_CLI_DEPS, | ||
data = [js_target], | ||
# Arguments documented at | ||
# https://github.com/protobufjs/protobuf.js/tree/6.8.8#pbts-for-typescript | ||
args = [ | ||
|