Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace protobufjs with protobufjs-cli in examples/protobufjs #3543

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 3 additions & 28 deletions examples/protobufjs/defs.bzl
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)

Expand Down Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions examples/protobufjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"long": "4.0.0",
"minimist": "^1.2.0",
"protobufjs": "=6.8.8",
"protobufjs-cli": "^1.0.1",
"semver": "^5.5.0",
"tmp": "0.0.33",
"typescript": "^3.3.1",
Expand Down
Loading