如何使用可单独部署的包制作 Bazel TypeScript monorepo

发布于 2025-01-13 04:16:49 字数 1374 浏览 1 评论 0原文

我一直在尝试让 bazel monorepo 与打字稿一起工作。我有几个要求。

  1. 我应该能够使用 @myworkspace/ 而不是 ../../../ 等导入本地包,而不需要 Bazel。这主要是为了让我在写作时能够自动完成。
  2. @myworkspace/ 包在开发和构建期间应该是相同的,但在运行沙箱时,只有 Bazel 管理的依赖项应该在导入时得到解析。只是为了让我知道我是否弄乱了 js_library 规则中的包名称。
  3. 整个项目应该只有一个锁定文件。所有依赖项应位于 root/node_modules 中。
  4. 应该可以单独部署节点包,即@myworkspace/myCloudFunction。
  5. 应该可以在将部署的包中包含本地依赖项。

我是 Bazel 的新手,来自 NPM 生态系统的我似乎需要一些心态上的改变。经过谷歌搜索后,我设法找到了适用于第 1 点和第 2 点的东西(但我可能是错的)。我已在 https://github.com/vitorelourenco/bazelmono-ts 发布了游乐场存储库(几乎是来自 https://github.com/lokshunhung/bazel-ts-monorepo 以及我从 https://github.com/angular/angular)

我关于第 3 点和第 4 点的问题: 假设我希望包 @myworkspace/cloudFunction 上提供 lib Lodash,并将其部署到 Google Cloud Functions。如果我在 @myworkspace/cloudFunction 文件夹中安装 Lodash,那么 Lodash 将被添加到 package.json 中,但我将拥有第二个 node_modules 文件夹和第二个 yarn.lock 文件,我不希望这样。但如果我将其安装在 root/ 中,那么 Lodash 将不会添加到位于 @myworkspace/cloudFunction 的 package.json 上列出的依赖项中,并且当我部署它时,它也不会安装。有聪明的方法来处理这个问题吗?

第5点非常相似。理想情况下,最终的 Bazel 输出将捆绑本地依赖项并准备使用,但我似乎还无法找到一种方法来做到这一点。我尝试将 pkg_npm 规则添加到 playgroup 存储库中的 //packages/app 中,但无法使其包含 //packages/common 。

I've been trying to get a bazel monorepo with typescript to work. I have a couple of requirements in mind.

  1. I should be able to import local packages using @myworkspace/ instead of ../../../ and so on, without needing Bazel. This is mostly so I get autocomplete while I'm writing.
  2. The @myworkspace/ package should be the same during development and build time but only Bazel-managed dependencies should be resolved on imports when running sandboxed. Just so I know if I've messed up the name of the package in the js_library rule.
  3. There should only be one lock file for the whole project. All dependencies should be located at root/node_modules.
  4. It should be possible to individually deploy node packages i.e. @myworkspace/myCloudFunction.
  5. It should be possible to include local dependencies in packages that will deployed.

I'm new to Bazel and it seems like it requires some mentality changes when coming from the NPM ecosystem. After googling, I've managed to find something that works for points 1 and 2 (But I might be wrong). I've published the playground repo at https://github.com/vitorelourenco/bazelmono-ts (pretty much a copy from https://github.com/lokshunhung/bazel-ts-monorepo with some ideas I took from https://github.com/angular/angular)

My questions about points 3 and 4:
Say I want the lib Lodash available on package @myworkspace/cloudFunction that will be deployed to Google Cloud Functions. If I install Lodash in the @myworkspace/cloudFunction folder, then Lodash will be added to package.json but I'll have a second node_modules folder and a second yarn.lock file, I don't want that. But if I install it in root/, then Lodash will not be added to the dependencies listed on package.json located at @myworkspace/cloudFunction, and when I deploy it, it won't install. Is there a smart way to handle this issue?

Point 5 is very similar. Ideally, the final Bazel output would have the local dependencies bundled in and ready to use but I can't seem to figure out a way to do it yet. I've tried adding a pkg_npm rule to //packages/app in the playgroup repo but couldn't get it to include //packages/common in it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文