aspect-build / rules_js

High-performance Bazel rules for running Node.js tools and building JavaScript projects
https://docs.aspect.build/rules/aspect_rules_js
Apache License 2.0
299 stars 102 forks source link

[Question]: How to use js_grpc_node_library with custom npm repo name #1004

Open ghost opened 1 year ago

ghost commented 1 year ago

I'm using rules_js, my WORKSPACE declares a custom name for the npm repo:

npm_translate_lock(
    name = "custom_npm",
)

I'm also using https://github.com/rules-proto-grpc/rules_proto_grpc , my BUILD file looks like this:

proto_library(
    name = "api_proto",
    srcs = ["api.proto"],
)

js_grpc_node_library(
    name = "protos_js",
    protos = [":api_proto"],
)

Adding deps_repo="@custom_npm" doesn't work because the dep is looked up at @custom_npm//@grpc/grpc-js which I believe is correct when using the old and now unmaintained rules_nodejs, but when using the newer rules_js the dep is placed instead at @custom_npm//:node_modules/@grpc/grpc-js (per docs https://docs-legacy.aspect.build/aspect-build/rules_js/v1.6.4/docs/npm_import-docgen.html#npm_translate_lock-link_workspace).

In rules_proto_grpc there's a string replacement taking place https://github.com/rules-proto-grpc/rules_proto_grpc/blob/bbb81931a510290127471b25d31b97e8211fa401/js/js_grpc_node_library.bzl#L22 that doesn't seem ameanable to working with the way rules_js declares the npm dependencies when using a custom repo name, unless there is some other trick I am missing, is there a way to make this work?

pcpLiu commented 1 year ago

Met same issue here. Wondering did you figure it out @giofunchal in the end?

ghost commented 1 year ago

No, I have no workaround to offer unfortunately @pcpLiu

alexeagle commented 1 year ago

From what I can tell, it doesn't seem like this is a bug in rules_js - have you tried filing it on rules-proto-grpc ?