babel: babel-node shouldn't pass the arguments-separator (`--`)

Input Code

Example repo: https://github.com/florianb/babelbug

console.dir(process.argv)

Babel Configuration (.babelrc, package.json, cli command)

None

Expected Behavior

Calling

babel-node index.js -- --version

should pass

[ 'node',
'/<...>/babelbug/index.js',
'--version' ]

to the called program.

Current Behavior

Calling

babel-node index.js -- --version

currently passes

[ 'node',
'/<...>/babelbug/index.js',
'--',
'--version' ]

to the called program.

Possible Solution

Increase the beginning index of the sliced userArgs (in https://github.com/babel/babel/blob/7.0/packages/babel-cli/src/babel-node.js#L17) by one:

userArgs = babelArgs.slice(argSeparator + 1); // including the  --

(The comment should, of course, be removed)

Context

I am trying to develop a command line app which is able to call other commands. In some cases i am calling commands with that command-line-tool, passing all arguments after the separator -- to the called command (i’m using minimist for that purpose).

However, i had to find out, that using babel-node just passes the first separator, too - which should separate babel-node arguments from the arguments mentioned to be consumed by my command-line application.

My command-line app now recieves the double-dash as first argument and since it is common practice to pass these arguments (following the arg-separator) to subsequent command calls, minimist puts them away for later use. Which leads to the current situation, that my application in fact doesn’t receive any dedicated arguments.

I really think the current behavior of babel-node is wrong, it should consume it’s arguments and the argument-separator and it should pass all arguments behind the separator to the executed program. So it is possible to chain calls as it is the separators intention.

I’d be happy to create a PR for that.

Your Environment

software version
Babel 6.18.0
node 7.4.0
npm 4.3.0
Operating System Darwin Kernel Version 15.6.0: Mon Jan 9 23:07:29 PST 2017; root:xnu-3248.60.11.2.1~1/RELEASE_X86_64 x86_64

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 3
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Another option which is not getting passed by babel-node is --require.

babel-node --require ./dev/mock.js ./src/script.js does not work. It doesn’t even run the script.

Alright @loganfsmyth, i would then propose

Refine the babel-node interface-docs

From currently

babel-node [options] [ -e script | script.js ] [arguments]

to

babel-node [options] [script.js | -e "script"] [--] [arguments]

where the -- should probably be documented as in the node-docs:

Indicate the end of node options. Pass the rest of the arguments to the script. If no script filename or eval/print script is supplied prior to this, then the next argument will be used as a script filename.

Fix the options parsing

From currently also acting on options after a script-name/eval-option/double-dash, to ignore options after a script-name/eval-option/double-dash.

💡 I would also like to bring to mind that babel-node is hiding node’s --version and --help options.

❓ Should i rewrite the issue-title/-text?

Or maybe we take everything up to the first argument we recognize as Node args, then take everything from there up to the filename as babel-node args, and everything after that as script args?

@conradoramalho I think you meant to tag someone else. I wasn’t involved in this discussion at all until you tagged me 😃