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

mun*_*air 7 git json node.js npm

我想把我自己的一个存储库作为我正在处理的项目的依赖项.现在我正在使用NPM链接来做到这一点.此外,我希望它提示我输入用户名和密码,而不是在我使用npm install时将这种数据放入我的存储库中.我怎么做?它现在不这样做.

我希望存储库的内容显示为他们自己的文件夹问题是当我运行npm install时它会给我一些来自NPM的错误消息.所以我尝试了两件事.首先,我尝试从github克隆一个公共仓库:

Public Repo Github

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

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

},
Run Code Online (Sandbox Code Playgroud)

^请注意,数据是假的.#是提交哈希.

当我运行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
Run Code Online (Sandbox Code Playgroud)

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

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

},
Run Code Online (Sandbox Code Playgroud)

它工作.....有点.它似乎在链接中安装了repo的所有依赖项,但没有在repo_name的链接中克隆repo,它似乎没有克隆任何东西.

所以我决定尝试不同的回购.一个没有自己的依赖.我使用了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.
Run Code Online (Sandbox Code Playgroud)

私人存储库Bitbucket

当我通过提供的bitbucket字符串(带有提交哈希)通过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>
Run Code Online (Sandbox Code Playgroud)

它不会提示我输入用户名或密码.

在私有仓库上使用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
Run Code Online (Sandbox Code Playgroud)

tho*_*ows 3

npm 无法提示输入用户名或密码。它只是不是为了那样工作而设计的。有几种方法可以让你所做的事情发挥作用。

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

2)将私有包公开(即开源它)

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

4) 如果您正在制作开源项目,请制作一个公共 npm 包。您仍然可以使用 npm link 将项目链接到辅助项目,以便在发布之前测试包。依赖项将根据您的而不是文件夹名称进行链接。

但通常不推荐选项 1 和 2。不使用 npm 包根本就违背了使用 npm 的目的。您应该尽量避免直接链接到 github,除非有情有可原的情况,例如您需要分叉不再维护的项目并更改代码。

如果您只是想避免为私有 npm 模块付费,我个人不会费心将应用程序逻辑分离到不同的包中。


只是为了说明一切。也许您正在尝试创建一个模块并且以前从未这样做过,所以我也会对此进行解释。如果您有一个私有或公共应用程序(不是 npm 模块,并且您正在尝试创建一个公共开源 npm 模块并链接到它。)

假设您有两个文件夹。

/git/my_application
/git/my_new_npm_module
Run Code Online (Sandbox Code Playgroud)

并且您的新 npm 模块在 package.json 中的包名称为“new-module”。为了在 my_application 应用程序中使用它,您需要进入该目录并在 npm 模块上运行 npm link

cd /git/my_application
npm link ../my_new_npm_module
Run Code Online (Sandbox Code Playgroud)

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

当您准备好公开您的包时,您只需更新新模块 package.json 中的版本标记并输入

npm publish
Run Code Online (Sandbox Code Playgroud)