melos icon indicating copy to clipboard operation
melos copied to clipboard

request: Allow overriding default scripts within melos.yaml

Open btrautmann opened this issue 10 months ago • 8 comments

Is there an existing feature request for this?

  • [x] I have searched the existing issues.

Command

No response

Description

In v5.1.0 the format command was introduced as a default command. However, our team already had a format command with some specifics used that are not supported by default filtering (AFAIK). We could run it by invoking either melos run format or melos format. In the latter case, melos knew that if we had a script named format it should run that. However, when v5.1.0 was introduced, the built-in command made it so that we could no longer run our format command via melos format.

This means we now need to change our command to something like fooFormat to avoid the collision if we indeed want melos fooFormat to be possible. This makes DX slightly worse/more confusing, and it would be ideal if we could override the default behavior with our own behavior by way of defining the script in melos.yaml.

Expected behavior: Defining a script foo in melos.yaml would override default behavior of melos foo, if any exists, such that you can run melos foo or melos run foo and have the expected behavior.

Current behavior: Running melos foo will have potentially different behavior than running melos run foo if a built-in foo command exists and functions differently.

Please let me know if I can offer any other details to make my request more clear!

Reasoning

I hope my previous answer addressed my reasoning!

Additional context and comments

No response

Other

  • [x] I'm interested in working on a PR for this.

btrautmann avatar Mar 06 '25 15:03 btrautmann

I just updated the Issue Description to better clarify a few things after playing with this more

btrautmann avatar Mar 20 '25 18:03 btrautmann

Sounds good! Sorry for the late reply. I'll assign you to the issue. :)

spydon avatar Mar 20 '25 18:03 spydon

It is actually already possible to override scripts in melos >v7.

spydon avatar Apr 08 '25 13:04 spydon

It is actually already possible to override scripts in melos >v7.

Are you sure? I'm on 7.0.0-dev.7 and I believe it's this line and this one that basically remove any of your scripts that share a name with a built-in one.

I tried this just now on that version of melos by declaring a script called format that does a simple echo and I ran melos format and it ran the built-in command, not mine.

btrautmann avatar Apr 08 '25 14:04 btrautmann

Are you sure? I'm on 7.0.0-dev.7 and I believe it's this line and this one that basically remove any of your scripts that share a name with a built-in one.

I tried this just now on that version of melos by declaring a script called format that does a simple echo and I ran melos format and it ran the built-in command, not mine.

Are you sure that you have 7.0.0-dev.7 in your pubspec too? Because I tried the same thing, and it worked for me. 😅

spydon avatar Apr 08 '25 15:04 spydon

@btrautmann You're right, I accidentally tried with test before, tried with format now. Do you want to provide a PR that fixes it? :)

spydon avatar Apr 08 '25 16:04 spydon

@btrautmann You're right, I accidentally tried with test before, tried with format now. Do you want to provide a PR that fixes it? :)

Yeah I'm hoping I can get a PR up sooooon. It should be pretty easy, my plan is to just overwrite the default commands (rather than excludeing the custom ones that have the same name as a built-in one) or alternatively checking the custom ones before adding built-in ones and only adding built-ins that don't match a custom one. Either way, I don't think it'll be terribly hard, I just haven't had the time yet!

btrautmann avatar Apr 08 '25 17:04 btrautmann

Any updates on this @btrautmann? :)

spydon avatar Jun 18 '25 07:06 spydon

Any updates on this @btrautmann? :)

Sadly, no... Swamped with a project at the moment, but my team will be doing some OSS-focused work next quarter so I am hoping to squeeze this in.

btrautmann avatar Jun 23 '25 16:06 btrautmann

@spydon sorry for the delay here. I just had a sec so opened up https://github.com/invertase/melos/pull/945. I have to run, but will come back to this tomorrow to address any CI failures (lint, tests, etc.). Wanted to get your eyes on it in case there's anything fundamentally wrong about it that we should address. Thank you!

By the way, in addition to the dart test, I validated this in a flutter create -e project. Happy to share that project if you want to also give it a run.

Image

btrautmann avatar Sep 30 '25 21:09 btrautmann