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.13k stars 201 forks source link

request: introduce a wild character for script names #646

Closed pastre closed 7 months ago

pastre commented 7 months ago

Is there an existing feature request for this?

Command

No response

Description

Just like Makefile has the % wildcard, this proposal aims to introduce a wild card for custom scripts. This would give us flexibility to write reusable scripts that take arguments on their names

Reasoning

A use case would be to run scripts without the menu - it's more efficient to just type instead of searching for an option in the menu. Also allows for more creative rules

Additional context and comments

My initial proposal is to have the asterisk (*) character symbolise a wild card. We would only accept one wild card per rule, and just like make, replace each occurrence of the * character before executing the rule. Example: Given the following workspace description

...
scripts:
  test:*:
    name: Run unit tests on an specific package
    run: cd * && flutter test

when we run melos test:my_package

then we expect the following command to be executed: cd my_package && flutter test

I can already see some conflicts arising with this suggestion (e.g.: what if my command runs ls *, how would we differentiate the * with the variable?), so that's why I'm raising this here and looking for suggestions.

I'm happy to come up with an implementation, as soon as the idea is a little more concrete :) Thanks in advance!

spydon commented 7 months ago

Can't you just do something like this instead? :thinking:

scripts:
  test:
    name: Run unit tests on an specific package
    run: cd $1 && flutter test

And then run it with:

$ melos test your_packages

If it's just for packages I would advice using the MELOS_PACKAGES environment variable instead though.

I don't think we want more ways to do this.

pastre commented 7 months ago

Oh I didn't know it'd forward the arguments :D Thanks!