如何使我的存储库成为package.json的一个依赖项并让它提示我input信息?

我想把我自己的一个版本库作为一个依赖于我正在开发的项目。 现在我正在使用NPM链接来做到这一点。 另外,当我使用npm install时,我希望它提示我input用户名和密码,而不是将这些数据放入我的存储库中。 我怎么做? 现在不这样做。

我想存储库的内容显示为自己的文件夹问题是,当我运行npm安装它给了我一堆来自NPM的错误消息。 所以我试了两件事 首先,我试图从github上克隆一个公共的repo:

公开回购Github

所以在package.json中,我使用了这样的ssh:

"dependencies": { "repo_name": "git@github.com:ownername/reponame.git#84876fa5aasf55fssfsfafsa" }, 

^请注意,数据是假的。 #是一个提交散列。

当我运行npm install时,它给了我这个错误:

 Warning: Permanently added the RSA host key for IP address '$IPADDRESS' to the list of known hosts. Permission denied (publickey) fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Code 128 

然后我尝试了HTTPS,再次提交哈希:

 "dependencies": { "repo_name": "https://github.com/ownername/reponame.git#84876fa5aasf55fssfsfafsa" }, 

它的工作…..种。 它似乎在链接安装所有从回购的依赖,但没有克隆到repo_name链接回购,它似乎并没有克隆任何东西。

所以我决定尝试一个不同的回购。 一个没有任何自己的依赖。 我用HTTPS ….它没有工作。

我得到这些错误:

 npm ERR! addLocal Could not install /tmp/npm-11929-4791330b/git-cache-2278328b/38b944c916c18cd4e004f07f2f476a4bb393ff8e npm ERR! Linux 4.8.0-58-generic npm ERR! argv "$nodepathname" "$npmpathname" "install" npm ERR! node v7.0.0 npm ERR! npm v3.10.8 npm ERR! code EISDIR npm ERR! errno -21 npm ERR! syscall read npm ERR! eisdir EISDIR: illegal operation on a directory, read npm ERR! eisdir This is most likely not a problem with npm itself npm ERR! eisdir and is related to npm not being able to find a package.json in npm ERR! eisdir a package you are trying to install. 

私人存储库Bitbucket

当我通过提供的bitbucketstring(使用提交散列)通过ssh尝试我的私有存储库时,它给了我与其他存储库类似的错误消息,它告诉我:

 Please make sure you have the correct access rights npm ERR! code 128 npm ERR! Permission denied (publickey). npm ERR! fatal: Could not read from remote repository. npm ERR! npm ERR! Please make sure you have the correct access rights npm ERR! and the repository exists. npm ERR! npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues> 

它不会提示我input用户名或密码。

在私有仓库上使用https(使用提交散列,与以前类似)给了我一个类似的错误,而不用任何用户名提示我:

  remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile. npm ERR! code 128 

npm无法提示input用户名或密码。 它只是没有devise工作的方式。 有几个方法可以使你做的工作。

1)生成一个ssh密钥(如果你还没有),并将其添加到你的bitbucket。

2)使私人包装公开(即开源)

3)支付私人npm包,并发布私人npm模块。

4)如果你做了开源项目,请制作公开的npm包。 您仍然可以使用npm链接将项目链接到辅助项目,以在发布之前testing这些包。 依赖关系将根据您的文件夹名称进行链接。

选项1和2通常不被推荐。 不使用npm包,完全不符合使用npm的目的。 你应该尽量避免直接链接到github上,除非有可能的情况下,如你需要分叉一个不再维护的项目和更改代码。

如果你只是想避免支付私人npm模块,个人我不会麻烦分开应用程序逻辑到不同的包。


只是为了所有的阐述。 也许你正在尝试创build一个模块,而且从来没有这样做过,所以我也会解释一下。 如果你有一个私有的或公共的应用程序(不是一个npm模块,而你正在尝试创build一个公共开源的npm模块并链接到它)。

可以说你有两个文件夹。

 /git/my_application /git/my_new_npm_module 

而你的新npm模块在package.json中有包名“new-module”。 为了在my_application应用程序中使用它,您需要input该目录并在npm模块上运行npm链接

 cd /git/my_application npm link ../my_new_npm_module 

现在在my_application应用程序中的任何节点文件中,可以使用require('new-module'); 来访问你新的npm模块输出的内容。

当你准备把你的软件包公开的时候,你只需要在新的模块package.json中更新版本标签并input

 npm publish 

你可以使用postinstall钩子在npm install之后启动Git克隆:

 "scripts": { "postinstall": "git clone ... node_modules/..." } 

在search具体问题后,我find了以下链接。 链接