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.1k stars 195 forks source link

Proposal: platform specific run scripts #122

Open 2ZeroSix opened 3 years ago

2ZeroSix commented 3 years ago

Problem:

It seems impossible to properly support multi-platform parsing of command in run section without invention of its own scripting language

For example this issue #15 is caused and cannot be easily and fully fixed because of custom cmd and sh handling

Proposal:

allow platform specific scripts

for example

scripts:
  my:command:
    run:
      windows: echo hey %USERNAME%
      unix: echo hey $USER

or

scripts:
  my:command:
    run:
      batch: path\to\script.bat
      shell: path/to/script.sh

then it would be possible to pass script in run section as-is to underlying interpreter without any custom parsing

Salakar commented 3 years ago

Would writing a dart script not be easier and cleaner for cross-platform execution, we have an example on the melos repo itself:

https://github.com/invertase/melos/blob/master/melos.yaml#L40 https://github.com/invertase/melos/blob/master/scripts/generate_version.dart

You could even add a pubspec.yaml at the root of your monorepo for any dev dependencies you may need for your scripts:

https://github.com/invertase/melos/blob/master/melos.yaml#L4 https://github.com/invertase/melos/blob/master/pubspec.yaml#L11-L12


I wanted to originally add something like you've mentioned before but opted not to since we can just write a cross-platform script using a single Dart file

2ZeroSix commented 3 years ago

Thanks for nice example!

Probably for most cases dart script would be a perfect solution.

Then run section docs must properly state that it's not intended to be used for full-featured scripts. As I can see && for chains and \, ^ for line continuations are "safe" expressions

Salakar commented 3 years ago

We are going through and updating the docs to have more examples and information on cross-platform scripts 🙈 sorry it's not fully documented yet

Then run section docs must properly state that it's not intended to be used for full-featured scripts. As I can see && for chains and \, ^ for line continuations are "safe" expressions

Is there any code improvements to Melos you would suggest we make to improve this?

2ZeroSix commented 3 years ago

I was thinking about this over the weekend, and I can say that this problem is much more complicated than I initially expected

Here is long running issue in npm (this is what lerna use in lerna run <script> by default): https://github.com/npm/npm/issues/4040 issue in yarn caused by some custom escape character parsing: https://github.com/yarnpkg/yarn/issues/7732 and there is many more in the wild

It seems critical to choose appropriate solution as soon as possible while most of the users are early adopters

Possible solutions:

Tokenyet commented 2 years ago

I think this is a must feature for cross-platform, because I met a line break issue on windows quickly.

  test:
    run: |
      flutter test --exclude-tags "integration" && \
      flutter pub run melos exec -c 1 --fail-fast -- \
        "flutter test --no-pub --exclude-tags "integration"
    description: Run `flutter test` for a specific package.
    select-package:
      dir-exists:
        - test
  test:windows:
    run: |
      flutter test --exclude-tags "integration" && ^
      flutter pub run melos exec -c 1 --fail-fast -- \
        "flutter test --no-pub --exclude-tags "integration"
    description: Run `flutter test` for a specific package.
    select-package:
      dir-exists:
        - test

Line break is different on windows (cmd), so can't be used easily, but almost the same code.

Edit Nevermind, Line break can be resolved by changing YAML syntax from | to >-.