yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.37k stars 1.1k forks source link

[Bug?]: workspaces foreach --include and --exclude do not filter workspaces #5505

Open petervannes opened 1 year ago

petervannes commented 1 year ago

Self-service

Describe the bug

In a Yarn 3 monorepo i have configured the workspaces ["packages/**","configs/**"],. When executing yarn workspaces list i do get the expected list of workspaces;

➤ YN0000: .
➤ YN0000: configs/babel
➤ YN0000: configs/eslint
➤ YN0000: configs/jest
➤ YN0000: packages/cancel
➤ YN0000: packages/save

I want to run a script for one or more specific workspaces using a specific name or using globs. In the root package.json i have several scripts which use yarn workspaces foreach with the include argument to run only the script for workspace 'configs/list', none of these seem to work

   "build:configs1": "yarn workspaces foreach --verbose  --include configs/list run build",
    "build:configs2": "yarn workspaces foreach --verbose  --include [configs/**] run build",
    "build:configs3": "yarn workspaces foreach --verbose  --include [configs/list] run build",
    "build:configs4": "yarn workspaces foreach --verbose  --include 'configs/list' run build",
    "build:configs5": "yarn workspaces foreach --verbose  --include ['configs/list'] run build",
    "build:configs6": "yarn workspaces foreach --verbose  --include ['configs\/list'] run build",
    "build:configs7": "yarn workspaces foreach --verbose  --include \"configs/list\" run build",
    "build:all": "yarn workspaces foreach --parallel --verbose  run build"

configs1 completes without processing any workspaces configs2 returns 'No matches found: "[configs/**]"' configs3 returns 'No matches found: "[configs/list]" configs4 completes without processing any workspaces configs5 completes without processing any workspaces configs6 completes without processing any workspaces configs7 completes without processing any workspaces

To reproduce

git clone https://github.com/petervannes/yarn3monorepo yarn install yarn build:configs1

Environment

System:
    OS: macOS 13.5
    CPU: (10) x64 Apple M1 Pro
  Binaries:
    Node: 14.19.1 - /private/var/folders/2t/fpdrn99x4ts52_69rv9_r4yc0000gn/T/xfs-475faa59/node
    Yarn: 3.6.0 - /private/var/folders/2t/fpdrn99x4ts52_69rv9_r4yc0000gn/T/xfs-475faa59/yarn

Additional context

I created a repo to demonstrate the issue https://github.com/petervannes/yarn3monorepo

petervannes commented 1 year ago

It seems the only way to include workspaces is using an explicit package name instead of workspace names;

yarn workspaces foreach --verbose --include @myorg/account-products-cancel --include @myorg/account-products-save run build

Using a array of glob pattern idents or glob pattern idents do not work

aderant-smcd commented 10 months ago

This is really unintuitive - I would expect a command that operates on workspaces like workspaces foreach to use the same names as declared in the root package.json workspaces array, not the names in the package.json.