invertase / melos

šŸŒ‹ A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.19k stars 207 forks source link

request: replace `--no-select` with option like `--filter` for `packageFilters` #530

Open kriswuollett opened 1 year ago

kriswuollett commented 1 year ago

Is there an existing feature request for this?

Command

No response

Description

Replace the interaction suppressing --no-select with a option like --filter. See Turborepo's --filter for inspiration.

Reasoning

I find it inconvenient to have to select a package on which I need to run a script if it uses packageFilters. Use cases are generating built_value or proto files in potentially multiple projects. If Melos does have knowledge whether something needs to be rebuilt or not, then it should delegate that responsibility to the command that generates it, i.e., the one of the scripts.

If my package-filtered script was expensive to run and/or isn't smart about rebuilding, then I'd also find it more convenient to specify on which package to run on the command line:

$ melos run build_runner --filter=my_library_b

... instead of a user-interaction-required prompt required now:

$ melos run build_runner
melos run build_runner
  ā””> melos exec -- "dart pub run build_runner build"
     ā””> RUNNING

Select a package to run the build_runner script:

1) * [Default - Press Enter]
2) my_app_a
3) my_library_b

? Enter your choice 

Requiring a prompt like this may inhibit filtering actions in a CI system, and likely affects its accessibility.

Additional context and comments

The issue was filed since IMO the run behavior with packageFilters is incongruent with run without them, while looking at setting something up like this, which I found interesting in that if a script is run in the hook, user interaction is not required and the script is run on all packages:

name: my
ide:
  # Suppress IDE file creation
  # See: https://github.com/invertase/melos/issues/478
  intellij: false
packages:
  - my/code/flutter_app
  - my/examples/dart/greetings
  - my/examples/dart/hello
scripts:
  build_runner:
    exec: echo dart pub run build_runner build
    packageFilters:
      dependsOn:
        - build_runner
command:
  bootstrap:
    hooks:
      post: melos run build_runner

Example run:

% melos bootstrap       
melos bootstrap
  ā””> /Users/kris/code/my/code

Running "flutter pub get" in workspace packages...
  āœ“ my_examples_dart_greetings
    ā””> my/examples/dart/greetings
  āœ“ my_code
    ā””> my/code/flutter_app
  āœ“ my_examples_dart_hello
    ā””> my/examples/dart/hello
  > SUCCESS

 -> 3 packages bootstrapped

melos bootstrap [post]
  ā””> melos run build_runner

melos run build_runner
  ā””> melos exec -- "echo dart pub run build_runner build"
     ā””> RUNNING

$ melos exec
  ā””> echo dart pub run build_runner build
     ā””> RUNNING (in 2 packages)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[my_flutter_app]: dart pub run build_runner build
[my_examples_dart_hello]: dart pub run build_runner build
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$ melos exec
  ā””> echo dart pub run build_runner build
     ā””> SUCCESS

melos run build_runner
  ā””> melos exec -- "echo dart pub run build_runner build"
     ā””> SUCCESS
kriswuollett commented 1 year ago

Also note that MELOS_PACKAGES environment variable does not have a command line flag, while MELOS_SDK_PATH has --sdk-path.

kankaristo commented 1 year ago

I agree, the current way that packageFilters works is not intuitive; it's strange that it "triggers" interactivity.

I would prefer for there to be a --select flag if I want to select packages interactively, instead of having to specify the current --no-select every time that I want a "regular" non-interactive run.

At the very least, there should be a way to specify --no-select in melos.yaml when using packageFilters (if there is a way to do this, I couldn't find it in the documentation). I'm currently working around this by doing something like this (to avoid typing --no-select on every run):

scripts:
  x:
    run: melos run _x --no-select
  _x:
    exec: ...
    packageFilters:
      ignore: ...
tgrushka commented 11 months ago

Really. If you pass --depends-on as a command line argument to melos exec, it works without prompting. Why does simply adding it as a config map option force a prompt? Should have a select option/flag to prompt.