【问题标题】:Storing multiple NPM libraries in single Git repo在单个 Git 存储库中存储多个 NPM 库
【发布时间】:2019-05-06 19:37:21
【问题描述】:

我们可以像这样在 Github 上引用 NPM deps:

"dependencies":{
   "foo":"github.com/org/root#commit"
}

但我有一个 Git 存储库,其中包含多个 NPM 库,如下所示:

root/
  nodejs/
    foo/
      package.json
    bar/
      package.json

有没有办法直接从这个 Github repo 安装 foo?像这样?

"dependencies":{
   "foo":"github.com/org/root/nodejs/foo#commit"
}

我尝试使用该网址进行安装,但没有成功,我收到此错误:

npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: https://raw.githubusercontent.com/org/root/master/nodejs/foo/package.json.
npm ERR! package.json npm can't find a package.json file in your current directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/oleg/.npm/_logs/2018-12-05T09_15_28_666Z-debug.log

我也尝试过像这样使用 raw.githubusercontent.com:

"dependencies":{
   "foo":"raw.githubusercontent.com/org/root/nodejs/foo#commit"
}

我也遇到了同样的错误。这肯定有可能吗?

【问题讨论】:

标签: git github npm npm-install


【解决方案1】:

好的,一种解决方案是使用 tarball。所以你可以使用这个命令:

 npm i -S 'https://raw.githubusercontent.com/org/root/master/nodejs/foo/foo-0.0.1001.tgz'

它起作用了..我在 package.json 中得到了这个:

 "dependencies": {
    "foo": "https://raw.githubusercontent.com/org/root/master/nodejs/foo/foo-0.0.1001.tgz"
  }

基本上,您需要做的就是使用指向 tarball 的 url 进行 npm install。

【讨论】:

  • 显然不能很好地与 semver 一起工作,因为我们被困在一个精确的版本中,但是,嘿
猜你喜欢
  • 2018-04-05
  • 1970-01-01
  • 1970-01-01
  • 2016-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
相关资源
最近更新 更多