如何使用多个嵌套的私有节点模块?

How to use multiple nested private node modules?

以下是我的项目结构

Base Application
  |
  |----Node Module 1 
  |       |
  |       |----Node Module 2
  |
  |----Node Module 2

所有这些都是私有存储库。我在基础应用程序的 package.json

中添加了以下内容
{
name: "Base Application",
  dependencies: {
  ..
  node-module1: "git+https://github.com/abc/node-module1.git",
  node-module2: "git+https://github.com/abc/node-module2.git",
  ..
  }
}

我使用 HTTPS 版本 (https://github.com/abc/base-application.git) 克隆了我的存储库,它提示我输入用户名和密码。克隆后,当我尝试执行 npm install 时,出现以下错误

npm ERR! Cloning into bare repository '/home/ubuntu/.npm/_git-remotes/git-https-github-com-abc-node-module1-git-3bd17fdf3s45ae0sdfadf68sdegk72e3'...
npm ERR! remote: Invalid username or password.
npm ERR! fatal: Authentication failed for 'https://github.com/abc/node-module1.git/'

经过一些挖掘,我修改了 package.json 以包含建议的版本 here

{
name: "Base Application",
  dependencies: {
  ..
  node-module1: "git+https://github.com/abc/node-module1.git#v0.0.1",
  node-module2: "git+https://github.com/abc/node-module2.git#v0.0.1",
  ..
  }
}

这行得通。但问题是我被提示输入用户名和密码多次。每次进行微小更改时,这也会增加在节点模块中创建版本的复杂性。

那么我如何像使用 public 一样使用私有节点模块。

检查您是否在 package.json 中表明了自己的身份,如“How to use private Github repo as npm dependency

中所述

https and oauth: create an access token that has "repo" scope and then use this syntax:

"package-name": "git+https://<github_token>:x-oauth-basic@github.com/<user>/<repo>.git"

这样,npm install 应该可以访问那些私有存储库而无需再次询问凭据。

除了版本,您还可以引用特定的分支,例如 master,这样您就不需要为每次提交都修改版本。

"node-module1": "git://github.com/abc/node-module1.git#master"

但是,我建议坚持使用 semantic versioning, and consider setting up your own private NPM repository such as https://github.com/rlidwka/sinopia。要测试在另一个 module/app 中正在开发的模块,您可以使用 npm link,然后在完成后发布版本化模块,每当您进行 API-incompatible 更改时,总是会更新主版本。