Storing multiple NPM libraries in single Git repo

故事扮演 提交于 2019-12-11 19:46:40

问题


We can reference NPM deps on Github like so:

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

But I have a Git repo with multiple NPM libraries in it, like so:

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

is there a way to install foo from this Github repo directly? Something like this?

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

I tried installing using that url, and it didn't work, I got this error:

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

I also tried using raw.githubusercontent.com like so:

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

And I got the same error. Surely this must be possible somehow?


回答1:


Ok so one solution is to use tarballs. So you can use this command:

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

it worked..and I get this in package.json:

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

basically all you need to do is npm install with a url that points to a tarball.



来源:https://stackoverflow.com/questions/53628830/storing-multiple-npm-libraries-in-single-git-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!