yarnpkg / berry

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

[Bug] Missing "plugin not installed" error for `yarn workspaces foreach` #2612

Open wdfinch opened 3 years ago

wdfinch commented 3 years ago

Describe the user story

I can't figure out how to use yarn workspaces foreach --include or --exclude from the docs. Some intuitive commands I have tried are:

yarn workspaces foreach --include ['packages/*'] run build
yarn workspaces foreach --include 'packages/*' run build
yarn workspaces foreach --include packages/* run build
yarn workspaces foreach --include packages/package-name run build

Every time I run the command I get the following output:

Unknown Syntax Error: Command not found; did you mean:

$ yarn workspaces list [-v,--verbose] [--json]
While running workspaces foreach --include packages/* run build

Describe the solution you'd like

I would really appreciate it if someone could add an example to the website docs on how to do this. Additionally, I think a better error message would be nice as "Unknown Syntax Error: Command not found; did you mean:" does not give me enough detail.

Describe the drawbacks of your solution

None

Describe alternatives you've considered

Asking in the discussion although this wouldn't solve the confusion for others.

merceyz commented 3 years ago

yarn workspaces foreach --include packages/* run build

The docs specify that it expects the names of your workspaces, not their paths https://yarnpkg.com/cli/workspaces/foreach#options-include%20%230 also since you're not quoting the glob pattern your shell expands it and actually passes yarn workspaces foreach --include packages/foo packages/bar [...] run build which is not a valid command

wdfinch commented 3 years ago

Thanks for the reply. That makes sense. I'm still having issues getting this to work. Could you please post an example or two of a valid command here?

It's confusing because yarn workspaces list shows the names as paths so I would think to use one of these. Additionally the docs say "An array of glob pattern idents" rather than names. I'm not sure of the exact format this would be in.

wdfinch commented 3 years ago

My issue is I didn't have the plugin installed. It would be nice if the commands on the website could show an error saying you need a certain plugin installed in order to use them. I know it's on the docs, but this could help as well.

merceyz commented 3 years ago

It's supposed to do that but It seems it broke and we don't have tests covering it - https://github.com/yarnpkg/berry/blob/bef203949d9acbd42da9b47b2a2dfe3615764eaf/packages/plugin-essentials/sources/commands/run.ts#L151-L154

wdfinch commented 3 years ago

Gotcha. Ok thanks.

paul-soporan commented 3 years ago

It's supposed to do that but It seems it broke and we don't have tests covering it -

It seems to be a bug in the Clipanion state machine since it throws an Unknown Syntax Error. I'll try looking into it. 🤔

paul-soporan commented 3 years ago

Clipanion repro:

Run this CLI with foo bar and it will throw an Unknown Syntax Error instead of being interpreted as an EntryCommand:

import {Cli, Command, Option} from 'clipanion';

class EntryCommand extends Command {
  first = Option.String();

  args = Option.Proxy();

  async execute() {
  }
}

class FooBazCommand extends Command {
  static paths = [[`foo`, `baz`]];

  async execute() {
  }
}

const cli = Cli.from([EntryCommand, FooBazCommand]);

console.log(cli.process(process.argv.slice(2)));