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.17k stars 205 forks source link

request: Add pre-command hooks #308

Open ookami-kb opened 2 years ago

ookami-kb commented 2 years ago

Is there an existing feature request for this?

Command

No response

Description

I would like to have a possibility to set up some hook that is running before each script is executed.

Reasoning

Currently, it's inconvenient to use multi-line scripts, as an error in one command won't fail the whole script. I can fix that by adding set -e to the script, but I need to do it for each script separately.

In the same way we have commands hooks, we can define some scripts with special meaning, e.g. setUp:

scripts:
  setUp: set -ex

that will run before each script (something like dart setUp function in tests).

Additional context and comments

No response

blaugold commented 2 years ago

I think we want to keep the scripts feature relatively simple and encourage users to externalize more complex scripts. We are using basic shells that are available on every system to allow users to specify a command line, but it's probably not a good idea to use scripts for anything more elaborate because they won't be cross-platform compatible.

I thought about adding -e per default when running a script with sh, but there is no equivalent for cmd.exe. Combining commands with && works everywhere.

blaugold commented 2 years ago

Yaml's multiline strings are a bit of a trap when used for scripts. I think we should warn users when they use multiline scripts and allow them to suppress the warning.

ookami-kb commented 2 years ago

I thought about adding -e per default when running a script with sh, but there is no equivalent for cmd.exe.

I understand that, that's why my proposition was to add custom setUp script rather than enabling this by default.

I think we want to keep the scripts feature relatively simple and encourage users to externalize more complex scripts.

That's understandable, but even for 2-lines script I either have to use && (which is less readable imho), or add set -e for each script, or make it an external script (and add set -e there as well).