Storing multiple NPM libraries in single Git repo

2019-08-28 22:03发布

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条回答
smile是对你的礼貌
2楼-- · 2019-08-28 22:13

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.

查看更多
登录 后发表回答