LiveScript icon indicating copy to clipboard operation
LiveScript copied to clipboard

Impossible to pass arguments to Node.js (using `--nodejs`) and execute a script from file name at the same time

Open ymeine opened this issue 9 years ago • 6 comments

Context

  • commit: 55ada776d82c06c274cd5e976c62d15a0c1f2fd9

Examples

Let me describe by examples:

  • lsc --nodejs --harmony --harmony-proxies will work as expected, but will start interactive mode
  • lsc --nodejs --harmony --harmony-proxies index.ls -a -b arg1 arg2 won't
  • lsc index.ls -a -b arg1 arg2 --nodejs --harmony --harmony-proxies won't either

Problem statement

The actual problem comes from the requirement: being able to pass an arbitrary sequence of arguments both for the invoked user program and for the Node.js executable.

Indeed, the second example will pass everything to Node.js, while the third will pass everything to the user program.

Investigation

I tried implementing different arguments processing before realizing the statement above: no implementation will allow passing any argument to any of these two programs (in this case we would forbid passing --nodejs/-n to user programs, or forbid passing purely positional arguments to Node.js).


Am I missing something?

If true, what would be suitable alternatives to input arguments without conflict?

The key is not to merge things that can conflict when present in one single input. Here are the different ones I'm thinking of regarding the invocation of a program:

  • stdin: but already used to read the user program content if -s is activated
  • command line
    • directly as a string: in this case can we fully escape everything to write an embedded command line?
    • path to a file containing the string: but this requires having a file containing the list of arguments, not handy

ymeine avatar Apr 15 '16 14:04 ymeine

Several points:

  1. lsc arguments always need to be passed before the script name. Otherwise we consider they're script arguments (no other way here).
  2. The arguments to the --nodejs flag, AFAIK, must be passed all at once (again, we can't know otherwise).

Use this line to invoke your script instead:

lsc --nodejs '--harmony --harmony-proxies' index.ls -a -b arg1 arg2

and tell us if that solves your issue.

vendethiel avatar Apr 15 '16 14:04 vendethiel

I didn't mention passing arguments to lsc itself, I described passing arbitrary arguments to Node.js and to the user program (the script). In fact, the point you mentioned is correct, lsc will consider all positional arguments to be at the end of the command line, and to correspond to [script_name, ...script_args]. It's its way to get the arbitrary arguments for the script.

However for the Node.js arguments it's a bit different:

  • if --nodejs is at the end, it will be captured by script_args and won't be detected (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/command.ls#L41), therefore passed as is to the script.
  • if it's before, everything after --nodejs will be captured and passed to Node.js, therefore making it impossible to pass positional arguments to lsc.

It's because the arguments list for Node.js is not input as a String (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/options.ls#L52) and just eats the rest of the command line (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/options.ls#L54).

ymeine avatar Apr 15 '16 14:04 ymeine

you also can't currently combine -e, -c, and -p), to compile a one liner without saving it first or using stdin/repl (compile from command line as input)

Announcement avatar May 17 '16 20:05 Announcement

This is still a thing. Makes it impossible to start Node in debug mode.

  • --nodejs before file name

    lsc --nodejs 'inspector' main.ls
    

    This does the equivalent of node inspector main.ls, starting in debug mode but dying on syntax error.

  • --nodejs after file name

    lsc main.ls --nodejs 'inspector'
    

    This just passes --nodejs and 'inspector' as arguments to main.ls, and doesn't start in debug mode.

anko avatar Mar 11 '19 07:03 anko

What do you think of a fix that makes --nodejs take String instead of Boolean as it does currently?

Might have to child_process.exec node over here in command.ls instead instead of child_process.spawn, so any quoted stuff and spaces in that --nodejs option string are handled according to the expected shell rules?

anko avatar Mar 11 '19 07:03 anko

What do you think of a fix that makes --nodejs take String instead of Boolean as it does currently?

That's how CoffeeScript has it. :+1: for me.

vendethiel avatar Mar 11 '19 09:03 vendethiel