簡體   English   中英

如何使用多個嵌套的私有節點模塊?

[英]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以包含此處建議的版本。

{
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",
  ..
  }
}

這有效。 但問題是,我被提示輸入用戶名和密碼多次 這也將導致每次進行一分鍾更改時在節點模塊中創建版本的復雜性。

那么我如何使用私有節點模塊作為我們如何使用公共模塊。

檢查您是否在package.json標識自己,如“ 如何將私有Github repo用作npm依賴項 ”中所述

https和oauth創建具有“repo”范圍的訪問令牌 ,然后使用以下語法:

"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"

但是,我建議堅持使用語義版本控制 ,並考慮建立自己的私有NPM存儲庫,例如https://github.com/rlidwka/sinopia 要測試另一個模塊/應用程序中正在開發的模塊,您可以使用npm link ,然后在完成后發布版本化模塊,每當進行API不兼容的更改時,總是碰撞主要版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM