yw

Published See discussion on Twitter

Update!

Note: This script is only compatible with yarn classic (e.g. v1), I have since published an updated version that works with yarn berry (v2 and v3 releases) in my Navigating Monorepos with Ease blog post!


Almost a year or more ago I stumbled across this super useful bash function that makes it incredibly easy to run scripts across a Yarn-based monorepo. Since then I haven't looked back, and have been slowly converting the rest of my team to adopt the same function in their local workflows as well!

Script:

1yw() {
2 yarn workspace $(yarn --json workspaces info | jq '.data' -r | jq "[keys][0] []" -r | fzf) $@
3}
1yw() {
2 yarn workspace $(yarn --json workspaces info | jq '.data' -r | jq "[keys][0] []" -r | fzf) $@
3}

Requirements:

  • jq
  • fzf

Both should be installable via homebrew: brew install fzf jq

Installation:

Copy the above script and dump it into your .bashrc or .zshrc, or whatever other config script your shell uses!