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

"not-in-install" failed to find command when giving custom configs between "npm" and "install" #8

Open
mettatw opened this issue Mar 22, 2016 · 3 comments

Comments

@mettatw
Copy link

mettatw commented Mar 22, 2016

When using commands like npm --userconfig file install instead of plain npm install, not-in-install always returns true.

Steps to reproduce are as follows, in an empty folder:

sh-4.3$ npm install in-publish
sh-4.3$ echo '{"scripts":{"prepublish":"not-in-install && echo Yeah || in-install"}}' > package.json
# The normal case
sh-4.3$ npm install

> undefined prepublish /tmp/test1
> not-in-install && echo Yeah || in-install

# The bugged case
sh-4.3$ npm --userconfig non-exist-file install                                                                                              

> undefined prepublish /tmp/test1
> not-in-install && echo Yeah || in-install

Yeah
sh-4.3$ npm --userconfig=non-exist-file install                                                                                              

> undefined prepublish /tmp/test1
> not-in-install && echo Yeah || in-install

Yeah

Tested on an ubuntu 14.04 box:

npm_config_user_agent=npm/3.6.0 node/v5.6.0 linux x64

and on Windows 7 x64 (with cygwin):

npm_config_user_agent=npm/3.6.0 node/v5.7.1 win32 x64

The problem may be in this part of index.js:

 while ((V = npm_config_argv.cooked.shift()) !== undefined) {
    if (/^-/.test(V)) continue
    if (cmd.test(V)) return true
    return false
  }

That return false returned when it encounter the non-exist-file entry after --userconfig, causing it not able to test the RegExp against install.

My current workaround is to change the command to --userconfig=non-exist-file and modify the above code to use npm_config_argv.original instead of npm_config_argv.cooked so that both side of = will be in the same entry of the array. I'm not sure whether this will cause other problems tho...

@mettatw
Copy link
Author

mettatw commented Mar 23, 2016

Just figure out a better workaround: just postfix the custom config options, such as npm install --userconfig non-exist-file.

p.s. I mainly work on Windows and use --userconfig inside a script to make npm kind of portable...

@iarna
Copy link
Owner

iarna commented Mar 28, 2016

Thanks for finding this, I'll have to invest in better (read: actual) argument parsing there.

@shellscape
Copy link

I can confirm this is an issue with in-publish as well.

I have an alias setup in .zshrc:

alias npmss='npm --userconfig=$HOME/shellscape/.npmrc'

Which results in the following npm_config_argv:

{ remain: [],
  cooked: [ '--userconfig', '/(home)/shellscape/.npmrc', 'publish' ],
  original: [ '--userconfig=/(home)/shellscape/.npmrc', 'publish' ] }

Rather large problem since user configs are a widely used option. The simple fix for me was:

  while ((V = npm_config_argv.cooked.shift()) !== undefined) {
    if (cmd.test(V)) return true
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants