NX包基于的存储库:projectRoot vs workspaceRoot?

huangapple go评论67阅读模式
英文:

NX package-based repo: projectRoot vs workspaceRoot?

问题

projectRoot 是指当前项目根目录的路径,而 workspaceRoot 是指工作区根目录的路径。

在你的目录结构中,projectRoot 会指向包含 nx.json 配置的顶层目录,而 workspaceRoot 会指向包含所有工作区(packages)的目录,也就是你的 git 仓库根目录。所以,workspaceRoot 指的是包含所有工作区的目录,而不是单个工作区(package)的根目录。

英文:

If I have a package-based monorepo with NX, which directory is projectRoot, and which one is workspaceRoot?

From the docs (https://nx.dev/reference/project-configuration):

> {projectRoot} and {workspaceRoot}
>
> {projectRoot} is a key word that is replaced by the path to the current project's root directory. {workspaceRoot} is a key word that is replaced by the path to the workspace root directory.

This is hilariously obvious and unhelpful explanation. I want to know which one is which, given I have this directory structure:

(git repo root dir)
|
+- nx.json
+- package.json - it says `"workspaces": [ "packages/*" ]`
|
+- packages/
   |
   +- package1/
   +- package2/

Because package.json mentions my packages/* as "workspaces", my guess is that each package is a workspace, thus workspaceRoot must refer to each package individually, while projectRoot must refer to a top-level dir with my nx.json config. But I have absolutely no idea how to confirm this. I'm experimenting with cache (setting various inputs as seeing is it hits or misses), and absolutely nothing works.

To clarify what I'm confused about: Is "workspace root" a directory containing all the workspaces (i.e. packages), or does it mean "root directory of an individual workspace (i.e. package)." (Here I'm assuming that "workspace" == "package", which may not be true.)

答案1

得分: 2

  • "project" = 每个包,例如库或应用程序,指的是packages/目录下的每个单独子目录
  • "projectRoot" = 每个单独包的根目录。在问题中的示例中,它将是packages/package1packages/package2
  • "workspace" = 所有包/项目的集合。请注意,“package.json”使用“workspaces”(复数)一词来指代包含所有包的目录,这让我感到困惑。
  • "workspaceRoot" = 包含nx.json的根目录

简而言之:

  • project = 包
  • workspace = 项目集合
英文:

Based on reading <https://nx.dev/concepts/mental-model>, here are my definitions:

  • "project" = each package, e.g. a library or an app, which refers to each individual subdirectory inside packages/
  • "projectRoot" = root of each individual package. In the example from the question, it will be packages/package1 and packages/package2
  • "workspace" = collection of all the packages/projects. Note that "package.json" uses the word "workspaces" (plural) to refer to a directory with all the packages, which is what confuses me.
  • "workspaceRoot" = the root directory where nx.json is located

In short:

  • project = package
  • workspace = collection of projects

huangapple
  • 本文由 发表于 2023年1月6日 22:22:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75032143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定