berry: [Bug] `yarn workspaces foreach exec` fails
- I’d be willing to implement a fix
Describe the bug
yarn workspaces foreach exec
fails
To Reproduce
I am trying to run depcheck
in every workspace, but it seems that exec
, while a valid yarn
command, is not passed through by yarn workspaces foreach
. Is this a bug or is exec
not meant to be supported?
yarn workspaces foreach exec depcheck
Usage Error: Invalid subcommand name for iteration - use the 'run' keyword if you wish to execute a script
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (17 by maintainers)
@DerekZiemba You’re using Yarn Classic (v1), while
yarn workpaces foreach
is a Yarn 2 feature. You can consult the installation guide to install Yarn 2. If it still doesn’t work, you should probably open another issue, as it’s unlikely it would be related to this one.It will skip over scripts that don’t declare a script of this name, yes. However it probably should execute it too if there’s a binary of the specified name, so if it doesn’t do so already I’d see that as a bug.
That’s funny, I never considered it would work with
exec
. I initially made it this way because it turns out there’s no real portable way to run a script regardless of the package manager (each time you need to explicitly specify npm / yarn / pnpm, …). I haven’t advocated it to other package managers though, so it’s not portable either (yet).yarn exec
has been implemented, but it hasn’t been released yet. You can doyarn set version from sources
to build and use the version from master, which includesyarn exec
.Edit: And yes, it’s supported by
yarn workspaces foreach
, I can confirm thatyarn workspaces foreach exec ls
works.