我有一个项目,其中包含几个 JS 包并使用 Yarn 工作区进行组织:
<root>
├── WORKSPACE
├── package.json
├── workspaces
│ ├── foo
│ │ ├── package.json
│ │ ├── BUILD.bazel
│ │ ├── src
│
├── bar
│ ├── package.json
│ ├── BUILD.bazel
│ ├── src
FOO
包取决于BAR
包,它定义在FOO/package.json
:
workspaces/foo/package.json
{
"name": "FOO",
"dependencies": {
"BAR": "link:../bar",
}
workspaces/bar/BUILD.bazel
看起来像这样
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
js_library(
name = "bar",
package_name = "BAR",
srcs = [
"package.json",
"index.js",
],
visibility = ["//visibility:public"],
)
和这里workspaces/foo/BUILD.bazel
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
js_library(
name = "foo",
package_name = "FOO",
srcs = [
"package.json",
"index.js",
],
deps = [
"//workspaces/bar:bar",
"@npm//:node_modules" # <-- this line causes an error because linked package couldn't be found in node_modules
],
visibility = ["//visibility:public"],
)
文件WORKSPACE
包括:
yarn_install(
name = "npm_foo",
package_json = "//workspaces/foo:package.json",
yarn_lock = "//workspaces/foo:yarn.lock",
package_path = "workspaces/foo",
strict_visibility = False,
# links = {
# "bar": "//workspaces/bar",
# },
# generate_local_modules_build_files = True,
)
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
yarn_install(
name = "npm_bar",
package_json = "//workspaces/bar:package.json",
yarn_lock = "//workspaces/bar:yarn.lock",
package_path = "workspaces/bar",
)
通过所有这些设置,我运行bazel build //workspaces/foo:foo
但它失败了。我需要配置links
或generate_local_modules_build_files
属性yarn_install
吗?或者让这个链接的包一起工作需要什么改变?