0

I need to install a module from a private github repo. In order to do that I'll run npm install git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>. My package.json file would look something like this:

"dependencies: {
    ...
    "private-repo-name": "git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>",
    ...
}

In this case, "private-repo-name" corresponds to the name field of the package.json of the private repo, i.e.:

"name": "private-repo-name"

My question is: How do I change the package name during npm install without changing the name field of the private repo?

Note: For public npm modules this wouldn't be a problem due to npm modules not sharing namespaces in the npm registry, but for privately developed modules that arent hosted in npm, there is a potential for the module name to conflict with current or future public npm modules in the npm registry.

t.c
  • 623
  • 5
  • 19
  • I haven't researched this (so offering as a comment, not an answer), but I would imagine if you scope the private package in its `package.json` you would be fine. By setting `name` in `private-repo-name`'s `package.json` then npm will install it with that name. Might I suggest something along the lines of `@my-company/private-package-name` for the name. – vivalldi Aug 02 '19 at 04:24
  • In this case, assume that I cannot change anything from the private repo. Thus I can't change the `name` field in `private-repo-name`'s `package.json` – t.c Aug 02 '19 at 07:33

2 Answers2

0

it can be done by setting up system HTTP_PROXY and HTTPS_PROXY environment variable to your private repo. after that it will work for command like npm install. but it will install the package with the name they have in the repo.

Swaroop
  • 7
  • 2
0

It turns out that you can simply run npm install new-name@git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>

how to install multiple versions of package using npm

There's no coupling between the keys in the dependencies field & the name field in the private repo.

i.e.

"dependencies: {
    ...
    "new-name": "git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>",
    ...
}

After this, commands like npm update new-name would work as expected.

t.c
  • 623
  • 5
  • 19