【问题标题】:How to install only the root packages in a Yarn Workspaces repo如何在 Yarn Workspaces 存储库中仅安装根包
【发布时间】:2022-06-23 16:41:24
【问题描述】:

使用 Yarn Workspaces,在其中一个包目录中使用 yarn install --focus 为单个 Workspace 安装包非常容易。

但是,有时我希望能够仅安装顶级package.json 中列出的软件包。我在整个 repo 中运行了一个 linter,我希望能够安装 linting 依赖项,而无需安装整个工作区所需的每个包。

我该怎么做?

【问题讨论】:

    标签: yarnpkg yarn-workspaces


    【解决方案1】:

    如果您仍在使用 Yarn v1 (v2 and v3 supposedly don't have that problem) 并且需要在 CI 中执行此操作,您可以执行此 bash hack

    tmp=$(mktemp) # create temporary file because jq can't push directly to package.json
    jq 'del(.workspaces)' package.json > $tmp && mv $tmp package.json
    

    jq是一个处理JSON的程序,你必须单独安装它

    这有效地从你的 package.json 中移除了“workspaces”键,所以唯一剩下的就是你的根包

    参考资料:

    【讨论】:

      猜你喜欢
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 2017-09-10
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多