开发者问题收集

如何使用 Yarn 定位单个工作区?

2019-06-28
34253

我已像这样设置工作区

"private": true,
  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/firebase-admin",
      "**/firebase-admin/**",
      "**/firebase-functions",
      "**/firebase-functions/**"
    ]
  },

在我的软件包目录中,我有一个文件夹 common ,其中包含自己的 package.json 等。

当我执行 yarn working run build 时,它会触发所有工作区的构建脚本。但是,如果我尝试使用 yarn working 命令(如 yarn working common build )定位一个特定工作区,我就会不断收到错误:

error Unknown workspace "common".

这是我从 yarn workings info 获得的输出:

yarn workspaces v1.17.0
{
  "@gemini/cli": {
    "location": "packages/cli",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/cloud-functions": {
    "location": "packages/cloud-functions",
    "workspaceDependencies": [
      "@gemini/common"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/common": {
    "location": "packages/common",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/tools": {
    "location": "packages/tools",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  }
}

我尝试将名称更改为 package/common 或 @gemini/common,但没有成功。

我在这里遗漏了什么?

2个回答

当您想要在特定工作区上调用命令时,您应该使用在其 package.json 文件“name”中设置的包名称。在您的例子中,它应该是:

yarn workspace @gemini/common build

I have tried changing the name to package/common or @gemini/common but without luck.

您不应该看到错误 error Unknown working "@gemini/common". 也许您遇到了其他错误?

user123
2019-06-28

如果您想在工作区 <workspace> 中运行 build 脚本,则该命令的语法为

yarn workspace <workspace> build

例如,我的根 package.json 中有以下内容:

  "workspaces": [
    "api",
    "app"
  ],

这样我就可以运行 yarn working space api build

dinvlad
2019-06-28