melos icon indicating copy to clipboard operation
melos copied to clipboard

fix: allow passing additional arguments to multiline run commands

Open KoheiKanagu opened this issue 2 years ago โ€ข 6 comments

Description

Fix #232

Type of Change

  • [ ] โœจ feat -- New feature (non-breaking change which adds functionality)
  • [x] ๐Ÿ› ๏ธ fix -- Bug fix (non-breaking change which fixes an issue)
  • [ ] โŒ ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] ๐Ÿงน refactor -- Code refactor
  • [ ] โœ… ci -- Build configuration change
  • [ ] ๐Ÿ“ docs -- Documentation
  • [ ] ๐Ÿ—‘๏ธ chore -- Chore

KoheiKanagu avatar May 16 '23 03:05 KoheiKanagu

To view this pull requests documentation preview, visit the following URL:

melos.invertase.dev/~525

Documentation is deployed and generated using docs.page.

docs-page[bot] avatar May 16 '23 03:05 docs-page[bot]

@KoheiKanagu sorry for the long delay, is this still needed after #540?

spydon avatar Dec 27 '23 08:12 spydon

@spydon Yes, it is needed. #232 has not been resolved.

KoheiKanagu avatar Dec 27 '23 08:12 KoheiKanagu

@blaugold you had some comments about this functionality in the issue, what do you think about this PR?

spydon avatar Dec 28 '23 09:12 spydon

In its current state, this PR would be a breaking change, because it changes from appending extra args to the script to passing them as extra args to the shell, which means they are only accessible through $1, $2, ...

In general, multiline scripts are a bit of a footgun and I don't think we should expand support for them. Melos just passes the script to the system shell. To ensure that multiple commands within a script fail fast, they all have to be concatenated through &&. This is the only approach that works across Windows and UNIX system shells.

I think we should keep Melos simple and keep the current behaviour of forwarding scripts with minimal processing to the system shell. This is how NPM scripts work, too. I would recommend maintaining scripts that are more complex in a separate file and just invoke the file through Melos. If you do that, extra parameters can be accessed through $1, $2 (in the case of sh type shells) in the script.

If we really want to support multiline scripts, we should look at CI/CD platforms like GitHub Actions for how to deal with cross-platform concerns and how to avoid unexpected behaviour.

blaugold avatar Jan 02 '24 09:01 blaugold

I agree that Melos should be kept simple.

In the current Melos, multiline scripts can be executed, but they may not behave as expected. For example, #232 shows an error that occurs when a multiline script is executed.

I think Melos should return an error when trying to execute a multiline script. Or, it would be better to state in the documentation that multiline scripts are not supported. This would prevent users from encountering unexpected errors.

KoheiKanagu avatar Jan 02 '24 14:01 KoheiKanagu

I'll close this and then we can continue to discuss in the issue, thanks for the effort though!

spydon avatar Mar 11 '24 20:03 spydon