Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --inspect flag to be provided after script name #11028

Closed
scottmas opened this issue Jan 26, 2017 · 7 comments
Closed

Allow --inspect flag to be provided after script name #11028

scottmas opened this issue Jan 26, 2017 · 7 comments
Labels
cli Issues and PRs related to the Node.js command line interface. feature request Issues that request new features to be added to Node.js.

Comments

@scottmas
Copy link

  • Version: 7.4
  • Platform: Sierra OSx

Currently, only this works

node --inspect myscript.js

It seems dumb that the following shouldn't work

node myscript.js --inspect

This becomes especially important when doing complex npm run scripts with passed arguments. For instance, if this feature existed, then we could define a regular run-script and a debug run-script in our package.json, like so

"scripts": {
  "regular": "node myscript.js",
  "debug": "npm run regular -- --inspect"
}

But this fails for the reasons described above.

Also, it just makes sense that order shouldn't matter with command line flags.

@mscdex mscdex added cli Issues and PRs related to the Node.js command line interface. feature request Issues that request new features to be added to Node.js. labels Jan 26, 2017
@mscdex
Copy link
Contributor

mscdex commented Jan 26, 2017

I'm -1 on this because it places unnecessary restrictions on user scripts for a minor "inconvenience."

@gibfahn
Copy link
Member

gibfahn commented Jan 26, 2017

I'm -1 on this because it places unnecessary restrictions on user scripts for a minor "inconvenience."

@mscdex could you elaborate? Do you mean that if you "fix" this then you can't pass --install as an argument to your script?

@sholladay
Copy link
Contributor

sholladay commented Jan 27, 2017

@gibfahn I think the issue is if Node starts swallowing arguments after the script, it will lead to confusing behavior in user-land.

What if myscript.js wants to accept its own --inspect option?

For example, if myscript.js is console.log(process.argv), then it prints (with the debugging help removed):

Seth-Laptop:tmp sholladay$ node myscript.js 
[ '/usr/local/Cellar/node/7.4.0/bin/node',
  '/private/tmp/myscript.js' ]
Seth-Laptop:tmp sholladay$ node --inspect myscript.js 
[ '/usr/local/Cellar/node/7.4.0/bin/node',
  '/private/tmp/myscript.js' ]
Seth-Laptop:tmp sholladay$ node myscript.js --inspect
[ '/usr/local/Cellar/node/7.4.0/bin/node',
  '/private/tmp/myscript.js',
  '--inspect' ]

The consequences of changing the above output would be severe.

@evanlucas
Copy link
Contributor

evanlucas commented Jan 27, 2017

Wouldn't that mean that node myscript.js --help would print node's usage? If so, that would break almost every cli tool written for node. Our options parser works that way so that node's options don't interfere with options that a user defines. You could probably do something like this though (EDIT: This is untested, btw):

"scripts": {
  "regular": "node $NODE_OPTIONS myscript.js",
  "debug": "NODE_OPTIONS=--inspect npm run regular"
}

@mscdex
Copy link
Contributor

mscdex commented Jan 27, 2017

@gibfahn Correct, you at least couldn't use --.

I just think there's too much potential breakage for such little gain. I think a better solution would be something less intrusive, like an environment variable or something.

@evanlucas
Copy link
Contributor

I'm going to go ahead and close as I don't see this as being something we can do without breaking a large part of the ecosystem. Thanks!

@scottmas
Copy link
Author

Okay cool, thanks for the quick response all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

5 participants