Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from private registry with fallback to a git repository URL

Tags:

git

node.js

npm

I am kind of a newbie regarding the npm, so please help.

Let's say that i have some modules i am working on using a git repository for each one of them and i also installed sinopia to have a private registry. The problem is that we are 2 teams. A team in a city and the other one is at world's end. In my team i have installed the private registry to be available in the local network. The issue here is that when we push on git, the other team doesn't have a private registry of their own, and even if they did they would need to publish each version of each module in their private registry. Also another issue is that we can't ( and don't want to ) make the sinopia server public via IP.

Now the question is: How can we configure the package.json / npm to manage dependencies from both the private registry ( if the registry responds ) and the git repository also ( if the private registry doesn't respond -- aka it doesn't exist -- ).

I know that we could set up each dependency to refer to a git tag/branch/commit but we want also to use the registry if possible.

UPDATE

So basically I would need a package.json that would know that if this part fails:

"dependencies": {
    "app.core": "0.1.1"
}

because the private registry is not installed or not available, it could still load the dependecy from something like this:

"dependencies": {
    "app.core": "git+ssh://[email protected]:group/app-core.git#v0.1.1"
},

Also note that i would prefer something that can be pushed in the git repository so that neither one of the teams should change the package.json locally.

Hope that someone can help.

like image 711
helly0d Avatar asked May 07 '14 09:05

helly0d


People also ask

What is npm registry URL?

npm is configured to use the npm public registry at https://registry.npmjs.org by default.

What is -- Save flag in npm install?

npm install --save-dev. –save-optional or -O: When this command is used the install the that packages will be listed under the optional Dependency section of the package. json file.


1 Answers

The only way that i found to work for the moment is to have a package.json like this:

"scripts": {
    "postinstall" : "node fallbackDependencies.js"
}
"dependencies": {
    "app.core": "git+ssh://[email protected]:group/app-core.git#v0.1.1"
},
"optionalDependencies": {
    "app.core": "0.1.1"
}

And in the fallbackDependencies.js file to run a script that takes all the dependencies from the package.json which are also in the optionalDependencies and for each of them check if there is a folder with that name in the node_modules folder. If there is no folder then run npm install <json.dependencies[x]>.

This is the only temporary solution that i could think of.

If someone has a better approach to this please feel free to answer.

like image 173
helly0d Avatar answered Oct 27 '22 18:10

helly0d