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

How to use js_grpc_node_library with custom repo #255

Open
giofunchal opened this issue Apr 14, 2023 · 1 comment
Open

How to use js_grpc_node_library with custom repo #255

giofunchal opened this issue Apr 14, 2023 · 1 comment
Labels
enhancement New feature or request lang-js JavaScript rules specific

Comments

@giofunchal
Copy link

Description

Hi, I'm using js_grpc_node_library, and I'm trying to use the deps_repo= parameter to point to a custom named repo.

I'm using rules_js, my WORKSPACE looks like this.

http_archive(
    name = "aspect_rules_js",
    sha256 = "7c50475662810ce9635fa45d718220285a8adef32b2febd8631aae62e5816353",
    strip_prefix = "rules_js-1.23.2",
    url = "https://github.com/aspect-build/rules_js/releases/download/v1.23.2/rules_js-v1.23.2.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

nodejs_register_toolchains(
    name = "nodejs",
    node_version = "16.15.1",
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
    name = "custom_npm",
)

and then 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). Is there a way to make this work?

I looked at the code a bit, and there's a string replacement taking place

dep.replace("@npm", kwargs.get("deps_repo", "@npm"))
that doesn't seem ameanable, unless there is some other trick I am missing.

@aaliddell aaliddell added lang-js JavaScript rules specific enhancement New feature or request labels Jun 4, 2023
@cfife-btig
Copy link

Hey there,

I'm running into pretty much the exact same issue, albeit I'm using js_grpc_web_library. I'm still underway moving our existing project from rules_nodejs to rules_js (so I don't fully understand what solutions or methods might exist). However, it seems like the main problem is simply that node_modules is a target of the workspace now (i.e. //:node_modules), whereas before it was an external repository (i.e. @npm//grpc-web).

setting deps_repo to an empty string, at least seems to point it in the workspace, but I suspect there are other issues that haven't been uncovered. For example, even if I could point to the correct target path ( i.e. //:node_modules). Is it still going to try to package it into node_modules using the js_library rule which comes from rules_nodejs (which I don't have anymore)?

I think the main issue is just that rules_js isn't like rules_nodejs, so it's just fundamentally broken compatibility. Hopefully it's an easy patch-file fix, but I would guess there isn't an existing work around.

Kinda surprised to see only one issue about this, but maybe many people are still holding off on upgrading out of rules_nodejs, or the universe of js and grpc and bazel people is pretty small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lang-js JavaScript rules specific
Projects
None yet
Development

No branches or pull requests

3 participants