如何从零安装和PNP中执行YARN工作区的根依赖性
我正在尝试设置带有纱线工作区的monorepo,零安装 + pnp(没有node_modules,而是根部内的.yarn/cache)。
由于我不想在所有工作区内定义依赖性,例如打字稿,因此我只想在the poffage.json中添加1次。
但是,如果我这样做,我会得到'TSC'被认为是内部或外部命令
我知道我可以在PC上全球安装它,但是我认为它曾经在YARN上使用是node_modules,我真的想使用我在root package.json文件中定义的打字稿版本。
让我们假设此文件夹结构
- .yarn/cache (where all dependencies are stored as .zip files)
- package.json (where typescript is defined)
- packages/package-a (when inside, I need to be able to reference "tsc")
在包含包装/package-a(或编写纱线workspace package-a build
时,我如何在该软件包中使用“ tsc”? node_modules binaries来提供通往二进制的路径?
root package.json-我可以使用 -protection“ class =” __ cf_email__“ data-cfemail =” 364f5744458760518041807“> [email  preected] ” ” ”
I'm trying to setup a monorepo with Yarn Workspaces, Zero Install + PnP (no node_modules, but instead a .yarn/cache inside the root).
Since I don't want to define dependencies such as typescript inside all my workspaces, I want to add it just 1 time in the package.json at the root.
But if I do that, I get 'tsc' is not recognized as an internal or external command
I know I could just install it globally on my pc, but I think it used to work with yarn when it was node_modules and I really want to use the typescript version that I defined in the root package.json file.
Let's assume this folder structure
- .yarn/cache (where all dependencies are stored as .zip files)
- package.json (where typescript is defined)
- packages/package-a (when inside, I need to be able to reference "tsc")
When inside packages/package-a (or when writing yarn workspace package-a build
, how can I use "tsc" in my build script for that package? The tsc defined in the root package.json - instead of "tsc" can i supply a path to the binary, or how does it work without node_modules binaries?
Using "packageManager": "[email protected]"
as defined in the root package.json
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的根工作空间是“ my-monorepo”(即“ package.json”中的“ name”属性),您可以在“ package-a/pofcage.json”中执行这样的事情,
这当然不限于“打字”,但是您可以为root“ pockage.json”中的所有(dev)依赖项做的事情。
话虽如此,我不建议这样做。相反,请保持集中。在根级别创建一个脚本文件夹,并编写一个构建/绒布/测试一个/所有软件包的构建脚本。
如果您打算拥有很多包裹,则可能值得研究Bazel。 Bazel将确保仅重建更改的软件包,因此您无需构建每个单独的软件包。
Let's say your root workspace is "my-monorepo" (ie. the "name" property in "package.json"), you could do something like this in "package-a/package.json"
Of course this is not limited to "typescript", but something you can do for all (dev)Dependencies inside your root "package.json".
With that said I wouldn't recommend doing it this way. Instead, keep things centralized. Create a scripts folder at the root level and write a build script that builds/lints/tests one/all package(s).
If you plan on having lots of packages it might be worth looking into Bazel instead. Bazel will make sure only changed packages is rebuilt, so you don't need to build each individual package.