melos icon indicating copy to clipboard operation
melos copied to clipboard

Melos scripts not parsing args fully

Open shmink opened this issue 1 year ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Version

3.2.0

Description

There's similar issues but I don't think they're exact in the same issues I'm seeing.

It seems to be that one can pass arguments to a melos script just as you would a bash script but the issue is that melos isn't working out where one argument begins and ends correctly.

Steps to reproduce

For example, from my melos.yaml file I have the following

  translations:test:
    run: $MELOS_ROOT_PATH/scripts/translations/test.sh

That test.sh file is below

echo "arg 1: "$1
echo "arg 2: "$2
echo "arg 3: "$3

If I run the script directly I get the following

~/work/app
❯ ./scripts/translations/test.sh "Hey there" "how" "are you?" 
arg 1: Hey there
arg 2: how
arg 3: are you?

If I run the melos version which is just pointing at the same script it does accept the arguments but I don't think it takes " " speech marks into account.

~/work/app                                                                                            
❯ melos translations:test "Hey there" "how" "are you?"
melos run translations:test
  └> $MELOS_ROOT_PATH/scripts/translations/test.sh Hey there how are you?
     └> RUNNING

arg 1: Hey
arg 2: there
arg 3: how

melos run translations:test
  └> $MELOS_ROOT_PATH/scripts/translations/test.sh Hey there how are you?
     └> SUCCESS

It looks like it sees ANY space as a separation in arguments.

Expected behavior

I would expect

~/work/app                                                                                            
❯ melos translations:test "Hey there" "how" "are you?"
melos run translations:test
  └> $MELOS_ROOT_PATH/scripts/translations/test.sh Hey there how are you?
     └> RUNNING

arg 1: Hey there
arg 2: how
arg 3: are you?

melos run translations:test
  └> $MELOS_ROOT_PATH/scripts/translations/test.sh Hey there how are you?
     └> SUCCESS

Screenshots

No response

Additional context and comments

No response

shmink avatar Feb 07 '24 12:02 shmink

Not that there should be any difference, but could you just verify that it is the same in the latest version (v4.1.0)?

spydon avatar Feb 07 '24 12:02 spydon

Unfortunately, I cannot due to dependency conflicts with the repo I work on. I was kind of hoping that some kind soul could just copy and paste my examples above as even creating a new project I run into other issues.

shmink avatar Feb 07 '24 13:02 shmink

You most likely have your monorepo set up in the wrong way if you get a dependency conflict with melos, check the recommended structure here (only melos should be in the root workspace pubspec): https://melos.invertase.dev/getting-started#recommended-directory-structure

spydon avatar Feb 07 '24 13:02 spydon

That structure looks like what I have but I'd rather stay on topic please.

shmink avatar Feb 07 '24 14:02 shmink

It is on topic, because if you can't test with the latest version it is much harder for us to debug.

spydon avatar Feb 07 '24 14:02 spydon

Fair enough. Finally managed to do it and yes the results are the same for v4.1

~/example                                                                                                                              
❯ melos --version
4.1.0

~/example                                                                                                                              
❯ ./test.sh "Hey there" "are" "you okay?"
arg 1: Hey there
arg 2: are
arg 3: you okay?

~/example                                                                                                                              
❯ cat melos.yaml 
name: example
sdkPath: .fvm/flutter_sdk

packages:
  - "*"

scripts:
  test:
    run: $MELOS_ROOT_PATH/test.sh

~/example                                                                                                                              
❯ melos test "Hey there" "are" "you okay?"
melos run test
  └> $MELOS_ROOT_PATH/test.sh Hey there are you okay?
     └> RUNNING

arg 1: Hey
arg 2: there
arg 3: are

melos run test
  └> $MELOS_ROOT_PATH/test.sh Hey there are you okay?
     └> SUCCESS

Still seems to be that melos sees any space as a separation in arguments ignoring cases where anything surrounded by speech marks should count as 1 argument.

In fact, in the final output it looks like " has been stripped out all together.

melos run test
  └> $MELOS_ROOT_PATH/test.sh Hey there are you okay?
     └> SUCCESS

shmink avatar Feb 07 '24 14:02 shmink

Can you try just doing MELOS_ROOT_PATH, without the $?

spydon avatar Apr 15 '24 09:04 spydon