How to install only the root packages in a Yarn Workspaces repo
Asked Answered
B

3

7

Using Yarn Workspaces it's very easy to install the packages for a single Workspace using yarn install --focus when inside one of the package directories.

However, sometimes I would like the ability to install only the packages listed in the top-level package.json. I run a linter across the entire repo, and I'd like to be able to install the linting dependencies without needing to install every package needed across the workspace.

How can I do this?

Bibliomancy answered 2/12, 2021 at 1:0 Comment(0)
A
0

If you are still on Yarn v1 (v2 and v3 supposedly don't have that problem) and need to do this in CI, you can do this 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 is a program for manipulating JSON, you'll have to install it separately

This effectively removes the "workspaces" key from your package.json, so the only thing that's left are your root packages

References:

Alexei answered 23/6, 2022 at 8:41 Comment(0)
G
0

Just an idea. As a workaround you can temporarily rename current workspaces directory to something different (if you need create an empty workspaces directory). Install packages in the root package with yarn command. Then you can do whatever you need and when previuos jobs are done replace an empty workspaces directory with the real one and install dependencies again (yarn).

Gauguin answered 20/9, 2022 at 14:56 Comment(0)
B
-1

you can just use the name of the root package present in package.json in key name, if the key is ~dev for example:

yarn workspaces focus ~dev
Bendicty answered 28/1, 2023 at 17:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.