“npm isntall” command exists

跟風遠走 提交于 2019-12-10 01:11:53

问题


When you type an illegal npm command, you are getting a user-friendly error message stating which commands are legal to use:

$ npm illegal

Usage: npm <command>

where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, issues, la, link,
    list, ll, ln, login, ls, outdated, owner, pack, prefix,
    prune, publish, r, rb, rebuild, remove, repo, restart, rm,
    root, run-script, s, se, search, set, show, shrinkwrap,
    star, stars, start, stop, submodule, tag, test, tst, un,
    uninstall, unlink, unpublish, unstar, up, update, v,
    version, view, whoami

As you may notice, among others there is isntall command.

What is the point of this command? If this was created to handle typos, then why doesn't it have a special handling for intall, insatll etc? Besides, uninstall doesn't have a corresponding unisntall option.

(Using npm 1.3.22 version).


The reason I ask is that I'm a bit surprised and confused about how the typo is handled. For example, git compares the command you've entered and suggests the closest commands it has available:

$ git stats
git: 'stats' is not a git command. See 'git --help'.

Did you mean this?
    status

Also, pip Python package manager has a similar functionality built-in:

$ pip isntall
ERROR: unknown command "isntall" - maybe you meant "install"

FYI, under-the-hood it uses difflib.get_close_matches() function.


回答1:


I was the original "raiser" of the connected issue on Github, and those were the first days of contributing to OSS software... I thought it was just a typo, and maybe a pull request would solve it. But I was blessed with some good sense to first raise an issue (#2933) to find out if they were looking for contribution on that front...

As it turned out, it unravelled a whole discussion around the issue, which was good to see.

The raison d'être of the isntall command is because the npm maintainers believe that it saves them time — and thus, by extension — several other developers. As has been discussed in the linked issue, this was a contentious decision, and several people have suggested more interesting methods for resolving typos such as using the levenshtein distance calculation of the illegal command from valid npm commands (https://www.npmjs.org/package/levenshtein).

At any rate, I presume if you do implement one of those algos and contribute to the npm project, it would be a nice addition to this awesome library...




回答2:


Because there's no way to handle every single possible typo, without breaking other stuff. Init could possibly be a typo of install.

Could do levenshtein distance from your input or something but introduces unnecessary complexity.



来源:https://stackoverflow.com/questions/26987238/npm-isntall-command-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!