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?

Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128

3 Answers3

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:

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).

humkins
  • 9,635
  • 11
  • 57
  • 75
0

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
DevTheJo
  • 2,179
  • 2
  • 21
  • 25